Ejemplo n.º 1
0
        /// <summary>
        /// 获取模块资源
        /// </summary>
        public ContentResult GetTaskResultContents(long packageId, string cid, int moduleId)
        {
            var key = string.Concat("_preview_taskresult_contents_", packageId, "_", cid, "_", moduleId);
            //var cacheContent = RedisHelper.GetItemFromSet<string>(key).FirstOrDefault();
            var cacheContent = RedisHelper.GetItem <string>(key);

            if (!string.IsNullOrEmpty(cacheContent))
            {
                return(Content(cacheContent, "application/json"));
            }

            var currContents = packageService.GetTaskResultContents(packageId, cid).ResultContents.Where(t => t.ModuleId.Equals(moduleId)).ToList();

            if (!currContents.Any())
            {
                return(Content(JSONHelper.Encode(new ReturnResult("未找到资源")), "application/json"));
            }

            cacheContent = JSONHelper.Encode(new ReturnResult <List <Tools.Package.DataContracts.TaskResultContentContract> >(currContents));

            if (!string.IsNullOrEmpty(cacheContent))
            {
                //RedisHelper.AddItemToSet(key, cacheContent);
                RedisHelper.SetItem(key, cacheContent);//缓存时间设置为半天 12小时
            }

            return(Content(cacheContent, "application/json"));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 电子书目录信息
        /// </summary>
        public ContentResult EbookCatalogues(long packageId)
        {
            var key = string.Concat("_preview_ebook_catalogues_", packageId);

            //var cacheContent = RedisHelper.GetItemFromSet<string>(key).FirstOrDefault();
            var cacheContent = RedisHelper.GetItem <string>(key);

            if (!string.IsNullOrEmpty(cacheContent))
            {
                return(Content(cacheContent, "application/json"));
            }

            var catalogues = packageService.GetCatalogues(packageId).OrderByDescending(t => t.DisplayOrder);

            var modules = packageService.GetTaskModules(packageId);
            var level   = catalogues.OrderBy(t => t.DisplayOrder).Where(t => t.Level == 1).ToList();

            foreach (var catalogue in level)
            {
                catalogue.Recursion(item =>
                {
                    item.Children = catalogues.Where(c => c.ParentId != null && c.ParentId.Equals(item.ID));
                }, item => item.Children);
            }

            cacheContent = JSONHelper.Encode(new ReturnResult <object>(new { catalogues = level, modules = modules }));

            if (!string.IsNullOrEmpty(cacheContent))
            {
                //RedisHelper.AddItemToSet(key, cacheContent);
                RedisHelper.SetItem(key, cacheContent);//设置缓存时间为12小时
            }
            return(Content(cacheContent, "application/json"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 根据资源类型ID和版本ID获取
        /// </summary>
        public ContentResult Get(Guid moduleId, long versionId)
        {
            DateTime d1 = DateTime.Now;
            //RedisHelper.RemoveItemByKey("_preview");
            var key = string.Concat("_preview_resource_get_", moduleId, "_", versionId);
            //var cacheContent = RedisHelper.GetItemFromSet<string>(key).FirstOrDefault();
            var cacheContent = RedisHelper.GetItem <string>(key);

            if (!string.IsNullOrEmpty(cacheContent))
            {
                //记录redis服务器用时.
                Response.Headers.Add("Redis-Total-Milliseconds", (DateTime.Now - d1).TotalMilliseconds.ToString());
                return(Content(cacheContent, "application/json"));
            }

            if (moduleId == ResourceModuleOptions.ExaminationPaper) //试卷
            {
                var ExaminationPaper = resourceService.GetExamination(versionId);
                if (ExaminationPaper.Ret == 0)
                {
                    cacheContent = JSONHelper.Encode(ExaminationPaper);
                }
            }
            else if (moduleId == ResourceModuleOptions.Question)//试题
            {
                //cacheContent = JSONHelper.Encode(resourceService.GetQuestions(versionId));
                var Question = resourceService.GetQuestions(versionId);
                if (Question.Ret == 0)
                {
                    cacheContent = JSONHelper.Encode(Question);
                }
            }
            else if (moduleId == ResourceModuleOptions.ListeningAndSpeakingExam)
            {
                var ListeningAndSpeakingExam = resourceService.GetListenExamination(versionId, ResourceModuleOptions.ListeningAndSpeaking);
                if (ListeningAndSpeakingExam.Ret == 0)
                {
                    cacheContent = JSONHelper.Encode(ListeningAndSpeakingExam);
                }
                // cacheContent = JSONHelper.Encode(resourceService.GetListenExamination(versionId, ResourceModuleOptions.ListeningAndSpeaking));
            }
            else
            {
                cacheContent = new RestClient(100001).ExecuteContent(WebAPI.ResourceGet, new { versionid = versionId, moduleid = moduleId });
                //result.Data = resultArticle.Data;
                //result.Ret = resultArticle.Ret;
                //result.Message = resultArticle.Message;
                //cacheContent = JSONHelper.Encode(resourceService.GetByVersionId(moduleId, versionId));
            }

            if (!string.IsNullOrEmpty(cacheContent))
            {
                //RedisHelper.AddItemToSet<string>(key, cacheContent);
                RedisHelper.SetItem <string>(key, cacheContent, 432000);//设置缓存时间5天
            }

            return(Content(cacheContent, "application/json"));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 根据资源类型ID和版本ID获取
        /// </summary>
        public ActionResult GetList(Guid moduleId, string versionIds)
        {
            var versions = versionIds.Split(',').Select(t => Convert.ToInt64(t)).ToArray();

            if (!versions.Any())
            {
                return(Json(new ReturnResult(1, "无效的资源"), JsonRequestBehavior.AllowGet));
            }

            DateTime d1  = DateTime.Now;
            var      key = string.Concat(string.Concat("_preview_resource_getlist_", moduleId, "_", string.Join("_", versionIds)));

            //获取缓存的数据
            //var cacheContent = RedisHelper.GetItemFromSet<string>(key).FirstOrDefault();
            var cacheContent = RedisHelper.GetItem <string>(key);

            if (!string.IsNullOrEmpty(cacheContent))
            {
                //记录redis服务器用时.
                Response.Headers.Add("Redis-Total-Milliseconds", (DateTime.Now - d1).TotalMilliseconds.ToString());
                return(Content(cacheContent, "application/json"));
            }

            if (moduleId == ResourceModuleOptions.ExaminationPaper) //试卷
            {
                cacheContent = JSONHelper.Encode(resourceService.GetExamination(versions[0]));
            }
            else if (moduleId == ResourceModuleOptions.Question)//试题
            {
                cacheContent = JSONHelper.Encode(resourceService.GetQuestions(versions));
            }
            else
            {
                cacheContent = resourceService.GetByVersionIds(moduleId, versionIds);
            }

            if (!string.IsNullOrEmpty(cacheContent) && cacheContent.Contains("\"ret\":0"))
            {
                RedisHelper.SetItem <string>(key, cacheContent, 432000);//设置缓存时间(s)
            }

            return(Content(cacheContent, "application/json"));
        }
Ejemplo n.º 5
0
 private WorkAnswerContract listenPaperCorrect(WorkAnswerContract workAnswer, long doId, long versionId, int sid, int assess, decimal itemScore)
 {
     if (null == workAnswer)
     {
         var questionAnswers = new List <ListenAnswerEntity>()
         {
             new ListenAnswerEntity()
             {
                 Sid          = sid,
                 AudioUrl     = string.Empty,
                 BlankContent = string.Empty
             }
         };
         workAnswer = new WorkAnswerContract()
         {
             DoId          = doId,
             VersionId     = versionId,
             AnswerType    = 1,
             ResourceType  = ResourceModuleOptions.Question.ToString(),
             Assess        = assess,
             Score         = itemScore,
             AnswerContent = JSONHelper.Encode <List <ListenAnswerEntity> >(questionAnswers)
         };
     }
     else
     {
         var questionAnswers = JSONHelper.Decode <List <ListenAnswerEntity> >(workAnswer.AnswerContent);
         if (null == questionAnswers || !questionAnswers.Any())
         {
             questionAnswers.Add(new ListenAnswerEntity()
             {
                 Sid          = sid,
                 AudioUrl     = string.Empty,
                 BlankContent = string.Empty
             });
             workAnswer.AnswerContent = JSONHelper.Encode <List <ListenAnswerEntity> >(questionAnswers);
         }
         workAnswer.Assess = assess;
         workAnswer.Score  = itemScore;
     }
     return(workAnswer);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 提交答案对象 同步跟读(单词,句子)、听力考试、模拟考试
        /// </summary>
        /// <param name="answer"></param>
        /// <returns></returns>
        public bool SubmitWork(SpeekingAnswersEntity <WorkAnswerContract <ReadAnswerEntity> > answers)
        {
            if (answers == null)
            {
                return(false);
            }

            //分享答案数据包写入答案表 此处答案方式提交都是一致的 根据类型不同提取数据
            //答案JSON编码
            answers.AnswerData.ForEach(item => { item.AnswerContent = JSONHelper.Encode <List <ReadAnswerEntity> >(item.Answers); });
            if (answers.Is_Work == 1)
            {
                var worksInfo = answers.worksInfo;
                //查询是否已做过
                var unitWork = workService.GetUserUnitWork(answers.worksInfo.ContentId, answers.worksInfo.DoWorkId);
                worksInfo.Status      = 3;//手动更新状态
                worksInfo.SubmitCount = 1;
                worksInfo.WorkLong    = Convert.ToInt32(worksInfo.WorkLong / 1000) + 1;
                worksInfo.WorkScore   = worksInfo.ActualScore;
                if (unitWork != null)
                {
                    worksInfo.WorkScore   = 100;
                    worksInfo.WorkLong    = worksInfo.WorkLong + unitWork.WorkLong; //时长相加
                    worksInfo.DoId        = unitWork.DoId;
                    worksInfo.Comment     = unitWork.Comment;
                    worksInfo.CommentType = unitWork.CommentType;
                    if (worksInfo.ActualScore < unitWork.ActualScore)
                    {//如果成绩小于之前成绩 则沿用历史成绩
                        worksInfo.ActualScore = unitWork.ActualScore;
                    }
                    worksInfo.SubmitCount = unitWork.SubmitCount + 1;
                }
                return(workService.DoUnitWorks(worksInfo, answers.AnswerData) > 0);
            }
            else
            {
                var practiceInfo = answers.practiceInfo;
                practiceInfo.Status   = 3;//手动更新状态
                practiceInfo.WorkLong = Convert.ToInt32(practiceInfo.WorkLong / 1000) + 1;
                return(workService.DoIndepPractice(practiceInfo, answers.AnswerData) > 0);
            }
        }
Ejemplo n.º 7
0
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var response = context.HttpContext.Response;

            response.ContentType = !String.IsNullOrEmpty(ContentType) ? ContentType : "application/json";

            if (ContentEncoding != null)
            {
                response.ContentEncoding = ContentEncoding;
            }

            if (Data != null)
            {
                response.Write(JSONHelper.Encode(Data));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 批改试题
        /// </summary>
        public List <WorkAnswerContract> WikiQuesCorrect(List <WorkAnswerContract <QuestionAnswer> > userAnswer, ref decimal totalScore, ref List <Ques.Core.Models.Question> wikiQues)
        {
            var _list = new List <WorkAnswerContract>();

            if (null == userAnswer || !userAnswer.Any())
            {
                return(_list);
            }

            wikiQues = quesService.GetQuestionByVersions(userAnswer.Select(t => t.VersionId).ToList());

            var corrResult = CorrectContext.Instance.Correct(userAnswer, wikiQues, ref totalScore);

            corrResult.ForEach(t =>
            {
                t.AnswerContent = JSONHelper.Encode(t.Answers);
                _list.Add(t);
            });

            return(_list);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 电子报目录及版面信息
        /// </summary>
        public ContentResult NewsPaperInfo(long packageId, long bookVersion)
        {
            var key = string.Concat("_preview_newspaper_info_", packageId);

            //var cacheContent = RedisHelper.GetItemFromSet<string>(key).FirstOrDefault();
            var cacheContent = RedisHelper.GetItem <string>(key);

            if (!string.IsNullOrEmpty(cacheContent))
            {
                return(Content(cacheContent, "application/json"));
            }

            //获取资源包目录*****/
            var catalogues = packageService.GetCatalogues(packageId, false, true).ToList();

            var bookResult = new RestClient(100001).ExecuteGet <ReturnResult <BookVersionContract> >(WebApi.GetBookVersion, new { bookId = bookVersion });

            var newsPaper = new
            {
                bookVersionName = bookResult != null && bookResult.Data != null ? bookResult.Data.Name : string.Empty,
                catalogues      = catalogues.Where(m => !catalogues.Any(t => t.ParentId == m.ID)).Select(t => new
                {
                    id   = t.ID,
                    name = t.Name
                })
            };

            cacheContent = JSONHelper.Encode(new ReturnResult <object>(newsPaper));

            if (!string.IsNullOrEmpty(cacheContent) && cacheContent.Contains("\"ret\":0"))
            {
                // RedisHelper.AddItemToSet<string>(key, cacheContent);
                RedisHelper.SetItem <string>(key, cacheContent);
            }
            return(Content(cacheContent, "application/json"));
        }
Ejemplo n.º 10
0
        private WorkAnswerContract paperCorrect(WorkAnswerContract workAnswer, long doId, long versionId, int sid, int assess, decimal itemScore)
        {
            if (null == workAnswer)
            {
                var questionAnswers = new List <QuestionAnswer>()
                {
                    new QuestionAnswer()
                    {
                        Sid       = sid,
                        Assess    = assess,
                        ItemScore = itemScore,
                        Content   = string.Empty
                    }
                };
                workAnswer = new WorkAnswerContract()
                {
                    DoId          = doId,
                    VersionId     = versionId,
                    AnswerType    = 1,
                    ResourceType  = ResourceModuleOptions.Question.ToString(),
                    Assess        = assess,
                    Score         = itemScore,
                    AnswerContent = JSONHelper.Encode <List <QuestionAnswer> >(questionAnswers)
                };
            }
            else
            {
                var questionAnswers = JSONHelper.Decode <List <QuestionAnswer> >(workAnswer.AnswerContent);
                var currAnswer      = questionAnswers.FirstOrDefault(t => t.Sid == sid);
                if (null == currAnswer)
                {
                    questionAnswers.Add(new QuestionAnswer()
                    {
                        Sid       = sid,
                        Assess    = assess,
                        ItemScore = itemScore,
                        Content   = string.Empty
                    });
                }
                else
                {
                    currAnswer.Assess    = assess;
                    currAnswer.ItemScore = itemScore;
                }

                if (questionAnswers.Count == 1)
                {
                    workAnswer.Assess = questionAnswers[0].Assess;
                }
                else if (!questionAnswers.Any(t => t.Assess != 1))
                {
                    workAnswer.Assess = 1;
                }
                else if (questionAnswers.Any(t => t.Assess == 2))
                {
                    workAnswer.Assess = 2;
                }
                else if (!questionAnswers.Any(t => t.Assess != 3))
                {
                    workAnswer.Assess = 3;
                }
                else if (questionAnswers.Any(t => t.Assess == 4))
                {
                    workAnswer.Assess = 4;
                }
                workAnswer.Score         = questionAnswers.Sum(t => t.ItemScore);
                workAnswer.AnswerContent = JSONHelper.Encode <List <QuestionAnswer> >(questionAnswers);
            }
            return(workAnswer);
        }
Ejemplo n.º 11
0
 public string Serialize(object obj)
 {
     return(JSONHelper.Encode(obj));
 }