/// <summary> /// 获取学生任务报告的统计部分 /// </summary> /// <param name="studentId"></param> /// <param name="taskId"></param> /// <returns></returns> public DtoStudentReport GetByStudentTask(int studentId, int taskId) { StudentPracticeBll studentPracticeBll = new StudentPracticeBll(); var result = studentPracticeBll.StudentTaskRepository.IsHasTaskReport(studentId, taskId); if (!result) { throw new AbhsException(ErrorCodeEnum.NotStudyReport, AbhsErrorMsg.ConstNotStudyReport); } //获取学生答案 Yw_StudentStudyTaskAnswerExt answer = studentPracticeBll.StuStudyTaskAnsRepo.GetByStudentTask(studentId, taskId) as Yw_StudentStudyTaskAnswerExt; StudentAnswerCard answerCard = answer.Yta_Answer_Obj; DtoStudentReport studentReport = new DtoStudentReport(); if (answerCard != null) { studentReport.StudyDate = answerCard.SubmitTime; studentReport.TotalScore = Convert.ToInt32(Math.Round(answerCard.TotalStars * 1.0 / (answerCard.AnswerCollection.Count() * 5) * 5, MidpointRounding.AwayFromZero)); studentReport.TotalStars = answerCard.TotalStars; studentReport.StudyTime = Convert.ToInt32(Math.Ceiling(answerCard.UseTime * 1.0 / 60)); studentReport.ResultCoins = answerCard.AnswerCollection.Select(s => s.ResultCoins).Sum(); studentReport.TotalCoins = answerCard.TotalCoins; studentReport.SubjectCount = answerCard.AnswerCollection.Count(); double rates = Math.Round((double)(answerCard.AnswerCollection.Where(x => x.ResultStars == 5).Count()) / answerCard.AnswerCollection.Count(), 2) * 100; studentReport.ExcellentRates = rates; List <Yw_Knowledge> knowledges = new List <Yw_Knowledge>(); var knowledgeShow = answerCard.AnswerCollection.Where(x => x.KnowledgeId != 0).GroupBy(s => s.KnowledgeId); studentReport.Knowledge = GetKnowledge(knowledgeShow); } return(studentReport); }
public void TestInsert() { List <StudentAnswerCard> answerCard = new List <StudentAnswerCard>(); DtoStudentWrongBook wrongBook = new DtoStudentWrongBook(); wrongBook.CourseId = 1; wrongBook.LessonId = 1; wrongBook.LessonProgressId = 1; wrongBook.Source = StudyWrongSourceEnum.课后任务; wrongBook.StudentId = 10; wrongBook.StudyTaskId = 1; StudentAnswerCard model = new StudentAnswerCard(); model.AnswerCollection = new List <StudentAnswerBase>() { }; for (int i = 7; i < 19; i++) { StuFreeAnswer tmp = new StuFreeAnswer(); tmp.ResultStars = 0; tmp.SubjectId = i; tmp.KnowledgeId = i; tmp.Answer = "123456"; model.AnswerCollection.Add(tmp); } answerCard.Add(model); var result = bll.SaveWrongBook(answerCard, wrongBook); Assert.IsTrue(result); }
public void GenerateTaskSubjectsAutoAfterStudy() { Yw_StudentLessonAnswerExt answer = new Yw_StudentLessonAnswerExt(); answer.Yla_Answer_Obj = new List <Domain.JsonEntity.Answer.StudentAnswerCard>(); StudentAnswerCard card = new StudentAnswerCard(); card.Part = 1; card.SubmitTime = DateTime.Now.ToString(); card.AnswerCollection = new List <StudentAnswerBase>(); BlankAnswerItem item = new BlankAnswerItem(); item.Index = 0; item.Score = 0.8; item.Text = "ce shi"; BlankAnswerItem item1 = new BlankAnswerItem(); item1.Index = 1; item1.Score = 0.8; item1.Text = "ce shi1"; card.AnswerCollection.Add(new StuBlankAnswer() { Answers = new List <StuBlankAnswer.BlankAnswerItem>() { item, item1 }, KnowledgeId = 10000, ResultCoins = 3, ResultStars = 3, SubjectCoins = 5, SubjectId = 10000, Type = (int)SubjectTypeEnum.填空题 }); card.AnswerCollection.Add(new StuBlankAnswer() { Answers = new List <StuBlankAnswer.BlankAnswerItem>() { item, item1 }, KnowledgeId = 10000, ResultCoins = 3, ResultStars = 3, SubjectCoins = 5, SubjectId = 10001, Type = (int)SubjectTypeEnum.填空题 }); card.AnswerCollection.Add(new StuBlankAnswer() { Answers = new List <StuBlankAnswer.BlankAnswerItem>() { item, item1 }, KnowledgeId = 10000, ResultCoins = 3, ResultStars = 3, SubjectCoins = 5, SubjectId = 10002, Type = (int)SubjectTypeEnum.填空题 }); card.AnswerCollection.Add(new StuBlankAnswer() { Answers = new List <StuBlankAnswer.BlankAnswerItem>() { item, item1 }, KnowledgeId = 10000, ResultCoins = 3, ResultStars = 3, SubjectCoins = 5, SubjectId = 10003, Type = (int)SubjectTypeEnum.填空题 }); card.AnswerCollection.Add(new StuBlankAnswer() { Answers = new List <StuBlankAnswer.BlankAnswerItem>() { item, item1 }, KnowledgeId = 10000, ResultCoins = 3, ResultStars = 3, SubjectCoins = 5, SubjectId = 10004, Type = (int)SubjectTypeEnum.填空题 }); card.AnswerCollection.Add(new StuBlankAnswer() { Answers = new List <StuBlankAnswer.BlankAnswerItem>() { item, item1 }, KnowledgeId = 10000, ResultCoins = 3, ResultStars = 3, SubjectCoins = 5, SubjectId = 10005, Type = (int)SubjectTypeEnum.填空题 }); StudentAnswerCard card1 = new StudentAnswerCard(); card1.Part = 1; card1.SubmitTime = DateTime.Now.ToString(); card1.AnswerCollection = new List <StudentAnswerBase>(); BlankAnswerItem item2 = new BlankAnswerItem(); item2.Index = 0; item2.Score = 0.8; item2.Text = "ce shi"; BlankAnswerItem item3 = new BlankAnswerItem(); item3.Index = 1; item3.Score = 0.8; item3.Text = "ce shi1"; card1.AnswerCollection.Add(new StuBlankAnswer() { Answers = new List <StuBlankAnswer.BlankAnswerItem>() { item2, item3 }, KnowledgeId = 10000, ResultCoins = 3, ResultStars = 3, SubjectCoins = 5, SubjectId = 10010, Type = (int)SubjectTypeEnum.填空题 }); card1.AnswerCollection.Add(new StuBlankAnswer() { Answers = new List <StuBlankAnswer.BlankAnswerItem>() { item2, item3 }, KnowledgeId = 10001, ResultCoins = 3, ResultStars = 3, SubjectCoins = 5, SubjectId = 10011, Type = (int)SubjectTypeEnum.填空题 }); card1.AnswerCollection.Add(new StuBlankAnswer() { Answers = new List <StuBlankAnswer.BlankAnswerItem>() { item2, item3 }, KnowledgeId = 10002, ResultCoins = 3, ResultStars = 3, SubjectCoins = 5, SubjectId = 10012, Type = (int)SubjectTypeEnum.填空题 }); card1.AnswerCollection.Add(new StuBlankAnswer() { Answers = new List <StuBlankAnswer.BlankAnswerItem>() { item2, item3 }, KnowledgeId = 10003, ResultCoins = 3, ResultStars = 3, SubjectCoins = 5, SubjectId = 10013, Type = (int)SubjectTypeEnum.填空题 }); card1.AnswerCollection.Add(new StuBlankAnswer() { Answers = new List <StuBlankAnswer.BlankAnswerItem>() { item2, item3 }, KnowledgeId = 10004, ResultCoins = 3, ResultStars = 3, SubjectCoins = 5, SubjectId = 10014, Type = (int)SubjectTypeEnum.填空题 }); card1.AnswerCollection.Add(new StuBlankAnswer() { Answers = new List <StuBlankAnswer.BlankAnswerItem>() { item2, item3 }, KnowledgeId = 10005, ResultCoins = 3, ResultStars = 3, SubjectCoins = 5, SubjectId = 10015, Type = (int)SubjectTypeEnum.填空题 }); answer.Yla_Answer_Obj.Add(card); answer.Yla_Answer_Obj.Add(card1); List <StudentAnswerBase> problemAnswers = answer.Yla_Answer_Obj.SelectMany(x => x.AnswerCollection).Where(x => x.ResultStars < 5).ToList(); List <Tuple <int, int> > errorSubjects = problemAnswers.GroupBy(x => x.SubjectId). Select(x => new Tuple <int, int>(x.Key, x.Min(y => y.ResultStars))).ToList(); List <DtoLesTaskSubject> subjects = new List <DtoLesTaskSubject>(); subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10000, Number = 3, Score = 1, SubjectId = 11000, SubjectType = (int)SubjectTypeEnum.判断题 }); subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10000, Number = 2, Score = 1, SubjectId = 11001, SubjectType = (int)SubjectTypeEnum.择题 }); subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10000, Number = 1, Score = 1, SubjectId = 11002, SubjectType = (int)SubjectTypeEnum.判断题 }); subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10001, Number = 1, Score = 2, SubjectId = 11002, SubjectType = (int)SubjectTypeEnum.判断题 }); subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10001, Number = 2, Score = 2, SubjectId = 11001, SubjectType = (int)SubjectTypeEnum.判断题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10001, Number = 3, Score = 2, SubjectId = 11003, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10001, Number = 3, Score = 2, SubjectId = 11004, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10001, Number = 3, Score = 2, SubjectId = 11005, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10002, Number = 3, Score = 2, SubjectId = 11202, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10003, Number = 3, Score = 2, SubjectId = 11203, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10004, Number = 3, Score = 2, SubjectId = 11204, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10005, Number = 3, Score = 2, SubjectId = 11205, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10006, Number = 3, Score = 2, SubjectId = 11006, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10007, Number = 3, Score = 2, SubjectId = 11007, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10008, Number = 3, Score = 2, SubjectId = 11008, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10009, Number = 3, Score = 2, SubjectId = 11009, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10010, Number = 3, Score = 2, SubjectId = 11010, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10011, Number = 3, Score = 2, SubjectId = 11011, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10012, Number = 3, Score = 2, SubjectId = 11012, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10013, Number = 3, Score = 2, SubjectId = 11013, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10014, Number = 3, Score = 2, SubjectId = 11014, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10015, Number = 3, Score = 2, SubjectId = 11015, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10016, Number = 3, Score = 2, SubjectId = 11016, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10017, Number = 3, Score = 2, SubjectId = 11017, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10018, Number = 3, Score = 2, SubjectId = 11018, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10019, Number = 3, Score = 2, SubjectId = 11019, SubjectType = (int)SubjectTypeEnum.选择题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10010, Number = 1, Score = 3, SubjectId = 12000, SubjectType = (int)SubjectTypeEnum.连线题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10011, Number = 1, Score = 3, SubjectId = 12001, SubjectType = (int)SubjectTypeEnum.连线题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10012, Number = 1, Score = 3, SubjectId = 12002, SubjectType = (int)SubjectTypeEnum.连线题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10013, Number = 1, Score = 3, SubjectId = 12003, SubjectType = (int)SubjectTypeEnum.连线题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10014, Number = 1, Score = 3, SubjectId = 12004, SubjectType = (int)SubjectTypeEnum.连线题 }); //subjects.Add(new DtoLesTaskSubject() { ErrorSubjectId = 10015, Number = 1, Score = 3, SubjectId = 12005, SubjectType = (int)SubjectTypeEnum.连线题 }); var groups = subjects.OrderBy(x => x.Number) .GroupBy(x => new { ErrorSubjectId = x.ErrorSubjectId, Score = x.Score }) .OrderBy(x => x.Key.Score); Dictionary <int, DtoLesTaskSubject> subjectSelected = new Dictionary <int, DtoLesTaskSubject>(); List <WrapSubjectGroup> wrapGroups = new List <WrapSubjectGroup>(); foreach (IGrouping <dynamic, DtoLesTaskSubject> group in groups) { wrapGroups.Add(new WrapSubjectGroup(group.Key.Score, group.ToList())); } bool hasSubject = false; bool reachMax = false; int maxSubjectCount = groups.Count() > 50 ? groups.Count() : 50;//每个错题至少推一个关联题目 int loopTime = 0; while (loopTime < maxSubjectCount) { hasSubject = false; foreach (WrapSubjectGroup group in wrapGroups) { bool result = group.TakeSubject(subjectSelected); if (result) { if (subjectSelected.Count >= maxSubjectCount) { reachMax = true; break; } hasSubject = true; } } if (!hasSubject || reachMax) { break; } loopTime++; } if (subjectSelected.Count > 0) { string str = string.Join(",", subjectSelected.OrderBy(x => x.Value.SubjectType).Select(x => x.Value.SubjectId)); } }
/// <summary> /// 保存课后任务或者练习题答案 /// </summary> public void SaveResult(int studentId, int taskId, int useTime, List <StudentAnswerBase> answers, StudyTaskTypeEnum taskType = 0, int partId = 0) { Yw_StudentTask stk = StudentTaskRepository.GetByStudentTask(studentId, taskId); if (stk.Yuk_Status == (int)StudentTaskStatusEnum.已完成) { throw new AbhsException(ErrorCodeEnum.StudentTaskStatusInvalid, AbhsErrorMsg.ConstStudentTaskStatusInvalid); } int totalStars = answers.Sum(x => x.ResultStars); int totalCoins = CalcCoins(answers); int fiveStarsAnswers = answers.Count(x => x.ResultStars == 5); var finishTime = DateTime.Now; //更新学生任务记录表 stk.Yuk_StartTime = finishTime.AddSeconds(0 - useTime);//反算时间 stk.Yuk_FinishTime = finishTime; stk.Yuk_StudentScore = totalStars; stk.Yuk_GainCoins = totalCoins; stk.Yuk_RightSubjectCount = fiveStarsAnswers; if (answers.Count > 0) { stk.Yuk_Percent = (int)(Math.Round(fiveStarsAnswers * 1.0 / answers.Count, 2) * 100); } stk.Yuk_Status = (int)StudentTaskStatusEnum.已完成; StudentTaskRepository.Update(stk); StudentAnswerCard card = new StudentAnswerCard(); card.UseTime = useTime; card.SubmitTime = finishTime.ToString("yyyy-MM-dd HH:mm:ss"); card.Part = partId; card.AnswerCollection = answers; card.TotalStars = totalStars; card.TotalCoins = totalCoins; //学生任务答题结果 Yw_StudentStudyTaskAnswerExt answer = new Yw_StudentStudyTaskAnswerExt(); answer.Yta_StudentId = studentId; answer.Yta_StudentStudyTaskId = stk.Yuk_Id; answer.Yta_TaskId = taskId; answer.Yta_Answer_Obj = card; answer.Yta_CreateTime = DateTime.Now; StuStudyTaskAnsRepo.Add(answer); //学生最近答题记录 Yw_StudyTask task = StudyTaskRepository.Get(taskId); StudentBll studentBll = new StudentBll(); List <int> ids = task.Ysk_SubjectIds.Split(',').Select(x => Convert.ToInt32(x)).ToList(); studentBll.RefreshStudentRecentSubject(studentId, ids); StudentInfoBll bll = new StudentInfoBll(); bll.AddCoins(studentId, totalCoins); if (taskType == StudyTaskTypeEnum.系统课后任务) { new StudentPracticeBll().PublishStudyTaskMessage( task.Ysk_CourseId, task.Ysk_LessonId, studentId, useTime, answers.Count, totalCoins); } else if (taskType == StudyTaskTypeEnum.课后练习) { new StudentPracticeBll().PublishStudyPractiseMessage( task.Ysk_CourseId, task.Ysk_LessonId, studentId, useTime, answers.Count, totalCoins); } //课程学习 = 1, 课后任务 = 2, 课后练习 = 3 StudyWrongSourceEnum?source = null; switch (taskType) { case StudyTaskTypeEnum.系统课后任务: case StudyTaskTypeEnum.老师课后任务: source = StudyWrongSourceEnum.课后任务; break; case StudyTaskTypeEnum.课后练习: source = StudyWrongSourceEnum.课后练习; break; default: source = StudyWrongSourceEnum.课后任务; break; } new StudentWrongBookBll().SaveWrongBook( new List <StudentAnswerCard> { card }, new DtoStudentWrongBook { CourseId = task.Ysk_CourseId, LessonId = task.Ysk_LessonId, LessonProgressId = task.Ysk_LessonProgressId, Source = source.Value, StudentId = studentId, StudyTaskId = taskId }); }
/// <summary> /// 提交学生学习进度数据 /// </summary> /// <param name="info"></param> /// <returns>0:添加成功,-1:课时进度秘钥错误,-2:数据重复提交,-3:金币数目错误</returns> public int SubmitStudyProgress(DtoStudnetUnitSubmit info) { ///注:这里考虑如何使用事务 DateTime submitTime = DateTime.Now; //获取最后一次学习进度 var progress = StuLesProgressRepository.GetLastProgress(info.StudnetId, info.LessonId); //判断课时进度秘钥是否正确 if (progress.Yle_key == info.ProgressKey) { //如果当前进度中的当前学习单元页大于提交的单元 if (progress.Yle_UnitIndex > info.UnitNum) { return(-2);//表示数据已经提交过,不能重复提交 } else { //创建答题卡对象 StudentAnswerCard card = null; #region 填充答题卡数据 if (info.Answers != null && info.Answers.Count > 0) { card = new StudentAnswerCard(); card.AnswerCollection = info.Answers; //填充答案 card.TotalStars = info.Answers.Sum(s => s.ResultStars); //填充总星数 card.TotalCoins = info.Answers.Sum(s => s.ResultCoins); //填充总金币数 card.Part = info.UnitID; //填充单元(页码)id card.SubmitTime = submitTime.ToString("yyyy-MM-dd HH:mm:ss"); //填充提交时间 card.UseTime = info.UseTime; //填充用户学习时间 } #endregion //创建金币记录对象 StuLessonCoinRecord coinRecord = null; #region 更新金币记录对象及答题卡部分数据 if (info.Coins != null && info.Coins.Count > 0) { coinRecord = new StuLessonCoinRecord(); coinRecord.CoinCollection = info.Coins; //填充金币记录 coinRecord.TotalCoins = info.Coins.Sum(s => s.GetCoins); //填充总金币数 coinRecord.Part = info.UnitID; //填充单元(页码)id coinRecord.SubmitTime = submitTime.ToString("yyyy-MM-dd HH:mm:ss"); //填充提交时间 coinRecord.UseTime = info.UseTime; //填充用户学习时间 } #endregion if (coinRecord != null && coinRecord.TotalCoins > info.AllCoin) //如果得到的金币数大于本页总金币数 { return(-3); //表示金币和大于总金币数 } else { #region 修改课时进度表数据 progress.Yle_UnitIndex = info.UnitNum + 1; //更新开始页 progress.Yle_IsFinished = info.UnitNum >= info.TotalUnitNum; //更新是否结束 progress.Yle_LastStudyTime = DateTime.Now; //更新最后学习时间 progress.Yle_SubjectCount += info.Answers.Count; //更新总题目数 progress.Yle_RightSubjectCount += info.Answers.Where(s => s.IsRight).Count(); //更新正确题目数 progress.Yle_GainCoins += info.Coins.Sum(s => s.GetCoins); //更新获取金币数量 progress.Yle_Percent = (int)(Math.Round(progress.Yle_RightSubjectCount * 1.0 / (progress.Yle_SubjectCount == 0 ? 1 : progress.Yle_SubjectCount), 2) * 100); //重新计算题目正确率 progress.Yle_StudySeconds += info.UseTime; //增加课时进度学习时长 #endregion #region 事务提交 using (TransactionScope scope = new TransactionScope()) { try { #region 提交 //如果学习完成,更新学生课程进度表 if (progress.Yle_IsFinished) { progress.Yle_FinishStudyTime = DateTime.Now;//修改课时完成完成时间 //获取完成的课时id var finisheds = StuLesProgressRepository.GetFinishedByLesson(info.StudnetId, info.CoruseId); if (!finisheds.Contains(info.LessonId))//如果课时没有学完过,修改课程进度表数据 { LessonBll bll = new LessonBll(); int lessonCount = bll.GetLessonsCountByCourse(info.CoruseId); //课程的课时数 var courseProgress = ScpRepository.GetByStudentCourse(info.StudnetId, info.CoruseId); //获取课程完成进度. courseProgress.Yps_LessonFinishedCount = finisheds.Count() + 1; //完成的课时数+1(自身) courseProgress.Yps_IsFinished = courseProgress.Yps_LessonFinishedCount >= lessonCount; //如果完成的课时数大于等于总课时数,则表示完成. courseProgress.Yps_NextLessonIndex = courseProgress.Yps_NextLessonIndex > info.LessonNum ? courseProgress.Yps_NextLessonIndex : info.LessonNum + 1; //如果下一课时数大于当前课时,则不更改.否则改为当前课时的下一课时序号 if (courseProgress.Yps_IsFinished && courseProgress.Yps_FinishStudyTime == new DateTime(1900, 1, 1)) //如果课程进度完成,且完成时间不为初始值,则修改此时间 { courseProgress.Yps_FinishStudyTime = DateTime.Now; } courseProgress.Yps_UpdateTime = DateTime.Now; //更新时间 ScpRepository.Update(courseProgress); //更新课程进度 } } StuLesProgressRepository.Update(progress);//更新课时数据 string cardJson = "", coinJson = ""; //添加错题数据 if (card != null) { cardJson = $",{JsonConvert.SerializeObject(card)}"; new StudentWrongBookBll().SaveWrongBook(new List <StudentAnswerCard> { card }, new DtoStudentWrongBook { CourseId = progress.Yle_CourseId, LessonId = progress.Yle_LessonId, LessonProgressId = progress.Yle_Id, Source = StudyWrongSourceEnum.课程学习, StudentId = progress.Yle_StudentId, StudyTaskId = 0 }); } //需要修改学生金币数量及经验 if (coinRecord != null) { coinJson = $",{JsonConvert.SerializeObject(coinRecord)}"; new StudentInfoBll().AddCoins(info.StudnetId, coinRecord.TotalCoins); } //更新学生课时答题结果表 if (card != null || coinRecord != null) { StuLessonAnsRepository.Update(info.ProgressID, cardJson, coinJson); } #endregion scope.Complete(); } catch (Exception ex) { RollbackTran(); throw ex; } } #endregion StudentStudyBll ssbll = new StudentStudyBll(); ssbll.PublishStudyMessage(progress.Yle_CourseId, progress.Yle_LessonId, progress.Yle_StudentId, info.UseTime, progress.Yle_SubjectCount, progress.Yle_GainCoins); if (progress.Yle_IsFinished) { ssbll.PublishLessonFinishMessage(progress.Yle_StudentId, progress.Yle_Id); } return(0);//表示成功 } } } else { return(-1);//表示课时进度秘钥错误,及在其他地方打开了这个课程学习 } }
public Yw_StudentLessonAnswerExt MakeTranslator(Yw_StudentLessonAnswer entity) { Yw_StudentLessonAnswerExt realEntity = entity.ConvertTo <Yw_StudentLessonAnswerExt>(); if (!string.IsNullOrEmpty(entity.Yla_StudentAnswer)) { realEntity.Yla_Answer_Obj = new List <StudentAnswerCard>(); JArray arr = JsonConvert.DeserializeObject($"[{entity.Yla_StudentAnswer.Trim(',')}]") as JArray;//数据库存储时没有数组的括号,并且两边可能会有","需要去除 foreach (var o in arr) { StudentAnswerCard card = new StudentAnswerCard(); card.UseTime = Convert.ToInt32(o["UTim"]); card.SubmitTime = o["STim"].ToString(); card.TotalStars = Convert.ToInt32(o["EStar"]); card.TotalCoins = Convert.ToInt32(o["TCoin"]); card.Part = Convert.ToInt32(o["Part"]); JArray answers = JsonConvert.DeserializeObject(o["Anws"].ToString()) as JArray; foreach (var a in answers) { #region 根据类型添加不同的对象 switch ((SubjectTypeEnum)Convert.ToInt32(a["Type"])) { case SubjectTypeEnum.择题: { card.AnswerCollection.Add(JsonConvert.DeserializeObject <StuSelectAnswer>(a.ToString())); } break; case SubjectTypeEnum.判断题: { card.AnswerCollection.Add(JsonConvert.DeserializeObject <StuTrueFalseAnswer>(a.ToString())); } break; case SubjectTypeEnum.填空题: { card.AnswerCollection.Add(JsonConvert.DeserializeObject <StuBlankAnswer>(a.ToString())); } break; case SubjectTypeEnum.择填空: { card.AnswerCollection.Add(JsonConvert.DeserializeObject <StuSelectBlankAnswer>(a.ToString())); } break; case SubjectTypeEnum.连线题: { card.AnswerCollection.Add(JsonConvert.DeserializeObject <StuMatchAnswer>(a.ToString())); } break; case SubjectTypeEnum.主观题: { card.AnswerCollection.Add(JsonConvert.DeserializeObject <StuFreeAnswer>(a.ToString())); } break; case SubjectTypeEnum.圈点批注标色: { card.AnswerCollection.Add(JsonConvert.DeserializeObject <StuMarkColorAnswer>(a.ToString())); } break; case SubjectTypeEnum.圈点批注断句: { card.AnswerCollection.Add(JsonConvert.DeserializeObject <StuMarkCutAnswer>(a.ToString())); } break; } #endregion } realEntity.Yla_Answer_Obj.Add(card); } } if (!string.IsNullOrEmpty(entity.Yla_StudentCoin)) { realEntity.Yla_StudentCoin_Obj = new List <StuLessonCoinRecord>(); JArray arr = JsonConvert.DeserializeObject($"[{entity.Yla_StudentCoin.Trim(',')}]") as JArray; //数据库存储时没有数组的括号,并且两边可能会有","需要去除 foreach (var o in arr) { StuLessonCoinRecord coin = new StuLessonCoinRecord(); coin.UseTime = Convert.ToInt32(o["UTim"]); coin.SubmitTime = o["STim"].ToString(); coin.TotalCoins = Convert.ToInt32(o["TCon"]); coin.Part = Convert.ToInt32(o["Part"]); coin.CoinCollection = new List <StuLessonCoinItem>(); JArray items = JsonConvert.DeserializeObject(o["Cons"].ToString()) as JArray; foreach (var i in items) { coin.CoinCollection.Add(JsonConvert.DeserializeObject <StuLessonCoinItem>(i.ToString())); } realEntity.Yla_StudentCoin_Obj.Add(coin); } } return(realEntity); }