StudentEncourageServices.cs 22 KB

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