RetakePlanResultServices.cs 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using Bowin.Common.Linq.Entity;
  7. using Bowin.Common.Linq;
  8. using EMIS.DataLogic.RetakeManage;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.RetakeManage;
  12. using EMIS.Utility;
  13. using EMIS.CommonLogic.SystemServices;
  14. using EMIS.ViewModel.EducationManage;
  15. using EMIS.DataLogic.EducationManage;
  16. using EMIS.CommonLogic.EducationSchedule;
  17. using EMIS.DataLogic.SystemSetting;
  18. using EMIS.CommonLogic.RetakeManage.General;
  19. using EMIS.CommonLogic.StudentManage.StudentStatistics;
  20. namespace EMIS.CommonLogic.RetakeManage.General
  21. {
  22. public class RetakePlanResultServices : BaseServices, IRetakePlanResultServices
  23. {
  24. public RetakePlanResultDAL RetakePlanResultDAL { get; set; }
  25. public EducationMissionClassDAL educationMissionClassDAL { get; set; }
  26. public RetakePlanTaskDAL RetakePlanTaskDAL { get; set; }
  27. public IInSchoolSettingServices InSchoolSettingServices { get; set; }
  28. public IRetakePlanStudentApplyServices IRetakePlanStudentApplyServices { get; set; }
  29. /// <summary>
  30. /// 查询重修班级信息View(统计已报人数)
  31. /// </summary>
  32. /// <param name="configuretView"></param>
  33. /// <param name="schoolyearID"></param>
  34. /// <param name="collegeID"></param>
  35. /// <param name="departmentID"></param>
  36. /// <param name="coursematerialID"></param>
  37. /// <param name="retakeTypeID"></param>
  38. /// <param name="pageIndex"></param>
  39. /// <param name="pageSize"></param>
  40. /// <returns></returns>
  41. public IGridResultSet<RetakePlanTaskView> GetRetakePlanResultTaskView(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID,
  42. Guid? departmentID, Guid? coursematerialID, int? retakeTypeID, int? statusID, int pageIndex, int pageSize)
  43. {
  44. //重修计划
  45. Expression<Func<ER_RetakePlan, bool>> expRetakePlan = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  46. //排除重修任务状态为未开放状态的信息
  47. expRetakePlan = expRetakePlan.And(x => x.RecordStatus != (int)ER_RetakePlanStatus.NotOpened);
  48. if (schoolyearID.HasValue)
  49. {
  50. //重修学年学期
  51. expRetakePlan = expRetakePlan.And(x => x.SchoolyearID == schoolyearID);
  52. }
  53. if (coursematerialID.HasValue)
  54. {
  55. //课程信息
  56. expRetakePlan = expRetakePlan.And(x => x.CoursematerialID == coursematerialID);
  57. }
  58. if (retakeTypeID.HasValue)
  59. {
  60. //重修类型
  61. expRetakePlan = expRetakePlan.And(x => x.RetakeTypeID == retakeTypeID);
  62. }
  63. if (statusID.HasValue)
  64. {
  65. //重修任务状态
  66. expRetakePlan = expRetakePlan.And(x => x.RecordStatus == statusID);
  67. }
  68. //查询对应的重修班级信息View
  69. var query = RetakePlanResultDAL.GetRetakePlanResultTaskView(expRetakePlan);
  70. if (collegeID.HasValue)
  71. {
  72. //开课院系所
  73. query = query.Where(x => x.CourseCollegeID == collegeID);
  74. }
  75. if (departmentID.HasValue)
  76. {
  77. //开课教研室
  78. query = query.Where(x => x.DepartmentID == departmentID);
  79. }
  80. //查询条件()
  81. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  82. {
  83. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  84. }
  85. var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SchoolyearCode.Length)
  86. .ThenBy(x => x.SchoolyearCode).ThenBy(x => x.DepartmentCode.Length)
  87. .ThenBy(x => x.DepartmentCode).ThenBy(x => x.RetakeTypeID)
  88. .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
  89. .ThenBy(x => x.CourseTypeID).ThenBy(x => x.ClassName)
  90. .ToGridResultSet<RetakePlanTaskView>(pageIndex, pageSize);
  91. //查询对应的重修计划IDList
  92. var retakePlanIDList = query.Select(x => x.RetakePlanID).ToList();
  93. //查询对应的课程表信息
  94. var schedulingList = RetakePlanTaskDAL.GetSchedulingView(x => retakePlanIDList.Contains(x.RetakePlanID.Value)).ToList();
  95. //查询合并显示的课程表信息
  96. var weekdayTimesList = IRetakePlanStudentApplyServices.GetWeekdayTimesSegmentName(schedulingList);
  97. result.rows.ForEach(x =>
  98. {
  99. var list = weekdayTimesList.Where(w => w.ID == x.RetakePlanID);
  100. x.WeekdayTimesSegmentName = string.Join(";", list.OrderBy(w => w.Weekday).Select(w => w.WeekdayTimesSegmentName));
  101. x.ClassroomName = schedulingList.Where(w => w.ID == x.RetakePlanID).Select(w => w.ClassroomName).FirstOrDefault();
  102. });
  103. //查询合并显示的任课老师信息
  104. var teacherList = RetakePlanResultDAL.GetRetakePlanTeacherView(x => retakePlanIDList.Contains(x.RetakePlanID));
  105. result.rows.ForEach(x =>
  106. x.TeacherName = string.Join(",", teacherList.Where(w => w.RetakePlanID == x.RetakePlanID).Select(w => w.TeacherName)));
  107. return result;
  108. }
  109. /// <summary>
  110. /// 查询重修班级信息List(统计已报人数)
  111. /// </summary>
  112. /// <param name="configuretView"></param>
  113. /// <param name="schoolyearID"></param>
  114. /// <param name="collegeID"></param>
  115. /// <param name="departmentID"></param>
  116. /// <param name="coursematerialID"></param>
  117. /// <param name="retakeTypeID"></param>
  118. /// <returns></returns>
  119. public List<RetakePlanTaskView> GetRetakePlanResultTaskViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID,
  120. Guid? departmentID, Guid? coursematerialID, int? retakeTypeID, int? statusID)
  121. {
  122. //重修计划
  123. Expression<Func<ER_RetakePlan, bool>> expRetakePlan = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  124. //排除重修任务状态为未开放状态的信息
  125. expRetakePlan = expRetakePlan.And(x => x.RecordStatus != (int)ER_RetakePlanStatus.NotOpened);
  126. if (schoolyearID.HasValue)
  127. {
  128. //重修学年学期
  129. expRetakePlan = expRetakePlan.And(x => x.SchoolyearID == schoolyearID);
  130. }
  131. if (coursematerialID.HasValue)
  132. {
  133. //课程信息
  134. expRetakePlan = expRetakePlan.And(x => x.CoursematerialID == coursematerialID);
  135. }
  136. if (retakeTypeID.HasValue)
  137. {
  138. //重修类型
  139. expRetakePlan = expRetakePlan.And(x => x.RetakeTypeID == retakeTypeID);
  140. }
  141. if (statusID.HasValue)
  142. {
  143. //重修任务状态
  144. expRetakePlan = expRetakePlan.And(x => x.RecordStatus == statusID);
  145. }
  146. //查询对应的重修班级信息View
  147. var query = RetakePlanResultDAL.GetRetakePlanResultTaskView(expRetakePlan);
  148. if (collegeID.HasValue)
  149. {
  150. //开课院系所
  151. query = query.Where(x => x.CourseCollegeID == collegeID);
  152. }
  153. if (departmentID.HasValue)
  154. {
  155. //开课教研室
  156. query = query.Where(x => x.DepartmentID == departmentID);
  157. }
  158. //查询条件()
  159. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  160. {
  161. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  162. }
  163. var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SchoolyearCode.Length)
  164. .ThenBy(x => x.SchoolyearCode).ThenBy(x => x.DepartmentCode.Length)
  165. .ThenBy(x => x.DepartmentCode).ThenBy(x => x.RetakeTypeID)
  166. .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
  167. .ThenBy(x => x.CourseTypeID).ThenBy(x => x.ClassName)
  168. .ToList();
  169. //查询对应的重修计划IDList
  170. var retakePlanIDList = query.Select(x => x.RetakePlanID).ToList();
  171. //查询对应的课程表信息
  172. var schedulingList = RetakePlanTaskDAL.GetSchedulingView(x => retakePlanIDList.Contains(x.RetakePlanID.Value)).ToList();
  173. //查询合并显示的课程表信息
  174. var weekdayTimesList = IRetakePlanStudentApplyServices.GetWeekdayTimesSegmentName(schedulingList);
  175. result.ForEach(x =>
  176. {
  177. var list = weekdayTimesList.Where(w => w.ID == x.RetakePlanID);
  178. x.WeekdayTimesSegmentName = string.Join(";", list.OrderBy(w => w.Weekday).Select(w => w.WeekdayTimesSegmentName));
  179. x.ClassroomName = schedulingList.Where(w => w.ID == x.RetakePlanID).Select(w => w.ClassroomName).FirstOrDefault();
  180. });
  181. //查询合并显示的任课老师信息
  182. var teacherList = RetakePlanResultDAL.GetRetakePlanTeacherView(x => retakePlanIDList.Contains(x.RetakePlanID));
  183. result.ForEach(x =>
  184. x.TeacherName = string.Join(",", teacherList.Where(w => w.RetakePlanID == x.RetakePlanID).Select(w => w.TeacherName)));
  185. return result;
  186. }
  187. /// <summary>
  188. /// 查询对应的重修班级报名名单信息
  189. /// </summary>
  190. /// <param name="retakePlanID"></param>
  191. /// <param name="pageIndex"></param>
  192. /// <param name="pageSize"></param>
  193. /// <returns></returns>
  194. public IGridResultSet<RetakeStudentListView> GetRetakePlanResultTaskStudentView(Guid? retakePlanID, int pageIndex, int pageSize)
  195. {
  196. var query = RetakePlanResultDAL.GetRetakePlanResultView(x => x.RetakePlanID == retakePlanID)
  197. .OrderBy(x => x.LoginID);
  198. return query.ToGridResultSet(pageIndex, pageSize);
  199. }
  200. /// <summary>
  201. /// 查询对应的重修班级报名名单信息List
  202. /// </summary>
  203. /// <param name="configuretView"></param>
  204. /// <param name="retakePlanID"></param>
  205. /// <returns></returns>
  206. public List<RetakeStudentListView> GetRetakePlanResultTaskStudentViewList(ConfiguretView configuretView, Guid? retakePlanID)
  207. {
  208. var query = RetakePlanResultDAL.GetRetakePlanResultView(x => x.RetakePlanID == retakePlanID)
  209. .OrderBy(x => x.LoginID);
  210. return query.ToList();
  211. }
  212. /// <summary>
  213. /// 查询对应的重修班级未报名名单列表(未报名名单)
  214. /// </summary>
  215. /// <param name="configuretView"></param>
  216. /// <param name="retakePlanID"></param>
  217. /// <param name="gradeYearID"></param>
  218. /// <param name="standardID"></param>
  219. /// <param name="classmajorID"></param>
  220. /// <param name="inSchoolStatus"></param>
  221. /// <param name="pageIndex"></param>
  222. /// <param name="pageSize"></param>
  223. /// <returns></returns>
  224. public IGridResultSet<RetakeStudentListView> GetStudentView(ConfiguretView configuretView, Guid? retakePlanID,
  225. int? gradeYearID, int? standardID, Guid? classmajorID, int? inSchoolStatus, int pageIndex, int pageSize)
  226. {
  227. //查询对应的重修计划信息
  228. var retakePlanView = RetakePlanResultDAL.RetakePlanRepository.Entities
  229. .Where(x => x.RetakePlanID == retakePlanID).SingleOrDefault();
  230. if (retakePlanView == null)
  231. {
  232. throw new Exception("数据有误,请核查。");
  233. }
  234. //查询对应的重修班级未报名名单
  235. var query = RetakePlanResultDAL.GetRetakePlanResultTaskStudentView(x => x.RetakePlanID == retakePlanID);
  236. if (gradeYearID.HasValue)
  237. {
  238. query = query.Where(x => x.Gradeyear == gradeYearID);
  239. }
  240. if (standardID.HasValue)
  241. {
  242. query = query.Where(x => x.StandardID == standardID);
  243. }
  244. if (classmajorID.HasValue)
  245. {
  246. query = query.Where(x => x.ClassmajorID == classmajorID);
  247. }
  248. if (inSchoolStatus != null && inSchoolStatus > -1)
  249. {
  250. //在校状态
  251. var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
  252. if (inSchoolStatus == 1)
  253. {
  254. //表示在校
  255. query = query.Where(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  256. }
  257. if (inSchoolStatus == 0)
  258. {
  259. //不在校
  260. query = query.Where(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  261. }
  262. }
  263. //查询条件
  264. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  265. {
  266. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  267. }
  268. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.LoginID.Length)
  269. .ThenBy(x => x.LoginID)
  270. .ToGridResultSet<RetakeStudentListView>(pageIndex, pageSize);
  271. }
  272. /// <summary>
  273. /// 重修班级报名名单报名(从计划人数中选择)
  274. /// 由于存在多个相对应的重修计划,需要判断报名情况
  275. /// </summary>
  276. /// <param name="retakePlanID"></param>
  277. /// <param name="UserIDs"></param>
  278. /// <returns></returns>
  279. public string AddStudent(Guid? retakePlanID, string UserIDs)
  280. {
  281. try
  282. {
  283. int success = 0; //成功
  284. int fail = 0; //失败
  285. string tipMessage = null; //提示消息
  286. List<Guid?> userIDslist = UserIDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
  287. .Select(x => (Guid?)new Guid(x)).ToList();
  288. //查询对应的学生信息View
  289. var studentViewList = RetakePlanResultDAL.StudentRepository
  290. .GetList(x => userIDslist.Contains(x.UserID)).ToList();
  291. //查询对应的重修计划信息View
  292. var retakePlanView = RetakePlanResultDAL.RetakePlanRepository
  293. .GetList(x => x.RetakePlanID == retakePlanID, (x => x.ER_RetakePlanSetting), (x => x.CF_Student)).FirstOrDefault();
  294. if (retakePlanView == null)
  295. {
  296. throw new Exception("数据有误,请核查");
  297. }
  298. if (retakePlanView.RecordStatus == (int)EMIS.ViewModel.ER_RetakePlanStatus.Generated)
  299. {
  300. throw new Exception("不能对已开班状态的信息进行报名。");
  301. }
  302. //对人数上限进行判断
  303. if (retakePlanView.PeopleNumlimit != null && retakePlanView.PeopleNumlimit != 0
  304. && (retakePlanView.CF_Student.Count() + userIDslist.Count()) > retakePlanView.PeopleNumlimit.Value)
  305. {
  306. throw new Exception("报名人数已达上限。");
  307. }
  308. //重修计划
  309. Expression<Func<ER_RetakePlan, bool>> expRetakePlan = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  310. if (retakePlanView.CoursematerialID.HasValue)
  311. {
  312. //课程信息
  313. expRetakePlan = expRetakePlan.And(x => x.CoursematerialID == retakePlanView.CoursematerialID);
  314. }
  315. if (retakePlanView.RetakeTypeID.HasValue)
  316. {
  317. //重修类型
  318. expRetakePlan = expRetakePlan.And(x => x.RetakeTypeID == retakePlanView.RetakeTypeID);
  319. }
  320. if (retakePlanView.SchoolyearID.HasValue)
  321. {
  322. //重修学年学期
  323. expRetakePlan = expRetakePlan.And(x => x.SchoolyearID == retakePlanView.SchoolyearID);
  324. }
  325. if (retakePlanView.CourseTypeID.HasValue)
  326. {
  327. //课程类型
  328. expRetakePlan = expRetakePlan.And(x => x.CourseTypeID == retakePlanView.CourseTypeID);
  329. }
  330. if (retakePlanView.Credit.HasValue)
  331. {
  332. //课程学分
  333. expRetakePlan = expRetakePlan.And(x => x.Credit == retakePlanView.Credit);
  334. }
  335. //查询对应的重修计划信息View
  336. var newRetakePlanViewList = RetakePlanResultDAL.GetRetakePlanResultTaskView(expRetakePlan);
  337. var newRetakePlanIDList = newRetakePlanViewList.Where(x => x.DepartmentID == retakePlanView.ER_RetakePlanSetting.DepartmentID).Select(x => x.RetakePlanID).ToList();
  338. //查询对应的重修报名信息List
  339. var retakePlanStudentApplyList = RetakePlanResultDAL.RetakePlanStudentRepository
  340. .GetList(x => newRetakePlanIDList.Contains(x.RetakePlanID),
  341. (x => x.ER_RetakePlan),
  342. (x => x.ER_RetakePlan.CF_Student))
  343. .Where(x => x.ER_RetakePlan.CF_Student.Any(w => w.UserID == x.UserID))
  344. .ToList();
  345. //if (retakePlanStudentApplyList.Count() > 0)
  346. //{
  347. // throw new Exception("存在对应的已报名重修计划名单。");
  348. //}
  349. //判断重修计划的报名情况
  350. foreach (var studentView in studentViewList)
  351. {
  352. //查询对应的学生重修报名信息
  353. var retakePlanStudentApply = retakePlanStudentApplyList
  354. .Where(x => x.UserID == studentView.UserID).ToList();
  355. if (retakePlanStudentApply.Count() <= 0)
  356. {
  357. //表示可报名
  358. //目前缺少排课冲突的判断(暂时不考虑)
  359. //重修报名
  360. retakePlanView.CF_Student.Add(studentView);
  361. success++;
  362. }
  363. else
  364. {
  365. //表示已存在报名名单
  366. fail++;
  367. }
  368. }
  369. UnitOfWork.Commit();
  370. if (success > 0 && fail <= 0)
  371. {
  372. tipMessage = success + "个";
  373. }
  374. else
  375. {
  376. tipMessage = success + "个," + fail + "个失败,原因:已存在相应的报名信息,请检查";
  377. }
  378. return tipMessage;
  379. }
  380. catch (Exception ex)
  381. {
  382. throw new Exception(ex.Message);
  383. }
  384. }
  385. /// <summary>
  386. /// 删除(重修报名名单删除,取消报名)
  387. /// </summary>
  388. /// <param name="retakePlanID"></param>
  389. /// <param name="UserIDs"></param>
  390. public void DeleteStudent(Guid? retakePlanID, string UserIDs)
  391. {
  392. try
  393. {
  394. List<Guid?> userIDslist = UserIDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
  395. .Select(x => (Guid?)new Guid(x)).ToList();
  396. //查询对应的重修计划信息
  397. var retakePlanView = RetakePlanResultDAL.RetakePlanRepository
  398. .GetList(x => x.RetakePlanID == retakePlanID, x => x.CF_Student).FirstOrDefault();
  399. if (retakePlanView == null)
  400. {
  401. throw new Exception("数据有误,请核查。");
  402. }
  403. if (retakePlanView.RecordStatus == (int)EMIS.ViewModel.ER_RetakePlanStatus.Generated)
  404. {
  405. throw new Exception("不能对已开班状态的信息取消报名。");
  406. }
  407. //重修报名表
  408. retakePlanView.CF_Student.RemoveWhere(x => userIDslist.Contains(x.UserID));
  409. UnitOfWork.Commit();
  410. }
  411. catch (Exception ex)
  412. {
  413. throw new Exception(ex.Message);
  414. }
  415. }
  416. /// <summary>
  417. /// 开班(重修计划)
  418. /// </summary>
  419. /// <param name="RetakePlanIDs"></param>
  420. /// <returns></returns>
  421. public string RetakePlanResultGenerate(string RetakePlanIDs)
  422. {
  423. try
  424. {
  425. int success = 0; //成功
  426. int fail = 0; //失败
  427. string tipMessage = null; //提示消息
  428. List<Guid?> RetakePlanIDslist = RetakePlanIDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
  429. .Select(x => (Guid?)new Guid(x)).ToList();
  430. //查询对应的重修计划信息
  431. var retakePlanList = RetakePlanResultDAL.RetakePlanRepository
  432. .GetList(x => RetakePlanIDslist.Contains(x.RetakePlanID),
  433. x => x.CF_Student,
  434. x => x.EM_Coursematerial,
  435. x => x.EM_Coursematerial.EM_ClassGrouping.EM_ClassGroupingSettings,
  436. x => x.ER_RetakePlanSetting,
  437. x => x.ER_RetakePlanSetting.ER_RetakePlanTeachingModeType,
  438. x => x.ER_RetakePlanSetting.ER_RetakePlanTeachingPlace,
  439. x => x.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting,
  440. x => x.ER_RetakePlanStudent,
  441. x => x.ER_RetakePlanTeacher,
  442. x => x.ER_RetakePlanSettingScheduling
  443. ).ToList();
  444. var noSchedulingList = retakePlanList.Where(x => x.ER_RetakePlanSettingScheduling.Count() == 0).FirstOrDefault();
  445. if (noSchedulingList != null)
  446. {
  447. throw new Exception(noSchedulingList.ClassName + ",缺少排课信息,不能开班");
  448. }
  449. var noClassRoomList = retakePlanList.Where(x => x.ER_RetakePlanSettingScheduling.Any(w => w.ClassroomID == null)).FirstOrDefault();
  450. if (noClassRoomList != null)
  451. {
  452. throw new Exception(noClassRoomList.ClassName + ",未设置上课教室,不能开班");
  453. }
  454. var DepartmentIDsList = retakePlanList.Select(x => x.ER_RetakePlanSetting.DepartmentID).Distinct().ToList();
  455. var CollegeDepartmentList = RetakePlanResultDAL.DepartmentRepository.GetList(x => DepartmentIDsList.Contains(x.DepartmentID));
  456. var RetakeGenerateList = retakePlanList.Where(x => x.RecordStatus == (int)EMIS.ViewModel.ER_RetakePlanStatus.Generated).ToList();
  457. if (RetakeGenerateList.Count > 0)
  458. {
  459. throw new Exception("已开班状态的重修计划不能进行开班,请核查。");
  460. }
  461. string coursematerialName = "";
  462. var courseNames = retakePlanList.Where(x => x.EM_Coursematerial != null && x.EM_Coursematerial.EM_ClassGrouping == null).Select(x => x.EM_Coursematerial.CourseName).Distinct().ToArray();
  463. coursematerialName = string.Join(",", courseNames);
  464. if (courseNames.Length > 0)
  465. {
  466. throw new Exception("以下重修所对应的课程并未设置上课类型,无法确定任务班的分班方式,请到课程资料菜单完成设置后再次进行提交:\r\n" + coursematerialName);
  467. }
  468. List<string> message = new List<string>();
  469. //var PassRetakeList = RetakeList;
  470. List<ER_RetakePlan> RemoveList = new List<ER_RetakePlan>();
  471. //验证必填项
  472. #region
  473. for (int i = 0; i < retakePlanList.Count; i++)
  474. //foreach (var Retake in PassRetakeList)
  475. {
  476. var Retake = retakePlanList[i];
  477. if (Retake.ER_RetakePlanSetting.DepartmentID == null)
  478. {
  479. message.Add("教研室、");
  480. //message += ;
  481. //RemoveList.Add(Retake);//PassRetakeList.Remove(Retake);
  482. RemoveList.Add(Retake);
  483. }
  484. if (Retake.ER_RetakePlanSetting.CourseCategoryID == null)
  485. {
  486. message.Add("课程属性、");
  487. //message += ;
  488. //RemoveList.Add(Retake);//PassRetakeList.Remove(Retake);
  489. RemoveList.Add(Retake);
  490. }
  491. if (Retake.ER_RetakePlanSetting.CourseQualityID == null)
  492. {
  493. message.Add("课程性质、");
  494. //message += ;
  495. RemoveList.Add(Retake);//RemoveList.Add(Retake);//PassRetakeList.Remove(Retake);
  496. }
  497. if (Retake.CourseTypeID == null)
  498. {
  499. message.Add("课程类型、");
  500. //message += ;
  501. RemoveList.Add(Retake);//PassRetakeList.Remove(Retake);
  502. }
  503. if (Retake.ER_RetakePlanSetting.ExaminationModeID == null)
  504. {
  505. message.Add("考试方式、");
  506. //message += ;
  507. RemoveList.Add(Retake);//PassRetakeList.Remove(Retake);
  508. }
  509. if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting != null)
  510. {
  511. if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting.TheoryCourse == null)
  512. {
  513. message.Add("理论学时、");
  514. //message += ;
  515. RemoveList.Add(Retake);//PassRetakeList.Remove(Retake);
  516. }
  517. if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting.Trialhours == null)
  518. {
  519. message.Add("实验学时、");
  520. //message += ;
  521. RemoveList.Add(Retake);//PassRetakeList.Remove(Retake);
  522. }
  523. if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting.WeeklyNum == null)
  524. {
  525. message.Add("每周次数、");
  526. //message += ;
  527. RemoveList.Add(Retake);//PassRetakeList.Remove(Retake);
  528. }
  529. if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting.TheoryWeeklyNum == null)
  530. {
  531. message.Add("理论周数、");
  532. //message += ;
  533. RemoveList.Add(Retake);//PassRetakeList.Remove(Retake);
  534. }
  535. if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting.TrialWeeklyNum == null)
  536. {
  537. message.Add("实验周数、");
  538. //message += "实验周数、";
  539. RemoveList.Add(Retake);//PassRetakeList.Remove(Retake);
  540. }
  541. if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting.StartWeeklyNum == null)
  542. {
  543. message.Add("开始周次、");
  544. //message += ;
  545. RemoveList.Add(Retake);//PassRetakeList.Remove(Retake);
  546. }
  547. if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting.EndWeeklyNum == null)
  548. {
  549. message.Add("结束周次、");
  550. //message += ;
  551. RemoveList.Add(Retake);//PassRetakeList.Remove(Retake);
  552. }
  553. if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting.WeeklyHours == null)
  554. {
  555. message.Add("周学时、");
  556. //message += ;
  557. RemoveList.Add(Retake);//PassRetakeList.Remove(Retake);
  558. }
  559. }
  560. else
  561. {
  562. message.Add("教学设置、");
  563. //message += ;
  564. RemoveList.Add(Retake);//PassRetakeList.Remove(Retake);
  565. }
  566. if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingModeType.Count == 0 || !Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingModeType.Any(w => w.TeachingModeID != null))
  567. {
  568. message.Add("授课方式、");
  569. //message += ;
  570. RemoveList.Add(Retake);//PassRetakeList.Remove(Retake);
  571. }
  572. //if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingPlace.Count == 0 || !Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingPlace.Any(w => w.TeachingPlace != null))
  573. //{
  574. // message += "授课地点、";
  575. // RemoveList.Add(Retake);//PassRetakeList.Remove(Retake);
  576. //}
  577. if (Retake.CF_Student.Count == 0)
  578. {
  579. message.Add("报名学生、");
  580. //message += ;
  581. RemoveList.Add(Retake);//PassRetakeList.Remove(Retake);
  582. }
  583. if (Retake.EM_Coursematerial != null && Retake.EM_Coursematerial.EM_ClassGrouping == null)
  584. {
  585. RemoveList.Add(Retake);//PassRetakeList.Remove(Retake);
  586. }
  587. }
  588. RemoveList = RemoveList.Distinct().ToList();
  589. retakePlanList.RemoveAll(x => RemoveList.Contains(x));
  590. //message = message.Length > 0 ? message.Remove(message.Length - 1) : message;
  591. string result = "";
  592. message.Distinct().ToList().ForEach(x => result += x);
  593. result = result.Length > 0 ? result.Remove(result.Length - 1) : result;
  594. #endregion
  595. ////判断是否有设置授课方式
  596. //var noTeachingModeTypeList = RetakeList.Where(x => x.ER_RetakePlanSetting.ER_RetakePlanTeachingModeType.Count == 0)
  597. // .Concat(RetakeList.Where(x => !x.ER_RetakePlanSetting.ER_RetakePlanTeachingModeType.Any(w => w.TeachingModeID != null))).ToList();
  598. //if (noTeachingModeTypeList.Count > 0)
  599. //{
  600. // throw new Exception("没有设置授课方式的计划不能提交,请核查。");
  601. //}
  602. var resultMissionList = new List<EM_EducationMission>(); //教学任务
  603. var resultMissionClassList = new List<EM_EducationMissionClass>(); //教学任务班
  604. var resultMissionClassTeachingSettingList = new List<EM_EducationMissionClassTeachingSetting>();
  605. var resultEducationSchedulingClassList = new List<EM_EducationSchedulingClass>(); //排课班表
  606. var resultTeacherList = new List<EM_MissionClassTeacher>(); //教学任务班任课老师表
  607. var resultEducationSchedulingList = new List<ES_EducationScheduling>(); //排课课表
  608. var resultEducationSchedulingTeacherList = new List<ES_EducationSchedulingTeacher>(); //排课老师表
  609. var resultEducationSchedulingWeekNumList = new List<ES_EducationSchedulingWeekNum>(); //排课周次表
  610. var resultCourseProcessList = new List<EM_CourseProcess>(); //课程进度
  611. var resultCourseProcessTeacherList = new List<EM_CourseProcessTeacher>(); //课程进度任课老师表
  612. var resultEducationMissionClassSettingsList = new List<EM_EducationMissionClassSettings>(); //任务班设置表
  613. var query = (
  614. from efsc in
  615. (
  616. //先找出上课类型没有设置的授课方式,然后单独成一个班
  617. (from efsc in retakePlanList
  618. where efsc.ER_RetakePlanSetting.ER_RetakePlanTeachingModeType
  619. .Any(x => !efsc.EM_Coursematerial
  620. .EM_ClassGrouping
  621. .EM_ClassGroupingSettings.Select(w => w.TeachingModeID).Contains(x.TeachingModeID))
  622. select new
  623. {
  624. RetakePlan = efsc,
  625. TeachingMode = efsc.ER_RetakePlanSetting.ER_RetakePlanTeachingModeType
  626. .FirstOrDefault(x => !efsc.EM_Coursematerial
  627. .EM_ClassGrouping
  628. .EM_ClassGroupingSettings.Select(w => w.TeachingModeID).Contains(x.TeachingModeID))
  629. .TeachingModeID
  630. })
  631. //接下来对除理论班之外的其他分班设置进行匹配,如果该专业课程有这个授课方式的话,就单独再分一个班
  632. .Concat(
  633. from efsc in retakePlanList
  634. from tmt in efsc.ER_RetakePlanSetting.ER_RetakePlanTeachingModeType
  635. from cgs in efsc.EM_Coursematerial.EM_ClassGrouping.EM_ClassGroupingSettings
  636. where tmt.TeachingModeID == cgs.TeachingModeID
  637. select new
  638. {
  639. RetakePlan = efsc,
  640. TeachingMode = cgs.TeachingModeID
  641. }))
  642. join co in RetakePlanResultDAL.DepartmentRepository.Entities on efsc.RetakePlan.ER_RetakePlanSetting.DepartmentID equals co.DepartmentID
  643. join dtm in DictionaryHelper.GetDictionaryValue(ViewModel.DictionaryItem.CF_TeachingMode) on efsc.TeachingMode equals dtm.Value
  644. group dtm by new
  645. {
  646. RetakePlan = efsc.RetakePlan,
  647. CollegeID = co.CollegeID
  648. } into g
  649. select new
  650. {
  651. collegeID = g.Key.CollegeID,
  652. RetakePlan = g.Key.RetakePlan,
  653. TeachingSetting = g.Key.RetakePlan.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting,
  654. TeachingMode = g.Select(x => x).ToList(),
  655. Teacher = g.Key.RetakePlan.ER_RetakePlanTeacher,
  656. Scheduling = g.Key.RetakePlan.ER_RetakePlanSettingScheduling,
  657. Student = g.Key.RetakePlan.CF_Student, //选此课的学生
  658. RetakePlanStudent = g.Key.RetakePlan.ER_RetakePlanStudent
  659. }
  660. );
  661. var missionDataList = query.ToList();
  662. for (int i = 0; i < missionDataList.Count; i++)
  663. {
  664. var mission = missionDataList[i];
  665. EM_EducationMission educationMission = new EM_EducationMission();
  666. educationMission.EducationMissionID = Guid.NewGuid();
  667. educationMission.ClassName = mission.RetakePlan.ClassName;
  668. educationMission.DepartmentID = mission.RetakePlan.ER_RetakePlanSetting.DepartmentID;
  669. educationMission.SchoolyearID = mission.RetakePlan.SchoolyearID;
  670. educationMission.CollegeID = mission.collegeID;//CollegeDepartmentList.FirstOrDefault(x => x.DepartmentID == mission.RetakePlan.ER_RetakePlanSetting.DepartmentID.Value).CollegeID;
  671. SetNewStatus(educationMission);
  672. //educationMission.CF_Classmajor.Add(mission.Classmajor);
  673. resultMissionList.Add(educationMission);
  674. foreach (var tm in mission.TeachingMode)
  675. {
  676. var Scheduling = mission.RetakePlan.ER_RetakePlanSettingScheduling.FirstOrDefault();
  677. EM_EducationMissionClass educationMissionClass = new EM_EducationMissionClass();
  678. educationMissionClass.EducationMissionClassID = Guid.NewGuid();
  679. educationMissionClass.OrderNo = 0;
  680. educationMissionClass.EducationMissionID = educationMission.EducationMissionID;
  681. educationMissionClass.Name = mission.RetakePlan.ClassName;
  682. //educationMissionClass.Name = mission.Classmajor.Name + "-" + mission.ExecutablePlan.EM_FreeSelectionCouse.EM_Coursematerial.CourseName;
  683. educationMissionClass.TeachingModeID = tm.Value;
  684. if (mission.TeachingMode.Count > 0)
  685. {
  686. educationMissionClass.Name += "【" + tm.Name + "】";
  687. }
  688. //重修默认为必修
  689. educationMissionClass.OptionalCourseTypeID = (int)CF_CourseSelectType.Required;
  690. educationMissionClass.CoursematerialID = mission.RetakePlan.CoursematerialID;
  691. educationMissionClass.CourseStructureID = mission.RetakePlan.ER_RetakePlanSetting.CourseStructureID;
  692. educationMissionClass.CourseCategoryID = mission.RetakePlan.ER_RetakePlanSetting.CourseCategoryID;
  693. educationMissionClass.CourseTypeID = mission.RetakePlan.CourseTypeID;
  694. educationMissionClass.CourseQualityID = mission.RetakePlan.ER_RetakePlanSetting.CourseQualityID;
  695. educationMissionClass.ExaminationModeID = mission.RetakePlan.ER_RetakePlanSetting.ExaminationModeID;
  696. educationMissionClass.TeachinglanguageID = mission.RetakePlan.ER_RetakePlanSetting.TeachinglanguageID;
  697. //重修默认为必修
  698. educationMissionClass.HandleModeID = (int)EMIS.ViewModel.CF_HandleMode.RequiredCourse;
  699. educationMissionClass.IsNeedMaterial = mission.RetakePlan.ER_RetakePlanSetting.IsNeedMaterial;
  700. //成绩类型,默认为百分制
  701. educationMissionClass.ResultTypeID = (int)EMIS.ViewModel.CF_ResultType.Percentage;
  702. SetNewStatus(educationMissionClass);
  703. educationMissionClass.RecordStatus = (int)EMIS.ViewModel.EM_EducationMissionClassStatus.Scheduled;
  704. //插入教学设置
  705. EM_EducationMissionClassTeachingSetting educationMissionClassTeachingSetting = new EM_EducationMissionClassTeachingSetting();
  706. educationMissionClassTeachingSetting.EducationMissionClassID = educationMissionClass.EducationMissionClassID;
  707. educationMissionClassTeachingSetting.Credit = mission.RetakePlan.Credit;
  708. educationMissionClassTeachingSetting.TheoryCourse = mission.TeachingSetting.TheoryCourse;
  709. educationMissionClassTeachingSetting.Practicehours = mission.TeachingSetting.Practicehours;
  710. educationMissionClassTeachingSetting.Trialhours = mission.TeachingSetting.Trialhours;
  711. educationMissionClassTeachingSetting.WeeklyNum = mission.TeachingSetting.WeeklyNum;
  712. educationMissionClassTeachingSetting.TheoryWeeklyNum = mission.TeachingSetting.TheoryWeeklyNum;
  713. educationMissionClassTeachingSetting.PracticeWeeklyNum = mission.TeachingSetting.PracticeWeeklyNum;
  714. educationMissionClassTeachingSetting.TrialWeeklyNum = mission.TeachingSetting.TrialWeeklyNum;
  715. educationMissionClassTeachingSetting.StartWeeklyNum = mission.TeachingSetting.StartWeeklyNum;
  716. educationMissionClassTeachingSetting.EndWeeklyNum = mission.TeachingSetting.EndWeeklyNum;
  717. educationMissionClassTeachingSetting.WeeklyHours = mission.TeachingSetting.WeeklyHours;
  718. foreach (var list in mission.Teacher.Select(x => new { x.UserID, x.TeachType }))
  719. {
  720. EM_MissionClassTeacher teacher = new EM_MissionClassTeacher();
  721. teacher.MissionClassTeacherID = Guid.NewGuid();
  722. teacher.MissionClassID = educationMissionClass.EducationMissionClassID;
  723. teacher.TeachType = list.TeachType;
  724. teacher.UserID = list.UserID;
  725. SetNewStatus(teacher);
  726. educationMissionClass.EM_MissionClassTeacher.Add(teacher);
  727. resultTeacherList.Add(teacher);
  728. }
  729. int? ClassroomType = null; //教室类型,教学任务班表和课程进度需要
  730. if (Scheduling != null && Scheduling.ClassroomID != null)
  731. {
  732. var classRoom = educationMissionClassDAL.ClassroomRepository.GetList(x => x.ClassroomID == Scheduling.ClassroomID, x => x.CF_ClassroomType).FirstOrDefault();
  733. if (classRoom != null && classRoom.CF_ClassroomType.FirstOrDefault() != null)
  734. {
  735. ClassroomType = classRoom.CF_ClassroomType.FirstOrDefault().ClassroomType;
  736. educationMissionClass.ClassroomTypeID = ClassroomType;
  737. }
  738. educationMissionClass.ClassroomID = Scheduling.ClassroomID;
  739. }
  740. if (Scheduling.CoursesTimeID != null)
  741. {
  742. var coursesTime = educationMissionClassDAL.CoursesTimeRepository.Entities.Where(x => x.CoursesTimeID == Scheduling.CoursesTimeID).FirstOrDefault();
  743. educationMissionClass.EM_CoursesTime = new HashSet<EM_CoursesTime>();
  744. educationMissionClass.EM_CoursesTime.Add(coursesTime);
  745. }
  746. //插入排课班
  747. EM_EducationSchedulingClass educationSchedulingClass = new EM_EducationSchedulingClass();
  748. educationSchedulingClass.EducationSchedulingClassID = Guid.NewGuid();
  749. educationSchedulingClass.EducationMissionClassID = educationMissionClass.EducationMissionClassID;
  750. educationSchedulingClass.TaskGroupName = "1班";
  751. SetNewStatus(educationSchedulingClass);
  752. //添加排课任务班学生
  753. educationSchedulingClass.CF_Student = mission.Student; //选此课的学生
  754. resultMissionClassList.Add(educationMissionClass);
  755. resultMissionClassTeachingSettingList.Add(educationMissionClassTeachingSetting);
  756. resultEducationSchedulingClassList.Add(educationSchedulingClass);
  757. #region//插入排课相关信息
  758. //添加排课任务班学生
  759. educationSchedulingClass.CF_Student = mission.Student; //选此课的学生
  760. //根据开始和结束周,得到所有周的列表
  761. List<int?> schedulingWeekList = new List<int?>();
  762. schedulingWeekList.Add(mission.TeachingSetting.StartWeeklyNum);
  763. schedulingWeekList.Add(mission.TeachingSetting.EndWeeklyNum);
  764. for (int j = 1; j + schedulingWeekList.Min() < schedulingWeekList.Max(); j++)
  765. {
  766. schedulingWeekList.Add(j + schedulingWeekList.Min());
  767. }
  768. //排课课表
  769. foreach (var list in mission.Scheduling.Select(x => new { x.CoursesTimeID, x.ClassroomID, x.Weekday }))
  770. {
  771. ES_EducationScheduling educationScheduling = new ES_EducationScheduling();
  772. educationScheduling.EducationSchedulingID = Guid.NewGuid();
  773. educationScheduling.EducationSchedulingClassID = educationSchedulingClass.EducationSchedulingClassID;
  774. educationScheduling.SchoolyearID = educationMission.SchoolyearID;
  775. educationScheduling.Weekday = list.Weekday;
  776. educationScheduling.ClassroomID = list.ClassroomID;
  777. educationScheduling.CoursesTimeID = list.CoursesTimeID;
  778. SetNewStatus(educationScheduling);
  779. //educationScheduling.ES_EducationSchedulingTeacher.Add(educationScheduling);
  780. resultEducationSchedulingList.Add(educationScheduling);
  781. //排课教师表
  782. foreach (var teacherlist in mission.Teacher.Select(x => new { x.UserID, x.TeachType }))
  783. {
  784. ES_EducationSchedulingTeacher teacher = new ES_EducationSchedulingTeacher();
  785. teacher.EducationSchedulingTeacherID = Guid.NewGuid();
  786. teacher.EducationSchedulingID = educationScheduling.EducationSchedulingID;
  787. teacher.TeachingMethod = teacherlist.TeachType;
  788. teacher.UserID = teacherlist.UserID;
  789. SetNewStatus(teacher);
  790. educationScheduling.ES_EducationSchedulingTeacher.Add(teacher);
  791. resultEducationSchedulingTeacherList.Add(teacher);
  792. }
  793. foreach (var weekList in schedulingWeekList)
  794. {
  795. ES_EducationSchedulingWeekNum week = new ES_EducationSchedulingWeekNum();
  796. week.EducationSchedulingWeekNumID = Guid.NewGuid();
  797. week.EducationSchedulingID = educationScheduling.EducationSchedulingID;
  798. week.WeekNum = weekList;
  799. SetNewStatus(week);
  800. educationScheduling.ES_EducationSchedulingWeekNum.Add(week);
  801. resultEducationSchedulingWeekNumList.Add(week);
  802. }
  803. }
  804. //课程进度和教室以及任务班设置表
  805. foreach (var weekList in schedulingWeekList)
  806. {
  807. EM_CourseProcess process = new EM_CourseProcess();
  808. process.CourseProcessID = Guid.NewGuid();
  809. process.EducationMissionClassID = educationMissionClass.EducationMissionClassID;
  810. process.Week = weekList;
  811. process.Times = mission.TeachingSetting.WeeklyHours;
  812. process.ClassroomTypeID = ClassroomType;
  813. process.ClassroomID = educationMissionClass.ClassroomID;
  814. SetNewStatus(process);
  815. resultCourseProcessList.Add(process);
  816. //任务班设置表
  817. EM_EducationMissionClassSettings educationMissionClassSettings = new EM_EducationMissionClassSettings();
  818. educationMissionClassSettings.EducationMissionClassSettingsID = Guid.NewGuid();
  819. educationMissionClassSettings.EducationMissionClassID = educationMissionClass.EducationMissionClassID;
  820. educationMissionClassSettings.WeeklyNum = weekList;
  821. SetNewStatus(educationMissionClassSettings);
  822. resultEducationMissionClassSettingsList.Add(educationMissionClassSettings);
  823. //排课教师表
  824. foreach (var teacherlist in mission.Teacher.Select(x => new { x.UserID, x.TeachType }))
  825. {
  826. EM_CourseProcessTeacher teacher = new EM_CourseProcessTeacher();
  827. teacher.CourseProcessTeacherID = Guid.NewGuid();
  828. teacher.CourseProcessID = process.CourseProcessID;
  829. teacher.UserID = teacherlist.UserID;
  830. teacher.TeachType = teacherlist.TeachType;
  831. SetNewStatus(teacher);
  832. resultCourseProcessTeacherList.Add(teacher);
  833. }
  834. }
  835. #endregion
  836. mission.RetakePlanStudent.ToList().ForEach(x => x.EducationMissionID = educationMission.EducationMissionID);
  837. }
  838. //UnitOfWork.Add(educationMission);
  839. }
  840. UnitOfWork.BulkInsert(resultMissionList); //教学任务
  841. UnitOfWork.BulkInsert(resultMissionClassList); //教学任务班
  842. UnitOfWork.BulkInsert(resultMissionClassTeachingSettingList);
  843. UnitOfWork.BulkInsert(resultTeacherList); //
  844. UnitOfWork.BulkInsert(resultMissionClassList, x => x.EM_CoursesTime); //
  845. UnitOfWork.BulkInsert(resultEducationMissionClassSettingsList); //任务班设置表
  846. UnitOfWork.BulkInsert(resultEducationSchedulingList); //排课课表
  847. UnitOfWork.BulkInsert(resultEducationSchedulingTeacherList); //排课老师表
  848. UnitOfWork.BulkInsert(resultEducationSchedulingWeekNumList); //
  849. UnitOfWork.BulkInsert(resultEducationSchedulingClassList); //排课班表
  850. UnitOfWork.BulkInsert(resultEducationSchedulingClassList, (x => x.CF_Student)); //排课班与学生关联表
  851. UnitOfWork.BulkInsert(resultCourseProcessList); //课程进度
  852. UnitOfWork.BulkInsert(resultCourseProcessTeacherList); //课程进度任课老师表
  853. retakePlanList.ForEach(x => x.RecordStatus = (int)EMIS.ViewModel.ER_RetakePlanStatus.Generated);
  854. UnitOfWork.Commit();
  855. if (RemoveList.Count == 0)
  856. {
  857. return "开班成功。";
  858. }
  859. else
  860. {
  861. return string.Format("成功开班{0}条,失败{1}条,原因:缺少{2}", retakePlanList.Count, RemoveList.Count, result + "。");
  862. }
  863. }
  864. catch (Exception ex)
  865. {
  866. throw new Exception(ex.Message);
  867. }
  868. }
  869. /// <summary>
  870. /// 检测重修报名人数是否超过人数下限和人数上限范围
  871. /// </summary>
  872. /// <param name="retakePlanIDs"></param>
  873. /// <returns></returns>
  874. public bool IsOverRange(string retakePlanIDs)
  875. {
  876. List<Guid?> list = retakePlanIDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
  877. .Select(x => (Guid?)new Guid(x)).ToList();
  878. var IsExistsList = this.RetakePlanTaskDAL.RetakePlanRepository
  879. .GetList(x => list.Contains(x.RetakePlanID), (x => x.CF_Student)).ToList();
  880. if (IsExistsList != null && IsExistsList.Count() > 0)
  881. {
  882. foreach (var IsExists in IsExistsList)
  883. {
  884. if (IsExists.PeopleNumlower != null && IsExists.PeopleNumlower != 0)
  885. {
  886. //人数下限
  887. if (IsExists.CF_Student.Count() < IsExists.PeopleNumlower.Value)
  888. {
  889. return true;
  890. }
  891. }
  892. else if (IsExists.PeopleNumlimit != null && IsExists.PeopleNumlimit != 0)
  893. {
  894. //人数上限
  895. if (IsExists.CF_Student.Count() > IsExists.PeopleNumlimit.Value)
  896. {
  897. return true;
  898. }
  899. }
  900. }
  901. }
  902. return false;
  903. }
  904. /// <summary>
  905. /// 查询重修计划报名名单信息View
  906. /// </summary>
  907. /// <param name="configuretView"></param>
  908. /// <param name="schoolyearID"></param>
  909. /// <param name="collegeID"></param>
  910. /// <param name="yearID"></param>
  911. /// <param name="standardID"></param>
  912. /// <param name="educationID"></param>
  913. /// <param name="learningformID"></param>
  914. /// <param name="learnSystem"></param>
  915. /// <param name="classmajorID"></param>
  916. /// <param name="coursematerialID"></param>
  917. /// <param name="inSchoolStatus"></param>
  918. /// <param name="retakePlanStatusID"></param>
  919. /// <param name="generalPurposeID"></param>
  920. /// <param name="pageIndex"></param>
  921. /// <param name="pageSize"></param>
  922. /// <returns></returns>
  923. public IGridResultSet<RetakeStudentListView> GetRetakePlanResultStudentView(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID,
  924. int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem, Guid? classmajorID, Guid? coursematerialID,
  925. int? inSchoolStatus, int? retakePlanStatusID, int? generalPurposeID, int pageIndex, int pageSize)
  926. {
  927. //重修计划
  928. Expression<Func<ER_RetakePlan, bool>> expRetakePlan = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  929. ////排除重修任务状态为未开放状态的信息
  930. //expRetakePlan = expRetakePlan.And(x => x.RecordStatus != (int)ER_RetakePlanStatus.NotOpened);
  931. if (coursematerialID.HasValue)
  932. {
  933. //课程信息
  934. expRetakePlan = expRetakePlan.And(x => x.CoursematerialID == coursematerialID);
  935. }
  936. if (schoolyearID.HasValue)
  937. {
  938. //重修学年学期
  939. expRetakePlan = expRetakePlan.And(x => x.SchoolyearID == schoolyearID);
  940. }
  941. if (retakePlanStatusID.HasValue)
  942. {
  943. //重修任务状态
  944. expRetakePlan = expRetakePlan.And(x => x.RecordStatus == retakePlanStatusID);
  945. }
  946. //学生信息
  947. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  948. if (classmajorID.HasValue)
  949. {
  950. //班级信息
  951. expStudent = expStudent.And(x => x.ClassmajorID == classmajorID);
  952. }
  953. if (inSchoolStatus != null && inSchoolStatus > -1)
  954. {
  955. //在校状态
  956. var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
  957. if (inSchoolStatus == 1)
  958. {
  959. //表示在校
  960. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  961. }
  962. if (inSchoolStatus == 0)
  963. {
  964. //不在校
  965. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  966. }
  967. }
  968. var query = RetakePlanResultDAL.GetRetakePlanResultStudentView(expRetakePlan, expStudent);
  969. if (collegeID.HasValue)
  970. {
  971. //院系所
  972. query = query.Where(x => x.CollegeID == collegeID);
  973. }
  974. if (yearID.HasValue)
  975. {
  976. //年级
  977. query = query.Where(x => x.Gradeyear == yearID);
  978. }
  979. if (standardID.HasValue)
  980. {
  981. //专业名称
  982. query = query.Where(x => x.StandardID == standardID);
  983. }
  984. if (educationID.HasValue)
  985. {
  986. //培养层次
  987. query = query.Where(x => x.EducationID == educationID);
  988. }
  989. if (learningformID.HasValue)
  990. {
  991. //学习形式
  992. query = query.Where(x => x.LearningformID == learningformID);
  993. }
  994. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  995. {
  996. //学制
  997. var LearnSystems = Convert.ToDecimal(learnSystem);
  998. query = query.Where(x => x.LearnSystem == LearnSystems);
  999. }
  1000. if (generalPurposeID.HasValue)
  1001. {
  1002. //报名状态
  1003. if (generalPurposeID.Value == (int)CF_GeneralPurpose.IsYes)
  1004. {
  1005. query = query.Where(x => x.ApplyStatus == true);
  1006. }
  1007. if (generalPurposeID.Value == (int)CF_GeneralPurpose.IsNo)
  1008. {
  1009. query = query.Where(x => x.ApplyStatus == false);
  1010. }
  1011. }
  1012. //查询条件
  1013. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  1014. {
  1015. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  1016. }
  1017. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SchoolyearCode)
  1018. .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
  1019. .ThenBy(x => x.CourseTypeID).ThenBy(x => x.CourseCredit)
  1020. .ThenBy(x => x.DepartmentCode.Length).ThenBy(x => x.DepartmentCode)
  1021. .ThenBy(x => x.LoginID.Length).ThenBy(x => x.LoginID)
  1022. .ToGridResultSet<RetakeStudentListView>(pageIndex, pageSize);
  1023. }
  1024. /// <summary>
  1025. /// 查询重修计划报名名单信息List
  1026. /// </summary>
  1027. /// <param name="configuretView"></param>
  1028. /// <param name="schoolyearID"></param>
  1029. /// <param name="collegeID"></param>
  1030. /// <param name="yearID"></param>
  1031. /// <param name="standardID"></param>
  1032. /// <param name="educationID"></param>
  1033. /// <param name="learningformID"></param>
  1034. /// <param name="learnSystem"></param>
  1035. /// <param name="classmajorID"></param>
  1036. /// <param name="coursematerialID"></param>
  1037. /// <param name="inSchoolStatus"></param>
  1038. /// <param name="retakePlanStatusID"></param>
  1039. /// <param name="generalPurposeID"></param>
  1040. /// <returns></returns>
  1041. public List<RetakeStudentListView> GetRetakePlanResultStudentViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID,
  1042. int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem, Guid? classmajorID, Guid? coursematerialID,
  1043. int? inSchoolStatus, int? retakePlanStatusID, int? generalPurposeID)
  1044. {
  1045. //重修计划
  1046. Expression<Func<ER_RetakePlan, bool>> expRetakePlan = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  1047. ////排除重修任务状态为未开放状态的信息
  1048. //expRetakePlan = expRetakePlan.And(x => x.RecordStatus != (int)ER_RetakePlanStatus.NotOpened);
  1049. if (coursematerialID.HasValue)
  1050. {
  1051. //课程信息
  1052. expRetakePlan = expRetakePlan.And(x => x.CoursematerialID == coursematerialID);
  1053. }
  1054. if (schoolyearID.HasValue)
  1055. {
  1056. //重修学年学期
  1057. expRetakePlan = expRetakePlan.And(x => x.SchoolyearID == schoolyearID);
  1058. }
  1059. if (retakePlanStatusID.HasValue)
  1060. {
  1061. //重修任务状态
  1062. expRetakePlan = expRetakePlan.And(x => x.RecordStatus == retakePlanStatusID);
  1063. }
  1064. //学生信息
  1065. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  1066. if (classmajorID.HasValue)
  1067. {
  1068. //班级信息
  1069. expStudent = expStudent.And(x => x.ClassmajorID == classmajorID);
  1070. }
  1071. if (inSchoolStatus != null && inSchoolStatus > -1)
  1072. {
  1073. //在校状态
  1074. var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
  1075. if (inSchoolStatus == 1)
  1076. {
  1077. //表示在校
  1078. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  1079. }
  1080. if (inSchoolStatus == 0)
  1081. {
  1082. //不在校
  1083. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  1084. }
  1085. }
  1086. var query = RetakePlanResultDAL.GetRetakePlanResultStudentView(expRetakePlan, expStudent);
  1087. if (collegeID.HasValue)
  1088. {
  1089. //院系所
  1090. query = query.Where(x => x.CollegeID == collegeID);
  1091. }
  1092. if (yearID.HasValue)
  1093. {
  1094. //年级
  1095. query = query.Where(x => x.Gradeyear == yearID);
  1096. }
  1097. if (standardID.HasValue)
  1098. {
  1099. //专业名称
  1100. query = query.Where(x => x.StandardID == standardID);
  1101. }
  1102. if (educationID.HasValue)
  1103. {
  1104. //培养层次
  1105. query = query.Where(x => x.EducationID == educationID);
  1106. }
  1107. if (learningformID.HasValue)
  1108. {
  1109. //学习形式
  1110. query = query.Where(x => x.LearningformID == learningformID);
  1111. }
  1112. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  1113. {
  1114. //学制
  1115. var LearnSystems = Convert.ToDecimal(learnSystem);
  1116. query = query.Where(x => x.LearnSystem == LearnSystems);
  1117. }
  1118. if (generalPurposeID.HasValue)
  1119. {
  1120. //报名状态
  1121. if (generalPurposeID.Value == (int)CF_GeneralPurpose.IsYes)
  1122. {
  1123. query = query.Where(x => x.ApplyStatus == true);
  1124. }
  1125. if (generalPurposeID.Value == (int)CF_GeneralPurpose.IsNo)
  1126. {
  1127. query = query.Where(x => x.ApplyStatus == false);
  1128. }
  1129. }
  1130. //查询条件
  1131. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  1132. {
  1133. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  1134. }
  1135. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SchoolyearCode)
  1136. .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
  1137. .ThenBy(x => x.CourseTypeID).ThenBy(x => x.CourseCredit)
  1138. .ThenBy(x => x.DepartmentCode.Length).ThenBy(x => x.DepartmentCode)
  1139. .ThenBy(x => x.LoginID.Length).ThenBy(x => x.LoginID)
  1140. .ToList();
  1141. }
  1142. /// <summary>
  1143. /// 取消报名(删除)
  1144. /// </summary>
  1145. /// <param name="RetakePlanStudentIDs"></param>
  1146. /// <param name="UserIDs"></param>
  1147. public void RetakePlanResultDelete(string RetakePlanStudentIDs)
  1148. {
  1149. try
  1150. {
  1151. List<Guid?> retakePlanStudentIDsList = RetakePlanStudentIDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
  1152. .Select(x => (Guid?)new Guid(x)).ToList();
  1153. //查询对应的重修报名信息List(已报名)
  1154. var retakePlanStudentApplyViewList = RetakePlanResultDAL.RetakePlanStudentRepository
  1155. .GetList(x => retakePlanStudentIDsList.Contains(x.RetakePlanStudentID),
  1156. (x => x.ER_RetakePlan),
  1157. (x => x.ER_RetakePlan.CF_Student))
  1158. .Where(x => x.ER_RetakePlan.CF_Student.Any(w => w.UserID == x.UserID))
  1159. .ToList();
  1160. if (retakePlanStudentApplyViewList.Count() > 0)
  1161. {
  1162. //查询对应的重修计划信息
  1163. var retakePlanViewList = retakePlanStudentApplyViewList
  1164. .Select(x => x.ER_RetakePlan).Distinct().ToList();
  1165. //重修报名表
  1166. foreach (var retakePlan in retakePlanViewList)
  1167. {
  1168. //查询存在报名名单的重修计划名单对应的userIDList
  1169. var userIDList = retakePlanStudentApplyViewList
  1170. .Where(x => x.RetakePlanID == retakePlan.RetakePlanID)
  1171. .Select(x => x.UserID).ToList();
  1172. //取消报名(删除)
  1173. retakePlan.CF_Student.RemoveWhere(x => userIDList.Contains(x.UserID));
  1174. }
  1175. }
  1176. UnitOfWork.Commit();
  1177. }
  1178. catch (Exception ex)
  1179. {
  1180. throw new Exception(ex.Message);
  1181. }
  1182. }
  1183. }
  1184. }