SelectCourseResultServices.cs 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970
  1. using EMIS.DataLogic.SelectCourse.SelectCourseResult;
  2. using EMIS.Entities;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Linq.Expressions;
  7. using System.Text;
  8. using Bowin.Common.Linq.Entity;
  9. using EMIS.ViewModel.SelectCourse.SelectCourseResult;
  10. using EMIS.ViewModel.Students;
  11. using EMIS.Utility;
  12. using EMIS.ViewModel.SelectCourse;
  13. using EMIS.DataLogic.SelectCourse;
  14. using EMIS.DataLogic.UniversityManage.SpecialtyClassManage;
  15. using EMIS.DataLogic.EducationManage;
  16. using EMIS.DataLogic.Repositories;
  17. using Bowin.Common.Linq;
  18. using EMIS.ViewModel;
  19. namespace EMIS.CommonLogic.SelectCourse.SelectCourseResult
  20. {
  21. public class SelectCourseResultServices : BaseServices, ISelectCourseResultServices
  22. {
  23. public EducationMissionClassDAL educationMissionClassDAL { get; set; }
  24. public MissionClassTeacherRepository missionClassTeacherRepository { get; set; }
  25. public SelectCourseResultDAL SelectCourseResultDAL { get; set; }
  26. public OptionalCourseSettingDAL optionalCourseSettingDAL { get; set; }
  27. public ClassmajorDAL classmajorDAL { get; set; }
  28. public ExecutablePlanDAL ExecutablePlanDAL { get; set; }
  29. public OptionalCourseSettingDAL OptionalCourseSettingDAL { get; set; }
  30. public OpenControlSettingDAL OpenControlSettingDAL { get; set; }
  31. public ExecutableFreeSelectionCouseDAL ExecutableFreeSelectionCouseDAL { get; set; }
  32. public IStudentSelectCourseServices IStudentSelectCourseServices { get; set; }
  33. public IGridResultSet<SelectCourseResultView> GetSelectCourseResultViewList
  34. (ViewModel.ConfiguretView configuretView, Guid? schoolYearID, Guid? collegeID,
  35. Guid? courseID, int? courseTypeID, int? selectCourseTypeID, int? isCreated, int? isOpened, int pageIndex, int pageSize)
  36. {
  37. Expression<Func<EM_ExecutableOptionalCourse, bool>> eocExp = (x => true);
  38. Expression<Func<EM_ExecutableFreeSelectionCouse, bool>> efcExp = (x => true);
  39. var query = SelectCourseResultDAL.GetSelectCourseResultViewQueryable(eocExp, efcExp);
  40. var query1 = SelectCourseResultDAL.GetSelectCourseResultTeacher(eocExp, efcExp);
  41. var query2 = SelectCourseResultDAL.GetSelectCourseResultTeachingMode(eocExp, efcExp);
  42. if (schoolYearID.HasValue)
  43. {
  44. query = query.Where(x => x.SchoolyearID == schoolYearID);
  45. query1 = query1.Where(x => x.SchoolyearID == schoolYearID);
  46. efcExp.And(x => x.SchoolyearID == schoolYearID);
  47. }
  48. if (collegeID.HasValue)
  49. {
  50. query = query.Where(x => x.CollegeID == collegeID);
  51. efcExp.And(x => x.CF_Department.CollegeID == collegeID);
  52. }
  53. if (courseID.HasValue)
  54. {
  55. query = query.Where(x => x.CoursematerialID == courseID);
  56. efcExp.And(x => x.EM_FreeSelectionCouse.CoursematerialID == courseID);
  57. }
  58. if (courseTypeID.HasValue)
  59. {
  60. query = query.Where(x => x.CourseTypeID == courseTypeID);
  61. query1 = query1.Where(x => x.CourseTypeID == courseTypeID);
  62. efcExp.And(x => x.CourseTypeID == courseTypeID);
  63. }
  64. if (selectCourseTypeID.HasValue)
  65. {
  66. query = query.Where(x => x.SelectCourseType == selectCourseTypeID);
  67. query1 = query1.Where(x => x.SelectCourseType == selectCourseTypeID);
  68. }
  69. if (isCreated.HasValue)
  70. {
  71. query = query.Where(x => x.RecordStatus == isCreated);
  72. efcExp.And(x => x.RecordStatus == isCreated);
  73. //if (isCreated == (int)EMIS.ViewModel.CF_GeneralPurpose.IsYes)
  74. // query = query.Where(x => x.RecordStatus == (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Created);
  75. //else if (isCreated == (int)EMIS.ViewModel.CF_GeneralPurpose.IsNo)
  76. // query = query.Where(x => x.RecordStatus != (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Created);
  77. }
  78. if (isOpened.HasValue)
  79. {
  80. query = query.Where(x => x.IsOpened == (isOpened == 1 ? true : false));
  81. //query1 = query1.Where(x => x.IsOpened == (isOpened == 1 ? true : false));
  82. }
  83. //未提交状态不显示
  84. query = query.Where(x => x.RecordStatus > (int)EMIS.ViewModel.EM_SelectCourseResultStatus.NotOpen);
  85. query1 = query1.Where(x => x.RecordStatus > (int)EMIS.ViewModel.EM_SelectCourseResultStatus.NotOpen);
  86. query2 = query2.Where(x => x.RecordStatus > (int)EMIS.ViewModel.EM_SelectCourseResultStatus.NotOpen);
  87. //任选具体上课时间
  88. var queryScheduling = SelectCourseResultDAL.GetScheduling(efcExp).ToList();
  89. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  90. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  91. var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SelectCourseType).ToGridResultSet<SelectCourseResultView>(pageIndex, pageSize);
  92. var teacher = query1.ToList().OrderBy(x => x.SelectCourseType);
  93. var teachingMode = query2.ToList().OrderBy(x => x.SelectCourseType);
  94. result.rows.ForEach(x => x.TeacherName = string.Join(",", teacher.Where(w => w.ID == x.ID).Select(w => w.TeacherName)));
  95. if (queryScheduling.Count > 0)
  96. {
  97. var schedulingList = IStudentSelectCourseServices.GetWeekdayTimesSegmentName(queryScheduling);
  98. result.rows.ForEach(x =>
  99. {
  100. var list = schedulingList.Where(w => w.ID == x.ID);
  101. x.WeekdayTimesSegmentName = string.Join(";", list.OrderBy(w => w.Weekday).Select(w => w.WeekdayTimesSegmentName));
  102. });
  103. }
  104. return result;
  105. }
  106. public List<ViewModel.SelectCourse.SelectCourseResult.SelectCourseResultView> GetSelectCourseResultViewList
  107. (ViewModel.ConfiguretView configuretView, Guid? schoolYearID, Guid? collegeID,
  108. Guid? courseID, int? courseTypeID, int? selectCourseTypeID, int? isCreated, int? isOpened)
  109. {
  110. Expression<Func<EM_ExecutableOptionalCourse, bool>> eocExp = (x => true);
  111. Expression<Func<EM_ExecutableFreeSelectionCouse, bool>> efcExp = (x => true);
  112. var query = SelectCourseResultDAL.GetSelectCourseResultViewQueryable(eocExp, efcExp);
  113. var query1 = SelectCourseResultDAL.GetSelectCourseResultTeacher(eocExp, efcExp);
  114. if (schoolYearID.HasValue)
  115. {
  116. query = query.Where(x => x.SchoolyearID == schoolYearID);
  117. query1 = query1.Where(x => x.SchoolyearID == schoolYearID);
  118. }
  119. if (collegeID.HasValue)
  120. {
  121. query = query.Where(x => x.CollegeID == collegeID);
  122. }
  123. if (courseID.HasValue)
  124. {
  125. query = query.Where(x => x.CoursematerialID == courseID);
  126. }
  127. if (courseTypeID.HasValue)
  128. {
  129. query = query.Where(x => x.CourseTypeID == courseTypeID);
  130. query1 = query1.Where(x => x.CourseTypeID == courseTypeID);
  131. }
  132. if (selectCourseTypeID.HasValue)
  133. {
  134. query = query.Where(x => x.SelectCourseType == selectCourseTypeID);
  135. query1 = query1.Where(x => x.SelectCourseType == selectCourseTypeID);
  136. }
  137. if (isCreated.HasValue)
  138. {
  139. query = query.Where(x => x.RecordStatus == isCreated);
  140. //if (isCreated == (int)EMIS.ViewModel.CF_GeneralPurpose.IsYes)
  141. // query = query.Where(x => x.RecordStatus == (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Created);
  142. //else if (isCreated == (int)EMIS.ViewModel.CF_GeneralPurpose.IsNo)
  143. // query = query.Where(x => x.RecordStatus != (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Created);
  144. }
  145. if (isOpened.HasValue)
  146. {
  147. query = query.Where(x => x.IsOpened == (isOpened == 1 ? true : false));
  148. query1 = query1.Where(x => x.IsOpened == (isOpened == 1 ? true : false));
  149. }
  150. //未提交状态不显示
  151. query = query.Where(x => x.RecordStatus > (int)EMIS.ViewModel.EM_SelectCourseResultStatus.NotOpen);
  152. query1 = query1.Where(x => x.RecordStatus > (int)EMIS.ViewModel.EM_SelectCourseResultStatus.NotOpen);
  153. //任选具体上课时间
  154. var queryScheduling = SelectCourseResultDAL.GetScheduling(efcExp).ToList();
  155. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  156. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  157. var teacher = query1.ToList().OrderBy(x => x.SelectCourseType);
  158. var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SelectCourseType).ToList();
  159. result.ForEach(x => x.TeacherName = string.Join(",", teacher.Where(w => w.ID == x.ID).Select(w => w.TeacherName)));
  160. if (queryScheduling.Count > 0)
  161. {
  162. var schedulingList = IStudentSelectCourseServices.GetWeekdayTimesSegmentName(queryScheduling);
  163. result.ForEach(x =>
  164. {
  165. var list = schedulingList.Where(w => w.ID == x.ID);
  166. x.WeekdayTimesSegmentName = string.Join(";", list.OrderBy(w => w.Weekday).Select(w => w.WeekdayTimesSegmentName));
  167. });
  168. }
  169. return result;
  170. }
  171. public IGridResultSet<BaseStudentView> GetSelectCourseStudentViewGrid(Guid ID, string type, int pageIndex, int pageSize)
  172. {
  173. if (type == "0")
  174. {
  175. var query = OptionalCourseSettingDAL.GetSelectCourseStudent(x => x.ExecutableOptionalCourseID == ID).OrderBy(x => x.LoginID).ToGridResultSet<BaseStudentView>(1, null);
  176. //var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.LoginID).ToGridResultSet<BaseStudentView>(pageIndex, pageSize);
  177. //return result;
  178. return query;
  179. }
  180. else
  181. {
  182. var query = OptionalCourseSettingDAL.GetSelectCourseStudent1(x => x.ExecutableFreeSelectionCouseID == ID).OrderBy(x => x.LoginID).ToGridResultSet<BaseStudentView>(1, null);
  183. //var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.LoginID).ToGridResultSet<BaseStudentView>(pageIndex, pageSize);
  184. //return result;
  185. return query;
  186. }
  187. }
  188. /// <summary>
  189. /// 学生选课名单,区分限选学生和任选学生(0-限选,1-任选)
  190. /// </summary>
  191. /// <param name="ID"></param>
  192. /// <param name="type"></param>
  193. /// <returns></returns>
  194. public List<BaseStudentView> GetSelectCourseStudentViewList(Guid ID, string type)
  195. {
  196. if (type == "0")
  197. {
  198. var result = OptionalCourseSettingDAL.GetSelectCourseStudent(x => x.ExecutableOptionalCourseID == ID).OrderBy(x => x.LoginID).ToList();
  199. return result;
  200. }
  201. else
  202. {
  203. var result = OptionalCourseSettingDAL.GetSelectCourseStudent1(x => x.ExecutableFreeSelectionCouseID == ID).OrderBy(x => x.LoginID).ToList();
  204. return result;
  205. }
  206. }
  207. /// <summary>
  208. /// 生成教学任务班,Type为0时生成限选,1生成任选
  209. /// </summary>
  210. /// <param name="executablePlanIDs"></param>
  211. /// <param name="isOverride"></param>
  212. /// <param name="Type"></param>
  213. public void ChooseEducationMissionClass(List<Guid?> executablePlanIDs, string Type)
  214. {
  215. if (Type == "0")
  216. GenerateEducationMissionClassOptionalCourse(executablePlanIDs);
  217. else
  218. GenerateEducationMissionClassFreeSelection(executablePlanIDs);
  219. }
  220. /// <summary>
  221. /// 取消开班
  222. /// </summary>
  223. /// <param name="executablePlanIDs"></param>
  224. /// <param name="isOverride"></param>
  225. /// <param name="Type"></param>
  226. public void CancelEducationMissionClass(List<Guid?> executablePlanIDs)
  227. {
  228. List<EM_ExecutableOptionalCourse> ExecutableOptionalCourse = new List<EM_ExecutableOptionalCourse>();
  229. List<EM_ExecutableFreeSelectionCouse> ExecutableFreeSelectionCouse = new List<EM_ExecutableFreeSelectionCouse>();
  230. var OptionalCourseList = SelectCourseResultDAL.ExecutableOptionalCourseRepository.GetList(x => executablePlanIDs.Contains(x.ExecutableOptionalCourseID)).ToList();
  231. var FreeSelectionList = SelectCourseResultDAL.ExecutableFreeSelectionCouseRepository.GetList(x => executablePlanIDs.Contains(x.ExecutableFreeSelectionCouseID)).ToList();
  232. foreach (var OptionalCourse in OptionalCourseList)
  233. {
  234. OptionalCourse.RecordStatus = (int)EMIS.ViewModel.EM_SelectCourseResultStatus.CancleCreate;
  235. ExecutableOptionalCourse.Add(OptionalCourse);
  236. }
  237. foreach (var FreeSelection in FreeSelectionList)
  238. {
  239. FreeSelection.RecordStatus = (int)EMIS.ViewModel.EM_SelectCourseResultStatus.CancleCreate;
  240. ExecutableFreeSelectionCouse.Add(FreeSelection);
  241. }
  242. UnitOfWork.Commit();
  243. }
  244. /// <summary>
  245. /// 生成限选教学任务班
  246. /// </summary>
  247. /// <param name="executableOptionalCourseIDs"></param>
  248. /// <param name="teachingTypeNames"></param>
  249. public void GenerateEducationMissionClassOptionalCourse(List<Guid?> executableOptionalCourseIDs)
  250. {
  251. try
  252. {
  253. var executableOptionalCourseList = OptionalCourseSettingDAL.ExecutableOptionalCourseRepository.GetList(x => executableOptionalCourseIDs.Contains(x.ExecutableOptionalCourseID),
  254. (x => x.CF_Grademajor.CF_Classmajor),
  255. (x => x.CF_Classmajor),
  256. (x => x.CF_Student),
  257. //(x => x.CF_Schoolyear),
  258. (x => x.EM_ExecutableOptionalCourseTeachingMode),
  259. (x => x.EM_ExecutableOptionalCourseTeacher),
  260. (x => x.EM_ExecutableOptionalCourseTeachingSetting),
  261. (x => x.EM_OptionalCoursePlan.EM_Coursematerial),
  262. (x => x.EM_OptionalCoursePlan.EM_Coursematerial.EM_ClassGrouping.EM_ClassGroupingSettings),
  263. (x => x.CF_Grademajor.CF_Facultymajor),
  264. (x => x.EM_OptionalCoursePlan.CF_Department)
  265. ).ToList();
  266. //不是“未开班”状态不能开班
  267. var submitedList = executableOptionalCourseList.Where(x => x.RecordStatus != (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Opened && x.RecordStatus != (int)EMIS.ViewModel.EM_SelectCourseResultStatus.CancleCreate).ToList();
  268. if (submitedList.Count > 0)
  269. {
  270. throw new Exception("不是“已开放”状态不能进行开班,请核查。");
  271. }
  272. //开放时间未结束,不能进行开班
  273. var OpenControlSettingGrademajorIDList = executableOptionalCourseList.Select(w => w.GrademajorID); //找到要开班的所有年级专业
  274. var OpenControlSettingList = OpenControlSettingDAL.SelectCourseOpenControlSettingRepository.Entities.Where(x =>
  275. OpenControlSettingGrademajorIDList.Contains(x.GrademajorID)).ToList(); //找到年级专业对应的开放结束时间
  276. //验证同一学年学期同一课程下,是否有重复学生
  277. var valid = OptionalCourseSettingDAL.GetDuplicateOptionCourseViewQueryable(x => executableOptionalCourseIDs.Contains(x.ExecutableOptionalCourseID)).ToList();
  278. if (valid.Count > 0)
  279. {
  280. List<string> validMessageList = new List<string>();
  281. for (int i = 0; i < valid.Count; i++)
  282. {
  283. validMessageList.Add("任务班【" + valid[i].SourceName + "】和【" + valid[i].DestinationName + "】有重复的学生,请核查。");
  284. }
  285. if (valid.Count > 0)
  286. {
  287. throw new Exception(string.Join(",", validMessageList));
  288. }
  289. }
  290. //判断是否有设置授课方式
  291. var noTeachingModeTypeList = executableOptionalCourseList.Where(x => x.EM_ExecutableOptionalCourseTeachingMode.Count == 0)
  292. .Concat(executableOptionalCourseList.Where(x => !x.EM_ExecutableOptionalCourseTeachingMode.Any(w => w.TeachingModeID != null))).ToList();
  293. if (noTeachingModeTypeList.Count > 0)
  294. {
  295. throw new Exception("没有设置授课方式的计划不能提交,请核查。");
  296. }
  297. var existsMissionClassStudentList = this.optionalCourseSettingDAL.GetEducationMissionClassStudentByExecutableOptionalCourseID(executableOptionalCourseIDs).ToList();
  298. var grademajorIDs = executableOptionalCourseList.Select(x => x.GrademajorID)
  299. .ToList();
  300. //var queryclassmajorList = classmajorDAL.classmajorRepository.GetList(x => grademajorIDs.Contains(x.GrademajorID),
  301. // (x => x.CF_Student)).ToList();
  302. var resultMissionList = new List<EM_EducationMission>();
  303. var resultMissionClassList = new List<EM_EducationMissionClass>();
  304. var resultMissionClassTeachingSettingList = new List<EM_EducationMissionClassTeachingSetting>();
  305. var resultSchedulingClassList = new List<EM_EducationSchedulingClass>();
  306. var resultTeacherList = new List<EM_MissionClassTeacher>();
  307. var noStudentList = executableOptionalCourseList.Where(x => x.CF_Student.Count == 0).Select(x => x.DefaultClassName).ToList();
  308. if (noStudentList.Count > 0)
  309. {
  310. throw new Exception("任务班" + string.Join(",", noStudentList) + "没有报名的学生,请核查!");
  311. }
  312. if (executableOptionalCourseList.Count > 0)
  313. {
  314. executableOptionalCourseList.ForEach(x => x.RecordStatus = (int)EMIS.ViewModel.EM_ExecuteStatus.Submited);
  315. string coursematerialName = "";
  316. var courseNames = executableOptionalCourseList.Where(x => x.EM_OptionalCoursePlan.EM_Coursematerial != null && x.EM_OptionalCoursePlan.EM_Coursematerial.EM_ClassGrouping == null).Select(x => x.EM_OptionalCoursePlan.EM_Coursematerial.CourseName).Distinct().ToArray();
  317. coursematerialName = string.Join(",", courseNames);
  318. if (courseNames.Length > 0)
  319. {
  320. throw new Exception("以下计划所对应的课程并未设置上课类型,无法确定任务班的分班方式,请到课程资料菜单完成设置后再次进行提交:\r\n" + coursematerialName);
  321. }
  322. }
  323. var query = (
  324. from eop in
  325. (
  326. //先找出上课类型没有设置的授课方式,然后单独成一个班
  327. (from eop in executableOptionalCourseList
  328. where eop.EM_ExecutableOptionalCourseTeachingMode
  329. .Any(x => !eop.EM_OptionalCoursePlan.EM_Coursematerial
  330. .EM_ClassGrouping
  331. .EM_ClassGroupingSettings.Select(w => w.TeachingModeID).Contains(x.TeachingModeID))
  332. select new
  333. {
  334. ExecutableOptionalCourse = eop,
  335. TeachingMode = eop.EM_ExecutableOptionalCourseTeachingMode
  336. .FirstOrDefault(x => !eop.EM_OptionalCoursePlan.EM_Coursematerial
  337. .EM_ClassGrouping
  338. .EM_ClassGroupingSettings.Select(w => w.TeachingModeID).Contains(x.TeachingModeID))
  339. .TeachingModeID
  340. })
  341. //接下来对除理论班之外的其他分班设置进行匹配,如果该专业课程有这个授课方式的话,就单独再分一个班
  342. .Concat(
  343. from eop in executableOptionalCourseList
  344. from tmt in eop.EM_ExecutableOptionalCourseTeachingMode
  345. from cgs in eop.EM_OptionalCoursePlan.EM_Coursematerial.EM_ClassGrouping.EM_ClassGroupingSettings
  346. where tmt.TeachingModeID == cgs.TeachingModeID
  347. select new
  348. {
  349. ExecutableOptionalCourse = eop,
  350. TeachingMode = cgs.TeachingModeID
  351. }))
  352. join dtm in DictionaryHelper.GetDictionaryValue(ViewModel.DictionaryItem.CF_TeachingMode) on eop.TeachingMode equals dtm.Value
  353. group dtm by new
  354. {
  355. //Classmajor = sp.Classmajor,
  356. ExecutableOptionalCourse = eop.ExecutableOptionalCourse
  357. } into g
  358. select new
  359. {
  360. ExecutableOptionalCourse = g.Key.ExecutableOptionalCourse,
  361. Classmajor = g.Key.ExecutableOptionalCourse.CF_Classmajor,
  362. TeachingMode = g.Select(x => x).ToList(),
  363. Teacher = g.Key.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeacher,
  364. Student = g.Key.ExecutableOptionalCourse.CF_Student, //选此课的学生
  365. }
  366. );
  367. var missionDataList = query.ToList();
  368. for (int i = 0; i < missionDataList.Count; i++)
  369. {
  370. var mission = missionDataList[i];
  371. EM_EducationMission educationMission = new EM_EducationMission();
  372. educationMission.EducationMissionID = Guid.NewGuid();
  373. educationMission.ClassName = mission.ExecutableOptionalCourse.DefaultClassName;
  374. educationMission.DepartmentID = mission.ExecutableOptionalCourse.DepartmentID;
  375. educationMission.CollegeID = mission.ExecutableOptionalCourse.CF_Grademajor.CF_Facultymajor.CollegeID;
  376. educationMission.SchoolyearID = mission.ExecutableOptionalCourse.SchoolyearID;
  377. SetNewStatus(educationMission);
  378. resultMissionList.Add(educationMission);
  379. foreach (var tm in mission.TeachingMode)
  380. {
  381. EM_EducationMissionClass educationMissionClass = new EM_EducationMissionClass();
  382. educationMissionClass.EducationMissionClassID = Guid.NewGuid();
  383. educationMissionClass.MainScheduleClassID = mission.Classmajor.OrderBy(x => x.No).FirstOrDefault().ClassmajorID;
  384. educationMissionClass.OrderNo = 0;
  385. educationMissionClass.EducationMissionID = educationMission.EducationMissionID;
  386. educationMissionClass.Name = mission.ExecutableOptionalCourse.DefaultClassName;
  387. educationMissionClass.TeachingModeID = tm.Value;
  388. if (mission.TeachingMode.Count > 0)
  389. {
  390. educationMissionClass.Name += "【" + tm.Name + "】";
  391. }
  392. educationMissionClass.OptionalCourseTypeID = (int)CF_CourseSelectType.OptionalCourse;
  393. educationMissionClass.CoursematerialID = mission.ExecutableOptionalCourse.EM_OptionalCoursePlan.CoursematerialID;
  394. educationMissionClass.CourseStructureID = mission.ExecutableOptionalCourse.CourseStructureID;
  395. educationMissionClass.CourseCategoryID = mission.ExecutableOptionalCourse.CourseCategoryID;
  396. educationMissionClass.CourseTypeID = mission.ExecutableOptionalCourse.CourseTypeID;
  397. educationMissionClass.CourseQualityID = mission.ExecutableOptionalCourse.CourseQualityID;
  398. educationMissionClass.ExaminationModeID = mission.ExecutableOptionalCourse.ExaminationModeID;
  399. educationMissionClass.TeachinglanguageID = mission.ExecutableOptionalCourse.TeachinglanguageID;
  400. educationMissionClass.HandleModeID = (int)CF_HandleMode.SelectionCourse;
  401. educationMissionClass.IsNeedMaterial = false;
  402. educationMissionClass.CF_Classmajor = mission.Classmajor;
  403. educationMissionClass.ResultTypeID = mission.ExecutableOptionalCourse.ResultTypeID;
  404. foreach (var list in mission.Teacher.Select(x => new { x.UserID, x.TeachingMethod }))
  405. {
  406. EM_MissionClassTeacher teacher = new EM_MissionClassTeacher();
  407. teacher.MissionClassTeacherID = Guid.NewGuid();
  408. teacher.MissionClassID = educationMissionClass.EducationMissionClassID;
  409. teacher.TeachType = list.TeachingMethod;
  410. teacher.UserID = list.UserID;
  411. SetNewStatus(teacher);
  412. educationMissionClass.EM_MissionClassTeacher.Add(teacher);
  413. resultTeacherList.Add(teacher);
  414. }
  415. //educationMissionClass.EM_MissionClassTeacher = mission.Teacher;
  416. SetNewStatus(educationMissionClass);
  417. educationMissionClass.RecordStatus = (int)EMIS.ViewModel.CF_ApprovalStatus.NotSubmitted;
  418. //插入教学设置
  419. EM_EducationMissionClassTeachingSetting educationMissionClassTeachingSetting = new EM_EducationMissionClassTeachingSetting();
  420. educationMissionClassTeachingSetting.EducationMissionClassID = educationMissionClass.EducationMissionClassID;
  421. educationMissionClassTeachingSetting.Credit = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.Credit;
  422. educationMissionClassTeachingSetting.TheoryCourse = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.TheoryCourse;
  423. educationMissionClassTeachingSetting.Practicehours = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.Practicehours;
  424. educationMissionClassTeachingSetting.Trialhours = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.Trialhours;
  425. educationMissionClassTeachingSetting.WeeklyNum = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.WeeklyNum;
  426. educationMissionClassTeachingSetting.TheoryWeeklyNum = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.TheoryWeeklyNum;
  427. educationMissionClassTeachingSetting.PracticeWeeklyNum = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.PracticeWeeklyNum;
  428. educationMissionClassTeachingSetting.TrialWeeklyNum = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.TrialWeeklyNum;
  429. educationMissionClassTeachingSetting.StartWeeklyNum = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.StartWeeklyNum;
  430. educationMissionClassTeachingSetting.EndWeeklyNum = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.EndWeeklyNum;
  431. educationMissionClassTeachingSetting.WeeklyHours = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.WeeklyHours;
  432. //插入排课班
  433. EM_EducationSchedulingClass educationSchedulingClass = new EM_EducationSchedulingClass();
  434. educationSchedulingClass.EducationSchedulingClassID = Guid.NewGuid();
  435. educationSchedulingClass.EducationMissionClassID = educationMissionClass.EducationMissionClassID;
  436. educationSchedulingClass.TaskGroupName = "1班";
  437. SetNewStatus(educationSchedulingClass);
  438. List<Guid> educationMissionClassUserIDs = existsMissionClassStudentList
  439. .Where(x => x.CoursematerialID == educationMissionClass.CoursematerialID
  440. && x.SchoolyearID == educationMission.SchoolyearID
  441. && x.HandleModeID == educationMissionClass.HandleModeID
  442. && x.CourseSelectTypeID == educationMissionClass.OptionalCourseTypeID).Select(x => x.UserID.Value).ToList();
  443. //查询要开班的教学任务班对应学生
  444. List<Guid> missionUserIDs = mission.Student.Select(x => x.UserID).ToList();
  445. //添加排课任务班学生(先查出要开班的学生与已存在的排课班对应学生的差集,排除重复学生,分班后删除再重新开班时存在重复学生)
  446. educationSchedulingClass.CF_Student = new HashSet<CF_Student>(mission.Student.Where(x => missionUserIDs.Except(educationMissionClassUserIDs).Contains(x.UserID))); //选此课的学生
  447. resultMissionClassList.Add(educationMissionClass);
  448. resultMissionClassTeachingSettingList.Add(educationMissionClassTeachingSetting);
  449. resultSchedulingClassList.Add(educationSchedulingClass);
  450. }
  451. mission.ExecutableOptionalCourse.RecordStatus = (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Created;
  452. }
  453. UnitOfWork.BulkInsert(resultMissionList);
  454. UnitOfWork.BulkInsert(resultMissionClassList);
  455. UnitOfWork.BulkInsert(resultMissionClassTeachingSettingList);
  456. UnitOfWork.BulkInsert(resultMissionClassList, (x => x.CF_Classmajor));
  457. UnitOfWork.BulkInsert(resultMissionClassList, (x => x.EM_MissionClassTeacher));
  458. UnitOfWork.BulkInsert(resultTeacherList);
  459. UnitOfWork.BulkInsert(resultSchedulingClassList);
  460. UnitOfWork.BulkInsert(resultSchedulingClassList, (x => x.CF_Student));
  461. UnitOfWork.Commit();
  462. }
  463. catch (Exception)
  464. {
  465. throw;
  466. }
  467. }
  468. /// <summary>
  469. /// 生成任选教学任务班
  470. /// </summary>
  471. /// <param name="executableFreeSelectionCourseIDs"></param>
  472. /// <param name="isOverride"></param>
  473. public void GenerateEducationMissionClassFreeSelection(List<Guid?> executableFreeSelectionCourseIDs)
  474. {
  475. try
  476. {
  477. var executableFreeSelectionCourseList = OptionalCourseSettingDAL.ExecutableFreeSelectionCouseRepository.GetList(x => executableFreeSelectionCourseIDs.Contains(x.ExecutableFreeSelectionCouseID),
  478. (x => x.CF_Student),
  479. (x => x.EM_ExecutableFreeSelectionCouseTeachingMode),
  480. (x => x.EM_ExecutableFreeSelectionCouseTeacher),
  481. (x => x.EM_ExecutableFreeSelectionCouseTeachingSetting),
  482. (x => x.EM_FreeSelectionCouse.EM_Coursematerial),
  483. (x => x.EM_FreeSelectionCouse.EM_Coursematerial.EM_ClassGrouping.EM_ClassGroupingSettings),
  484. (x => x.EM_ExecutableFreeSelectionCouseScheduling),
  485. (x => x.CF_Department)
  486. ).ToList();
  487. var submitedList = executableFreeSelectionCourseList.Where(x => x.RecordStatus != (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Opened && x.RecordStatus != (int)EMIS.ViewModel.EM_SelectCourseResultStatus.CancleCreate).ToList();
  488. if (submitedList.Count > 0)
  489. {
  490. throw new Exception("不是已开放状态不能进行开班,请核查。");
  491. }
  492. var noTeachingModeTypeList = executableFreeSelectionCourseList.Where(x => x.EM_ExecutableFreeSelectionCouseTeachingMode.Count == 0)
  493. .Concat(executableFreeSelectionCourseList.Where(x => !x.EM_ExecutableFreeSelectionCouseTeachingMode.Any(w => w.TeachingModeID != null))).ToList();
  494. if (noTeachingModeTypeList.Count > 0)
  495. {
  496. throw new Exception("没有设置授课方式的计划不能提交,请核查。");
  497. }
  498. var noSchedulingList = executableFreeSelectionCourseList.Where(x => x.EM_ExecutableFreeSelectionCouseScheduling.Count == 0).FirstOrDefault();
  499. if (noSchedulingList != null)
  500. throw new Exception(noSchedulingList.DefaultClassName + "缺少排课信息,不能开班");
  501. var resultMissionList = new List<EM_EducationMission>(); //教学任务
  502. var resultMissionClassList = new List<EM_EducationMissionClass>(); //教学任务班
  503. var resultMissionClassTeachingSettingList = new List<EM_EducationMissionClassTeachingSetting>();
  504. var resultEducationSchedulingClassList = new List<EM_EducationSchedulingClass>(); //排课班表
  505. var resultTeacherList = new List<EM_MissionClassTeacher>(); //教学任务班任课老师表
  506. var resultEducationSchedulingList = new List<ES_EducationScheduling>(); //排课课表
  507. var resultEducationSchedulingTeacherList = new List<ES_EducationSchedulingTeacher>(); //排课老师表
  508. var resultEducationSchedulingWeekNumList = new List<ES_EducationSchedulingWeekNum>(); //排课周次表
  509. var resultCourseProcessList = new List<EM_CourseProcess>(); //课程进度
  510. var resultCourseProcessTeacherList = new List<EM_CourseProcessTeacher>(); //课程进度任课老师表
  511. var resultEducationMissionClassSettingsList = new List<EM_EducationMissionClassSettings>(); //任务班设置表
  512. var noStudentList = executableFreeSelectionCourseList.Where(x => x.CF_Student.Count == 0).Select(x => x.DefaultClassName).ToList();
  513. if (noStudentList.Count > 0)
  514. {
  515. throw new Exception("任务班" + string.Join(",", noStudentList) + "未分配学生!");
  516. }
  517. if (executableFreeSelectionCourseList.Count > 0)
  518. {
  519. executableFreeSelectionCourseList.ForEach(x => x.RecordStatus = (int)EMIS.ViewModel.EM_ExecuteStatus.Submited);
  520. string coursematerialName = "";
  521. var courseNames = executableFreeSelectionCourseList.Where(x => x.EM_FreeSelectionCouse.EM_Coursematerial != null && x.EM_FreeSelectionCouse.EM_Coursematerial.EM_ClassGrouping == null).Select(x => x.EM_FreeSelectionCouse.EM_Coursematerial.CourseName).Distinct().ToArray();
  522. coursematerialName = string.Join(",", courseNames);
  523. if (courseNames.Length > 0)
  524. {
  525. throw new Exception("以下计划所对应的课程并未设置上课类型,无法确定任务班的分班方式,请到课程资料菜单完成设置后再次进行提交:\r\n" + coursematerialName);
  526. }
  527. }
  528. var query = (
  529. from efsc in
  530. (
  531. //先找出上课类型没有设置的授课方式,然后单独成一个班
  532. (from efsc in executableFreeSelectionCourseList
  533. where efsc.EM_ExecutableFreeSelectionCouseTeachingMode
  534. .Any(x => !efsc.EM_FreeSelectionCouse.EM_Coursematerial
  535. .EM_ClassGrouping
  536. .EM_ClassGroupingSettings.Select(w => w.TeachingModeID).Contains(x.TeachingModeID))
  537. select new
  538. {
  539. ExecutableFreeSelectionCourse = efsc,
  540. TeachingMode = efsc.EM_ExecutableFreeSelectionCouseTeachingMode
  541. .FirstOrDefault(x => !efsc.EM_FreeSelectionCouse.EM_Coursematerial
  542. .EM_ClassGrouping
  543. .EM_ClassGroupingSettings.Select(w => w.TeachingModeID).Contains(x.TeachingModeID))
  544. .TeachingModeID
  545. })
  546. //接下来对除理论班之外的其他分班设置进行匹配,如果该专业课程有这个授课方式的话,就单独再分一个班
  547. .Concat(
  548. from efsc in executableFreeSelectionCourseList
  549. from tmt in efsc.EM_ExecutableFreeSelectionCouseTeachingMode
  550. from cgs in efsc.EM_FreeSelectionCouse.EM_Coursematerial.EM_ClassGrouping.EM_ClassGroupingSettings
  551. where tmt.TeachingModeID == cgs.TeachingModeID
  552. select new
  553. {
  554. ExecutableFreeSelectionCourse = efsc,
  555. TeachingMode = cgs.TeachingModeID
  556. }))
  557. join dtm in DictionaryHelper.GetDictionaryValue(ViewModel.DictionaryItem.CF_TeachingMode) on efsc.TeachingMode equals dtm.Value
  558. group dtm by new
  559. {
  560. ExecutableFreeSelectionCourse = efsc.ExecutableFreeSelectionCourse
  561. } into g
  562. select new
  563. {
  564. ExecutableFreeSelectionCourse = g.Key.ExecutableFreeSelectionCourse,
  565. TeachingSetting = g.Key.ExecutableFreeSelectionCourse.EM_ExecutableFreeSelectionCouseTeachingSetting,
  566. TeachingMode = g.Select(x => x).ToList(),
  567. Teacher = g.Key.ExecutableFreeSelectionCourse.EM_ExecutableFreeSelectionCouseTeacher,
  568. Scheduling = g.Key.ExecutableFreeSelectionCourse.EM_ExecutableFreeSelectionCouseScheduling,
  569. Student = g.Key.ExecutableFreeSelectionCourse.CF_Student, //选此课的学生
  570. }
  571. );
  572. var missionDataList = query.ToList();
  573. for (int i = 0; i < missionDataList.Count; i++)
  574. {
  575. var mission = missionDataList[i];
  576. EM_EducationMission educationMission = new EM_EducationMission();
  577. educationMission.EducationMissionID = Guid.NewGuid();
  578. educationMission.ClassName = mission.ExecutableFreeSelectionCourse.DefaultClassName;
  579. educationMission.DepartmentID = mission.ExecutableFreeSelectionCourse.DepartmentID;
  580. educationMission.SchoolyearID = mission.ExecutableFreeSelectionCourse.SchoolyearID;
  581. educationMission.CollegeID = mission.ExecutableFreeSelectionCourse.CF_Department.CollegeID;
  582. SetNewStatus(educationMission);
  583. //educationMission.CF_Classmajor.Add(mission.Classmajor);
  584. resultMissionList.Add(educationMission);
  585. foreach (var tm in mission.TeachingMode)
  586. {
  587. var executableFreeSelectionCouseScheduling = mission.ExecutableFreeSelectionCourse.EM_ExecutableFreeSelectionCouseScheduling.FirstOrDefault();
  588. EM_EducationMissionClass educationMissionClass = new EM_EducationMissionClass();
  589. educationMissionClass.EducationMissionClassID = Guid.NewGuid();
  590. educationMissionClass.OrderNo = 0;
  591. educationMissionClass.EducationMissionID = educationMission.EducationMissionID;
  592. educationMissionClass.Name = mission.ExecutableFreeSelectionCourse.DefaultClassName;
  593. //educationMissionClass.Name = mission.Classmajor.Name + "-" + mission.ExecutablePlan.EM_FreeSelectionCouse.EM_Coursematerial.CourseName;
  594. educationMissionClass.TeachingModeID = tm.Value;
  595. if (mission.TeachingMode.Count > 0)
  596. {
  597. educationMissionClass.Name += "【" + tm.Name + "】";
  598. }
  599. //educationMissionClass.OptionalCourseTypeID = null;
  600. educationMissionClass.OptionalCourseTypeID = (int)CF_CourseSelectType.FreeSelectionCourse;
  601. educationMissionClass.CoursematerialID = mission.ExecutableFreeSelectionCourse.EM_FreeSelectionCouse.CoursematerialID;
  602. educationMissionClass.CourseStructureID = mission.ExecutableFreeSelectionCourse.CourseStructureID;
  603. educationMissionClass.CourseCategoryID = mission.ExecutableFreeSelectionCourse.CourseCategoryID;
  604. educationMissionClass.CourseTypeID = mission.ExecutableFreeSelectionCourse.CourseTypeID;
  605. educationMissionClass.CourseQualityID = mission.ExecutableFreeSelectionCourse.CourseQualityID;
  606. educationMissionClass.ExaminationModeID = mission.ExecutableFreeSelectionCourse.ExaminationModeID;
  607. educationMissionClass.TeachinglanguageID = mission.ExecutableFreeSelectionCourse.TeachinglanguageID;
  608. educationMissionClass.HandleModeID = mission.ExecutableFreeSelectionCourse.HandleModeID;
  609. educationMissionClass.IsNeedMaterial = mission.ExecutableFreeSelectionCourse.IsNeedMaterial;
  610. educationMissionClass.ResultTypeID = mission.ExecutableFreeSelectionCourse.ResultTypeID;
  611. SetNewStatus(educationMissionClass);
  612. educationMissionClass.RecordStatus = (int)EMIS.ViewModel.EM_EducationMissionClassStatus.Scheduled;
  613. //插入教学设置
  614. EM_EducationMissionClassTeachingSetting educationMissionClassTeachingSetting = new EM_EducationMissionClassTeachingSetting();
  615. educationMissionClassTeachingSetting.EducationMissionClassID = educationMissionClass.EducationMissionClassID;
  616. educationMissionClassTeachingSetting.Credit = mission.TeachingSetting.Credit;
  617. educationMissionClassTeachingSetting.TheoryCourse = mission.TeachingSetting.TheoryCourse;
  618. educationMissionClassTeachingSetting.Practicehours = mission.TeachingSetting.Practicehours;
  619. educationMissionClassTeachingSetting.Trialhours = mission.TeachingSetting.Trialhours;
  620. educationMissionClassTeachingSetting.WeeklyNum = mission.TeachingSetting.WeeklyNum;
  621. educationMissionClassTeachingSetting.TheoryWeeklyNum = mission.TeachingSetting.TheoryWeeklyNum;
  622. educationMissionClassTeachingSetting.PracticeWeeklyNum = mission.TeachingSetting.PracticeWeeklyNum;
  623. educationMissionClassTeachingSetting.TrialWeeklyNum = mission.TeachingSetting.TrialWeeklyNum;
  624. educationMissionClassTeachingSetting.StartWeeklyNum = mission.TeachingSetting.StartWeeklyNum;
  625. educationMissionClassTeachingSetting.EndWeeklyNum = mission.TeachingSetting.EndWeeklyNum;
  626. educationMissionClassTeachingSetting.WeeklyHours = mission.TeachingSetting.WeeklyHours;
  627. foreach (var list in mission.Teacher.Select(x => new { x.UserID, x.TeachingMethod }))
  628. {
  629. EM_MissionClassTeacher teacher = new EM_MissionClassTeacher();
  630. teacher.MissionClassTeacherID = Guid.NewGuid();
  631. teacher.MissionClassID = educationMissionClass.EducationMissionClassID;
  632. teacher.TeachType = list.TeachingMethod;
  633. teacher.UserID = list.UserID;
  634. SetNewStatus(teacher);
  635. educationMissionClass.EM_MissionClassTeacher.Add(teacher);
  636. resultTeacherList.Add(teacher);
  637. }
  638. int? ClassroomType = null; //教室类型,教学任务班表和课程进度需要
  639. if (executableFreeSelectionCouseScheduling != null && executableFreeSelectionCouseScheduling.ClassroomID != null)
  640. {
  641. var classRoom = educationMissionClassDAL.ClassroomRepository.GetList(x => x.ClassroomID == executableFreeSelectionCouseScheduling.ClassroomID, x => x.CF_ClassroomType).FirstOrDefault();
  642. if (classRoom != null && classRoom.CF_ClassroomType.FirstOrDefault() != null)
  643. {
  644. ClassroomType = classRoom.CF_ClassroomType.FirstOrDefault().ClassroomType;
  645. educationMissionClass.ClassroomTypeID = ClassroomType;
  646. }
  647. educationMissionClass.ClassroomID = executableFreeSelectionCouseScheduling.ClassroomID;
  648. }
  649. if (executableFreeSelectionCouseScheduling.CoursesTimeID != null)
  650. {
  651. var coursesTime = educationMissionClassDAL.CoursesTimeRepository.Entities.Where(x => x.CoursesTimeID == executableFreeSelectionCouseScheduling.CoursesTimeID).FirstOrDefault();
  652. educationMissionClass.EM_CoursesTime = new HashSet<EM_CoursesTime>();
  653. educationMissionClass.EM_CoursesTime.Add(coursesTime);
  654. }
  655. //插入排课班
  656. EM_EducationSchedulingClass educationSchedulingClass = new EM_EducationSchedulingClass();
  657. educationSchedulingClass.EducationSchedulingClassID = Guid.NewGuid();
  658. educationSchedulingClass.EducationMissionClassID = educationMissionClass.EducationMissionClassID;
  659. educationSchedulingClass.TaskGroupName = "1班";
  660. SetNewStatus(educationSchedulingClass);
  661. //添加排课任务班学生
  662. educationSchedulingClass.CF_Student = mission.Student; //选此课的学生
  663. resultMissionClassList.Add(educationMissionClass);
  664. resultMissionClassTeachingSettingList.Add(educationMissionClassTeachingSetting);
  665. resultEducationSchedulingClassList.Add(educationSchedulingClass);
  666. //添加排课任务班学生
  667. educationSchedulingClass.CF_Student = mission.Student; //选此课的学生
  668. //resultMissionClassList.Add(educationMissionClass);
  669. //resultSchedulingClassList.Add(educationSchedulingClass);
  670. //根据开始和结束周,得到所有周的列表
  671. List<int?> schedulingWeekList = new List<int?>();
  672. schedulingWeekList.Add(mission.TeachingSetting.StartWeeklyNum);
  673. schedulingWeekList.Add(mission.TeachingSetting.EndWeeklyNum);
  674. for (int j = 1; j + schedulingWeekList.Min() < schedulingWeekList.Max(); j++)
  675. {
  676. schedulingWeekList.Add(j + schedulingWeekList.Min());
  677. }
  678. //排课课表
  679. foreach (var list in mission.Scheduling.Select(x => new { x.CoursesTimeID, x.ClassroomID, x.Weekday }))
  680. {
  681. ES_EducationScheduling educationScheduling = new ES_EducationScheduling();
  682. educationScheduling.EducationSchedulingID = Guid.NewGuid();
  683. educationScheduling.EducationSchedulingClassID = educationSchedulingClass.EducationSchedulingClassID;
  684. educationScheduling.SchoolyearID = educationMission.SchoolyearID;
  685. educationScheduling.Weekday = list.Weekday;
  686. educationScheduling.ClassroomID = list.ClassroomID;
  687. educationScheduling.CoursesTimeID = list.CoursesTimeID;
  688. SetNewStatus(educationScheduling);
  689. //educationScheduling.ES_EducationSchedulingTeacher.Add(educationScheduling);
  690. resultEducationSchedulingList.Add(educationScheduling);
  691. //排课教师表
  692. foreach (var teacherlist in mission.Teacher.Select(x => new { x.UserID, x.TeachingMethod }))
  693. {
  694. ES_EducationSchedulingTeacher teacher = new ES_EducationSchedulingTeacher();
  695. teacher.EducationSchedulingTeacherID = Guid.NewGuid();
  696. teacher.EducationSchedulingID = educationScheduling.EducationSchedulingID;
  697. teacher.TeachingMethod = teacherlist.TeachingMethod;
  698. teacher.UserID = teacherlist.UserID;
  699. SetNewStatus(teacher);
  700. educationScheduling.ES_EducationSchedulingTeacher.Add(teacher);
  701. resultEducationSchedulingTeacherList.Add(teacher);
  702. }
  703. foreach (var weekList in schedulingWeekList)
  704. {
  705. ES_EducationSchedulingWeekNum week = new ES_EducationSchedulingWeekNum();
  706. week.EducationSchedulingWeekNumID = Guid.NewGuid();
  707. week.EducationSchedulingID = educationScheduling.EducationSchedulingID;
  708. week.WeekNum = weekList;
  709. SetNewStatus(week);
  710. educationScheduling.ES_EducationSchedulingWeekNum.Add(week);
  711. resultEducationSchedulingWeekNumList.Add(week);
  712. }
  713. }
  714. //课程进度和教室以及任务班设置表
  715. foreach (var weekList in schedulingWeekList)
  716. {
  717. EM_CourseProcess process = new EM_CourseProcess();
  718. process.CourseProcessID = Guid.NewGuid();
  719. process.EducationMissionClassID = educationMissionClass.EducationMissionClassID;
  720. process.Week = weekList;
  721. process.Times = mission.TeachingSetting.WeeklyHours;
  722. process.ClassroomTypeID = ClassroomType;
  723. process.ClassroomID = educationMissionClass.ClassroomID;
  724. SetNewStatus(process);
  725. resultCourseProcessList.Add(process);
  726. //任务班设置表
  727. EM_EducationMissionClassSettings educationMissionClassSettings = new EM_EducationMissionClassSettings();
  728. educationMissionClassSettings.EducationMissionClassSettingsID = Guid.NewGuid();
  729. educationMissionClassSettings.EducationMissionClassID = educationMissionClass.EducationMissionClassID;
  730. educationMissionClassSettings.WeeklyNum = weekList;
  731. SetNewStatus(educationMissionClassSettings);
  732. resultEducationMissionClassSettingsList.Add(educationMissionClassSettings);
  733. //排课教师表
  734. foreach (var teacherlist in mission.Teacher.Select(x => new { x.UserID, x.TeachingMethod }))
  735. {
  736. EM_CourseProcessTeacher teacher = new EM_CourseProcessTeacher();
  737. teacher.CourseProcessTeacherID = Guid.NewGuid();
  738. teacher.CourseProcessID = process.CourseProcessID;
  739. teacher.UserID = teacherlist.UserID;
  740. teacher.TeachType = teacherlist.TeachingMethod;
  741. SetNewStatus(teacher);
  742. resultCourseProcessTeacherList.Add(teacher);
  743. }
  744. }
  745. }
  746. //UnitOfWork.Add(educationMission);
  747. EM_ExecutableFreeSelectionCouse eoc = GetExecutableFreeSelectionCouseEntity(mission.ExecutableFreeSelectionCourse.ExecutableFreeSelectionCouseID);
  748. if (eoc != null) //状态改为已开班
  749. eoc.RecordStatus = (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Created;
  750. }
  751. UnitOfWork.BulkInsert(resultMissionList); //教学任务
  752. UnitOfWork.BulkInsert(resultMissionClassList); //教学任务班
  753. UnitOfWork.BulkInsert(resultMissionClassTeachingSettingList);
  754. UnitOfWork.BulkInsert(resultTeacherList); //
  755. UnitOfWork.BulkInsert(resultMissionClassList, x => x.EM_CoursesTime); //
  756. UnitOfWork.BulkInsert(resultEducationMissionClassSettingsList); //任务班设置表
  757. UnitOfWork.BulkInsert(resultEducationSchedulingList); //排课课表
  758. UnitOfWork.BulkInsert(resultEducationSchedulingTeacherList); //排课老师表
  759. UnitOfWork.BulkInsert(resultEducationSchedulingWeekNumList); //
  760. UnitOfWork.BulkInsert(resultEducationSchedulingClassList); //排课班表
  761. UnitOfWork.BulkInsert(resultEducationSchedulingClassList, (x => x.CF_Student)); //排课班与学生关联表
  762. UnitOfWork.BulkInsert(resultCourseProcessList); //课程进度
  763. UnitOfWork.BulkInsert(resultCourseProcessTeacherList); //课程进度任课老师表
  764. UnitOfWork.Commit();
  765. }
  766. catch (Exception)
  767. {
  768. throw;
  769. }
  770. }
  771. public bool EditStudent(SelectCourseResultView selectCourseResult, IList<StudentsView> studentList)
  772. {
  773. try
  774. {
  775. var executableOptionalCourse = OptionalCourseSettingDAL.ExecutableOptionalCourseRepository.GetList(x => x.ExecutableOptionalCourseID == selectCourseResult.ID,
  776. (x => x.CF_Student)
  777. ).FirstOrDefault();
  778. var executableFreeSelectionCouse = OptionalCourseSettingDAL.ExecutableFreeSelectionCouseRepository.GetList(x => x.ExecutableFreeSelectionCouseID == selectCourseResult.ID,
  779. (x => x.CF_Student)
  780. ).FirstOrDefault();
  781. var ids = studentList.Select(x => x.UserID).ToList();
  782. var list = SelectCourseResultDAL.StudentRepository.GetList(x => ids.Contains(x.UserID));
  783. if (executableOptionalCourse != null)
  784. {
  785. if (executableOptionalCourse.RecordStatus == (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Created)
  786. throw new Exception("已生成教学任务班,不能修改学生");
  787. executableOptionalCourse.CF_Student = new HashSet<CF_Student>();
  788. //UnitOfWork.Delete(executableFreeSelectionCouse, (x => x.CF_Student));
  789. foreach (var student in list)
  790. {
  791. executableOptionalCourse.CF_Student.Add(student);
  792. }
  793. //UnitOfWork.Update<EM_ExecutableFreeSelectionCouse>(executableFreeSelectionCouse);
  794. }
  795. else if (executableFreeSelectionCouse != null)
  796. {
  797. if (executableFreeSelectionCouse.RecordStatus == (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Created)
  798. throw new Exception("已生成教学任务班,不能修改学生");
  799. executableFreeSelectionCouse.CF_Student = new HashSet<CF_Student>();
  800. foreach (var student in list)
  801. {
  802. executableFreeSelectionCouse.CF_Student.Add(student);
  803. }
  804. //UnitOfWork.Update<EM_ExecutableFreeSelectionCouse>(executableFreeSelectionCouse);
  805. }
  806. UnitOfWork.Commit();
  807. return true;
  808. }
  809. catch (Exception)
  810. {
  811. throw;
  812. }
  813. }
  814. /// <summary>
  815. /// 更新
  816. /// </summary>
  817. /// <param name="optionalCourseSettingView"></param>
  818. /// <returns></returns>
  819. public void OptionalCourseSettingUpdate(OptionalCourseSettingView optionalCourseSettingView, IList<OptionalCourseTeacherListView> teacherList)
  820. {
  821. try
  822. {
  823. //删除教师
  824. UnitOfWork.Delete<EM_ExecutableOptionalCourseTeacher>(x => x.ExecutableOptionalCourseID == optionalCourseSettingView.ExecutableOptionalCourseID);
  825. //添加教师
  826. if (teacherList.Count > 0)
  827. {
  828. foreach (var teacher in teacherList)
  829. {
  830. EM_ExecutableOptionalCourseTeacher executableOptionalCourseTeacher = new EM_ExecutableOptionalCourseTeacher();
  831. executableOptionalCourseTeacher.ExecutableOptionalCourseTeacherID = Guid.NewGuid();
  832. executableOptionalCourseTeacher.ExecutableOptionalCourseID = optionalCourseSettingView.ExecutableOptionalCourseID;
  833. executableOptionalCourseTeacher.UserID = teacher.UserID;
  834. executableOptionalCourseTeacher.TeachingMethod = teacher.TeachingMethod;
  835. SetNewStatus(executableOptionalCourseTeacher);
  836. UnitOfWork.Add(executableOptionalCourseTeacher);
  837. }
  838. UnitOfWork.Commit();
  839. }
  840. }
  841. catch (Exception)
  842. {
  843. throw;
  844. }
  845. }
  846. /// <summary>
  847. /// 获取教学任务授课老师
  848. /// </summary>
  849. /// <param name="educationMissionClassID"></param>
  850. /// <returns></returns>
  851. public List<EMIS.ViewModel.SelectCourse.OptionalCourseTeacherListView> GetTeacherList(Guid? ID, string Type)
  852. {
  853. if (Type == "0")
  854. return OptionalCourseSettingDAL.GetTeacherList().Where(x => x.ID == ID).OrderBy(x => x.TeachingMethod).ToList();
  855. else
  856. return OptionalCourseSettingDAL.GetTeacherList1().Where(x => x.ID == ID).OrderBy(x => x.TeachingMethod).ToList();
  857. }
  858. public EM_ExecutableFreeSelectionCouse GetExecutableFreeSelectionCouseEntity(Guid? executableOptionalCourseID)
  859. {
  860. return SelectCourseResultDAL.ExecutableFreeSelectionCouseRepository.GetSingle(x => x.ExecutableFreeSelectionCouseID == executableOptionalCourseID);
  861. }
  862. /// <summary>
  863. /// 选课结果人数是否达到下限
  864. /// </summary>
  865. /// <param name="IDs"></param>
  866. /// <returns></returns>
  867. public bool CheckEnouthNum(IList<Guid?> IDs)
  868. {
  869. var query = SelectCourseResultDAL.GetCheckEnouthNumSelectCourseResult(IDs).Where(x => x.StudentTotalNum < x.PeopleNumlower);
  870. if (query.ToList().Count > 0)
  871. return true;
  872. else
  873. return false;
  874. }
  875. /// <summary>
  876. /// 选课结果判断是否有教师、教室
  877. /// </summary>
  878. /// <param name="IDs"></param>
  879. /// <returns></returns>
  880. //public bool CheckHaveTeacherOrClassroom(IList<Guid?> IDs)
  881. //{
  882. // var query = SelectCourseResultDAL
  883. // if (query.ToList().Count > 0)
  884. // return true;
  885. // else
  886. // return false;
  887. //}
  888. }
  889. }