StudentChangeServices.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. namespace EMIS.CommonLogic.StudentWeb.Change
  14. {
  15. public class StudentChangeServices : BaseWorkflowServices<CF_DifferentDynamic>, IStudentChangeServices
  16. {
  17. public Lazy<StudentChangeDAL> StudentChangeDAL { get; set; }
  18. /// <summary>
  19. ///
  20. /// </summary>
  21. public StudentChangeServices()
  22. {
  23. }
  24. /// <summary>
  25. /// 查询学生异动申请信息View
  26. /// </summary>
  27. /// <param name="configuretView"></param>
  28. /// <param name="userID"></param>
  29. /// <param name="pageIndex"></param>
  30. /// <param name="pageSize"></param>
  31. /// <returns></returns>
  32. public IGridResultSet<StudentChangeView> GetStudentChangeViewGrid(ConfiguretView configuretView, Guid? userID, int pageIndex, int pageSize)
  33. {
  34. var applyStatusList = this.GetStatusViewList();
  35. Expression<Func<CF_DifferentDynamic, bool>> expStudentChange = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  36. expStudentChange = expStudentChange.And(x => x.UserID == userID);
  37. var query = StudentChangeDAL.Value.GetStudentChangeViewQueryable(expStudentChange);
  38. //查询条件
  39. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  40. {
  41. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  42. }
  43. var result = query.OrderByDescending(x => x.SchoolyearValue).ThenByDescending(x => x.ChangeDate).ToGridResultSet<StudentChangeView>(pageIndex, pageSize);
  44. result.rows.ForEach(x => x.ApprovalStatusName = applyStatusList.Where(w => w.ID == x.ApprovalStatus).Select(w => w.Name).FirstOrDefault());
  45. return result;
  46. }
  47. /// <summary>
  48. /// 查询学生异动申请信息List
  49. /// </summary>
  50. /// <param name="configuretView"></param>
  51. /// <param name="userID"></param>
  52. /// <returns></returns>
  53. public IList<StudentChangeView> GetStudentChangeViewList(ConfiguretView configuretView, Guid? userID)
  54. {
  55. var applyStatusList = this.GetStatusViewList();
  56. Expression<Func<CF_DifferentDynamic, bool>> expStudentChange = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  57. expStudentChange = expStudentChange.And(x => x.UserID == userID);
  58. var query = StudentChangeDAL.Value.GetStudentChangeViewQueryable(expStudentChange);
  59. //查询条件
  60. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  61. {
  62. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  63. }
  64. var result = query.OrderByDescending(x => x.SchoolyearValue).ThenByDescending(x => x.ChangeDate).ToList();
  65. result.ForEach(x => x.ApprovalStatusName = applyStatusList.Where(w => w.ID == x.ApprovalStatus).Select(w => w.Name).FirstOrDefault());
  66. return result;
  67. }
  68. /// <summary>
  69. /// 查询对应的学生异动信息View
  70. /// </summary>
  71. /// <param name="studentChangeID"></param>
  72. /// <returns></returns>
  73. public StudentChangeView GetStudentChangeView(Guid? studentChangeID)
  74. {
  75. try
  76. {
  77. Expression<Func<CF_DifferentDynamic, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  78. exp = exp.And(x => x.StudentChangeID == studentChangeID);
  79. var query = StudentChangeDAL.Value.GetStudentChangeViewQueryable(exp).SingleOrDefault();
  80. return query;
  81. }
  82. catch (Exception ex)
  83. {
  84. throw new Exception(ex.Message);
  85. }
  86. }
  87. /// <summary>
  88. /// 编辑
  89. /// </summary>
  90. /// <param name="studentChangeView"></param>
  91. public void StudentChangeEdit(StudentChangeView studentChangeView)
  92. {
  93. try
  94. {
  95. var workflowStatusViewList = this.GetStatusViewList();
  96. if (workflowStatusViewList == null || workflowStatusViewList.Count() <= 0)
  97. {
  98. throw new Exception("数据有误,请联系辅导员或学籍异动负责老师。");
  99. }
  100. var startStatusID = this.GetStartStatus();
  101. if (startStatusID == null)
  102. {
  103. throw new Exception("数据有误,请联系辅导员或学籍异动负责老师。");
  104. }
  105. var endStatusID = this.GetCorrectEndStatus();
  106. if (endStatusID == null)
  107. {
  108. throw new Exception("数据有误,请联系辅导员或学籍异动负责老师。");
  109. }
  110. var approveStatusIDList = this.GetApproveStatusViewList().Select(x => x.ID).ToList();
  111. var applyStatusIDList = workflowStatusViewList.Where(x => x.ID != endStatusID && !approveStatusIDList.Contains(x.ID)).Select(x => x.ID).ToList();
  112. var studentChangeVerify = StudentChangeDAL.Value.StudentChangeRepository.GetList(x => x.StudentChangeID != studentChangeView.StudentChangeID
  113. && x.UserID == studentChangeView.UserID && x.SchoolyearID == studentChangeView.SchoolyearID && x.ChangeTypeID == studentChangeView.ChangeTypeID).SingleOrDefault();
  114. if (studentChangeVerify == null)
  115. {
  116. if (studentChangeView.StudentChangeID != Guid.Empty)
  117. {
  118. var studentChange = StudentChangeDAL.Value.StudentChangeRepository.GetList(x => x.StudentChangeID == studentChangeView.StudentChangeID).SingleOrDefault();
  119. if (studentChange == null)
  120. {
  121. throw new Exception("数据有误,请联系辅导员或学籍异动负责老师。");
  122. }
  123. else
  124. {
  125. if (applyStatusIDList.Any(x => x == studentChange.ApprovalStatus))
  126. {
  127. studentChange.UserID = studentChangeView.UserID;
  128. studentChange.SchoolyearID = studentChangeView.SchoolyearID;
  129. studentChange.ChangeTypeID = studentChangeView.ChangeTypeID;
  130. studentChange.BeforeClassmajorID = studentChangeView.BeforeClassmajorID;
  131. studentChange.BeforeInSchoolStatusID = studentChangeView.BeforeInSchoolStatusID;
  132. studentChange.BeforeStudentStatus = studentChangeView.BeforeStudentStatus;
  133. studentChange.AfterClassmajorID = studentChangeView.AfterClassmajorID;
  134. studentChange.AfterInSchoolStatusID = studentChangeView.AfterInSchoolStatusID;
  135. studentChange.AfterStudentStatus = studentChangeView.AfterStudentStatus;
  136. studentChange.ReturnSchoolyearID = studentChangeView.ReturnSchoolyearID;
  137. studentChange.ChangeReasonID = studentChangeView.ChangeReasonID;
  138. studentChange.ChangeDate = studentChangeView.ChangeDate;
  139. studentChange.Description = studentChangeView.Description;
  140. studentChange.Remark = studentChangeView.Remark;
  141. SetModifyStatus(studentChange);
  142. }
  143. else
  144. {
  145. throw new Exception("只能修改未提交、已退回状态的信息,请核查。");
  146. }
  147. }
  148. }
  149. else
  150. {
  151. var newStudentChange = new CF_DifferentDynamic();
  152. newStudentChange.StudentChangeID = Guid.NewGuid();
  153. newStudentChange.UserID = studentChangeView.UserID;
  154. newStudentChange.SchoolyearID = studentChangeView.SchoolyearID;
  155. newStudentChange.ChangeTypeID = studentChangeView.ChangeTypeID;
  156. newStudentChange.BeforeClassmajorID = studentChangeView.BeforeClassmajorID;
  157. newStudentChange.BeforeInSchoolStatusID = studentChangeView.BeforeInSchoolStatusID;
  158. newStudentChange.BeforeStudentStatus = studentChangeView.BeforeStudentStatus;
  159. newStudentChange.AfterClassmajorID = studentChangeView.AfterClassmajorID;
  160. newStudentChange.AfterInSchoolStatusID = studentChangeView.AfterInSchoolStatusID;
  161. newStudentChange.AfterStudentStatus = studentChangeView.AfterStudentStatus;
  162. newStudentChange.ReturnSchoolyearID = studentChangeView.ReturnSchoolyearID;
  163. newStudentChange.ChangeApplyTypeID = (int)CF_ChangeApplyType.Normal;
  164. newStudentChange.ChangeReasonID = studentChangeView.ChangeReasonID;
  165. newStudentChange.ChangeDate = studentChangeView.ChangeDate;
  166. newStudentChange.Description = studentChangeView.Description;
  167. newStudentChange.ApprovalStatus = startStatusID;
  168. newStudentChange.Remark = studentChangeView.Remark;
  169. SetNewStatus(newStudentChange);
  170. UnitOfWork.Add(newStudentChange);
  171. }
  172. }
  173. else
  174. {
  175. throw new Exception("已存在相同的异动申请信息,请核查。");
  176. }
  177. UnitOfWork.Commit();
  178. }
  179. catch (Exception ex)
  180. {
  181. throw new Exception(ex.Message);
  182. }
  183. }
  184. /// <summary>
  185. /// 删除
  186. /// </summary>
  187. /// <param name="studentChangeIDs"></param>
  188. /// <returns></returns>
  189. public bool StudentChangeDelete(List<Guid?> studentChangeIDs)
  190. {
  191. try
  192. {
  193. var workflowStatusViewList = this.GetStatusViewList();
  194. if (workflowStatusViewList == null || workflowStatusViewList.Count() <= 0)
  195. {
  196. throw new Exception("数据有误,请联系辅导员或学籍异动负责老师。");
  197. }
  198. var startStatusID = this.GetStartStatus();
  199. if (startStatusID == null)
  200. {
  201. throw new Exception("数据有误,请联系辅导员或学籍异动负责老师。");
  202. }
  203. var endStatusID = this.GetCorrectEndStatus();
  204. if (endStatusID == null)
  205. {
  206. throw new Exception("数据有误,请联系辅导员或学籍异动负责老师。");
  207. }
  208. var approveStatusIDList = this.GetApproveStatusViewList().Select(x => x.ID).ToList();
  209. var applyStatusIDList = workflowStatusViewList.Where(x => x.ID != endStatusID && !approveStatusIDList.Contains(x.ID)).Select(x => x.ID).ToList();
  210. var studentChangeList = StudentChangeDAL.Value.StudentChangeRepository.GetList(x => studentChangeIDs.Contains(x.StudentChangeID)).ToList();
  211. foreach (var studentChange in studentChangeList)
  212. {
  213. if (!applyStatusIDList.Any(x => x == studentChange.ApprovalStatus))
  214. {
  215. throw new Exception("只能删除未提交、已退回状态的信息,请刷新页面再次尝试。");
  216. }
  217. }
  218. UnitOfWork.Delete<CF_DifferentDynamic>(x => studentChangeIDs.Contains(x.StudentChangeID));
  219. return true;
  220. }
  221. catch (Exception)
  222. {
  223. throw;
  224. }
  225. }
  226. /// <summary>
  227. /// 提交
  228. /// </summary>
  229. /// <param name="studentChangeIDs"></param>
  230. /// <param name="userID"></param>
  231. /// <param name="comment"></param>
  232. /// <returns></returns>
  233. public string StudentChangeSubmit(List<Guid> studentChangeIDs, Guid userID, string comment = "")
  234. {
  235. try
  236. {
  237. var startStatusID = this.GetStartStatus();
  238. if (startStatusID == null)
  239. {
  240. throw new Exception("数据有误,请联系辅导员或学籍异动负责老师。");
  241. }
  242. int success = 0;
  243. string tipMessage = null;
  244. var submitIDList = new List<Guid>();
  245. var approveIDList = new List<Guid>();
  246. var studentChangeList = StudentChangeDAL.Value.StudentChangeRepository.GetList(x => studentChangeIDs.Contains(x.StudentChangeID)).ToList();
  247. foreach (var studentChange in studentChangeList)
  248. {
  249. if (!studentChange.SchoolyearID.HasValue)
  250. {
  251. throw new Exception("选择提交的数据存在异常(如:学年学期为空),请核查。");
  252. }
  253. if (!studentChange.ChangeTypeID.HasValue)
  254. {
  255. throw new Exception("选择提交的数据存在异常(如:异动类型为空),请核查。");
  256. }
  257. if (!studentChange.BeforeClassmajorID.HasValue)
  258. {
  259. throw new Exception("选择提交的数据存在异常(如:异动前班级为空),请核查。");
  260. }
  261. if (!studentChange.BeforeInSchoolStatusID.HasValue)
  262. {
  263. throw new Exception("选择提交的数据存在异常(如:异动前在校状态为空),请核查。");
  264. }
  265. if (!studentChange.AfterClassmajorID.HasValue)
  266. {
  267. throw new Exception("选择提交的数据存在异常(如:异动后班级为空),请核查。");
  268. }
  269. if (!studentChange.AfterInSchoolStatusID.HasValue)
  270. {
  271. throw new Exception("选择提交的数据存在异常(如:异动后在校状态为空),请核查。");
  272. }
  273. if (!studentChange.ChangeReasonID.HasValue)
  274. {
  275. throw new Exception("选择提交的数据存在异常(如:异动原因为空),请核查。");
  276. }
  277. if (!studentChange.ChangeDate.HasValue)
  278. {
  279. throw new Exception("选择提交的数据存在异常(如:异动日期为空),请核查。");
  280. }
  281. if (studentChange.ApprovalStatus == startStatusID)
  282. {
  283. submitIDList.Add(studentChange.StudentChangeID);
  284. }
  285. else
  286. {
  287. approveIDList.Add(studentChange.StudentChangeID);
  288. }
  289. success++;
  290. }
  291. if (submitIDList.Count > 0)
  292. {
  293. this.StartUp(submitIDList, userID, comment);
  294. }
  295. if (approveIDList.Count > 0)
  296. {
  297. this.Approve(approveIDList, userID, Guid.Empty, comment);
  298. }
  299. tipMessage = success + "条";
  300. return tipMessage;
  301. }
  302. catch (Exception ex)
  303. {
  304. throw new Exception(ex.Message);
  305. }
  306. }
  307. }
  308. }