CollegeScheduleApprovalServices.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.SchedulingManage.ScheduleApproval;
  6. using EMIS.ViewModel.SchedulingManage.ScheduleApproval;
  7. using EMIS.Entities;
  8. using System.Linq.Expressions;
  9. using EMIS.ViewModel;
  10. using Bowin.Common.Linq;
  11. using Bowin.Common.Linq.Entity;
  12. using EMIS.CommonLogic.SystemServices;
  13. using EMIS.Utility.FormValidate;
  14. using EMIS.DataLogic.SchedulingManage.SchedulingSettings;
  15. namespace EMIS.CommonLogic.SchedulingManage.ScheduleApproval
  16. {
  17. public class CollegeScheduleApprovalServices : BaseWorkflowServices<ES_CollegeScheduleStatus>, ICollegeScheduleApprovalServices
  18. {
  19. public CollegeScheduleApprovalDAL collegeScheduleApprovalDAL { get; set; }
  20. public CollegePriorityDAL CollegePriorityDAL { get; set; }
  21. public IGridResultSet<CollegeScheduleApprovalView> GetCollegeScheduleApprovalViewGrid(Guid? SchoolyearID, Guid? collegeID, int? approvalStatus, int pageIndex, int pageSize)
  22. {
  23. var status = this.GetStatusViewList();
  24. Expression<Func<CF_College, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  25. Expression<Func<ES_CollegeScheduleStatus, bool>> exp1 = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  26. if (SchoolyearID != null)
  27. exp1 = exp1.And(x => x.SchoolyearID == SchoolyearID);
  28. if (collegeID != null)
  29. exp = exp.And(x => x.CollegeID == collegeID);
  30. //if (approvalStatus != null)
  31. //{
  32. // if (approvalStatus == (int)EMIS.ViewModel.ES_CollegeScheduleStatusCode.NotSubmited)
  33. // exp1 = exp1.And(x => x.RecordStatus == approvalStatus || x.RecordStatus == null);
  34. // else
  35. // exp1 = exp1.And(x => x.RecordStatus == approvalStatus);
  36. //}
  37. var query = this.GetQueryByDataRangeByCollege(collegeScheduleApprovalDAL.GetCollegeScheduleApprovalViewQueryable(exp, exp1));
  38. if (approvalStatus != null)
  39. {
  40. if (approvalStatus == (int)EMIS.ViewModel.ES_CollegeScheduleStatusCode.NotSubmited)
  41. query = query.Where(x => x.RecordStatus == approvalStatus || x.RecordStatus == null);
  42. else
  43. query = query.Where(x => x.RecordStatus == approvalStatus);
  44. }
  45. var result = query.OrderBy(x => x.CollegeNo).ThenByDescending(x => x.CreateTime).ToGridResultSet<CollegeScheduleApprovalView>(pageIndex, pageSize);
  46. result.rows.ForEach(x => {
  47. x.CollegeScheduleStatusID = x.CollegeScheduleStatusID ?? Guid.Empty;
  48. x.RecordStatus = x.RecordStatus ?? (int)EMIS.ViewModel.ES_CollegeScheduleStatusCode.NotSubmited;
  49. x.StatusName = status.FirstOrDefault(w => w.ID == x.RecordStatus).Name;
  50. });
  51. return result;
  52. }
  53. public List<CollegeScheduleApprovalView> GetCollegeScheduleApprovalViewList(IList<ViewModel.EducationSchedule.CollegeSchoolyearView> collegeAndSchoolyearList,
  54. bool isNeedDataRange = true)
  55. {
  56. var status = this.GetStatusViewList();
  57. Expression<Func<CF_College, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  58. Expression<Func<ES_CollegeScheduleStatus, bool>> exp1 = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  59. var query = collegeScheduleApprovalDAL.GetCollegeScheduleApprovalViewQueryable(exp, exp1);
  60. if (isNeedDataRange)
  61. {
  62. query = this.GetQueryByDataRangeByCollege(query);
  63. }
  64. try
  65. {
  66. var result = query
  67. .SelectByKeys(collegeAndSchoolyearList).OrderBy(x => x.CollegeNo).ThenByDescending(x => x.CreateTime).ToList();
  68. result.ForEach(x => x.StatusName = status.FirstOrDefault(w => w.ID == x.RecordStatus).Name);
  69. return result;
  70. }
  71. catch (Exception)
  72. {
  73. throw;
  74. }
  75. }
  76. public bool Submit(List<Guid?> collegeScheduleStatusIDs, List<Guid?> collegeIDs, Guid schoolYearID)
  77. {
  78. try
  79. {
  80. int i = 0;
  81. string allMessage = "";
  82. List<Guid> submitCollegeScheduleStatusIDList = new List<Guid>();
  83. for (i = 0; i < collegeIDs.Count; i++)
  84. {
  85. var collegeID = collegeIDs[i];
  86. var collegeScheduleStatus = this.collegeScheduleApprovalDAL.collegeScheduleStatusRepository
  87. .GetList(x => x.SchoolyearID == schoolYearID && x.CollegeID == collegeID, (x => x.CF_College)).FirstOrDefault();
  88. if (collegeScheduleStatus != null)
  89. {
  90. if (collegeScheduleStatus.RecordStatus != (int)ES_CollegeScheduleStatusCode.NotSubmited)
  91. {
  92. allMessage += collegeScheduleStatus.CF_College.Name + "的课表已经提交,无需重复提交。";
  93. continue;
  94. }
  95. SetModifyStatus(collegeScheduleStatus);
  96. }
  97. else
  98. {
  99. collegeScheduleStatus = new ES_CollegeScheduleStatus();
  100. collegeScheduleStatus.CollegeScheduleStatusID = Guid.NewGuid();
  101. collegeScheduleStatus.CollegeID = collegeIDs[i];
  102. collegeScheduleStatus.SchoolyearID = schoolYearID;
  103. SetNewStatus(collegeScheduleStatus);
  104. collegeScheduleStatus.RecordStatus = (int)ES_CollegeScheduleStatusCode.NotSubmited;
  105. UnitOfWork.Add(collegeScheduleStatus);
  106. }
  107. this.UnitOfWork.Commit();
  108. submitCollegeScheduleStatusIDList.Add(collegeScheduleStatus.CollegeScheduleStatusID);
  109. }
  110. this.StartUp(submitCollegeScheduleStatusIDList, CustomPrincipal.Current.UserID);
  111. if (allMessage != "")
  112. {
  113. throw new Exception(allMessage);
  114. }
  115. return true;
  116. }
  117. catch (Exception)
  118. {
  119. throw;
  120. }
  121. }
  122. public bool Approve(List<Guid> collegeScheduleStatusIDs)
  123. {
  124. try
  125. {
  126. var startStatus = this.GetStartStatus();
  127. var endStatus = this.GetCorrectEndStatus();
  128. var collegeScheduleStatusList = this.collegeScheduleApprovalDAL.GetCollegeScheduleApprovalViewQueryable((x => true),
  129. (x => collegeScheduleStatusIDs.Contains(x.CollegeScheduleStatusID))).ToList();
  130. if (collegeScheduleStatusIDs.Count == 0)
  131. {
  132. return true;
  133. }
  134. var appproveList = collegeScheduleStatusIDs.Where(x => false).Select(x => new { ID = x, ActionID = Guid.Empty }).ToList();
  135. foreach (var id in collegeScheduleStatusIDs)
  136. {
  137. var collegeScheduleStatus = collegeScheduleStatusList
  138. .Where(x => x.CollegeScheduleStatusID == id).FirstOrDefault();
  139. if (!collegeScheduleStatus.RecordStatus.HasValue || collegeScheduleStatus.RecordStatus == startStatus)
  140. {
  141. throw new Exception(collegeScheduleStatus.CollegeName + "的课表目前并未提交,请先提交后再进行审核。");
  142. }
  143. //if (collegeScheduleStatus.RecordStatus == endStatus)
  144. //{
  145. // throw new Exception(collegeScheduleStatus.CollegeName + "的课表目前已形成正式课表,无需审核,教务管理员可以使用撤销功能退回给院系所重新提交。");
  146. //}
  147. var actionList = this.GetActionView(id, CustomPrincipal.Current.UserID).Where(x => x.ActionName == "同意").ToList();
  148. //collegeScheduleStatus.RecordStatus = (int)ES_CollegeScheduleStatusCode.NotSubmited;
  149. var action = actionList.FirstOrDefault();
  150. if (action == null)
  151. {
  152. throw new Exception(collegeScheduleStatus.CollegeName + "的课表所在的环节并无审核流程,无法审核。");
  153. }
  154. appproveList.Add(new { ID = id, ActionID = action.ActionID });
  155. }
  156. appproveList.GroupBy(x => x.ActionID).ToList().ForEach(x => this.Approve(x.Select(w => w.ID).ToList(), CustomPrincipal.Current.UserID, x.Key));
  157. //this.UnitOfWork.Commit();
  158. return true;
  159. }
  160. catch (Exception)
  161. {
  162. throw;
  163. }
  164. }
  165. public bool ReturnBack(List<Guid> collegeScheduleStatusIDs)
  166. {
  167. try
  168. {
  169. var appproveList = collegeScheduleStatusIDs.Where(x => false).Select(x => new { ID = x, ActionID = Guid.Empty }).ToList();
  170. foreach (var id in collegeScheduleStatusIDs)
  171. {
  172. var actionList = this.GetActionView(id, CustomPrincipal.Current.UserID).Where(x => x.ActionName == "不同意" || x.ActionName == "退回").ToList();
  173. //var collegeScheduleStatus = this.collegeScheduleApprovalDAL.collegeScheduleStatusRepository.GetList(x => x.CollegeScheduleStatusID == id).FirstOrDefault();
  174. //collegeScheduleStatus.RecordStatus = (int)ES_CollegeScheduleStatusCode.NotSubmited;
  175. var action = actionList.FirstOrDefault();
  176. if (action == null)
  177. {
  178. throw new Exception("该环节不能退回。");
  179. }
  180. appproveList.Add(new { ID = id, ActionID = action.ActionID });
  181. }
  182. //this.UnitOfWork.Commit();
  183. appproveList.GroupBy(x => x.ActionID).ToList().ForEach(x => this.Approve(x.Select(w => w.ID).ToList(), CustomPrincipal.Current.UserID, x.Key));
  184. return true;
  185. }
  186. catch (Exception)
  187. {
  188. throw;
  189. }
  190. }
  191. }
  192. }