EducationMissionClassServices_Partial.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using EMIS.CommonLogic.EducationManagement;
  2. using EMIS.DataLogic.Repositories;
  3. using EMIS.Entities;
  4. using EMIS.ViewModel;
  5. using EMIS.ViewModel.EducationManagement;
  6. using EMIS.ViewModel.UniversityManage.TeacherManage;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using EMIS.DataLogic.EducationSchedule;
  12. using EMIS.ViewModel.EducationManage;
  13. using EMIS.DataLogic.SchedulingManage.SchedulingSettings;
  14. namespace EMIS.CommonLogic.EducationManagement
  15. {
  16. public partial class EducationMissionClassServices : BaseServices, IEducationMissionClassServices
  17. {
  18. public EducationSchedulingDAL EducationSchedulingDAL { get; set; }
  19. public StaffRepository StaffRepository { get; set; }
  20. public ClassroomScheduleSettingDAL ClassroomScheduleSettingDAL { get; set; }
  21. public ClassroomReserveDAL classroomReserveDAL { get; set; }
  22. public CollegeClassroomDAL collegeClassroomDAL { get; set; }
  23. private void CheckTeacherIsAvailable(EducationMissionClassView educationMissionClassView, List<Guid> teacherIDList,
  24. int? weekday = null, Guid? CoursesTimeID = null)
  25. {
  26. var notAvailableTeacherMessage = "";
  27. var teacherIsOnWorkList = this.EducationSchedulingDAL.CheckTeacherIsOnWork(x =>
  28. x.EM_EducationSchedulingClass.EducationMissionClassID == educationMissionClassView.EducationMissionClassID,
  29. (x => teacherIDList.Contains(x.UserID))).ToList();
  30. if (teacherIsOnWorkList.Count > 0)
  31. {
  32. teacherIsOnWorkList.ForEach(x => notAvailableTeacherMessage += string.Format("任务班在{1}第{2}节课有课,但教师{0}在该节次不能排课。\n",
  33. x.Name,
  34. x.WeekdayDesc,
  35. x.Times));
  36. }
  37. var teacherIsBusyList = this.EducationSchedulingDAL.CheckTeacherIsBusy(x =>
  38. x.EM_EducationSchedulingClass.EducationMissionClassID == educationMissionClassView.EducationMissionClassID,
  39. (x => teacherIDList.Contains(x.UserID))).ToList();
  40. if (teacherIsBusyList.Count > 0)
  41. {
  42. teacherIsBusyList.ForEach(x => notAvailableTeacherMessage += string.Format("任务班在{1}第{2}节课有课,但教师{0}在该节次在其他班级有课,不能排课。\n",
  43. x.Name,
  44. x.WeekdayDesc,
  45. x.Times));
  46. }
  47. if (!string.IsNullOrEmpty(notAvailableTeacherMessage))
  48. {
  49. throw new Exception(notAvailableTeacherMessage);
  50. }
  51. }
  52. /// <summary>
  53. /// 更新教学任务班表 处理状态
  54. /// </summary>
  55. /// <param name="educationMissionClassIDs"></param>
  56. public void EducationMissionClassUpdateTeacher(EducationMissionClassView educationMissionClassView, List<EducationMissionClassTeacherListView> teacherList)
  57. {
  58. if (educationMissionClassView.EducationMissionClassID != null && educationMissionClassView.EducationMissionClassID != Guid.Empty)
  59. {
  60. var userList = teacherList.Select(w => w.UserID).ToList();
  61. CheckTeacherIsAvailable(educationMissionClassView, userList);
  62. var courseProcessList = educationMissionClassDAL.CourseProcessRepository.GetList(x => x.EducationMissionClassID == educationMissionClassView.EducationMissionClassID,
  63. (x => x.EM_CourseProcessTeacher)).ToList();
  64. #region 修改教学任务的任课老师
  65. UnitOfWork.Remove<EM_MissionClassTeacher>(p => p.MissionClassID == educationMissionClassView.EducationMissionClassID);
  66. //如果该用户在任课老师表中不存在、写入进去
  67. teacherList.ForEach(x =>
  68. {
  69. EM_MissionClassTeacher missionClassTeacherEntity = new EM_MissionClassTeacher();
  70. missionClassTeacherEntity.MissionClassTeacherID = Guid.NewGuid();
  71. missionClassTeacherEntity.MissionClassID = educationMissionClassView.EducationMissionClassID;
  72. missionClassTeacherEntity.UserID = x.UserID;
  73. missionClassTeacherEntity.TeachType = x.TeachingMethod ?? (int)EM_TeachingMethod.Lecturer;
  74. SetNewStatus(missionClassTeacherEntity);
  75. UnitOfWork.Add(missionClassTeacherEntity);
  76. });
  77. #endregion
  78. #region 修改课程进度的老师
  79. var newCourseProcessList = courseProcessList.GroupBy(x => new { x.EducationMissionClassID, x.Week, x.ClassroomID, x.ClassroomTypeID })
  80. .Select((x) => new {
  81. x.Key.EducationMissionClassID,
  82. x.Key.Week,
  83. Times = x.Sum(w => w.Times),
  84. x.Key.ClassroomID,
  85. x.Key.ClassroomTypeID
  86. }).ToList();
  87. courseProcessList.ForEach(x => {
  88. UnitOfWork.RemoveRange(x.EM_CourseProcessTeacher);
  89. UnitOfWork.Remove(x);
  90. });
  91. newCourseProcessList.ForEach(x =>
  92. {
  93. var newCourseProcess = new EM_CourseProcess
  94. {
  95. CourseProcessID = Guid.NewGuid(),
  96. EducationMissionClassID = x.EducationMissionClassID,
  97. Week = x.Week,
  98. Times = x.Times,
  99. ClassroomTypeID = x.ClassroomTypeID,
  100. ClassroomID = x.ClassroomID
  101. };
  102. this.SetNewStatus(newCourseProcess);
  103. UnitOfWork.Add(newCourseProcess);
  104. teacherList.ForEach(w =>
  105. {
  106. EM_CourseProcessTeacher courseProcessTeacher = new EM_CourseProcessTeacher();
  107. courseProcessTeacher.CourseProcessTeacherID = Guid.NewGuid();
  108. courseProcessTeacher.CourseProcessID = newCourseProcess.CourseProcessID;
  109. courseProcessTeacher.UserID = w.UserID;
  110. courseProcessTeacher.TeachType = w.TeachingMethod ?? (int)EM_TeachingMethod.Lecturer;
  111. SetNewStatus(courseProcessTeacher);
  112. UnitOfWork.Add(courseProcessTeacher);
  113. });
  114. });
  115. #endregion
  116. #region 修改排课的老师
  117. var schedulingList = this.EducationSchedulingDAL.EducationSchedulingRepository.GetList(x =>
  118. x.EM_EducationSchedulingClass.EducationMissionClassID == educationMissionClassView.EducationMissionClassID,
  119. (x => x.ES_EducationSchedulingTeacher)).ToList();
  120. schedulingList.ForEach(x => {
  121. UnitOfWork.Remove<ES_EducationSchedulingTeacher>(p => p.EducationSchedulingID == x.EducationSchedulingID);
  122. //如果该用户在任课老师表中不存在、写入进去
  123. teacherList.ForEach(w =>
  124. {
  125. ES_EducationSchedulingTeacher educationSchedulingTeacherEntity = new ES_EducationSchedulingTeacher();
  126. educationSchedulingTeacherEntity.EducationSchedulingTeacherID = Guid.NewGuid();
  127. educationSchedulingTeacherEntity.EducationSchedulingID = x.EducationSchedulingID;
  128. educationSchedulingTeacherEntity.UserID = w.UserID;
  129. educationSchedulingTeacherEntity.TeachingMethod = w.TeachingMethod ?? (int)EM_TeachingMethod.Lecturer;
  130. SetNewStatus(educationSchedulingTeacherEntity);
  131. UnitOfWork.Add(educationSchedulingTeacherEntity);
  132. });
  133. });
  134. #endregion
  135. UnitOfWork.Commit();
  136. }
  137. }
  138. private void SetEducationMissionClassClassroomID(EM_EducationMissionClass EducationMissionClass, EducationMissionClassView educationMissionClassView)
  139. {
  140. EducationMissionClass.ClassroomID = educationMissionClassView.ClassroomID;
  141. EducationMissionClass.ClassroomTypeID = educationMissionClassView.ClassroomTypeID;
  142. SetModifyStatus(EducationMissionClass);
  143. EducationMissionClass.EM_CourseProcess.ToList().ForEach(x =>
  144. {
  145. x.ClassroomID = educationMissionClassView.ClassroomID;
  146. x.ClassroomTypeID = educationMissionClassView.ClassroomTypeID;
  147. SetModifyStatus(x);
  148. });
  149. }
  150. /// <summary>
  151. /// 更新教学任务班表 处理状态
  152. /// </summary>
  153. /// <param name="educationMissionClassIDs"></param>
  154. public void EducationMissionClassUpdateClassRoom(EducationMissionClassView educationMissionClassView)
  155. {
  156. if (educationMissionClassView.EducationMissionClassID != null && educationMissionClassView.EducationMissionClassID != Guid.Empty)
  157. {
  158. var EducationMissionClass=this.GetEducationMissionClass(educationMissionClassView.EducationMissionClassID);
  159. var educationMission = educationMissionClassDAL.GetEducationMissionClassViewQueryble(x => x.EducationMissionClassID == educationMissionClassView.EducationMissionClassID).FirstOrDefault();
  160. if (educationMissionClassView.ApprovalStatus != (int)EM_EducationMissionClassStatus.Scheduled)
  161. {
  162. SetEducationMissionClassClassroomID(EducationMissionClass, educationMissionClassView);
  163. }
  164. else
  165. {
  166. var ClassRoomType = this.ClassroomScheduleDAL.ClassroomDAL.Value.ClassroomRepository.Entities.Where(x => x.ClassroomID == educationMissionClassView.ClassroomID).FirstOrDefault();
  167. if (ClassRoomType.IsConcurrentUse == true)
  168. {
  169. var before = this.EducationSchedulingDAL.EducationSchedulingRepository.GetList
  170. (x => x.EM_EducationSchedulingClass.EducationMissionClassID == educationMissionClassView.EducationMissionClassID, (x => x.ES_EducationSchedulingWeekNum)).ToList();
  171. foreach (var EducationScheduling in before)
  172. {
  173. //ES_EducationScheduling EducationSchedulings = new ES_EducationScheduling();
  174. //EducationSchedulings.EducationSchedulingID = EducationScheduling.EducationSchedulingID;
  175. //EducationSchedulings.SchoolyearID = EducationScheduling.SchoolyearID;
  176. //EducationSchedulings.EducationSchedulingClassID = EducationScheduling.EducationSchedulingClassID;
  177. //EducationSchedulings.Weekday = EducationScheduling.Weekday;
  178. //EducationSchedulings.CoursesTimeID = EducationScheduling.CoursesTimeID;
  179. EducationScheduling.ClassroomID = educationMissionClassView.ClassroomID;
  180. //EducationSchedulings.IsAuto = EducationSchedulings.IsAuto;
  181. SetModifyStatus(EducationScheduling);
  182. UnitOfWork.Commit();
  183. }
  184. SetEducationMissionClassClassroomID(EducationMissionClass, educationMissionClassView);
  185. }
  186. else
  187. {
  188. if (educationMission.ClassNum > ClassRoomType.Totalseating)
  189. {
  190. throw new Exception("该教室座位数不够不能设置!");
  191. }
  192. var before = this.EducationSchedulingDAL.EducationSchedulingRepository.GetList
  193. (x => x.EM_EducationSchedulingClass.EducationMissionClassID == educationMissionClassView.EducationMissionClassID, (x => x.ES_EducationSchedulingWeekNum)).ToList();
  194. var order = this.EducationSchedulingDAL.EducationSchedulingRepository.GetList
  195. (x => x.EducationSchedulingClassID != educationMissionClassView.EducationMissionClassID
  196. && x.ClassroomID == educationMissionClassView.ClassroomID,(x => x.ES_EducationSchedulingWeekNum)).ToList();
  197. foreach (ES_EducationScheduling educationScheduling in order)
  198. {
  199. if (before.Any(x => x.SchoolyearID == educationScheduling.SchoolyearID))
  200. {
  201. foreach (ES_EducationSchedulingWeekNum weeks in educationScheduling.ES_EducationSchedulingWeekNum)
  202. {
  203. if (before.Any(x => x.ES_EducationSchedulingWeekNum.Any(w => w.WeekNum == weeks.WeekNum) && x.Weekday == educationScheduling.Weekday && x.CoursesTimeID == educationScheduling.CoursesTimeID))
  204. {
  205. throw new Exception("该教室已被占用!");
  206. }
  207. }
  208. }
  209. }
  210. //var EducationSchedulingID = before.Select(x => x.EducationSchedulingID).ToList();
  211. //var WeekDay = before.Select(x => x.Weekday).ToList();
  212. //var SchoolyearID = before.Select(x => x.SchoolyearID).Distinct().ToList();
  213. //var Week = before.Select(x => x.ES_EducationSchedulingWeekNum).ToList();
  214. //var CoursesTimeID = before.Select(x => x.CoursesTimeID).ToList();
  215. //var beforeWeekNum = this.EducationSchedulingDAL.EducationSchedulingWeekNumRepository.GetList(x => EducationSchedulingID.Contains((Guid)x.EducationSchedulingID)).Select(x=>x.WeekNum).Distinct().ToList();
  216. //var after = this.EducationSchedulingDAL.EducationSchedulingRepository.GetList
  217. // (x => !EducationSchedulingID.Contains(x.EducationSchedulingID) &&
  218. // WeekDay.Contains(x.Weekday) && SchoolyearID.Contains(x.SchoolyearID)
  219. // && x.ClassroomID == educationMissionClassView.ClassroomID
  220. // && CoursesTimeID.Contains(x.CoursesTimeID)
  221. // ).ToList();
  222. //var afterEducationSchedulingID = after.Select(x=>x.EducationSchedulingID).ToList();
  223. //var afterWeekNum = this.EducationSchedulingDAL.EducationSchedulingWeekNumRepository.GetList(x => afterEducationSchedulingID.Contains((Guid)x.EducationSchedulingID)).Select(x => x.WeekNum).Distinct().ToList();
  224. //int isok = 0;
  225. //for (int i = 0; i < afterWeekNum.Count();i++ )
  226. //{
  227. // if (beforeWeekNum.Contains(afterWeekNum[i]))
  228. // {
  229. // isok++;
  230. // }
  231. //}
  232. var classroomTime= ClassroomScheduleSettingDAL.GetArrangementViewQueryable(educationMissionClassView.ClassroomID).ToList();
  233. var classroomReserve = classroomReserveDAL.GetClassroomReserveViewQueryable(x => x.ClassroomID == educationMissionClassView.ClassroomID);
  234. var collegeClassroom = collegeClassroomDAL.GetCollegeClassroomViewQueryable(x => x.ClassroomID == educationMissionClassView.ClassroomID && x.CollegeID == educationMission.CollegeID).FirstOrDefault();
  235. if (collegeClassroom==null)
  236. {
  237. throw new Exception("该教室不属于该教学任务的院系所不能设置!");
  238. }
  239. //if (after.Count == 0 && isok == 0)
  240. //{
  241. foreach (var EducationScheduling in before)
  242. {
  243. var isokTime = classroomTime.Where(x => x.CoursesTimeID == EducationScheduling.CoursesTimeID && x.Weekday == EducationScheduling.Weekday && x.IsOnWork == true).FirstOrDefault();
  244. if (isokTime != null)
  245. {
  246. throw new Exception("该教室不在可排时间内不能设置!");
  247. }
  248. var isReserve = classroomReserve.Where(x => x.ClassroomID == educationMissionClassView.ClassroomID && x.IsReserve == true).FirstOrDefault();
  249. if (isReserve != null)
  250. {
  251. throw new Exception("该教室已经被预留不能设置!");
  252. }
  253. EducationScheduling.ClassroomID = educationMissionClassView.ClassroomID;
  254. SetModifyStatus(EducationScheduling);
  255. UnitOfWork.Commit();
  256. }
  257. SetEducationMissionClassClassroomID(EducationMissionClass, educationMissionClassView);
  258. //}
  259. //else
  260. //{
  261. // throw new Exception("该教室已被占用!");
  262. //}
  263. }
  264. }
  265. UnitOfWork.Commit();
  266. }
  267. }
  268. }
  269. }