コード例 #1
0
        protected bool isRedirectBuy = true; //未购买是否跳转到购买页面

        public WorkAuthorize(bool isRedirect = true, bool isAjax = false, bool isRedirectBuy = true)
            : base(isRedirect)
        {
            this.isAjax        = isAjax;
            this.isRedirectBuy = isRedirectBuy;
            this.baseParam     = new WorkParam();
        }
コード例 #2
0
 public virtual ActionResult WorkResult(WorkParam baseParam, long doWorkId, long contentId)
 {
     if (baseParam.workStatus != 2 && baseParam.workStatus != 3)
     {
         return(View("DoWork", baseParam));
     }
     return(View(baseParam));
 }
コード例 #3
0
 public virtual ActionResult DoWork(WorkParam baseParam, long doWorkId, long contentId)
 {
     //此处通过状态判断,如果已经提交作业,则直接用结果视图(WorkResult.cshtml)对数据进行处理
     if (baseParam.workStatus == 2 || baseParam.workStatus == 3)
     {
         return(View("WorkResult", baseParam));
     }
     return(View(baseParam));
 }
コード例 #4
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);

            if (null == current || current.UserID == 0)
            {
                if (isAjax || !isRedirectBuy)
                {
                    filterContext.Result = new CustomJsonResult()
                    {
                        Data = new ReturnResult(-1, "未检测到登录用户,请登录后再试!")
                    };
                }
                else
                {
                    baseParam.User = current;
                }
                return;
            }

            var workBaseService = (WorkBaseService)DependencyResolver.Current.GetService <WorkBaseService>();
            var workService     = (WorkService)DependencyResolver.Current.GetService <WorkService>();
            var packageService  = DependencyResolver.Current.GetService <PackageService>();

            var result = filterContext.HttpContext.Request.CheckWorkParams(current, workBaseService, workService, packageService, !isAjax, isRedirectBuy);

            baseParam = result.Data;

            if (result.Code != 0 && result.Code < 100 && !isAjax)//参数或权限验证失败
            {
                filterContext.Result = new RedirectResult("/error?message=" + result.Message);
            }
            else if (result.Code != 0 && result.Code < 100)
            {
                filterContext.Result = new CustomJsonResult()
                {
                    Data = result
                };
            }
            else if (result.Code != 0 && isAjax)
            {
                filterContext.Result = new CustomJsonResult()
                {
                    Data = new ReturnResult(-1, result.Message)
                };
            }
            else if (!baseParam.IsCan && baseParam.PackageType == 1 && isRedirectBuy && 5 != baseParam.WorkResource.ModuleId)
            {
                filterContext.Result = filterContext.Result = filterContext.HttpContext.Request.Url.ToString().LastIndexOf("mobile") > -1 ?
                                                              null //new RedirectResult(string.Format("/mobile/paper/buyWork?doworkId={0}&contentId={1}", result.Data.DoWorkBase.DoWorkID, result.Data.WorkResource.ContentId))
                 : new RedirectResult(string.Format("/home/buyWork?doworkId={0}&contentId={1}", result.Data.DoWorkBase.DoWorkID, result.Data.WorkResource.ContentId));
            }
            baseParam.ReturnResult = result;
        }
