EducationMissionClassServices.cs 106 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using EMIS.Entities;
  7. using EMIS.Utility;
  8. using Bowin.Common.Linq;
  9. using Bowin.Common.Linq.Entity;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.EducationManagement;
  12. using EMIS.ViewModel.EducationManage;
  13. using EMIS.ViewModel.CacheManage;
  14. using EMIS.ViewModel.UniversityManage.ClassroomManage;
  15. using EMIS.ViewModel.UniversityManage.TeacherManage;
  16. using EMIS.DataLogic.Common.Students;
  17. using EMIS.DataLogic.UniversityManage.TeacherManage;
  18. using EMIS.DataLogic.RetakeManage;
  19. using EMIS.DataLogic.SchedulingManage.SchedulingSettings;
  20. using EMIS.DataLogic.SelectCourse;
  21. using EMIS.DataLogic.EducationManage;
  22. using EMIS.DataLogic.Common.CalendarManage;
  23. using EMIS.DataLogic.EducationSchedule;
  24. using EMIS.CommonLogic.Students;
  25. using EMIS.ViewModel.UniversityManage.SpecialtyClassManage;
  26. namespace EMIS.CommonLogic.EducationManagement
  27. {
  28. public partial class EducationMissionClassServices : BaseServices, IEducationMissionClassServices
  29. {
  30. public ExecutableMinorPlanDAL ExecutableMinorPlanDAL { get; set; }
  31. public RetakePlanDAL RetakePlanDAL { get; set; }
  32. public EducationMissionClassDAL educationMissionClassDAL { get; set; }
  33. public ClassroomScheduleDAL ClassroomScheduleDAL { get; set; }
  34. public SchoolYearDAL schoolYearDAL { get; set; }
  35. public IStudentsServices studentServices { get; set; }
  36. public Lazy<StudentsDAL> StudentsDAL { get; set; }
  37. public Lazy<StaffDAL> staffDAL { get; set; }
  38. public CourseTimeHoursDAL CourseTimeHoursDAL { get; set; }
  39. public CoursesTimeDAL coursesTimeDAL { get; set; }
  40. public OptionalCourseSettingDAL OptionalCourseSettingDAL { get; set; }
  41. public ExecutableFreeSelectionCouseDAL ExecutableFreeSelectionCouseDAL { get; set; }
  42. public EducationMissionOpenControlDAL EducationMissionOpenControlDAL { get; set; }
  43. /// <summary>
  44. /// 根据任务班ID查询对应班级
  45. /// </summary>
  46. /// <param name="eductionMissionClassID"></param>
  47. /// <returns></returns>
  48. public ClassmajorView GetClassmajorByEducationClassID(Guid? eductionMissionClassID)
  49. {
  50. Expression<Func<EM_EducationMissionClass, bool>> exp = x => true;
  51. if (eductionMissionClassID.HasValue)
  52. {
  53. exp = exp.And(x => x.EducationMissionClassID == eductionMissionClassID);
  54. }
  55. return educationMissionClassDAL.GetClassmajorByEducationMissionClassID(exp);
  56. }
  57. //添加学生
  58. public void AddStudentbyEducationMissionClassID(Guid? educationMissionClassID, List<Guid> userIDs)
  59. {
  60. try
  61. {
  62. List<CF_Student> stuList = new List<CF_Student>();
  63. var queryUserIDList = userIDs.Select(x => (Guid?)x).ToList();
  64. //EM_EducationSchedulingClass educationSchedulingClass = ClassroomScheduleDAL.EducationSchedulingRepository.GetList(x => x.EM_EducationSchedulingClass.EducationMissionClassID == educationMissionClassID);
  65. EducationMissionClassView educationMissionClassView = GetEducationMissionClassView(educationMissionClassID);
  66. List<EducationMissionClassStudentView> studentList = GetEducationMissionClassSchedulingStudentViewList(educationMissionClassID);
  67. var studentcount = studentList.Where(x => queryUserIDList.Contains(x.UserID)).Count();
  68. if (studentcount > 0)
  69. {
  70. throw new Exception("抱歉,您添加的学生的数据中已存在学生,请检查!");
  71. }
  72. List<EM_EducationSchedulingClass> educationSchedulingClassList = GetEducationSchedulingClassList(educationMissionClassID);
  73. EM_EducationSchedulingClass educationSchedulingClass = educationSchedulingClassList.FirstOrDefault();
  74. foreach (var userID in userIDs)
  75. {
  76. Expression<Func<CF_Student, bool>> expression = x => x.UserID == userID;
  77. educationSchedulingClass.CF_Student.Add(StudentsDAL.Value.StudentRepository.GetSingle(expression));
  78. }
  79. UnitOfWork.Commit();
  80. }
  81. catch (Exception)
  82. {
  83. throw;
  84. }
  85. }
  86. /// <summary>
  87. /// 查询教师列表
  88. /// </summary>
  89. /// <param name="configuretView">查询条件实体</param>
  90. /// <param name="campusID">校区ID</param>
  91. /// <param name="collegeID">学院ID</param>
  92. /// <param name="DepartmentID">教研室ID</param>
  93. /// <param name="isPhoto">是否显示照片</param>
  94. /// <param name="pageIndex">页码</param>
  95. /// <param name="pageSize">显示码</param>
  96. /// <returns></returns>
  97. public IGridResultSet<StaffView> GetStaffViewGrid(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, int? isPhoto, Guid? userID, int pageIndex, int pageSize)
  98. {
  99. var query = staffDAL.Value.GetStaffViewQueryable(x => true);
  100. if (campusID.HasValue)
  101. query = query.Where(x => x.CampusID == campusID);
  102. if (collegeID.HasValue)
  103. query = query.Where(x => x.CollegeID == collegeID);
  104. if (userID.HasValue)
  105. query = query.Where(x => x.UserID == userID);
  106. if (departmentID.HasValue)
  107. query = query.Where(x => x.DepartmentID == departmentID);
  108. if (isPhoto > 0)
  109. query = query.Where(x => x.PhotoUrl != null && x.PhotoUrl != "");
  110. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  111. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  112. return query
  113. .OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode)
  114. .ToGridResultSet<StaffView>(pageIndex, pageSize);
  115. }
  116. public void DeleteStudentbyEducationMissionClassID(Guid? educationMissionClassID, List<Guid> userIDs)
  117. {
  118. try
  119. {
  120. List<CF_Student> stuList = new List<CF_Student>();
  121. var queryUserIDList = userIDs.Select(x => (Guid?)x).ToList();
  122. //EM_EducationSchedulingClass educationSchedulingClass = ClassroomScheduleDAL.EducationSchedulingRepository.GetList(x => x.EM_EducationSchedulingClass.EducationMissionClassID == educationMissionClassID);
  123. //EducationMissionClassView educationMissionClassView = GetEducationMissionClassView(educationMissionClassID);
  124. //List<EducationMissionClassStudentView> studentList = GetEducationMissionClassSchedulingStudentViewList(educationMissionClassID);
  125. //var studentcount = studentList.Where(x => queryUserIDList.Contains(x.UserID)).Count();
  126. //if (studentcount > 0)
  127. //{
  128. // throw new Exception("抱歉,您添加的学生的数据中已存在学生,请检查!");
  129. //}
  130. List<EM_EducationSchedulingClass> educationSchedulingClassList = GetEducationSchedulingClassList(educationMissionClassID);
  131. EM_EducationSchedulingClass educationSchedulingClass = educationSchedulingClassList.FirstOrDefault();
  132. foreach (var userID in userIDs)
  133. {
  134. Expression<Func<CF_Student, bool>> expression = x => x.UserID == userID;
  135. educationSchedulingClass.CF_Student.Remove(StudentsDAL.Value.StudentRepository.GetSingle(expression));
  136. }
  137. UnitOfWork.Commit();
  138. }
  139. catch (Exception)
  140. {
  141. throw;
  142. }
  143. }
  144. /// <summary>
  145. /// 查询教学任务班
  146. /// </summary>
  147. /// <param name="configuretView">查询条件</param>
  148. /// <param name="schoolyearID">学年学期ID</param>
  149. /// <param name="courseCode">课程代码</param>
  150. /// <param name="courseName">课程名称</param>
  151. /// <param name="name">排课班级</param>
  152. /// <param name="pageIndex">页数</param>
  153. /// <param name="pageSize">显示数</param>
  154. /// <returns></returns>
  155. public Bowin.Common.Linq.Entity.IGridResultSet<EducationMissionClassView> GetEducationMissionClassViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? schoolyearID, Guid? departmentID, Guid? coursematerialID,
  156. int? approvalStatus, int? teachingModeID, Guid? classmajorID, int? gradeYearID, int pageIndex, int pageSize)
  157. {
  158. bool hasClassmajorFilter = false;
  159. Expression<Func<EM_EducationMissionClass, bool>> exp = (x => true);
  160. Expression<Func<CF_Classmajor, bool>> classmajorFilter = x => true;
  161. if (campusID.HasValue)
  162. {
  163. exp = exp.And(x => x.EM_EducationMission.CF_College.CampusID == campusID);
  164. }
  165. if (collegeID.HasValue)
  166. {
  167. exp = exp.And(x => x.EM_EducationMission.CF_Department.CollegeID == collegeID);
  168. }
  169. if (departmentID.HasValue)
  170. {
  171. exp = exp.And(x => x.EM_EducationMission.DepartmentID == departmentID);
  172. }
  173. if (gradeYearID.HasValue)
  174. {
  175. hasClassmajorFilter = true;
  176. classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.GradeID == gradeYearID);
  177. }
  178. if (classmajorID.HasValue)
  179. {
  180. hasClassmajorFilter = true;
  181. classmajorFilter = classmajorFilter.And(x => x.ClassmajorID == classmajorID);
  182. }
  183. if (hasClassmajorFilter)
  184. {
  185. exp = exp.And(w => w.CF_Classmajor.AsQueryable().Any(classmajorFilter));
  186. }
  187. if (schoolyearID.HasValue)
  188. {
  189. exp = exp.And(x => x.EM_EducationMission.SchoolyearID == schoolyearID);
  190. }
  191. if (coursematerialID.HasValue)
  192. {
  193. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  194. }
  195. if (approvalStatus.HasValue)
  196. {
  197. exp = exp.And(x => x.RecordStatus == approvalStatus);
  198. }
  199. if (teachingModeID.HasValue)
  200. {
  201. exp = exp.And(x => x.TeachingModeID == teachingModeID);
  202. }
  203. var query = educationMissionClassDAL.GetEducationMissionClassViewQueryble(exp);
  204. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  205. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  206. var result = this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearCode)
  207. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeYearID)
  208. .ThenBy(x => x.StandardID).ThenBy(x => x.CourseName).ThenBy(x => x.OrderNo).ThenBy(x => x.Name)
  209. .ToGridResultSet<EducationMissionClassView>(pageIndex, pageSize);
  210. var educationMissionClassID = result.rows.Select(x => x.EducationMissionClassID).ToList();
  211. var missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).ToList();
  212. result.rows.ForEach(x => x.MissionClassTeacherView = new HashSet<MissionClassTeacherView>(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID)));
  213. //result.rows.ForEach(x => x.CourseTimeID = new HashSet<EM_CoursesTime>(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID)));
  214. return result;
  215. }
  216. /// <summary>
  217. /// 查询教学任务班
  218. /// </summary>
  219. /// <param name="configuretView">查询条件</param>
  220. /// <param name="schoolyearID">学年学期ID</param>
  221. /// <param name="courseCode">课程代码</param>
  222. /// <param name="courseName">课程名称</param>
  223. /// <param name="name">排课班级</param>
  224. /// <returns></returns>
  225. public List<EducationMissionClassView> GetEducationMissionClassViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? schoolyearID, Guid? departmentID, Guid? coursematerialID,
  226. int? approvalStatus, int? teachingModeID, Guid? classmajorID, int? gradeYearID)
  227. {
  228. bool hasClassmajorFilter = false;
  229. Expression<Func<EM_EducationMissionClass, bool>> exp = (x => true);
  230. Expression<Func<CF_Classmajor, bool>> classmajorFilter = x => true;
  231. if (campusID.HasValue)
  232. {
  233. exp = exp.And(x => x.EM_EducationMission.CF_College.CampusID == campusID);
  234. }
  235. if (collegeID.HasValue)
  236. {
  237. exp = exp.And(x => x.EM_EducationMission.CF_Department.CollegeID == collegeID);
  238. }
  239. if (departmentID.HasValue)
  240. {
  241. exp = exp.And(x => x.EM_EducationMission.DepartmentID == departmentID);
  242. }
  243. if (gradeYearID.HasValue)
  244. {
  245. hasClassmajorFilter = true;
  246. classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.GradeID == gradeYearID);
  247. }
  248. if (classmajorID.HasValue)
  249. {
  250. hasClassmajorFilter = true;
  251. classmajorFilter = classmajorFilter.And(x => x.ClassmajorID == classmajorID);
  252. }
  253. if (hasClassmajorFilter)
  254. {
  255. exp = exp.And(w => w.CF_Classmajor.AsQueryable().Any(classmajorFilter));
  256. }
  257. if (schoolyearID.HasValue)
  258. {
  259. exp = exp.And(x => x.EM_EducationMission.SchoolyearID == schoolyearID);
  260. }
  261. if (coursematerialID.HasValue)
  262. {
  263. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  264. }
  265. if (approvalStatus.HasValue)
  266. {
  267. exp = exp.And(x => x.RecordStatus == approvalStatus);
  268. }
  269. if (teachingModeID.HasValue)
  270. {
  271. exp = exp.And(x => x.TeachingModeID == teachingModeID);
  272. }
  273. var query = educationMissionClassDAL.GetEducationMissionClassViewQueryble(exp);
  274. var educationMissionClassID = query.Select(x => x.EducationMissionClassID).ToList();
  275. var missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).ToList();
  276. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  277. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  278. var result = this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearCode)
  279. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeYearID)
  280. .ThenBy(x => x.StandardID).ThenBy(x => x.CourseName).ThenBy(x => x.OrderNo).ThenBy(x => x.Name)
  281. .ToList();
  282. result.ForEach(x => x.MissionClassTeacherView = new HashSet<MissionClassTeacherView>(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID)));
  283. return result;
  284. }
  285. /// <summary>
  286. /// 查询教学任务班
  287. /// </summary>
  288. /// <param name="configuretView">查询条件</param>
  289. /// <param name="schoolyearID">学年学期ID</param>
  290. /// <param name="courseCode">课程代码</param>
  291. /// <param name="courseName">课程名称</param>
  292. /// <param name="name">排课班级</param>
  293. /// <param name="pageIndex">页数</param>
  294. /// <param name="pageSize">显示数</param>
  295. /// <returns></returns>
  296. public Bowin.Common.Linq.Entity.IGridResultSet<EducationMissionClassView> GetEducationMissionClassViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? schoolyearID, int? standardID, Guid? coursematerialID,
  297. int? approvalStatus, int? teachingModeID, Guid? classmajorID, int? gradeYearID, Guid? CoursesTimeID, int pageIndex, int pageSize)
  298. {
  299. bool hasClassmajorFilter = false;
  300. Expression<Func<EM_EducationMissionClass, bool>> exp = (x => true);
  301. Expression<Func<CF_Classmajor, bool>> classmajorExp = (x => true);
  302. if (campusID.HasValue)
  303. {
  304. exp = exp.And(x => x.EM_EducationMission.CF_College.CampusID == campusID);
  305. }
  306. if (collegeID.HasValue)
  307. {
  308. exp = exp.And(x => x.EM_EducationMission.CF_Department.CollegeID == collegeID);
  309. }
  310. if (CoursesTimeID.HasValue)
  311. {
  312. exp = exp.And(x => x.EM_CoursesTime.Any(c => c.CoursesTimeID == CoursesTimeID));
  313. }
  314. if (standardID.HasValue)
  315. {
  316. hasClassmajorFilter = true;
  317. classmajorExp = classmajorExp.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
  318. }
  319. if (gradeYearID.HasValue)
  320. {
  321. hasClassmajorFilter = true;
  322. classmajorExp = classmajorExp.And(x => x.CF_Grademajor.GradeID == gradeYearID);
  323. }
  324. if (classmajorID.HasValue)
  325. {
  326. hasClassmajorFilter = true;
  327. classmajorExp = classmajorExp.And(x => x.ClassmajorID == classmajorID);
  328. }
  329. if (hasClassmajorFilter)
  330. {
  331. exp = exp.And(w => w.CF_Classmajor.AsQueryable().Any(classmajorExp));
  332. }
  333. if (schoolyearID.HasValue)
  334. {
  335. exp = exp.And(x => x.EM_EducationMission.SchoolyearID == schoolyearID);
  336. }
  337. if (coursematerialID.HasValue)
  338. {
  339. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  340. }
  341. if (approvalStatus.HasValue)
  342. {
  343. exp = exp.And(x => x.RecordStatus == approvalStatus);
  344. }
  345. if (teachingModeID.HasValue)
  346. {
  347. exp = exp.And(x => x.TeachingModeID == teachingModeID);
  348. }
  349. var query = educationMissionClassDAL.GetEducationMissionClassViewQueryble(exp);
  350. if (configuretView.Attribute == "TeacherName" && !string.IsNullOrEmpty(configuretView.ConditionValue))
  351. {
  352. var educationMissionClassID = query.Select(x => x.EducationMissionClassID).ToList();
  353. //获取查询结果教学任务所有教师
  354. var missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).ToList();
  355. //按教师姓名条件查询对应教学任务
  356. missionClassTeacherList = missionClassTeacherList.Where(x => x.Name == configuretView.ConditionValue).ToList();
  357. var missionClassIDList = missionClassTeacherList.Select(x => x.EducationMissionClassID).ToList();
  358. //由于教学任务可能有多个教师授课,所以还要再拿筛选后的教学任务在匹配一次教师
  359. missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => missionClassIDList.Contains(x.EducationMissionClassID)).ToList();
  360. query = query.Where(x => missionClassIDList.Contains(x.EducationMissionClassID));
  361. var resultQuery = this.GetQueryByDataRangeByDepartment(query).OrderByDescending(x => x.SchoolyearCode)
  362. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeYearID)
  363. .ThenBy(x => x.StandardID).ThenBy(x => x.CourseName).ThenBy(x => x.OrderNo).ThenBy(x => x.Name);
  364. var result = resultQuery.ToGridResultSet<EducationMissionClassView>(pageIndex, pageSize);
  365. result.rows.ForEach(x => x.MissionClassTeacherView = new HashSet<MissionClassTeacherView>(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID)));
  366. return result;
  367. }
  368. else
  369. {
  370. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && configuretView.Attribute != "TeacherName")
  371. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  372. var resultQuery = this.GetQueryByDataRangeByDepartment(query).OrderByDescending(x => x.SchoolyearCode)
  373. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeYearID)
  374. .ThenBy(x => x.StandardID).ThenBy(x => x.CourseName).ThenBy(x => x.OrderNo).ThenBy(x => x.Name);
  375. var result = resultQuery.ToGridResultSet<EducationMissionClassView>(pageIndex, pageSize);
  376. var educationMissionClassID = result.rows.Select(x => x.EducationMissionClassID).ToList();
  377. var missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).ToList();
  378. result.rows.ForEach(x => x.MissionClassTeacherView = new HashSet<MissionClassTeacherView>(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID)));
  379. return result;
  380. }
  381. }
  382. public List<EducationMissionClassView> GetEducationMissionClassViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? schoolyearID, int? standardID, Guid? coursematerialID, int? approvalStatus, int? teachingModeID, Guid? classmajorID, int? gradeYearID, int? learningformID, int? education, string LearnSystem, List<Guid?> EducationMissionClassIDList)
  383. {
  384. bool hasClassmajorFilter = false;
  385. Expression<Func<EM_EducationMissionClass, bool>> exp = (x => true);
  386. Expression<Func<CF_Classmajor, bool>> classmajorExp = (x => true);
  387. if (EducationMissionClassIDList!=null)
  388. {
  389. exp = exp.And(x => EducationMissionClassIDList.Contains(x.EducationMissionClassID));
  390. }
  391. if (campusID.HasValue)
  392. {
  393. exp = exp.And(x => x.EM_EducationMission.CF_College.CampusID == campusID);
  394. }
  395. if (collegeID.HasValue)
  396. {
  397. exp = exp.And(x => x.EM_EducationMission.CF_Department.CollegeID == collegeID);
  398. }
  399. if (standardID.HasValue)
  400. {
  401. hasClassmajorFilter = true;
  402. classmajorExp = classmajorExp.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
  403. }
  404. if (gradeYearID.HasValue)
  405. {
  406. hasClassmajorFilter = true;
  407. classmajorExp = classmajorExp.And(x => x.CF_Grademajor.GradeID == gradeYearID);
  408. }
  409. if (classmajorID.HasValue)
  410. {
  411. hasClassmajorFilter = true;
  412. classmajorExp = classmajorExp.And(x => x.ClassmajorID == classmajorID);
  413. }
  414. if (hasClassmajorFilter)
  415. {
  416. exp = exp.And(w => w.CF_Classmajor.AsQueryable().Any(classmajorExp));
  417. }
  418. if (schoolyearID.HasValue)
  419. {
  420. exp = exp.And(x => x.EM_EducationMission.SchoolyearID == schoolyearID);
  421. }
  422. if (coursematerialID.HasValue)
  423. {
  424. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  425. }
  426. if (approvalStatus.HasValue)
  427. {
  428. exp = exp.And(x => x.RecordStatus == approvalStatus);
  429. }
  430. if (teachingModeID.HasValue)
  431. {
  432. exp = exp.And(x => x.TeachingModeID == teachingModeID);
  433. }
  434. if (learningformID.HasValue)
  435. exp = exp.And(x => x.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID));
  436. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  437. {
  438. var LearnSystems = Convert.ToDecimal(LearnSystem);
  439. exp = exp.And(x => x.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems));
  440. }
  441. if (education.HasValue)
  442. {
  443. exp = exp.And(x => x.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.EducationID == education.Value));
  444. }
  445. var query = educationMissionClassDAL.GetEducationMissionClassViewQueryble(exp);
  446. if (configuretView.Attribute == "TeacherName" && !string.IsNullOrEmpty(configuretView.ConditionValue))
  447. {
  448. var educationMissionClassID = query.Select(x => x.EducationMissionClassID).ToList();
  449. //获取查询结果教学任务所有教师
  450. var missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).ToList();
  451. //按教师姓名条件查询对应教学任务
  452. missionClassTeacherList = missionClassTeacherList.Where(x => x.Name == configuretView.ConditionValue).ToList();
  453. var missionClassIDList = missionClassTeacherList.Select(x => x.EducationMissionClassID).ToList();
  454. //由于教学任务可能有多个教师授课,所以还要再拿筛选后的教学任务在匹配一次教师
  455. missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => missionClassIDList.Contains(x.EducationMissionClassID)).ToList();
  456. query = query.Where(x => missionClassIDList.Contains(x.EducationMissionClassID));
  457. var resultQuery = this.GetQueryByDataRangeByDepartment(query).OrderByDescending(x => x.SchoolyearCode)
  458. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeYearID)
  459. .ThenBy(x => x.StandardID).ThenBy(x => x.CourseName).ThenBy(x => x.OrderNo).ThenBy(x => x.Name);
  460. var result = resultQuery.ToList();
  461. result.ForEach(x => x.MissionClassTeacherView = new HashSet<MissionClassTeacherView>(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID)));
  462. return result;
  463. }
  464. else
  465. {
  466. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && configuretView.Attribute != "TeacherName")
  467. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  468. var resultQuery = this.GetQueryByDataRangeByDepartment(query).OrderByDescending(x => x.SchoolyearCode)
  469. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeYearID)
  470. .ThenBy(x => x.StandardID).ThenBy(x => x.CourseName).ThenBy(x => x.OrderNo).ThenBy(x => x.Name);
  471. var result = resultQuery.ToList();
  472. var educationMissionClassID = result.Select(x => x.EducationMissionClassID).ToList();
  473. var missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).ToList();
  474. result.ForEach(x => x.MissionClassTeacherView = new HashSet<MissionClassTeacherView>(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID)));
  475. return result;
  476. }
  477. }
  478. /// <summary>
  479. /// 查询教学任务班
  480. /// </summary>
  481. /// <param name="configuretView">查询条件</param>
  482. /// <param name="schoolyearID">学年学期ID</param>
  483. /// <param name="courseCode">课程代码</param>
  484. /// <param name="courseName">课程名称</param>
  485. /// <param name="name">排课班级</param>
  486. /// <returns></returns>
  487. public List<EducationMissionClassView> GetEducationMissionClassViewList(IList<Guid> educationMissionClassIDList)
  488. {
  489. Expression<Func<EM_EducationMissionClass, bool>> exp = (x => educationMissionClassIDList.Contains(x.EducationMissionClassID));
  490. var query = educationMissionClassDAL.GetEducationMissionClassViewQueryble(exp);
  491. var missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassIDList.Contains(x.EducationMissionClassID)).ToList();
  492. var result = this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearCode)
  493. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeYearID)
  494. .ThenBy(x => x.StandardID).ThenBy(x => x.CourseName).ThenBy(x => x.OrderNo).ThenBy(x => x.Name)
  495. .ToList();
  496. var missionClassClassmajorList = educationMissionClassDAL.GetClassmajorQuery(x => educationMissionClassIDList.Contains(x.EducationMissionClassID)).ToList();
  497. result.ForEach(x => x.ClassmajorViewList = new HashSet<ClassView>
  498. (missionClassClassmajorList.Where(y => y.CoursematerialID == x.CoursematerialID
  499. && y.TeachingModeID == x.TeachingModeID
  500. && y.SchoolyearID == x.SchoolyearID)));
  501. result.ForEach(x => x.MissionClassTeacherView = new HashSet<MissionClassTeacherView>(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID)));
  502. return result;
  503. }
  504. /// <summary>
  505. /// 获取任务班信息
  506. /// </summary>
  507. /// <param name="educationMissionClassID"></param>
  508. /// <returns></returns>
  509. public EducationMissionClassView GetEducationMissionClassView(Guid? educationMissionClassID)
  510. {
  511. return educationMissionClassDAL.GetEducationMissionClassViewQueryble(x => x.EducationMissionClassID == educationMissionClassID).FirstOrDefault();
  512. }
  513. /// <summary>
  514. /// 获取任务班信息
  515. /// </summary>
  516. /// <param name="educationMissionClassID"></param>
  517. /// <returns></returns>
  518. public Entities.EM_EducationMissionClass GetEducationMissionClass(Guid? educationMissionClassID)
  519. {
  520. return educationMissionClassDAL.EducationMissionClassRepository.GetSingle(x => x.EducationMissionClassID == educationMissionClassID,
  521. (x => x.EM_EducationMission),
  522. (x => x.CF_Classmajor),
  523. (x => x.EM_CoursesTime),
  524. (x => x.EM_MissionClassTeacher),
  525. (x => x.EM_EducationMissionClassSettings),
  526. (x => x.EM_CourseProcess),
  527. (x => x.EM_CourseProcess.Select(y => y.EM_CourseProcessTeacher)),
  528. (x => x.EM_EducationSchedulingClass),
  529. (x => x.EM_EducationMissionClassTeachingSetting),
  530. (x => x.CF_Classroom));
  531. }
  532. /// <summary>
  533. /// 保存更新排课序号
  534. /// </summary>
  535. /// <param name="educationMissionClasss"></param>
  536. /// <param name="orderNos"></param>
  537. public void UpdateEducationMissionClassOrderNo(List<Guid?> educationMissionClassIDs, List<int?> orderNos)
  538. {
  539. try
  540. {
  541. int i = 0;
  542. foreach (var educationMissionClassID in educationMissionClassIDs)
  543. {
  544. EM_EducationMissionClass educationMissionClass = GetEducationMissionClass(educationMissionClassID);
  545. educationMissionClass.OrderNo = orderNos[i];
  546. i++;
  547. }
  548. UnitOfWork.Commit();
  549. }
  550. catch (Exception)
  551. {
  552. throw;
  553. }
  554. }
  555. /// <summary>
  556. /// 更新教学任务班信息
  557. /// </summary>
  558. /// <param name="educationMissionClassView"></param>
  559. public void UpdateEducationMissionClass(EducationMissionClassView educationMissionClassView)
  560. {
  561. throw new NotImplementedException();
  562. }
  563. /// <summary>
  564. /// 获取设置周数
  565. /// </summary>
  566. /// <param name="educationMissionClassID"></param>
  567. /// <returns></returns>
  568. public List<string> GetEducationMissionClassSettings(Guid? educationMissionClassID)
  569. {
  570. List<string> listeducation = new List<string>();
  571. var list = educationMissionClassDAL.GetEducationMissionClassSettingsQueryble(educationMissionClassID);
  572. if (list.Count > 0)
  573. return list;
  574. var educationMissionClass = GetEducationMissionClassView(educationMissionClassID);
  575. if (educationMissionClass != null)
  576. {
  577. for (int i = (int)educationMissionClass.StartWeeklyNum; i <= (int)educationMissionClass.EndWeeklyNum; i++)
  578. {
  579. listeducation.Add(i.ToString());
  580. }
  581. }
  582. return listeducation;
  583. }
  584. /// <summary>
  585. /// 获取教学任务授课老师
  586. /// </summary>
  587. /// <param name="educationMissionClassID"></param>
  588. /// <returns></returns>
  589. public List<EducationMissionClassTeacherListView> GetEducationMissionClassTeacherListViewList(Guid? educationMissionClassID)
  590. {
  591. return educationMissionClassDAL.GetEducationMissionClassTeacherListViewQueryble().Where(x => x.EducationMissionClassID == educationMissionClassID).OrderBy(x => x.TeachingMethod).ToList();
  592. }
  593. /// <summary>
  594. /// 教学安排
  595. /// </summary>
  596. /// <param name="educationMissionClassView">实体</param>
  597. /// <param name="weekNumList">选中周次</param>
  598. /// <param name="teacherList">教师</param>
  599. public void EducationMissionClassUpdate(EducationMissionClassView educationMissionClassView, List<int?> weekNumList, List<EducationMissionClassTeacherListView> teacherList)
  600. {
  601. try
  602. {
  603. if (educationMissionClassView.EducationMissionClassID != null && educationMissionClassView.EducationMissionClassID != Guid.Empty)
  604. {
  605. EM_EducationMissionClass educationMissionClass = GetEducationMissionClass(educationMissionClassView.EducationMissionClassID);
  606. if (educationMissionClass.RecordStatus == (int)EM_EducationMissionClassStatus.Scheduled)
  607. {
  608. throw new Exception("当前任务班已经排课,无法进行教学安排。");
  609. }
  610. if (educationMissionClass.RecordStatus == (int)EM_EducationMissionClassStatus.Submitted)
  611. {
  612. throw new Exception("当前任务班已经提交,无法进行教学安排。");
  613. }
  614. if (educationMissionClassView.ClassroomID != null)
  615. {
  616. CF_Classroom classroomEntity = educationMissionClassDAL.ClassroomRepository.GetSingle(x => x.ClassroomID == educationMissionClassView.ClassroomID);
  617. EM_EducationSchedulingClass educationSchedulingEntity = educationMissionClassDAL.EducationSchedulingClassRepository.GetSingle(x => x.EducationMissionClassID == educationMissionClass.EducationMissionClassID, x => x.CF_Student);
  618. int classNum = educationSchedulingEntity.CF_Student.Count();
  619. if (classroomEntity != null && classroomEntity.Totalseating != null
  620. && classroomEntity.Totalseating > 0
  621. && classNum > classroomEntity.Totalseating)//教学安排班级人数不能大于选定的教室总座位数
  622. {
  623. throw new Exception("该教室总座位数不能小于班级人数。");
  624. }
  625. }
  626. if (educationMissionClass != null)
  627. {
  628. educationMissionClass.ClassroomID = educationMissionClassView.ClassroomID;
  629. educationMissionClass.ClassroomTypeID = educationMissionClassView.ClassroomTypeID;
  630. educationMissionClass.Name = educationMissionClassView.Name;//已提交状态可编辑教学任务名称
  631. SetModifyStatus(educationMissionClass);
  632. //添加周次设置表
  633. if (weekNumList.Count > 0)
  634. {
  635. //删除设置
  636. UnitOfWork.Delete<EM_EducationMissionClassSettings>(x => x.EducationMissionClassID == educationMissionClass.EducationMissionClassID);
  637. UnitOfWork.Delete<EM_CourseProcess>(x => x.EducationMissionClassID == educationMissionClass.EducationMissionClassID);
  638. foreach (var weekNum in weekNumList)
  639. {
  640. EM_EducationMissionClassSettings educationMissionClassSettings = new EM_EducationMissionClassSettings();
  641. educationMissionClassSettings.EducationMissionClassSettingsID = Guid.NewGuid();
  642. educationMissionClassSettings.EducationMissionClassID = educationMissionClass.EducationMissionClassID;
  643. educationMissionClassSettings.WeeklyNum = weekNum;
  644. SetNewStatus(educationMissionClassSettings);
  645. UnitOfWork.Add(educationMissionClassSettings);
  646. EM_CourseProcess courseProcess = new EM_CourseProcess();
  647. courseProcess.CourseProcessID = Guid.NewGuid();
  648. courseProcess.EducationMissionClassID = educationMissionClass.EducationMissionClassID;
  649. courseProcess.Week = weekNum;
  650. //周学时改为用户手动修改,不在根据任、限选计划自动修改。
  651. courseProcess.Times = educationMissionClassView.WeeklyHours;
  652. courseProcess.ClassroomTypeID = educationMissionClass.ClassroomTypeID;
  653. courseProcess.ClassroomID = educationMissionClass.ClassroomID;
  654. teacherList.ForEach(x => {
  655. var courseProcessTeacher = new EM_CourseProcessTeacher
  656. {
  657. CourseProcessTeacherID = Guid.NewGuid(),
  658. CourseProcessID = courseProcess.CourseProcessID,
  659. UserID = x.UserID,
  660. TeachType = x.TeachingMethod
  661. };
  662. SetNewStatus(courseProcessTeacher);
  663. courseProcess.EM_CourseProcessTeacher.Add(courseProcessTeacher);
  664. });
  665. SetNewStatus(courseProcess);
  666. UnitOfWork.Add(courseProcess);
  667. }
  668. }
  669. if (teacherList.Count == 0)
  670. {
  671. //删除教师
  672. UnitOfWork.Delete<EM_MissionClassTeacher>(x => x.MissionClassID == educationMissionClass.EducationMissionClassID);
  673. }
  674. //添加教师
  675. if (teacherList.Count > 0)
  676. {
  677. //删除教师
  678. UnitOfWork.Delete<EM_MissionClassTeacher>(x => x.MissionClassID == educationMissionClass.EducationMissionClassID);
  679. foreach (var teacher in teacherList)
  680. {
  681. EM_MissionClassTeacher missionClassTeacher = new EM_MissionClassTeacher();
  682. missionClassTeacher.MissionClassTeacherID = Guid.NewGuid();
  683. missionClassTeacher.MissionClassID = educationMissionClass.EducationMissionClassID;
  684. missionClassTeacher.UserID = teacher.UserID;
  685. missionClassTeacher.TeachType = teacher.TeachingMethod;
  686. SetNewStatus(missionClassTeacher);
  687. UnitOfWork.Add(missionClassTeacher);
  688. }
  689. }
  690. //添加教学任务时间段
  691. if (educationMissionClassView.CourseTimeID != null)
  692. {
  693. var year = educationMissionClassDAL.GetEducationMissionClassViewQueryble(x => x.EducationMissionClassID == educationMissionClassView.EducationMissionClassID).FirstOrDefault();
  694. var isok = CourseTimeHoursDAL.GetCoursesTimeQueryable(x => x.RecordStatus > (int?)SYS_STATUS.UNUSABLE, w => w.RecordStatus > (int?)SYS_STATUS.UNUSABLE && w.Years == year.GradeYearID).ToList();
  695. if (isok.Count() > 0)
  696. {
  697. List<EM_CoursesTime> coursesTime = coursesTimeDAL.coursesTimeRepository.Entities.Where(x => x.CoursesTimeID == educationMissionClassView.CourseTimeID).ToList();
  698. educationMissionClass.EM_CoursesTime = new HashSet<EM_CoursesTime>();
  699. foreach (var time in coursesTime)
  700. {
  701. EM_CoursesTime c = time;
  702. educationMissionClass.EM_CoursesTime.Add(c);
  703. }
  704. }
  705. }
  706. UnitOfWork.Commit();
  707. }
  708. }
  709. }
  710. catch (Exception)
  711. {
  712. throw;
  713. }
  714. }
  715. public void EducationMissionConjunctionClassAdd(List<Guid?> educationMissionClassIDs)
  716. {
  717. throw new NotImplementedException();
  718. }
  719. /// <summary>
  720. /// 排课分班
  721. /// </summary>
  722. /// <param name="educationMissionClassIDs"></param>
  723. public void DivideIntoClassesAdd(DivideIntoClassesView divideIntoClassesView)
  724. {
  725. try
  726. {
  727. if (divideIntoClassesView.EducationMissionClassID != null && divideIntoClassesView.EducationMissionClassID != Guid.Empty)
  728. {
  729. EM_EducationMissionClass educationMissionClass = GetEducationMissionClass(divideIntoClassesView.EducationMissionClassID);
  730. if (educationMissionClass.RecordStatus == (int)EM_EducationMissionClassStatus.Scheduled)
  731. {
  732. throw new Exception("当前任务班已经排课,无法分班。");
  733. }
  734. if (educationMissionClass.RecordStatus == (int)EM_EducationMissionClassStatus.Submitted)
  735. {
  736. throw new Exception("当前任务班已经提交,无法分班。");
  737. }
  738. if (educationMissionClass != null)
  739. {
  740. //获取学生
  741. var listStudent = GetEducationMissionClassStudentViewList(educationMissionClass.EducationMissionClassID);
  742. int createMissionClassCount;
  743. #region 为了兼容以前的旧数据,分班时需要把原任务班的排课班数据重置成新格式
  744. UnitOfWork.RemoveRange(educationMissionClass.EM_EducationSchedulingClass);
  745. EM_EducationSchedulingClass newMainEducationSchedulingClass = new EM_EducationSchedulingClass();
  746. newMainEducationSchedulingClass.EducationSchedulingClassID = Guid.NewGuid();
  747. newMainEducationSchedulingClass.EducationMissionClassID = educationMissionClass.EducationMissionClassID;
  748. newMainEducationSchedulingClass.TaskGroupName = "1组";
  749. SetNewStatus(newMainEducationSchedulingClass);
  750. UnitOfWork.Add(newMainEducationSchedulingClass);
  751. #endregion
  752. var studentGroup = listStudent.GroupBy(x => x.ClassmajorID).ToList();
  753. if (divideIntoClassesView.OrderType ==true)
  754. {
  755. educationMissionClass.CF_Classmajor.RemoveWhere(x => x.ClassmajorID != studentGroup[0].Key);
  756. educationMissionClass.MainScheduleClassID = studentGroup[0].Key;
  757. newMainEducationSchedulingClass.CF_Student = new HashSet<CF_Student>(studentGroup[0].Select(x => x));
  758. createMissionClassCount = studentGroup.Count - 1;
  759. }
  760. else
  761. {
  762. createMissionClassCount = (divideIntoClassesView.GroupNum ?? 0) - 1;
  763. if (divideIntoClassesView.OrderType == false)
  764. {
  765. listStudent = listStudent.OrderBy(x => x.Sys_User.LoginID).ToList();
  766. }
  767. newMainEducationSchedulingClass.CF_Student = new HashSet<CF_Student>(listStudent.Take(divideIntoClassesView.StudentNum ?? 0).ToList());
  768. //跳过第一个班的学生
  769. listStudent = listStudent.Skip(divideIntoClassesView.StudentNum ?? 0).ToList();
  770. }
  771. for (int i = 0; i < createMissionClassCount; i++)
  772. {
  773. string groupNum = (i + 2).ToString();
  774. string groupName = "(" + groupNum + ")";
  775. EM_EducationMission newEducationMission = new EM_EducationMission();
  776. if (divideIntoClassesView.IsNotBuildEducationMission)
  777. {
  778. newEducationMission = educationMissionClass.EM_EducationMission;
  779. }
  780. else
  781. {
  782. newEducationMission.EducationMissionID = Guid.NewGuid();
  783. newEducationMission.CollegeID = educationMissionClass.EM_EducationMission.CollegeID;
  784. newEducationMission.DepartmentID = educationMissionClass.EM_EducationMission.DepartmentID;
  785. newEducationMission.SchoolyearID = educationMissionClass.EM_EducationMission.SchoolyearID;
  786. newEducationMission.ClassName = educationMissionClass.EM_EducationMission.ClassName + groupName;
  787. SetNewStatus(newEducationMission);
  788. UnitOfWork.Add(newEducationMission);
  789. }
  790. EM_EducationMissionClass newEducationMissionClass = new EM_EducationMissionClass();
  791. newEducationMissionClass.EducationMissionClassID = Guid.NewGuid();
  792. newEducationMissionClass.EducationMissionID = newEducationMission.EducationMissionID;
  793. if (divideIntoClassesView.OrderType == true)
  794. {
  795. newEducationMissionClass.MainScheduleClassID = studentGroup[i + 1].FirstOrDefault().CF_Classmajor.ClassmajorID;
  796. }
  797. else
  798. {
  799. newEducationMissionClass.MainScheduleClassID = educationMissionClass.MainScheduleClassID;
  800. }
  801. newEducationMissionClass.OrderNo = educationMissionClass.OrderNo;
  802. newEducationMissionClass.Name = educationMissionClass.Name + groupName;
  803. newEducationMissionClass.TeachingModeID = educationMissionClass.TeachingModeID;
  804. newEducationMissionClass.OptionalCourseTypeID = educationMissionClass.OptionalCourseTypeID;
  805. newEducationMissionClass.ClassroomTypeID = educationMissionClass.ClassroomTypeID;
  806. newEducationMissionClass.ClassroomID = educationMissionClass.ClassroomID;
  807. newEducationMissionClass.CoursematerialID = educationMissionClass.CoursematerialID;
  808. newEducationMissionClass.CourseStructureID = educationMissionClass.CourseStructureID;
  809. newEducationMissionClass.CourseCategoryID = educationMissionClass.CourseCategoryID;
  810. newEducationMissionClass.CourseTypeID = educationMissionClass.CourseTypeID;
  811. newEducationMissionClass.CourseQualityID = educationMissionClass.CourseQualityID;
  812. newEducationMissionClass.ExaminationModeID = educationMissionClass.ExaminationModeID;
  813. newEducationMissionClass.TeachinglanguageID = educationMissionClass.TeachinglanguageID;
  814. newEducationMissionClass.HandleModeID = educationMissionClass.HandleModeID;
  815. newEducationMissionClass.IsNeedMaterial = educationMissionClass.IsNeedMaterial;
  816. newEducationMissionClass.Remark = educationMissionClass.Remark;
  817. newEducationMissionClass.ResultTypeID = educationMissionClass.ResultTypeID;
  818. newEducationMissionClass.EM_CoursesTime = educationMissionClass.EM_CoursesTime;
  819. SetNewStatus(newEducationMissionClass);
  820. newEducationMissionClass.RecordStatus = educationMissionClass.RecordStatus;
  821. if (divideIntoClassesView.OrderType == true)
  822. {
  823. newEducationMissionClass.CF_Classmajor.Add(studentGroup[i + 1].FirstOrDefault().CF_Classmajor);
  824. }
  825. else
  826. {
  827. newEducationMissionClass.CF_Classmajor = educationMissionClass.CF_Classmajor;
  828. }
  829. UnitOfWork.Add(newEducationMissionClass);
  830. EM_EducationMissionClassTeachingSetting newEducationMissionClassTeachingSetting = new EM_EducationMissionClassTeachingSetting();
  831. newEducationMissionClassTeachingSetting.EducationMissionClassID = newEducationMissionClass.EducationMissionClassID;
  832. newEducationMissionClassTeachingSetting.Credit = educationMissionClass.EM_EducationMissionClassTeachingSetting.Credit;
  833. newEducationMissionClassTeachingSetting.TheoryCourse = educationMissionClass.EM_EducationMissionClassTeachingSetting.TheoryCourse;
  834. newEducationMissionClassTeachingSetting.Practicehours = educationMissionClass.EM_EducationMissionClassTeachingSetting.Practicehours;
  835. newEducationMissionClassTeachingSetting.Trialhours = educationMissionClass.EM_EducationMissionClassTeachingSetting.Trialhours;
  836. newEducationMissionClassTeachingSetting.WeeklyNum = educationMissionClass.EM_EducationMissionClassTeachingSetting.WeeklyNum;
  837. newEducationMissionClassTeachingSetting.TheoryWeeklyNum = educationMissionClass.EM_EducationMissionClassTeachingSetting.TheoryWeeklyNum;
  838. newEducationMissionClassTeachingSetting.PracticeWeeklyNum = educationMissionClass.EM_EducationMissionClassTeachingSetting.PracticeWeeklyNum;
  839. newEducationMissionClassTeachingSetting.TrialWeeklyNum = educationMissionClass.EM_EducationMissionClassTeachingSetting.TrialWeeklyNum;
  840. newEducationMissionClassTeachingSetting.StartWeeklyNum = educationMissionClass.EM_EducationMissionClassTeachingSetting.StartWeeklyNum;
  841. newEducationMissionClassTeachingSetting.EndWeeklyNum = educationMissionClass.EM_EducationMissionClassTeachingSetting.EndWeeklyNum;
  842. newEducationMissionClassTeachingSetting.WeeklyHours = educationMissionClass.EM_EducationMissionClassTeachingSetting.WeeklyHours;
  843. UnitOfWork.Add(newEducationMissionClassTeachingSetting);
  844. //生成任务班设置表
  845. foreach (var educationMissionClassSettings in educationMissionClass.EM_EducationMissionClassSettings.ToList())
  846. {
  847. EM_EducationMissionClassSettings newEducationMissionClassSettings = new EM_EducationMissionClassSettings();
  848. newEducationMissionClassSettings.EducationMissionClassSettingsID = Guid.NewGuid();
  849. newEducationMissionClassSettings.EducationMissionClassID = newEducationMissionClass.EducationMissionClassID;
  850. newEducationMissionClassSettings.WeeklyNum = educationMissionClassSettings.WeeklyNum;
  851. SetNewStatus(newEducationMissionClassSettings);
  852. UnitOfWork.Add(newEducationMissionClassSettings);
  853. }
  854. //生成任课老师
  855. foreach (var educationMissionClassTeacher in educationMissionClass.EM_MissionClassTeacher.ToList())
  856. {
  857. EM_MissionClassTeacher newMissionClassTeacher = new EM_MissionClassTeacher();
  858. newMissionClassTeacher.MissionClassTeacherID = Guid.NewGuid();
  859. newMissionClassTeacher.MissionClassID = newEducationMissionClass.EducationMissionClassID;
  860. newMissionClassTeacher.UserID = educationMissionClassTeacher.UserID;
  861. newMissionClassTeacher.TeachType = educationMissionClassTeacher.TeachType;
  862. SetNewStatus(newMissionClassTeacher);
  863. UnitOfWork.Add(newMissionClassTeacher);
  864. }
  865. //生成课程进度
  866. foreach (var courseProcess in educationMissionClass.EM_CourseProcess.ToList())
  867. {
  868. EM_CourseProcess newCourseProcess = new EM_CourseProcess();
  869. newCourseProcess.CourseProcessID = Guid.NewGuid();
  870. newCourseProcess.EducationMissionClassID = newEducationMissionClass.EducationMissionClassID;
  871. newCourseProcess.Week = courseProcess.Week;
  872. newCourseProcess.Times = courseProcess.Times;
  873. newCourseProcess.ClassroomTypeID = courseProcess.ClassroomTypeID;
  874. newCourseProcess.ClassroomID = courseProcess.ClassroomID;
  875. newCourseProcess.EM_CourseProcessTeacher = new HashSet<EM_CourseProcessTeacher>();
  876. courseProcess.EM_CourseProcessTeacher.ToList().ForEach(x => {
  877. var newCourseProcessTeacher = new EM_CourseProcessTeacher
  878. {
  879. CourseProcessTeacherID = Guid.NewGuid(),
  880. CourseProcessID = newCourseProcess.CourseProcessID,
  881. UserID = x.UserID,
  882. TeachType = x.TeachType
  883. };
  884. this.SetNewStatus(newCourseProcessTeacher);
  885. newCourseProcess.EM_CourseProcessTeacher.Add(newCourseProcessTeacher);
  886. });
  887. SetNewStatus(newCourseProcess);
  888. UnitOfWork.Add(newCourseProcess);
  889. }
  890. //生成排课班
  891. EM_EducationSchedulingClass newEducationSchedulingClass = new EM_EducationSchedulingClass();
  892. newEducationSchedulingClass.EducationSchedulingClassID = Guid.NewGuid();
  893. newEducationSchedulingClass.EducationMissionClassID = newEducationMissionClass.EducationMissionClassID;
  894. newEducationSchedulingClass.TaskGroupName = groupNum + "组";
  895. SetNewStatus(newEducationSchedulingClass);
  896. if (divideIntoClassesView.OrderType == true)
  897. {
  898. newEducationSchedulingClass.CF_Student = new HashSet<CF_Student>(studentGroup[i + 1]);
  899. }
  900. else
  901. {
  902. newEducationSchedulingClass.CF_Student = new HashSet<CF_Student>(listStudent.Take(divideIntoClassesView.StudentNum ?? 0).ToList());
  903. listStudent = listStudent.Skip(divideIntoClassesView.StudentNum ?? 0).ToList();
  904. }
  905. //当运行到最后一次循环,需要把剩余的学生都加入到这个排课班中
  906. if (i == createMissionClassCount - 1 && divideIntoClassesView.OrderType != true)
  907. {
  908. newEducationSchedulingClass.CF_Student = new HashSet<CF_Student>(newEducationSchedulingClass.CF_Student.Concat(listStudent));
  909. }
  910. var retakePlanStudentList = newEducationSchedulingClass.CF_Student.SelectMany(x => x.ER_RetakePlanStudent)
  911. .Where(x => x.EducationMissionID == educationMissionClass.EducationMissionID).ToList();
  912. retakePlanStudentList.ForEach(x => x.EducationMissionID = newEducationMission.EducationMissionID);
  913. UnitOfWork.Add(newEducationSchedulingClass);
  914. }
  915. educationMissionClass.EM_EducationMission.ClassName += "(1)";
  916. educationMissionClass.Name += "(1)";
  917. UnitOfWork.Commit();
  918. }
  919. }
  920. }
  921. catch (Exception ex)
  922. {
  923. throw;
  924. }
  925. }
  926. /// <summary>
  927. /// 分班信息
  928. /// </summary>
  929. /// <param name="educationMissionClassID"></param>
  930. /// <returns></returns>
  931. public DivideIntoClassesView GetDivideIntoClassesView(Guid? educationMissionClassID)
  932. {
  933. string ClassName = string.Empty;
  934. int StudentTotalNum = 0; //学生总数
  935. DivideIntoClassesView divideIntoClassesView = new DivideIntoClassesView();
  936. var listDivideIntoClassesView = educationMissionClassDAL.GetDivideIntoClassesViewQueryable().Where(x => x.EducationMissionClassID == educationMissionClassID).ToList();
  937. foreach (var item in listDivideIntoClassesView)
  938. {
  939. ClassName = item.ClassName;
  940. StudentTotalNum += (int)item.StudentTotalNum;
  941. }
  942. divideIntoClassesView.ClassName = ClassName;
  943. divideIntoClassesView.StudentTotalNum = StudentTotalNum;
  944. return divideIntoClassesView;
  945. }
  946. /// <summary>
  947. /// 排课班表
  948. /// </summary>
  949. /// <param name="educationMissionClassID"></param>
  950. /// <returns></returns>
  951. public EM_EducationSchedulingClass GetEducationSchedulingClass(Guid? educationSchedulingClassID)
  952. {
  953. System.Linq.Expressions.Expression<Func<EM_EducationSchedulingClass, bool>> expression = (x => x.EducationSchedulingClassID == educationSchedulingClassID);
  954. return educationMissionClassDAL.EducationSchedulingClassRepository.GetSingle(expression, (x => x.CF_Student));
  955. }
  956. /// <summary>
  957. /// 获取排课班学生信息
  958. /// </summary>
  959. /// <param name="educationMissionClassID">任务班ID</param>
  960. /// <param name="IsStudentLogin">按学号顺序进行分组</param>
  961. /// <returns></returns>
  962. private List<CF_Student> GetEducationMissionClassStudentViewList(Guid? educationMissionClassID)
  963. {
  964. List<CF_Student> listStudent = new List<CF_Student>();
  965. List<EM_EducationSchedulingClass> listEducationSchedulingClass = GetEducationSchedulingClassList(educationMissionClassID);
  966. return listEducationSchedulingClass.SelectMany(x => x.CF_Student).ToList();
  967. }
  968. /// <summary>
  969. /// 获取排课班信息
  970. /// </summary>
  971. /// <returns></returns>
  972. public IGridResultSet<EducationSchedulingClassView> GetEducationSchedulingClassViewGrid(Guid? educationMissionClassID, int pageIndex, int pageSize)
  973. {
  974. var query = educationMissionClassDAL.GetEducationSchedulingClassViewQueryable().Where(x => x.EducationMissionClassID == educationMissionClassID);
  975. return query.OrderBy(x => x.TaskGroupName).ToGridResultSet<EducationSchedulingClassView>(pageIndex, pageSize);
  976. }
  977. /// <summary>
  978. /// 获取排课班学生信息
  979. /// </summary>
  980. /// <param name="educationSchedulingClassID">排课班ID</param>
  981. /// <returns></returns>
  982. public IGridResultSet<EducationMissionClassStudentView> GetEducationMissionClassStudentViewGrid(Guid? educationSchedulingClassID, int pageIndex, int pageSize)
  983. {
  984. return educationMissionClassDAL.GetEducationMissionClassStudentViewQueryable(educationSchedulingClassID).OrderBy(x => x.LoginID).ToGridResultSet<EducationMissionClassStudentView>(pageIndex, pageSize);
  985. }
  986. /// <summary>
  987. /// 获取排课班列表
  988. /// </summary>
  989. /// <param name="educationMissionClassID"></param>
  990. /// <returns></returns>
  991. private List<EM_EducationSchedulingClass> GetEducationSchedulingClassList(Guid? educationMissionClassID)
  992. {
  993. return educationMissionClassDAL.EducationSchedulingClassRepository
  994. .GetList(x => x.EducationMissionClassID == educationMissionClassID,
  995. (x => x.CF_Student),
  996. (x => x.CF_Student.Select(w => w.Sys_User)),
  997. (x => x.CF_Student.Select(w => w.CF_Classmajor)),
  998. (x => x.CF_Student.Select(w => w.ER_RetakePlanStudent))
  999. ).ToList();
  1000. }
  1001. /// <summary>
  1002. /// 获取任务班对应的所以排课班学生信息
  1003. /// </summary>
  1004. /// <param name="educationMissionClassID"></param>
  1005. /// <param name="pageIndex"></param>
  1006. /// <param name="pageSize"></param>
  1007. /// <returns></returns>
  1008. public IGridResultSet<EducationMissionClassStudentView> GetEducationMissionClassSchedulingStudentViewGrid(Guid? educationMissionClassID, int pageIndex, int pageSize)
  1009. {
  1010. return educationMissionClassDAL.GetEducationMissionClassSchedulingStudentViewQueryble(educationMissionClassID).OrderBy(x => x.LoginID).ToGridResultSet<EducationMissionClassStudentView>(pageIndex, pageSize);
  1011. }
  1012. /// <summary>
  1013. /// 获取任务班对应的所以排课班学生信息
  1014. /// </summary>
  1015. /// <param name="educationMissionClassID"></param>
  1016. /// <param name="pageIndex"></param>
  1017. /// <param name="pageSize"></param>
  1018. /// <returns></returns>
  1019. public List<EducationMissionClassStudentView> GetEducationMissionClassSchedulingStudentViewList(Guid? educationMissionClassID)
  1020. {
  1021. return educationMissionClassDAL.GetEducationMissionClassSchedulingStudentViewQueryble(educationMissionClassID).OrderBy(x => x.LoginID).ToList();
  1022. }
  1023. /// <summary>
  1024. /// 合班
  1025. /// </summary>
  1026. /// <param name="educationMissionClassView"></param>
  1027. /// <param name="educationMissionClassIDs"></param>
  1028. public void EducationMissionClassConjunctionAdd(EducationMissionClassView educationMissionClassView, List<Guid?> educationMissionClassIDs)
  1029. {
  1030. try
  1031. {
  1032. var educationMissionClassList = educationMissionClassDAL.EducationMissionClassRepository
  1033. .GetList(x => educationMissionClassIDs.Contains(x.EducationMissionClassID),
  1034. (x => x.CF_Classmajor),
  1035. (x => x.EM_EducationMission),
  1036. (x => x.EM_EducationMission.ER_FinalExamination.Select(w => w.EM_EducationMission)),
  1037. (x => x.EM_EducationMission.ER_RetakePlanStudent.Select(w => w.EM_EducationMission)),
  1038. (x => x.EM_EducationMission.EX_ExaminationPlan.Select(w => w.EM_EducationMission)),
  1039. (x => x.EM_EducationMissionClassSettings),
  1040. (x => x.EM_EducationMissionClassTeachingSetting),
  1041. (x => x.EM_EducationSchedulingClass),
  1042. (x => x.EM_EducationSchedulingClass.Select(w => w.CF_Student)),
  1043. (x => x.EM_EducationSchedulingClass.Select(w => w.CF_Student.Select(v => v.ER_RetakePlanStudent))),
  1044. (x => x.EM_EvaluationSetting),
  1045. (x => x.EM_EvaluationEnter),
  1046. (x => x.EM_MissionClassTeacher),
  1047. (x => x.EM_CourseProcess),
  1048. (x => x.EM_CoursesTime),
  1049. (x => x.EM_CourseProcess.Select(y => y.EM_CourseProcessTeacher))).ToList();
  1050. EM_EducationMission mainEducationMission = null;
  1051. EM_EducationMissionClass mainEducationMissionClass = null;
  1052. int? type = null; //
  1053. if (educationMissionClassList.Count > 0)
  1054. {
  1055. type = educationMissionClassList[0].OptionalCourseTypeID;
  1056. }
  1057. foreach (var educationMissionClass in educationMissionClassList)
  1058. {
  1059. if (type != null)
  1060. {
  1061. if (type == educationMissionClass.OptionalCourseTypeID)
  1062. {
  1063. type = educationMissionClass.OptionalCourseTypeID;
  1064. }
  1065. else
  1066. {
  1067. throw new Exception("不是相同选修类型的任务,不能合班。如限选只能与限选合班");
  1068. }
  1069. }
  1070. if (educationMissionClass.EducationMissionClassID == educationMissionClassView.EducationMissionClassID)
  1071. {
  1072. mainEducationMission = educationMissionClass.EM_EducationMission;
  1073. mainEducationMissionClass = educationMissionClass;
  1074. }
  1075. }
  1076. if (mainEducationMission == null)
  1077. {
  1078. throw new Exception("主要排课任务班数据异常,没有匹配的教学任务。");
  1079. }
  1080. #region 根据主要班级生成新的任务班
  1081. string teachingModeName = IdNameExt.GetDictionaryItem(DictionaryItem.CF_TeachingMode.ToString())
  1082. .Where(x => x.Value == mainEducationMissionClass.TeachingModeID).Select(x => x.Name).FirstOrDefault();
  1083. EM_EducationMission newEducationMission = new EM_EducationMission();
  1084. newEducationMission.EducationMissionID = Guid.NewGuid();
  1085. newEducationMission.CollegeID = mainEducationMission.CollegeID;
  1086. newEducationMission.DepartmentID = mainEducationMission.DepartmentID;
  1087. newEducationMission.SchoolyearID = mainEducationMission.SchoolyearID;
  1088. string teachingModeString = "(" + teachingModeName + ")";
  1089. newEducationMission.ClassName = educationMissionClassView.Name.Replace("-" + teachingModeString, "");
  1090. newEducationMission.ClassName = newEducationMission.ClassName.Replace(teachingModeString, "");
  1091. SetNewStatus(newEducationMission);
  1092. UnitOfWork.Add(newEducationMission);
  1093. #region 将教学任务对应的期末设定指向新的合班后的教学任务,防止学分之类的信息丢失
  1094. var finalExaminationList = educationMissionClassList.SelectMany(x => x.EM_EducationMission.ER_FinalExamination).ToList();
  1095. finalExaminationList.ForEach(x => x.EducationMissionID = newEducationMission.EducationMissionID);
  1096. #endregion
  1097. #region 将教学任务对应的重修名单指向新的合班后的教学任务
  1098. var retakePlanStudentList = educationMissionClassList.SelectMany(x => x.EM_EducationMission.ER_RetakePlanStudent).ToList();
  1099. retakePlanStudentList.ForEach(x => x.EducationMissionID = newEducationMission.EducationMissionID);
  1100. #endregion
  1101. #region 将教学任务对应的考试计划指向新的合班后的教学任务
  1102. var examinationPlanList = educationMissionClassList.SelectMany(x => x.EM_EducationMission.EX_ExaminationPlan).ToList();
  1103. examinationPlanList.ForEach(x => x.EducationMissionID = newEducationMission.EducationMissionID);
  1104. #endregion
  1105. EM_EducationMissionClass newEducationMissionClass = new EM_EducationMissionClass();
  1106. newEducationMissionClass.EducationMissionClassID = Guid.NewGuid();
  1107. newEducationMissionClass.EducationMissionID = newEducationMission.EducationMissionID;
  1108. newEducationMissionClass.MainScheduleClassID = mainEducationMissionClass.MainScheduleClassID;
  1109. newEducationMissionClass.OrderNo = mainEducationMissionClass.OrderNo;
  1110. newEducationMissionClass.Name = educationMissionClassView.Name;
  1111. newEducationMissionClass.TeachingModeID = mainEducationMissionClass.TeachingModeID;
  1112. newEducationMissionClass.OptionalCourseTypeID = mainEducationMissionClass.OptionalCourseTypeID;
  1113. newEducationMissionClass.ClassroomTypeID = mainEducationMissionClass.ClassroomTypeID;
  1114. newEducationMissionClass.ClassroomID = mainEducationMissionClass.ClassroomID;
  1115. newEducationMissionClass.CoursematerialID = mainEducationMissionClass.CoursematerialID;
  1116. newEducationMissionClass.CourseStructureID = mainEducationMissionClass.CourseStructureID;
  1117. newEducationMissionClass.CourseCategoryID = mainEducationMissionClass.CourseCategoryID;
  1118. newEducationMissionClass.CourseTypeID = mainEducationMissionClass.CourseTypeID;
  1119. newEducationMissionClass.CourseQualityID = mainEducationMissionClass.CourseQualityID;
  1120. newEducationMissionClass.ExaminationModeID = mainEducationMissionClass.ExaminationModeID;
  1121. newEducationMissionClass.TeachinglanguageID = mainEducationMissionClass.TeachinglanguageID;
  1122. newEducationMissionClass.HandleModeID = mainEducationMissionClass.HandleModeID;
  1123. newEducationMissionClass.IsNeedMaterial = mainEducationMissionClass.IsNeedMaterial;
  1124. newEducationMissionClass.ResultTypeID = mainEducationMissionClass.ResultTypeID;
  1125. newEducationMissionClass.Remark = mainEducationMissionClass.Remark;
  1126. SetNewStatus(newEducationMissionClass);
  1127. newEducationMissionClass.RecordStatus = (int)EMIS.ViewModel.EM_EducationMissionClassStatus.NotSubmitted;
  1128. newEducationMissionClass.EM_CoursesTime = mainEducationMissionClass.EM_CoursesTime;
  1129. newEducationMissionClass.CF_Classmajor = new HashSet<CF_Classmajor>(educationMissionClassList
  1130. .SelectMany(x => x.CF_Classmajor)
  1131. .GroupBy(x => x.ClassmajorID, (x, y) => y.FirstOrDefault())
  1132. .ToList());
  1133. UnitOfWork.Add(newEducationMissionClass);
  1134. #region 将教学任务班对应的教学评价指向新的合班后的教学任务班
  1135. var evaluationSettingList = educationMissionClassList.SelectMany(x => x.EM_EvaluationSetting).ToList();
  1136. evaluationSettingList.ForEach(x => x.EducationMissionClassID = newEducationMissionClass.EducationMissionClassID);
  1137. var evaluationEnterList = educationMissionClassList.SelectMany(x => x.EM_EvaluationEnter).ToList();
  1138. evaluationEnterList.ForEach(x => x.EducationMissionClassID = newEducationMissionClass.EducationMissionClassID);
  1139. #endregion
  1140. EM_EducationMissionClassTeachingSetting newEducationMissionClassTeachingSetting = new EM_EducationMissionClassTeachingSetting();
  1141. newEducationMissionClassTeachingSetting.EducationMissionClassID = newEducationMissionClass.EducationMissionClassID;
  1142. newEducationMissionClassTeachingSetting.Credit = mainEducationMissionClass.EM_EducationMissionClassTeachingSetting.Credit;
  1143. newEducationMissionClassTeachingSetting.TheoryCourse = mainEducationMissionClass.EM_EducationMissionClassTeachingSetting.TheoryCourse;
  1144. newEducationMissionClassTeachingSetting.Practicehours = mainEducationMissionClass.EM_EducationMissionClassTeachingSetting.Practicehours;
  1145. newEducationMissionClassTeachingSetting.Trialhours = mainEducationMissionClass.EM_EducationMissionClassTeachingSetting.Trialhours;
  1146. newEducationMissionClassTeachingSetting.WeeklyNum = mainEducationMissionClass.EM_EducationMissionClassTeachingSetting.WeeklyNum;
  1147. newEducationMissionClassTeachingSetting.TheoryWeeklyNum = mainEducationMissionClass.EM_EducationMissionClassTeachingSetting.TheoryWeeklyNum;
  1148. newEducationMissionClassTeachingSetting.PracticeWeeklyNum = mainEducationMissionClass.EM_EducationMissionClassTeachingSetting.PracticeWeeklyNum;
  1149. newEducationMissionClassTeachingSetting.TrialWeeklyNum = mainEducationMissionClass.EM_EducationMissionClassTeachingSetting.TrialWeeklyNum;
  1150. newEducationMissionClassTeachingSetting.StartWeeklyNum = mainEducationMissionClass.EM_EducationMissionClassTeachingSetting.StartWeeklyNum;
  1151. newEducationMissionClassTeachingSetting.EndWeeklyNum = mainEducationMissionClass.EM_EducationMissionClassTeachingSetting.EndWeeklyNum;
  1152. newEducationMissionClassTeachingSetting.WeeklyHours = mainEducationMissionClass.EM_EducationMissionClassTeachingSetting.WeeklyHours;
  1153. UnitOfWork.Add(newEducationMissionClassTeachingSetting);
  1154. //生成任务班设置表
  1155. foreach (var mainEducationMissionClassSettings in mainEducationMissionClass.EM_EducationMissionClassSettings.ToList())
  1156. {
  1157. EM_EducationMissionClassSettings newEducationMissionClassSettings = new EM_EducationMissionClassSettings();
  1158. newEducationMissionClassSettings.EducationMissionClassSettingsID = Guid.NewGuid();
  1159. newEducationMissionClassSettings.EducationMissionClassID = newEducationMissionClass.EducationMissionClassID;
  1160. newEducationMissionClassSettings.WeeklyNum = mainEducationMissionClassSettings.WeeklyNum;
  1161. SetNewStatus(newEducationMissionClassSettings);
  1162. UnitOfWork.Add(newEducationMissionClassSettings);
  1163. }
  1164. //生成任课老师
  1165. foreach (var mainMissionClassTeacher in mainEducationMissionClass.EM_MissionClassTeacher.ToList())
  1166. {
  1167. EM_MissionClassTeacher newMissionClassTeacher = new EM_MissionClassTeacher();
  1168. newMissionClassTeacher.MissionClassTeacherID = Guid.NewGuid();
  1169. newMissionClassTeacher.MissionClassID = newEducationMissionClass.EducationMissionClassID;
  1170. newMissionClassTeacher.UserID = mainMissionClassTeacher.UserID;
  1171. newMissionClassTeacher.TeachType = mainMissionClassTeacher.TeachType;
  1172. SetNewStatus(newMissionClassTeacher);
  1173. UnitOfWork.Add(newMissionClassTeacher);
  1174. }
  1175. //生成课程进度
  1176. foreach (var mainCourseProcess in mainEducationMissionClass.EM_CourseProcess.ToList())
  1177. {
  1178. EM_CourseProcess newCourseProcess = new EM_CourseProcess();
  1179. newCourseProcess.CourseProcessID = Guid.NewGuid();
  1180. newCourseProcess.EducationMissionClassID = newEducationMissionClass.EducationMissionClassID;
  1181. newCourseProcess.Week = mainCourseProcess.Week;
  1182. newCourseProcess.Times = mainCourseProcess.Times;
  1183. newCourseProcess.ClassroomTypeID = mainCourseProcess.ClassroomTypeID;
  1184. newCourseProcess.ClassroomID = mainCourseProcess.ClassroomID;
  1185. mainCourseProcess.EM_CourseProcessTeacher.ToList().ForEach(x =>
  1186. {
  1187. var newCourseProcessTeacher = new EM_CourseProcessTeacher
  1188. {
  1189. CourseProcessTeacherID = Guid.NewGuid(),
  1190. CourseProcessID = newCourseProcess.CourseProcessID,
  1191. UserID = x.UserID,
  1192. TeachType = x.TeachType
  1193. };
  1194. this.SetNewStatus(newCourseProcessTeacher);
  1195. newCourseProcess.EM_CourseProcessTeacher.Add(newCourseProcessTeacher);
  1196. });
  1197. SetNewStatus(newCourseProcess);
  1198. UnitOfWork.Add(newCourseProcess);
  1199. }
  1200. //生成排课班
  1201. EM_EducationSchedulingClass newEducationSchedulingClass = new EM_EducationSchedulingClass();
  1202. newEducationSchedulingClass.EducationSchedulingClassID = Guid.NewGuid();
  1203. newEducationSchedulingClass.EducationMissionClassID = newEducationMissionClass.EducationMissionClassID;
  1204. newEducationSchedulingClass.TaskGroupName = "1组";
  1205. SetNewStatus(newEducationSchedulingClass);
  1206. //获取主排课班学生
  1207. List<CF_Student> studentList = educationMissionClassList
  1208. .SelectMany(x => x.EM_EducationSchedulingClass)
  1209. .SelectMany(x => x.CF_Student)
  1210. .GroupBy(x => x.UserID, (x, y) => y.FirstOrDefault())
  1211. .ToList();
  1212. newEducationSchedulingClass.CF_Student = new HashSet<CF_Student>(studentList);
  1213. UnitOfWork.Add(newEducationSchedulingClass);
  1214. var allEducationMissionIDList = educationMissionClassList.Select(x => x.EducationMissionID).Distinct().ToList();
  1215. //var retakePlanStudentList = newEducationSchedulingClass.CF_Student.SelectMany(x => x.ER_RetakePlanStudent)
  1216. // .Where(x => allEducationMissionIDList.Contains(x.EducationMissionID)).ToList();
  1217. //retakePlanStudentList.ForEach(x => x.EducationMissionID = newEducationMission.EducationMissionID);
  1218. #endregion
  1219. #region 将参与合班的教学任务其他的任务班拉到这个合并后的教学任务中
  1220. var allEducationMissionClassList = educationMissionClassDAL.EducationMissionClassRepository
  1221. .GetList(x => allEducationMissionIDList.Contains(x.EducationMissionID) && !educationMissionClassIDs.Contains(x.EducationMissionClassID))
  1222. .ToList();
  1223. foreach (var otherEducationMissionClass in allEducationMissionClassList)
  1224. {
  1225. otherEducationMissionClass.EducationMissionID = newEducationMission.EducationMissionID;
  1226. }
  1227. #endregion
  1228. //删除课程类型
  1229. foreach (var id in educationMissionClassIDs)
  1230. {
  1231. if (id != mainEducationMissionClass.EducationMissionClassID)
  1232. {
  1233. EM_EducationMissionClass EducationMissionClass = GetEducationMissionClass(id);
  1234. EducationMissionClass.EM_CoursesTime = new HashSet<EM_CoursesTime>();
  1235. }
  1236. }
  1237. mainEducationMissionClass.EM_CoursesTime = new HashSet<EM_CoursesTime>();
  1238. UnitOfWork.Remove<EM_EducationMissionClassTeachingSetting>(x => educationMissionClassIDs.Contains(x.EducationMissionClassID));
  1239. UnitOfWork.Remove<EM_EducationMissionClass>(x => educationMissionClassIDs.Contains(x.EducationMissionClassID));
  1240. UnitOfWork.Remove<EM_EducationMission>(x => allEducationMissionIDList.Contains(x.EducationMissionID)); //删除教学任务
  1241. UnitOfWork.Commit();
  1242. }
  1243. catch (Exception)
  1244. {
  1245. throw;
  1246. }
  1247. }
  1248. /// <summary>
  1249. /// 获取主表对象
  1250. /// </summary>
  1251. /// <param name="educationMissionID"></param>
  1252. /// <returns></returns>
  1253. public EM_EducationMission GetEducationMission(Guid? educationMissionID)
  1254. {
  1255. return educationMissionClassDAL.EducationMissionRepository.GetSingle(x => x.EducationMissionID == educationMissionID);
  1256. }
  1257. /// <summary>
  1258. /// 获取学籍班的所有任务班
  1259. /// </summary>
  1260. /// <param name="educationMissionID">学籍班ID</param>
  1261. /// <returns></returns>
  1262. public List<EM_EducationMissionClass> GetEducationMissionClassList(Guid? educationMissionID)
  1263. {
  1264. return educationMissionClassDAL.EducationMissionClassRepository.GetList(x => x.EducationMissionID == educationMissionID, (x => x.EM_EducationSchedulingClass)).ToList();
  1265. }
  1266. /// <summary>
  1267. /// 获取学籍班的所有任务班
  1268. /// </summary>
  1269. /// <returns></returns>
  1270. public List<EM_EducationMissionClass> GetEducationMissionClassList()
  1271. {
  1272. return educationMissionClassDAL.EducationMissionClassRepository.GetList(x => true, (x => x.EM_MissionClassTeacher), (x => x.EM_EducationMissionClassSettings)).ToList();
  1273. }
  1274. /// <summary>
  1275. /// 更新教学任务班表 处理状态
  1276. /// </summary>
  1277. /// <param name="educationMissionClassIDs"></param>
  1278. public void EducationMissionClassUpdate(List<Guid?> educationMissionClassIDs)
  1279. {
  1280. try
  1281. {
  1282. string massge = string.Empty;
  1283. var educationMissionClassList = educationMissionClassDAL
  1284. .GetEducationMissionClass(x => educationMissionClassIDs.Contains(x.EducationMissionClassID)).Distinct().ToList();
  1285. var educationMissionIDList = educationMissionClassList.Select(x => x.EducationMissionID).Distinct();
  1286. //var courseProcessList = educationMissionClassDAL.GetRelatedCourseProcess(x => educationMissionClassIDs.Contains(x.EducationMissionClassID))
  1287. // .ToList();
  1288. foreach (var educationMissionClass in educationMissionClassList)
  1289. {
  1290. if (educationMissionClass.RecordStatus != (int)EMIS.ViewModel.EM_EducationMissionClassStatus.NotSubmitted)
  1291. massge += educationMissionClass.Name + "任务班,已提交,不能重复提交。";
  1292. if (educationMissionClass.EM_MissionClassTeacher.Count == 0 && !Const.LOCAL_SETTING_MISSIONCLASS_CAN_SUBMIT_NOTEACHER)
  1293. massge += educationMissionClass.Name + "任务班,未设置授课老师。";
  1294. if (educationMissionClass.EM_EducationMissionClassSettings.Count == 0)
  1295. massge += educationMissionClass.Name + "任务班,未设置授课周次。";
  1296. if (educationMissionClass.ClassroomTypeID == null)
  1297. massge += educationMissionClass.Name + "任务班,未设置教室类型。";
  1298. var courseProcessList = educationMissionClassDAL.GetRelatedCourseProcess(x => x.EducationMissionClassID == educationMissionClass.EducationMissionClassID)
  1299. .ToList();
  1300. var hours = courseProcessList.Select(x => x.Times).Sum();
  1301. //总学时
  1302. int? totalHours = (educationMissionClass.EM_EducationMissionClassTeachingSetting.TheoryCourse ?? 0)
  1303. + (educationMissionClass.EM_EducationMissionClassTeachingSetting.Practicehours ?? 0);
  1304. //TODO:兵良说:排课学时要小于等于总学时 2016年10月17日18:48:49
  1305. if (hours > totalHours)
  1306. {
  1307. massge += educationMissionClass.Name + "任务班,课程进度设置错误,请检查并重新设置后提交。";
  1308. }
  1309. if (!string.IsNullOrEmpty(massge))
  1310. massge += ",";
  1311. }
  1312. //20161110 MM姐提的要求, 先提交数据检测是否问题,有问题把所有问题反馈回页面让客户进行修改,再重新提交
  1313. if (!string.IsNullOrEmpty(massge))
  1314. throw new Exception(massge.TrimEnd(','));
  1315. foreach (var educationMissionClass in educationMissionClassList)
  1316. {
  1317. educationMissionClass.RecordStatus = (int)EMIS.ViewModel.EM_EducationMissionClassStatus.Submitted;
  1318. }
  1319. UnitOfWork.Commit();
  1320. }
  1321. catch (Exception)
  1322. {
  1323. throw;
  1324. }
  1325. }
  1326. public void UnSubmit(List<Guid?> educationMissionClassIDs)
  1327. {
  1328. try
  1329. {
  1330. string massge = string.Empty;
  1331. var educationMissionClassList = educationMissionClassDAL
  1332. .GetEducationMissionClass(x => educationMissionClassIDs.Contains(x.EducationMissionClassID)).Distinct().ToList();
  1333. foreach (var educationMissionClass in educationMissionClassList)
  1334. {
  1335. if (educationMissionClass.RecordStatus == (int)EMIS.ViewModel.EM_EducationMissionClassStatus.NotSubmitted)
  1336. massge += educationMissionClass.Name + "任务班未提交,不能撤销。";
  1337. if (educationMissionClass.RecordStatus == (int)EMIS.ViewModel.EM_EducationMissionClassStatus.Scheduled)
  1338. massge += educationMissionClass.Name + "任务班已排课,不能撤销。";
  1339. }
  1340. if (!string.IsNullOrEmpty(massge))
  1341. throw new Exception(massge.TrimEnd(','));
  1342. foreach (var educationMissionClass in educationMissionClassList)
  1343. {
  1344. educationMissionClass.RecordStatus = (int)EMIS.ViewModel.EM_EducationMissionClassStatus.NotSubmitted;
  1345. }
  1346. UnitOfWork.Commit();
  1347. }
  1348. catch (Exception)
  1349. {
  1350. throw;
  1351. }
  1352. }
  1353. public void Delete(List<Guid?> educationMissionClassIDs)
  1354. {
  1355. try
  1356. {
  1357. var educationMissionClassList = this.educationMissionClassDAL.EducationMissionClassRepository
  1358. .GetList(x => educationMissionClassIDs.Contains(x.EducationMissionClassID),
  1359. (x => x.CF_Classmajor),
  1360. (x => x.EM_EducationMission),
  1361. (x => x.EM_EducationMission.EM_EducationMissionClass),
  1362. (x => x.EM_EducationSchedulingClass.Select(w => w.ES_EducationScheduling)),
  1363. (x => x.EM_EducationMissionClassSettings),
  1364. (x => x.EM_EducationMissionClassTeachingSetting),
  1365. (x => x.EM_MissionClassTeacher),
  1366. (x => x.EM_CoursesTime)).ToList();
  1367. //先找出教学任务主表ID,若是重修生成的教学任务,更新重修任务时用到
  1368. var educationMissionIDList = educationMissionClassList.Select(x => x.EducationMissionID).Distinct().ToList();
  1369. var errorList = new List<string>();
  1370. foreach (var educationMissionClass in educationMissionClassList)
  1371. {
  1372. //任选课生成时就已经排了课,所以即使已排课状态也可以删除
  1373. if (educationMissionClass.RecordStatus == (int)EM_EducationMissionClassStatus.Scheduled
  1374. && !(educationMissionClass.HandleModeID == (int)CF_HandleMode.SelectionCourse && educationMissionClass.OptionalCourseTypeID == (int)CF_CourseSelectType.FreeSelectionCourse))
  1375. {
  1376. errorList.Add("任务班" + educationMissionClass.Name + "包含已排课状态,不能删除");
  1377. }
  1378. }
  1379. if (errorList.Count > 0)
  1380. {
  1381. throw new Exception(string.Join("\n", errorList));
  1382. }
  1383. //由于要兼容合班,因此不能直接以任务班自身的ID去搜索执行计划,必须用学年学期、年级专业、课程这三个条件去找匹配的执行计划来更新状态
  1384. var executablePlanList = educationMissionClassDAL.GetRelatedExecutablePlan(x => educationMissionClassIDs.Contains(x.EducationMissionClassID)).ToList();
  1385. //先预先找出需要删除的教学任务,逻辑是找出自身教学任务中,没有和自己不同的其他任务班的教学任务
  1386. var needDeleteEducationMissionList = (from emc in educationMissionClassList
  1387. where !emc.EM_EducationMission.EM_EducationMissionClass
  1388. .Any(x => !educationMissionClassIDs.Contains(x.EducationMissionClassID))
  1389. group emc.EM_EducationMission by emc.EM_EducationMission.EducationMissionID into g
  1390. select g.FirstOrDefault()).ToList();
  1391. List<Guid> educationMissionClassIDList = new List<Guid>();
  1392. var ExecutableMinorPlanList = ExecutableMinorPlanDAL.ExecutableMinorPlanRepository.GetList(x => true,(x=>x.EM_EducationMissionClass)).ToList();
  1393. var ExecutableMinorPlanEducationMissionList = ExecutableMinorPlanDAL.GetEducationMissionClassQuerybles().ToList();
  1394. foreach (var educationMissionClass in educationMissionClassList)
  1395. {
  1396. var ExecutableMinorPlanIDList = ExecutableMinorPlanEducationMissionList.Where(x => x.EducationMissionClassID == educationMissionClass.EducationMissionClassID).Select(x => x.ExecutableMinorPlanID).ToList();
  1397. if (ExecutableMinorPlanIDList.Count>0)
  1398. {
  1399. var ExecutableMinorPlan = ExecutableMinorPlanList.Where(x => ExecutableMinorPlanIDList.Contains(x.ExecutableMinorPlanID));
  1400. foreach (var ExecutableMinor in ExecutableMinorPlan)
  1401. {
  1402. ExecutableMinor.EM_EducationMissionClass=new HashSet<EM_EducationMissionClass>();
  1403. ExecutableMinor.RecordStatus = (int)EM_ExecuteStatus.NotSubmited;
  1404. }
  1405. }
  1406. educationMissionClassIDList.Add(educationMissionClass.EducationMissionClassID);
  1407. educationMissionClass.EM_CoursesTime = new HashSet<EM_CoursesTime>();
  1408. var educationSchedulingIDList = educationMissionClass.EM_EducationSchedulingClass
  1409. .SelectMany(x => x.ES_EducationScheduling).Select(x => x.EducationSchedulingID).ToList();
  1410. //由于前面已经有拦截必修和限选的排课状态数据,所以这里应该只会包含任选课的排课表,可以放心地删掉
  1411. UnitOfWork.Remove<ES_EducationSchedulingWeekNum>(x => educationSchedulingIDList.Contains(x.EducationSchedulingID.Value));
  1412. UnitOfWork.Remove<ES_EducationSchedulingTeacher>(x => educationSchedulingIDList.Contains(x.EducationSchedulingID.Value));
  1413. UnitOfWork.Remove<ES_EducationScheduling>(x => educationSchedulingIDList.Contains(x.EducationSchedulingID));
  1414. UnitOfWork.RemoveRange(educationMissionClass.EM_CourseProcess);
  1415. UnitOfWork.RemoveRange(educationMissionClass.EM_EducationSchedulingClass);
  1416. if (educationMissionClass.HandleModeID == (int)CF_HandleMode.SelectionCourse && educationMissionClass.OptionalCourseTypeID == (int)CF_CourseSelectType.OptionalCourse)
  1417. UnitOfWork.RemoveRange(educationMissionClass.EM_EducationSchedulingClass);
  1418. UnitOfWork.RemoveRange(educationMissionClass.EM_EducationMissionClassSettings);
  1419. UnitOfWork.RemoveRange(educationMissionClass.EM_MissionClassTeacher);
  1420. UnitOfWork.Remove(educationMissionClass.EM_EducationMissionClassTeachingSetting);
  1421. UnitOfWork.Remove(educationMissionClass);
  1422. }
  1423. //UnitOfWork.Commit();
  1424. foreach (var executablePlan in executablePlanList)
  1425. {
  1426. executablePlan.RecordStatus = (int)EM_ExecuteStatus.NotSubmited;
  1427. }
  1428. //由于任务班会分班合班,无法直接关联,所以现在改为直接找报名学生都不在任务班中的限选设定进行重置
  1429. var value = schoolYearDAL.schoolyearRepository.Entities.Where(x => x.IsCurrent == true).FirstOrDefault().Value;
  1430. var executableOptionalCourseList = OptionalCourseSettingDAL.GetNoMissionClassExecutableOptionalCourse(value, educationMissionClassIDList).ToList();
  1431. foreach (var executableOptionalCourse in executableOptionalCourseList)
  1432. {
  1433. //要删除的教学任务对应的限选设定,变成取消开班状态
  1434. executableOptionalCourse.RecordStatus = (int)EM_SelectCourseResultStatus.CancleCreate;
  1435. }
  1436. //任选设定同上,分别是任选设定还要强制删除课程进度及排课
  1437. var executableFreeSelectionCourseList = ExecutableFreeSelectionCouseDAL.GetNoMissionClassExecutableFreeSelectionCourse(value, educationMissionClassIDList).ToList();
  1438. foreach (var executableFreeSelectionCourse in executableFreeSelectionCourseList)
  1439. {
  1440. executableFreeSelectionCourse.RecordStatus = (int)EM_SelectCourseResultStatus.CancleCreate;
  1441. }
  1442. //考虑到重修开班时根据授课方式生成多个教学任务班时,只有当教学任务班都删除完时才修改重修计划
  1443. var educationMissionIDList1 = educationMissionClassDAL.EducationMissionClassRepository.GetList(x => educationMissionIDList.Contains(x.EducationMissionID)).Select(x => x.EducationMissionID).ToList();
  1444. var educationIDList = educationMissionIDList1.Except(educationMissionIDList);
  1445. //更新重修计划状态和删除重修名单的教学任务主表ID,用教学任务主表ID查询重修名单表,
  1446. var retakePlan = RetakePlanDAL.RetakePlanRepository.GetList(x => x.ER_RetakePlanStudent.Any(w => educationMissionIDList1.Contains(w.EducationMissionID.Value) && !educationIDList.Contains(w.EducationMissionID.Value)), x => x.ER_RetakePlanStudent).ToList();
  1447. if (retakePlan.Count > 0)
  1448. {
  1449. //重修计划状态改为已开放
  1450. retakePlan.ForEach(x =>
  1451. {
  1452. x.RecordStatus = (int)EMIS.ViewModel.ER_RetakePlanStatus.Opened;
  1453. x.ER_RetakePlanStudent.ToList().ForEach(w => w.EducationMissionID = null);
  1454. });
  1455. }
  1456. foreach (var needDeleteEducationMission in needDeleteEducationMissionList)
  1457. {
  1458. UnitOfWork.Remove(needDeleteEducationMission);
  1459. }
  1460. UnitOfWork.Commit();
  1461. }
  1462. catch (Exception)
  1463. {
  1464. throw;
  1465. }
  1466. }
  1467. public List<CourseProcessView> GetCourseProcessView(Guid educationMissionClassID)
  1468. {
  1469. //2016年12月1日15:28:47
  1470. //TODO :调整教学任务课程进度统计规则[将原按教学任务获取该教学任务下所对应的教学任务班课程进度信息调整为按对应教学任务班进行统计]
  1471. //var courseViewList = this.educationMissionClassDAL.GetCourseProcessView(x => x.EducationMissionID == educationMissionID)
  1472. // .OrderBy(x => x.Week).ToList();
  1473. var courseViewList = this.educationMissionClassDAL.GetCourseProcessView(x => x.EducationMissionClassID == educationMissionClassID)
  1474. .OrderBy(x => x.Week).ToList();
  1475. var courseViewTeacherList = this.educationMissionClassDAL.GetCourseProcessTeacherView(x => x.EducationMissionClassID == educationMissionClassID).ToList();
  1476. courseViewList.ForEach(x =>
  1477. {
  1478. x.CourseProcessTeacherViewList = courseViewTeacherList.Where(w => w.CourseProcessID == x.CourseProcessID).ToList();
  1479. //x.StaffIDAndTeachTypes = string.Join(",", x.CourseProcessTeacherViewList.Select(w => w.UserID.ToString() + "|" + w.TeacherType.ToString()));
  1480. //x.StaffNames = string.Join(",", x.CourseProcessTeacherViewList.Select(w => w.Name));
  1481. });
  1482. return courseViewList;
  1483. }
  1484. public List<CourseProcessTeacherView> GetCourseProcessTeacherView(Guid courseProcessID)
  1485. {
  1486. var courseProcessTeacherQueryable = this.educationMissionClassDAL.GetCourseProcessTeacherViewByCourseProcess(x => x.CourseProcessID == courseProcessID);
  1487. return courseProcessTeacherQueryable.ToList();
  1488. }
  1489. public void SaveCourseProcessView(EducationMissionClassView educationMissionClassView, IList<CourseProcessView> courseProcessViewList)
  1490. {
  1491. var educationMissionClass = educationMissionClassDAL.EducationMissionClassRepository
  1492. .GetSingle(x => x.EducationMissionClassID == educationMissionClassView.EducationMissionClassID,
  1493. (x => x.EM_MissionClassTeacher));
  1494. if (courseProcessViewList.Count > 0)
  1495. {
  1496. if (courseProcessViewList.Select(x => x.Times).Sum() > educationMissionClassView.Totalhours)
  1497. {
  1498. throw new Exception("课程进度学时不能超出总学时,请检查调整!");
  1499. }
  1500. }
  1501. if (educationMissionClass.RecordStatus == (int)EM_EducationMissionClassStatus.Scheduled)
  1502. {
  1503. //TODO:已提交的数据不能做编辑操作~
  1504. throw new Exception("已排课的任务班不能修改。");
  1505. }
  1506. var groupedCoursesProcessViewList = courseProcessViewList
  1507. .GroupBy(x => new
  1508. {
  1509. x.EducationMissionClassID,
  1510. x.Week,
  1511. x.ClassroomID,
  1512. x.ClassroomTypeID,
  1513. TeacherKey = string.Join(",", x.CourseProcessTeacherViewList.OrderBy(w => w.UserID).ThenBy(w => w.TeachingMethod)
  1514. .Select(w => w.UserID.ToString() + "|" + w.TeachingMethod.ToString()))
  1515. }).Select(x => new {
  1516. x.Key.EducationMissionClassID,
  1517. x.Key.Week,
  1518. x.Key.ClassroomID,
  1519. x.Key.ClassroomTypeID,
  1520. x.FirstOrDefault().CourseProcessTeacherViewList,
  1521. Times = x.Sum(w => w.Times)
  1522. }).ToList();
  1523. this.UnitOfWork.Delete<EM_CourseProcess>(x => x.EducationMissionClassID == educationMissionClassView.EducationMissionClassID);
  1524. foreach (var courseProcessView in groupedCoursesProcessViewList)
  1525. {
  1526. EM_CourseProcess courseProcess = new EM_CourseProcess();
  1527. courseProcess.CourseProcessID = Guid.NewGuid();
  1528. courseProcess.EducationMissionClassID = courseProcessView.EducationMissionClassID;
  1529. courseProcess.Week = courseProcessView.Week;
  1530. courseProcess.Times = courseProcessView.Times;
  1531. courseProcess.ClassroomTypeID = courseProcessView.ClassroomTypeID;
  1532. courseProcess.ClassroomID = courseProcessView.ClassroomID;
  1533. courseProcess.EM_CourseProcessTeacher = new HashSet<EM_CourseProcessTeacher>();
  1534. SetNewStatus(courseProcess);
  1535. UnitOfWork.Add(courseProcess);
  1536. courseProcessView.CourseProcessTeacherViewList.ToList().ForEach(x =>
  1537. {
  1538. UnitOfWork.Add(new EM_CourseProcessTeacher
  1539. {
  1540. CourseProcessTeacherID = Guid.NewGuid(),
  1541. CourseProcessID = courseProcess.CourseProcessID,
  1542. UserID = x.UserID,
  1543. TeachType = x.TeachingMethod,
  1544. RecordStatus = (int)SYS_STATUS.USABLE,
  1545. CreateTime = courseProcess.CreateTime,
  1546. CreateUserID = courseProcess.CreateUserID,
  1547. ModifyTime = courseProcess.ModifyTime,
  1548. ModifyUserID = courseProcess.ModifyUserID
  1549. });
  1550. });
  1551. }
  1552. var missionClassTeacherList = (from courseProcess in courseProcessViewList
  1553. from teacher in courseProcess.CourseProcessTeacherViewList
  1554. group teacher by new { teacher.UserID, teacher.TeachingMethod } into g
  1555. select g.FirstOrDefault()).ToList();
  1556. educationMissionClass.EM_MissionClassTeacher.ToList().ForEach(x => UnitOfWork.Remove(x));
  1557. missionClassTeacherList.ForEach(x =>
  1558. {
  1559. var missionClassTeacher = new EM_MissionClassTeacher
  1560. {
  1561. MissionClassTeacherID = Guid.NewGuid(),
  1562. MissionClassID = educationMissionClass.EducationMissionClassID,
  1563. UserID = x.UserID,
  1564. TeachType = x.TeachingMethod
  1565. };
  1566. this.SetNewStatus(missionClassTeacher);
  1567. this.UnitOfWork.Add(missionClassTeacher);
  1568. });
  1569. this.UnitOfWork.Commit();
  1570. }
  1571. public int GetStudentCount(Guid educationMissionClassID)
  1572. {
  1573. var educationSchedulingClass = educationMissionClassDAL
  1574. .EducationSchedulingClassRepository
  1575. .GetSingle(x => x.EducationMissionClassID == educationMissionClassID, (x => x.CF_Student));
  1576. return educationSchedulingClass.CF_Student.Count;
  1577. }
  1578. public IGridResultSet<ClassroomView> GetAvailableClassroom(ConfiguretView configuretView, Guid collegeID, Guid? buildingID,
  1579. int? classroomType, int? minSeatCount, int? pageIndex, int? pageSize)
  1580. {
  1581. Expression<Func<CF_Classroom, bool>> exp = (x => true);
  1582. if (buildingID.HasValue)
  1583. {
  1584. exp = exp.And(x => x.BuildingsInfoID == buildingID);
  1585. }
  1586. var classroomView = ClassroomScheduleDAL.GetAvailableClassroom(collegeID, minSeatCount, exp, classroomType);
  1587. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  1588. classroomView = classroomView.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  1589. return classroomView.OrderBy(x => x.BuildingsInfoName)
  1590. .ThenBy(x => x.Name)
  1591. .ThenBy(x => x.Totalseating).ToGridResultSet(pageIndex, pageSize);
  1592. }
  1593. public List<string> GetEducationMissionClassStatus()
  1594. {
  1595. var list = DictionaryHelper.GetDictionaryValue("EM_EducationMissionClassStatus").Select(x => x.Value.ToString()).ToList();
  1596. return list;
  1597. }
  1598. [Obsolete]
  1599. public bool Verification(List<Guid?> collegeIDList, List<Guid?> schoolyearIDList)
  1600. {
  1601. Expression<Func<EM_EducationMissionOpenControl, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  1602. var isOK = true;
  1603. var query = EducationMissionOpenControlDAL.GetEducationMissionOpenControlViewQueryable(exp).ToList();
  1604. int VerificationNum = collegeIDList.Count();
  1605. for (int i = 0; i < VerificationNum; i++)
  1606. {
  1607. var OpenControl = query.Where(x => x.CollegeID == collegeIDList[i] && x.SchoolyearID == schoolyearIDList[i]).FirstOrDefault();
  1608. if (OpenControl!=null)
  1609. {
  1610. if (OpenControl.StartDate > System.DateTime.Now || System.DateTime.Now > OpenControl.EndDate.Value.AddDays(1))
  1611. {
  1612. isOK = false;
  1613. return isOK;
  1614. }
  1615. }
  1616. }
  1617. return isOK;
  1618. }
  1619. public bool CheckEducationMissionClassOpenControl(IList<Guid> educationMissionClassIDList)
  1620. {
  1621. var nowTime = DateTime.Today;
  1622. var collegeSchoolyearKeyList = this.educationMissionClassDAL.EducationMissionClassRepository.GetList(x => educationMissionClassIDList.Contains(x.EducationMissionClassID))
  1623. .GroupBy(x => new { x.EM_EducationMission.SchoolyearID, x.EM_EducationMission.CF_Department.CollegeID })
  1624. .Select(x => new { x.Key.SchoolyearID, x.Key.CollegeID }).ToList();
  1625. var openControlList = EducationMissionOpenControlDAL.EducationMissionOpenControlRepository
  1626. .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && (x.StartDate > nowTime || x.EndDate < nowTime))
  1627. .SelectByKeys(collegeSchoolyearKeyList);
  1628. if (openControlList.Count > 0)
  1629. {
  1630. throw new Exception("受教学安排的时间控制,所选教学任务不在可操作时间范围,暂时无法操作。");
  1631. }
  1632. return true;
  1633. }
  1634. [Obsolete]
  1635. public IGridResultSet<EducationMissionClassView> GetLastCourseEducationMissionClassViewGrid(ConfiguretView configuretView, Guid userID,
  1636. int? pageIndex, int? pageSize)
  1637. {
  1638. Expression<Func<CF_Student, bool>> studentExp = (x => x.UserID == userID);
  1639. var query = this.educationMissionClassDAL.GetLastCourseEducationMissionClassViewQueryable(studentExp);
  1640. query = query.OrderBy(x => x.CourseCode).ThenBy(x => x.CourseName);
  1641. return query.ToGridResultSet(pageIndex, pageSize);
  1642. }
  1643. }
  1644. }