/// <summary>
        /// 根据学生id课程id及课时id,分页查询课时单元信息
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        public List <DtoLessonUnit> SelectUnitByNext(DtoLessonUnitSearch search)
        {
            StudentStudyBll bll = new StudentStudyBll();

            //如果学生有这个课程进度
            if (bll.GetProgressByStudentCourse(search.StudentID, search.CourseID) != null)
            {
                //获取课时单元信息数据并转换成动作对象
                var list = UnitServer.SelectUnitsByNext(search).Select(u => (Yw_LessonUnitStepActions)UnitStepFactory.Create(u)).ToList();
                //将数据转换成为dto模型
                return(list.Select(u => new DtoLessonUnit()
                {
                    CourseId = u.Yls_CourseId,
                    LessonId = u.Yls_LessonId,
                    Id = u.Yls_UnitId,
                    Index = u.Yls_UnitIndex,
                    Coins = u.Yls_Coins,
                    Steps = u.Steps,
                    Status = u.Yls_Status,
                    CreateTime = u.Yls_CreateTime,
                    UpdateTime = u.Yls_UpdateTime
                }).ToList());
            }
            return(new List <DtoLessonUnit>());
        }
        /// <summary>
        /// 学生完成课时学习后,创建课后任务
        /// </summary>
        public Yw_StudentTask CreateTaskAutoAfterStudy(int studentId, int lesProgressId)
        {
            StudentStudyBll          studyBll    = new StudentStudyBll();
            Yw_StudentLessonProgress lesProgress = studyBll.GetStuLessonProgressById(lesProgressId);

            if (lesProgress.Yle_Percent < 100 && lesProgress.Yle_SubjectCount > 0)//学生课时学习中,如果题目全部作对,就不创建课后任务
            {
                Yw_StudentCourseProgress progress = studyBll.GetProgressByStudentCourse(studentId, lesProgress.Yle_CourseId);
                return(CreateStudyPractice(progress, studentId, lesProgress.Yle_LessonId, lesProgress.Yle_LessonIndex, lesProgressId, null, StudyTaskTypeEnum.系统课后任务));
            }
            return(null);
        }
        /// <summary>
        /// 生成课后练习,根据学生已学的课程的课时,随机组题排除最近学生已经练习的题目
        /// </summary>
        public Yw_StudentTask GeneratePractice(int studentId, int courseId, int returnCount)
        {
            SubjectBll      subjectBll = new SubjectBll();
            StudentStudyBll studyBll   = new StudentStudyBll();

            Yw_StudentCourseProgress progress = studyBll.GetProgressByStudentCourse(studentId, courseId);

            if (progress != null && progress.Yps_NextLessonIndex > 1)
            {
                List <Yw_Subject> subjects = subjectBll.GetSubjectForPractice(studentId, courseId, progress.Yps_NextLessonIndex, returnCount);
                if (subjects.Count > 0)
                {
                    var task = CreateStudyPractice(progress, studentId, 0, progress.Yps_NextLessonIndex, 0, subjects.OrderBy(x => x.Ysj_SubjectType).Select(x => x.Ysj_Id).ToList(), StudyTaskTypeEnum.课后练习);
                    return(task);
                }
            }
            return(null);
        }