コード例 #5
0
        /// <summary>
        /// 作业参数验证与基础信息赋值
        /// </summary>
        public static ReturnResult <WorkParam> CheckWorkParams(this HttpRequestBase request, User user, WorkBaseService workBaseService, WorkService workService, PackageService packageService, bool isGetParts = true, bool isRedirectBuy = true)
        {
            var query  = request.Url.ParseQueryString();
            var client = new RestClient(100001);

            var defectParams = worksParamsArray.Except(query.AllKeys.Select(t => t.ToLower()));

            if (defectParams.Any())
            {
                return(new ReturnResult <WorkParam>(1, null, string.Concat("基础参数验证失败,参数:", string.Join(",", defectParams), "未找到")));
            }

            var baseParam = new WorkParam()
            {
                User     = user,
                ViewType = 2
            };

            long doWorkId = Convert.ToInt64(query.Get("doWorkId")), contentId = Convert.ToInt64(query.Get("contentId"));

            ///请求用户个人列表
            baseParam.DoWorkBase = workBaseService.GetDoWorkBase(doWorkId);

            if (null == baseParam.DoWorkBase || baseParam.DoWorkBase.WorkType < 101)
            {
                return(new ReturnResult <WorkParam>(2, baseParam, "未找到符合条件的作业"));
            }
            if (baseParam.DoWorkBase.SubmitUserID != user.UserID && baseParam.DoWorkBase.PublishUserId != user.UserID)
            {
                return(new ReturnResult <WorkParam>(3, baseParam, "暂无作业权限"));
            }
            if (baseParam.DoWorkBase.WorkBaseStatus != 0)
            {
                return(new ReturnResult <WorkParam>(7, baseParam, "这份作业已经被老师取消布置啦,再去作业系统看看有没有重新布置哦!"));
            }

            var recordId = Convert.ToInt64(baseParam.DoWorkBase.RedirectParm.Split('.')[0].Replace("bid_", string.Empty));

            baseParam.WorkResource = workService.GetWorkResource(contentId);

            if (null == baseParam.WorkResource || baseParam.WorkResource.RecordId != recordId)
            {
                return(new ReturnResult <WorkParam>(4, baseParam, "未找到符合条件的作业"));
            }

            baseParam.Package = packageService.GetPackage(baseParam.WorkResource.PackageId);

            baseParam.PackageType = baseParam.Package.GroupType;

            baseParam.UnitWork = workService.GetUserUnitWork(contentId, doWorkId);

            baseParam.workStatus = null == baseParam.UnitWork ? 0 : baseParam.UnitWork.Status;

            #region 使用权限判断

            if (!string.IsNullOrEmpty(baseParam.WorkResource.RelationPath))
            {
                long rootVersion = Convert.ToInt64(baseParam.WorkResource.RelationPath.Split('/').First());

                var packageResults = packageService.GetTaskResultContents(baseParam.Package.PackageId, rootVersion);

                if (null == packageResults || !packageResults.Any())
                {
                    return(new ReturnResult <WorkParam>(5, baseParam, "未找到指定资源"));
                }

                ////  DateTime.Now < DateTime.Parse("2015-09-01")  时间小于九月一号的所有资源免费开放
                if (baseParam.workStatus > 0 || packageResults.Any(t => t.IsFree) || DateTime.Now < DateTime.Parse("2015-09-01"))                 //如果免费资源或者已经完成的作业,则不进行验证
                {
                    baseParam.PackagePermission = new PackagePermissionContract()
                    {
                        IsFree = true
                    };
                }
                else
                {
                    //判断用户使用权限 VipCode(1:已购买书籍 2:无使用权限 3:已购买但已过期  4:免费资源  5:已开通会员服务 6:已经开通服务但已经过期)
                    //var result = new RestClient(user.UserID, "http://192.168.1.61:8123").ExecuteGet<ReturnResult<PackagePermissionContract>>("/bookcase/home/IsCan", new { packageId = baseParam.Package.PackageId, userid = user.UserID });
                    var result = new RestClient(user.UserID).ExecuteGet <ReturnResult <PackagePermissionContract> >(WebApi.UserIsCan, new { packageId = baseParam.Package.PackageId, userid = user.UserID });

                    if (result.Ret == 0 && null != result.Data)
                    {
                        baseParam.PackagePermission = result.Data;
                    }

                    if (null == baseParam.PackagePermission && (baseParam.WorkResource.ModuleId != 5 || baseParam.WorkResource.ModuleId != 9))
                    {
                        return(new ReturnResult <WorkParam>(102, baseParam, "您还未购买,请购买后再使用!"));
                    }
                    if (baseParam.WorkResource.ModuleId != 5 && baseParam.WorkResource.ModuleId != 9)
                    {
                        if (null != baseParam.PackagePermission && baseParam.PackagePermission.ExpirationDate < DateTime.Now)
                        {
                            return(new ReturnResult <WorkParam>(103, baseParam, "产品已过期,请重新购买!"));
                        }
                    }
                }
            }
            #endregion

            if (baseParam.WorkResource.IsFull && isGetParts)
            {
                baseParam.WorkResource.resourceParts = workService.GetResourceParts(contentId);
            }

            if (baseParam.DoWorkBase.PublishUserId == user.UserID && baseParam.DoWorkBase.SubmitUserID != user.UserID && baseParam.workStatus != 3)
            {
                return(new ReturnResult <WorkParam>(6, baseParam, "学生未完成作业,无法查看"));
            }

            return(new ReturnResult <WorkParam>(baseParam));
        }
