ExecutableMinorPlanServices.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq.Entity;
  6. using EMIS.ViewModel.EducationManage;
  7. using EMIS.ViewModel;
  8. using System.Linq.Expressions;
  9. using EMIS.Entities;
  10. using Bowin.Common.Linq;
  11. using EMIS.DataLogic.EducationManage;
  12. using Bowin.Common.Exceptions;
  13. using EMIS.Utility;
  14. namespace EMIS.CommonLogic.EducationManage
  15. {
  16. public class ExecutableMinorPlanServices : BaseServices, IExecutableMinorPlanServices
  17. {
  18. public ExecutableMinorPlanDAL ExecutableMinorPlanDAL { get; set; }
  19. public IGridResultSet<ExecutableMinorPlanView> GetExecutableMinorPlanViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID, int? yearID,
  20. int? standardID, Guid? coursematerialID, int? schoolyearNum, int? schoolcode, int? executableMinorPlanStatus, int pageIndex, int pageSize)
  21. {
  22. Expression<Func<EM_ExecutableMinorPlan, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  23. if (schoolyearID.HasValue)
  24. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  25. if (collegeID.HasValue)
  26. exp = exp.And(x => x.CollegeID == collegeID);
  27. if (yearID.HasValue)
  28. exp = exp.And(x => x.EM_MinorPlan.CF_Grademinor.YearID == yearID);
  29. if (standardID.HasValue)
  30. exp = exp.And(x => x.StandardID == standardID);
  31. if (coursematerialID.HasValue)
  32. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  33. if (executableMinorPlanStatus.HasValue)
  34. exp = exp.And(x => x.RecordStatus == executableMinorPlanStatus);
  35. var query = ExecutableMinorPlanDAL.GetExecutableMinorPlanView(exp);
  36. if (schoolyearNum.HasValue)
  37. query = query.Where(x => x.SchoolyearNumID == schoolyearNum);
  38. if (schoolcode.HasValue)
  39. query = query.Where(x => x.SchoolcodeID == schoolcode);
  40. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  41. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  42. var resultSet = this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolcodeStr)
  43. .ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenByDescending(x => x.StandardID)
  44. .ToGridResultSet<ExecutableMinorPlanView>(pageIndex, pageSize);
  45. var executablePlanIDList = resultSet.rows.Select(x => x.ExecutableMinorPlanID).ToList();
  46. return resultSet;
  47. }
  48. public ExecutableMinorPlanView GetExecutableMinorPlanView(Guid? ExecutableMinorPlanID)
  49. {
  50. Expression<Func<EM_ExecutableMinorPlan, bool>> exp = (x => x.ExecutableMinorPlanID == ExecutableMinorPlanID);
  51. var query = ExecutableMinorPlanDAL.GetExecutableMinorPlanView(exp);
  52. return query.FirstOrDefault();
  53. }
  54. /// <summary>
  55. /// 获取辅修执行计划信息
  56. /// </summary>
  57. /// <param name="MinorPlanID">辅修执行计划ID</param>
  58. /// <returns></returns>
  59. public EM_ExecutableMinorPlan GetExecutableMinorPlan(Guid? ExecutableMinorPlanID)
  60. {
  61. //查询条件
  62. Expression<Func<EM_ExecutableMinorPlan, bool>> exp = (x => x.ExecutableMinorPlanID == ExecutableMinorPlanID);
  63. return ExecutableMinorPlanDAL.ExecutableMinorPlanRepository.GetSingle(exp, (x => x.CF_Department), (x => x.EM_Coursematerial), (x => x.EM_ExecutableMinorPlanTeachingSetting));
  64. }
  65. /// <summary>
  66. /// 根据专业课程获取授课方式
  67. /// </summary>
  68. /// <param name="specialtyCourseID"></param>
  69. /// <returns></returns>
  70. public List<string> GetTeachingModeType(Guid? ExecutableMinorPlanID)
  71. {
  72. return ExecutableMinorPlanDAL.GetTeachingModeTypeQueryble(ExecutableMinorPlanID);
  73. }
  74. /// <summary>
  75. /// 根据专业课程获取授课地点
  76. /// </summary>
  77. /// <param name="specialtyCourseID"></param>
  78. /// <returns></returns>
  79. public List<string> GetTeachingPlace(Guid? ExecutableMinorPlanID)
  80. {
  81. return ExecutableMinorPlanDAL.GetTeachingPlaceQueryble(ExecutableMinorPlanID);
  82. }
  83. /// <summary>
  84. /// 辅修执行计划设置表
  85. /// </summary>
  86. /// <param name="MinorPlanID">辅修执行计划ID</param>
  87. /// <returns></returns>
  88. public EM_ExecutableMinorPlanTeachingSetting GetExecutableMinorPlanTeachingSetting(Guid? ExecutableMinorPlanID)
  89. {
  90. //查询条件
  91. Expression<Func<EM_ExecutableMinorPlanTeachingSetting, bool>> exp = (x => x.ExecutableMinorPlanID == ExecutableMinorPlanID);
  92. return ExecutableMinorPlanDAL.ExecutableMinorPlanTeachingSettingRepository.GetSingle(exp);
  93. }
  94. public void isOKForexecutablePlan(ExecutableMinorPlanView executableMinorPlanView)
  95. {
  96. if (this.ExecutableMinorPlanDAL.ExecutableMinorPlanRepository
  97. .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  98. && x.MinorPlanID == executableMinorPlanView.MinorPlanID
  99. && x.SchoolyearID == executableMinorPlanView.SchoolyearID
  100. && x.CoursematerialID == executableMinorPlanView.CoursematerialID).Count() > 0)
  101. {
  102. throw new Exception("指定的年级专业及课程在这学期已经开课或列表存在重复数据,请重新输入。");
  103. }
  104. }
  105. public void GenerateExecutablePlan(int? StandardID, Guid? SchoolyearID, bool IsOverwrite, Guid? CampusID, Guid? CollegeID, int? YearID)
  106. {
  107. try
  108. {
  109. Expression<Func<EM_MinorPlan, bool>> exp = (x => x.CF_Grademinor.RecordStatus == (int)CF_GrademinorStatus.Confirmed);
  110. if (StandardID.HasValue)
  111. {
  112. exp = exp.And(x => x.CF_Grademinor.StandardID == StandardID);
  113. }
  114. if (CollegeID.HasValue)
  115. {
  116. exp = exp.And(x => x.CF_Grademinor.CollegeID == CollegeID);
  117. }
  118. if (YearID.HasValue)
  119. {
  120. exp = exp.And(x => x.CF_Grademinor.YearID == YearID);
  121. }
  122. if (SchoolyearID.HasValue)
  123. {
  124. exp = exp.And(x => x.SchoolyearID == SchoolyearID);
  125. }
  126. //if (!isOverwrite)
  127. //{
  128. // exp = exp.And(x => x.TeachingStatus == null);
  129. //}
  130. if (!IsOverwrite)
  131. {
  132. //TODO:调整执行计划生成查询逻辑 2016年10月26日15:56:18
  133. exp = exp.And(x => x.EM_ExecutableMinorPlan.FirstOrDefault().ExecutableMinorPlanID == null);
  134. }
  135. var executablePlanIDs = this.GetQueryByDataRangeByCollege(ExecutableMinorPlanDAL.MinorPlanRepository.GetList(exp, (x => x.CF_Department.CF_College)).Select(x => new { x.MinorPlanID, x.CF_Department.CollegeID })).ToList().Select(x => (Guid?)x.MinorPlanID).ToList();
  136. var listSpecialtyPlan = ExecutableMinorPlanDAL.MinorPlanRepository
  137. .GetList(exp,
  138. (x => x.EM_MinorPlanTeachingModeType),
  139. (x => x.EM_MinorPlanTeachingPlace),
  140. (x => x.EM_MinorPlanTeachingSetting),
  141. (x => x.EM_ExecutableMinorPlan),
  142. (x => x.CF_Grademinor)
  143. ).Where(x => executablePlanIDs.Contains(x.MinorPlanID)).ToList();
  144. var relateMissionClass = ExecutableMinorPlanDAL.GetEducationMissionClassByExecutablePlanID(executablePlanIDs);
  145. if (listSpecialtyPlan.Count() == 0)
  146. throw new Exception("未能匹配到需要生成执行计划的数据,请查检辅修计划和辅修执行计划信息! (注:辅修计划信息未生成相关的辅修执行计划时,系统会以红字标识)");
  147. if (!IsOverwrite) //当选择覆盖时,不判断重复。现在判断重复方法感觉没什么作用,因为当不选择覆盖时查询出来的数据是未生成执行计划,理论上不会有重复
  148. {
  149. ExecutableMinorPlanView ex = new ExecutableMinorPlanView();
  150. foreach (var e in listSpecialtyPlan)
  151. {
  152. ex.MinorPlanID = e.MinorPlanID;
  153. ex.SchoolyearID = e.SchoolyearID;
  154. ex.CoursematerialID = e.CoursematerialID;
  155. isOKForexecutablePlan(ex);
  156. }
  157. }
  158. //辅修执行计划
  159. List<EM_ExecutableMinorPlan> executablePlanList = new List<EM_ExecutableMinorPlan>();
  160. List<EM_ExecutableMinorPlanTeachingSetting> executablePlanTeachingSettingList = new List<EM_ExecutableMinorPlanTeachingSetting>();
  161. List<EM_ExecutableMinorPlanTeachingModeType> teachingModeTypeList = new List<EM_ExecutableMinorPlanTeachingModeType>();
  162. List<EM_ExecutableMinorPlanTeachingPlace> teachingPlaceList = new List<EM_ExecutableMinorPlanTeachingPlace>();
  163. List<EM_MinorPlan> executablePlanSubmitedList = new List<EM_MinorPlan>();
  164. foreach (var specialtyPlan in listSpecialtyPlan)
  165. {
  166. if (specialtyPlan.EM_ExecutableMinorPlan.Count > 0)
  167. {
  168. var existExecutablePlanList = specialtyPlan.EM_ExecutableMinorPlan.ToList();
  169. var hasSubmitedExecutablePlan = false;
  170. foreach (var existExecutablePlan in existExecutablePlanList)
  171. {
  172. var ClassID=existExecutablePlan.EM_MinorPlan.CF_Grademinor.CF_Classminor.Select(s=>s.ClassminorID).FirstOrDefault();
  173. var existMissionClass = relateMissionClass.Where(x => x.EM_EducationMission.SchoolyearID == existExecutablePlan.SchoolyearID
  174. && x.CoursematerialID == existExecutablePlan.CoursematerialID
  175. && x.CF_Classmajor.Any(w => w.ClassmajorID == ClassID)).ToList();
  176. if (existExecutablePlan.RecordStatus == (int)EM_ExecuteStatus.Submited
  177. || existMissionClass.Count > 0)
  178. {
  179. hasSubmitedExecutablePlan = true;
  180. break;
  181. }
  182. }
  183. if (hasSubmitedExecutablePlan)
  184. {
  185. executablePlanSubmitedList.Add(specialtyPlan);
  186. continue;
  187. }
  188. else
  189. {
  190. var existExecutablePlanIDList = existExecutablePlanList.Select(x => x.ExecutableMinorPlanID).ToList();
  191. foreach (var e in existExecutablePlanIDList)
  192. {
  193. UnitOfWork.Delete<EM_ExecutableMinorPlanTeachingSetting>(x =>x.ExecutableMinorPlanID==e);
  194. UnitOfWork.Delete<EM_ExecutableMinorPlanTeachingPlace>(x =>x.ExecutableMinorPlanID==e);
  195. UnitOfWork.Delete<EM_ExecutableMinorPlanTeachingModeType>(x => x.ExecutableMinorPlanID==e);
  196. UnitOfWork.Delete<EM_ExecutableMinorPlan>(x =>x.ExecutableMinorPlanID==e);
  197. }
  198. }
  199. }
  200. EM_ExecutableMinorPlan executablePlan = new EM_ExecutableMinorPlan();
  201. executablePlan.ExecutableMinorPlanID = Guid.NewGuid();
  202. executablePlan.MinorPlanID = specialtyPlan.MinorPlanID;
  203. executablePlan.SchoolyearID = specialtyPlan.SchoolyearID;
  204. executablePlan.CoursematerialID = specialtyPlan.CoursematerialID;
  205. executablePlan.DepartmentID = specialtyPlan.DepartmentID;
  206. executablePlan.CollegeID = specialtyPlan.CF_Grademinor.CollegeID;
  207. executablePlan.YearID = specialtyPlan.CF_Grademinor.YearID;
  208. executablePlan.StandardID = specialtyPlan.CF_Grademinor.StandardID;
  209. executablePlan.CourseStructureID = specialtyPlan.CourseStructureID;
  210. executablePlan.CourseCategoryID = specialtyPlan.CourseCategoryID;
  211. executablePlan.CourseTypeID = specialtyPlan.CourseTypeID;
  212. executablePlan.CourseQualityID = specialtyPlan.CourseQualityID;
  213. executablePlan.PracticeTypeID = specialtyPlan.PracticeTypeID;
  214. executablePlan.ExaminationModeID = specialtyPlan.ExaminationModeID;
  215. executablePlan.CourseFineID = specialtyPlan.CourseFineID;
  216. executablePlan.IsSpecialtycore = specialtyPlan.IsSpecialtycore;
  217. executablePlan.IsCooperation = specialtyPlan.IsCooperation;
  218. executablePlan.IsRequired = specialtyPlan.IsRequired;
  219. executablePlan.IsElective = specialtyPlan.IsElective;
  220. executablePlan.IsNetworkCourse = specialtyPlan.IsNetworkCourse;
  221. executablePlan.IsMainCourse = specialtyPlan.IsMainCourse;
  222. executablePlan.TeachinglanguageID = specialtyPlan.TeachinglanguageID;
  223. executablePlan.HandleModeID = specialtyPlan.HandleModeID;
  224. executablePlan.IsNeedMaterial = specialtyPlan.IsNeedMaterial;
  225. executablePlan.ResultTypeID = specialtyPlan.ResultTypeID;
  226. executablePlan.Remarks = specialtyPlan.Remarks;
  227. this.SetNewStatus(executablePlan);
  228. executablePlan.RecordStatus = (int)EM_ExecuteStatus.NotSubmited;
  229. executablePlanList.Add(executablePlan);
  230. if (specialtyPlan.EM_MinorPlanTeachingSetting == null)
  231. {
  232. throw new Exception("该专业计划教学设置信息不存在。");
  233. }
  234. EM_ExecutableMinorPlanTeachingSetting executablePlanTeachingSetting = new EM_ExecutableMinorPlanTeachingSetting();
  235. executablePlanTeachingSetting.ExecutableMinorPlanID = executablePlan.ExecutableMinorPlanID;
  236. executablePlanTeachingSetting.Credit = specialtyPlan.EM_MinorPlanTeachingSetting.Credit ?? 0;
  237. executablePlanTeachingSetting.TheoryCourse = specialtyPlan.EM_MinorPlanTeachingSetting.TheoryCourse ?? 0;
  238. executablePlanTeachingSetting.Practicehours = specialtyPlan.EM_MinorPlanTeachingSetting.Practicehours ?? 0;
  239. executablePlanTeachingSetting.Trialhours = specialtyPlan.EM_MinorPlanTeachingSetting.Trialhours ?? 0;
  240. executablePlanTeachingSetting.WeeklyNum = specialtyPlan.EM_MinorPlanTeachingSetting.WeeklyNum ?? 0;
  241. executablePlanTeachingSetting.TheoryWeeklyNum = specialtyPlan.EM_MinorPlanTeachingSetting.TheoryWeeklyNum ?? 0;
  242. executablePlanTeachingSetting.PracticeWeeklyNum = specialtyPlan.EM_MinorPlanTeachingSetting.PracticeWeeklyNum ?? 0;
  243. executablePlanTeachingSetting.TrialWeeklyNum = specialtyPlan.EM_MinorPlanTeachingSetting.TrialWeeklyNum ?? 0;
  244. executablePlanTeachingSetting.StartWeeklyNum = specialtyPlan.EM_MinorPlanTeachingSetting.StartWeeklyNum ?? 0;
  245. executablePlanTeachingSetting.EndWeeklyNum = specialtyPlan.EM_MinorPlanTeachingSetting.EndWeeklyNum ?? 0;
  246. executablePlanTeachingSetting.WeeklyHours = specialtyPlan.EM_MinorPlanTeachingSetting.WeeklyHours ?? 0;
  247. executablePlanTeachingSettingList.Add(executablePlanTeachingSetting);
  248. specialtyPlan.EM_MinorPlanTeachingModeType.ToList().ForEach(x =>
  249. {
  250. EM_ExecutableMinorPlanTeachingModeType teachingModeType = new EM_ExecutableMinorPlanTeachingModeType();
  251. teachingModeType.ExecutableMinorPlanTeachingModeTypeID = Guid.NewGuid();
  252. teachingModeType.ExecutableMinorPlanID = executablePlan.ExecutableMinorPlanID;
  253. teachingModeType.TeachingModeID = x.TeachingModeID;
  254. this.SetNewStatus(teachingModeType);
  255. teachingModeTypeList.Add(teachingModeType);
  256. });
  257. specialtyPlan.EM_MinorPlanTeachingPlace.ToList().ForEach(x =>
  258. {
  259. EM_ExecutableMinorPlanTeachingPlace teachingPlace = new EM_ExecutableMinorPlanTeachingPlace();
  260. teachingPlace.ExecutableMinorPlanTeachingPlaceID = Guid.NewGuid();
  261. teachingPlace.ExecutableMinorPlanID = executablePlan.ExecutableMinorPlanID;
  262. teachingPlace.TeachingPlace = x.TeachingPlace;
  263. this.SetNewStatus(teachingPlace);
  264. teachingPlaceList.Add(teachingPlace);
  265. });
  266. }
  267. UnitOfWork.AddRange(executablePlanList);
  268. UnitOfWork.AddRange(executablePlanTeachingSettingList);
  269. UnitOfWork.AddRange(teachingModeTypeList);
  270. UnitOfWork.AddRange(teachingPlaceList);
  271. UnitOfWork.Commit();
  272. if (executablePlanSubmitedList.Count > 0)
  273. {
  274. var sucessCount = listSpecialtyPlan.Count - executablePlanSubmitedList.Count;
  275. if (sucessCount > 0)
  276. {
  277. throw new SuccessException(string.Format("执行完成,成功生成{0}条记录,{1}条记录由于对应的执行计划已经提交,无法覆盖。", sucessCount, executablePlanSubmitedList.Count));
  278. }
  279. }
  280. }
  281. catch (SuccessException ex)
  282. {
  283. throw new SuccessException(ex.Message);
  284. }
  285. catch (Exception ex)
  286. {
  287. throw new Exception(ex.Message);
  288. }
  289. }
  290. public void ExecutableMinorPlanEdit(ExecutableMinorPlanView executableMinorPlanView)
  291. {
  292. EM_ExecutableMinorPlan ExecutableMinorPlan = null;
  293. EM_ExecutableMinorPlanTeachingSetting ExecutableMinorPlanTeachingSetting = null;
  294. ExecutableMinorPlan = GetExecutableMinorPlan(executableMinorPlanView.ExecutableMinorPlanID);
  295. ExecutableMinorPlanTeachingSetting = GetExecutableMinorPlanTeachingSetting(executableMinorPlanView.ExecutableMinorPlanID);
  296. ExecutableMinorPlan.ResultTypeID = executableMinorPlanView.ResultTypeID;
  297. ExecutableMinorPlan.Remarks = executableMinorPlanView.Remark;
  298. SetModifyStatus(ExecutableMinorPlan);
  299. ExecutableMinorPlanTeachingSetting.Credit = executableMinorPlanView.Credit;
  300. ExecutableMinorPlanTeachingSetting.TheoryCourse = executableMinorPlanView.TheoryCourse;
  301. ExecutableMinorPlanTeachingSetting.Practicehours = executableMinorPlanView.Practicehours;
  302. ExecutableMinorPlanTeachingSetting.Trialhours = executableMinorPlanView.Trialhours;
  303. ExecutableMinorPlanTeachingSetting.WeeklyNum = executableMinorPlanView.WeeklyNum;
  304. ExecutableMinorPlanTeachingSetting.TheoryWeeklyNum = executableMinorPlanView.TheoryWeeklyNum;
  305. ExecutableMinorPlanTeachingSetting.PracticeWeeklyNum = executableMinorPlanView.PracticeWeeklyNum;
  306. ExecutableMinorPlanTeachingSetting.TrialWeeklyNum = executableMinorPlanView.TrialWeeklyNum;
  307. ExecutableMinorPlanTeachingSetting.StartWeeklyNum = executableMinorPlanView.StartWeeklyNum;
  308. ExecutableMinorPlanTeachingSetting.EndWeeklyNum = executableMinorPlanView.EndWeeklyNum;
  309. ExecutableMinorPlanTeachingSetting.WeeklyHours = executableMinorPlanView.WeeklyHours;
  310. UnitOfWork.Update(ExecutableMinorPlanTeachingSetting);
  311. if (executableMinorPlanView.TeachingModeID != null)
  312. {
  313. UnitOfWork.Delete<EM_ExecutableMinorPlanTeachingModeType>(x => x.ExecutableMinorPlanID == ExecutableMinorPlan.ExecutableMinorPlanID);
  314. foreach (var i in executableMinorPlanView.TeachingModeID)
  315. {
  316. EM_ExecutableMinorPlanTeachingModeType ExecutableMinorPlanTeachingModeType = new EM_ExecutableMinorPlanTeachingModeType();
  317. ExecutableMinorPlanTeachingModeType.ExecutableMinorPlanTeachingModeTypeID = Guid.NewGuid();
  318. ExecutableMinorPlanTeachingModeType.ExecutableMinorPlanID = ExecutableMinorPlan.ExecutableMinorPlanID;
  319. ExecutableMinorPlanTeachingModeType.TeachingModeID = i;
  320. SetNewStatus(ExecutableMinorPlanTeachingModeType);
  321. UnitOfWork.Add(ExecutableMinorPlanTeachingModeType);
  322. }
  323. }
  324. if (executableMinorPlanView.TeachingPlaceID != null)
  325. {
  326. UnitOfWork.Delete<EM_ExecutableMinorPlanTeachingPlace>(x => x.ExecutableMinorPlanID == ExecutableMinorPlan.ExecutableMinorPlanID);
  327. foreach (var i in executableMinorPlanView.TeachingPlaceID)
  328. {
  329. EM_ExecutableMinorPlanTeachingPlace ExecutableMinorPlanTeachingPlace = new EM_ExecutableMinorPlanTeachingPlace();
  330. ExecutableMinorPlanTeachingPlace.ExecutableMinorPlanTeachingPlaceID = Guid.NewGuid();
  331. ExecutableMinorPlanTeachingPlace.ExecutableMinorPlanID = ExecutableMinorPlan.ExecutableMinorPlanID;
  332. ExecutableMinorPlanTeachingPlace.TeachingPlace = i;
  333. SetNewStatus(ExecutableMinorPlanTeachingPlace);
  334. UnitOfWork.Add(ExecutableMinorPlanTeachingPlace);
  335. }
  336. }
  337. UnitOfWork.Commit();
  338. }
  339. public bool ExecutableMinorPlanDelete(List<Guid?> IDList)
  340. {
  341. try
  342. {
  343. if (IDList.Count > 0)
  344. {
  345. UnitOfWork.Delete<EM_ExecutableMinorPlanTeachingSetting>(x => IDList.Contains(x.ExecutableMinorPlanID));
  346. UnitOfWork.Delete<EM_ExecutableMinorPlanTeachingModeType>(x => IDList.Contains(x.ExecutableMinorPlanID));
  347. UnitOfWork.Delete<EM_ExecutableMinorPlanTeachingPlace>(x => IDList.Contains(x.ExecutableMinorPlanID));
  348. UnitOfWork.Delete<EM_ExecutableMinorPlan>(x => IDList.Contains(x.ExecutableMinorPlanID));
  349. }
  350. return true;
  351. }
  352. catch (Exception)
  353. {
  354. throw;
  355. }
  356. }
  357. /// <summary>
  358. /// 生成限选教学任务班
  359. /// </summary>
  360. /// <param name="executableOptionalCourseIDs"></param>
  361. /// <param name="teachingTypeNames"></param>
  362. public void GenerateEducationMissionClassOptionalCourse(List<Guid?> ExecutableMinorPlanIDs)
  363. {
  364. try
  365. {
  366. var executableMinorCourseList = ExecutableMinorPlanDAL.ExecutableMinorPlanRepository.GetList(x => ExecutableMinorPlanIDs.Contains(x.ExecutableMinorPlanID),
  367. (x => x.EM_MinorPlan.CF_Grademinor.CF_Classminor),
  368. (x => x.EM_MinorPlan.CF_Grademinor),
  369. (x => x.EM_ExecutableMinorPlanTeachingModeType),
  370. (x => x.EM_ExecutableMinorPlanTeachingSetting),
  371. (x => x.EM_MinorPlan.EM_Coursematerial),
  372. (x => x.EM_MinorPlan.EM_Coursematerial.EM_ClassGrouping.EM_ClassGroupingSettings),
  373. (x => x.EM_MinorPlan.CF_Department.CF_College.CF_Facultymajor),
  374. (x => x.EM_MinorPlan.CF_Department)
  375. ).ToList();
  376. //判断是否有设置授课方式
  377. var noTeachingModeTypeList = executableMinorCourseList.Where(x => x.EM_ExecutableMinorPlanTeachingModeType.Count == 0)
  378. .Concat(executableMinorCourseList.Where(x => !x.EM_ExecutableMinorPlanTeachingModeType.Any(w => w.TeachingModeID != null))).ToList();
  379. if (noTeachingModeTypeList.Count > 0)
  380. {
  381. throw new Exception("没有设置授课方式的计划不能提交,请核查。");
  382. }
  383. var resultMissionList = new List<EM_EducationMission>();
  384. var resultMissionClassList = new List<EM_EducationMissionClass>();
  385. var resultMissionClassTeachingSettingList = new List<EM_EducationMissionClassTeachingSetting>();
  386. var resultSchedulingClassList = new List<EM_EducationSchedulingClass>();
  387. var resultTeacherList = new List<EM_MissionClassTeacher>();
  388. string coursematerialName = "";
  389. var courseNames = executableMinorCourseList.Where(x =>x.EM_Coursematerial != null && x.EM_Coursematerial.EM_ClassGrouping == null).Select(x => x.EM_Coursematerial.CourseName).Distinct().ToArray();
  390. coursematerialName = string.Join(",", courseNames);
  391. if (courseNames.Length > 0)
  392. {
  393. throw new Exception("以下执行计划所对应的课程并未设置上课类型,无法确定任务班的分班方式,请到课程资料菜单完成设置后再次进行提交:\r\n" + coursematerialName);
  394. }
  395. var query = (
  396. from eop in
  397. (
  398. //先找出上课类型没有设置的授课方式,然后单独成一个班
  399. (from eop in executableMinorCourseList
  400. where eop.EM_ExecutableMinorPlanTeachingModeType
  401. .Any(x => !eop.EM_Coursematerial
  402. .EM_ClassGrouping
  403. .EM_ClassGroupingSettings.Select(w => w.TeachingModeID).Contains(x.TeachingModeID))
  404. select new
  405. {
  406. ExecutableMinorCourse = eop,
  407. TeachingMode = eop.EM_ExecutableMinorPlanTeachingModeType
  408. .FirstOrDefault(x => !eop.EM_Coursematerial
  409. .EM_ClassGrouping
  410. .EM_ClassGroupingSettings.Select(w => w.TeachingModeID).Contains(x.TeachingModeID))
  411. .TeachingModeID
  412. })
  413. //接下来对除理论班之外的其他分班设置进行匹配,如果该专业课程有这个授课方式的话,就单独再分一个班
  414. .Concat(
  415. from eop in executableMinorCourseList
  416. from tmt in eop.EM_ExecutableMinorPlanTeachingModeType
  417. from cgs in eop.EM_Coursematerial.EM_ClassGrouping.EM_ClassGroupingSettings
  418. where tmt.TeachingModeID == cgs.TeachingModeID
  419. select new
  420. {
  421. ExecutableMinorCourse = eop,
  422. TeachingMode = cgs.TeachingModeID
  423. }))
  424. join dtm in DictionaryHelper.GetDictionaryValue(ViewModel.DictionaryItem.CF_TeachingMode) on eop.TeachingMode equals dtm.Value
  425. group dtm by new
  426. {
  427. //Classmajor = sp.Classmajor,
  428. ExecutableMinorCourse = eop.ExecutableMinorCourse
  429. } into g
  430. select new
  431. {
  432. ExecutableMinorPlanID=g.Key.ExecutableMinorCourse.ExecutableMinorPlanID,
  433. ExecutableMinorCourse = g.Key.ExecutableMinorCourse,
  434. Classmajor = g.Key.ExecutableMinorCourse.EM_MinorPlan.CF_Grademinor.CF_Classminor,
  435. Student=g.Key.ExecutableMinorCourse.EM_MinorPlan.CF_Grademinor.CF_Classminor.Select(x=>x.CF_ClassminorStudent),
  436. TeachingMode = g.Select(x => x).ToList()
  437. }
  438. );
  439. var missionDataList = query.ToList();
  440. for (int i = 0; i < missionDataList.Count; i++)
  441. {
  442. var mission = missionDataList[i];
  443. EM_EducationMission educationMission = new EM_EducationMission();
  444. educationMission.EducationMissionID = Guid.NewGuid();
  445. educationMission.ClassName = mission.ExecutableMinorCourse.EM_MinorPlan.CF_Grademinor.CF_Classminor.Select(x => x.Name).FirstOrDefault() +"-"+ mission.ExecutableMinorCourse.EM_Coursematerial.CourseName;
  446. educationMission.DepartmentID = mission.ExecutableMinorCourse.DepartmentID;
  447. educationMission.CollegeID = mission.ExecutableMinorCourse.CollegeID;
  448. educationMission.SchoolyearID = mission.ExecutableMinorCourse.SchoolyearID;
  449. SetNewStatus(educationMission);
  450. resultMissionList.Add(educationMission);
  451. foreach (var tm in mission.TeachingMode)
  452. {
  453. EM_EducationMissionClass educationMissionClass = new EM_EducationMissionClass();
  454. educationMissionClass.EducationMissionClassID = Guid.NewGuid();
  455. educationMissionClass.EducationMissionID = educationMission.EducationMissionID;
  456. educationMissionClass.MainScheduleClassID = mission.Classmajor.OrderBy(x => x.ClassNum).FirstOrDefault().ClassminorID;
  457. educationMissionClass.OrderNo = 0;
  458. educationMissionClass.Name = mission.ExecutableMinorCourse.EM_MinorPlan.CF_Grademinor.CF_Classminor.Select(x => x.Name).FirstOrDefault() + "-" + mission.ExecutableMinorCourse.EM_Coursematerial.CourseName;
  459. educationMissionClass.TeachingModeID = tm.Value;
  460. if (mission.TeachingMode.Count > 0)
  461. {
  462. educationMissionClass.Name += "【" + tm.Name + "】";
  463. }
  464. educationMissionClass.OptionalCourseTypeID = (int)CF_CourseSelectType.OptionalCourse;
  465. educationMissionClass.CoursematerialID = mission.ExecutableMinorCourse.CoursematerialID;
  466. educationMissionClass.CourseStructureID = mission.ExecutableMinorCourse.CourseStructureID;
  467. educationMissionClass.CourseCategoryID = mission.ExecutableMinorCourse.CourseCategoryID;
  468. educationMissionClass.CourseTypeID = mission.ExecutableMinorCourse.CourseTypeID;
  469. educationMissionClass.CourseQualityID = mission.ExecutableMinorCourse.CourseQualityID;
  470. educationMissionClass.ExaminationModeID = mission.ExecutableMinorCourse.ExaminationModeID;
  471. educationMissionClass.TeachinglanguageID = mission.ExecutableMinorCourse.TeachinglanguageID;
  472. educationMissionClass.HandleModeID = (int)CF_HandleMode.MinorCourse;
  473. educationMissionClass.IsNeedMaterial = false;
  474. educationMissionClass.CF_Classmajor = null;
  475. educationMissionClass.ResultTypeID = mission.ExecutableMinorCourse.ResultTypeID;
  476. SetNewStatus(educationMissionClass);
  477. educationMissionClass.RecordStatus = (int)EMIS.ViewModel.CF_ApprovalStatus.NotSubmitted;
  478. //插入教学设置
  479. EM_EducationMissionClassTeachingSetting educationMissionClassTeachingSetting = new EM_EducationMissionClassTeachingSetting();
  480. educationMissionClassTeachingSetting.EducationMissionClassID = educationMissionClass.EducationMissionClassID;
  481. educationMissionClassTeachingSetting.Credit = mission.ExecutableMinorCourse.EM_ExecutableMinorPlanTeachingSetting.Credit;
  482. educationMissionClassTeachingSetting.TheoryCourse = mission.ExecutableMinorCourse.EM_ExecutableMinorPlanTeachingSetting.TheoryCourse;
  483. educationMissionClassTeachingSetting.Practicehours = mission.ExecutableMinorCourse.EM_ExecutableMinorPlanTeachingSetting.Practicehours;
  484. educationMissionClassTeachingSetting.Trialhours = mission.ExecutableMinorCourse.EM_ExecutableMinorPlanTeachingSetting.Trialhours;
  485. educationMissionClassTeachingSetting.WeeklyNum = mission.ExecutableMinorCourse.EM_ExecutableMinorPlanTeachingSetting.WeeklyNum;
  486. educationMissionClassTeachingSetting.TheoryWeeklyNum = mission.ExecutableMinorCourse.EM_ExecutableMinorPlanTeachingSetting.TheoryWeeklyNum;
  487. educationMissionClassTeachingSetting.PracticeWeeklyNum = mission.ExecutableMinorCourse.EM_ExecutableMinorPlanTeachingSetting.PracticeWeeklyNum;
  488. educationMissionClassTeachingSetting.TrialWeeklyNum = mission.ExecutableMinorCourse.EM_ExecutableMinorPlanTeachingSetting.TrialWeeklyNum;
  489. educationMissionClassTeachingSetting.StartWeeklyNum = mission.ExecutableMinorCourse.EM_ExecutableMinorPlanTeachingSetting.StartWeeklyNum;
  490. educationMissionClassTeachingSetting.EndWeeklyNum = mission.ExecutableMinorCourse.EM_ExecutableMinorPlanTeachingSetting.EndWeeklyNum;
  491. educationMissionClassTeachingSetting.WeeklyHours = mission.ExecutableMinorCourse.EM_ExecutableMinorPlanTeachingSetting.WeeklyHours;
  492. //插入排课班
  493. EM_EducationSchedulingClass educationSchedulingClass = new EM_EducationSchedulingClass();
  494. educationSchedulingClass.EducationSchedulingClassID = Guid.NewGuid();
  495. educationSchedulingClass.EducationMissionClassID = educationMissionClass.EducationMissionClassID;
  496. educationSchedulingClass.TaskGroupName = "1班";
  497. SetNewStatus(educationSchedulingClass);
  498. var ClassminorIDList =mission.Classmajor.Select(x=>x.ClassminorID).ToList();
  499. var studentIDList=ExecutableMinorPlanDAL.ClassminorStudentRepository.GetList(x=>ClassminorIDList.Contains(x.ClassminorID)).Select(w=>w.UserID).ToList();
  500. var StudentList= ExecutableMinorPlanDAL.StudentRepository.GetList(x=>studentIDList.Contains(x.UserID)).ToList();
  501. foreach(var s in StudentList)
  502. {
  503. CF_Student stu=s;
  504. educationSchedulingClass.CF_Student.Add(s);
  505. }
  506. EM_ExecutableMinorPlan ExecutableMinorPlan = ExecutableMinorPlanDAL.ExecutableMinorPlanRepository.GetList(x => x.ExecutableMinorPlanID == mission.ExecutableMinorPlanID).FirstOrDefault();
  507. if (ExecutableMinorPlan!=null)
  508. {
  509. ExecutableMinorPlan.EM_EducationMissionClass.Add(educationMissionClass);
  510. }
  511. resultMissionClassList.Add(educationMissionClass);
  512. resultMissionClassTeachingSettingList.Add(educationMissionClassTeachingSetting);
  513. resultSchedulingClassList.Add(educationSchedulingClass);
  514. }
  515. mission.ExecutableMinorCourse.RecordStatus = (int)EMIS.ViewModel.EM_ExecuteStatus.Submited;
  516. }
  517. UnitOfWork.BulkInsert(resultMissionList);
  518. //UnitOfWork.BulkInsert(resultMissionClassList);
  519. UnitOfWork.BulkInsert(resultMissionClassTeachingSettingList);
  520. UnitOfWork.BulkInsert(resultSchedulingClassList);
  521. UnitOfWork.BulkInsert(resultSchedulingClassList, (x => x.CF_Student));
  522. UnitOfWork.Commit();
  523. }
  524. catch (Exception)
  525. {
  526. throw;
  527. }
  528. }
  529. }
  530. }