ChangeApplyServices.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using Bowin.Common.Linq;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.Entities;
  9. using EMIS.ViewModel;
  10. using EMIS.ViewModel.StudentManage.StudentChange;
  11. using EMIS.DataLogic.StudentManage.StudentChange;
  12. using EMIS.CommonLogic.SystemServices;
  13. using EMIS.CommonLogic.StudentManage.StudentStatistics;
  14. namespace EMIS.CommonLogic.StudentManage.StudentChange
  15. {
  16. public class ChangeApplyServices : BaseWorkflowServices<CF_DifferentDynamic>, IChangeApplyServices
  17. {
  18. public Lazy<StudentChangeDAL> StudentChangeDAL { get; set; }
  19. public Lazy<IInSchoolSettingServices> InSchoolSettingServices { get; set; }
  20. /// <summary>
  21. /// 数据范围
  22. /// </summary>
  23. public ChangeApplyServices()
  24. {
  25. DataRangeUserFunc = ((x, y) => this.IsUserInDataRangeByCollege<CF_DifferentDynamic>(x, y, (w => w.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID)));
  26. }
  27. /// <summary>
  28. /// 查询学籍异动申请信息View
  29. /// </summary>
  30. /// <param name="configuretView"></param>
  31. /// <param name="campusID"></param>
  32. /// <param name="collegeID"></param>
  33. /// <param name="gradeID"></param>
  34. /// <param name="standardID"></param>
  35. /// <param name="educationID"></param>
  36. /// <param name="learningformID"></param>
  37. /// <param name="learnSystem"></param>
  38. /// <param name="classmajorID"></param>
  39. /// <param name="schoolyearID"></param>
  40. /// <param name="changeTypeID"></param>
  41. /// <param name="inSchoolStatus"></param>
  42. /// <param name="approvalStatus"></param>
  43. /// <param name="pageIndex"></param>
  44. /// <param name="pageSize"></param>
  45. /// <returns></returns>
  46. public IGridResultSet<StudentChangeView> GetChangeApplyViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID,
  47. int? educationID, int? learningformID, string learnSystem, Guid? classmajorID, Guid? schoolyearID, int? changeTypeID, int? inSchoolStatus, int? approvalStatus, int pageIndex, int pageSize)
  48. {
  49. var endStatusID = this.GetCorrectEndStatus();
  50. var approveStatusIDList = this.GetApproveStatusViewList().Select(x => x.ID).ToList();
  51. var applyStatusList = this.GetStatusViewList();
  52. var applyStatusIDList = applyStatusList.Where(x => x.ID != endStatusID && !approveStatusIDList.Contains(x.ID)).Select(x => x.ID).ToList();
  53. Expression<Func<CF_DifferentDynamic, bool>> expStudentChange = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  54. expStudentChange = expStudentChange.And(x => applyStatusIDList.Contains(x.ApprovalStatus));
  55. if (schoolyearID.HasValue)
  56. {
  57. expStudentChange = expStudentChange.And(x => x.SchoolyearID == schoolyearID);
  58. }
  59. if (changeTypeID.HasValue)
  60. {
  61. expStudentChange = expStudentChange.And(x => x.ChangeTypeID == changeTypeID);
  62. }
  63. if (approvalStatus.HasValue)
  64. {
  65. expStudentChange = expStudentChange.And(x => x.ApprovalStatus == approvalStatus);
  66. }
  67. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  68. if (classmajorID.HasValue)
  69. {
  70. expStudent = expStudent.And(x => x.ClassmajorID == classmajorID);
  71. }
  72. if (inSchoolStatus != null && inSchoolStatus > -1)
  73. {
  74. var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
  75. if (inSchoolStatus == 1)
  76. {
  77. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  78. }
  79. if (inSchoolStatus == 0)
  80. {
  81. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  82. }
  83. }
  84. var query = StudentChangeDAL.Value.GetStudentChangeViewQueryable(expStudentChange, expStudent);
  85. if (campusID.HasValue)
  86. {
  87. query = query.Where(x => x.CampusID == campusID);
  88. }
  89. if (collegeID.HasValue)
  90. {
  91. query = query.Where(x => x.CollegeID == collegeID);
  92. }
  93. if (gradeID.HasValue)
  94. {
  95. query = query.Where(x => x.GradeID == gradeID);
  96. }
  97. if (standardID.HasValue)
  98. {
  99. query = query.Where(x => x.StandardID == standardID);
  100. }
  101. if (educationID.HasValue)
  102. {
  103. query = query.Where(x => x.EducationID == educationID);
  104. }
  105. if (learningformID.HasValue)
  106. {
  107. query = query.Where(x => x.LearningformID == learningformID);
  108. }
  109. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  110. {
  111. var LearnSystems = Convert.ToDecimal(learnSystem);
  112. query = query.Where(x => x.LearnSystem == LearnSystems);
  113. }
  114. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  115. {
  116. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  117. }
  118. var result = this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query))
  119. .OrderBy(x => x.SchoolyearValue).ThenBy(x => x.ChangeTypeID).ThenBy(x => x.GradeID).ThenBy(x => x.StandardID)
  120. .ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ThenBy(x => x.StudentNo)
  121. .ThenByDescending(x => x.ChangeDate).ToGridResultSet<StudentChangeView>(pageIndex, pageSize);
  122. result.rows.ForEach(x => x.ApprovalStatusName = applyStatusList.Where(w => w.ID == x.ApprovalStatus).Select(w => w.Name).FirstOrDefault());
  123. return result;
  124. }
  125. /// <summary>
  126. /// 查询学籍异动申请信息List
  127. /// </summary>
  128. /// <param name="configuretView"></param>
  129. /// <param name="campusID"></param>
  130. /// <param name="collegeID"></param>
  131. /// <param name="gradeID"></param>
  132. /// <param name="standardID"></param>
  133. /// <param name="educationID"></param>
  134. /// <param name="learningformID"></param>
  135. /// <param name="learnSystem"></param>
  136. /// <param name="classmajorID"></param>
  137. /// <param name="schoolyearID"></param>
  138. /// <param name="changeTypeID"></param>
  139. /// <param name="inSchoolStatus"></param>
  140. /// <param name="approvalStatus"></param>
  141. /// <returns></returns>
  142. public IList<StudentChangeView> GetChangeApplyViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID,
  143. int? educationID, int? learningformID, string learnSystem, Guid? classmajorID, Guid? schoolyearID, int? changeTypeID, int? inSchoolStatus, int? approvalStatus)
  144. {
  145. var endStatusID = this.GetCorrectEndStatus();
  146. var approveStatusIDList = this.GetApproveStatusViewList().Select(x => x.ID).ToList();
  147. var applyStatusList = this.GetStatusViewList();
  148. var applyStatusIDList = applyStatusList.Where(x => x.ID != endStatusID && !approveStatusIDList.Contains(x.ID)).Select(x => x.ID).ToList();
  149. Expression<Func<CF_DifferentDynamic, bool>> expStudentChange = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  150. expStudentChange = expStudentChange.And(x => applyStatusIDList.Contains(x.ApprovalStatus));
  151. if (schoolyearID.HasValue)
  152. {
  153. expStudentChange = expStudentChange.And(x => x.SchoolyearID == schoolyearID);
  154. }
  155. if (changeTypeID.HasValue)
  156. {
  157. expStudentChange = expStudentChange.And(x => x.ChangeTypeID == changeTypeID);
  158. }
  159. if (approvalStatus.HasValue)
  160. {
  161. expStudentChange = expStudentChange.And(x => x.ApprovalStatus == approvalStatus);
  162. }
  163. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  164. if (classmajorID.HasValue)
  165. {
  166. expStudent = expStudent.And(x => x.ClassmajorID == classmajorID);
  167. }
  168. if (inSchoolStatus != null && inSchoolStatus > -1)
  169. {
  170. var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
  171. if (inSchoolStatus == 1)
  172. {
  173. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  174. }
  175. if (inSchoolStatus == 0)
  176. {
  177. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  178. }
  179. }
  180. var query = StudentChangeDAL.Value.GetStudentChangeViewQueryable(expStudentChange, expStudent);
  181. if (campusID.HasValue)
  182. {
  183. query = query.Where(x => x.CampusID == campusID);
  184. }
  185. if (collegeID.HasValue)
  186. {
  187. query = query.Where(x => x.CollegeID == collegeID);
  188. }
  189. if (gradeID.HasValue)
  190. {
  191. query = query.Where(x => x.GradeID == gradeID);
  192. }
  193. if (standardID.HasValue)
  194. {
  195. query = query.Where(x => x.StandardID == standardID);
  196. }
  197. if (educationID.HasValue)
  198. {
  199. query = query.Where(x => x.EducationID == educationID);
  200. }
  201. if (learningformID.HasValue)
  202. {
  203. query = query.Where(x => x.LearningformID == learningformID);
  204. }
  205. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  206. {
  207. var LearnSystems = Convert.ToDecimal(learnSystem);
  208. query = query.Where(x => x.LearnSystem == LearnSystems);
  209. }
  210. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  211. {
  212. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  213. }
  214. var result = this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query))
  215. .OrderBy(x => x.SchoolyearValue).ThenBy(x => x.ChangeTypeID).ThenBy(x => x.GradeID).ThenBy(x => x.StandardID)
  216. .ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ThenBy(x => x.StudentNo)
  217. .ThenByDescending(x => x.ChangeDate).ToList();
  218. result.ForEach(x => x.ApprovalStatusName = applyStatusList.Where(w => w.ID == x.ApprovalStatus).Select(w => w.Name).FirstOrDefault());
  219. return result;
  220. }
  221. /// <summary>
  222. /// 查询对应的学籍异动信息View
  223. /// </summary>
  224. /// <param name="studentChangeID"></param>
  225. /// <returns></returns>
  226. public StudentChangeView GetStudentChangeView(Guid? studentChangeID)
  227. {
  228. try
  229. {
  230. Expression<Func<CF_DifferentDynamic, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  231. exp = exp.And(x => x.StudentChangeID == studentChangeID);
  232. var query = StudentChangeDAL.Value.GetStudentChangeViewQueryable(exp).SingleOrDefault();
  233. return query;
  234. }
  235. catch (Exception ex)
  236. {
  237. throw new Exception(ex.Message);
  238. }
  239. }
  240. /// <summary>
  241. /// 编辑
  242. /// </summary>
  243. /// <param name="studentChangeView"></param>
  244. public void ChangeApplyEdit(StudentChangeView studentChangeView)
  245. {
  246. try
  247. {
  248. var workflowStatusViewList = this.GetStatusViewList();
  249. if (workflowStatusViewList == null || workflowStatusViewList.Count() <= 0)
  250. {
  251. throw new Exception("工作流平台中,学籍异动流程未配置,请核查。");
  252. }
  253. var startStatusID = this.GetStartStatus();
  254. if (startStatusID == null)
  255. {
  256. throw new Exception("工作流平台中,学籍异动流程开始环节未配置,请核查。");
  257. }
  258. var endStatusID = this.GetCorrectEndStatus();
  259. if (endStatusID == null)
  260. {
  261. throw new Exception("工作流平台中,学籍异动流程结束环节未配置,请核查。");
  262. }
  263. var approveStatusIDList = this.GetApproveStatusViewList().Select(x => x.ID).ToList();
  264. var applyStatusIDList = workflowStatusViewList.Where(x => x.ID != endStatusID && !approveStatusIDList.Contains(x.ID)).Select(x => x.ID).ToList();
  265. var studentChangeVerify = StudentChangeDAL.Value.StudentChangeRepository.GetList(x => x.StudentChangeID != studentChangeView.StudentChangeID
  266. && x.UserID == studentChangeView.UserID && x.SchoolyearID == studentChangeView.SchoolyearID && x.ChangeTypeID == studentChangeView.ChangeTypeID).SingleOrDefault();
  267. if (studentChangeVerify == null)
  268. {
  269. if (studentChangeView.StudentChangeID != Guid.Empty)
  270. {
  271. var studentChange = StudentChangeDAL.Value.StudentChangeRepository.GetList(x => x.StudentChangeID == studentChangeView.StudentChangeID).SingleOrDefault();
  272. if (studentChange == null)
  273. {
  274. throw new Exception("数据有误,请核查。");
  275. }
  276. else
  277. {
  278. if (applyStatusIDList.Any(x => x == studentChange.ApprovalStatus))
  279. {
  280. studentChange.UserID = studentChangeView.UserID;
  281. studentChange.SchoolyearID = studentChangeView.SchoolyearID;
  282. studentChange.ChangeTypeID = studentChangeView.ChangeTypeID;
  283. studentChange.BeforeClassmajorID = studentChangeView.BeforeClassmajorID;
  284. studentChange.BeforeInSchoolStatusID = studentChangeView.BeforeInSchoolStatusID;
  285. studentChange.BeforeStudentStatus = studentChangeView.BeforeStudentStatus;
  286. studentChange.AfterClassmajorID = studentChangeView.AfterClassmajorID;
  287. studentChange.AfterInSchoolStatusID = studentChangeView.AfterInSchoolStatusID;
  288. studentChange.AfterStudentStatus = studentChangeView.AfterStudentStatus;
  289. studentChange.ReturnSchoolyearID = studentChangeView.ReturnSchoolyearID;
  290. studentChange.ChangeReasonID = studentChangeView.ChangeReasonID;
  291. studentChange.ChangeDate = studentChangeView.ChangeDate;
  292. studentChange.Description = studentChangeView.Description;
  293. studentChange.Remark = studentChangeView.Remark;
  294. SetModifyStatus(studentChange);
  295. }
  296. else
  297. {
  298. throw new Exception("只能修改未提交、已退回状态的信息,请核查。");
  299. }
  300. }
  301. }
  302. else
  303. {
  304. var newStudentChange = new CF_DifferentDynamic();
  305. newStudentChange.StudentChangeID = Guid.NewGuid();
  306. newStudentChange.UserID = studentChangeView.UserID;
  307. newStudentChange.SchoolyearID = studentChangeView.SchoolyearID;
  308. newStudentChange.ChangeTypeID = studentChangeView.ChangeTypeID;
  309. newStudentChange.BeforeClassmajorID = studentChangeView.BeforeClassmajorID;
  310. newStudentChange.BeforeInSchoolStatusID = studentChangeView.BeforeInSchoolStatusID;
  311. newStudentChange.BeforeStudentStatus = studentChangeView.BeforeStudentStatus;
  312. newStudentChange.AfterClassmajorID = studentChangeView.AfterClassmajorID;
  313. newStudentChange.AfterInSchoolStatusID = studentChangeView.AfterInSchoolStatusID;
  314. newStudentChange.AfterStudentStatus = studentChangeView.AfterStudentStatus;
  315. newStudentChange.ReturnSchoolyearID = studentChangeView.ReturnSchoolyearID;
  316. newStudentChange.ChangeApplyTypeID = (int)CF_ChangeApplyType.Normal;
  317. newStudentChange.ChangeReasonID = studentChangeView.ChangeReasonID;
  318. newStudentChange.ChangeDate = studentChangeView.ChangeDate;
  319. newStudentChange.Description = studentChangeView.Description;
  320. newStudentChange.ApprovalStatus = startStatusID;
  321. newStudentChange.Remark = studentChangeView.Remark;
  322. SetNewStatus(newStudentChange);
  323. UnitOfWork.Add(newStudentChange);
  324. }
  325. }
  326. else
  327. {
  328. throw new Exception("已存在相同的异动申请信息,请核查。");
  329. }
  330. UnitOfWork.Commit();
  331. }
  332. catch (Exception ex)
  333. {
  334. throw new Exception(ex.Message);
  335. }
  336. }
  337. /// <summary>
  338. /// 删除
  339. /// </summary>
  340. /// <param name="studentChangeIDs"></param>
  341. /// <returns></returns>
  342. public bool ChangeApplyDelete(List<Guid?> studentChangeIDs)
  343. {
  344. try
  345. {
  346. var workflowStatusViewList = this.GetStatusViewList();
  347. if (workflowStatusViewList == null || workflowStatusViewList.Count() <= 0)
  348. {
  349. throw new Exception("工作流平台中,学籍异动流程未配置,请核查。");
  350. }
  351. var startStatusID = this.GetStartStatus();
  352. if (startStatusID == null)
  353. {
  354. throw new Exception("工作流平台中,学籍异动流程开始环节未配置,请核查。");
  355. }
  356. var endStatusID = this.GetCorrectEndStatus();
  357. if (endStatusID == null)
  358. {
  359. throw new Exception("工作流平台中,学籍异动流程结束环节未配置,请核查。");
  360. }
  361. var approveStatusIDList = this.GetApproveStatusViewList().Select(x => x.ID).ToList();
  362. var applyStatusIDList = workflowStatusViewList.Where(x => x.ID != endStatusID && !approveStatusIDList.Contains(x.ID)).Select(x => x.ID).ToList();
  363. var studentChangeList = StudentChangeDAL.Value.StudentChangeRepository.GetList(x => studentChangeIDs.Contains(x.StudentChangeID)).ToList();
  364. foreach (var studentChange in studentChangeList)
  365. {
  366. if (!applyStatusIDList.Any(x => x == studentChange.ApprovalStatus))
  367. {
  368. throw new Exception("只能删除未提交、已退回状态的信息,请刷新页面再次尝试。");
  369. }
  370. }
  371. UnitOfWork.Delete<CF_DifferentDynamic>(x => studentChangeIDs.Contains(x.StudentChangeID));
  372. return true;
  373. }
  374. catch (Exception)
  375. {
  376. throw;
  377. }
  378. }
  379. /// <summary>
  380. /// 提交
  381. /// </summary>
  382. /// <param name="studentChangeIDs"></param>
  383. /// <param name="userID"></param>
  384. /// <param name="comment"></param>
  385. /// <returns></returns>
  386. public string ChangeApplySubmit(List<Guid> studentChangeIDs, Guid userID, string comment = "")
  387. {
  388. try
  389. {
  390. var startStatusID = this.GetStartStatus();
  391. if (startStatusID == null)
  392. {
  393. throw new Exception("工作流平台中,学籍异动流程开始环节未配置,请核查。");
  394. }
  395. int success = 0;
  396. string tipMessage = null;
  397. var submitIDList = new List<Guid>();
  398. var approveIDList = new List<Guid>();
  399. var studentChangeList = StudentChangeDAL.Value.StudentChangeRepository.GetList(x => studentChangeIDs.Contains(x.StudentChangeID)).ToList();
  400. foreach (var studentChange in studentChangeList)
  401. {
  402. if (!studentChange.SchoolyearID.HasValue)
  403. {
  404. throw new Exception("选择提交的数据存在异常(如:学年学期为空),请核查。");
  405. }
  406. if (!studentChange.ChangeTypeID.HasValue)
  407. {
  408. throw new Exception("选择提交的数据存在异常(如:异动类型为空),请核查。");
  409. }
  410. if (!studentChange.BeforeClassmajorID.HasValue)
  411. {
  412. throw new Exception("选择提交的数据存在异常(如:异动前班级为空),请核查。");
  413. }
  414. if (!studentChange.BeforeInSchoolStatusID.HasValue)
  415. {
  416. throw new Exception("选择提交的数据存在异常(如:异动前在校状态为空),请核查。");
  417. }
  418. if (!studentChange.AfterClassmajorID.HasValue)
  419. {
  420. throw new Exception("选择提交的数据存在异常(如:异动后班级为空),请核查。");
  421. }
  422. if (!studentChange.AfterInSchoolStatusID.HasValue)
  423. {
  424. throw new Exception("选择提交的数据存在异常(如:异动后在校状态为空),请核查。");
  425. }
  426. if (!studentChange.ChangeReasonID.HasValue)
  427. {
  428. throw new Exception("选择提交的数据存在异常(如:异动原因为空),请核查。");
  429. }
  430. if (!studentChange.ChangeDate.HasValue)
  431. {
  432. throw new Exception("选择提交的数据存在异常(如:异动日期为空),请核查。");
  433. }
  434. if (studentChange.ApprovalStatus == startStatusID)
  435. {
  436. submitIDList.Add(studentChange.StudentChangeID);
  437. }
  438. else
  439. {
  440. approveIDList.Add(studentChange.StudentChangeID);
  441. }
  442. success++;
  443. }
  444. if (submitIDList.Count > 0)
  445. {
  446. this.StartUp(submitIDList, userID, comment);
  447. }
  448. if (approveIDList.Count > 0)
  449. {
  450. this.Approve(approveIDList, userID, Guid.Empty, comment);
  451. }
  452. tipMessage = success + "条";
  453. return tipMessage;
  454. }
  455. catch (Exception ex)
  456. {
  457. throw new Exception(ex.Message);
  458. }
  459. }
  460. }
  461. }