ChangeApproveServices.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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 ChangeApproveServices : BaseWorkflowServices<CF_DifferentDynamic>, IChangeApproveServices
  17. {
  18. public Lazy<StudentChangeDAL> StudentChangeDAL { get; set; }
  19. public Lazy<IInSchoolSettingServices> InSchoolSettingServices { get; set; }
  20. /// <summary>
  21. /// 数据范围
  22. /// </summary>
  23. public ChangeApproveServices()
  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> GetChangeApproveViewGrid(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 approveStatusList = this.GetApproveStatusViewList();
  50. var approveStatusIDList = approveStatusList.Select(x => x.ID).ToList();
  51. Expression<Func<CF_DifferentDynamic, bool>> expStudentChange = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  52. expStudentChange = expStudentChange.And(x => approveStatusIDList.Contains(x.ApprovalStatus));
  53. if (schoolyearID.HasValue)
  54. {
  55. expStudentChange = expStudentChange.And(x => x.SchoolyearID == schoolyearID);
  56. }
  57. if (changeTypeID.HasValue)
  58. {
  59. expStudentChange = expStudentChange.And(x => x.ChangeTypeID == changeTypeID);
  60. }
  61. if (approvalStatus.HasValue)
  62. {
  63. expStudentChange = expStudentChange.And(x => x.ApprovalStatus == approvalStatus);
  64. }
  65. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  66. if (classmajorID.HasValue)
  67. {
  68. expStudent = expStudent.And(x => x.ClassmajorID == classmajorID);
  69. }
  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 = StudentChangeDAL.Value.GetStudentChangeViewQueryable(expStudentChange, 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. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  113. {
  114. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  115. }
  116. var result = this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query))
  117. .OrderBy(x => x.SchoolyearValue).ThenBy(x => x.ChangeTypeID).ThenBy(x => x.GradeID).ThenBy(x => x.StandardID)
  118. .ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ThenBy(x => x.StudentNo)
  119. .OrderByDescending(x => x.ChangeDate).ToGridResultSet<StudentChangeView>(pageIndex, pageSize);
  120. result.rows.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name);
  121. return result;
  122. }
  123. /// <summary>
  124. /// 查询学籍异动审核信息List
  125. /// </summary>
  126. /// <param name="configuretView"></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="classmajorID"></param>
  135. /// <param name="schoolyearID"></param>
  136. /// <param name="changeTypeID"></param>
  137. /// <param name="inSchoolStatus"></param>
  138. /// <param name="approvalStatus"></param>
  139. /// <returns></returns>
  140. public IList<StudentChangeView> GetChangeApproveViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID,
  141. int? educationID, int? learningformID, string learnSystem, Guid? classmajorID, Guid? schoolyearID, int? changeTypeID, int? inSchoolStatus, int? approvalStatus)
  142. {
  143. var approveStatusList = this.GetApproveStatusViewList();
  144. var approveStatusIDList = approveStatusList.Select(x => x.ID).ToList();
  145. Expression<Func<CF_DifferentDynamic, bool>> expStudentChange = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  146. expStudentChange = expStudentChange.And(x => approveStatusIDList.Contains(x.ApprovalStatus));
  147. if (schoolyearID.HasValue)
  148. {
  149. expStudentChange = expStudentChange.And(x => x.SchoolyearID == schoolyearID);
  150. }
  151. if (changeTypeID.HasValue)
  152. {
  153. expStudentChange = expStudentChange.And(x => x.ChangeTypeID == changeTypeID);
  154. }
  155. if (approvalStatus.HasValue)
  156. {
  157. expStudentChange = expStudentChange.And(x => x.ApprovalStatus == approvalStatus);
  158. }
  159. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  160. if (classmajorID.HasValue)
  161. {
  162. expStudent = expStudent.And(x => x.ClassmajorID == classmajorID);
  163. }
  164. if (inSchoolStatus != null && inSchoolStatus > -1)
  165. {
  166. var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
  167. if (inSchoolStatus == 1)
  168. {
  169. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  170. }
  171. if (inSchoolStatus == 0)
  172. {
  173. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  174. }
  175. }
  176. var query = StudentChangeDAL.Value.GetStudentChangeViewQueryable(expStudentChange, expStudent);
  177. if (campusID.HasValue)
  178. {
  179. query = query.Where(x => x.CampusID == campusID);
  180. }
  181. if (collegeID.HasValue)
  182. {
  183. query = query.Where(x => x.CollegeID == collegeID);
  184. }
  185. if (gradeID.HasValue)
  186. {
  187. query = query.Where(x => x.GradeID == gradeID);
  188. }
  189. if (standardID.HasValue)
  190. {
  191. query = query.Where(x => x.StandardID == standardID);
  192. }
  193. if (educationID.HasValue)
  194. {
  195. query = query.Where(x => x.EducationID == educationID);
  196. }
  197. if (learningformID.HasValue)
  198. {
  199. query = query.Where(x => x.LearningformID == learningformID);
  200. }
  201. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  202. {
  203. var LearnSystems = Convert.ToDecimal(learnSystem);
  204. query = query.Where(x => x.LearnSystem == LearnSystems);
  205. }
  206. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  207. {
  208. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  209. }
  210. var result = this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query))
  211. .OrderBy(x => x.SchoolyearValue).ThenBy(x => x.ChangeTypeID).ThenBy(x => x.GradeID).ThenBy(x => x.StandardID)
  212. .ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ThenBy(x => x.StudentNo)
  213. .OrderByDescending(x => x.ChangeDate).ToList();
  214. result.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name);
  215. return result;
  216. }
  217. /// <summary>
  218. /// 查询对应的学籍异动信息View
  219. /// </summary>
  220. /// <param name="studentChangeID"></param>
  221. /// <returns></returns>
  222. public StudentChangeView GetStudentChangeView(Guid? studentChangeID)
  223. {
  224. try
  225. {
  226. Expression<Func<CF_DifferentDynamic, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  227. exp = exp.And(x => x.StudentChangeID == studentChangeID);
  228. var query = StudentChangeDAL.Value.GetStudentChangeViewQueryable(exp).SingleOrDefault();
  229. return query;
  230. }
  231. catch (Exception ex)
  232. {
  233. throw new Exception(ex.Message);
  234. }
  235. }
  236. /// <summary>
  237. /// 删除
  238. /// </summary>
  239. /// <param name="studentChangeIDs"></param>
  240. /// <returns></returns>
  241. public bool ChangeApproveDelete(List<Guid?> studentChangeIDs)
  242. {
  243. try
  244. {
  245. var workflowStatusViewList = this.GetStatusViewList();
  246. if (workflowStatusViewList == null || workflowStatusViewList.Count() <= 0)
  247. {
  248. throw new Exception("工作流平台中,学籍异动流程未配置,请核查。");
  249. }
  250. var approveStatusIDList = this.GetApproveStatusViewList().Select(x => x.ID).ToList();
  251. var studentChangeList = StudentChangeDAL.Value.StudentChangeRepository.GetList(x => studentChangeIDs.Contains(x.StudentChangeID)).ToList();
  252. foreach (var studentChange in studentChangeList)
  253. {
  254. if (!approveStatusIDList.Any(x => x == studentChange.ApprovalStatus))
  255. {
  256. throw new Exception("只能删除待审核状态的信息,请刷新页面再次尝试。");
  257. }
  258. }
  259. UnitOfWork.Delete<CF_DifferentDynamic>(x => studentChangeIDs.Contains(x.StudentChangeID));
  260. return true;
  261. }
  262. catch (Exception)
  263. {
  264. throw;
  265. }
  266. }
  267. /// <summary>
  268. /// 审核确定(批量)
  269. /// </summary>
  270. /// <param name="studentChangeIDs"></param>
  271. /// <param name="userID"></param>
  272. /// <param name="actionID"></param>
  273. /// <param name="comment"></param>
  274. public void ChangeApproveConfirm(List<Guid?> studentChangeIDs, Guid userID, Guid actionID, string comment)
  275. {
  276. try
  277. {
  278. var studentChangeList = StudentChangeDAL.Value.StudentChangeRepository.GetList(x => studentChangeIDs.Contains(x.StudentChangeID)).ToList();
  279. foreach (var studentChangeID in studentChangeIDs)
  280. {
  281. var studentChange = studentChangeList.Where(x => x.StudentChangeID == studentChangeID).SingleOrDefault();
  282. if (studentChange == null)
  283. {
  284. throw new Exception("数据有误,请核查");
  285. }
  286. else
  287. {
  288. if (!studentChange.SchoolyearID.HasValue)
  289. {
  290. throw new Exception("选择提交的数据存在异常(如:学年学期为空),请核查。");
  291. }
  292. if (!studentChange.ChangeTypeID.HasValue)
  293. {
  294. throw new Exception("选择提交的数据存在异常(如:异动类型为空),请核查。");
  295. }
  296. if (!studentChange.BeforeClassmajorID.HasValue)
  297. {
  298. throw new Exception("选择提交的数据存在异常(如:异动前班级为空),请核查。");
  299. }
  300. if (!studentChange.BeforeInSchoolStatusID.HasValue)
  301. {
  302. throw new Exception("选择提交的数据存在异常(如:异动前在校状态为空),请核查。");
  303. }
  304. if (!studentChange.AfterClassmajorID.HasValue)
  305. {
  306. throw new Exception("选择提交的数据存在异常(如:异动后班级为空),请核查。");
  307. }
  308. if (!studentChange.AfterInSchoolStatusID.HasValue)
  309. {
  310. throw new Exception("选择提交的数据存在异常(如:异动后在校状态为空),请核查。");
  311. }
  312. if (!studentChange.ChangeReasonID.HasValue)
  313. {
  314. throw new Exception("选择提交的数据存在异常(如:异动原因为空),请核查。");
  315. }
  316. if (!studentChange.ChangeDate.HasValue)
  317. {
  318. throw new Exception("选择提交的数据存在异常(如:异动日期为空),请核查。");
  319. }
  320. }
  321. }
  322. this.Approve(studentChangeIDs.Select(x => x.Value).ToList(), userID, actionID, comment);
  323. }
  324. catch (Exception ex)
  325. {
  326. throw new Exception(ex.Message);
  327. }
  328. }
  329. }
  330. }