EducationSchedulingAdjustmentServices.cs 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Entity;
  4. using System.Linq;
  5. using System.Linq.Expressions;
  6. using System.Text;
  7. using Bowin.Common.Linq;
  8. using Bowin.Common.Linq.Entity;
  9. using EMIS.ViewModel.EducationSchedule;
  10. using EMIS.ViewModel;
  11. using EMIS.Entities;
  12. using EMIS.CommonLogic.SystemServices;
  13. using EMIS.DataLogic.EducationSchedule;
  14. using EMIS.ViewModel.EducationManage;
  15. using EMIS.Utility.FormValidate;
  16. using System.Transactions;
  17. using EMIS.CommonLogic.CalendarManage;
  18. using EMIS.ViewModel.CalendarManage;
  19. using EMIS.CommonLogic.ExaminationManage;
  20. using EMIS.DataLogic.Repositories;
  21. using EMIS.DataLogic.ExaminationManage;
  22. using EMIS.ViewModel.ExaminationManage;
  23. namespace EMIS.CommonLogic.EducationSchedule
  24. {
  25. public class EducationSchedulingAdjustmentServices : BaseWorkflowServices<ES_EducationSchedulingAdjustment>, IEducationSchedulingAdjustmentServices
  26. {
  27. public EducationSchedulingDAL EducationSchedulingDAL { get; set; }
  28. public EducationSchedulingAdjustmentDAL EducationSchedulingAdjustmentDAL { get; set; }
  29. public EducationSchedulingStopDAL EducationSchedulingStopDAL { get; set; }
  30. public ExaminationPlanDAL ExaminationPlanDAL { get; set; }
  31. public Lazy<IScheduleServices> ScheduleServices { get; set; }
  32. public Lazy<ISchoolYearServices> SchoolYearServices { get; set; }
  33. public Lazy<ICoursesTimeServices> CoursesTimeServices { get; set; }
  34. public Lazy<IEducationSchedulingStopServices> EducationSchedulingStopServices { get; set; }
  35. public void Save(ScheduleAdjustmentEditView scheduleAdjustmentView)
  36. {
  37. ES_EducationScheduling educationSchedule;
  38. if (scheduleAdjustmentView.EducationSchedulingID.HasValue)
  39. {
  40. educationSchedule = this.EducationSchedulingDAL.EducationSchedulingRepository.GetSingle(x =>
  41. x.EducationSchedulingID == scheduleAdjustmentView.EducationSchedulingID,
  42. (x => x.EM_EducationSchedulingClass),
  43. (x => x.ES_EducationSchedulingTeacher));
  44. }
  45. else
  46. {
  47. educationSchedule = this.EducationSchedulingDAL.EducationSchedulingRepository.GetSingle(x =>
  48. x.EM_EducationSchedulingClass.EducationMissionClassID == scheduleAdjustmentView.EducationMissionClassID
  49. && x.Weekday == scheduleAdjustmentView.Weekday && x.CoursesTimeID == scheduleAdjustmentView.CoursesTimeID
  50. && x.ES_EducationSchedulingWeekNum.Any(w => scheduleAdjustmentView.WeekNum == w.WeekNum),
  51. (x => x.EM_EducationSchedulingClass),
  52. (x => x.ES_EducationSchedulingTeacher));
  53. }
  54. if (educationSchedule == null)
  55. {
  56. throw new Exception("所选排课记录不存在,请退出重新选择。");
  57. }
  58. var startStatusID = this.GetStartStatus();
  59. var backpointStatusList = this.GetBackpointStatus();
  60. var scheduleAdjustment = new ES_EducationSchedulingAdjustment();
  61. if (scheduleAdjustmentView.EducationSchedulingAdjustmentID != Guid.Empty)
  62. {
  63. scheduleAdjustment = this.EducationSchedulingAdjustmentDAL.EducationSchedulingAdjustmentRepository
  64. .GetSingle(x => x.EducationSchedulingAdjustmentID == scheduleAdjustmentView.EducationSchedulingAdjustmentID,
  65. (x => x.ES_EducationSchedulingAdjustmentTeacher),
  66. (x => x.ES_EducationSchedulingAdjustmentToTeacher));
  67. if (scheduleAdjustment == null)
  68. {
  69. throw new Exception("数据已经被删除,请退出重新选择。");
  70. }
  71. if (scheduleAdjustment.RecordStatus != startStatusID && !backpointStatusList.Contains(scheduleAdjustment.RecordStatus))
  72. {
  73. throw new Exception("数据已提交,不能修改。");
  74. }
  75. this.SetModifyStatus(scheduleAdjustment);
  76. }
  77. else
  78. {
  79. scheduleAdjustment.EducationSchedulingAdjustmentID = Guid.NewGuid();
  80. this.SetNewStatus(scheduleAdjustment);
  81. scheduleAdjustment.RecordStatus = startStatusID;
  82. this.UnitOfWork.Add(scheduleAdjustment);
  83. }
  84. scheduleAdjustment.EducationMissionClassID = educationSchedule.EM_EducationSchedulingClass.EducationMissionClassID;
  85. scheduleAdjustment.Weekday = scheduleAdjustmentView.Weekday;
  86. scheduleAdjustment.CoursesTimeID = scheduleAdjustmentView.CoursesTimeID;
  87. scheduleAdjustment.ClassroomTypeID = scheduleAdjustmentView.ClassroomTypeID;
  88. scheduleAdjustment.ClassroomID = scheduleAdjustmentView.ClassroomID;
  89. scheduleAdjustment.UserID = scheduleAdjustmentView.UserID;
  90. scheduleAdjustment.ToWeekday = scheduleAdjustmentView.ToWeekday;
  91. scheduleAdjustment.ToCoursesTimeID = scheduleAdjustmentView.ToCoursesTimeID;
  92. scheduleAdjustment.ToClassroomTypeID = scheduleAdjustmentView.ToClassroomTypeID;
  93. scheduleAdjustment.ToClassroomID = scheduleAdjustmentView.ToClassroomID;
  94. scheduleAdjustment.ToUserID = scheduleAdjustmentView.ToUserID;
  95. scheduleAdjustment.WeekNum = scheduleAdjustmentView.WeekNum;
  96. scheduleAdjustment.ToWeekNum = scheduleAdjustmentView.ToWeekNum;
  97. scheduleAdjustment.ES_EducationSchedulingAdjustmentTeacher = new HashSet<ES_EducationSchedulingAdjustmentTeacher>();
  98. foreach (var teacher in educationSchedule.ES_EducationSchedulingTeacher)
  99. {
  100. var fromTeacher = new ES_EducationSchedulingAdjustmentTeacher();
  101. fromTeacher.EducationSchedulingAdjustmentTeacherID = Guid.NewGuid();
  102. fromTeacher.EducationSchedulingAdjustmentID = scheduleAdjustment.EducationSchedulingAdjustmentID;
  103. fromTeacher.UserID = teacher.UserID;
  104. fromTeacher.TeachingMethod = teacher.TeachingMethod;
  105. this.SetNewStatus(fromTeacher);
  106. scheduleAdjustment.ES_EducationSchedulingAdjustmentTeacher.Add(fromTeacher);
  107. }
  108. scheduleAdjustment.ES_EducationSchedulingAdjustmentToTeacher = new HashSet<ES_EducationSchedulingAdjustmentToTeacher>();
  109. foreach (var teacher in educationSchedule.ES_EducationSchedulingTeacher)
  110. {
  111. var toTeacher = new ES_EducationSchedulingAdjustmentToTeacher();
  112. toTeacher.EducationSchedulingAdjustmentToTeacherID = Guid.NewGuid();
  113. toTeacher.EducationSchedulingAdjustmentID = scheduleAdjustment.EducationSchedulingAdjustmentID;
  114. toTeacher.UserID = (teacher.UserID == scheduleAdjustment.UserID && scheduleAdjustment.ToUserID.HasValue) ? scheduleAdjustment.ToUserID : teacher.UserID;
  115. toTeacher.TeachingMethod = teacher.TeachingMethod;
  116. this.SetNewStatus(toTeacher);
  117. scheduleAdjustment.ES_EducationSchedulingAdjustmentToTeacher.Add(toTeacher);
  118. }
  119. this.UnitOfWork.Commit();
  120. }
  121. public IGridResultSet<ScheduleAdjustmentView> GetScheduleAdjustmentViewList(ConfiguretView configuretView,
  122. Guid? schoolyearID, Guid? coursematerialID, Guid? collegeID, Guid? userID, Guid? classroomID, Guid? applyUserID,
  123. DateTime? startTime, DateTime? endTime, int? recordStatus, int? pageIndex, int? pageSize)
  124. {
  125. var statusList = this.GetStatusViewList();
  126. Expression<Func<ES_EducationSchedulingAdjustment, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  127. Expression<Func<EM_EducationMission, bool>> missionExp = (x => true);
  128. Expression<Func<EM_EducationMissionClass, bool>> missionClassExp = (x => true);
  129. Expression<Func<CF_Staff, bool>> staffExp = (x => true);
  130. if (schoolyearID.HasValue)
  131. {
  132. missionExp = missionExp.And(x => x.SchoolyearID == schoolyearID);
  133. }
  134. if (coursematerialID.HasValue)
  135. {
  136. missionClassExp = missionClassExp.And(x => x.CoursematerialID == coursematerialID);
  137. }
  138. if (collegeID.HasValue)
  139. {
  140. staffExp = staffExp.And(x => x.CollegeID == collegeID);
  141. }
  142. if (userID.HasValue)
  143. {
  144. exp = exp.And(x => x.ES_EducationSchedulingAdjustmentTeacher.Any(y => y.UserID == userID));
  145. //staffExp = staffExp.And(x => x.UserID == userID);
  146. }
  147. if (classroomID.HasValue)
  148. {
  149. exp = exp.And(x => x.ClassroomID == classroomID);
  150. }
  151. if (applyUserID.HasValue)
  152. {
  153. exp = exp.And(x => x.CreateUserID == applyUserID);
  154. }
  155. if (startTime.HasValue)
  156. {
  157. exp = exp.And(x => x.ApplyTime >= startTime);
  158. }
  159. if (endTime.HasValue)
  160. {
  161. var correctEndTime = endTime.Value.Date.AddDays(1);
  162. exp = exp.And(x => x.ApplyTime < correctEndTime);
  163. }
  164. if (recordStatus.HasValue)
  165. {
  166. exp = exp.And(x => x.RecordStatus == recordStatus);
  167. }
  168. var query = this.EducationSchedulingAdjustmentDAL.GetScheduleAdjustmentViewQueryable(exp, missionExp, missionClassExp, staffExp);
  169. var teacherQuery = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingAdjustmentTeacherQueryable(
  170. exp, missionExp, missionClassExp, staffExp);
  171. var toTeacherQuery = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingAdjustmentToTeacherQueryable(
  172. exp, missionExp, missionClassExp, staffExp);
  173. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  174. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  175. query = this.GetQueryByDataRange(query, (x => x.UserID));
  176. var resultQuery = query.OrderByDescending(x => x.SchoolyearCode)
  177. .ThenByDescending(x => x.ApplyTime).ThenBy(x => x.ApplyUserID).ThenBy(x => x.WeekNum).ThenBy(x => x.Weekday)
  178. .ThenBy(x => x.StartTimes);
  179. var result = resultQuery.ToGridResultSet<ScheduleAdjustmentView>(pageIndex, pageSize);
  180. if (pageIndex.HasValue && pageSize.HasValue)
  181. {
  182. var adjustmentIDList = result.rows.Select(x => (Guid?)x.EducationSchedulingAdjustmentID).ToList();
  183. var teacherList = teacherQuery.Where(x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID))
  184. .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name)
  185. .ToList();
  186. var toTeacherList = toTeacherQuery.Where(x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID))
  187. .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList();
  188. result.rows.ForEach(x =>
  189. {
  190. x.TeacherNames = string.Join(",", teacherList
  191. .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID)
  192. .Select(w => w.Name));
  193. x.ToTeacherNames = string.Join(",", toTeacherList
  194. .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID)
  195. .Select(w => w.Name));
  196. x.RecordStatusName = statusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name;
  197. });
  198. }
  199. else
  200. {
  201. var teacherList = teacherQuery
  202. .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList();
  203. var toTeacherList = toTeacherQuery
  204. .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList();
  205. result.rows.ForEach(x =>
  206. {
  207. x.TeacherNames = string.Join(",", teacherList
  208. .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID)
  209. .Select(w => w.Name));
  210. x.ToTeacherNames = string.Join(",", toTeacherList
  211. .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID)
  212. .Select(w => w.Name));
  213. x.RecordStatusName = statusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name;
  214. });
  215. }
  216. return result;
  217. }
  218. public List<ScheduleAdjustmentView> GetScheduleAdjustmentViewList(ConfiguretView configuretView,
  219. Guid? schoolyearID, Guid? coursematerialID, Guid? collegeID, Guid? userID, Guid? classroomID,
  220. Guid? applyUserID, DateTime? startTime, DateTime? endTime, int? recordStatus)
  221. {
  222. return this.GetScheduleAdjustmentViewList(configuretView, schoolyearID, coursematerialID, collegeID,
  223. userID, classroomID, applyUserID, startTime, endTime, recordStatus, null, null).rows;
  224. }
  225. public void OnApproved(List<Guid> scheduleAdjustmentIDList, Guid userID)
  226. {
  227. var scheduleAdjustmentList = EducationSchedulingAdjustmentDAL.EducationSchedulingAdjustmentRepository
  228. .GetList(x => scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID),
  229. (x => x.ES_EducationSchedulingAdjustmentTeacher), (x => x.ES_EducationSchedulingAdjustmentToTeacher)).ToList();
  230. var endStatusID = this.GetCorrectEndStatus();
  231. var startStatusID = this.GetStartStatus();
  232. var backpointStatusList = this.GetBackpointStatus();
  233. var submitedStatusList = this.GetStatusViewList().Where(x => x.ID != startStatusID && x.ID != endStatusID
  234. && !backpointStatusList.Contains(x.ID)).Select(x => x.ID).ToList();
  235. var currentSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
  236. var adjustmentList = this.EducationSchedulingAdjustmentDAL.EducationSchedulingAdjustmentRepository
  237. .GetList(x => scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID), (x => x.CoursesTimeID_Nav), (x => x.ToCoursesTimeID_Nav),
  238. (x => x.EM_EducationMissionClass.EM_EducationSchedulingClass.Select(w => w.CF_Student))).ToList();
  239. var stopApprovedStatus = this.EducationSchedulingStopServices.Value.GetCorrectEndStatus().Value;
  240. var stopList = this.EducationSchedulingStopDAL.GetEducationSchedulingAdjustmentStopView(x =>
  241. scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID), stopApprovedStatus).ToList();
  242. if (adjustmentList.Any(x => SchoolYearServices.Value.IsTimePassed(
  243. currentSchoolyear, x.WeekNum, x.Weekday, x.CoursesTimeID_Nav.StartHour, x.CoursesTimeID_Nav.StartMinutes)
  244. && !stopList.Any(w => w.IsStop && w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID))
  245. || adjustmentList.Any(x => SchoolYearServices.Value.IsTimePassed(
  246. currentSchoolyear, x.ToWeekNum, x.ToWeekday, x.ToCoursesTimeID_Nav.StartHour, x.ToCoursesTimeID_Nav.StartMinutes)))
  247. {
  248. throw new Exception("调整前后的时间均不能早于当前时间,请核对。");
  249. }
  250. var adjustmentQuery = this.EducationSchedulingDAL
  251. .GetConflictAdjustmentSchedule(x => scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID), submitedStatusList);
  252. var adjustmentConflictList = this.EducationSchedulingDAL.GetSelfClassroomConflictQueryable(adjustmentQuery).ToList()
  253. .Concat(this.EducationSchedulingDAL.GetSelfTeacherConflictQueryable(adjustmentQuery).ToList())
  254. .Concat(this.EducationSchedulingDAL.GetSelfStudentConflictQueryable(adjustmentQuery).ToList()
  255. .GroupBy(w => new { w.EducationSchedulingWeekNumID, w.EducationSchedulingAdjustmentID })
  256. .Select(w => w.FirstOrDefault()).ToList())
  257. .Concat(this.EducationSchedulingDAL.GetSelfConflictQueryable(adjustmentQuery).ToList())
  258. .Concat(this.EducationSchedulingDAL.GetClassroomSeatConflictQueryable(adjustmentQuery).ToList())
  259. .Concat(this.EducationSchedulingDAL.GetClassroomReserveQueryable(adjustmentQuery).ToList())
  260. .Concat(this.EducationSchedulingDAL.GetClassroomScheduleConflicQueryable(adjustmentQuery).ToList())
  261. .Concat(this.EducationSchedulingDAL.GetClassroomConflicQueryable(adjustmentQuery).ToList())
  262. .Concat(this.EducationSchedulingDAL.GetClassroomExcessiveUseQueryable(adjustmentQuery).ToList())
  263. .Concat(this.EducationSchedulingDAL.GetClassroomAdjustmentConflictQueryable(adjustmentQuery, submitedStatusList).ToList())
  264. .Concat(this.EducationSchedulingDAL.GetCourseScheduleConflictQueryable(adjustmentQuery).ToList())
  265. .Concat(this.EducationSchedulingDAL.GetTeacherScheduleConflictQueryable(adjustmentQuery).ToList())
  266. .Concat(this.EducationSchedulingDAL.GetTeacherConflictQueryable(adjustmentQuery).ToList())
  267. .Concat(this.EducationSchedulingDAL.GetTeacherAdjustmentConflictQueryable(adjustmentQuery, submitedStatusList).ToList())
  268. .Concat(this.EducationSchedulingDAL.GetStudentScheduleConflictQueryable(adjustmentQuery).ToList())
  269. .Concat(this.EducationSchedulingDAL.GetStudentConflictQueryable(adjustmentQuery).ToList())
  270. .Concat(this.EducationSchedulingDAL.GetStudentAdjustmentConflictQueryable(adjustmentQuery, submitedStatusList).ToList()).ToList();
  271. var dateList = SchoolYearServices.Value.GetDateByCoursesTime(currentSchoolyear.SchoolYearID ?? Guid.Empty,
  272. adjustmentList.Select(x => new FullCoursesTimeView
  273. {
  274. WeekNum = x.ToWeekNum,
  275. Weekday = x.ToWeekday
  276. }).ToList());
  277. var examinationPlanList = ExaminationPlanDAL.GetExaminationPlanView(x => dateList.Contains(x.ExaminationDate ?? DateTime.MinValue) && x.SchoolyearID == currentSchoolyear.SchoolYearID
  278. && x.RecordStatus == (int)EX_ExaminationPlanStatus.Submitted).ToList();
  279. var examinationPlanIDList = examinationPlanList.Select(x => x.ExaminationPlanID).ToList();
  280. var examinationRoomLayoutViewList = ExaminationPlanDAL.GetExaminationRoomLayoutView(x => examinationPlanIDList.Contains((Guid)x.ExaminationPlanID)).ToList();
  281. examinationPlanList.ForEach(x => x.ExaminationRoomLayoutView = new HashSet<ExaminationRoomLayoutView>(examinationRoomLayoutViewList.Where(y => y.ExaminationPlanID == x.ExaminationPlanID)));
  282. var firstWeek = currentSchoolyear.FirstWeek.Value.AddDays(1 - (int)currentSchoolyear.FirstWeek.Value.DayOfWeek);
  283. adjustmentConflictList = adjustmentConflictList.Concat(
  284. adjustmentList.Where(x => examinationPlanList.Any(w => SchoolYearServices.Value.GetStartEndTimeByCourseTime(firstWeek, new FullCoursesTimeView
  285. {
  286. WeekNum = x.ToWeekNum,
  287. Weekday = x.ToWeekday,
  288. CoursesTimeID = x.ToCoursesTimeID,
  289. StartHour = x.ToCoursesTimeID_Nav.StartHour,
  290. StartMinute = x.ToCoursesTimeID_Nav.StartMinutes,
  291. EndHour = x.ToCoursesTimeID_Nav.EndHour,
  292. EndMinute = x.ToCoursesTimeID_Nav.EndMinutes
  293. }).IsOverlap(w.ExaminationDate.Value.Add(w.StartTime.Value), w.ExaminationDate.Value.Add(w.EndTime.Value)) && w.ExaminationRoomLayoutView.Select(v => (Guid?)v.ClassroomID).Contains(x.ToClassroomID))
  294. ).Select(x => new EducationSchedulingConflictView
  295. {
  296. EducationSchedulingAdjustmentID = x.EducationSchedulingAdjustmentID,
  297. EducationMissionClassName = x.EM_EducationMissionClass.Name,
  298. WeekNum = x.WeekNum,
  299. Weekday = x.Weekday,
  300. StartTimes = x.CoursesTimeID_Nav.StartTimes,
  301. EndTimes = x.CoursesTimeID_Nav.EndTimes,
  302. ClassroomID = x.ClassroomID,
  303. Reason = "教室在该节次安排了考试。"
  304. }).ToList()).Concat(
  305. adjustmentList.Where(x => examinationPlanList.Any(w => SchoolYearServices.Value.GetStartEndTimeByCourseTime(firstWeek, new FullCoursesTimeView
  306. {
  307. WeekNum = x.ToWeekNum,
  308. Weekday = x.ToWeekday,
  309. CoursesTimeID = x.ToCoursesTimeID,
  310. StartHour = x.ToCoursesTimeID_Nav.StartHour,
  311. StartMinute = x.ToCoursesTimeID_Nav.StartMinutes,
  312. EndHour = x.ToCoursesTimeID_Nav.EndHour,
  313. EndMinute = x.ToCoursesTimeID_Nav.EndMinutes
  314. }).IsOverlap(w.ExaminationDate.Value.Add(w.StartTime.Value), w.ExaminationDate.Value.Add(w.EndTime.Value)) && w.ExaminationRoomLayoutView
  315. .SelectMany(v => v.Sys_User).Select(v => (Guid?)v.UserID).Contains(x.ToUserID))
  316. ).Select(x => new EducationSchedulingConflictView
  317. {
  318. EducationSchedulingAdjustmentID = x.EducationSchedulingAdjustmentID,
  319. EducationMissionClassName = x.EM_EducationMissionClass.Name,
  320. WeekNum = x.WeekNum,
  321. Weekday = x.Weekday,
  322. StartTimes = x.CoursesTimeID_Nav.StartTimes,
  323. EndTimes = x.CoursesTimeID_Nav.EndTimes,
  324. ClassroomID = x.ClassroomID,
  325. Reason = "教师在该节次安排了考试。"
  326. }).ToList()).Concat(
  327. adjustmentList.Where(x => examinationPlanList.Any(w => SchoolYearServices.Value.GetStartEndTimeByCourseTime(firstWeek, new FullCoursesTimeView
  328. {
  329. WeekNum = x.ToWeekNum,
  330. Weekday = x.ToWeekday,
  331. CoursesTimeID = x.ToCoursesTimeID,
  332. StartHour = x.ToCoursesTimeID_Nav.StartHour,
  333. StartMinute = x.ToCoursesTimeID_Nav.StartMinutes,
  334. EndHour = x.ToCoursesTimeID_Nav.EndHour,
  335. EndMinute = x.ToCoursesTimeID_Nav.EndMinutes
  336. }).IsOverlap(w.ExaminationDate.Value.Add(w.StartTime.Value), w.ExaminationDate.Value.Add(w.EndTime.Value)) && w.ExaminationRoomLayoutView
  337. .SelectMany(v => v.EX_ExaminationRoomStudent).Select(v => v.UserID)
  338. .Intersect(x.EM_EducationMissionClass.EM_EducationSchedulingClass.SelectMany(v => v.CF_Student).Select(v => (Guid?)v.UserID)).Count() > 0)
  339. ).Select(x => new EducationSchedulingConflictView
  340. {
  341. EducationSchedulingAdjustmentID = x.EducationSchedulingAdjustmentID,
  342. EducationMissionClassName = x.EM_EducationMissionClass.Name,
  343. WeekNum = x.WeekNum,
  344. Weekday = x.Weekday,
  345. StartTimes = x.CoursesTimeID_Nav.StartTimes,
  346. EndTimes = x.CoursesTimeID_Nav.EndTimes,
  347. ClassroomID = x.ClassroomID,
  348. Reason = "学生在该节次安排了考试。"
  349. }).ToList()).ToList();
  350. if (adjustmentConflictList.Count > 0)
  351. {
  352. var errorMessage = string.Join(";", adjustmentConflictList.Select(x =>
  353. string.Format("{0}第{1}周星期{2}的{3}-{4}节调整失败,原因:{5}",
  354. x.EducationMissionClassName, x.WeekNum, WeekDayView.GetWeekdayName(x.Weekday), x.StartTimes, x.EndTimes, x.Reason)
  355. ));
  356. throw new Exception(errorMessage);
  357. }
  358. var educationSchedulingList = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingQueryableByAdjustment(x =>
  359. scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)).Include(x => x.EM_EducationSchedulingClass).ToList();
  360. var educationSchedulingWeekNumList = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingWeekNumQueryableByAdjustment(x =>
  361. scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)).ToList();
  362. var educationSchedulingTeacherList = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingTeacherQueryableByAdjustment(x =>
  363. scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)).ToList();
  364. var newEducationSchedulingList = this.EducationSchedulingAdjustmentDAL.GetNewEducationSchedulingQueryableByAdjustment(x =>
  365. scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)).Include(x => x.EM_EducationSchedulingClass).ToList();
  366. var newEducationSchedulingWeekNumList = this.EducationSchedulingAdjustmentDAL.GetNewEducationSchedulingWeekNumQueryableByAdjustment(x =>
  367. scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)).ToList();
  368. var newEducationSchedulingTeacherList = this.EducationSchedulingAdjustmentDAL.GetNewEducationSchedulingTeacherQueryableByAdjustment(x =>
  369. scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)).ToList();
  370. List<ES_EducationScheduling> insertEducationSchedulingList = new List<ES_EducationScheduling>();
  371. List<ES_EducationSchedulingTeacher> insertEducationSchedulingTeacherList = new List<ES_EducationSchedulingTeacher>();
  372. List<ES_EducationSchedulingWeekNum> insertEducationSchedulingWeekNumList = new List<ES_EducationSchedulingWeekNum>();
  373. List<ES_EducationScheduling> deleteEducationSchedulingList = new List<ES_EducationScheduling>();
  374. List<ES_EducationSchedulingTeacher> deleteEducationSchedulingTeacherList = new List<ES_EducationSchedulingTeacher>();
  375. List<ES_EducationSchedulingWeekNum> deleteEducationSchedulingWeekNumList = new List<ES_EducationSchedulingWeekNum>();
  376. foreach (var scheduleAdjustment in scheduleAdjustmentList)
  377. {
  378. var educationScheduling = educationSchedulingList
  379. .FirstOrDefault(x => x.Weekday == scheduleAdjustment.Weekday
  380. && x.CoursesTimeID == scheduleAdjustment.CoursesTimeID
  381. && x.EM_EducationSchedulingClass.EducationMissionClassID == scheduleAdjustment.EducationMissionClassID
  382. && educationSchedulingTeacherList.Any(w => w.EducationSchedulingID == x.EducationSchedulingID && w.UserID == scheduleAdjustment.UserID)
  383. && educationSchedulingWeekNumList.Any(w => w.EducationSchedulingID == x.EducationSchedulingID && scheduleAdjustment.WeekNum == w.WeekNum));
  384. var curEducationSchedulingTeacherList = educationSchedulingTeacherList
  385. .Where(w => w.EducationSchedulingID == educationScheduling.EducationSchedulingID)
  386. .ToList();
  387. var curEducationSchedulingWeekNumList = educationSchedulingWeekNumList
  388. .Where(w => w.EducationSchedulingID == educationScheduling.EducationSchedulingID)
  389. .ToList();
  390. if (educationScheduling != null)
  391. {
  392. var toTeacherList = scheduleAdjustment.ES_EducationSchedulingAdjustmentToTeacher.Select(x => new CourseProcessTeacherView
  393. {
  394. UserID = x.UserID ?? Guid.Empty,
  395. TeachingMethod = x.TeachingMethod
  396. }).ToList();
  397. ES_EducationScheduling newEducationScheduling;
  398. var curNewEducationSchedulingList = newEducationSchedulingList
  399. .Where(x => x.Weekday == scheduleAdjustment.ToWeekday
  400. && x.CoursesTimeID == scheduleAdjustment.ToCoursesTimeID
  401. && x.EM_EducationSchedulingClass.EducationMissionClassID == scheduleAdjustment.EducationMissionClassID
  402. && x.ClassroomID == scheduleAdjustment.ToClassroomID).ToList();
  403. newEducationScheduling = curNewEducationSchedulingList.FirstOrDefault(x =>
  404. string.Join(",", newEducationSchedulingTeacherList.Where(w => x.EducationSchedulingID == w.EducationSchedulingID)
  405. .Select(w => w.UserID.ToString() + "," + w.TeachingMethod).OrderBy(w => w))
  406. == string.Join(",", toTeacherList.Select(w => w.UserID.ToString() + "," + w.TeachingMethod).OrderBy(w => w)));
  407. if (newEducationScheduling == null)
  408. {
  409. newEducationScheduling = new ES_EducationScheduling
  410. {
  411. EducationSchedulingID = Guid.NewGuid(),
  412. SchoolyearID = educationScheduling.SchoolyearID,
  413. EducationSchedulingClassID = educationScheduling.EducationSchedulingClassID,
  414. EM_EducationSchedulingClass = educationScheduling.EM_EducationSchedulingClass,
  415. Weekday = scheduleAdjustment.ToWeekday,
  416. CoursesTimeID = scheduleAdjustment.ToCoursesTimeID,
  417. ClassroomID = scheduleAdjustment.ToClassroomID
  418. };
  419. toTeacherList.ForEach(x =>
  420. {
  421. var educationSchedulingTeacher = new ES_EducationSchedulingTeacher
  422. {
  423. EducationSchedulingTeacherID = Guid.NewGuid(),
  424. EducationSchedulingID = newEducationScheduling.EducationSchedulingID,
  425. UserID = x.UserID,
  426. TeachingMethod = x.TeachingMethod
  427. };
  428. this.SetNewStatus(educationSchedulingTeacher);
  429. insertEducationSchedulingTeacherList.Add(educationSchedulingTeacher);
  430. newEducationSchedulingTeacherList.Add(educationSchedulingTeacher);
  431. });
  432. this.SetNewStatus(newEducationScheduling);
  433. insertEducationSchedulingList.Add(newEducationScheduling);
  434. newEducationSchedulingList.Add(newEducationScheduling);
  435. }
  436. var curNewEducationSchedulingWeekNumList = newEducationSchedulingWeekNumList.Where(x => x.EducationSchedulingID == newEducationScheduling.EducationSchedulingID).ToList();
  437. if (curNewEducationSchedulingWeekNumList.Any(w => scheduleAdjustment.ToWeekNum == w.WeekNum && w.EducationSchedulingID != educationScheduling.EducationSchedulingID))
  438. {
  439. throw new Exception("调整后的课程周次冲突,请检查课表。");
  440. }
  441. var educationSchedulingWeekNum = new ES_EducationSchedulingWeekNum
  442. {
  443. EducationSchedulingWeekNumID = Guid.NewGuid(),
  444. EducationSchedulingID = newEducationScheduling.EducationSchedulingID,
  445. WeekNum = scheduleAdjustment.ToWeekNum
  446. };
  447. this.SetNewStatus(educationSchedulingWeekNum);
  448. insertEducationSchedulingWeekNumList.Add(educationSchedulingWeekNum);
  449. newEducationSchedulingWeekNumList.Add(educationSchedulingWeekNum);
  450. deleteEducationSchedulingWeekNumList.AddRange(curEducationSchedulingWeekNumList.Where(x => x.EducationSchedulingID == educationScheduling.EducationSchedulingID
  451. && x.WeekNum == scheduleAdjustment.WeekNum).ToList());
  452. educationSchedulingWeekNumList.RemoveAll(x => x.EducationSchedulingID == educationScheduling.EducationSchedulingID
  453. && x.WeekNum == scheduleAdjustment.WeekNum);
  454. curEducationSchedulingWeekNumList.RemoveAll(x => x.EducationSchedulingID == educationScheduling.EducationSchedulingID
  455. && x.WeekNum == scheduleAdjustment.WeekNum);
  456. newEducationSchedulingWeekNumList.RemoveAll(x => x.EducationSchedulingID == educationScheduling.EducationSchedulingID
  457. && x.WeekNum == scheduleAdjustment.WeekNum);
  458. if (curEducationSchedulingWeekNumList.Count == 0)
  459. {
  460. deleteEducationSchedulingTeacherList.AddRange(curEducationSchedulingTeacherList);
  461. deleteEducationSchedulingList.Add(educationScheduling);
  462. }
  463. }
  464. else
  465. {
  466. throw new Exception("原先选定的课程已经被调整。");
  467. }
  468. }
  469. using (var scope = new TransactionScope())
  470. {
  471. UnitOfWork.BulkInsert(insertEducationSchedulingList);
  472. UnitOfWork.BulkInsert(insertEducationSchedulingTeacherList);
  473. UnitOfWork.BulkInsert(insertEducationSchedulingWeekNumList);
  474. UnitOfWork.Delete(deleteEducationSchedulingWeekNumList);
  475. UnitOfWork.Delete(deleteEducationSchedulingTeacherList);
  476. UnitOfWork.Delete(deleteEducationSchedulingList);
  477. scope.Complete();
  478. }
  479. }
  480. public ScheduleAdjustmentEditView GetScheduleAdjustmentEditView(Guid educationAdjustmentSchedulingID)
  481. {
  482. var result = this.EducationSchedulingAdjustmentDAL
  483. .GetScheduleAdjustmentEditViewQueryable(x => x.EducationSchedulingAdjustmentID == educationAdjustmentSchedulingID,
  484. (x => true), (x => true), (x => true)).FirstOrDefault();
  485. return result;
  486. }
  487. public void Delete(IList<Guid> adjustmentIDList)
  488. {
  489. var startStatus = this.GetStartStatus();
  490. var submitedAdjustmentList = this.EducationSchedulingAdjustmentDAL.EducationSchedulingAdjustmentRepository
  491. .GetList(x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID) && x.RecordStatus != startStatus).ToList();
  492. if (submitedAdjustmentList.Count > 0)
  493. {
  494. throw new Exception("所选记录当中存在已经提交的记录,无法删除。");
  495. }
  496. var nullableAdjustmentIDList = adjustmentIDList.Select(x => (Guid?)x).ToList();
  497. this.UnitOfWork.Delete<ES_EducationSchedulingAdjustmentTeacher>(x => nullableAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID));
  498. this.UnitOfWork.Delete<ES_EducationSchedulingAdjustmentToTeacher>(x => nullableAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID));
  499. this.UnitOfWork.Delete<ES_EducationSchedulingAdjustment>(x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID));
  500. }
  501. public void Submit(IList<Guid> adjustmentIDList, Guid userID)
  502. {
  503. var startStatusID = this.GetStartStatus();
  504. var endStatusID = this.GetCorrectEndStatus();
  505. var backpointStatusList = this.GetBackpointStatus();
  506. var submitedStatusList = this.GetStatusViewList().Where(x => x.ID != startStatusID && x.ID != endStatusID
  507. && !backpointStatusList.Contains(x.ID)).Select(x => x.ID).ToList();
  508. var currentSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
  509. var adjustmentList = this.EducationSchedulingAdjustmentDAL.EducationSchedulingAdjustmentRepository
  510. .GetList(x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID), (x => x.CoursesTimeID_Nav), (x => x.ToCoursesTimeID_Nav),
  511. (x => x.EM_EducationMissionClass.EM_EducationSchedulingClass.Select(w => w.CF_Student))).ToList();
  512. if (adjustmentList.Any(x => x.RecordStatus != startStatusID && !backpointStatusList.Contains(x.RecordStatus)))
  513. {
  514. throw new Exception("只能提交已提交和已退回的记录。");
  515. }
  516. var stopApprovedStatus = this.EducationSchedulingStopServices.Value.GetCorrectEndStatus().Value;
  517. var stopList = this.EducationSchedulingStopDAL.GetEducationSchedulingAdjustmentStopView(x =>
  518. adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID), stopApprovedStatus).ToList();
  519. if (adjustmentList.Any(x => SchoolYearServices.Value.IsTimePassed(
  520. currentSchoolyear, x.WeekNum, x.Weekday, x.CoursesTimeID_Nav.StartHour, x.CoursesTimeID_Nav.StartMinutes)
  521. && !stopList.Any(w => w.IsStop && w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID))
  522. || adjustmentList.Any(x => SchoolYearServices.Value.IsTimePassed(
  523. currentSchoolyear, x.ToWeekNum, x.ToWeekday, x.ToCoursesTimeID_Nav.StartHour, x.ToCoursesTimeID_Nav.StartMinutes)))
  524. {
  525. throw new Exception("调整前后的时间均不能早于当前时间,请核对。");
  526. }
  527. var adjustmentQuery = this.EducationSchedulingDAL.GetConflictAdjustmentSchedule(x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID), submitedStatusList);
  528. var adjustmentConflictList =
  529. //提交的各调整记录之间的教室冲突
  530. this.EducationSchedulingDAL.GetSelfClassroomConflictQueryable(adjustmentQuery).ToList()
  531. //提交的各调整记录之间的教师冲突
  532. .Concat(this.EducationSchedulingDAL.GetSelfTeacherConflictQueryable(adjustmentQuery).ToList())
  533. //提交的各调整记录之间的学生冲突
  534. .Concat(this.EducationSchedulingDAL.GetSelfStudentConflictQueryable(adjustmentQuery).ToList()
  535. .GroupBy(w => new { w.EducationSchedulingWeekNumID, w.EducationSchedulingAdjustmentID })
  536. .Select(w => w.FirstOrDefault()).ToList())
  537. //提交的各调整记录之间的同一节课的重复调动冲突
  538. .Concat(this.EducationSchedulingDAL.GetSelfConflictQueryable(adjustmentQuery).ToList())
  539. //座位不足冲突
  540. .Concat(this.EducationSchedulingDAL.GetClassroomSeatConflictQueryable(adjustmentQuery).ToList())
  541. //教室预留冲突
  542. .Concat(this.EducationSchedulingDAL.GetClassroomReserveQueryable(adjustmentQuery).ToList())
  543. //教室可排时间冲突
  544. .Concat(this.EducationSchedulingDAL.GetClassroomScheduleConflicQueryable(adjustmentQuery).ToList())
  545. //教室课表冲突
  546. .Concat(this.EducationSchedulingDAL.GetClassroomConflicQueryable(adjustmentQuery).ToList())
  547. //教室占用冲突
  548. .Concat(this.EducationSchedulingDAL.GetClassroomExcessiveUseQueryable(adjustmentQuery).ToList())
  549. //教室被他人调课占用冲突
  550. .Concat(this.EducationSchedulingDAL.GetClassroomAdjustmentConflictQueryable(adjustmentQuery, submitedStatusList).ToList())
  551. //课程可排时间冲突
  552. .Concat(this.EducationSchedulingDAL.GetCourseScheduleConflictQueryable(adjustmentQuery).ToList())
  553. //教师可排时间冲突
  554. .Concat(this.EducationSchedulingDAL.GetTeacherScheduleConflictQueryable(adjustmentQuery).ToList())
  555. //教师课表冲突
  556. .Concat(this.EducationSchedulingDAL.GetTeacherConflictQueryable(adjustmentQuery).ToList())
  557. //教师被他人调课占用冲突
  558. .Concat(this.EducationSchedulingDAL.GetTeacherAdjustmentConflictQueryable(adjustmentQuery, submitedStatusList).ToList())
  559. //班级可排时间冲突
  560. .Concat(this.EducationSchedulingDAL.GetStudentScheduleConflictQueryable(adjustmentQuery).ToList())
  561. //学生课表冲突
  562. .Concat(this.EducationSchedulingDAL.GetStudentConflictQueryable(adjustmentQuery).ToList())
  563. //学生被他人调课占用冲突
  564. .Concat(this.EducationSchedulingDAL.GetStudentAdjustmentConflictQueryable(adjustmentQuery, submitedStatusList).ToList())
  565. .ToList();
  566. var dateList = SchoolYearServices.Value.GetDateByCoursesTime(currentSchoolyear.SchoolYearID ?? Guid.Empty,
  567. adjustmentList.Select(x => new FullCoursesTimeView
  568. {
  569. WeekNum = x.ToWeekNum,
  570. Weekday = x.ToWeekday
  571. }).ToList());
  572. var examinationPlanList = ExaminationPlanDAL.GetExaminationPlanView(x => dateList.Contains(x.ExaminationDate ?? DateTime.MinValue) && x.SchoolyearID == currentSchoolyear.SchoolYearID
  573. && x.RecordStatus == (int)EX_ExaminationPlanStatus.Submitted).ToList();
  574. var examinationPlanIDList = examinationPlanList.Select(x => x.ExaminationPlanID).ToList();
  575. var examinationRoomLayoutViewList = ExaminationPlanDAL.GetExaminationRoomLayoutView(x => examinationPlanIDList.Contains((Guid)x.ExaminationPlanID)).ToList();
  576. examinationPlanList.ForEach(x => x.ExaminationRoomLayoutView = new HashSet<ExaminationRoomLayoutView>(examinationRoomLayoutViewList.Where(y => y.ExaminationPlanID == x.ExaminationPlanID)));
  577. var firstWeek = currentSchoolyear.FirstWeek.Value.AddDays(1 - (int)currentSchoolyear.FirstWeek.Value.DayOfWeek);
  578. //学年学期还有问题,应该按照提交的记录找出他们的学年学期
  579. adjustmentConflictList = adjustmentConflictList.Concat(
  580. adjustmentList.Where(x => examinationPlanList.Any(w => SchoolYearServices.Value.GetStartEndTimeByCourseTime(firstWeek, new FullCoursesTimeView {
  581. WeekNum = x.ToWeekNum,
  582. Weekday = x.ToWeekday,
  583. CoursesTimeID = x.ToCoursesTimeID,
  584. StartHour = x.ToCoursesTimeID_Nav.StartHour,
  585. StartMinute = x.ToCoursesTimeID_Nav.StartMinutes,
  586. EndHour = x.ToCoursesTimeID_Nav.EndHour,
  587. EndMinute = x.ToCoursesTimeID_Nav.EndMinutes
  588. }).IsOverlap(w.ExaminationDate.Value.Add(w.StartTime.Value), w.ExaminationDate.Value.Add(w.EndTime.Value)) && w.ExaminationRoomLayoutView.Select(v => (Guid?)v.ClassroomID).Contains(x.ToClassroomID))
  589. ).Select(x => new EducationSchedulingConflictView
  590. {
  591. EducationSchedulingAdjustmentID = x.EducationSchedulingAdjustmentID,
  592. EducationMissionClassName = x.EM_EducationMissionClass.Name,
  593. WeekNum = x.WeekNum,
  594. Weekday = x.Weekday,
  595. StartTimes = x.CoursesTimeID_Nav.StartTimes,
  596. EndTimes = x.CoursesTimeID_Nav.EndTimes,
  597. ClassroomID = x.ClassroomID,
  598. Reason = "教室在该节次安排了考试。"
  599. }).ToList()).Concat(
  600. adjustmentList.Where(x => examinationPlanList.Any(w => SchoolYearServices.Value.GetStartEndTimeByCourseTime(firstWeek, new FullCoursesTimeView
  601. {
  602. WeekNum = x.ToWeekNum,
  603. Weekday = x.ToWeekday,
  604. CoursesTimeID = x.ToCoursesTimeID,
  605. StartHour = x.ToCoursesTimeID_Nav.StartHour,
  606. StartMinute = x.ToCoursesTimeID_Nav.StartMinutes,
  607. EndHour = x.ToCoursesTimeID_Nav.EndHour,
  608. EndMinute = x.ToCoursesTimeID_Nav.EndMinutes
  609. }).IsOverlap(w.ExaminationDate.Value.Add(w.StartTime.Value), w.ExaminationDate.Value.Add(w.EndTime.Value)) && w.ExaminationRoomLayoutView
  610. .SelectMany(v => v.Sys_User).Select(v => (Guid?)v.UserID).Contains(x.ToUserID))
  611. ).Select(x => new EducationSchedulingConflictView
  612. {
  613. EducationSchedulingAdjustmentID = x.EducationSchedulingAdjustmentID,
  614. EducationMissionClassName = x.EM_EducationMissionClass.Name,
  615. WeekNum = x.WeekNum,
  616. Weekday = x.Weekday,
  617. StartTimes = x.CoursesTimeID_Nav.StartTimes,
  618. EndTimes = x.CoursesTimeID_Nav.EndTimes,
  619. ClassroomID = x.ClassroomID,
  620. Reason = "教师在该节次安排了考试。"
  621. }).ToList()).Concat(
  622. adjustmentList.Where(x => examinationPlanList.Any(w => SchoolYearServices.Value.GetStartEndTimeByCourseTime(firstWeek, new FullCoursesTimeView
  623. {
  624. WeekNum = x.ToWeekNum,
  625. Weekday = x.ToWeekday,
  626. CoursesTimeID = x.ToCoursesTimeID,
  627. StartHour = x.ToCoursesTimeID_Nav.StartHour,
  628. StartMinute = x.ToCoursesTimeID_Nav.StartMinutes,
  629. EndHour = x.ToCoursesTimeID_Nav.EndHour,
  630. EndMinute = x.ToCoursesTimeID_Nav.EndMinutes
  631. }).IsOverlap(w.ExaminationDate.Value.Add(w.StartTime.Value), w.ExaminationDate.Value.Add(w.EndTime.Value)) && w.ExaminationRoomLayoutView
  632. .SelectMany(v => v.EX_ExaminationRoomStudent).Select(v => v.UserID)
  633. .Intersect(x.EM_EducationMissionClass.EM_EducationSchedulingClass.SelectMany(v => v.CF_Student).Select(v => (Guid?)v.UserID)).Count() > 0)
  634. ).Select(x => new EducationSchedulingConflictView
  635. {
  636. EducationSchedulingAdjustmentID = x.EducationSchedulingAdjustmentID,
  637. EducationMissionClassName = x.EM_EducationMissionClass.Name,
  638. WeekNum = x.WeekNum,
  639. Weekday = x.Weekday,
  640. StartTimes = x.CoursesTimeID_Nav.StartTimes,
  641. EndTimes = x.CoursesTimeID_Nav.EndTimes,
  642. ClassroomID = x.ClassroomID,
  643. Reason = "学生在该节次安排了考试。"
  644. }).ToList()).ToList();
  645. if (adjustmentConflictList.Count > 0)
  646. {
  647. var errorMessage = string.Join(";", adjustmentConflictList.Select(x =>
  648. string.Format("{0}第{1}周{2}的{3}-{4}节调整失败,原因:{5}",
  649. x.EducationMissionClassName, x.WeekNum, WeekDayView.GetWeekdayName(x.Weekday), x.StartTimes, x.EndTimes, x.Reason)
  650. ));
  651. throw new Exception(errorMessage);
  652. }
  653. var notSubmitList = adjustmentList.Where(x => x.RecordStatus == startStatusID).Select(x => x.EducationSchedulingAdjustmentID).ToList();
  654. var submitedList = adjustmentList.Where(x => x.RecordStatus != startStatusID).Select(x => x.EducationSchedulingAdjustmentID).ToList();
  655. if (notSubmitList.Count > 0)
  656. {
  657. this.StartUp(notSubmitList, userID);
  658. }
  659. if (submitedList.Count > 0)
  660. {
  661. var action = this.GetActionView(submitedList.First(), userID).FirstOrDefault();
  662. if (action != null)
  663. {
  664. this.Approve(submitedList, userID, action.ActionID);
  665. }
  666. }
  667. var nowTime = DateTime.Now;
  668. UnitOfWork.Update<ES_EducationSchedulingAdjustment>((x => new ES_EducationSchedulingAdjustment { ApplyUserID = userID, ApplyTime = nowTime }), (x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)));
  669. }
  670. public IGridResultSet<ScheduleAdjustmentView> GetScheduleAdjustmentViewApproveList(ConfiguretView configuretView,
  671. Guid? schoolyearID, Guid? coursematerialID, Guid? collegeID, Guid? userID, Guid? classroomID, Guid? applyUserID,
  672. DateTime? startTime, DateTime? endTime, int? recordStatus, int? pageIndex, int? pageSize)
  673. {
  674. var statusList = this.GetStatusViewList();
  675. Expression<Func<ES_EducationSchedulingAdjustment, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  676. Expression<Func<EM_EducationMission, bool>> missionExp = (x => true);
  677. Expression<Func<EM_EducationMissionClass, bool>> missionClassExp = (x => true);
  678. Expression<Func<CF_Staff, bool>> staffExp = (x => true);
  679. if (schoolyearID.HasValue)
  680. {
  681. missionExp = missionExp.And(x => x.SchoolyearID == schoolyearID);
  682. }
  683. if (coursematerialID.HasValue)
  684. {
  685. missionClassExp = missionClassExp.And(x => x.CoursematerialID == coursematerialID);
  686. }
  687. if (collegeID.HasValue)
  688. {
  689. staffExp = staffExp.And(x => x.CollegeID == collegeID);
  690. }
  691. if (userID.HasValue)
  692. {
  693. exp = exp.And(x => x.ES_EducationSchedulingAdjustmentTeacher.Any(y => y.UserID == userID));
  694. //staffExp = staffExp.And(x => x.UserID == userID);
  695. }
  696. if (classroomID.HasValue)
  697. {
  698. exp = exp.And(x => x.ClassroomID == classroomID);
  699. }
  700. if (applyUserID.HasValue)
  701. {
  702. exp = exp.And(x => x.CreateUserID == applyUserID);
  703. }
  704. if (startTime.HasValue)
  705. {
  706. exp = exp.And(x => x.ApplyTime >= startTime);
  707. }
  708. if (endTime.HasValue)
  709. {
  710. var correctEndTime = endTime.Value.Date.AddDays(1);
  711. exp = exp.And(x => x.ApplyTime < correctEndTime);
  712. }
  713. if (recordStatus.HasValue)
  714. {
  715. exp = exp.And(x => x.RecordStatus == recordStatus);
  716. }
  717. var query = this.EducationSchedulingAdjustmentDAL.GetScheduleAdjustmentViewQueryable(exp, missionExp, missionClassExp, staffExp);
  718. var teacherQuery = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingAdjustmentTeacherQueryable(
  719. exp, missionExp, missionClassExp, staffExp);
  720. var toTeacherQuery = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingAdjustmentToTeacherQueryable(
  721. exp, missionExp, missionClassExp, staffExp);
  722. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  723. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  724. query = this.GetQueryByDataRangeByDepartment(query);
  725. var resultQuery = query.OrderByDescending(x => x.SchoolyearCode)
  726. .ThenByDescending(x => x.ApplyTime).ThenBy(x => x.ApplyUserID).ThenBy(x => x.WeekNum).ThenBy(x => x.Weekday)
  727. .ThenBy(x => x.StartTimes);
  728. var result = resultQuery.ToGridResultSet<ScheduleAdjustmentView>(pageIndex, pageSize);
  729. if (pageIndex.HasValue && pageSize.HasValue)
  730. {
  731. var adjustmentIDList = result.rows.Select(x => (Guid?)x.EducationSchedulingAdjustmentID).ToList();
  732. var teacherList = teacherQuery.Where(x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID))
  733. .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name)
  734. .ToList();
  735. var toTeacherList = toTeacherQuery.Where(x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID))
  736. .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList();
  737. result.rows.ForEach(x =>
  738. {
  739. x.TeacherNames = string.Join(",", teacherList
  740. .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID)
  741. .Select(w => w.Name));
  742. x.ToTeacherNames = string.Join(",", toTeacherList
  743. .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID)
  744. .Select(w => w.Name));
  745. x.RecordStatusName = statusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name;
  746. });
  747. }
  748. else
  749. {
  750. var teacherList = teacherQuery
  751. .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList();
  752. var toTeacherList = toTeacherQuery
  753. .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList();
  754. result.rows.ForEach(x =>
  755. {
  756. x.TeacherNames = string.Join(",", teacherList
  757. .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID)
  758. .Select(w => w.Name));
  759. x.ToTeacherNames = string.Join(",", toTeacherList
  760. .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID)
  761. .Select(w => w.Name));
  762. x.RecordStatusName = statusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name;
  763. });
  764. }
  765. return result;
  766. }
  767. public List<ScheduleAdjustmentView> GetScheduleAdjustmentViewApproveList(ConfiguretView configuretView, Guid? schoolyearID,
  768. Guid? coursematerialID, Guid? collegeID, Guid? userID, Guid? classroomID, Guid? applyUserID, DateTime? startTime, DateTime? endTime,
  769. int? recordStatus)
  770. {
  771. return this.GetScheduleAdjustmentViewApproveList(configuretView, schoolyearID, coursematerialID, collegeID,
  772. userID, classroomID, applyUserID, startTime, endTime, recordStatus, null, null).rows;
  773. }
  774. public List<ScheduleAdjustmentView> GetScheduleAdjustmentViewList(IList<Guid> scheduleAdjustmentIDList)
  775. {
  776. if (scheduleAdjustmentIDList.Count == 0)
  777. {
  778. throw new Exception("请选择需要查询的调课记录。");
  779. }
  780. var statusList = this.GetStatusViewList();
  781. Expression<Func<ES_EducationSchedulingAdjustment, bool>> exp = (x => scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID));
  782. var query = this.EducationSchedulingAdjustmentDAL.GetScheduleAdjustmentViewQueryable(exp, (x => true), (x => true), (x => true));
  783. var teacherQuery = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingAdjustmentTeacherQueryable(
  784. exp, (x => true), (x => true), (x => true));
  785. var toTeacherQuery = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingAdjustmentToTeacherQueryable(
  786. exp, (x => true), (x => true), (x => true));
  787. query = this.GetQueryByDataRange(query, (x => x.UserID));
  788. var resultQuery = query.OrderByDescending(x => x.SchoolyearCode)
  789. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo)
  790. .ThenBy(x => x.CourseName).ThenBy(x => x.UserName);
  791. var result = resultQuery.ToList();
  792. var teacherList = teacherQuery
  793. .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList();
  794. var toTeacherList = toTeacherQuery
  795. .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList();
  796. result.ForEach(x =>
  797. {
  798. x.TeacherNames = string.Join(",", teacherList
  799. .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID)
  800. .Select(w => w.Name));
  801. x.ToTeacherNames = string.Join(",", toTeacherList
  802. .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID)
  803. .Select(w => w.Name));
  804. x.RecordStatusName = statusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name;
  805. });
  806. return result;
  807. }
  808. public List<ScheduleAdjustmentView> GetScheduleAdjustmentViewApproveList(IList<Guid> scheduleAdjustmentIDList)
  809. {
  810. if (scheduleAdjustmentIDList.Count == 0)
  811. {
  812. throw new Exception("请选择需要查询的调课记录。");
  813. }
  814. var statusList = this.GetStatusViewList();
  815. Expression<Func<ES_EducationSchedulingAdjustment, bool>> exp = (x => scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID));
  816. var query = this.EducationSchedulingAdjustmentDAL.GetScheduleAdjustmentViewQueryable(exp, (x => true), (x => true), (x => true));
  817. var teacherQuery = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingAdjustmentTeacherQueryable(
  818. exp, (x => true), (x => true), (x => true));
  819. var toTeacherQuery = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingAdjustmentToTeacherQueryable(
  820. exp, (x => true), (x => true), (x => true));
  821. query = this.GetQueryByDataRangeByDepartment(query);
  822. var resultQuery = query.OrderByDescending(x => x.SchoolyearCode)
  823. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo)
  824. .ThenBy(x => x.CourseName).ThenBy(x => x.UserName);
  825. var result = resultQuery.ToList();
  826. var teacherList = teacherQuery
  827. .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList();
  828. var toTeacherList = toTeacherQuery
  829. .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList();
  830. result.ForEach(x =>
  831. {
  832. x.TeacherNames = string.Join(",", teacherList
  833. .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID)
  834. .Select(w => w.Name));
  835. x.ToTeacherNames = string.Join(",", toTeacherList
  836. .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID)
  837. .Select(w => w.Name));
  838. x.RecordStatusName = statusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name;
  839. });
  840. return result;
  841. }
  842. public void BatchSave(IList<Guid?> educationSchedulingWeekNumIDList, Guid fromUserID, int? toWeekNum, int? toWeekday, Guid? toUserID,
  843. Guid? toCoursesTimeID, int? toClassroomType, Guid? toClassroom)
  844. {
  845. var startStatusID = this.GetStartStatus();
  846. var endStatusID = this.GetCorrectEndStatus();
  847. var backpointStatusList = this.GetBackpointStatus();
  848. var submitedStatusList = this.GetStatusViewList().Where(x => x.ID != startStatusID && x.ID != endStatusID
  849. && !backpointStatusList.Contains(x.ID)).Select(x => x.ID).ToList();
  850. var currentSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
  851. var toCourseTime = this.CoursesTimeServices.Value.GetCoursesTime(toCoursesTimeID);
  852. var weekNumList = this.EducationSchedulingDAL.EducationSchedulingWeekNumRepository.GetList(x =>
  853. educationSchedulingWeekNumIDList.Contains(x.EducationSchedulingWeekNumID),
  854. (x => x.ES_EducationScheduling.EM_CoursesTime)).ToList();
  855. var stopApprovedStatus = this.EducationSchedulingStopServices.Value.GetCorrectEndStatus().Value;
  856. var stopList = this.EducationSchedulingStopDAL.GetEducationSchedulingWeekNumStopView(x =>
  857. educationSchedulingWeekNumIDList.Contains(x.EducationSchedulingWeekNumID), stopApprovedStatus).ToList();
  858. if (weekNumList.Any(x => SchoolYearServices.Value.IsTimePassed(
  859. currentSchoolyear, x.WeekNum, x.ES_EducationScheduling.Weekday,
  860. x.ES_EducationScheduling.EM_CoursesTime.StartHour, x.ES_EducationScheduling.EM_CoursesTime.StartMinutes)
  861. && !stopList.Any(w => w.IsStop && w.EducationSchedulingWeekNumID == x.EducationSchedulingWeekNumID))
  862. || (
  863. toCourseTime != null && toWeekNum != null && toWeekday != null &&
  864. SchoolYearServices.Value.IsTimePassed(
  865. currentSchoolyear, toWeekNum, toWeekday, toCourseTime.StartHour, toCourseTime.StartMinutes)
  866. ))
  867. {
  868. throw new Exception("调整前后的时间均不能早于当前时间,请核对。");
  869. }
  870. var adjustmentQuery = this.EducationSchedulingDAL.GetConflictAdjustmentSchedule(x => educationSchedulingWeekNumIDList.Contains(x.EducationSchedulingWeekNumID),
  871. submitedStatusList, fromUserID, toWeekNum, toWeekday, toUserID, toCoursesTimeID, toClassroom);
  872. var adjustmentConflictList = this.EducationSchedulingDAL.GetSelfClassroomConflictQueryable(adjustmentQuery).ToList()
  873. .Concat(this.EducationSchedulingDAL.GetSelfTeacherConflictQueryable(adjustmentQuery).ToList())
  874. .Concat(this.EducationSchedulingDAL.GetSelfStudentConflictQueryable(adjustmentQuery).ToList()
  875. .GroupBy(w => new { w.EducationSchedulingWeekNumID, w.EducationSchedulingAdjustmentID })
  876. .Select(w => w.FirstOrDefault()).ToList())
  877. .Concat(this.EducationSchedulingDAL.GetSelfConflictQueryable(adjustmentQuery).ToList())
  878. .Concat(this.EducationSchedulingDAL.GetClassroomSeatConflictQueryable(adjustmentQuery).ToList())
  879. .Concat(this.EducationSchedulingDAL.GetClassroomReserveQueryable(adjustmentQuery).ToList())
  880. .Concat(this.EducationSchedulingDAL.GetClassroomScheduleConflicQueryable(adjustmentQuery).ToList())
  881. .Concat(this.EducationSchedulingDAL.GetClassroomConflicQueryable(adjustmentQuery).ToList())
  882. .Concat(this.EducationSchedulingDAL.GetClassroomExcessiveUseQueryable(adjustmentQuery).ToList())
  883. .Concat(this.EducationSchedulingDAL.GetClassroomAdjustmentConflictQueryable(adjustmentQuery, submitedStatusList).ToList())
  884. .Concat(this.EducationSchedulingDAL.GetCourseScheduleConflictQueryable(adjustmentQuery).ToList())
  885. .Concat(this.EducationSchedulingDAL.GetTeacherScheduleConflictQueryable(adjustmentQuery).ToList())
  886. .Concat(this.EducationSchedulingDAL.GetTeacherConflictQueryable(adjustmentQuery).ToList())
  887. .Concat(this.EducationSchedulingDAL.GetTeacherAdjustmentConflictQueryable(adjustmentQuery, submitedStatusList).ToList())
  888. .Concat(this.EducationSchedulingDAL.GetStudentScheduleConflictQueryable(adjustmentQuery).ToList())
  889. .Concat(this.EducationSchedulingDAL.GetStudentConflictQueryable(adjustmentQuery).ToList())
  890. .Concat(this.EducationSchedulingDAL.GetStudentAdjustmentConflictQueryable(adjustmentQuery, submitedStatusList).ToList())
  891. .Concat(this.EducationSchedulingDAL.GetArrangementsQueryable(adjustmentQuery).ToList()).ToList();
  892. //var adjustmentConflictList = this.EducationSchedulingDAL.GetConflictAdjustmentSchedule(x => educationSchedulingWeekNumIDList.Contains(x.EducationSchedulingWeekNumID),
  893. // submitedStatusList, fromUserID, toWeekNum, toWeekday, toUserID, toCoursesTimeID, toClassroom).ToList();
  894. var educationSchedulingWeekNumList = this.EducationSchedulingDAL.EducationSchedulingWeekNumRepository
  895. .GetList(x => educationSchedulingWeekNumIDList.Contains(x.EducationSchedulingWeekNumID),
  896. (x => x.ES_EducationScheduling.EM_CoursesTime),
  897. (x => x.ES_EducationScheduling.EM_EducationSchedulingClass.EM_EducationMissionClass),
  898. (x => x.ES_EducationScheduling.ES_EducationSchedulingTeacher)).ToList();
  899. var dateList = SchoolYearServices.Value.GetDateByCoursesTime(currentSchoolyear.SchoolYearID ?? Guid.Empty,
  900. educationSchedulingWeekNumList.GroupBy(x => new FullCoursesTimeView
  901. {
  902. WeekNum = toWeekNum.HasValue ? toWeekNum : x.WeekNum,
  903. Weekday = toWeekday.HasValue ? toWeekday : x.ES_EducationScheduling.Weekday
  904. }).Select(x => x.Key).ToList());
  905. var examinationPlanList = ExaminationPlanDAL.GetExaminationPlanView(x => dateList.Contains(x.ExaminationDate ?? DateTime.MinValue) && x.SchoolyearID == currentSchoolyear.SchoolYearID
  906. && x.RecordStatus == (int)EX_ExaminationPlanStatus.Submitted).ToList();
  907. var examinationPlanIDList = examinationPlanList.Select(x => x.ExaminationPlanID).ToList();
  908. var examinationRoomLayoutViewList = ExaminationPlanDAL.GetExaminationRoomLayoutView(x => examinationPlanIDList.Contains((Guid)x.ExaminationPlanID)).ToList();
  909. examinationPlanList.ForEach(x => x.ExaminationRoomLayoutView = new HashSet<ExaminationRoomLayoutView>(examinationRoomLayoutViewList.Where(y => y.ExaminationPlanID == x.ExaminationPlanID)));
  910. var firstWeek = currentSchoolyear.FirstWeek.Value.AddDays(1 - (int)currentSchoolyear.FirstWeek.Value.DayOfWeek);
  911. //学年学期还有问题,应该按照提交的记录找出他们的学年学期
  912. adjustmentConflictList = adjustmentConflictList.Concat(
  913. educationSchedulingWeekNumList.Where(x => examinationPlanList.Any(w => SchoolYearServices.Value.GetStartEndTimeByCourseTime(firstWeek, new FullCoursesTimeView
  914. {
  915. WeekNum = toWeekNum.HasValue ? toWeekNum : x.WeekNum,
  916. Weekday = toWeekday.HasValue ? toWeekday : x.ES_EducationScheduling.Weekday,
  917. CoursesTimeID = toCoursesTimeID.HasValue ? toCoursesTimeID : x.ES_EducationScheduling.CoursesTimeID,
  918. StartHour = toCoursesTimeID.HasValue ? toCourseTime.StartHour : x.ES_EducationScheduling.EM_CoursesTime.StartHour,
  919. StartMinute = toCoursesTimeID.HasValue ? toCourseTime.StartMinutes : x.ES_EducationScheduling.EM_CoursesTime.StartMinutes,
  920. EndHour = toCoursesTimeID.HasValue ? toCourseTime.EndHour : x.ES_EducationScheduling.EM_CoursesTime.EndHour,
  921. EndMinute = toCoursesTimeID.HasValue ? toCourseTime.EndMinutes : x.ES_EducationScheduling.EM_CoursesTime.EndMinutes
  922. }).IsOverlap(w.ExaminationDate.Value.Add(w.StartTime.Value), w.ExaminationDate.Value.Add(w.EndTime.Value))
  923. && w.ExaminationRoomLayoutView.Select(v => (Guid?)v.ClassroomID)
  924. .Contains((toClassroom.HasValue ? toClassroom : x.ES_EducationScheduling.ClassroomID)))
  925. ).Select(x => new EducationSchedulingConflictView
  926. {
  927. EducationSchedulingWeekNumID = x.EducationSchedulingWeekNumID,
  928. EducationSchedulingAdjustmentID = null,
  929. EducationMissionClassName = x.ES_EducationScheduling.EM_EducationSchedulingClass.EM_EducationMissionClass.Name,
  930. WeekNum = x.WeekNum,
  931. Weekday = x.ES_EducationScheduling.Weekday,
  932. StartTimes = x.ES_EducationScheduling.EM_CoursesTime.StartTimes,
  933. EndTimes = x.ES_EducationScheduling.EM_CoursesTime.EndTimes,
  934. ClassroomID = x.ES_EducationScheduling.ClassroomID,
  935. Reason = "教室在该节次安排了考试。"
  936. }).ToList()).Concat(
  937. educationSchedulingWeekNumList.Where(x => examinationPlanList.Any(w => SchoolYearServices.Value.GetStartEndTimeByCourseTime(firstWeek, new FullCoursesTimeView
  938. {
  939. WeekNum = toWeekNum.HasValue ? toWeekNum : x.WeekNum,
  940. Weekday = toWeekday.HasValue ? toWeekday : x.ES_EducationScheduling.Weekday,
  941. CoursesTimeID = toCoursesTimeID.HasValue ? toCoursesTimeID : x.ES_EducationScheduling.CoursesTimeID,
  942. StartHour = toCoursesTimeID.HasValue ? toCourseTime.StartHour : x.ES_EducationScheduling.EM_CoursesTime.StartHour,
  943. StartMinute = toCoursesTimeID.HasValue ? toCourseTime.StartMinutes : x.ES_EducationScheduling.EM_CoursesTime.StartMinutes,
  944. EndHour = toCoursesTimeID.HasValue ? toCourseTime.EndHour : x.ES_EducationScheduling.EM_CoursesTime.EndHour,
  945. EndMinute = toCoursesTimeID.HasValue ? toCourseTime.EndMinutes : x.ES_EducationScheduling.EM_CoursesTime.EndMinutes
  946. }).IsOverlap(w.ExaminationDate.Value.Add(w.StartTime.Value), w.ExaminationDate.Value.Add(w.EndTime.Value))
  947. && w.ExaminationRoomLayoutView
  948. .SelectMany(v => v.Sys_User).Select(v => (Guid?)v.UserID)
  949. .Intersect(
  950. x.ES_EducationScheduling.ES_EducationSchedulingTeacher
  951. .Select(v => (toUserID.HasValue ? (v.UserID == fromUserID ? toUserID : (Guid?)v.UserID) : (Guid?)v.UserID))
  952. ).Count() > 0)
  953. ).Select(x => new EducationSchedulingConflictView
  954. {
  955. EducationSchedulingWeekNumID = x.EducationSchedulingWeekNumID,
  956. EducationSchedulingAdjustmentID = null,
  957. EducationMissionClassName = x.ES_EducationScheduling.EM_EducationSchedulingClass.EM_EducationMissionClass.Name,
  958. WeekNum = x.WeekNum,
  959. Weekday = x.ES_EducationScheduling.Weekday,
  960. StartTimes = x.ES_EducationScheduling.EM_CoursesTime.StartTimes,
  961. EndTimes = x.ES_EducationScheduling.EM_CoursesTime.EndTimes,
  962. ClassroomID = x.ES_EducationScheduling.ClassroomID,
  963. Reason = "教师在该节次安排了考试。"
  964. }).ToList()).Concat(
  965. educationSchedulingWeekNumList.Where(x => examinationPlanList.Any(w => SchoolYearServices.Value.GetStartEndTimeByCourseTime(firstWeek, new FullCoursesTimeView
  966. {
  967. WeekNum = toWeekNum.HasValue ? toWeekNum : x.WeekNum,
  968. Weekday = toWeekday.HasValue ? toWeekday : x.ES_EducationScheduling.Weekday,
  969. CoursesTimeID = toCoursesTimeID.HasValue ? toCoursesTimeID : x.ES_EducationScheduling.CoursesTimeID,
  970. StartHour = toCoursesTimeID.HasValue ? toCourseTime.StartHour : x.ES_EducationScheduling.EM_CoursesTime.StartHour,
  971. StartMinute = toCoursesTimeID.HasValue ? toCourseTime.StartMinutes : x.ES_EducationScheduling.EM_CoursesTime.StartMinutes,
  972. EndHour = toCoursesTimeID.HasValue ? toCourseTime.EndHour : x.ES_EducationScheduling.EM_CoursesTime.EndHour,
  973. EndMinute = toCoursesTimeID.HasValue ? toCourseTime.EndMinutes : x.ES_EducationScheduling.EM_CoursesTime.EndMinutes
  974. }).IsOverlap(w.ExaminationDate.Value.Add(w.StartTime.Value), w.ExaminationDate.Value.Add(w.EndTime.Value))
  975. && w.ExaminationRoomLayoutView
  976. .SelectMany(v => v.EX_ExaminationRoomStudent).Select(v => v.UserID)
  977. .Intersect(x.ES_EducationScheduling.EM_EducationSchedulingClass.CF_Student.Select(v => (Guid?)v.UserID)).Count() > 0)
  978. ).Select(x => new EducationSchedulingConflictView
  979. {
  980. EducationSchedulingWeekNumID = x.EducationSchedulingWeekNumID,
  981. EducationSchedulingAdjustmentID = null,
  982. EducationMissionClassName = x.ES_EducationScheduling.EM_EducationSchedulingClass.EM_EducationMissionClass.Name,
  983. WeekNum = x.WeekNum,
  984. Weekday = x.ES_EducationScheduling.Weekday,
  985. StartTimes = x.ES_EducationScheduling.EM_CoursesTime.StartTimes,
  986. EndTimes = x.ES_EducationScheduling.EM_CoursesTime.EndTimes,
  987. ClassroomID = x.ES_EducationScheduling.ClassroomID,
  988. Reason = "学生在该节次安排了考试。"
  989. }).ToList()).ToList();
  990. if (adjustmentConflictList.Count > 0)
  991. {
  992. var errorMessage = string.Join(";", adjustmentConflictList.Select(x =>
  993. string.Format("{0}第{1}周星期{2}的{3}-{4}节调整失败,原因:{5}",
  994. x.EducationMissionClassName, x.WeekNum, WeekDayView.GetWeekdayName(x.Weekday), x.StartTimes, x.EndTimes, x.Reason)
  995. ));
  996. throw new Exception(errorMessage);
  997. }
  998. if (educationSchedulingWeekNumList.Count != educationSchedulingWeekNumIDList.Count)
  999. {
  1000. throw new Exception("所选部分排课记录不存在,可能已经被修改,请重新查询排课列表并选择。");
  1001. }
  1002. List<ES_EducationSchedulingAdjustment> insertList = new List<ES_EducationSchedulingAdjustment>();
  1003. List<ES_EducationSchedulingAdjustmentTeacher> fromTeacherInsertList = new List<ES_EducationSchedulingAdjustmentTeacher>();
  1004. List<ES_EducationSchedulingAdjustmentToTeacher> toTeacherInsertList = new List<ES_EducationSchedulingAdjustmentToTeacher>();
  1005. foreach (var educationSchedulingWeekNum in educationSchedulingWeekNumList)
  1006. {
  1007. var scheduleAdjustment = new ES_EducationSchedulingAdjustment();
  1008. {
  1009. scheduleAdjustment.EducationSchedulingAdjustmentID = Guid.NewGuid();
  1010. this.SetNewStatus(scheduleAdjustment);
  1011. scheduleAdjustment.RecordStatus = startStatusID;
  1012. insertList.Add(scheduleAdjustment);
  1013. }
  1014. scheduleAdjustment.EducationMissionClassID = educationSchedulingWeekNum
  1015. .ES_EducationScheduling
  1016. .EM_EducationSchedulingClass
  1017. .EducationMissionClassID;
  1018. scheduleAdjustment.Weekday = educationSchedulingWeekNum
  1019. .ES_EducationScheduling
  1020. .Weekday;
  1021. scheduleAdjustment.CoursesTimeID = educationSchedulingWeekNum
  1022. .ES_EducationScheduling
  1023. .CoursesTimeID;
  1024. scheduleAdjustment.ClassroomTypeID = educationSchedulingWeekNum
  1025. .ES_EducationScheduling
  1026. .EM_EducationSchedulingClass
  1027. .EM_EducationMissionClass
  1028. .ClassroomTypeID;
  1029. scheduleAdjustment.ClassroomID = educationSchedulingWeekNum
  1030. .ES_EducationScheduling
  1031. .ClassroomID;
  1032. scheduleAdjustment.UserID = fromUserID;
  1033. scheduleAdjustment.ToWeekday = toWeekday.HasValue ? toWeekday : educationSchedulingWeekNum
  1034. .ES_EducationScheduling
  1035. .Weekday;
  1036. scheduleAdjustment.ToCoursesTimeID = toCoursesTimeID.HasValue ? toCoursesTimeID : educationSchedulingWeekNum
  1037. .ES_EducationScheduling
  1038. .CoursesTimeID;
  1039. scheduleAdjustment.ToClassroomTypeID = toClassroomType.HasValue ? toClassroomType : educationSchedulingWeekNum
  1040. .ES_EducationScheduling
  1041. .EM_EducationSchedulingClass
  1042. .EM_EducationMissionClass
  1043. .ClassroomTypeID;
  1044. scheduleAdjustment.ToClassroomID = toClassroom.HasValue ? toClassroom : educationSchedulingWeekNum
  1045. .ES_EducationScheduling
  1046. .ClassroomID;
  1047. scheduleAdjustment.ToUserID = toUserID.HasValue ? toUserID : fromUserID;
  1048. scheduleAdjustment.WeekNum = educationSchedulingWeekNum.WeekNum;
  1049. scheduleAdjustment.ToWeekNum = toWeekNum.HasValue ? toWeekNum : educationSchedulingWeekNum.WeekNum;
  1050. foreach (var teacher in educationSchedulingWeekNum.ES_EducationScheduling.ES_EducationSchedulingTeacher)
  1051. {
  1052. var fromTeacher = new ES_EducationSchedulingAdjustmentTeacher();
  1053. fromTeacher.EducationSchedulingAdjustmentTeacherID = Guid.NewGuid();
  1054. fromTeacher.EducationSchedulingAdjustmentID = scheduleAdjustment.EducationSchedulingAdjustmentID;
  1055. fromTeacher.UserID = teacher.UserID;
  1056. fromTeacher.TeachingMethod = teacher.TeachingMethod;
  1057. this.SetNewStatus(fromTeacher);
  1058. fromTeacherInsertList.Add(fromTeacher);
  1059. }
  1060. foreach (var teacher in educationSchedulingWeekNum.ES_EducationScheduling.ES_EducationSchedulingTeacher)
  1061. {
  1062. var toTeacher = new ES_EducationSchedulingAdjustmentToTeacher();
  1063. toTeacher.EducationSchedulingAdjustmentToTeacherID = Guid.NewGuid();
  1064. toTeacher.EducationSchedulingAdjustmentID = scheduleAdjustment.EducationSchedulingAdjustmentID;
  1065. toTeacher.UserID = (teacher.UserID == scheduleAdjustment.UserID && scheduleAdjustment.ToUserID.HasValue) ? scheduleAdjustment.ToUserID : teacher.UserID;
  1066. toTeacher.TeachingMethod = teacher.TeachingMethod;
  1067. this.SetNewStatus(toTeacher);
  1068. toTeacherInsertList.Add(toTeacher);
  1069. }
  1070. }
  1071. using (var scope = new TransactionScope())
  1072. {
  1073. UnitOfWork.BulkInsert(insertList);
  1074. UnitOfWork.BulkInsert(fromTeacherInsertList);
  1075. UnitOfWork.BulkInsert(toTeacherInsertList);
  1076. scope.Complete();
  1077. }
  1078. }
  1079. }
  1080. }