コード例 #6
0
        public virtual JsonResult SubmitWork(WorkParam baseParam, long doWorkId, long contentId)
        {
            if (baseParam.workStatus == 2 || baseParam.workStatus == 3)
            {
                //跟读作业通过接口调用,其他作业只允许提交一次
                return(Json(new ReturnResult(101, "无法重复提交已完成的作业")));
            }

            if (baseParam.DoWorkBase.WorkBaseStatus != 0)
            {
                return(Json(new ReturnResult(102, "这份作业已经被老师取消布置啦,再去作业系统看看有没有重新布置哦!")));
            }

            var unitWorks = baseParam.UnitWork ?? new UnitWorksContract();             //第一次提交,baseParam.UnitWork是为null.

            var actualScore = 0m;
            var content     = Request.Form["content"];
            var answerList  = new List <WorkAnswerContract>();

            if (!string.IsNullOrWhiteSpace(content))             //目前只做试题批改,后期有新的类型再修改
            {
                var questionCount = Convert.ToInt32(Request.Form["questionCount"]);

                var userAnswer = JSONHelper.Decode <List <WorkAnswerContract <QuestionAnswer> > >(content);

                var correctService = DependencyResolver.Current.GetService <CorrectService>();
                var wikiQues       = new List <Ques.Core.Models.Question>();

                answerList = correctService.WikiQuesCorrect(userAnswer, ref actualScore, ref wikiQues);

                answerList.ForEach(t => t.ResourceType = ResourceModuleOptions.Question.ToString());

                unitWorks.CorrectRate = questionCount > 0 ? answerList.Count(t => t.Assess == 1) * 1.0m / questionCount : 0;
            }

            if (!string.IsNullOrWhiteSpace(Request.Form["workScore"]))
            {
                unitWorks.WorkScore = Convert.ToDecimal(Request.Form["workScore"]);
            }

            unitWorks.ContentId      = contentId;
            unitWorks.RecordId       = baseParam.WorkResource.RecordId;
            unitWorks.WorkId         = baseParam.DoWorkBase.WorkID;
            unitWorks.DoWorkId       = doWorkId;
            unitWorks.SubmitUserId   = baseParam.User.UserID;
            unitWorks.SubmitUserName = baseParam.User.UserName;
            unitWorks.ActualScore    = actualScore;
            unitWorks.SubmitDate     = DateTime.Now;
            unitWorks.IsTimeOut      = unitWorks.SubmitDate > baseParam.DoWorkBase.EffectiveDate;
            unitWorks.SubmitCount    = unitWorks.SubmitCount + 1;
            unitWorks.Status         = 3;
            unitWorks.WorkLong       = Convert.ToInt32(Request["workLong"]);
            unitWorks.WorkLong       = unitWorks.WorkLong < 1 ? 1 : unitWorks.WorkLong;

            var doId = workService.DoUnitWorks(unitWorks, answerList, baseParam.DoWorkBase.TotalNum);

            #region 发送消息
            if (doId > 0 && actualScore >= 70)
            {
                var msg      = new CApi.Client.XiXinClient();
                var workname = "我于" + unitWorks.SubmitDate.ToString("MM月dd日 HH:mm") + "提交了“" + baseParam.WorkResource.ResourceName + "”,得分" + actualScore + ",";
                if (actualScore >= 70 && actualScore < 80)
                {
                    workname += "成绩中等。";
                }
                else if (actualScore >= 80 && actualScore < 90)
                {
                    workname += "成绩良好。";
                }
                else if (actualScore >= 90)
                {
                    workname += "成绩优秀。";
                }
                //异步发送习信与书房消息
                System.Threading.Tasks.Task.Factory.StartNew(() => msg.SendToFamily(baseParam.User.UserID, workname));
                System.Threading.Tasks.Task.Factory.StartNew(() => SendMessage(baseParam.User, "作业消息", workname));
            }
            #endregion

            return(Json(doId == 0 ? new ReturnResult("作业提交失败,请稍后再试") : new ReturnResult <long>(doId)));
        }