Exemple #4
0
        public bool SaveWrongBook(List <StudentAnswerCard> answerCard, DtoStudentWrongBook wrongBook)
        {
            bool result       = false;
            var  studyProcess = StudentStudyBll.GetProgressByStudentCourse(wrongBook.StudentId, wrongBook.CourseId);
            int  schoolId     = studyProcess == null ? 0 : studyProcess.Yps_SchoolId;
            int  classId      = studyProcess == null ? 0 : studyProcess.Yps_ClassId;
            List <StudentAnswerBase>      answers     = answerCard.SelectMany(s => s.AnswerCollection).ToList();
            List <Yw_StudentWrongSubject> listSubject = new List <Yw_StudentWrongSubject>();

            if (answers.Any(s => s.SubjectId <= 0))
            {
                throw new AbhsException(ErrorCodeEnum.ParameterInvalid, AbhsErrorMsg.ConstParameterInvalid);
            }
            answers.ForEach(a =>
            {
                if (CheckAnswerNeedRecordWorng(a))
                {
                    Yw_StudentWrongSubjectExt tmp = new Yw_StudentWrongSubjectExt();
                    tmp.Yws_CourseId       = wrongBook.CourseId;
                    tmp.Yws_CreateTime     = DateTime.Now;
                    tmp.Yws_KnowledgeId    = a.KnowledgeId;
                    tmp.Yws_LessonId       = wrongBook.LessonId;
                    tmp.Yws_RemoveTryCount = 0;
                    tmp.Yws_Source         = (int)wrongBook.Source;
                    tmp.Yws_Status         = (int)StudyWrongStatusEnum.未消除;
                    tmp.Yws_Answer_Obj     = a;
                    tmp.Yws_StudentId      = wrongBook.StudentId;
                    tmp.Yws_SubjectType    = a.Type;
                    tmp.Yws_UpdateTime     = DateTime.Now;
                    tmp.Yws_WrongBookId    = 0;
                    tmp.Yws_WrongSubjectId = a.SubjectId;

                    listSubject.Add(tmp);
                }
            });
            if (listSubject.Count == 0)
            {
                return(true);
            }
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    Yw_StudentWrongBook bookModel = GetBookByStudentAndStudy(wrongBook.StudentId, wrongBook.CourseId, wrongBook.LessonId, wrongBook.LessonProgressId, wrongBook.StudyTaskId);
                    bool saveSubject         = false;
                    bool saveBook            = false;
                    int  WrongCount          = 0;
                    int  WrongKnowledgeCount = 0;

                    #region 获取要插入的错题及错题数的计算
                    if (bookModel != null)
                    {
                        List <Yw_StudentWrongSubject> oldSubjectList = GetSubjectByBookId(bookModel.Ywb_Id);
                        listSubject = listSubject.ExceptExt(oldSubjectList, l => l.Yws_WrongSubjectId)
                                      //.Where(s =>
                                      // {
                                      //     return !oldSubjectList.Exists(o => o.Yws_WrongSubjectId == s.Yws_WrongSubjectId);
                                      // })
                                      .Select(s => s)
                                      .ToList();
                        WrongCount          = bookModel.Yws_WrongCount + listSubject.Select(s => s.Yws_WrongSubjectId).Distinct().Count();
                        WrongKnowledgeCount = (from o in oldSubjectList
                                               where o.Yws_Status == (int)StudyWrongStatusEnum.未消除 && o.Yws_KnowledgeId > 0
                                               select o.Yws_KnowledgeId)
                                              .Concat(from n in listSubject where n.Yws_KnowledgeId > 0 select n.Yws_KnowledgeId)
                                              .Distinct().Count();
                    }
                    else
                    {
                        WrongCount          = listSubject.Select(s => s.Yws_WrongSubjectId).Distinct().Count();
                        WrongKnowledgeCount = listSubject.Where(s => s.Yws_KnowledgeId > 0).Select(s => s.Yws_KnowledgeId).Distinct().Count();
                    }
                    #endregion

                    #region save错题本
                    if (bookModel != null)
                    {
                        bookModel.Yws_WrongCount          = WrongCount;
                        bookModel.Yws_WrongKnowledgeCount = WrongKnowledgeCount;
                        bookModel.Yws_UpdateTime          = DateTime.Now;
                        saveBook = StudentWrongBookRepository.Update(bookModel);
                    }
                    else
                    {
                        bookModel = new Yw_StudentWrongBook();
                        bookModel.Ywb_CourseId            = wrongBook.CourseId;
                        bookModel.Ywb_LessonId            = wrongBook.LessonId;
                        bookModel.Ywb_LessonProgressId    = wrongBook.LessonProgressId;
                        bookModel.Ywb_StudentId           = wrongBook.StudentId;
                        bookModel.Ywb_StudyTaskId         = wrongBook.StudyTaskId;
                        bookModel.Yws_ClassId             = classId;
                        bookModel.Yws_CreateTime          = DateTime.Now;
                        bookModel.Yws_RemoveCount         = 0;
                        bookModel.Yws_SchoolId            = schoolId;
                        bookModel.Yws_Source              = (int)wrongBook.Source;
                        bookModel.Yws_Status              = (int)StudyWrongStatusEnum.未消除;
                        bookModel.Yws_UpdateTime          = DateTime.Now;
                        bookModel.Yws_WrongCount          = WrongCount;
                        bookModel.Yws_WrongKnowledgeCount = WrongKnowledgeCount;
                        bookModel.Ywb_Id = StudentWrongBookRepository.Insert(bookModel);
                        saveBook         = bookModel.Ywb_Id > 0;
                    }
                    listSubject.ForEach(s => s.Yws_WrongBookId = bookModel.Ywb_Id);
                    #endregion

                    #region save错题详情
                    saveSubject = InsertSubjectList(listSubject);
                    #endregion
                    result = saveBook && saveSubject;
                    if (result)
                    {
                        scope.Complete();
                    }
                    else
                    {
                        RollbackTran();
                    }
                }
                catch (Exception)
                {
                    RollbackTran();
                    throw;
                }
            }

            return(result);
        }