ScheduleServices.cs 130 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using System.Data.Entity;
  7. using Bowin.Common.Linq;
  8. using Bowin.Common.Linq.Entity;
  9. using EMIS.DataLogic.Common.CalendarManage;
  10. using EMIS.CommonLogic.CalendarManage;
  11. using EMIS.DataLogic.EducationSchedule;
  12. using Bowin.Common.Log;
  13. using EMIS.ViewModel.CalendarManage;
  14. using EMIS.ViewModel;
  15. using EMIS.ViewModel.UniversityManage.ClassroomManage;
  16. using EMIS.Entities;
  17. using EMIS.CommonLogic.EducationManage;
  18. using EMIS.ViewModel.EducationManage;
  19. using EMIS.ViewModel.EducationSchedule;
  20. using EMIS.CommonLogic.SystemServices;
  21. using EMIS.DataLogic.UniversityManage.ClassroomManage;
  22. using EMIS.DataLogic.Common.Cultureplan;
  23. using EMIS.DataLogic.EducationManage;
  24. using EMIS.DataLogic.UniversityManage.TeacherManage;
  25. using EMIS.ViewModel.UniversityManage.TeacherManage;
  26. using EMIS.Utility;
  27. using EMIS.CommonLogic.SchedulingManage.ScheduleApproval;
  28. using EMIS.CommonLogic.SchedulingManage.SchedulingSettings;
  29. using EMIS.DataLogic.SchedulingManage.SchedulingSettings;
  30. using EMIS.ViewModel.Students;
  31. using EMIS.DataLogic.Common.Students;
  32. using EMIS.ViewModel.SchedulingManage.ScheduleApproval;
  33. using EMIS.Utility.FormValidate;
  34. using EMIS.ViewModel.EducationManagement;
  35. using EMIS.DataLogic.ExaminationManage;
  36. using EMIS.ViewModel.ExaminationManage;
  37. using EMIS.ViewModel.UniversityManage.AdministrativeOrgan;
  38. namespace EMIS.CommonLogic.EducationSchedule
  39. {
  40. /// <summary>
  41. /// 排课服务(前方高能,阅读小心……)
  42. /// </summary>
  43. public class ScheduleServices : BaseServices, IScheduleServices
  44. {
  45. public CollegeScheduleDAL CollegeScheduleDAL { get; set; }
  46. public CollegePriorityDAL CollegePriorityDAL { get; set; }
  47. public ClassroomDAL ClassroomDAL { get; set; }
  48. public ClassroomExcessiveUseDAL ClassroomExcessiveUseDAL { get; set; }
  49. public StaffDAL StaffDAL { get; set; }
  50. public ClassroomScheduleDAL ClassroomScheduleDAL { get; set; }
  51. public CourseScheduleDAL CourseScheduleDAL { get; set; }
  52. public CourseTypeScheduleDAL CourseTypeScheduleDAL { get; set; }
  53. public TeacherScheduleDAL TeacherScheduleDAL { get; set; }
  54. public ArrangementDAL ArrangementDAL { get; set; }
  55. public EducationSchedulingDAL EducationSchedulingDAL { get; set; }
  56. public EducationSchedulingClassDAL EducationSchedulingClassDAL { get; set; }
  57. public EducationMissionClassDAL EducationMissionClassDAL { get; set; }
  58. public CoursematerialDAL CoursematerialDAL { get; set; }
  59. public StudentsDAL StudentsDAL { get; set; }
  60. public ExaminationPlanDAL ExaminationPlanDAL { get; set; }
  61. public Lazy<ICoursesTimeServices> CoursesTimeServices { get; set; }
  62. public Lazy<ISchoolYearServices> SchoolYearServices { get; set; }
  63. public Lazy<IEducationSchedulingClassServices> EducationSchedulingClassServices { get; set; }
  64. public Lazy<IParameterServices> ParameterServices { get; set; }
  65. public Lazy<ICollegeScheduleApprovalServices> CollegeScheduleApprovalServices { get; set; }
  66. public Lazy<IEducationSchedulingStopServices> EducationSchedulingStopServices { get; set; }
  67. private int? TeacherScheduleContinuousCount { get; set; }
  68. private int? ClassScheduleContinuousCount { get; set; }
  69. private int? ClassCourseScheduleContinuousCount { get; set; }
  70. private SchoolYearView SchoolYear { get; set; }
  71. private CalendarView CalendarView { get; set; }
  72. private List<CollegeView> CollegeList { get; set; }
  73. private List<ClassroomView> ClassroomList { get; set; }
  74. private List<CF_Staff> StaffList { get; set; }
  75. private List<ES_CollegeClassroom> CollegeClassroomList { get; set; }
  76. private List<ES_CourseTypePriority> CourseTypePriorityList { get; set; }
  77. private List<CoursesTimeView> CourseTimeList { get; set; }
  78. private List<ArrangementView> ArrangementList { get; set; }
  79. private List<ES_CourseScheduleSetting> CourseSchedulingSettingList { get; set; }
  80. private List<ES_TeacherScheduleSetting> TeacherSchedulingSettingList { get; set; }
  81. private List<ES_ClassroomScheduleSetting> ClassroomSchedulingSettingList { get; set; }
  82. private List<EducationSchedulingClassScheduleView> EducationSchedulingClassViewList { get; set; }
  83. private List<EducationSchedulingClassStudentView> EducationSchedulingClassStudentViewList { get; set; }
  84. private List<EducationSchedulingView> ScheduledEducationViewList { get; set; }
  85. private List<EducationSchedulingClassStudentView> ScheduledEducationStudentViewList { get; set; }
  86. //结果列表
  87. private List<ES_EducationScheduling> SchedulingResult { get; set; }
  88. private List<ES_EducationSchedulingWeekNum> SchedulingWeekNumResult { get; set; }
  89. private List<ES_EducationSchedulingTeacher> SchedulingTeacherResult { get; set; }
  90. //失败列表
  91. private List<EducationSchedulingClassScheduleView> NotScheduledList { get; set; }
  92. private void InitCommonInfo()
  93. {
  94. SchedulingResult = new List<ES_EducationScheduling>(); //初始化排课结果
  95. SchedulingWeekNumResult = new List<ES_EducationSchedulingWeekNum>();
  96. SchedulingTeacherResult = new List<ES_EducationSchedulingTeacher>();
  97. NotScheduledList = new List<EducationSchedulingClassScheduleView>();
  98. LogHelper.WriteLog(LogType.ServiceLog, "开始获取学年学期。");
  99. SchoolYear = SchoolYearServices.Value.GetNextSchoolYear();
  100. LogHelper.WriteLog(LogType.ServiceLog, "开始获取课程时间。");
  101. CourseTimeList = CoursesTimeServices.Value.GetCoursesTimeViewList(new ConfiguretView(), null);
  102. CourseTimeList = CourseTimeList.OrderBy(x => x.StartTimes).ToList();
  103. LogHelper.WriteLog(LogType.ServiceLog, "开始获取周工作时间表。");
  104. ArrangementList = ArrangementDAL.GetArrangementView(x => x.IsOnWork == true).ToList();
  105. LogHelper.WriteLog(LogType.ServiceLog, "开始获取课程可排时间设定。");
  106. StaffList = StaffDAL.staffRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  107. LogHelper.WriteLog(LogType.ServiceLog, "开始获取教师信息。");
  108. CourseSchedulingSettingList = CourseScheduleDAL.CourseScheduleSettingRepository
  109. .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  110. LogHelper.WriteLog(LogType.ServiceLog, "开始获取教师可排时间设定。");
  111. TeacherSchedulingSettingList = TeacherScheduleDAL.TeacherScheduleSettingRepository
  112. .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  113. LogHelper.WriteLog(LogType.ServiceLog, "开始获取课程类型优先级设置。");
  114. CourseTypePriorityList = this.CourseTypeScheduleDAL.CourseTypePriorityRepository.Entities.ToList();
  115. LogHelper.WriteLog(LogType.ServiceLog, "开始获取连续上课限制");
  116. TeacherScheduleContinuousCount = this.ParameterServices.Value.GetParameterValue<int>(CF_ParameterType.TeacherScheduleContinuousCount);
  117. ClassScheduleContinuousCount = this.ParameterServices.Value.GetParameterValue<int>(CF_ParameterType.ClassScheduleContinuousCount);
  118. ClassCourseScheduleContinuousCount = this.ParameterServices.Value.GetParameterValue<int>(CF_ParameterType.ClassCourseScheduleContinuousCount);
  119. }
  120. private void InitScheduleClassInfo()
  121. {
  122. LogHelper.WriteLog(LogType.ServiceLog, "开始获取排课" + RSL.Get("College") + "。");
  123. CollegeList = CollegeScheduleDAL.GetCollegeViewByTime(DateTime.Now).ToList();
  124. var collegeIDList = CollegeList.Select(x => (Guid?)x.CollegeID).ToList();
  125. LogHelper.WriteLog(LogType.ServiceLog, "开始获取任务班。");
  126. EducationSchedulingClassViewList = EducationSchedulingClassServices.Value
  127. .GetEducationSchedulingClassViewList(SchoolYear.SchoolYearID.Value, collegeIDList);
  128. EducationSchedulingClassStudentViewList = EducationSchedulingClassServices.Value
  129. .GetEducationSchedulingClassStudentViewList(SchoolYear.SchoolYearID.Value, collegeIDList);
  130. LogHelper.WriteLog(LogType.ServiceLog, "开始获取本学期已排任务。");
  131. ScheduledEducationViewList = this.GetEducationScheduleView(new ConfiguretView(), (x => x.SchoolyearID == SchoolYear.SchoolYearID), false).rows;
  132. var scheduledEducationClassIDList = ScheduledEducationViewList.Select(x => x.EducationSchedulingClassID).Distinct().ToList();
  133. ScheduledEducationStudentViewList = EducationSchedulingClassDAL
  134. .GetEducationSchedulingClassStudentViewQueryable(x => scheduledEducationClassIDList.Contains(x.EducationSchedulingClassID))
  135. .ToList();
  136. EducationSchedulingClassViewList = (from escv in EducationSchedulingClassViewList
  137. join sevl in ScheduledEducationViewList on escv.EducationSchedulingClassID equals sevl.EducationSchedulingClassID
  138. into dsevl
  139. from esevl in dsevl.DefaultIfEmpty()
  140. where esevl == null
  141. select escv).ToList();
  142. }
  143. private void InitClassroomInfo()
  144. {
  145. LogHelper.WriteLog(LogType.ServiceLog, "开始获取可排教室。");
  146. ClassroomList = ClassroomScheduleDAL.GetAvailableClassroom().ToList();
  147. var classroomIDList = ClassroomList.Select(x => x.ClassroomID).Distinct().ToList();
  148. var classroomTypeList = ClassroomDAL.classroomTypeRepository.GetList(x => classroomIDList.Contains(x.ClassroomID)).ToList();
  149. ClassroomList.ForEach(x => x.ClassroomTypeID = classroomTypeList.Where(w => w.ClassroomID == x.ClassroomID)
  150. .Select(w => w.ClassroomType ?? -1).ToList());
  151. LogHelper.WriteLog(LogType.ServiceLog, "开始获取教室可排时间设定。");
  152. ClassroomSchedulingSettingList = ClassroomScheduleDAL.ClassroomScheduleSettingRepository
  153. .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  154. LogHelper.WriteLog(LogType.ServiceLog, "开始获取" + RSL.Get("College") + "分配教室设置。");
  155. CollegeClassroomList = ClassroomScheduleDAL.CollegeClassroomRepository.Entities.ToList();
  156. }
  157. private void InitSchedule()
  158. {
  159. InitCommonInfo();
  160. InitScheduleClassInfo();
  161. InitClassroomInfo();
  162. }
  163. /// <summary>
  164. /// 获取所有排课记录的方法
  165. /// </summary>
  166. /// <param name="configuretView"></param>
  167. /// <param name="exp"></param>
  168. private IGridResultSet<EducationSchedulingView> GetEducationScheduleView(ConfiguretView configuretView,
  169. Expression<Func<ES_EducationScheduling, bool>> exp, bool isNeedDataRange = true, int? pageIndex = null, int? pageSize = null)
  170. {
  171. var educationScheduleViewQueryable = this.EducationSchedulingDAL.GetEducationSchedulingViewQueryable(exp);
  172. var educationScheduleWeekNumQueryable = this.EducationSchedulingDAL.GetEducationMissionWeekNumQueryable(exp);
  173. var classMajorQueryable = this.EducationSchedulingDAL.GetClassmajorQueryable(exp);
  174. var teacherViewQueryable = this.EducationSchedulingDAL.GetTeacherViewQueryable(exp);
  175. var courseProcessQueryable = this.EducationSchedulingDAL.GetCourseProcessQueryable(exp);
  176. var courseProcessTeacherQueryable = this.EducationSchedulingDAL.GetCourseProcessTeacherViewQueryable(exp);
  177. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  178. {
  179. educationScheduleViewQueryable = educationScheduleViewQueryable
  180. .DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  181. }
  182. if (isNeedDataRange)
  183. {
  184. educationScheduleViewQueryable = this.GetQueryByDataRangeByCollege(educationScheduleViewQueryable);
  185. }
  186. IGridResultSet<EducationSchedulingView> result;
  187. List<ES_EducationSchedulingWeekNum> educationScheduleWeekNumList;
  188. List<EducationMissionClassContainClassView> classMajorList;
  189. List<EducationSchedulingTeacherListView> teacherViewList;
  190. List<CourseProcessView> courseProcessList;
  191. var startStatus = CollegeScheduleApprovalServices.Value.GetStartStatus();
  192. var collegeScheduleApprovalViewList = new List<CollegeScheduleApprovalView>();
  193. if (pageIndex.HasValue && pageSize.HasValue)
  194. {
  195. result = educationScheduleViewQueryable.OrderBy(x => x.Weekday).ThenBy(x => x.CoursesTime.StartTimes)
  196. .ToGridResultSet(pageIndex, pageSize);
  197. //由于分页后数据量较少,可以考虑用Contains方法在数据库端筛选一下,不分页的情况就不要了
  198. var educationMissionClassIDList = result.rows.Select(x => x.EducationMissionClassID).ToList();
  199. var educationSchedulingIDList = result.rows.Select(x => (Guid?)x.EducationSchedulingID).ToList();
  200. collegeScheduleApprovalViewList = CollegeScheduleApprovalServices.Value.GetCollegeScheduleApprovalViewList(
  201. result.rows.GroupBy(x => new { x.CourseCollegeID, x.SchoolyearID })
  202. .Select(x => new CollegeSchoolyearView { CollegeID = x.Key.CourseCollegeID.Value, SchoolyearID = x.Key.SchoolyearID.Value }).ToList()
  203. , isNeedDataRange);
  204. teacherViewList = teacherViewQueryable.Where(x => educationSchedulingIDList.Contains(x.EducationSchedulingID)).Distinct().ToList();
  205. classMajorList = classMajorQueryable.Where(x => educationMissionClassIDList.Contains(x.EducationMissionClassID)).Distinct().ToList();
  206. educationScheduleWeekNumList = educationScheduleWeekNumQueryable
  207. .Where(x => educationSchedulingIDList.Contains(x.EducationSchedulingID)).Distinct().ToList();
  208. courseProcessList = courseProcessQueryable.Where(x => educationMissionClassIDList.Contains(x.EducationMissionClassID)).Distinct().ToList();
  209. var courseProcessTeacherViewList = courseProcessTeacherQueryable.Where(x => educationMissionClassIDList.Contains(x.EducationMissionClassID)).Distinct().ToList();
  210. courseProcessList.ForEach(x => x.CourseProcessTeacherViewList = courseProcessTeacherViewList.Where(w => w.CourseProcessID == x.CourseProcessID)
  211. .OrderBy(w => w.TeachingMethod).ThenBy(w => w.Name).ToList());
  212. }
  213. else
  214. {
  215. var list = educationScheduleViewQueryable.ToList();
  216. result = new GridResultSet<EducationSchedulingView>() { rows = list, total = list.Count };
  217. collegeScheduleApprovalViewList = CollegeScheduleApprovalServices.Value.GetCollegeScheduleApprovalViewList(
  218. result.rows.GroupBy(x => new { x.CourseCollegeID, x.SchoolyearID })
  219. .Select(x => new CollegeSchoolyearView { CollegeID = x.Key.CourseCollegeID.Value, SchoolyearID = x.Key.SchoolyearID.Value }).ToList()
  220. , isNeedDataRange);
  221. teacherViewList = teacherViewQueryable.Distinct().ToList();
  222. classMajorList = classMajorQueryable.Distinct().ToList();
  223. educationScheduleWeekNumList = educationScheduleWeekNumQueryable.Distinct().ToList();
  224. courseProcessList = courseProcessQueryable.Distinct().ToList();
  225. var courseProcessTeacherViewList = courseProcessTeacherQueryable.Distinct().ToList();
  226. courseProcessList.ForEach(x => x.CourseProcessTeacherViewList = courseProcessTeacherViewList.Where(w => w.CourseProcessID == x.CourseProcessID)
  227. .OrderBy(w => w.TeachingMethod).ThenBy(w => w.Name).ToList());
  228. }
  229. var submitedCollegeScheduleApprovalViewList = collegeScheduleApprovalViewList.Where(x => x.CollegeScheduleStatusID.HasValue).ToList();
  230. result.rows.ForEach(x =>
  231. {
  232. var collegeScheduleApprovalView = submitedCollegeScheduleApprovalViewList.FirstOrDefault(w => w.CollegeID == x.CourseCollegeID && w.SchoolyearID == x.SchoolyearID);
  233. x.TeacherTeachingViewList = teacherViewList
  234. .Where(w => x.EducationSchedulingID == w.EducationSchedulingID)
  235. .OrderBy(w => w.TeachingMethod).ThenBy(w => w.Name)
  236. .Select(w => (BaseTeacherTeachingView)w).ToList();
  237. x.WeekNumList = educationScheduleWeekNumList.Where(w => x.EducationSchedulingID == w.EducationSchedulingID)
  238. .Select(w => w.WeekNum).ToList();
  239. x.ClassMajorIDList = classMajorList.Where(w => x.EducationMissionClassID == w.EducationMissionClassID)
  240. .Select(w => w.ClassMajor.ClassmajorID).ToList();
  241. x.CourseProcessViewList = courseProcessList.Where(w => x.EducationMissionClassID == w.EducationMissionClassID)
  242. .ToList();
  243. x.IsCanEdit = x.IsCanEdit && (collegeScheduleApprovalView == null || collegeScheduleApprovalView.RecordStatus == startStatus);
  244. });
  245. return result;
  246. }
  247. private List<EducationSchedulingClassScheduleView> GetOrderedEducationSchedulingClassViewList(
  248. IList<EducationSchedulingClassScheduleView> educationSchedulingClassViewList)
  249. {
  250. var result = (from escv in educationSchedulingClassViewList
  251. select new {
  252. EducationSchedulingClassView = escv,
  253. //课程类型优先级
  254. CourseTypeOrderID = this.CourseTypePriorityList.Where(x => x.CourseTypeID == escv.CourseTypeID)
  255. .Select(x => x.Priority).FirstOrDefault(),
  256. //上课周数优先级(总上课周数大的不好排,要优先安排)
  257. WeekCountOrderID = escv.WeeklyNumList.Count,
  258. //涉及学籍班多的不好排,要先排
  259. ClassmajorCount = (escv.ClassMajorIDList == null) ? 0 : escv.ClassMajorIDList.Count,
  260. //指定教室优先级
  261. AssignClassroomOrderID = (escv.ClassroomID.HasValue ? 1 : 0),
  262. //涉及学生多的不好排,要先排
  263. StudentNum = escv.StudentNum
  264. }).OrderBy(x => x.CourseTypeOrderID)
  265. .ThenBy(x => x.EducationSchedulingClassView.CoursematerialName)
  266. .ThenBy(x => x.EducationSchedulingClassView.EducationMissionClassOrderNo)
  267. //.ThenBy(x => x.EducationSchedulingClassView.EducationMissionClassName)
  268. .ThenByDescending(x => x.ClassmajorCount)
  269. .ThenByDescending(x => x.AssignClassroomOrderID)
  270. .ThenByDescending(x => x.StudentNum)
  271. .ThenByDescending(x => x.WeekCountOrderID)
  272. .Select(x => x.EducationSchedulingClassView).ToList();
  273. return result;
  274. }
  275. private List<ClassroomView> GetCurrentClassroomViewList(int weekday, CoursesTimeView courseTime, IList<int?> schedulingWeekList)
  276. {
  277. var fullSchedulingResult = (from sr in this.SchedulingResult
  278. from swnr in sr.ES_EducationSchedulingWeekNum
  279. select new
  280. {
  281. SchedulingResult = sr,
  282. SchedulingWeekNumResult = swnr
  283. });
  284. //两个条件:1、当前时间点可排,2:当前时间点未被使用
  285. var result = (from r in this.ClassroomList
  286. join css in this.ClassroomSchedulingSettingList
  287. on new { r.ClassroomID, Weekday = (int?)weekday, courseTime.CoursesTimeID } equals
  288. new { css.ClassroomID, css.Weekday, css.CoursesTimeID }
  289. into dcss
  290. from ecss in dcss.DefaultIfEmpty()
  291. where (ecss == null || ecss.IsOnWork == true) //当前时间点可排
  292. && !this.ScheduledEducationViewList.Any(x => x.Weekday == weekday
  293. && x.CoursesTimeID == courseTime.CoursesTimeID
  294. && x.WeekNumList.Any(w => schedulingWeekList.Contains(w))
  295. && x.ClassroomID == r.ClassroomID)
  296. && !fullSchedulingResult.Any(x => x.SchedulingResult.Weekday == weekday
  297. && x.SchedulingResult.CoursesTimeID == courseTime.CoursesTimeID
  298. && schedulingWeekList.Contains(x.SchedulingWeekNumResult.WeekNum)
  299. && x.SchedulingResult.ClassroomID == r.ClassroomID) //当前时间点未被使用
  300. select r);
  301. return result.ToList();
  302. }
  303. private List<ClassroomView> GetOrderedClassroomViewList(List<ClassroomView> classroomViewList, Guid collegeID)
  304. {
  305. var result = (from r in classroomViewList
  306. join ccl in this.CollegeClassroomList
  307. on new { CollegeID = (Guid?)collegeID, r.ClassroomID } equals
  308. new { ccl.CollegeID, ccl.ClassroomID }
  309. where (ccl.CollegeID == collegeID)
  310. select new
  311. {
  312. ClassroomView = r,
  313. CollegeClassroom = ccl
  314. })
  315. .OrderBy(x => x.ClassroomView.Totalseating)
  316. .ThenBy(x => x.ClassroomView.Name).Select(x => x.ClassroomView);
  317. return result.ToList();
  318. }
  319. private bool IsEducationSchedulingClassCanAddSchedule(EducationSchedulingClassScheduleView currentScheduleClass,
  320. int weekday, CoursesTimeView courseTime, List<CourseProcessView> courseProcessViewList, List<Guid?> currentStaffIDList,
  321. Guid? currentClassroomID)
  322. {
  323. var weekNumList = courseProcessViewList.Select(x => x.Week);
  324. //检查课程在该节次是否可以上课
  325. //(需要在课程时间设置那里将每次保存的全部记录,不管是否勾选都保存起来,否则这个逻辑就会失效,以下其他设置同理)
  326. var courseSchedulingSettingList = (from css in this.CourseSchedulingSettingList
  327. where css.CoursematerialID == currentScheduleClass.CoursematerialID
  328. && css.Weekday == weekday && css.CoursesTimeID == courseTime.CoursesTimeID
  329. && css.IsOnWork == false
  330. select css
  331. ).ToList();
  332. if (courseSchedulingSettingList.Count > 0)
  333. {
  334. return false;
  335. }
  336. //检查各任课老师在该节次是否可以上课
  337. var teacherSchedulingSettingList = (from t in currentStaffIDList
  338. join tss in this.TeacherSchedulingSettingList
  339. on new { UserID = t, Weekday = (int?)weekday, courseTime.CoursesTimeID } equals
  340. new { tss.UserID, tss.Weekday, tss.CoursesTimeID }
  341. where tss.IsOnWork == false
  342. select t
  343. ).ToList();
  344. if (teacherSchedulingSettingList.Count > 0)
  345. {
  346. return false;
  347. }
  348. //检查指定教室在该节次是否可以上课
  349. if (currentClassroomID.HasValue)
  350. {
  351. var classroomSchedulingSettingList = (from css in this.ClassroomSchedulingSettingList
  352. where css.ClassroomID == currentClassroomID
  353. && css.Weekday == weekday && css.CoursesTimeID == courseTime.CoursesTimeID
  354. && css.IsOnWork == false
  355. select css
  356. ).ToList();
  357. if (classroomSchedulingSettingList.Count > 0)
  358. {
  359. return false;
  360. }
  361. }
  362. //教师是否忙
  363. //第一步
  364. //从排课结果数组(SchedulingResult)中获取除自身外的其他排课班,并带出它们的教师列表,
  365. // 检测是否有和目前周次有交集的,排课班上课周次取排课结果的周次数组(SchedulingWeekNumResult)
  366. //从之前已有的排课记录(ScheduledEducationViewList)中获取排课班,并带出它们的教师列表,
  367. // 检测是否有和目前周次有交集的,排课班上课周次取排课表中的周次(ScheduledEducationViewList.WeekNumList)
  368. //这一步结束后并未确定教师冲突,只是获取出同一周次所有教师的班表
  369. var teacherWorkTimeList = (
  370. from sr in SchedulingResult
  371. .Where(x => x.EducationSchedulingClassID != currentScheduleClass.EducationSchedulingClassID)
  372. join srs in SchedulingTeacherResult on sr.EducationSchedulingID equals srs.EducationSchedulingID
  373. where SchedulingWeekNumResult.Where(x => x.EducationSchedulingID == sr.EducationSchedulingID).Select(x => x.WeekNum)
  374. .Intersect(weekNumList).Count() > 0
  375. select new { sr.Weekday, sr.CoursesTimeID, srs.UserID }
  376. ).Concat(
  377. from esv in this.ScheduledEducationViewList
  378. .Where(x => x.EducationSchedulingClassID != currentScheduleClass.EducationSchedulingClassID)
  379. from ttvl in esv.TeacherTeachingViewList
  380. where esv.WeekNumList.Intersect(weekNumList).Count() > 0
  381. select new { esv.Weekday, esv.CoursesTimeID, UserID = (Guid?)ttvl.UserID }
  382. ).ToList();
  383. //第二步
  384. //从第一步的结果中找出具体星期几第几节都和本任务相同的记录,如果有则可以确定教师时间冲突
  385. var teacherUsedList = (from srttvl in teacherWorkTimeList
  386. join csid in currentStaffIDList
  387. on srttvl.UserID equals csid
  388. where srttvl.Weekday == weekday && srttvl.CoursesTimeID == courseTime.CoursesTimeID
  389. select srttvl).ToList();
  390. if (teacherUsedList.Count > 0)
  391. {
  392. return false;
  393. }
  394. //学生是否忙
  395. var studentUsedList = (from c in (
  396. (from sr in SchedulingResult
  397. .Where(x => x.EducationSchedulingClassID != currentScheduleClass.EducationSchedulingClassID)
  398. join escv in EducationSchedulingClassViewList
  399. on sr.EducationSchedulingClassID equals escv.EducationSchedulingClassID
  400. join s in EducationSchedulingClassStudentViewList on sr.EducationSchedulingClassID equals s.EducationSchedulingClassID
  401. where SchedulingWeekNumResult.Where(x => x.EducationSchedulingID == sr.EducationSchedulingID)
  402. .Select(x => x.WeekNum)
  403. .Intersect(weekNumList).Count() > 0
  404. select new { sr.Weekday, sr.CoursesTimeID, UserID = s.UserID }
  405. ).Concat(
  406. from esv in this.ScheduledEducationViewList
  407. .Where(x => x.EducationSchedulingClassID != currentScheduleClass.EducationSchedulingClassID)
  408. join s in ScheduledEducationStudentViewList on esv.EducationSchedulingClassID equals s.EducationSchedulingClassID
  409. where esv.WeekNumList.Intersect(weekNumList).Count() > 0
  410. select new { esv.Weekday, esv.CoursesTimeID, UserID = s.UserID })
  411. )
  412. join cc in EducationSchedulingClassStudentViewList.Where(x => x.EducationSchedulingClassID == currentScheduleClass.EducationSchedulingClassID)
  413. on c.UserID equals cc.UserID
  414. where c.Weekday == weekday && c.CoursesTimeID == courseTime.CoursesTimeID
  415. select c).ToList();
  416. if (studentUsedList.Count > 0)
  417. {
  418. return false;
  419. }
  420. #region 检查指定教室的冲突(没有指定就跳过)
  421. if (currentClassroomID.HasValue)
  422. {
  423. var currentClassroom = this.ClassroomList.FirstOrDefault(x => x.ClassroomID == currentClassroomID);
  424. //一般会找不到都是因为指定的教室被预留了,这种情况不能排
  425. if (currentClassroom == null)
  426. {
  427. return false;
  428. }
  429. if (currentClassroom.IsConcurrentUse != true)
  430. {
  431. var classroomScheduleList = (from c in
  432. (
  433. (from sr in SchedulingResult
  434. .Where(x => x.EducationSchedulingClassID != currentScheduleClass.EducationSchedulingClassID)
  435. join escv in EducationSchedulingClassViewList
  436. on sr.EducationSchedulingClassID equals escv.EducationSchedulingClassID
  437. where SchedulingWeekNumResult.Where(x => x.EducationSchedulingID == sr.EducationSchedulingID)
  438. .Select(x => x.WeekNum)
  439. .Intersect(weekNumList).Count() > 0
  440. select new { sr.Weekday, sr.CoursesTimeID, sr.ClassroomID }
  441. ).Concat(
  442. from esv in this.ScheduledEducationViewList
  443. .Where(x => x.EducationSchedulingClassID != currentScheduleClass.EducationSchedulingClassID)
  444. from c in esv.ClassMajorIDList
  445. where esv.WeekNumList.Intersect(weekNumList).Count() > 0
  446. && esv.ClassMajorIDList.Count == 0
  447. select new { esv.Weekday, esv.CoursesTimeID, esv.ClassroomID })
  448. )
  449. where c.Weekday == weekday && c.CoursesTimeID == courseTime.CoursesTimeID
  450. && c.ClassroomID == currentClassroomID
  451. select c).ToList();
  452. if (classroomScheduleList.Count > 0)
  453. {
  454. return false;
  455. }
  456. }
  457. }
  458. #endregion
  459. //是否有连续上课超限
  460. #region 判断教师连续上课超限
  461. var teacherContinuousList = (from sr in teacherWorkTimeList
  462. join ct in CourseTimeList on sr.CoursesTimeID equals ct.CoursesTimeID
  463. join csid in currentStaffIDList on sr.UserID equals csid
  464. where sr.Weekday == weekday
  465. group ct by sr.UserID into g
  466. select new { UserID = g.Key, Count = g.Sum(x => x.Workhours) + courseTime.Workhours })
  467. .Where(x => x.Count > TeacherScheduleContinuousCount).ToList();
  468. if (teacherContinuousList.Count > 0)
  469. {
  470. return false;
  471. }
  472. #endregion
  473. return true;
  474. }
  475. private bool IsClassScheduleContinuousExcessed(EducationSchedulingClassScheduleView currentScheduleClass, int weekday,
  476. CoursesTimeView courseTime, IList<int?> weeknumList)
  477. {
  478. #region 判断班级连续上课超限
  479. var classContinuousList = (from sc in (
  480. from sr in SchedulingResult
  481. join ct in this.CourseTimeList on sr.CoursesTimeID equals ct.CoursesTimeID
  482. join swn in SchedulingWeekNumResult on sr.EducationSchedulingID equals swn.EducationSchedulingID
  483. join sc in this.EducationSchedulingClassViewList on sr.EducationSchedulingClassID equals sc.EducationSchedulingClassID
  484. from c in sc.ClassMajorIDList
  485. join cc in currentScheduleClass.ClassMajorIDList on c equals cc
  486. where sr.Weekday == weekday
  487. && weeknumList.Contains(swn.WeekNum)
  488. select new { WeekNum = swn.WeekNum, ClassMajorID = c, Times = ct.Workhours, sc }).Concat(
  489. from esv in ScheduledEducationViewList
  490. from esvwn in esv.WeekNumList
  491. join ct in this.CourseTimeList on esv.CoursesTimeID equals ct.CoursesTimeID
  492. join sc in EducationSchedulingClassViewList on esv.EducationSchedulingClassID equals sc.EducationSchedulingClassID
  493. from c in esv.ClassMajorIDList
  494. join cc in currentScheduleClass.ClassMajorIDList on c equals cc
  495. where esv.Weekday == weekday
  496. && weeknumList.Contains(esvwn)
  497. select new { WeekNum = esvwn, ClassMajorID = c, Times = ct.Workhours, sc }
  498. )
  499. group sc by new { WeekNum = sc.WeekNum, ClassMajorID = sc.ClassMajorID, sc.sc } into g
  500. where g.Sum(x => x.Times) + courseTime.Workhours > ClassScheduleContinuousCount
  501. select new { WeekNum = g.Key.WeekNum, ClassMajorID = g.Key.ClassMajorID, Count = g.Sum(x => x.Times) + courseTime.Workhours });
  502. if (classContinuousList.Count() > 0)
  503. {
  504. return true;
  505. }
  506. #endregion
  507. #region 判断班级相同课程连续上课超限
  508. var classCourseContinuousList = (from sc in
  509. (from sr in SchedulingResult
  510. join ct in this.CourseTimeList on sr.CoursesTimeID equals ct.CoursesTimeID
  511. join swn in SchedulingWeekNumResult on sr.EducationSchedulingID equals swn.EducationSchedulingID
  512. join sc in EducationSchedulingClassViewList on sr.EducationSchedulingClassID equals sc.EducationSchedulingClassID
  513. from c in sc.ClassMajorIDList
  514. join cc in currentScheduleClass.ClassMajorIDList on
  515. new { ClassMajorID = c, sc.CoursematerialID } equals
  516. new { ClassMajorID = cc, CoursematerialID = currentScheduleClass.CoursematerialID }
  517. where sr.Weekday == weekday
  518. && weeknumList.Contains(swn.WeekNum)
  519. select new { WeekNum = swn.WeekNum, ClassMajorID = c, sc.CoursematerialID, Times = ct.Workhours, sc }
  520. ).Concat(from esv in ScheduledEducationViewList
  521. from esvwn in esv.WeekNumList
  522. join ct in this.CourseTimeList on esv.CoursesTimeID equals ct.CoursesTimeID
  523. join sc in EducationSchedulingClassViewList on esv.EducationSchedulingClassID equals sc.EducationSchedulingClassID
  524. from c in sc.ClassMajorIDList
  525. join cc in currentScheduleClass.ClassMajorIDList on
  526. new { ClassMajorID = c, sc.CoursematerialID } equals
  527. new { ClassMajorID = cc, CoursematerialID = currentScheduleClass.CoursematerialID }
  528. where esv.Weekday == weekday
  529. && weeknumList.Contains(esvwn)
  530. select new { WeekNum = esvwn, ClassMajorID = c, sc.CoursematerialID, Times = ct.Workhours, sc }
  531. )
  532. group sc by new { WeekNum = sc.WeekNum, ClassMajorID = sc.ClassMajorID, sc.CoursematerialID, sc.sc } into g
  533. where g.Sum(x => x.Times) + courseTime.Workhours > ClassCourseScheduleContinuousCount
  534. select new
  535. {
  536. WeekNum = g.Key.WeekNum,
  537. ClassMajorID = g.Key.ClassMajorID,
  538. CoursematerialID = g.Key.CoursematerialID,
  539. Count = g.Sum(x => x.Times) + courseTime.Workhours
  540. });
  541. if (classCourseContinuousList.Count() > 0)
  542. {
  543. return true;
  544. }
  545. #endregion
  546. return false;
  547. }
  548. private List<int?> GetOrderedWeekdays(EducationSchedulingClassScheduleView currentScheduleClass, IList<int?> weekdayList)
  549. {
  550. //计算每周要排多少天课
  551. var weekCount = ArrangementList.Select(x => (x.Weekday == 0) ? 7 : x.Weekday).Max();
  552. //获取已经排了的课程
  553. var allScheduledWeekdays = SchedulingResult.Where(x => x.EducationSchedulingClassID == currentScheduleClass.EducationSchedulingClassID)
  554. .Join(CourseTimeList, (x => x.CoursesTimeID), (x => x.CoursesTimeID), ((x, y) => new { x.Weekday, y.Workhours }))
  555. .Concat(
  556. ScheduledEducationViewList.Where(x => x.EducationSchedulingClassID == currentScheduleClass.EducationSchedulingClassID)
  557. .Join(CourseTimeList, (x => x.CoursesTimeID), (x => x.CoursesTimeID), ((x, y) => new { x.Weekday, y.Workhours })))
  558. .ToList();
  559. //计算已经排过的课程中,最后一课是周几
  560. var lastScheduledWeekday = allScheduledWeekdays.Max(x => x.Weekday) ?? 0;
  561. var schedulingWeekList = currentScheduleClass.CourseProcessViewList.Select(x => new { x.Week, x.Times });
  562. allScheduledWeekdays.ForEach(x => {
  563. schedulingWeekList = schedulingWeekList.Select(m => new {
  564. m.Week,
  565. Times = (x.Weekday == m.Week) ? (m.Times - x.Workhours) : m.Times
  566. });
  567. });
  568. var maxToBeScheduleCount = schedulingWeekList.Where(x => x.Times > 0).Max(x => x.Times);
  569. //1、((double)weekCount - (double)lastScheduledWeekday)=剩余多少天需要排课
  570. //2、((double)maxToBeScheduleCount) / (double)ClassCourseScheduleContinuousCount)计算出需要排课的课程时间最多的周次,按照班级课程连续排课限制计算,需要排多少天
  571. //1/2得出需要间隔开的天数
  572. //(该逻辑基于自动排课,是按固定周次顺序一直排下来的循环中使用)
  573. var skipDayCount = Convert.ToInt32(Math.Ceiling(((double)weekCount - (double)lastScheduledWeekday) / ((double)maxToBeScheduleCount) / (double)ClassCourseScheduleContinuousCount));
  574. //预留排课后又被删掉一天的工作安排的情况
  575. if (skipDayCount < 0)
  576. {
  577. skipDayCount = 0;
  578. }
  579. var startWeekday = lastScheduledWeekday == 0 ? weekdayList.Min() : lastScheduledWeekday;
  580. return weekdayList.OrderBy(x => (
  581. ((x == 0) ? 7 : x) > lastScheduledWeekday
  582. && (((x == 0) ? 7 : x) - startWeekday) % (skipDayCount + 1) == 0) ? 0 : 1)
  583. .ThenBy(x => (x == 0) ? 7 : x).ToList();
  584. }
  585. public void GenerateSchedule()
  586. {
  587. this.InitSchedule();
  588. this.GenerateScheduleByInited();
  589. }
  590. private void GenerateScheduleByInited()
  591. {
  592. var totalScheduleTime = ArrangementList.Select(x => new
  593. {
  594. x.Weekday,
  595. x.CoursesTimeID
  596. }).ToList();
  597. var weekdayList = ArrangementList.Select(x => x.Weekday).Distinct().ToList();
  598. ////自动排课时,保证涉及的院校都是重新排的,所以以前的记录要清掉
  599. //this.ScheduledEducationViewList = this.ScheduledEducationViewList.Where(x => !CollegeList.Select(w => w.CollegeID).Contains(x.CollegeID)).ToList();
  600. var allMissionClassIDList = EducationSchedulingClassViewList.Select(x => x.EducationMissionClassID).Distinct().ToList();
  601. var educationMissionClassList = this.EducationSchedulingClassDAL.EducationMissionClassDAL.Value.
  602. EducationMissionClassRepository.GetList(x => allMissionClassIDList.Contains(x.EducationMissionClassID)).ToList();
  603. foreach (var college in CollegeList)
  604. {
  605. LogHelper.WriteLog(LogType.ServiceLog, "开始对" + college.Name + "进行排课。");
  606. var currentScheduleClassList = this.EducationSchedulingClassViewList.Where(c => c.CourseCollegeID == college.CollegeID).ToList();
  607. //排序
  608. currentScheduleClassList = this.GetOrderedEducationSchedulingClassViewList(currentScheduleClassList);
  609. //var skipDayCount = this.GetCommonSkipDays(currentScheduleClassList);
  610. foreach (var currentScheduleClass in currentScheduleClassList)
  611. {
  612. var scheduleClassProcess = (from cpv in currentScheduleClass.CourseProcessViewList
  613. group cpv by new
  614. {
  615. cpv.ClassroomTypeID,
  616. cpv.ClassroomID,
  617. teacherKey = string.Join(",", cpv.CourseProcessTeacherViewList
  618. .OrderBy(x => x.TeacherType).ThenBy(x => x.UserID)
  619. .Select(x => x.UserID.ToString() + "|" + x.TeacherType.ToString()))
  620. } into g
  621. select new
  622. {
  623. ClassroomTypeID = g.Key.ClassroomTypeID,
  624. ClassroomID = g.Key.ClassroomID,
  625. TeacherViewList = g.FirstOrDefault().CourseProcessTeacherViewList,
  626. CourseProcessViewList = g.Select(x => x).ToList()
  627. }).ToList();
  628. foreach (var classroomAndStaff in scheduleClassProcess)
  629. {
  630. var currentTeacherViewList = new List<BaseTeacherTeachingView>();
  631. int? currentClassroomTypeID = classroomAndStaff.ClassroomTypeID ?? currentScheduleClass.ClassroomTypeID;
  632. Guid? currentClassroomID = classroomAndStaff.ClassroomID ?? currentScheduleClass.ClassroomID;
  633. var currentScheduleTimes = 0;
  634. var maxScheduleTimes = classroomAndStaff.CourseProcessViewList.Max(x => x.Times);
  635. var courseProcessViewList = classroomAndStaff.CourseProcessViewList.OrderBy(x => x.Times).ToList();
  636. if (classroomAndStaff.TeacherViewList.Count == 0)
  637. {
  638. currentTeacherViewList = currentScheduleClass.TeacherTeachingViewList;
  639. }
  640. else
  641. {
  642. currentTeacherViewList = classroomAndStaff.TeacherViewList.Select(x => (BaseTeacherTeachingView)x).ToList();
  643. }
  644. //需要根据skipDayCount计算出weekday循环的顺序(不一定是1到7)
  645. weekdayList = GetOrderedWeekdays(currentScheduleClass, weekdayList);
  646. for (int i = 0; i < weekdayList.Count; i ++)
  647. {
  648. var weekday = weekdayList[i] ?? 0;
  649. if (!totalScheduleTime.Any(w => w.Weekday == weekday))
  650. {
  651. continue;
  652. }
  653. //这里只需要计算出,参与这节课的老师里面的其中一个人在某个节次上过课就行了
  654. var staffUsedCourseTime = (from ct in (
  655. from sr in SchedulingResult
  656. .Where(x => x.EducationSchedulingClassID != currentScheduleClass.EducationSchedulingClassID)
  657. join str in SchedulingTeacherResult on sr.EducationSchedulingID equals str.EducationSchedulingID
  658. join s in currentTeacherViewList on str.UserID equals s.UserID
  659. select sr.CoursesTimeID)
  660. .Concat(
  661. from esv in this.ScheduledEducationViewList
  662. .Where(x => x.EducationSchedulingClassID != currentScheduleClass.EducationSchedulingClassID)
  663. from esvs in esv.TeacherTeachingViewList
  664. where currentTeacherViewList.Select(x => x.UserID).Contains(esvs.UserID)
  665. select esv.CoursesTimeID
  666. )
  667. select ct).Distinct();
  668. //当前教师之前有排过课的节次往后移,实在排不下才排到那些节次去,保证各个教师的上课时间相对公平些
  669. var staffCourseTimeList = (from ct in CourseTimeList
  670. join sr in staffUsedCourseTime on ct.CoursesTimeID equals sr into dsr
  671. from esr in dsr.DefaultIfEmpty()
  672. select new { ct, esr })
  673. .OrderBy(x => (x.esr == null ? 0 : 1))
  674. .ThenBy(x => x.ct.StartTimes)
  675. .Select(x => x.ct)
  676. .ToList();
  677. foreach (var courseTime in staffCourseTimeList)
  678. {
  679. if (!totalScheduleTime.Any(w => w.Weekday == weekday && w.CoursesTimeID == courseTime.CoursesTimeID))
  680. {
  681. continue;
  682. }
  683. //获取该次排课排的周次
  684. var tmpScheduleTimes = currentScheduleTimes + (courseTime.EndTimes.Value - courseTime.StartTimes.Value + 1);
  685. if (tmpScheduleTimes > maxScheduleTimes)
  686. {
  687. break;
  688. }
  689. var weeknumList = courseProcessViewList.Where(x => x.Times >= tmpScheduleTimes).ToList();
  690. if (!this.IsEducationSchedulingClassCanAddSchedule(currentScheduleClass, weekday, courseTime, weeknumList, currentTeacherViewList.Select(x => (Guid?)x.UserID).ToList(), currentClassroomID))
  691. {
  692. continue;
  693. }
  694. if (this.IsClassScheduleContinuousExcessed(currentScheduleClass, weekday, courseTime, weeknumList.Select(x => x.Week).ToList()))
  695. {
  696. break;
  697. }
  698. //获取该时间点可以使用的教室
  699. var currentClassroomList = this.GetCurrentClassroomViewList(weekday, courseTime, weeknumList.Select(x => x.Week).ToList());
  700. //没有教室,就什么都不用排了
  701. if (currentClassroomList.Count == 0)
  702. {
  703. continue;
  704. }
  705. //排序
  706. currentClassroomList = this.GetOrderedClassroomViewList(currentClassroomList, currentScheduleClass.CollegeID.Value);
  707. if (currentClassroomID.HasValue)
  708. {
  709. currentClassroomList = currentClassroomList.Where(x => x.ClassroomID == currentClassroomID).ToList();
  710. }
  711. else if (currentClassroomTypeID.HasValue)
  712. {
  713. currentClassroomList = currentClassroomList.Where(x => x.ClassroomTypeID.Contains(currentClassroomTypeID.Value)
  714. && ((x.Totalseating ?? 0) > currentScheduleClass.StudentNum || x.IsConcurrentUse == true)
  715. ).ToList();
  716. }
  717. //筛选完以后再看看还有没有
  718. if (currentClassroomList.Count == 0)
  719. {
  720. continue;
  721. }
  722. var currentClassroom = currentClassroomList.First();
  723. var educationScheduling = new ES_EducationScheduling
  724. {
  725. EducationSchedulingID = Guid.NewGuid(),
  726. SchoolyearID = this.SchoolYear.SchoolYearID,
  727. EducationSchedulingClassID = currentScheduleClass.EducationSchedulingClassID,
  728. Weekday = weekday,
  729. CoursesTimeID = courseTime.CoursesTimeID,
  730. ClassroomID = currentClassroom.ClassroomID,
  731. IsAuto = true,
  732. RecordStatus = (int)SYS_STATUS.USABLE,
  733. CreateTime = DateTime.Now,
  734. ModifyTime = DateTime.Now
  735. };
  736. //增加排课教师
  737. var staffList = this.StaffList.Where(x => currentTeacherViewList.Any(w => w.UserID == x.UserID)).ToList();
  738. staffList.ForEach(x =>
  739. {
  740. var educationSchedulingTeacher = new ES_EducationSchedulingTeacher
  741. {
  742. EducationSchedulingTeacherID = Guid.NewGuid(),
  743. EducationSchedulingID = educationScheduling.EducationSchedulingID,
  744. UserID = x.UserID,
  745. TeachingMethod = (int)EM_TeachingMethod.Lecturer,
  746. RecordStatus = (int)SYS_STATUS.USABLE,
  747. CreateTime = DateTime.Now,
  748. ModifyTime = DateTime.Now
  749. };
  750. this.SchedulingTeacherResult.Add(educationSchedulingTeacher);
  751. });
  752. this.SchedulingResult.Add(educationScheduling);
  753. //确实排课了,这时候才更改currentScheduleTimes的值
  754. currentScheduleTimes = tmpScheduleTimes;
  755. weeknumList.ForEach(x =>
  756. {
  757. var educationSchedulingWeekNum = new ES_EducationSchedulingWeekNum
  758. {
  759. EducationSchedulingWeekNumID = Guid.NewGuid(),
  760. EducationSchedulingID = educationScheduling.EducationSchedulingID,
  761. WeekNum = x.Week,
  762. RecordStatus = (int)SYS_STATUS.USABLE,
  763. CreateTime = DateTime.Now,
  764. ModifyTime = DateTime.Now
  765. };
  766. this.SchedulingWeekNumResult.Add(educationSchedulingWeekNum);
  767. });
  768. var educatiomMissionClass = educationMissionClassList.FirstOrDefault(x => x.EducationMissionClassID == currentScheduleClass.EducationMissionClassID);
  769. if (educatiomMissionClass != null)
  770. {
  771. educatiomMissionClass.RecordStatus = (int)EM_EducationMissionClassStatus.Scheduled;
  772. }
  773. }
  774. }
  775. }
  776. }
  777. LogHelper.WriteLog(LogType.ServiceLog, college.Name + "排课结束。");
  778. }
  779. this.UnitOfWork.AddRange(this.SchedulingResult);
  780. this.UnitOfWork.AddRange(this.SchedulingWeekNumResult);
  781. this.UnitOfWork.AddRange(this.SchedulingTeacherResult);
  782. this.UnitOfWork.Commit();
  783. }
  784. public void ClearAutoSchedule(Guid schoolYearID, Guid? collegeID, int? standardID, int? year, Guid? classmajorID)
  785. {
  786. Expression<Func<ES_EducationScheduling, bool>> exp = (x => x.SchoolyearID == schoolYearID && x.IsAuto == true);
  787. Expression<Func<ES_EducationSchedulingTeacher, bool>> expTeacher = (x => x.ES_EducationScheduling.SchoolyearID == schoolYearID && x.ES_EducationScheduling.IsAuto == true);
  788. Expression<Func<ES_EducationSchedulingWeekNum, bool>> expWeekNum = (x => x.ES_EducationScheduling.SchoolyearID == schoolYearID && x.ES_EducationScheduling.IsAuto == true);
  789. if (collegeID.HasValue)
  790. {
  791. exp = exp.And(x => x.EM_EducationSchedulingClass.EM_EducationMissionClass.EM_EducationMission.CollegeID == collegeID);
  792. expTeacher = expTeacher.And(x => x.ES_EducationScheduling.EM_EducationSchedulingClass.EM_EducationMissionClass.EM_EducationMission.CollegeID == collegeID);
  793. expWeekNum = expWeekNum.And(x => x.ES_EducationScheduling.EM_EducationSchedulingClass.EM_EducationMissionClass.EM_EducationMission.CollegeID == collegeID);
  794. }
  795. if (year.HasValue)
  796. {
  797. exp = exp.And(x => x.EM_EducationSchedulingClass.EM_EducationMissionClass.CF_Classmajor.Any(w => w.CF_Grademajor.GradeID == year));
  798. expTeacher = expTeacher.And(x => x.ES_EducationScheduling.EM_EducationSchedulingClass.EM_EducationMissionClass.CF_Classmajor.Any(w => w.CF_Grademajor.GradeID == year));
  799. expWeekNum = expWeekNum.And(x => x.ES_EducationScheduling.EM_EducationSchedulingClass.EM_EducationMissionClass.CF_Classmajor.Any(w => w.CF_Grademajor.GradeID == year));
  800. }
  801. if (standardID.HasValue)
  802. {
  803. exp = exp.And(x => x.EM_EducationSchedulingClass.EM_EducationMissionClass.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.StandardID == standardID));
  804. expTeacher = expTeacher.And(x => x.ES_EducationScheduling.EM_EducationSchedulingClass.EM_EducationMissionClass.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.StandardID == standardID));
  805. expWeekNum = expWeekNum.And(x => x.ES_EducationScheduling.EM_EducationSchedulingClass.EM_EducationMissionClass.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.StandardID == standardID));
  806. }
  807. if (classmajorID.HasValue)
  808. {
  809. exp = exp.And(x => x.EM_EducationSchedulingClass.EM_EducationMissionClass.CF_Classmajor.Any(w => w.ClassmajorID == classmajorID));
  810. expTeacher = expTeacher.And(x => x.ES_EducationScheduling.EM_EducationSchedulingClass.EM_EducationMissionClass.CF_Classmajor.Any(w => w.ClassmajorID == classmajorID));
  811. expWeekNum = expWeekNum.And(x => x.ES_EducationScheduling.EM_EducationSchedulingClass.EM_EducationMissionClass.CF_Classmajor.Any(w => w.ClassmajorID == classmajorID));
  812. }
  813. var educationSchedulingList = this.EducationSchedulingDAL.EducationSchedulingRepository.GetList(exp, (x => x.EM_EducationSchedulingClass.EM_EducationMissionClass)).ToList();
  814. educationSchedulingList.ForEach(x => x.EM_EducationSchedulingClass.EM_EducationMissionClass.RecordStatus = (int)EM_EducationMissionClassStatus.Submitted);
  815. this.UnitOfWork.Remove<ES_EducationSchedulingTeacher>(expTeacher);
  816. this.UnitOfWork.Remove<ES_EducationSchedulingWeekNum>(expWeekNum);
  817. this.UnitOfWork.RemoveRange(new HashSet<ES_EducationScheduling>(educationSchedulingList));
  818. this.UnitOfWork.Commit();
  819. }
  820. public void ClearClassmajorSchedule(Guid schoolYearID, Guid classmajorID)
  821. {
  822. this.UnitOfWork.Delete<ES_EducationScheduling>(x =>
  823. x.SchoolyearID == schoolYearID
  824. && x.EM_EducationSchedulingClass.EM_EducationMissionClass.CF_Classmajor
  825. .Any(w => w.ClassmajorID == classmajorID));
  826. }
  827. public List<EducationSchedulingView> GetClassmajorSchedule(Guid schoolYearID, Guid classmajorID)
  828. {
  829. var classmajorScheduleList = this.GetEducationScheduleView(new ConfiguretView(), (x => x.SchoolyearID == schoolYearID &&
  830. x.EM_EducationSchedulingClass.EM_EducationMissionClass.CF_Classmajor
  831. .Any(w => w.ClassmajorID == classmajorID)), false);
  832. return classmajorScheduleList.rows;
  833. }
  834. public List<EducationSchedulingView> GetDepartmentSchedule(Guid schoolYearID, Guid departmentID, IList<int?> handleModeList)
  835. {
  836. var departmentScheduleList = this.GetEducationScheduleView(new ConfiguretView(), (x => x.SchoolyearID == schoolYearID
  837. && x.EM_EducationSchedulingClass.EM_EducationMissionClass.EM_EducationMission.DepartmentID == departmentID
  838. && handleModeList.Contains(x.EM_EducationSchedulingClass.EM_EducationMissionClass.HandleModeID)), false);
  839. return departmentScheduleList.rows;
  840. }
  841. public List<ClassroomView> GetAvailableClassroomList(Guid collegeID, Guid schoolYearID, IList<int?> schedulingWeekList,
  842. int weekday, Guid courseTimeID, int? studentNum, int? classroomTypeID = null)
  843. {
  844. return ClassroomScheduleDAL.GetAvailableClassroom(collegeID, schoolYearID, schedulingWeekList, weekday,
  845. courseTimeID, studentNum, classroomTypeID).ToList()
  846. .OrderBy(x => x.BuildingsInfoName)
  847. .ThenBy(x => string.Join(",", x.CF_ClassroomType.OrderBy(w => w.ClassroomType).Select(w => w.ClassroomType).ToList()))
  848. .ThenBy(x => x.Totalseating).ToList();
  849. }
  850. public void CheckClassroomIsAvailable(Guid collegeID, Guid schoolYearID, IList<int?> schedulingWeekList,
  851. int weekday, Guid courseTimeID, Guid classroomID)
  852. {
  853. //this.InitClassroomInfo();
  854. //this.ClassroomList = this.ClassroomList.Where(x => x.ClassroomID == classroomID).ToList();
  855. var classroom = this.ClassroomScheduleDAL.GetAvailableClassroom().Where(x => x.ClassroomID == classroomID)
  856. .FirstOrDefault();
  857. if (classroom == null)
  858. {
  859. throw new Exception("指定的教室不可用或被预留。");
  860. }
  861. var courseTimeView = this.CoursesTimeServices.Value.GetCoursesTimeView(courseTimeID);
  862. var cannotScheduleList = this.ClassroomScheduleDAL.ClassroomScheduleSettingRepository.GetList(x =>
  863. x.ClassroomID == classroomID && x.Weekday == weekday && x.CoursesTimeID == courseTimeID
  864. && x.IsOnWork == false).ToList();
  865. if (cannotScheduleList.Count > 0)
  866. {
  867. throw new Exception("教室在当前时间点不可以排课,请检查教室可排时间设置。");
  868. }
  869. var classroomList = this.ClassroomScheduleDAL.GetAvailableClassroom(schoolYearID,
  870. schedulingWeekList, weekday, courseTimeID, null)
  871. .Where(x => x.ClassroomID == classroomID)
  872. .ToList(); //当前时间点未被使用
  873. if (classroomList.Count == 0)
  874. {
  875. throw new ClassroomConflictException("指定的教室已被其他任务班占用。");
  876. }
  877. }
  878. public void CheckClassroomIsAvailable(Guid schoolYearID, IList<int?> schedulingWeekList,
  879. int weekday, Guid courseTimeID, Guid classroomID)
  880. {
  881. var classroom = this.ClassroomScheduleDAL.GetAvailableClassroom().Where(x => x.ClassroomID == classroomID)
  882. .FirstOrDefault();
  883. if (classroom == null)
  884. {
  885. throw new Exception("指定的教室不可用或被预留。");
  886. }
  887. var courseTimeView = this.CoursesTimeServices.Value.GetCoursesTimeView(courseTimeID);
  888. var classroomList = this.ClassroomScheduleDAL.GetAvailableClassroom(schoolYearID,
  889. schedulingWeekList, weekday, courseTimeID, null)
  890. .Where(x => x.ClassroomID == classroomID)
  891. .ToList(); //当前时间点未被使用
  892. if (classroomList.Count == 0)
  893. {
  894. throw new ClassroomConflictException("指定的教室已被其他任务班占用。");
  895. }
  896. }
  897. public void CheckEducationSchedulingClassCanAddManualSchedule(
  898. Guid educationScheduleClassID, IList<SchedulingWeekListView> schedulingWeekList, Guid schoolYearID, int weekday, Guid courseTimeID)
  899. {
  900. var schedulingClassView = this.EducationSchedulingClassServices.Value.GetEducationSchedulingClassView(educationScheduleClassID);
  901. var studentQuery = this.EducationSchedulingClassDAL.GetStudentQueryable(x => x.EducationSchedulingClassID == educationScheduleClassID);
  902. var teacherWeekList = (from swl in schedulingWeekList
  903. from ctv in swl.CourseProcessTeacherViewList
  904. select new { UserID = ctv.UserID, WeekNum = swl.Week }).ToList();
  905. var weekList = schedulingWeekList.Select(x => x.Week).ToList();
  906. var teacherIsBusyQuery = (from es in this.EducationSchedulingDAL.EducationSchedulingRepository.GetList(
  907. x => x.SchoolyearID == schoolYearID && x.EducationSchedulingClassID != educationScheduleClassID)
  908. from mct in es.ES_EducationSchedulingTeacher
  909. from eswn in es.ES_EducationSchedulingWeekNum
  910. where es.Weekday == weekday && es.CoursesTimeID == courseTimeID
  911. select new { es.EducationSchedulingID, mct.UserID, mct.CF_Staff.Sys_User.Name, eswn.WeekNum });
  912. var teacherIsBusy = teacherIsBusyQuery.SelectByKeys(teacherWeekList).ToList();
  913. if (teacherIsBusy.Count > 0)
  914. {
  915. var ex = new Exception("教师" + string.Join(",", teacherIsBusy.Select(x => x.Name).Distinct()) + "在其他班级有课,不能上课。");
  916. teacherIsBusy.GroupBy(x => x.UserID, (x, y) => y.FirstOrDefault()).ToList().ForEach(x => ex.Data.Add(x.UserID, x.Name));
  917. throw ex;
  918. }
  919. var studentIsBusy = (from es in this.EducationSchedulingDAL.EducationSchedulingRepository.GetList(
  920. x => x.SchoolyearID == schoolYearID && x.EducationSchedulingClassID != educationScheduleClassID)
  921. from s in es.EM_EducationSchedulingClass.CF_Student
  922. .Join(studentQuery, (x => x.UserID), (x => x.UserID), (x, y) => x)
  923. where es.Weekday == weekday && es.CoursesTimeID == courseTimeID
  924. && es.ES_EducationSchedulingWeekNum.Any(x => weekList.Contains(x.WeekNum))
  925. select s).Include(x => x.Sys_User).ToList();
  926. if (studentIsBusy.Count > 0)
  927. {
  928. throw new Exception("排课班涉及的部分学生在该时段有课,不能上课。");
  929. }
  930. }
  931. public void CheckCourseIsOnWork(Guid coursematerialID, int weekday, Guid courseTimeID)
  932. {
  933. var course = this.CoursematerialDAL.CoursematerialRepository.GetSingle(x => x.CoursematerialID == coursematerialID);
  934. var courseIsOnWork = this.CourseScheduleDAL.CourseScheduleSettingRepository
  935. .GetList(x => x.Weekday == weekday && x.CoursesTimeID == courseTimeID
  936. && x.CoursematerialID == coursematerialID).Select(x => x.IsOnWork)
  937. .FirstOrDefault();
  938. //这里的逻辑和自动排课有点不同,自动排课没有设置的话,则按照周工作时间来,但手工排课不需要按照周工作时间的限制排课,
  939. //如果课程时间没有设置,则默认可排
  940. if (!(courseIsOnWork ?? true))
  941. {
  942. throw new Exception("课程" + course.CourseName + "在该节次不能排课。");
  943. }
  944. }
  945. public void CheckTeacherIsOnWork(Guid educationScheduleClassID, IList<SchedulingWeekListView> schedulingWeekList, int weekday, Guid courseTimeID)
  946. {
  947. var weekTeacherList = schedulingWeekList.SelectMany(w => w.CourseProcessTeacherViewList).GroupBy(w => w.UserID)
  948. .Select(w => w.FirstOrDefault()).ToList();
  949. var teacherIDList = weekTeacherList.Select(w => (Guid?)w.UserID).Distinct().ToList();
  950. var teacherIsOnWorkList = this.TeacherScheduleDAL.TeacherScheduleSettingRepository
  951. .GetList(x => x.Weekday == weekday && x.CoursesTimeID == courseTimeID
  952. && teacherIDList.Contains(x.UserID))
  953. .Select(x => new { x.UserID, x.IsOnWork }).ToList();
  954. weekTeacherList.ForEach(x =>
  955. {
  956. if (teacherIsOnWorkList.Any(w => w.UserID == x.UserID && w.IsOnWork == false))
  957. {
  958. throw new Exception("教师" + x.Name + "在该节次不能排课。");
  959. }
  960. });
  961. }
  962. public List<TeacherWorkTimeView> GetTeacherContinuousWorkTime(Guid educationScheduleClassID, IList<SchedulingWeekListView> schedulingWeekList,
  963. Guid schoolYearID, int weekday)
  964. {
  965. var weekTeacherList = (from swl in schedulingWeekList
  966. from ctv in swl.CourseProcessTeacherViewList
  967. select new { UserID = ctv.UserID, Name = ctv.Name, WeekNum = swl.Week }).ToList();
  968. var teacherIDList = weekTeacherList.Select(x => x.UserID).Distinct().ToList();
  969. var teacherWorkTime = this.TeacherScheduleDAL.GetTeacherWorkTimeView(x =>
  970. x.SchoolyearID == schoolYearID && x.Weekday == weekday,
  971. (x => teacherIDList.Contains(x.UserID))
  972. ).ToList();
  973. return (from t in weekTeacherList
  974. join tw in teacherWorkTime on new { UserID = t.UserID, WeekNum = t.WeekNum } equals new { UserID = tw.UserID, WeekNum = (int?)tw.WeekNum } into dtw
  975. from etw in dtw.DefaultIfEmpty()
  976. select new TeacherWorkTimeView
  977. {
  978. UserID = t.UserID,
  979. Name = t.Name,
  980. WeekNum = t.WeekNum ?? 0,
  981. WorkTime = (etw == null ? 0 : etw.WorkTime)
  982. }).ToList();
  983. }
  984. public void AddScheduling(EducationSchedulingView educationSchedulingView, IList<int?> schedulingWeekList, IList<CourseProcessTeacherView> teacherList)
  985. {
  986. var educationSchedulingClassWithCourseProcess = this.EducationSchedulingClassDAL.EducationSchedulingClassRepository
  987. .GetSingle(x => x.EducationSchedulingClassID == educationSchedulingView.EducationSchedulingClassID,
  988. (x => x.EM_EducationMissionClass),
  989. (x => x.EM_EducationMissionClass.EM_EducationSchedulingClass.Select(w => w.ES_EducationScheduling.Select(y => y.ES_EducationSchedulingTeacher))),
  990. (x => x.EM_EducationMissionClass.EM_EducationSchedulingClass.Select(w => w.ES_EducationScheduling.Select(y => y.ES_EducationSchedulingWeekNum))),
  991. (x => x.EM_EducationMissionClass.EM_CourseProcess),
  992. (x => x.EM_EducationMissionClass.EM_MissionClassTeacher),
  993. (x => x.EM_EducationMissionClass.EM_MissionClassTeacher.Select(w => w.CF_Staff)),
  994. (x => x.EM_EducationMissionClass.EM_CourseProcess.Select(w => w.EM_CourseProcessTeacher)),
  995. (x => x.EM_EducationMissionClass.EM_CourseProcess.Select(w => w.EM_CourseProcessTeacher.Select(v => v.CF_Staff))));
  996. //var teacherScheduleList = from es in educationSchedulingClassWithCourseProcess.EM_EducationMissionClass.EM_EducationSchedulingClass.SelectMany(x => x.ES_EducationScheduling)
  997. // from est in es.ES_EducationSchedulingTeacher
  998. // from esw in es.ES_EducationSchedulingWeekNum
  999. // from cpt in courseProcessTeacherList.Where(x => x.CourseProcessTeacher.Teachers.Select(w => w.UserID).Contains()
  1000. var educationScheduling = new ES_EducationScheduling
  1001. {
  1002. EducationSchedulingID = Guid.NewGuid(),
  1003. SchoolyearID = educationSchedulingView.SchoolyearID,
  1004. EducationSchedulingClassID = educationSchedulingView.EducationSchedulingClassID,
  1005. Weekday = educationSchedulingView.Weekday,
  1006. CoursesTimeID = educationSchedulingView.CoursesTimeID,
  1007. ClassroomID = educationSchedulingView.ClassroomID
  1008. };
  1009. this.SetNewStatus(educationScheduling);
  1010. this.UnitOfWork.Add(educationScheduling);
  1011. teacherList.ToList().ForEach(x =>
  1012. {
  1013. var educationSchedulingTeacher = new ES_EducationSchedulingTeacher
  1014. {
  1015. EducationSchedulingTeacherID = Guid.NewGuid(),
  1016. EducationSchedulingID = educationScheduling.EducationSchedulingID,
  1017. UserID = x.UserID,
  1018. TeachingMethod = x.TeachingMethod
  1019. };
  1020. this.SetNewStatus(educationSchedulingTeacher);
  1021. this.UnitOfWork.Add(educationSchedulingTeacher);
  1022. });
  1023. foreach (var schedulingWeek in schedulingWeekList)
  1024. {
  1025. var educationSchedulingWeekNum = new ES_EducationSchedulingWeekNum
  1026. {
  1027. EducationSchedulingWeekNumID = Guid.NewGuid(),
  1028. EducationSchedulingID = educationScheduling.EducationSchedulingID,
  1029. WeekNum = schedulingWeek
  1030. };
  1031. this.SetNewStatus(educationSchedulingWeekNum);
  1032. this.UnitOfWork.Add(educationSchedulingWeekNum);
  1033. }
  1034. //更改教学任务状态
  1035. var educationSchedulingClass = this.EducationSchedulingClassDAL.EducationSchedulingClassRepository.GetSingle(x => x.EducationSchedulingClassID == educationSchedulingView.EducationSchedulingClassID,
  1036. (x => x.EM_EducationMissionClass.EM_EducationMission),
  1037. (x => x.EM_EducationMissionClass.EM_CourseProcess.Select(w => w.EM_CourseProcessTeacher)));
  1038. var courseProcessList = educationSchedulingClass.EM_EducationMissionClass.EM_CourseProcess.Where(x => schedulingWeekList.Contains(x.Week)
  1039. && string.Join(",", teacherList.Select(w => w.UserID.ToString() + "," + w.TeachingMethod).OrderBy(w => w))
  1040. == string.Join(",", x.EM_CourseProcessTeacher.Select(w => (w.UserID ?? Guid.Empty).ToString() + "," + w.TeachType).OrderBy(w => w)));
  1041. educationSchedulingClass.EM_EducationMissionClass.RecordStatus = (int)EM_EducationMissionClassStatus.Scheduled;
  1042. this.UnitOfWork.Commit();
  1043. }
  1044. public void DelScheduling(Guid educationSchedulingID)
  1045. {
  1046. var educationScheduling = this.EducationSchedulingDAL.EducationSchedulingRepository.
  1047. GetSingle(x => x.EducationSchedulingID == educationSchedulingID, (x => x.EM_EducationSchedulingClass.EM_EducationMissionClass));
  1048. var educationSchedulingClass = this.EducationSchedulingClassDAL.EducationSchedulingClassRepository
  1049. .GetSingle((x => x.EducationSchedulingClassID == educationScheduling.EducationSchedulingClassID
  1050. && x.EM_EducationMissionClass.EM_EducationSchedulingClass
  1051. .SelectMany(w => w.ES_EducationScheduling)
  1052. .Where(w => w.EducationSchedulingID != educationSchedulingID).Count() == 0),
  1053. (x => x.EM_EducationMissionClass));
  1054. if (educationSchedulingClass != null)
  1055. {
  1056. educationSchedulingClass.EM_EducationMissionClass.RecordStatus = (int)EM_EducationMissionClassStatus.Submitted;
  1057. }
  1058. this.UnitOfWork.Remove<ES_EducationSchedulingTeacher>(x => x.EducationSchedulingID == educationSchedulingID);
  1059. this.UnitOfWork.Remove<ES_EducationSchedulingWeekNum>(x => x.EducationSchedulingID == educationSchedulingID);
  1060. this.UnitOfWork.Remove(educationScheduling);
  1061. this.UnitOfWork.Commit();
  1062. }
  1063. public void DelWeeks(Guid educationSchedulingID, IList<int?> weekList)
  1064. {
  1065. this.UnitOfWork.Remove<ES_EducationSchedulingWeekNum>(x => x.EducationSchedulingID == educationSchedulingID
  1066. && weekList.Contains(x.WeekNum));
  1067. this.UnitOfWork.Commit();
  1068. }
  1069. public void Submit(Guid collegeID)
  1070. {
  1071. var collegePriority = this.CollegeScheduleDAL.CollegePriorityRepository.GetList(x => x.CollegeID == collegeID).FirstOrDefault();
  1072. if (collegePriority == null)
  1073. {
  1074. collegePriority = new ES_CollegePriority();
  1075. collegePriority.CollegePriorityID = Guid.NewGuid();
  1076. collegePriority.CollegeID = collegeID;
  1077. collegePriority.Priority = 1;
  1078. collegePriority.StartDate = DateTime.Today;
  1079. collegePriority.EndDate = DateTime.Today;
  1080. SetNewStatus(collegePriority);
  1081. this.UnitOfWork.Add(collegePriority);
  1082. }
  1083. collegePriority.ApprovalStatus = (int)CF_ApprovalStatus.Submitted;
  1084. this.UnitOfWork.Commit();
  1085. }
  1086. public List<ScheduleAdjustmentEditView> GetTeacherScheduleAdjustmentViewList(Guid schoolyearID, Guid userID, Guid? coursematerialID,
  1087. Guid? educationMissionClassID, int? weekNum, int? weekday, Guid? courseTimesID, Guid? classroomID)
  1088. {
  1089. Expression<Func<ES_EducationScheduling, bool>> educationSchedulingExp = x => x.SchoolyearID == schoolyearID;
  1090. Expression<Func<EM_EducationMissionClass, bool>> missionClassExp = (x => true);
  1091. Expression<Func<ES_EducationSchedulingWeekNum, bool>> weeknumExp = (x => true);
  1092. var stopApprovedStatus = this.EducationSchedulingStopServices.Value.GetCorrectEndStatus().Value;
  1093. if (coursematerialID.HasValue)
  1094. {
  1095. missionClassExp = missionClassExp.And(x => x.CoursematerialID == coursematerialID);
  1096. }
  1097. if (educationMissionClassID.HasValue)
  1098. {
  1099. missionClassExp = missionClassExp.And(x => x.EducationMissionClassID == educationMissionClassID);
  1100. }
  1101. if (weekNum.HasValue)
  1102. {
  1103. weeknumExp = weeknumExp.And(x => x.WeekNum == weekNum);
  1104. }
  1105. if (weekday.HasValue)
  1106. {
  1107. educationSchedulingExp = educationSchedulingExp.And(x => x.Weekday == weekday);
  1108. }
  1109. if (courseTimesID.HasValue)
  1110. {
  1111. educationSchedulingExp = educationSchedulingExp.And(x => x.CoursesTimeID == courseTimesID);
  1112. }
  1113. if (classroomID.HasValue)
  1114. {
  1115. educationSchedulingExp = educationSchedulingExp.And(x => x.ClassroomID == classroomID);
  1116. }
  1117. var scheduleAdjustmentViewList = this.EducationSchedulingDAL.GetScheduleAdjustmentViewQueryable(
  1118. x => x.UserID == userID,
  1119. educationSchedulingExp, missionClassExp, weeknumExp, stopApprovedStatus).ToList();
  1120. var educationSchedulingIDList = scheduleAdjustmentViewList.Select(x => x.EducationSchedulingID).ToList();
  1121. var teacherList = this.EducationSchedulingDAL.EducationSchedulingTeacherRepository.GetList(x => educationSchedulingIDList.Contains(x.EducationSchedulingID),
  1122. (x => x.CF_Staff.Sys_User)).ToList();
  1123. var result = scheduleAdjustmentViewList.OrderBy(x => x.WeekNum)
  1124. .ThenBy(x => (x.Weekday == 0 ? 7 : x.Weekday)).ThenBy(x => x.TimesSegment).ThenBy(x => x.CoursesTimeName)
  1125. .ThenBy(x => x.EducationMissionClassName).ToList();
  1126. result.ForEach(x => x.TeacherList = teacherList.Where(w => w.EducationSchedulingID == x.EducationSchedulingID)
  1127. .Select(w => new MissionClassTeacherView
  1128. {
  1129. EducationMissionClassID = x.EducationMissionClassID,
  1130. UserID = w.UserID,
  1131. Name = w.CF_Staff.Sys_User.Name,
  1132. TeachingMethod = w.TeachingMethod
  1133. }).ToList());
  1134. return result;
  1135. }
  1136. public List<ScheduleStopEditView> GetTeacherScheduleStopViewList(Guid schoolyearID, Guid userID, Guid? coursematerialID,
  1137. Guid? educationMissionClassID, int? weekNum, int? weekday, Guid? courseTimesID, Guid? classroomID)
  1138. {
  1139. Expression<Func<ES_EducationScheduling, bool>> educationSchedulingExp = x => x.SchoolyearID == schoolyearID;
  1140. Expression<Func<EM_EducationMissionClass, bool>> missionClassExp = (x => true);
  1141. Expression<Func<ES_EducationSchedulingWeekNum, bool>> weeknumExp = (x => true);
  1142. var stopApprovedStatus = this.EducationSchedulingStopServices.Value.GetCorrectEndStatus().Value;
  1143. if (coursematerialID.HasValue)
  1144. {
  1145. missionClassExp = missionClassExp.And(x => x.CoursematerialID == coursematerialID);
  1146. }
  1147. if (educationMissionClassID.HasValue)
  1148. {
  1149. missionClassExp = missionClassExp.And(x => x.EducationMissionClassID == educationMissionClassID);
  1150. }
  1151. if (weekNum.HasValue)
  1152. {
  1153. weeknumExp = weeknumExp.And(x => x.WeekNum == weekNum);
  1154. }
  1155. if (weekday.HasValue)
  1156. {
  1157. educationSchedulingExp = educationSchedulingExp.And(x => x.Weekday == weekday);
  1158. }
  1159. if (courseTimesID.HasValue)
  1160. {
  1161. educationSchedulingExp = educationSchedulingExp.And(x => x.CoursesTimeID == courseTimesID);
  1162. }
  1163. if (classroomID.HasValue)
  1164. {
  1165. educationSchedulingExp = educationSchedulingExp.And(x => x.ClassroomID == classroomID);
  1166. }
  1167. var scheduleStopViewList = this.EducationSchedulingDAL.GetScheduleStopViewQueryable(
  1168. x => x.UserID == userID,
  1169. educationSchedulingExp, missionClassExp, weeknumExp, stopApprovedStatus).ToList();
  1170. var educationSchedulingIDList = scheduleStopViewList.Select(x => x.EducationSchedulingID).ToList();
  1171. var teacherList = this.EducationSchedulingDAL.EducationSchedulingTeacherRepository.GetList(x => educationSchedulingIDList.Contains(x.EducationSchedulingID),
  1172. (x => x.CF_Staff.Sys_User)).ToList();
  1173. var result = scheduleStopViewList.OrderBy(x => x.WeekNum)
  1174. .ThenBy(x => (x.Weekday == 0 ? 7 : x.Weekday)).ThenBy(x => x.TimesSegment).ThenBy(x => x.CoursesTimeName)
  1175. .ThenBy(x => x.EducationMissionClassName).ToList();
  1176. result.ForEach(x => x.TeacherList = teacherList.Where(w => w.EducationSchedulingID == x.EducationSchedulingID)
  1177. .Select(w => new MissionClassTeacherView
  1178. {
  1179. EducationMissionClassID = x.EducationMissionClassID,
  1180. UserID = w.UserID,
  1181. Name = w.CF_Staff.Sys_User.Name,
  1182. TeachingMethod = w.TeachingMethod
  1183. }).ToList());
  1184. return result;
  1185. }
  1186. /// <summary>
  1187. /// 批量调课获取可调课节次
  1188. /// </summary>
  1189. /// <param name="schoolyearID"></param>
  1190. /// <param name="toWeekday"></param>
  1191. /// <param name="courseTimeID"></param>
  1192. /// <param name="toWeekNum"></param>
  1193. /// <param name="teacherID"></param>
  1194. /// <param name="educationSchedulingWeekNumIDList"></param>
  1195. /// <returns></returns>
  1196. public List<CoursesTimeView> GetNotUseCoursesTimeViewListForBatchAdjustment(Guid? schoolyearID, int? toWeekday, int? toWeekNum, Guid? teacherID, List<Guid?> educationSchedulingWeekNumIDList)
  1197. {
  1198. var educationSchedulingWeekNumList = this.EducationSchedulingDAL.EducationSchedulingWeekNumRepository
  1199. .GetList(x => educationSchedulingWeekNumIDList.Contains(x.EducationSchedulingWeekNumID),
  1200. (x => x.ES_EducationScheduling), (x => x.ES_EducationScheduling.ES_EducationSchedulingTeacher)).ToList();
  1201. var weekTeacherList = educationSchedulingWeekNumList.Select(x => new
  1202. {
  1203. SchoolyearID = schoolyearID ?? x.ES_EducationScheduling.SchoolyearID,
  1204. Weekday = toWeekday ?? x.ES_EducationScheduling.Weekday,
  1205. WeekNum = toWeekNum ?? x.WeekNum
  1206. });
  1207. var dateList = weekTeacherList.GroupBy(x => x.SchoolyearID).Select(x =>
  1208. SchoolYearServices.Value.GetDateByCoursesTime(x.Key.Value, x.Select(w => new FullCoursesTimeView
  1209. {
  1210. Weekday = w.Weekday,
  1211. WeekNum = w.WeekNum
  1212. }).ToList())
  1213. ).SelectMany(x => x).Select(x => (DateTime?)x).Distinct().ToList();
  1214. var examinationPlanList = ExaminationPlanDAL.GetExaminationPlanView(x => dateList.Contains(x.ExaminationDate)
  1215. && x.RecordStatus == (int)EX_ExaminationPlanStatus.Submitted).ToList();
  1216. var examinationPlanIDList = examinationPlanList.Select(x => x.ExaminationPlanID).ToList();
  1217. var examinationRoomLayoutViewList = ExaminationPlanDAL.GetExaminationRoomLayoutView(x => examinationPlanIDList.Contains((Guid)x.ExaminationPlanID)).ToList();
  1218. examinationPlanList.ForEach(x => x.ExaminationRoomLayoutView = new HashSet<ExaminationRoomLayoutView>(examinationRoomLayoutViewList.Where(y => y.ExaminationPlanID == x.ExaminationPlanID)));
  1219. List<Guid> teacherList = new List<Guid>();
  1220. List<CoursesTimeView> result = new List<CoursesTimeView>();
  1221. List<CoursesTimeView> allCoursesTimeView = CoursesTimeServices.Value.GetCoursesTimeViewList(new ConfiguretView(), null);
  1222. List<Guid> examinationCourseTimeIDList = new List<Guid>();
  1223. foreach (var educationSchedulingWeekNumID in educationSchedulingWeekNumIDList)
  1224. {
  1225. var EducationSchedulingWeekNum = educationSchedulingWeekNumList.FirstOrDefault(x => x.EducationSchedulingWeekNumID == educationSchedulingWeekNumID);
  1226. List<CoursesTimeView> query = new List<CoursesTimeView>();
  1227. if (!schoolyearID.HasValue)
  1228. {
  1229. schoolyearID = EducationSchedulingWeekNum.ES_EducationScheduling.SchoolyearID;
  1230. }
  1231. if (!toWeekday.HasValue)
  1232. {
  1233. toWeekday = EducationSchedulingWeekNum.ES_EducationScheduling.Weekday;
  1234. }
  1235. if (!toWeekNum.HasValue)
  1236. {
  1237. toWeekNum = EducationSchedulingWeekNum.WeekNum;
  1238. }
  1239. if (!teacherID.HasValue)
  1240. {
  1241. var dbteacherList = EducationSchedulingWeekNum.ES_EducationScheduling.ES_EducationSchedulingTeacher.Select(x => x.UserID).ToList();
  1242. foreach (var id in dbteacherList)
  1243. {
  1244. teacherList.Add(id.Value);
  1245. }
  1246. }
  1247. else
  1248. {
  1249. teacherList.Add(teacherID.Value);
  1250. }
  1251. query = this.EducationSchedulingDAL.GetNotUseCoursesTime(schoolyearID.Value, toWeekday.Value, teacherList, toWeekNum, educationSchedulingWeekNumID.Value).ToList();
  1252. var arrangementsNotWork = EducationSchedulingDAL.ArrangementsRepository.Entities.Where(x => !x.IsOnWork.Value && x.Weekday == toWeekday && x.EM_CoursesTime.RecordStatus == 1).ToList();
  1253. var notWorkCoursesTimeIDList = arrangementsNotWork.Select(x => x.CoursesTimeID).ToList();
  1254. var examinationDate = SchoolYearServices.Value.GetDateByCoursesTime(schoolyearID.Value, new List<FullCoursesTimeView> { new FullCoursesTimeView { Weekday = toWeekday.Value, WeekNum = toWeekNum.Value } }).FirstOrDefault();
  1255. if (examinationDate != null)
  1256. {
  1257. var dateExaminationPlanList = examinationPlanList.Where(x => x.ExaminationDate == examinationDate).ToList();
  1258. examinationCourseTimeIDList.AddRange(query.Where(x => dateExaminationPlanList.Any(w => w.StartTime < new TimeSpan(x.EndHour ?? 0, x.EndMinutes ?? 0, 0).Add(new TimeSpan(0, 1, 0))
  1259. && w.EndTime >= new TimeSpan(x.StartHour ?? 0, x.StartMinutes ?? 0, 0)
  1260. && w.ExaminationRoomLayoutView.SelectMany(v => v.Sys_User).Select(v => v.UserID).Intersect(teacherList).Count() > 0))
  1261. .Select(x => x.CoursesTimeID.Value)
  1262. .ToList());
  1263. }
  1264. result = result.Concat(query.Where(x => !notWorkCoursesTimeIDList.Contains(x.CoursesTimeID))).ToList();
  1265. }
  1266. //var arrangementsNotWork = EducationSchedulingDAL.ArrangementsRepository.Entities.Where(x => !x.IsOnWork.Value && x.Weekday == toWeekday && x.EM_CoursesTime.RecordStatus == (int)SYS_STATUS.USABLE).ToList();
  1267. //var notWorkCoursesTimeIDList = arrangementsNotWork.Select(x => x.CoursesTimeID).ToList();
  1268. var coursesTimeViewList = result.GroupBy(x => x.CoursesTimeID).Select(x => new { x.Key, count = x.Count() }).ToList();
  1269. var coursesTimeIDList = coursesTimeViewList.Where(x => x.count >= educationSchedulingWeekNumIDList.Count).Select(x => x.Key).ToList();
  1270. examinationCourseTimeIDList = examinationCourseTimeIDList.Distinct().ToList();
  1271. result = allCoursesTimeView.Where(x => coursesTimeIDList.Contains(x.CoursesTimeID) && !examinationCourseTimeIDList.Contains(x.CoursesTimeID.Value)).Distinct().ToList();
  1272. return result.OrderBy(x => x.StartTimes).ToList();
  1273. }
  1274. public List<CoursesTimeView> GetNotUseCoursesTimeViewList(Guid schoolyearID, int weekday, int toWeekday, Guid courseTimeID,
  1275. int? weekNum, int? toWeekNum, Guid? fromTeacherID, Guid? replaceTeacherID, Guid educationMissionClassID)
  1276. {
  1277. var schedule = this.GetEducationScheduleView(new ConfiguretView(),
  1278. (x => x.EM_EducationSchedulingClass.EducationMissionClassID == educationMissionClassID
  1279. && x.Weekday == weekday && x.CoursesTimeID == courseTimeID
  1280. && x.ES_EducationSchedulingWeekNum.Any(w => weekNum == w.WeekNum)), false).rows.FirstOrDefault();
  1281. if (schedule == null)
  1282. {
  1283. return new List<CoursesTimeView>();
  1284. }
  1285. var scheduleWeekNum = this.EducationSchedulingDAL.EducationSchedulingWeekNumRepository
  1286. .GetSingle(x => x.EducationSchedulingID == schedule.EducationSchedulingID && x.WeekNum == weekNum);
  1287. var teacherList = schedule.TeacherTeachingViewList.Select(x => x.UserID).ToList();
  1288. if (replaceTeacherID.HasValue)
  1289. {
  1290. teacherList.Remove(fromTeacherID ?? Guid.Empty);
  1291. teacherList.Add(replaceTeacherID.Value);
  1292. }
  1293. var arrangementsNotWork = EducationSchedulingDAL.ArrangementsRepository.Entities.Where(x => !x.IsOnWork.Value && x.Weekday == toWeekday && x.EM_CoursesTime.RecordStatus == (int)SYS_STATUS.USABLE).ToList();
  1294. var notWorkCoursesTimeIDList = arrangementsNotWork.Select(x => x.CoursesTimeID).ToList();
  1295. var result = this.EducationSchedulingDAL.GetNotUseCoursesTime(schoolyearID, toWeekday, teacherList, toWeekNum,
  1296. scheduleWeekNum.EducationSchedulingWeekNumID)
  1297. .OrderBy(x => x.TimesSegment).ThenBy(x => x.StartTimes).ToList();
  1298. var schoolyear = this.SchoolYearServices.Value.GetSchoolYearView(schoolyearID);
  1299. result = result.Where(x => !this.SchoolYearServices.Value.IsTimePassed(schoolyear, toWeekNum, toWeekday, x.StartHour, x.StartMinutes) && !notWorkCoursesTimeIDList.Contains(x.CoursesTimeID))
  1300. .ToList();
  1301. var scheduleDate = this.SchoolYearServices.Value.GetDateByCoursesTime(schoolyear.SchoolYearID.Value, new List<FullCoursesTimeView> {
  1302. new FullCoursesTimeView {
  1303. WeekNum = toWeekNum,
  1304. Weekday = toWeekday
  1305. }
  1306. }).FirstOrDefault();
  1307. if (scheduleDate != null)
  1308. {
  1309. var examinationPlanList = ExaminationPlanDAL.GetExaminationPlanView(x => x.ExaminationDate == scheduleDate && x.SchoolyearID == schoolyear.SchoolYearID
  1310. && x.RecordStatus == (int)EX_ExaminationPlanStatus.Submitted).ToList();
  1311. var examinationPlanIDList = examinationPlanList.Select(x => x.ExaminationPlanID).ToList();
  1312. var examinationRoomLayoutViewList = ExaminationPlanDAL.GetExaminationRoomLayoutView(x => examinationPlanIDList.Contains((Guid)x.ExaminationPlanID)).ToList();
  1313. examinationPlanList.ForEach(x => x.ExaminationRoomLayoutView = new HashSet<ExaminationRoomLayoutView>(examinationRoomLayoutViewList.Where(y => y.ExaminationPlanID == x.ExaminationPlanID)));
  1314. result = result.Where(x => !examinationPlanList.Any(w => w.StartTime < new TimeSpan(x.EndHour ?? 0, x.EndMinutes ?? 0, 0).Add(new TimeSpan(0, 1, 0))
  1315. && w.EndTime >= new TimeSpan(x.StartHour ?? 0, x.StartMinutes ?? 0, 0)
  1316. && w.ExaminationRoomLayoutView.SelectMany(v => v.Sys_User).Select(v => (Guid?)v.UserID).Contains(replaceTeacherID))
  1317. ).ToList();
  1318. }
  1319. return result;
  1320. }
  1321. public IGridResultSet<ClassroomView> GetNotUseClassroomViewList(ConfiguretView configuretView, Guid schoolyearID, int weekday, int toWeekday,
  1322. Guid coursesTimeID, Guid toCoursesTimeID, IList<int?> weekNumList, IList<int?> toWeekNumList, int classroomTypeID, Guid educationMissionClassID,
  1323. int? pageIndex = null, int? pageSize = null)
  1324. {
  1325. var schedule = this.GetEducationScheduleView(new ConfiguretView(),
  1326. (x => x.EM_EducationSchedulingClass.EducationMissionClassID == educationMissionClassID
  1327. && x.Weekday == weekday && x.CoursesTimeID == coursesTimeID
  1328. && x.ES_EducationSchedulingWeekNum.Any(w => weekNumList.Contains(w.WeekNum))), false).rows.FirstOrDefault();
  1329. if (schedule == null)
  1330. {
  1331. return new GridResultSet<ClassroomView>() { rows = new List<ClassroomView>(), total = 0 };
  1332. }
  1333. var result = this.EducationSchedulingDAL.GetNotUseClassroomForAdjustment(schoolyearID, toWeekday, toCoursesTimeID, classroomTypeID,
  1334. toWeekNumList, schedule.EducationSchedulingID);
  1335. var schoolyear = this.SchoolYearServices.Value.GetSchoolYearView(schoolyearID);
  1336. var coursesTime = CoursesTimeServices.Value.GetCoursesTimeView(coursesTimeID);
  1337. var scheduleDateList = this.SchoolYearServices.Value.GetDateByCoursesTime(schoolyear.SchoolYearID.Value, toWeekNumList.Select(x => new FullCoursesTimeView {
  1338. WeekNum = x,
  1339. Weekday = toWeekday
  1340. }).ToList()).Select(x => (DateTime?)x).ToList();
  1341. if (scheduleDateList.Count > 0)
  1342. {
  1343. var examinationPlanList = ExaminationPlanDAL.GetExaminationPlanView(x => scheduleDateList.Contains(x.ExaminationDate) && x.SchoolyearID == schoolyear.SchoolYearID
  1344. && x.RecordStatus == (int)EX_ExaminationPlanStatus.Submitted).ToList();
  1345. examinationPlanList = examinationPlanList.Where(x => x.StartTime < new TimeSpan(coursesTime.EndHour ?? 0, coursesTime.EndMinutes ?? 0, 0).Add(new TimeSpan(0, 1, 0))
  1346. && x.EndTime >= new TimeSpan(coursesTime.StartHour ?? 0, coursesTime.StartMinutes ?? 0, 0))
  1347. .ToList();
  1348. var examinationPlanIDList = examinationPlanList.Select(x => x.ExaminationPlanID).ToList();
  1349. var examinationRoomLayoutViewList = ExaminationPlanDAL.GetExaminationRoomLayoutView(x => examinationPlanIDList.Contains((Guid)x.ExaminationPlanID)).ToList();
  1350. examinationPlanList.ForEach(x => x.ExaminationRoomLayoutView = new HashSet<ExaminationRoomLayoutView>(examinationRoomLayoutViewList.Where(y => y.ExaminationPlanID == x.ExaminationPlanID)));
  1351. var examinationClassRoomIDList = examinationPlanList.SelectMany(x => x.ExaminationRoomLayoutView).Select(x => x.ClassroomID).Distinct().ToList();
  1352. result = result.Where(x => !examinationClassRoomIDList.Contains(x.ClassroomID));
  1353. }
  1354. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  1355. {
  1356. result = result
  1357. .DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  1358. }
  1359. result = result.OrderBy(x => x.Code);
  1360. return result.ToGridResultSet(pageIndex, pageSize);
  1361. }
  1362. public ScheduleAdjustmentEditView GetScheduleAdjustmentView(Guid educationSchedulingWeekNumID)
  1363. {
  1364. var stopApprovalStatus = this.EducationSchedulingStopServices.Value.GetCorrectEndStatus().Value;
  1365. var scheduleAdjustmentView = this.EducationSchedulingDAL.GetScheduleAdjustmentViewQueryable(x => true,
  1366. x => true, (x => true), (x => x.EducationSchedulingWeekNumID == educationSchedulingWeekNumID), stopApprovalStatus).FirstOrDefault();
  1367. return scheduleAdjustmentView;
  1368. }
  1369. public EducationSchedulingStopView GetEducationSchedulingStopView(Guid educationSchedulingID)
  1370. {
  1371. var scheduleStopView = this.EducationSchedulingDAL.GetEducationSchedulingStopViewQueryable(x => true, x => x.EducationSchedulingID == educationSchedulingID).FirstOrDefault();
  1372. var weekNumList = this.EducationSchedulingDAL.GetEducationMissionWeekNumQueryable(
  1373. x => x.EducationSchedulingID == educationSchedulingID);
  1374. scheduleStopView.ScheduleWeekNumList = weekNumList.Select(w => w.WeekNum)
  1375. .ToList();
  1376. return scheduleStopView;
  1377. }
  1378. public List<ClassroomScheduleView> GetClassroomScheduleViewList(Guid schoolyearID, Guid classroomID)
  1379. {
  1380. var scheduleQuery = (from es in this.EducationSchedulingDAL.EducationSchedulingRepository.GetList(x => x.SchoolyearID == schoolyearID
  1381. && x.ClassroomID == classroomID)
  1382. from esw in es.ES_EducationSchedulingWeekNum
  1383. select new
  1384. {
  1385. es.CoursesTimeID,
  1386. es.Weekday,
  1387. WeekNum = esw.WeekNum
  1388. }
  1389. ).Concat(
  1390. from ceu in this.ClassroomExcessiveUseDAL.ClassroomExcessiveUseRepository.GetList(x => x.SchoolyearID == schoolyearID
  1391. && x.ClassroomID == classroomID, (x => x.ES_ClassroomExcessiveUseScheduling.Select(w => w.ES_ClassroomExcessiveUseSchedulingWeekNum)))
  1392. from ceus in ceu.ES_ClassroomExcessiveUseScheduling
  1393. from ceusw in ceus.ES_ClassroomExcessiveUseSchedulingWeekNum
  1394. select new
  1395. {
  1396. ceus.CoursesTimeID,
  1397. ceus.Weekday,
  1398. WeekNum = ceusw.WeekNum
  1399. }
  1400. ).GroupBy(x => new { x.CoursesTimeID, x.Weekday })
  1401. .Select(x => new { x.Key.CoursesTimeID, x.Key.Weekday, WeekNumList = x.Select(w => w.WeekNum).Distinct() }).ToList();
  1402. var classroomScheduleList = (
  1403. from ct in this.CoursesTimeServices.Value.GetCoursesTimeViewList(new ConfiguretView(), null).ToList()
  1404. join es in scheduleQuery on ct.CoursesTimeID equals es.CoursesTimeID into des
  1405. from ees in des.DefaultIfEmpty()
  1406. select new
  1407. {
  1408. CoursesTime = ct,
  1409. Weekday = (ees == null) ? null : ees.Weekday,
  1410. WeekNumList = (ees == null) ? new List<int?>() : ees.WeekNumList
  1411. }).ToList();
  1412. var result = (from cs in classroomScheduleList
  1413. group cs by cs.CoursesTime.CoursesTimeID into g
  1414. select new ClassroomScheduleView
  1415. {
  1416. ClassroomID = classroomID,
  1417. CoursesTimeID = g.FirstOrDefault().CoursesTime.CoursesTimeID ?? Guid.Empty,
  1418. StartTimes = g.FirstOrDefault().CoursesTime.StartTimes,
  1419. EndTimes = g.FirstOrDefault().CoursesTime.EndTimes,
  1420. StartHour = g.FirstOrDefault().CoursesTime.StartHour,
  1421. EndHour = g.FirstOrDefault().CoursesTime.EndHour,
  1422. StartMinutes = g.FirstOrDefault().CoursesTime.StartMinutes,
  1423. EndMinutes = g.FirstOrDefault().CoursesTime.EndMinutes,
  1424. Monday = g.Where(x => x.Weekday != null && x.Weekday == (int)DayOfWeek.Monday)
  1425. .SelectMany(x => x.WeekNumList).Distinct().ToList()
  1426. .GetWeekNumString(),
  1427. Tuesday = g.Where(x => x.Weekday != null && x.Weekday == (int)DayOfWeek.Tuesday)
  1428. .SelectMany(x => x.WeekNumList).Distinct().ToList()
  1429. .GetWeekNumString(),
  1430. Wednesday = g.Where(x => x.Weekday != null && x.Weekday == (int)DayOfWeek.Wednesday)
  1431. .SelectMany(x => x.WeekNumList).Distinct().ToList()
  1432. .GetWeekNumString(),
  1433. Thurday = g.Where(x => x.Weekday != null && x.Weekday == (int)DayOfWeek.Thursday)
  1434. .SelectMany(x => x.WeekNumList).Distinct().ToList()
  1435. .GetWeekNumString(),
  1436. Friday = g.Where(x => x.Weekday != null && x.Weekday == (int)DayOfWeek.Friday)
  1437. .SelectMany(x => x.WeekNumList).Distinct().ToList()
  1438. .GetWeekNumString(),
  1439. Saturday = g.Where(x => x.Weekday != null && x.Weekday == (int)DayOfWeek.Saturday)
  1440. .SelectMany(x => x.WeekNumList).Distinct().ToList()
  1441. .GetWeekNumString(),
  1442. Sunday = g.Where(x => x.Weekday != null && x.Weekday == (int)DayOfWeek.Sunday)
  1443. .SelectMany(x => x.WeekNumList).Distinct().ToList()
  1444. .GetWeekNumString()
  1445. }).OrderBy(x => x.StartTimes).ToList();
  1446. return result;
  1447. }
  1448. private void ChangeCourseProcess(ES_EducationScheduling educationScheduling,
  1449. IList<EducationSchedulingTeacherListView> lastTeacherViewList,
  1450. IList<EducationSchedulingTeacherListView> newTeacherList)
  1451. {
  1452. var coursesTime = this.CoursesTimeServices.Value.GetCoursesTime(educationScheduling.CoursesTimeID);
  1453. var weekList = educationScheduling.ES_EducationSchedulingWeekNum.Select(x => x.WeekNum).ToList();
  1454. var userIDList = newTeacherList.Select(x => x.UserID).ToList();
  1455. var lastTeacherList = lastTeacherViewList.Select(x => new { x.UserID, x.TeachingMethod }).ToList();
  1456. var courseProcessList = this.EducationSchedulingClassDAL.EducationMissionClassDAL.Value.CourseProcessRepository
  1457. .GetList(x => x.EducationMissionClassID == educationScheduling.EM_EducationSchedulingClass.EducationMissionClassID,
  1458. (x => x.EM_CourseProcessTeacher))
  1459. .ToList();
  1460. var educationSchedulingList = this.EducationSchedulingDAL.EducationSchedulingRepository
  1461. .GetList(x => x.EM_EducationSchedulingClass.EducationMissionClassID == educationScheduling.EM_EducationSchedulingClass.EducationMissionClassID,
  1462. (x => x.ES_EducationSchedulingTeacher), (x => x.ES_EducationSchedulingWeekNum), (x => x.EM_CoursesTime))
  1463. .ToList();
  1464. var courseTimes = coursesTime.EndTimes - coursesTime.StartTimes + 1;
  1465. //先找出涉及周内,之前的老师上课的课程进度记录,这批是要扣减课时的,但扣到多少为止,后面查一下课表再说
  1466. var decreaseCourseProcessList = courseProcessList.Where(x => weekList.Contains(x.Week)
  1467. && (lastTeacherList.Join(x.EM_CourseProcessTeacher.ToList(),
  1468. (w => new { UserID = (Guid?)w.UserID, TeachType = w.TeachingMethod }),
  1469. (w => new { w.UserID, w.TeachType }),
  1470. ((w, y) => w)).Count() == lastTeacherList.Count
  1471. && lastTeacherList.Count == x.EM_CourseProcessTeacher.Count))
  1472. .ToList();
  1473. var increaseCourseProcessList = courseProcessList.Where(x => weekList.Contains(x.Week)
  1474. && (newTeacherList.Join(x.EM_CourseProcessTeacher.ToList(),
  1475. (w => new { UserID = (Guid?)w.UserID, TeachType = w.TeachingMethod }),
  1476. (w => new { w.UserID, w.TeachType }),
  1477. ((w, y) => w)).Count() == newTeacherList.Count
  1478. && newTeacherList.Count == x.EM_CourseProcessTeacher.Count))
  1479. .ToList();
  1480. var addCourseProcessWeekList = (from w in weekList
  1481. join icp in increaseCourseProcessList on w equals icp.Week into dicp
  1482. from icp in dicp.DefaultIfEmpty()
  1483. where icp == null
  1484. select w).ToList();
  1485. //保存起要扣减的记录,添加时要找回对应的教室类型和教室
  1486. var needAddCourseProcessList = decreaseCourseProcessList.Select(x => new {
  1487. x.Week,
  1488. x.ClassroomTypeID,
  1489. x.ClassroomID }).ToList();
  1490. decreaseCourseProcessList.ForEach(x =>
  1491. {
  1492. var minTimes = educationSchedulingList.Where(w => w.ES_EducationSchedulingWeekNum.Any(y => y.WeekNum == x.Week)
  1493. && w.ES_EducationSchedulingTeacher.Join(x.EM_CourseProcessTeacher,
  1494. (y => new { y.UserID, TeachType = y.TeachingMethod }),
  1495. (y => new { y.UserID, y.TeachType }),
  1496. ((y, z) => y)).Count() == w.ES_EducationSchedulingTeacher.Count
  1497. && w.ES_EducationSchedulingTeacher.Count == x.EM_CourseProcessTeacher.Count)
  1498. .Sum(w => w.EM_CoursesTime.EndTimes - w.EM_CoursesTime.StartTimes + 1);
  1499. if (x.Times - courseTimes < minTimes)
  1500. {
  1501. x.Times = minTimes;
  1502. }
  1503. else
  1504. {
  1505. x.Times -= courseTimes;
  1506. }
  1507. if (x.Times <= 0)
  1508. {
  1509. UnitOfWork.Remove(x);
  1510. }
  1511. else
  1512. {
  1513. SetModifyStatus(x);
  1514. }
  1515. });
  1516. increaseCourseProcessList.ForEach(x =>
  1517. {
  1518. x.Times += courseTimes;
  1519. SetModifyStatus(x);
  1520. });
  1521. addCourseProcessWeekList.ForEach(week =>
  1522. {
  1523. var currentLastCourseProcess = needAddCourseProcessList.FirstOrDefault(x => x.Week == week);
  1524. var newCourseProcess = new EM_CourseProcess
  1525. {
  1526. CourseProcessID = Guid.NewGuid(),
  1527. EducationMissionClassID = educationScheduling.EM_EducationSchedulingClass.EducationMissionClassID,
  1528. ClassroomTypeID = currentLastCourseProcess.ClassroomTypeID,
  1529. ClassroomID = currentLastCourseProcess.ClassroomID,
  1530. Times = courseTimes,
  1531. Week = week
  1532. };
  1533. SetNewStatus(newCourseProcess);
  1534. newTeacherList.ToList().ForEach(x =>
  1535. {
  1536. var newCourseProcessTeacher = new EM_CourseProcessTeacher
  1537. {
  1538. CourseProcessTeacherID = Guid.NewGuid(),
  1539. CourseProcessID = newCourseProcess.CourseProcessID,
  1540. UserID = x.UserID,
  1541. TeachType = x.TeachingMethod
  1542. };
  1543. SetNewStatus(newCourseProcessTeacher);
  1544. newCourseProcess.EM_CourseProcessTeacher.Add(newCourseProcessTeacher);
  1545. });
  1546. UnitOfWork.Add(newCourseProcess);
  1547. });
  1548. }
  1549. public void ChangeClassroom(Guid educationSchedulingID, Guid classroomID)
  1550. {
  1551. var educationScheduling = this.EducationSchedulingDAL.EducationSchedulingRepository
  1552. .GetSingle(x => x.EducationSchedulingID == educationSchedulingID,
  1553. (x => x.ES_EducationSchedulingTeacher), (x => x.ES_EducationSchedulingWeekNum), (x => x.EM_EducationSchedulingClass), (x => x.CF_Classroom.CF_ClassroomType));
  1554. educationScheduling.ClassroomID = classroomID;
  1555. this.UnitOfWork.Commit();
  1556. }
  1557. public List<EducationSchedulingTeacherListView> GetEducationSchedulingTeacherViewList(Guid educationSchedulingID)
  1558. {
  1559. var teacherViewQueryable = this.EducationSchedulingDAL.GetTeacherViewQueryable(x => x.EducationSchedulingID == educationSchedulingID);
  1560. return teacherViewQueryable.ToList();
  1561. }
  1562. private void CheckTeacherIsAvailable(ES_EducationScheduling educationScheduling, List<Guid> teacherIDList)
  1563. {
  1564. var notAvailableTeacherMessage = "";
  1565. var teacherIsOnWorkList = this.EducationSchedulingDAL.CheckTeacherIsOnWork(x =>
  1566. x.EducationSchedulingID == educationScheduling.EducationSchedulingID,
  1567. (x => teacherIDList.Contains(x.UserID))).ToList();
  1568. if (teacherIsOnWorkList.Count > 0)
  1569. {
  1570. teacherIsOnWorkList.ForEach(x => notAvailableTeacherMessage += string.Format("教师{0}在该节次不能排课。\n",
  1571. x.Name,
  1572. x.WeekdayDesc,
  1573. x.Times));
  1574. }
  1575. var teacherIsBusyList = this.EducationSchedulingDAL.CheckTeacherIsBusy(x =>
  1576. x.EducationSchedulingID == educationScheduling.EducationSchedulingID,
  1577. (x => teacherIDList.Contains(x.UserID))).ToList();
  1578. if (teacherIsBusyList.Count > 0)
  1579. {
  1580. teacherIsBusyList.ForEach(x => notAvailableTeacherMessage += string.Format("教师{0}在该节次在其他班级有课,不能排课。\n",
  1581. x.Name,
  1582. x.WeekdayDesc,
  1583. x.Times));
  1584. }
  1585. if (!string.IsNullOrEmpty(notAvailableTeacherMessage))
  1586. {
  1587. throw new Exception(notAvailableTeacherMessage);
  1588. }
  1589. }
  1590. private void RefreshEducationMissionClassTeachers(Guid educationMissionClassID)
  1591. {
  1592. var educationMissionClass = EducationSchedulingClassDAL.EducationMissionClassRepository
  1593. .GetSingle(x => x.EducationMissionClassID == educationMissionClassID,
  1594. (x => x.EM_MissionClassTeacher),
  1595. (x => x.EM_CourseProcess.Select(w => w.EM_CourseProcessTeacher)));
  1596. var teacherList = (from courseProcess in educationMissionClass.EM_CourseProcess
  1597. from teacher in courseProcess.EM_CourseProcessTeacher
  1598. group teacher by new { teacher.UserID, teacher.TeachType } into g
  1599. select g.FirstOrDefault()).ToList();
  1600. educationMissionClass.EM_MissionClassTeacher.ToList().ForEach(x => UnitOfWork.Remove(x));
  1601. teacherList.ForEach(x => {
  1602. var missionClassTeacher = new EM_MissionClassTeacher
  1603. {
  1604. MissionClassTeacherID = Guid.NewGuid(),
  1605. MissionClassID = educationMissionClassID,
  1606. UserID = x.UserID,
  1607. TeachType = x.TeachType
  1608. };
  1609. this.SetNewStatus(missionClassTeacher);
  1610. this.UnitOfWork.Add(missionClassTeacher);
  1611. });
  1612. }
  1613. public void ChangeTeacher(Guid educationSchedulingID, IList<EducationSchedulingTeacherListView> teacherList)
  1614. {
  1615. var educationScheduling = this.EducationSchedulingDAL.EducationSchedulingRepository.GetSingle(x => x.EducationSchedulingID == educationSchedulingID,
  1616. (x => x.ES_EducationSchedulingTeacher), (x => x.ES_EducationSchedulingWeekNum), (x => x.EM_EducationSchedulingClass), (x => x.CF_Classroom.CF_ClassroomType));
  1617. this.CheckTeacherIsAvailable(educationScheduling, teacherList.Select(x => x.UserID).ToList());
  1618. var lastTeacherList = this.EducationSchedulingDAL.GetTeacherViewQueryable(x => x.EducationSchedulingID == educationSchedulingID).ToList();
  1619. this.UnitOfWork.Remove<ES_EducationSchedulingTeacher>(x => x.EducationSchedulingID == educationSchedulingID);
  1620. teacherList.ToList().ForEach(x =>
  1621. {
  1622. var educationSchedulingTeacher = new ES_EducationSchedulingTeacher
  1623. {
  1624. EducationSchedulingTeacherID = Guid.NewGuid(),
  1625. EducationSchedulingID = educationSchedulingID,
  1626. UserID = x.UserID,
  1627. TeachingMethod = x.TeachingMethod
  1628. };
  1629. this.SetNewStatus(educationSchedulingTeacher);
  1630. this.UnitOfWork.Add(educationSchedulingTeacher);
  1631. });
  1632. this.ChangeCourseProcess(educationScheduling, lastTeacherList, teacherList);
  1633. this.RefreshEducationMissionClassTeachers(educationScheduling.EM_EducationSchedulingClass.EducationMissionClassID.Value);
  1634. this.UnitOfWork.Commit();
  1635. }
  1636. private void InitCommonByEducationSchedulingClassList(IList<EducationSchedulingClassScheduleView> educationSchedulingClassList)
  1637. {
  1638. SchedulingResult = new List<ES_EducationScheduling>(); //初始化排课结果
  1639. SchedulingWeekNumResult = new List<ES_EducationSchedulingWeekNum>();
  1640. SchedulingTeacherResult = new List<ES_EducationSchedulingTeacher>();
  1641. NotScheduledList = new List<EducationSchedulingClassScheduleView>();
  1642. SchoolYear = SchoolYearServices.Value.GetSchoolYearView(educationSchedulingClassList.First().SchoolYearID);
  1643. CourseTimeList = CoursesTimeServices.Value.GetCoursesTimeViewList(new ConfiguretView(), null);
  1644. CourseTimeList = CourseTimeList.OrderBy(x => x.StartTimes).ToList();
  1645. ArrangementList = ArrangementDAL.GetArrangementView(x => x.IsOnWork == true).ToList();
  1646. var staffIDList = educationSchedulingClassList.SelectMany(x => x.CourseProcessViewList)
  1647. .SelectMany(x => x.CourseProcessTeacherViewList)
  1648. .Select(x => x.UserID)
  1649. .Union(
  1650. educationSchedulingClassList.SelectMany(x => x.TeacherTeachingViewList)
  1651. .Select(x => x.UserID)
  1652. ).ToList();
  1653. StaffList = StaffDAL.staffRepository.GetList(x => staffIDList.Contains(x.UserID)).ToList();
  1654. CourseSchedulingSettingList = CourseScheduleDAL.CourseScheduleSettingRepository
  1655. .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  1656. TeacherSchedulingSettingList = TeacherScheduleDAL.TeacherScheduleSettingRepository
  1657. .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  1658. CourseTypePriorityList = this.CourseTypeScheduleDAL.CourseTypePriorityRepository.Entities.ToList();
  1659. TeacherScheduleContinuousCount = this.ParameterServices.Value.GetParameterValue<int>(CF_ParameterType.TeacherScheduleContinuousCount);
  1660. ClassScheduleContinuousCount = this.ParameterServices.Value.GetParameterValue<int>(CF_ParameterType.ClassScheduleContinuousCount);
  1661. ClassCourseScheduleContinuousCount = this.ParameterServices.Value.GetParameterValue<int>(CF_ParameterType.ClassCourseScheduleContinuousCount);
  1662. }
  1663. private void InitScheduleClassInfoByEducationSchedulingClassList(IList<EducationSchedulingClassScheduleView> educationSchedulingClassList)
  1664. {
  1665. var collegeIDList = educationSchedulingClassList.Select(x => x.CourseCollegeID).ToList();
  1666. CollegeList = CollegeScheduleDAL.CollegeDAL.Value.GetCollegeViewQueryable().Where(x => collegeIDList.Contains(x.CollegeID)).ToList();
  1667. var submittedCollegeQuery = this.CollegeScheduleDAL.CollegeScheduleStatusRepository
  1668. .GetList(x => collegeIDList.Contains(x.CollegeID) && x.RecordStatus == (int)ES_CollegeScheduleStatusCode.Submited
  1669. && x.SchoolyearID == SchoolYear.SchoolYearID)
  1670. .Include(x => x.CF_College);
  1671. var submittedCollege = submittedCollegeQuery.ToList();
  1672. if (submittedCollege.Count > 0)
  1673. {
  1674. throw new Exception(string.Join("、", submittedCollege.Select(x => x.CF_College.Name)) + "的相关课表已经提交,请先撤销提交后再进行排课。");
  1675. }
  1676. var today = DateTime.Today;
  1677. var collegePriority = this.CollegePriorityDAL.GetCollegePriorityViewQueryable(x => collegeIDList.Contains(x.CollegeID)).ToList();
  1678. var noPriorityCollege = (from c in CollegeList
  1679. join cp in collegePriority on c.CollegeID equals cp.CollegeID into dcp
  1680. from ecp in dcp.DefaultIfEmpty()
  1681. where ecp == null
  1682. select c).ToList();
  1683. if (noPriorityCollege.Count > 0)
  1684. {
  1685. throw new Exception(string.Join("、", noPriorityCollege.Select(x => x.Name)) + "的未设置排课时间,无法排课,请通知相关管理人员调整排课优先级设置。");
  1686. }
  1687. var expireCollege = collegePriority.Where(x => x.StartDate > today || x.EndDate < today).ToList();
  1688. if (expireCollege.Count > 0)
  1689. {
  1690. throw new Exception(string.Join("、", expireCollege.Select(x => x.CollegeName)) + "的已不在排课时间内,无法排课,请通知相关管理人员调整排课优先级设置。");
  1691. }
  1692. var educationSchedulingClassIDList = educationSchedulingClassList.Select(x => x.EducationSchedulingClassID).Distinct().ToList();
  1693. EducationSchedulingClassViewList = educationSchedulingClassList.ToList();
  1694. EducationSchedulingClassStudentViewList = EducationSchedulingClassDAL.GetEducationSchedulingClassStudentViewQueryable(x => educationSchedulingClassIDList.Contains(x.EducationSchedulingClassID))
  1695. .ToList();
  1696. ScheduledEducationViewList = this.GetEducationScheduleView(new ConfiguretView(), (x => x.SchoolyearID == SchoolYear.SchoolYearID), false).rows;
  1697. var scheduledClassIDList = ScheduledEducationViewList.Select(x => x.EducationSchedulingClassID).Distinct().ToList();
  1698. ScheduledEducationStudentViewList = EducationSchedulingClassDAL.GetEducationSchedulingClassStudentViewQueryable(x => scheduledClassIDList.Contains(x.EducationSchedulingClassID)).ToList();
  1699. }
  1700. public void GenerateSchedule(IList<Guid?> educationMissionClassIDList)
  1701. {
  1702. var educationSchedulingClassList = EducationSchedulingClassServices.Value.GetEducationSchedulingClassView(new ConfiguretView(),
  1703. (x => educationMissionClassIDList.Contains(x.EducationMissionClassID))).rows;
  1704. if (educationSchedulingClassList.Count == 0)
  1705. {
  1706. return;
  1707. }
  1708. if (educationSchedulingClassList.Select(x => x.SchoolYearID).Distinct().Count() > 1)
  1709. {
  1710. throw new Exception("所选记录包括不同学年学期的教学任务班,多个学期智能排课会使逻辑比较混乱,目前只支持同一个学年学期的智能排课。");
  1711. }
  1712. this.InitCommonByEducationSchedulingClassList(educationSchedulingClassList);
  1713. this.InitScheduleClassInfoByEducationSchedulingClassList(educationSchedulingClassList);
  1714. this.InitClassroomInfo();
  1715. this.GenerateScheduleByInited();
  1716. }
  1717. public List<MobileUserEducationScheduleView> GetMobileStudentSchedule(Guid userID, DateTime date)
  1718. {
  1719. Expression<Func<ES_EducationScheduling, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  1720. var schoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
  1721. var firstMonday = schoolyear.FirstWeek.Value.AddDays(1 - (int)schoolyear.FirstWeek.Value.DayOfWeek);
  1722. var todayWeekNum = Math.Ceiling((Math.Floor(date.Subtract(schoolyear.FirstWeek.Value).TotalDays + 1)) / 7);
  1723. var todayWeekday = date.DayOfWeek == DayOfWeek.Sunday ? 0 : (int)date.DayOfWeek;
  1724. exp = exp.And(x => x.SchoolyearID == schoolyear.SchoolYearID && x.Weekday == todayWeekday);
  1725. exp = exp.And(x => x.EM_EducationSchedulingClass.CF_Student.Any(w => w.UserID == userID));
  1726. exp = exp.And(x => x.ES_EducationSchedulingWeekNum.Any(w => w.WeekNum == todayWeekNum));
  1727. var scheduleViewList = this.GetEducationScheduleView(new ConfiguretView(), exp, false).rows;
  1728. var resultGroup = scheduleViewList.GroupBy(x => new {
  1729. SchoolyearID = x.SchoolyearID,
  1730. SchoolyearCode = x.SchoolyearCode,
  1731. CoursematerialID = x.CoursematerialID,
  1732. CoursematerialName = x.CoursematerialName,
  1733. TeachingModeID = x.TeachingModeID,
  1734. Weekday = x.Weekday,
  1735. TimeGroup = (x.CoursesTime.StartTimes - 1) / 2,
  1736. ClassroomID = x.ClassroomID,
  1737. ClassroomName = x.ClassroomName
  1738. //TeacherTeachingViewList = x.TeacherTeachingViewList
  1739. });
  1740. var resultList = resultGroup
  1741. .Select(x => new MobileUserEducationScheduleView
  1742. {
  1743. SchoolyearID = x.Key.SchoolyearID,
  1744. SchoolyearCode = x.Key.SchoolyearCode,
  1745. CoursematerialID = x.Key.CoursematerialID,
  1746. CoursematerialName = x.Key.CoursematerialName,
  1747. TeachingModeID = x.Key.TeachingModeID,
  1748. Weekday = x.Key.Weekday,
  1749. TimeGroup = x.Key.TimeGroup,
  1750. CoursesTimeList = x.Select(w => w.CoursesTime).ToList(),
  1751. ClassroomID = x.Key.ClassroomID,
  1752. ClassroomName = x.Key.ClassroomName
  1753. //TeacherTeachingViewList = x.Key.TeacherTeachingViewList
  1754. });
  1755. return resultList.OrderBy(x => x.TimeGroup)
  1756. .ToList();
  1757. }
  1758. public EducationMissionClassView GetEducationMissionClassViewBySchedule(Guid? schoolyearID, DateTime date, Guid coursesTimeID, Guid teacherUserID)
  1759. {
  1760. var currentSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
  1761. var firstWeek = currentSchoolyear.FirstWeek.Value.AddDays(1 - (int)currentSchoolyear.FirstWeek.Value.DayOfWeek);
  1762. var nowWeekNum = (date.Subtract(firstWeek).Days + 7) / 7;
  1763. var nowWeekday = (int)date.DayOfWeek == 0 ? 7 : (int)date.DayOfWeek;
  1764. var scheduling = this.EducationSchedulingDAL.GetEducationSchedulingViewQueryable(x => x.ES_EducationSchedulingTeacher.Any(w => w.UserID == teacherUserID)
  1765. && x.ES_EducationSchedulingWeekNum.Any(w => w.WeekNum == nowWeekNum) && x.Weekday == nowWeekday && x.CoursesTimeID == coursesTimeID && x.SchoolyearID == schoolyearID).FirstOrDefault();
  1766. if (scheduling == null) return null;
  1767. var educationMissionClass = this.EducationMissionClassDAL
  1768. .GetEducationMissionClassViewQueryble(x => x.EducationMissionClassID == scheduling.EducationMissionClassID)
  1769. .FirstOrDefault();
  1770. return educationMissionClass;
  1771. }
  1772. public List<EducationSchedulingWeekNumView> GetEducationSchedulingWeekNumViewByDateTimeList(Guid schoolyearID, IList<StartEndTimeView> dateTimeList)
  1773. {
  1774. var fullCoursesTimeList = this.SchoolYearServices.Value.GetCoursesTimeByDateTime(schoolyearID, dateTimeList);
  1775. var coursesTimeList = fullCoursesTimeList.Select(x => new { SchoolyearID = schoolyearID, x.WeekNum, x.Weekday, x.CoursesTimeID }).ToList();
  1776. var educationSchedulingViewList = this.EducationSchedulingDAL.GetEducationSchedulingWeekNumViewQueryable(x => true)
  1777. .SelectByKeys(coursesTimeList).ToList();
  1778. var educationMissionClassIDList = educationSchedulingViewList.Select(x => x.EducationMissionClassID).Distinct().ToList();
  1779. var teacherList = this.EducationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassIDList.Contains(x.EducationMissionClassID)).ToList();
  1780. var studentList = this.EducationSchedulingClassDAL.EducationSchedulingClassRepository.GetList(x => educationMissionClassIDList.Contains(x.EducationMissionClassID),
  1781. (x => x.CF_Student)).ToList();
  1782. educationSchedulingViewList.ForEach(x =>
  1783. {
  1784. var fullCoursesTime = fullCoursesTimeList.FirstOrDefault(w => w.WeekNum == x.WeekNum && w.Weekday == x.Weekday && w.CoursesTimeID == x.CoursesTimeID);
  1785. x.TeacherList = teacherList.Where(w => w.EducationMissionClassID == x.EducationMissionClassID).ToList();
  1786. x.Date = fullCoursesTime.Date;
  1787. x.StartTime = new TimeSpan(fullCoursesTime.StartHour ?? 0, fullCoursesTime.StartMinute ?? 0, 0);
  1788. x.EndTime = new TimeSpan(fullCoursesTime.EndHour ?? 0, fullCoursesTime.EndMinute ?? 0, 0);
  1789. x.StudentList = studentList.Where(w => w.EducationMissionClassID == x.EducationMissionClassID).SelectMany(w => w.CF_Student).ToList();
  1790. });
  1791. return educationSchedulingViewList;
  1792. }
  1793. /// <summary>
  1794. /// 手动排考查询排考时间有课的老师
  1795. /// </summary>
  1796. /// <param name="schoolyearID"></param>
  1797. /// <param name="dateTimeList"></param>
  1798. /// <returns></returns>
  1799. public List<EducationSchedulingWeekNumView> GetEducationSchedulingWeekNumViewForExaminationTeacher(Guid schoolyearID, IList<StartEndTimeView> dateTimeList)
  1800. {
  1801. var fullCoursesTimeList = this.SchoolYearServices.Value.GetCoursesTimeByDateTime(schoolyearID, dateTimeList);
  1802. var coursesTimeList = fullCoursesTimeList.Select(x => new { SchoolyearID = schoolyearID, x.WeekNum, x.Weekday, x.CoursesTimeID }).ToList();
  1803. var educationSchedulingViewList = this.EducationSchedulingDAL.GetEducationSchedulingWeekNumViewQueryable(x => true)
  1804. .SelectByKeys(coursesTimeList).ToList();
  1805. var educationMissionClassIDList = educationSchedulingViewList.Select(x => x.EducationMissionClassID).Distinct().ToList();
  1806. var teacherListScheduling = this.EducationMissionClassDAL.GetEducationSchedulingTeacherQuery(x => educationMissionClassIDList.Contains(x.EducationMissionClassID)).ToList();
  1807. var teacherList = this.EducationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassIDList.Contains(x.EducationMissionClassID)).ToList();
  1808. var studentList = this.EducationSchedulingClassDAL.EducationSchedulingClassRepository.GetList(x => educationMissionClassIDList.Contains(x.EducationMissionClassID),
  1809. (x => x.CF_Student)).ToList();
  1810. educationSchedulingViewList.ForEach(x =>
  1811. {
  1812. var fullCoursesTime = fullCoursesTimeList.FirstOrDefault(w => w.WeekNum == x.WeekNum && w.Weekday == x.Weekday && w.CoursesTimeID == x.CoursesTimeID);
  1813. //x.TeacherList = teacherList.Where(w => w.EducationMissionClassID == x.EducationMissionClassID).ToList();
  1814. x.TeacherList = teacherListScheduling.Where(w => w.WeekNum == x.WeekNum && w.Weekday == x.Weekday && w.CoursesTimeID == x.CoursesTimeID).ToList();
  1815. x.Date = fullCoursesTime.Date;
  1816. x.StartTime = new TimeSpan(fullCoursesTime.StartHour ?? 0, fullCoursesTime.StartMinute ?? 0, 0);
  1817. x.EndTime = new TimeSpan(fullCoursesTime.EndHour ?? 0, fullCoursesTime.EndMinute ?? 0, 0);
  1818. x.StudentList = studentList.Where(w => w.EducationMissionClassID == x.EducationMissionClassID).SelectMany(w => w.CF_Student).ToList();
  1819. });
  1820. return educationSchedulingViewList;
  1821. }
  1822. }
  1823. public class ClassroomConflictException : Exception
  1824. {
  1825. public ClassroomConflictException(string message)
  1826. : base(message)
  1827. {
  1828. }
  1829. public ClassroomConflictException(string message, Exception ex)
  1830. : base(message, ex)
  1831. {
  1832. }
  1833. }
  1834. }