public List <DtoMediaResourceToCourse> GetSubjectToCourse(PagingObject paging, int courseId, int subjectType, string nameOrKey) { SubjectBll subjectBll = new SubjectBll(); List <DtoMediaResourceToCourse> subjectList = new List <DtoMediaResourceToCourse>(); if (!string.IsNullOrEmpty(nameOrKey)) { if (nameOrKey.IsNumberic() && nameOrKey.Length >= 5) { subjectList = subjectBll.SubjectService.GetSubjectToCourseById(paging, subjectType, courseId, nameOrKey._ToInt32()); } else { subjectList = subjectBll.SubjectService.GetSubjectToCourse(paging, courseId, subjectType, nameOrKey); } } else { subjectList = subjectBll.SubjectService.GetSubjectToCourseById(paging, subjectType, courseId, 0); } return(subjectList); //var list = ResourceGroupItemRepository.GetGroupIdAndResourceType(courseId); //var subjectIds = list.Where(s => s.Ygi_ResourceType == (int)ResourceTypeEnum.题目).Select(x => x.Ygi_ResourceId).ToList(); //return subjectBll.SubjectService.GetSubjectToCourse(paging, subjectIds, subjectType, nameOrKey); }
/// <summary> /// 资源组关联题目列表 /// </summary> /// <param name="paging"></param> /// <param name="grade"></param> /// <param name="mediaType"></param> /// <param name="nameOrKey"></param> /// <returns></returns> public List <Yw_Subject> GetSubjectList(PagingObject paging, int grade, int subjectType, string nameOrKey) { List <Yw_Subject> subjectList = new List <Yw_Subject>(); SubjectBll subjectBll = new SubjectBll(); if (!string.IsNullOrEmpty(nameOrKey)) { if (nameOrKey.IsNumberic() && nameOrKey.Length >= 5) { subjectList = subjectBll.SubjectService.GetPagingSubjectForResourceGroup(paging, grade, subjectType, nameOrKey._ToInt32()).ToList(); } else { var resourceIds = subjectBll.SubjectIndexService.GetPagingSubjectIds(paging, grade, subjectType, nameOrKey).ToList(); //Dictionary<int, int> orderDic = resourceIds.ToOrderDic(); subjectList = subjectBll.SubjectService.GetSubjectsByIds(resourceIds).ToList(); //subjectList = subjectList.OrderBy(x => orderDic[x.Ysj_Id]).ToList(); } } else { subjectList = subjectBll.SubjectService.GetPagingSubjectForResourceGroup(paging, grade, subjectType, nameOrKey._ToInt32()).ToList(); } return(subjectList); }
public void AddSubjectToLesson(Yw_CourseLesson lesson, int subjectId) { Yw_CourseSubjectRelation rel = Repository.GetDirectRelation(lesson.Ycl_Id, subjectId); if (rel == null) { SubjectBll subjectBll = new SubjectBll(); Yw_Subject subject = subjectBll.GetSubject(subjectId); rel = new Yw_CourseSubjectRelation(); rel.Ysr_CourseId = lesson.Ycl_CourseId; rel.Ysr_CreateTime = DateTime.Now; rel.Ysr_DirectSubjectId = 0; rel.Ysr_IsDirect = true; rel.Ysr_LessonId = lesson.Ycl_Id; rel.Ysr_LessonIndex = lesson.Ycl_Index; rel.Ysr_SubjectId = subjectId; rel.Ysr_SubjectType = subject.Ysj_SubjectType; Repository.Add(rel); SubjectGroupBll groupBll = new SubjectGroupBll(); Yw_SubjectGroup group = groupBll.GetBySubjectId(subjectId); if (group != null && !string.IsNullOrEmpty(group.Ysg_RelSubjectId)) { int[] subjectIds = group.Ysg_RelSubjectId.Split(',').Select(x => Convert.ToInt32(x)).ToArray(); Repository.CreateInDirectRelation(rel.Ysr_Id, subjectIds); } } }
public void CancelRelation(int subjectId, int relationSubjectId) { using (TransactionScope scope = new TransactionScope()) { try { var subjectBll = new SubjectBll(); var subjects = subjectBll.GetSubjectsByIds( new List <int> { subjectId, relationSubjectId }); foreach (var subject in subjects) { subject.EnableAudit(); subject.Ysj_GroupItemCount = subject.Ysj_GroupItemCount - 1; subjectBll.UpdateSubject(subject); } int[] ids = new int[2] { subjectId, relationSubjectId }; IList <Yw_SubjectGroup> subjectGroups = GetBySubjectIds(ids); if (subjectGroups.Count != 2) { throw new AbhsException( ErrorCodeEnum.RelationOutOfRange, AbhsErrorMsg.RelationOutOfRange); } foreach (var item in subjectGroups) { item.EnableAudit(); string pattern = string.Empty; string relSubjectId = item.Ysg_RelSubjectId; relSubjectId = "," + relSubjectId + ","; if (item.Ysg_SubjectId == subjectId) { pattern = "," + relationSubjectId + ","; } else { pattern = "," + subjectId + ","; } relSubjectId = relSubjectId.Replace(pattern, ",").Trim(','); item.Ysg_RelSubjectId = relSubjectId.Replace(pattern, ","); SubjectGroupRepository.Update(item); } scope.Complete(); } catch { RollbackTran(); throw; } } new CourseSubjectRelBll().RemoveSubjectFromGroup(subjectId, relationSubjectId); }
/// <summary> /// 返回题目(获取题目难度) /// </summary> /// <param name="ids"></param> /// <returns></returns> public List <Yw_Subject> GetSubjects(List <int> ids) { List <Yw_Subject> subjects = new List <Yw_Subject>(); SubjectBll subjectBll = new SubjectBll(); subjects = subjectBll.GetByIds(ids); return(subjects); }
/// <summary> /// 返回练习报告的题目 /// </summary> public List <Yw_SubjectContent> GetTaskSubject(List <int> subjectIds) { List <Yw_SubjectContent> subjectContents = new List <Yw_SubjectContent>(); SubjectBll subjectBll = new SubjectBll(); subjectContents = subjectBll.GetSubjectContents(subjectIds); return(subjectContents); }
/// <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); }
/// <summary> /// 分批次返回课后任务的题目,每次返回10个题目数据 /// </summary> public List <DtoSubjectContent> GetTaskSubject(int studyTaskId, int pageIndex, out int totalCount) { List <DtoSubjectContent> subjectContents = new List <DtoSubjectContent>(); Yw_StudyTask task = StudyTaskRepository.Get(studyTaskId); string[] ids = task.Ysk_SubjectIds.Split(','); totalCount = ids.Length; if ((pageIndex - 1) * 10 < ids.Length) { var pageIds = ids.Skip((pageIndex - 1) * 10).Take(10).ToList(); Dictionary <string, int> orderDic = pageIds.ToOrderDic(); SubjectBll subjectBll = new SubjectBll(); subjectContents = subjectBll.GetCompleteContentsOfSubject( pageIds.Select(x => Convert.ToInt32(x))).ToList(); subjectContents = subjectContents.OrderBy(x => orderDic[x.SubjectId.ToString()]).ToList(); } return(subjectContents); }
/// <summary> /// 将一组题目加入到课时,题目与课时建立直接关系,题目的关联题目与课时建立间接关系 /// </summary> /// <param name="lesson"></param> /// <param name="subjectId"></param> public void AddSubjectToLesson(Yw_CourseLesson lesson, List <int> subjectIds) { List <int> newSubjectIds = subjectIds.Distinct().ToList(); List <Yw_CourseSubjectRelation> existingRel = Repository.GetDirectRelationsOfLesson(lesson.Ycl_Id); List <int> existingSubIds = existingRel.Select(x => x.Ysr_SubjectId).ToList(); List <int> deletedIds = existingSubIds.Except(newSubjectIds).ToList(); List <int> addIds = newSubjectIds.Except(existingSubIds).ToList(); if (addIds.Count > 0) { Dictionary <int, int[]> dic = GetGroupDictionary(addIds); IEnumerable <int> tempSubjectIds = GetAllItemOfDictionary(dic); SubjectBll bll = new SubjectBll(); List <Yw_Subject> subjects = bll.GetByIds(tempSubjectIds.ToList()); Dictionary <int, Yw_Subject> subDic = subjects.ToDictionary(x => x.Ysj_Id, x => x); DataTable table = BuildBulkTable(); foreach (KeyValuePair <int, int[]> pair in dic) { if (subDic.ContainsKey(pair.Key)) { BuildBulkRow(table, lesson.Ycl_CourseId, lesson.Ycl_Id, lesson.Ycl_Index, pair.Key, subDic[pair.Key].Ysj_SubjectType, true, pair.Key); } foreach (int id in pair.Value) { if (subDic.ContainsKey(id)) { BuildBulkRow(table, lesson.Ycl_CourseId, lesson.Ycl_Id, lesson.Ycl_Index, id, subDic[id].Ysj_SubjectType, false, pair.Key); } } } Repository.AddBatch(table); } if (deletedIds.Count > 0) { Repository.DeleteDirectRelationOfLesson(lesson.Ycl_Id, deletedIds); } }
public List <DtoResourceGroupItem> GetResourceGroupItem(PagingObject paging, int groupid, int resouceType) { List <DtoResourceGroupItem> groupItems = new List <DtoResourceGroupItem>(); var resourceIds = ResourceGroupItemRepository.GetResourceIdByTypeAndGroupId(groupid, resouceType).Select(s => s.Ygi_ResourceId).ToList(); if (resouceType == (int)ResourceTypeEnum.多媒体资源) { groupItems = MediaResourceRepository.GetMediaForGroupItem(paging, resourceIds); } else if (resouceType == (int)ResourceTypeEnum.文本资源) { groupItems = TextResourceRepository.GetTextForGroupItem(paging, resourceIds); } else if (resouceType == (int)ResourceTypeEnum.题目) { SubjectBll subjectBll = new SubjectBll(); groupItems = subjectBll.SubjectService.GetSubjectForGroupItem(paging, resourceIds); } return(groupItems); }
/// <summary> /// 添加题目到题目组,A,B两个题目互为主副关系。A如果与某些课时有直接关联关系,就要创建B与该课时的间接关联关系;同理B也一样。 /// </summary> /// <param name="subjectId"></param> /// <param name="targetSubjectId"></param> public void AddSubjectToGroup(int subjectId, int targetSubjectId) { SubjectBll subjectBll = new SubjectBll(); Yw_Subject subject = subjectBll.GetSubject(subjectId); Yw_Subject targetSubject = subjectBll.GetSubject(targetSubjectId); using (TransactionScope scope = new TransactionScope()) { try { Repository.AddSubjectToGroup(subjectId, subject.Ysj_SubjectType, targetSubjectId); Repository.AddSubjectToGroup(targetSubjectId, targetSubject.Ysj_SubjectType, subjectId); scope.Complete(); } catch { RollbackTran(); throw; } } }
/// <summary> /// 学生开始课后任务,生成题目 /// </summary> public void GenerateTaskSubjectsAutoAfterStudy(int studyTaskId, int studentId) { StudentStudyBll studyBll = new StudentStudyBll(); SubjectBll subjectBll = new SubjectBll(); Yw_StudyTask task = StudyTaskRepository.Get(studyTaskId); Yw_StudentTask stuTask = StudentTaskRepository.GetByStudentTask(studentId, studyTaskId); if (task == null || stuTask == null) { return; } Yw_StudentLessonAnswerExt answer = studyBll.GetLessonAnswer(task.Ysk_LessonProgressId) as Yw_StudentLessonAnswerExt; if (answer == null) { return; } 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 = subjectBll.GetLessonTaskSubject(task.Ysk_LessonId, errorSubjects); 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) { task.Ysk_SubjectIds = string.Join(",", subjectSelected.OrderBy(x => x.Value.SubjectType).Select(x => x.Value.SubjectId)); task.Ysk_SubjectCount = subjectSelected.Count; task.Ysk_Score = 5 * subjectSelected.Count; StudyTaskRepository.Update(task); stuTask.Yuk_SubjectCount = subjectSelected.Count; StudentTaskRepository.Update(stuTask); } }
public void AddRelation(int subjectId, int relationSubjectId, int currentUser) { using (TransactionScope scope = new TransactionScope()) { try { if (subjectId == relationSubjectId) { throw new AbhsException( ErrorCodeEnum.CanNotAddRelationToSelf, AbhsErrorMsg.CanNotAddRelationToSelf); } var subjectBll = new SubjectBll(); var subjects = subjectBll.GetSubjectsByIds( new List <int> { subjectId, relationSubjectId }); foreach (var subject in subjects) { subject.EnableAudit(); subject.Ysj_GroupItemCount = subject.Ysj_GroupItemCount + 1; subjectBll.UpdateSubject(subject); } var subjectGroup = SubjectGroupRepository.GetBySubjectId(subjectId); if (subjectGroup == null) { subjectGroup = new Yw_SubjectGroup { Ysg_SubjectId = subjectId, Ysg_RelSubjectId = relationSubjectId.ToString(), Ysg_CreateTime = Clock.Now, Ysg_Creator = currentUser, Ysg_UpdateTime = Clock.Now, Ysg_Editor = currentUser }; SubjectGroupRepository.Insert(subjectGroup); } else { if (subjectGroup.Ysg_RelSubjectId.Contains(relationSubjectId.ToString())) { throw new AbhsException( ErrorCodeEnum.CanNotAddRelation, AbhsErrorMsg.CanNotAddRelation); } subjectGroup.Ysg_RelSubjectId = subjectGroup.Ysg_RelSubjectId + "," + relationSubjectId.ToString(); SubjectGroupRepository.Update(subjectGroup); } var subjectGroup2 = SubjectGroupRepository.GetBySubjectId(relationSubjectId); if (subjectGroup2 == null) { subjectGroup2 = new Yw_SubjectGroup { Ysg_SubjectId = relationSubjectId, Ysg_RelSubjectId = subjectId.ToString(), Ysg_CreateTime = Clock.Now, Ysg_Creator = currentUser, Ysg_UpdateTime = Clock.Now, Ysg_Editor = currentUser }; SubjectGroupRepository.Insert(subjectGroup2); } else { subjectGroup2.Ysg_RelSubjectId = subjectGroup2.Ysg_RelSubjectId + "," + subjectId.ToString(); SubjectGroupRepository.Update(subjectGroup2); } scope.Complete(); } catch { RollbackTran(); throw; } } new CourseSubjectRelBll().AddSubjectToGroup(subjectId, relationSubjectId); }