/// <summary> /// 生成新的学习进度数据 /// </summary> /// <param name="studentId">学生id</param> /// <param name="courseId">课程id</param> /// <param name="lessonId">课时id</param> /// <returns></returns> public Yw_StudentLessonProgress GetNewProgressByStudent(int studentId, int courseId, int lessonId) { if (ScpRepository.GetByStudentCourse(studentId, courseId) != null)//如果此学生有此课程 { LessonBll bll = new LessonBll(); var lesson = bll.GetLesson(lessonId); //获取最后一次学习进度 var progress = StuLesProgressRepository.GetLastProgress(studentId, lessonId); //学习进度 var newProgress = new Yw_StudentLessonProgress() { Yle_StudentId = studentId, Yle_CourseId = courseId, Yle_LessonId = lessonId, Yle_LessonIndex = lesson.Ycl_Index, Yle_CreateTime = DateTime.Now, Yle_CoinFromUIndex = 1, Yle_LastStudyTime = DateTime.Now, Yle_StartStudyTime = DateTime.Now, Yle_UnitIndex = 1, Yle_StudySeconds = 0, Yle_IsFinished = false, Yle_IsLastest = true, Yle_key = Guid.NewGuid().ToString("N").ToLower() }; //学生答题记录 var newAnswers = new Yw_StudentLessonAnswer() { Yla_StudentId = studentId, Yla_CourseId = courseId, Yla_LessonId = lessonId, Yla_StudentAnswer = "", Yla_StudentCoin = "" }; if (progress == null)//如果没有学习进度,则重新添加一个学习进度 { StuLesProgressRepository.Insert(newProgress); newAnswers.Yla_LessonProgressId = newProgress.Yle_Id; StuLessonAnsRepository.Insert(newAnswers); } else //否则新增加一个学习进度,并且修改最大金币发放单元 { newProgress.Yle_CoinFromUIndex = progress.Yle_CoinFromUIndex > progress.Yle_UnitIndex ? progress.Yle_CoinFromUIndex : progress.Yle_UnitIndex;//修改最大金币发放单元 StuLesProgressRepository.Insert(newProgress); newAnswers.Yla_LessonProgressId = newProgress.Yle_Id; StuLessonAnsRepository.Insert(newAnswers); } return(newProgress); } return(null); }
/// <summary> /// 获取最新的课时数据,并更新学习进度秘钥 /// </summary> /// <param name="studentId">学生id</param> /// <param name="courseId">课程id</param> /// <param name="lessonId">课时id</param> /// <returns></returns> public Yw_StudentLessonProgress GetLastProgressByStudent(int studentId, int courseId, int lessonId) { var course = ScpRepository.GetByStudentCourse(studentId, courseId); if (course != null) //如果此学生有此课程 { ScpRepository.UpdateStudyTime(course.Yps_Id, DateTime.Now); //更新最后学习时间 LessonBll bll = new LessonBll(); var lesson = bll.GetLesson(lessonId); if (lesson.Ycl_CourseId != courseId || lesson.Ycl_Status != (int)LessonStatusEnum.合格) { return(null); } //如果课时的课程id不一致或课时不是合格状态,则返回空 //获取最后一次学习进度 var progress = StuLesProgressRepository.GetLastProgress(studentId, lessonId); var newProgress = new Yw_StudentLessonProgress { Yle_StudentId = studentId, Yle_CourseId = courseId, Yle_LessonId = lessonId, Yle_LessonIndex = lesson.Ycl_Index, Yle_CreateTime = DateTime.Now, Yle_CoinFromUIndex = 1, Yle_LastStudyTime = DateTime.Now, Yle_StartStudyTime = DateTime.Now, Yle_UnitIndex = 1, Yle_StudySeconds = 0, Yle_IsFinished = false, Yle_IsLastest = true, Yle_key = Guid.NewGuid().ToString("N").ToLower() }; var newAnswers = new Yw_StudentLessonAnswer() { Yla_StudentId = studentId, Yla_CourseId = courseId, Yla_LessonId = lessonId, Yla_StudentAnswer = "", Yla_StudentCoin = "" }; if (progress == null)//如果没有学习进度,则重新添加一个学习进度 { StuLesProgressRepository.Insert(newProgress); newAnswers.Yla_LessonProgressId = newProgress.Yle_Id; StuLessonAnsRepository.Insert(newAnswers); return(newProgress); } else if (progress.Yle_IsFinished) //如果学习进度完成了,则新增加一个学习进度,并且修改最大金币发放单元 { newProgress.Yle_CoinFromUIndex = progress.Yle_CoinFromUIndex > progress.Yle_UnitIndex ? progress.Yle_CoinFromUIndex : progress.Yle_UnitIndex; //修改最大金币发放单元 StuLesProgressRepository.Insert(newProgress); newAnswers.Yla_LessonProgressId = newProgress.Yle_Id; StuLessonAnsRepository.Insert(newAnswers); return(newProgress); } else //如果学习进度没有完成 { progress.Yle_key = StuLesProgressRepository.UpdateKey(progress.Yle_Id);//更新学习进度的秘钥 return(progress); } } return(null); }