EducationSchedulingClassServices.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq.Entity;
  6. using EMIS.ViewModel.EducationManage;
  7. using EMIS.ViewModel;
  8. using System.Linq.Expressions;
  9. using EMIS.Entities;
  10. using EMIS.DataLogic.EducationManage;
  11. using EMIS.CommonLogic.SchedulingManage.ScheduleApproval;
  12. using EMIS.Utility.FormValidate;
  13. using EMIS.ViewModel.EducationSchedule;
  14. using EMIS.ViewModel.SchedulingManage.ScheduleApproval;
  15. namespace EMIS.CommonLogic.EducationManage
  16. {
  17. public class EducationSchedulingClassServices : BaseServices, IEducationSchedulingClassServices
  18. {
  19. public EducationSchedulingClassDAL EducationSchedulingClassDAL { get; set; }
  20. public Lazy<ICollegeScheduleApprovalServices> CollegeScheduleApprovalServices { get; set; }
  21. /// <summary>
  22. /// 获取完整结构的任务班视图的方法,主要是要组合教师列表和上课周列表
  23. /// </summary>
  24. /// <param name="configuretView"></param>
  25. /// <param name="exp"></param>
  26. /// <param name="resultExp"></param>
  27. /// <param name="dataRangeFunc"></param>
  28. /// <param name="pageIndex"></param>
  29. /// <param name="pageSize"></param>
  30. /// <returns></returns>
  31. public IGridResultSet<EducationSchedulingClassScheduleView> GetEducationSchedulingClassView(ConfiguretView configuretView,
  32. Expression<Func<EM_EducationSchedulingClass, bool>> exp,
  33. Expression<Func<EducationSchedulingClassScheduleView, bool>> resultExp = null,
  34. Func<IQueryable<EducationSchedulingClassScheduleView>, Expression<Func<EducationSchedulingClassScheduleView, Guid?>>,
  35. IQueryable<EducationSchedulingClassScheduleView>> dataRangeFunc = null,
  36. int? pageIndex = null, int? pageSize = null)
  37. {
  38. var educationSchedulingClassViewQueryable = EducationSchedulingClassDAL.GetEducationSchedulingClassViewQueryable(exp);
  39. var classMajorQueryable = EducationSchedulingClassDAL.GetClassmajorQueryable(exp);
  40. var teacherViewQueryable = EducationSchedulingClassDAL.GetTeacherViewQueryable(exp);
  41. var educationMissionClassSettingQueryable = EducationSchedulingClassDAL.GetEducationMissionClassSettingQueryable(exp);
  42. var courseProcessQueryable = EducationSchedulingClassDAL.GetCourseProcessViewQueryable(exp);
  43. var courseProcessTeacherQueryable = this.EducationSchedulingClassDAL.GetCourseProcessTeacherViewQueryable(exp);
  44. if (resultExp != null)
  45. {
  46. educationSchedulingClassViewQueryable = educationSchedulingClassViewQueryable.Where(resultExp);
  47. }
  48. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  49. {
  50. educationSchedulingClassViewQueryable = educationSchedulingClassViewQueryable
  51. .DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  52. }
  53. if (dataRangeFunc != null)
  54. {
  55. educationSchedulingClassViewQueryable = dataRangeFunc
  56. .Invoke(educationSchedulingClassViewQueryable, null);
  57. }
  58. IGridResultSet<EducationSchedulingClassScheduleView> result;
  59. List<EducationMissionClassTeacherListView> teacherViewList;
  60. List<EM_EducationMissionClassSettings> educationMissionClassSettingList;
  61. List<EducationMissionClassContainClassView> classMajorList;
  62. List<CourseProcessView> courseProcessList;
  63. var startStatus = CollegeScheduleApprovalServices.Value.GetStartStatus();
  64. var collegeScheduleApprovalViewList = new List<CollegeScheduleApprovalView>();
  65. if (pageIndex.HasValue && pageSize.HasValue)
  66. {
  67. result = educationSchedulingClassViewQueryable.OrderBy(x => x.EducationMissionClassOrderNo)
  68. .ToGridResultSet(pageIndex, pageSize);
  69. //var isCanApprove = CollegeScheduleApprovalServices.Value.IsCanApprove(collegeStatus.CollegeScheduleStatusID, CustomPrincipal.Current.UserID);
  70. collegeScheduleApprovalViewList = CollegeScheduleApprovalServices.Value.GetCollegeScheduleApprovalViewList(
  71. result.rows.GroupBy(x => new { x.CourseCollegeID, x.SchoolYearID })
  72. .Select(x => new CollegeSchoolyearView { CollegeID = x.Key.CourseCollegeID.Value, SchoolyearID = x.Key.SchoolYearID.Value }).ToList()
  73. );
  74. //由于分页后数据量较少,可以考虑用Contains方法在数据库端筛选一下,不分页的情况就不要了
  75. var educationMissionClassIDList = result.rows.Select(x => x.EducationMissionClassID).ToList();
  76. teacherViewList = teacherViewQueryable.Where(x => educationMissionClassIDList.Contains(x.EducationMissionClassID)).ToList();
  77. classMajorList = classMajorQueryable.Where(x => educationMissionClassIDList.Contains(x.EducationMissionClassID)).ToList();
  78. educationMissionClassSettingList = educationMissionClassSettingQueryable
  79. .Where(x => educationMissionClassIDList.Contains(x.EducationMissionClassID)).ToList();
  80. courseProcessList = courseProcessQueryable.Where(x => educationMissionClassIDList.Contains(x.EducationMissionClassID)).ToList();
  81. var courseProcessTeacherViewList = courseProcessTeacherQueryable.Where(x => educationMissionClassIDList.Contains(x.EducationMissionClassID)).Distinct().ToList();
  82. courseProcessList.ForEach(x => x.CourseProcessTeacherViewList = courseProcessTeacherViewList.Where(w => w.CourseProcessID == x.CourseProcessID)
  83. .OrderBy(w => w.TeachingMethod).ThenBy(w => w.Name).ToList());
  84. }
  85. else
  86. {
  87. var list = educationSchedulingClassViewQueryable.ToList();
  88. result = new GridResultSet<EducationSchedulingClassScheduleView>() { rows = list, total = list.Count };
  89. collegeScheduleApprovalViewList = CollegeScheduleApprovalServices.Value.GetCollegeScheduleApprovalViewList(
  90. result.rows.GroupBy(x => new { x.CourseCollegeID, x.SchoolYearID })
  91. .Select(x => new CollegeSchoolyearView { CollegeID = x.Key.CourseCollegeID.Value, SchoolyearID = x.Key.SchoolYearID.Value }).ToList()
  92. );
  93. teacherViewList = teacherViewQueryable.ToList();
  94. classMajorList = classMajorQueryable.ToList();
  95. educationMissionClassSettingList = educationMissionClassSettingQueryable.ToList();
  96. courseProcessList = courseProcessQueryable.ToList();
  97. var courseProcessTeacherViewList = courseProcessTeacherQueryable.Distinct().ToList();
  98. courseProcessList.ForEach(x => x.CourseProcessTeacherViewList = courseProcessTeacherViewList.Where(w => w.CourseProcessID == x.CourseProcessID)
  99. .OrderBy(w => w.TeachingMethod).ThenBy(w => w.Name).ToList());
  100. }
  101. var submitedCollegeScheduleApprovalViewList = collegeScheduleApprovalViewList.Where(x => x.CollegeScheduleStatusID.HasValue).ToList();
  102. result.rows.ForEach(x =>
  103. {
  104. var collegeScheduleApprovalView = submitedCollegeScheduleApprovalViewList.FirstOrDefault(w => w.CollegeID == x.CourseCollegeID && w.SchoolyearID == x.SchoolYearID);
  105. x.TeacherTeachingViewList = teacherViewList
  106. .Where(w => x.EducationMissionClassID == w.EducationMissionClassID)
  107. .Select(w => (BaseTeacherTeachingView)w)
  108. .OrderBy(w => w.TeachingMethod).ThenBy(w => w.Name).ToList();
  109. x.WeeklyNumList = educationMissionClassSettingList.Where(w => x.EducationMissionClassID == w.EducationMissionClassID)
  110. .Select(w => w.WeeklyNum).Distinct().ToList();
  111. x.ClassMajorIDList = classMajorList.Where(w => x.EducationMissionClassID == w.EducationMissionClassID)
  112. .Select(w => w.ClassMajor.ClassmajorID).Distinct().ToList();
  113. x.CourseProcessViewList = courseProcessList.Where(w => x.EducationMissionClassID == w.EducationMissionClassID).ToList();
  114. x.IsCanEdit = x.IsCanEdit && (collegeScheduleApprovalView == null || collegeScheduleApprovalView.RecordStatus == startStatus);
  115. });
  116. return result;
  117. }
  118. public List<EducationSchedulingClassScheduleView> GetEducationSchedulingClassViewList(Guid schoolYearID, IList<Guid?> collegeIDList)
  119. {
  120. return this.GetEducationSchedulingClassView(new ConfiguretView(),
  121. (x => collegeIDList.Contains(x.EM_EducationMissionClass.EM_EducationMission.CF_Department.CollegeID)
  122. && x.EM_EducationMissionClass.EM_EducationMission.SchoolyearID == schoolYearID
  123. && x.EM_EducationMissionClass.RecordStatus != (int)EM_EducationMissionClassStatus.NotSubmitted
  124. )).rows;
  125. }
  126. public List<EducationSchedulingClassStudentView> GetEducationSchedulingClassStudentViewList(Guid schoolYearID, IList<Guid?> collegeIDList)
  127. {
  128. return EducationSchedulingClassDAL.GetEducationSchedulingClassStudentViewQueryable((x => collegeIDList.Contains(x.EM_EducationMissionClass.EM_EducationMission.CF_Department.CollegeID)
  129. && x.EM_EducationMissionClass.EM_EducationMission.SchoolyearID == schoolYearID
  130. && x.EM_EducationMissionClass.RecordStatus != (int)EM_EducationMissionClassStatus.NotSubmitted
  131. )).ToList();
  132. }
  133. public List<EducationSchedulingClassScheduleView> GetEducationSchedulingClassViewList(Guid schoolYearID, Guid classMajorID)
  134. {
  135. return this.GetEducationSchedulingClassView(new ConfiguretView(),
  136. (x => x.EM_EducationMissionClass.CF_Classmajor.Any(w => w.ClassmajorID == classMajorID)
  137. && x.EM_EducationMissionClass.EM_EducationMission.SchoolyearID == schoolYearID
  138. && x.EM_EducationMissionClass.RecordStatus != (int)EM_EducationMissionClassStatus.NotSubmitted), null,
  139. this.GetQueryByDataRangeByDepartment).rows;
  140. }
  141. public List<EducationSchedulingClassScheduleView> GetDepartmentEducationSchedulingClassViewList(Guid schoolYearID, Guid departmentID, IList<int?> handleModeList)
  142. {
  143. return this.GetEducationSchedulingClassView(new ConfiguretView(),
  144. (x => x.EM_EducationMissionClass.EM_EducationMission.DepartmentID == departmentID
  145. && x.EM_EducationMissionClass.EM_EducationMission.SchoolyearID == schoolYearID
  146. && handleModeList.Contains(x.EM_EducationMissionClass.HandleModeID)
  147. && x.EM_EducationMissionClass.RecordStatus != (int)EM_EducationMissionClassStatus.NotSubmitted), null,
  148. this.GetQueryByDataRangeByDepartment).rows;
  149. }
  150. public EducationSchedulingClassScheduleView GetEducationSchedulingClassView(Guid educationSchedulingClassID)
  151. {
  152. return this.GetEducationSchedulingClassView(new ConfiguretView(),
  153. (x => x.EducationSchedulingClassID == educationSchedulingClassID)).rows.FirstOrDefault();
  154. }
  155. }
  156. }