StudentPunishServices.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using System.Transactions;
  7. using Bowin.Common.Linq;
  8. using Bowin.Common.Linq.Entity;
  9. using Bowin.Common.Utility;
  10. using EMIS.Entities;
  11. using EMIS.ViewModel;
  12. using EMIS.ViewModel.StudentManage.StudentProfile;
  13. using EMIS.DataLogic.StudentManage.StudentProfile;
  14. using EMIS.CommonLogic.StudentManage.StudentStatistics;
  15. using EMIS.CommonLogic.SystemServices;
  16. namespace EMIS.CommonLogic.StudentManage.StudentProfile
  17. {
  18. public class StudentPunishServices : BaseWorkflowServices<EM_StudentPunish>, IStudentPunishServices
  19. {
  20. public Lazy<StudentPunishDAL> StudentPunishDAL { get; set; }
  21. public Lazy<IInSchoolSettingServices> InSchoolSettingServices { get; set; }
  22. /// <summary>
  23. /// 数据范围
  24. /// </summary>
  25. public StudentPunishServices()
  26. {
  27. DataRangeUserFunc = ((x, y) => this.IsUserInDataRangeByCollege<EM_StudentPunish>(x, y, (w => w.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID)));
  28. }
  29. /// <summary>
  30. /// 查询对应的学生处分信息StudentPunishView
  31. /// </summary>
  32. /// <param name="configuretView"></param>
  33. /// <param name="schoolyearID"></param>
  34. /// <param name="campusID"></param>
  35. /// <param name="collegeID"></param>
  36. /// <param name="gradeID"></param>
  37. /// <param name="standardID"></param>
  38. /// <param name="educationID"></param>
  39. /// <param name="learningformID"></param>
  40. /// <param name="learnSystem"></param>
  41. /// <param name="punishTypeID"></param>
  42. /// <param name="punishLevelID"></param>
  43. /// <param name="inSchoolStatus"></param>
  44. /// <param name="approvalStatus"></param>
  45. /// <param name="pageIndex"></param>
  46. /// <param name="pageSize"></param>
  47. /// <returns></returns>
  48. public IGridResultSet<StudentPunishView> GetStudentPunishViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID,
  49. int? educationID, int? learningformID, string learnSystem, int? punishTypeID, int? punishLevelID, int? inSchoolStatus, int? approvalStatus, int pageIndex, int pageSize)
  50. {
  51. var approveStatusList = this.GetStatusViewList();
  52. Expression<Func<EM_StudentPunish, bool>> expStudentPunish = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  53. if (schoolyearID.HasValue)
  54. {
  55. expStudentPunish = expStudentPunish.And(x => x.SchoolyearID == schoolyearID);
  56. }
  57. if (punishTypeID.HasValue)
  58. {
  59. expStudentPunish = expStudentPunish.And(x => x.PunishTypeID == punishTypeID);
  60. }
  61. if (punishLevelID.HasValue)
  62. {
  63. expStudentPunish = expStudentPunish.And(x => x.PunishLevelID == punishLevelID);
  64. }
  65. if (approvalStatus.HasValue)
  66. {
  67. expStudentPunish = expStudentPunish.And(x => x.ApprovalStatus == approvalStatus);
  68. }
  69. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  70. if (inSchoolStatus != null && inSchoolStatus > -1)
  71. {
  72. var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
  73. if (inSchoolStatus == 1)
  74. {
  75. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  76. }
  77. if (inSchoolStatus == 0)
  78. {
  79. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  80. }
  81. }
  82. var query = StudentPunishDAL.Value.GetStudentPunishViewQueryable(expStudentPunish, expStudent);
  83. if (campusID.HasValue)
  84. {
  85. query = query.Where(x => x.CampusID == campusID);
  86. }
  87. if (collegeID.HasValue)
  88. {
  89. query = query.Where(x => x.CollegeID == collegeID);
  90. }
  91. if (gradeID.HasValue)
  92. {
  93. query = query.Where(x => x.GradeID == gradeID);
  94. }
  95. if (standardID.HasValue)
  96. {
  97. query = query.Where(x => x.StandardID == standardID);
  98. }
  99. if (educationID.HasValue)
  100. {
  101. query = query.Where(x => x.EducationID == educationID);
  102. }
  103. if (learningformID.HasValue)
  104. {
  105. query = query.Where(x => x.LearningformID == learningformID);
  106. }
  107. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  108. {
  109. var LearnSystems = Convert.ToDecimal(learnSystem);
  110. query = query.Where(x => x.LearnSystem == LearnSystems);
  111. }
  112. //查询条件
  113. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  114. {
  115. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  116. }
  117. var result = this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query)).OrderBy(x => x.ClassmajorNo.Length)
  118. .ThenBy(x => x.ClassmajorNo).ThenBy(x => x.StudentNo.Length).ThenBy(x => x.StudentNo).ThenByDescending(x => x.SchoolyearValue).ToGridResultSet<StudentPunishView>(pageIndex, pageSize);
  119. result.rows.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name);
  120. return result;
  121. }
  122. /// <summary>
  123. /// 查询对应的学生处分信息List
  124. /// </summary>
  125. /// <param name="configuretView"></param>
  126. /// <param name="schoolyearID"></param>
  127. /// <param name="campusID"></param>
  128. /// <param name="collegeID"></param>
  129. /// <param name="gradeID"></param>
  130. /// <param name="standardID"></param>
  131. /// <param name="educationID"></param>
  132. /// <param name="learningformID"></param>
  133. /// <param name="learnSystem"></param>
  134. /// <param name="punishTypeID"></param>
  135. /// <param name="punishLevelID"></param>
  136. /// <param name="inSchoolStatus"></param>
  137. /// <param name="approvalStatus"></param>
  138. /// <returns></returns>
  139. public IList<StudentPunishView> GetStudentPunishViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID,
  140. int? educationID, int? learningformID, string learnSystem, int? punishTypeID, int? punishLevelID, int? inSchoolStatus, int? approvalStatus)
  141. {
  142. var approveStatusList = this.GetStatusViewList();
  143. Expression<Func<EM_StudentPunish, bool>> expStudentPunish = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  144. if (schoolyearID.HasValue)
  145. {
  146. expStudentPunish = expStudentPunish.And(x => x.SchoolyearID == schoolyearID);
  147. }
  148. if (punishTypeID.HasValue)
  149. {
  150. expStudentPunish = expStudentPunish.And(x => x.PunishTypeID == punishTypeID);
  151. }
  152. if (punishLevelID.HasValue)
  153. {
  154. expStudentPunish = expStudentPunish.And(x => x.PunishLevelID == punishLevelID);
  155. }
  156. if (approvalStatus.HasValue)
  157. {
  158. expStudentPunish = expStudentPunish.And(x => x.ApprovalStatus == approvalStatus);
  159. }
  160. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  161. if (inSchoolStatus != null && inSchoolStatus > -1)
  162. {
  163. var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
  164. if (inSchoolStatus == 1)
  165. {
  166. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  167. }
  168. if (inSchoolStatus == 0)
  169. {
  170. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  171. }
  172. }
  173. var query = StudentPunishDAL.Value.GetStudentPunishViewQueryable(expStudentPunish, expStudent);
  174. if (campusID.HasValue)
  175. {
  176. query = query.Where(x => x.CampusID == campusID);
  177. }
  178. if (collegeID.HasValue)
  179. {
  180. query = query.Where(x => x.CollegeID == collegeID);
  181. }
  182. if (gradeID.HasValue)
  183. {
  184. query = query.Where(x => x.GradeID == gradeID);
  185. }
  186. if (standardID.HasValue)
  187. {
  188. query = query.Where(x => x.StandardID == standardID);
  189. }
  190. if (educationID.HasValue)
  191. {
  192. query = query.Where(x => x.EducationID == educationID);
  193. }
  194. if (learningformID.HasValue)
  195. {
  196. query = query.Where(x => x.LearningformID == learningformID);
  197. }
  198. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  199. {
  200. var LearnSystems = Convert.ToDecimal(learnSystem);
  201. query = query.Where(x => x.LearnSystem == LearnSystems);
  202. }
  203. //查询条件
  204. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  205. {
  206. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  207. }
  208. var result = this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query)).OrderBy(x => x.ClassmajorNo.Length)
  209. .ThenBy(x => x.ClassmajorNo).ThenBy(x => x.StudentNo.Length).ThenBy(x => x.StudentNo).ThenByDescending(x => x.SchoolyearValue).ToList();
  210. result.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name);
  211. return result;
  212. }
  213. /// <summary>
  214. /// 查询对应的学生处分信息View
  215. /// </summary>
  216. /// <param name="studentPunishID"></param>
  217. /// <returns></returns>
  218. public StudentPunishView GetStudentPunishView(Guid? studentPunishID)
  219. {
  220. try
  221. {
  222. var query = StudentPunishDAL.Value.GetStudentPunishViewQueryable(x => x.StudentPunishID == studentPunishID).SingleOrDefault();
  223. return query;
  224. }
  225. catch (Exception ex)
  226. {
  227. throw new Exception(ex.Message);
  228. }
  229. }
  230. /// <summary>
  231. /// 编辑
  232. /// </summary>
  233. /// <param name="studentPunishView"></param>
  234. public void StudentPunishEdit(StudentPunishView studentPunishView)
  235. {
  236. try
  237. {
  238. var approveStatusList = this.GetStatusViewList();
  239. if (approveStatusList == null || approveStatusList.Count() <= 0)
  240. {
  241. throw new Exception("工作流平台中,学生处分流程未配置,请核查。");
  242. }
  243. var startStatusID = this.GetStartStatus();
  244. if (startStatusID == null)
  245. {
  246. throw new Exception("工作流平台中,学生处分流程开始环节未配置,请核查。");
  247. }
  248. var studentPunishVerify = StudentPunishDAL.Value.StudentPunishRepository.GetList(x => x.StudentPunishID != studentPunishView.StudentPunishID
  249. && x.SchoolyearID == studentPunishView.SchoolyearID && x.UserID == studentPunishView.UserID && x.PunishTypeID == studentPunishView.PunishTypeID).SingleOrDefault();
  250. if (studentPunishVerify == null)
  251. {
  252. if (studentPunishView.StudentPunishID != Guid.Empty)
  253. {
  254. var studentPunish = StudentPunishDAL.Value.StudentPunishRepository.GetList(x => x.StudentPunishID == studentPunishView.StudentPunishID).SingleOrDefault();
  255. if (studentPunish == null)
  256. {
  257. throw new Exception("数据有误,请核查。");
  258. }
  259. else
  260. {
  261. //表示修改
  262. studentPunish.PunishLevelID = studentPunishView.PunishLevelID;
  263. studentPunish.DocNo = studentPunishView.DocNo;
  264. studentPunish.PunishDate = studentPunishView.PunishDate;
  265. studentPunish.Reason = studentPunishView.Reason;
  266. studentPunish.CancelDocNo = studentPunishView.CancelDocNo;
  267. studentPunish.CancelDate = studentPunishView.CancelDate;
  268. SetModifyStatus(studentPunish);
  269. }
  270. }
  271. else
  272. {
  273. //表示新增
  274. var newStudentPunish = new EM_StudentPunish();
  275. newStudentPunish.StudentPunishID = Guid.NewGuid();
  276. newStudentPunish.SchoolyearID = studentPunishView.SchoolyearID;
  277. newStudentPunish.UserID = studentPunishView.UserID;
  278. newStudentPunish.PunishTypeID = studentPunishView.PunishTypeID;
  279. newStudentPunish.PunishLevelID = studentPunishView.PunishLevelID;
  280. newStudentPunish.DocNo = studentPunishView.DocNo;
  281. newStudentPunish.PunishDate = studentPunishView.PunishDate;
  282. newStudentPunish.Reason = studentPunishView.Reason;
  283. newStudentPunish.CancelDocNo = studentPunishView.CancelDocNo;
  284. newStudentPunish.CancelDate = studentPunishView.CancelDate;
  285. newStudentPunish.ApprovalStatus = startStatusID;
  286. SetNewStatus(newStudentPunish);
  287. UnitOfWork.Add(newStudentPunish);
  288. }
  289. }
  290. else
  291. {
  292. throw new Exception("已存在相同的学生处分信息,请核查。");
  293. }
  294. UnitOfWork.Commit();
  295. }
  296. catch (Exception ex)
  297. {
  298. throw new Exception(ex.Message);
  299. }
  300. }
  301. /// <summary>
  302. /// 删除
  303. /// </summary>
  304. /// <param name="studentPunishIDs"></param>
  305. /// <returns></returns>
  306. public bool StudentPunishDelete(List<Guid?> studentPunishIDs)
  307. {
  308. try
  309. {
  310. var startStatusID = this.GetStartStatus();
  311. if (startStatusID == null)
  312. {
  313. throw new Exception("工作流平台中,学生处分流程开始环节流程未配置,请核查");
  314. }
  315. var approvalStatusList = StudentPunishDAL.Value.StudentPunishRepository.GetList(x => studentPunishIDs.Contains(x.StudentPunishID)).Select(x => x.ApprovalStatus).ToList();
  316. foreach (var approvalStatus in approvalStatusList)
  317. {
  318. if (approvalStatus != startStatusID)
  319. {
  320. throw new Exception("只能对未提交状态的信息进行删除");
  321. }
  322. }
  323. UnitOfWork.Delete<EM_StudentPunish>(x => studentPunishIDs.Contains(x.StudentPunishID));
  324. return true;
  325. }
  326. catch (Exception)
  327. {
  328. throw;
  329. }
  330. }
  331. /// <summary>
  332. /// 提交
  333. /// </summary>
  334. /// <param name="studentPunishIDs"></param>
  335. /// <param name="userID"></param>
  336. /// <param name="comment"></param>
  337. /// <returns></returns>
  338. public string StudentPunishSubmit(List<Guid> studentPunishIDs, Guid userID, string comment = "")
  339. {
  340. try
  341. {
  342. var startStatusID = this.GetStartStatus();
  343. if (startStatusID == null)
  344. {
  345. throw new Exception("工作流平台中,学生处分流程开始环节流程未配置,请核查。");
  346. }
  347. var studentPunishList = StudentPunishDAL.Value.StudentPunishRepository.GetList(x => studentPunishIDs.Contains(x.StudentPunishID)).ToList();
  348. int success = 0;
  349. string tipMessage = null;
  350. var submitIDList = new List<Guid>();
  351. var approveIDList = new List<Guid>();
  352. foreach (var studentPunish in studentPunishList)
  353. {
  354. if (studentPunish.ApprovalStatus == startStatusID)
  355. {
  356. submitIDList.Add(studentPunish.StudentPunishID);
  357. }
  358. else
  359. {
  360. approveIDList.Add(studentPunish.StudentPunishID);
  361. }
  362. success++;
  363. }
  364. if (submitIDList.Count > 0)
  365. {
  366. this.StartUp(submitIDList, userID, comment);
  367. }
  368. if (approveIDList.Count > 0)
  369. {
  370. this.Approve(approveIDList, userID, Guid.Empty, comment);
  371. }
  372. tipMessage = success + "条";
  373. return tipMessage;
  374. }
  375. catch (Exception ex)
  376. {
  377. throw new Exception(ex.Message);
  378. }
  379. }
  380. /// <summary>
  381. /// 审核确定(批量)
  382. /// </summary>
  383. /// <param name="studentPunishIDs"></param>
  384. /// <param name="userID"></param>
  385. /// <param name="actionID"></param>
  386. /// <param name="comment"></param>
  387. public void StudentPunishApproveConfirm(List<Guid?> studentPunishIDs, Guid userID, Guid actionID, string comment)
  388. {
  389. try
  390. {
  391. var studentPunishList = StudentPunishDAL.Value.StudentPunishRepository.GetList(x => studentPunishIDs.Contains(x.StudentPunishID)).ToList();
  392. foreach (var studentPunishID in studentPunishIDs)
  393. {
  394. var studentPunish = studentPunishList.Where(x => x.StudentPunishID == studentPunishID).SingleOrDefault();
  395. if (studentPunish == null)
  396. {
  397. throw new Exception("数据有误,请核查。");
  398. }
  399. }
  400. this.Approve(studentPunishIDs.Select(x => x.Value).ToList(), userID, actionID, comment);
  401. }
  402. catch (Exception ex)
  403. {
  404. throw new Exception(ex.Message);
  405. }
  406. }
  407. /// <summary>
  408. /// 撤销确定(批量)
  409. /// </summary>
  410. /// <param name="studentPunishIDs"></param>
  411. /// <param name="userID"></param>
  412. /// <param name="comment"></param>
  413. public void StudentPunishCancelConfirm(List<Guid?> studentPunishIDs, Guid userID, string comment)
  414. {
  415. try
  416. {
  417. var studentPunishList = StudentPunishDAL.Value.StudentPunishRepository.GetList(x => studentPunishIDs.Contains(x.StudentPunishID)).ToList();
  418. foreach (var studentPunishID in studentPunishIDs)
  419. {
  420. var studentPunish = studentPunishList.Where(x => x.StudentPunishID == studentPunishID).SingleOrDefault();
  421. if (studentPunish == null)
  422. {
  423. throw new Exception("数据有误,请核查。");
  424. }
  425. }
  426. var actionID = this.GetActionView(studentPunishIDs[0].Value, userID).Where(x => (x.Description ?? "").Contains("[CANCEL]")).Select(x => x.ActionID).SingleOrDefault();
  427. this.Approve(studentPunishIDs.Select(x => x.Value).ToList(), userID, actionID, comment);
  428. }
  429. catch (Exception ex)
  430. {
  431. throw new Exception(ex.Message);
  432. }
  433. }
  434. /// <summary>
  435. /// 撤销确定(批量)
  436. /// </summary>
  437. /// <param name="studentPunishIDs"></param>
  438. /// <param name="userID"></param>
  439. /// <param name="cancelDocNo"></param>
  440. /// <param name="cancelDate"></param>
  441. /// <param name="comment"></param>
  442. public void StudentPunishCancelConfirm(List<Guid?> studentPunishIDs, Guid userID, string cancelDocNo, DateTime? cancelDate, string comment)
  443. {
  444. try
  445. {
  446. var newStudentPunishUpList = new List<EM_StudentPunish>();
  447. var studentPunishList = StudentPunishDAL.Value.StudentPunishRepository.GetList(x => studentPunishIDs.Contains(x.StudentPunishID)).ToList();
  448. foreach (var studentPunishID in studentPunishIDs)
  449. {
  450. var studentPunish = studentPunishList.Where(x => x.StudentPunishID == studentPunishID).SingleOrDefault();
  451. if (studentPunish == null)
  452. {
  453. throw new Exception("数据有误,请核查。");
  454. }
  455. studentPunish.CancelDocNo = cancelDocNo;
  456. studentPunish.CancelDate = cancelDate;
  457. this.SetModifyStatus(studentPunish);
  458. newStudentPunishUpList.Add(studentPunish);
  459. }
  460. var actionID = this.GetActionView(studentPunishIDs[0].Value, userID).Where(x => (x.Description ?? "").Contains("[CANCEL]")).Select(x => x.ActionID).SingleOrDefault();
  461. using (TransactionScope ts = new TransactionScope())
  462. {
  463. this.Approve(studentPunishIDs.Select(x => x.Value).ToList(), userID, actionID, comment);
  464. this.UnitOfWork.BatchUpdate(newStudentPunishUpList);
  465. ts.Complete();
  466. }
  467. }
  468. catch (Exception ex)
  469. {
  470. throw new Exception(ex.Message);
  471. }
  472. }
  473. /// <summary>
  474. /// 流程结束跳转函数(工作流平台中配置)
  475. /// </summary>
  476. /// <param name="studentPunishIDList"></param>
  477. /// <param name="userID"></param>
  478. public void OnApproveEnd(List<Guid> studentPunishIDList, Guid? userID)
  479. {
  480. throw new NotImplementedException();
  481. }
  482. }
  483. }