EducationMissionClassScheduleServices.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Bowin.Common.Linq;
  5. using System.Linq.Expressions;
  6. using EMIS.Entities;
  7. using EMIS.ViewModel.EducationManagement;
  8. using EMIS.DataLogic.EducationManage;
  9. using Bowin.Common.Linq.Entity;
  10. using EMIS.DataLogic.EducationSchedule;
  11. using EMIS.ViewModel;
  12. using EMIS.DataLogic.SchedulingManage.SchedulingSettings;
  13. namespace EMIS.CommonLogic.EducationSchedule
  14. {
  15. public class EducationMissionClassScheduleServices : BaseServices, IEducationMissionClassScheduleServices
  16. {
  17. public EducationMissionClassDAL educationMissionClassDAL { get; set; }
  18. public EducationMissionClassScheduleDAL educationMissionClassScheduleDAL { get; set; }
  19. public CollegePriorityDAL collegePriorityDAL { get; set; }
  20. /// <summary>
  21. /// 无数据范围限制
  22. /// </summary>
  23. /// <param name="configuretView"></param>
  24. /// <param name="campusID"></param>
  25. /// <param name="collegeID"></param>
  26. /// <param name="schoolyearID"></param>
  27. /// <param name="departmentID"></param>
  28. /// <param name="coursematerialID"></param>
  29. /// <param name="approvalStatus"></param>
  30. /// <param name="teachingModeID"></param>
  31. /// <param name="grademajorID"></param>
  32. /// <param name="gradeYearID"></param>
  33. /// <param name="StandardID"></param>
  34. /// <param name="pageIndex"></param>
  35. /// <param name="pageSize"></param>
  36. /// <returns></returns>
  37. public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.EducationManagement.EducationMissionClassView> GetEducationMissionClassScheduleViewGrid(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? schoolyearID, Guid? departmentID, Guid? coursematerialID, int? approvalStatus, int? teachingModeID, Guid? grademajorID, int? gradeYearID, int? StandardID, int pageIndex, int pageSize)
  38. {
  39. Expression<Func<EM_EducationMissionClass, bool>> exp = (x => true);
  40. Expression<Func<EM_ExecutablePlan, bool>> executablePlanExp = (x => true);
  41. Expression<Func<EM_ExecutableOptionalCourse, bool>> executableOptionalCourseExp = (x => true);
  42. Expression<Func<EM_ExecutableFreeSelectionCouse, bool>> executableFreeSelectionCourseCourseExp = (x => true);
  43. //if(StandardID.HasValue)
  44. //{
  45. // executablePlanExp = executablePlanExp.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == StandardID);
  46. //}
  47. if (campusID.HasValue)
  48. {
  49. exp = exp.And(x => x.EM_EducationMission.CF_College.CampusID == campusID);
  50. }
  51. if (collegeID.HasValue)
  52. {
  53. exp = exp.And(x => x.EM_EducationMission.CollegeID == collegeID);
  54. }
  55. if (departmentID.HasValue)
  56. {
  57. exp = exp.And(x => x.EM_EducationMission.DepartmentID == departmentID);
  58. }
  59. //if (gradeYearID.HasValue)
  60. //{
  61. // //exp = exp.And(x => x.EM_ExecutablePlan.CF_Grademajor.SchoolyearID == gradeYearID);
  62. // executablePlanExp = executablePlanExp.And(x => x.CF_Grademajor.SchoolyearID == gradeYearID);
  63. // executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.CF_Grademajor.SchoolyearID == gradeYearID);
  64. //}
  65. //if (grademajorID.HasValue)
  66. //{
  67. // //exp = exp.And(x => x.EM_ExecutablePlan.GrademajorID == grademajorID);
  68. // executablePlanExp = executablePlanExp.And(x => x.GrademajorID == grademajorID);
  69. // executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.GrademajorID == grademajorID);
  70. //}
  71. if (schoolyearID.HasValue)
  72. {
  73. exp = exp.And(x => x.EM_EducationMission.SchoolyearID == schoolyearID);
  74. }
  75. if (coursematerialID.HasValue)
  76. {
  77. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  78. executablePlanExp = executablePlanExp.And(x => x.CoursematerialID == coursematerialID);
  79. executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.EM_OptionalCoursePlan.CoursematerialID == coursematerialID);
  80. executableFreeSelectionCourseCourseExp = executableFreeSelectionCourseCourseExp.And(x => x.EM_FreeSelectionCouse.CoursematerialID == coursematerialID);
  81. }
  82. if (approvalStatus.HasValue)
  83. {
  84. exp = exp.And(x => x.RecordStatus == approvalStatus);
  85. }
  86. if (teachingModeID.HasValue)
  87. {
  88. exp = exp.And(x => x.TeachingModeID == teachingModeID);
  89. }
  90. var query = educationMissionClassScheduleDAL.GetEducationMissionClassViewQueryble(exp, executablePlanExp,
  91. executableOptionalCourseExp, executableFreeSelectionCourseCourseExp);
  92. if (StandardID.HasValue)
  93. {
  94. query = query.Where(x => x.StandardID == StandardID);
  95. }
  96. if (grademajorID.HasValue)
  97. {
  98. query = query.Where(x => x.GrademajorID == grademajorID);
  99. }
  100. if (gradeYearID.HasValue)
  101. {
  102. query = query.Where(x => x.GradeYearID == gradeYearID);
  103. }
  104. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  105. {
  106. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  107. }
  108. query = this.GetQueryByDataRangeByCollege(query);
  109. var result = query.OrderByDescending(x => x.SchoolyearCode)
  110. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeYearID)
  111. .ThenBy(x => x.StandardID).ThenBy(x => x.CourseName).ThenBy(x => x.OrderNo).ThenBy(x => x.Name)
  112. .ToGridResultSet<EducationMissionClassView>(pageIndex, pageSize);
  113. var educationMissionClassID = result.rows.Select(x => x.EducationMissionClassID).ToList();
  114. var missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).ToList();
  115. result.rows.ForEach(x => x.MissionClassTeacherView = new HashSet<MissionClassTeacherView>(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID)));
  116. return result;
  117. }
  118. public List<EducationMissionClassView> GetEducationMissionClassScheduleViewList(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? schoolyearID, Guid? departmentID, Guid? coursematerialID, int? approvalStatus, int? teachingModeID, Guid? grademajorID, int? gradeYearID)
  119. {
  120. Expression<Func<EM_EducationMissionClass, bool>> exp = (x => true);
  121. Expression<Func<EM_ExecutablePlan, bool>> executablePlanExp = (x => true);
  122. Expression<Func<EM_ExecutableOptionalCourse, bool>> executableOptionalCourseExp = (x => true);
  123. Expression<Func<EM_ExecutableFreeSelectionCouse, bool>> executableFreeSelectionCourseCourseExp = (x => true);
  124. if (campusID.HasValue)
  125. {
  126. exp = exp.And(x => x.EM_EducationMission.CF_College.CampusID == campusID);
  127. }
  128. if (collegeID.HasValue)
  129. {
  130. exp = exp.And(x => x.EM_EducationMission.CollegeID == collegeID);
  131. }
  132. if (departmentID.HasValue)
  133. {
  134. exp = exp.And(x => x.EM_EducationMission.DepartmentID == departmentID);
  135. }
  136. if (gradeYearID.HasValue)
  137. {
  138. //exp = exp.And(x => x.EM_ExecutablePlan.CF_Grademajor.SchoolyearID == gradeYearID);
  139. executablePlanExp = executablePlanExp.And(x => x.CF_Grademajor.GradeID == gradeYearID);
  140. executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.CF_Grademajor.GradeID == gradeYearID);
  141. }
  142. if (grademajorID.HasValue)
  143. {
  144. //exp = exp.And(x => x.EM_ExecutablePlan.GrademajorID == grademajorID);
  145. executablePlanExp = executablePlanExp.And(x => x.GrademajorID == grademajorID);
  146. executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.GrademajorID == grademajorID);
  147. }
  148. if (schoolyearID.HasValue)
  149. {
  150. exp = exp.And(x => x.EM_EducationMission.SchoolyearID == schoolyearID);
  151. }
  152. if (coursematerialID.HasValue)
  153. {
  154. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  155. executablePlanExp = executablePlanExp.And(x => x.CoursematerialID == coursematerialID);
  156. executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.EM_OptionalCoursePlan.CoursematerialID == coursematerialID);
  157. executableFreeSelectionCourseCourseExp = executableFreeSelectionCourseCourseExp.And(x => x.EM_FreeSelectionCouse.CoursematerialID == coursematerialID);
  158. }
  159. if (approvalStatus.HasValue)
  160. {
  161. exp = exp.And(x => x.RecordStatus == approvalStatus);
  162. }
  163. if (teachingModeID.HasValue)
  164. {
  165. exp = exp.And(x => x.TeachingModeID == teachingModeID);
  166. }
  167. var query = educationMissionClassScheduleDAL.GetEducationMissionClassViewQueryble(exp, executablePlanExp,
  168. executableOptionalCourseExp, executableFreeSelectionCourseCourseExp);
  169. var educationMissionClassID = query.Select(x => x.EducationMissionClassID).ToList();
  170. var missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).ToList();
  171. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  172. {
  173. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  174. }
  175. query = this.GetQueryByDataRangeByCollege(query);
  176. var result = this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearCode)
  177. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeYearID)
  178. .ThenBy(x => x.StandardID).ThenBy(x => x.CourseName).ThenBy(x => x.OrderNo).ThenBy(x => x.Name)
  179. .ToList();
  180. result.ForEach(x => x.MissionClassTeacherView = new HashSet<MissionClassTeacherView>(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID)));
  181. return result;
  182. }
  183. public void Delete(List<Guid?> educationMissionClassIDs)
  184. {
  185. #region 检查课表是否已提交
  186. var submittedCollege = this.educationMissionClassDAL.GetSchedulingSubmittedCollege(educationMissionClassIDs).ToList();
  187. if (submittedCollege.Count != 0)
  188. {
  189. string collegeNameString = string.Join("、", submittedCollege.Select(x => x.Name));
  190. throw new Exception(collegeNameString + "的课表已经提交并形成正式课表,因此无法撤销。");
  191. }
  192. #endregion
  193. #region 根据教学任务、删除排课未提交状态的相关信息
  194. var educationSchedulingClassList = this.educationMissionClassDAL.EducationSchedulingClassRepository
  195. .GetList(x => educationMissionClassIDs.Contains(x.EM_EducationMissionClass.EducationMissionClassID)).Select(w => w.EducationSchedulingClassID)
  196. .ToList();
  197. var educationSchedulingList = this.educationMissionClassDAL.EducationSchedulingRepository
  198. .GetList(x => educationSchedulingClassList.Contains(x.EM_EducationSchedulingClass.EducationSchedulingClassID)
  199. , (x => x.ES_EducationSchedulingTeacher), (x => x.ES_EducationSchedulingWeekNum))
  200. .ToList();
  201. foreach (var educationScheduling in educationSchedulingList)
  202. {
  203. UnitOfWork.Delete<ES_EducationSchedulingTeacher>(x => x.EducationSchedulingID == educationScheduling.EducationSchedulingID);
  204. UnitOfWork.Delete<ES_EducationSchedulingWeekNum>(x => x.EducationSchedulingID == educationScheduling.EducationSchedulingID);
  205. UnitOfWork.Delete<ES_EducationScheduling>(x => x.EducationSchedulingID == educationScheduling.EducationSchedulingID);
  206. }
  207. var educationMissionClassList = educationMissionClassDAL.EducationMissionClassRepository.GetList(x => educationMissionClassIDs.Contains(x.EducationMissionClassID)).ToList();
  208. educationMissionClassList.ForEach(x =>
  209. {
  210. x.RecordStatus = (int)EM_EducationMissionClassStatus.Submitted;
  211. UnitOfWork.Update(x);
  212. });
  213. #endregion
  214. UnitOfWork.Commit();
  215. }
  216. }
  217. }