BatchRepeatServices.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using EMIS.Entities;
  7. using EMIS.CommonLogic.SystemServices;
  8. using EMIS.DataLogic.Common.Students;
  9. using Bowin.Common.Linq;
  10. using Bowin.Common.Linq.Entity;
  11. using EMIS.ViewModel.DifferentDynamic;
  12. using EMIS.ViewModel;
  13. using EMIS.Utility.FormValidate;
  14. using EMIS.ViewModel.WorkflowManage;
  15. using EMIS.CommonLogic.CalendarManage;
  16. namespace EMIS.CommonLogic.Students
  17. {
  18. public class BatchRepeatServices : BaseWorkflowServices<CF_DifferentDynamic>, IBatchRepeatServices
  19. {
  20. public Lazy<IDifferentDynamicServices> DifferentDynamicServices { get; set; }
  21. public Lazy<ISchoolYearServices> SchoolYearServices { get; set; }
  22. public BatchRepeatDAL BatchRepeatDAL { get; set; }
  23. public IGridResultSet<DifferentDynamicView> GetDifferentDynamicViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID,
  24. Guid? collegeID, int? education, int? year, int? standard, int? learningform, int? differentDynamicStatus, int pageIndex, int pageSize)
  25. {
  26. var statusList = this.GetStatusViewList();
  27. Expression<Func<CF_DifferentDynamic, bool>> filter = (x => x.ChangeApplyTypeID == (int)CF_ChangeApplyType.BatchRepeat);
  28. Expression<Func<CF_College, bool>> collegeFilter = (x => true);
  29. Expression<Func<CF_Facultymajor, bool>> facultyFilter = (x => true);
  30. Expression<Func<CF_Grademajor, bool>> gradeFilter = (x => true);
  31. if (schoolyearID.HasValue)
  32. {
  33. filter = filter.And(x => x.SchoolyearID == schoolyearID);
  34. }
  35. if (campusID.HasValue)
  36. {
  37. collegeFilter = collegeFilter.And(x => x.CampusID == campusID);
  38. }
  39. if (collegeID.HasValue)
  40. {
  41. collegeFilter = collegeFilter.And(x => x.CollegeID == collegeID);
  42. }
  43. if (year.HasValue)
  44. {
  45. gradeFilter = gradeFilter.And(x => x.GradeID == year);
  46. }
  47. if (standard.HasValue)
  48. {
  49. facultyFilter = facultyFilter.And(x => x.StandardID == standard);
  50. }
  51. if (education.HasValue)
  52. {
  53. facultyFilter = facultyFilter.And(x => x.EducationID == education);
  54. }
  55. if (learningform.HasValue)
  56. {
  57. facultyFilter = facultyFilter.And(x => x.LearningformID == learningform);
  58. }
  59. if (differentDynamicStatus.HasValue)
  60. {
  61. filter = filter.And(x => x.ApprovalStatus == differentDynamicStatus);
  62. }
  63. var query = BatchRepeatDAL.GetDifferentDynamicQueryable(filter, gradeFilter, facultyFilter, collegeFilter);
  64. query = GetQueryByDataRangeByCollege(query);
  65. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  66. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  67. query = query.OrderByDescending(w => w.SchoolyearCode).ThenByDescending(w => w.EntityCreateTime).ThenBy(w => w.LoginID);
  68. var result = query.ToGridResultSet(pageIndex, pageSize);
  69. result.rows.ForEach(x => x.ApprovalStatusName = statusList.Where(w => w.ID == x.EntityApprovalStatus).Select(w => w.Name).FirstOrDefault());
  70. return result;
  71. }
  72. public List<DifferentDynamicView> GetDifferentDynamicViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID,
  73. int? education, int? year, int? standard, int? learningform, int? differentDynamicStatus)
  74. {
  75. var statusList = this.GetStatusViewList();
  76. Expression<Func<CF_DifferentDynamic, bool>> filter = (x => x.ChangeApplyTypeID == (int)CF_ChangeApplyType.BatchRepeat);
  77. Expression<Func<CF_College, bool>> collegeFilter = (x => true);
  78. Expression<Func<CF_Facultymajor, bool>> facultyFilter = (x => true);
  79. Expression<Func<CF_Grademajor, bool>> gradeFilter = (x => true);
  80. if (schoolyearID.HasValue)
  81. {
  82. filter = filter.And(x => x.SchoolyearID == schoolyearID);
  83. }
  84. if (campusID.HasValue)
  85. {
  86. collegeFilter = collegeFilter.And(x => x.CampusID == campusID);
  87. }
  88. if (collegeID.HasValue)
  89. {
  90. collegeFilter = collegeFilter.And(x => x.CollegeID == collegeID);
  91. }
  92. if (year.HasValue)
  93. {
  94. gradeFilter = gradeFilter.And(x => x.GradeID == year);
  95. }
  96. if (standard.HasValue)
  97. {
  98. facultyFilter = facultyFilter.And(x => x.StandardID == standard);
  99. }
  100. if (education.HasValue)
  101. {
  102. facultyFilter = facultyFilter.And(x => x.EducationID == education);
  103. }
  104. if (learningform.HasValue)
  105. {
  106. facultyFilter = facultyFilter.And(x => x.LearningformID == learningform);
  107. }
  108. if (differentDynamicStatus.HasValue)
  109. {
  110. filter = filter.And(x => x.ApprovalStatus == differentDynamicStatus);
  111. }
  112. var query = BatchRepeatDAL.GetDifferentDynamicQueryable(filter, gradeFilter, facultyFilter, collegeFilter);
  113. query = GetQueryByDataRangeByCollege(query);
  114. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  115. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  116. query = query.OrderByDescending(w => w.SchoolyearCode).ThenByDescending(w => w.EntityCreateTime).ThenBy(w => w.LoginID);
  117. var result = query.ToList();
  118. result.ForEach(x => x.ApprovalStatusName = statusList.Where(w => w.ID == x.EntityApprovalStatus).Select(w => w.Name).FirstOrDefault());
  119. return result;
  120. }
  121. public void BatchAddStudents(IList<Guid> studentIDList)
  122. {
  123. var studentList = StudentDAL.StudentRepository.GetList(x => studentIDList.Contains(x.UserID), (x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor)).ToList();
  124. var schoolyear = SchoolYearServices.Value.GetCurrentSchoolYear();
  125. studentList.ForEach(student =>
  126. {
  127. var differentDynamicView = new DifferentDynamicView()
  128. {
  129. EntityID = Guid.Empty,
  130. SchoolyearID = schoolyear.SchoolYearID,
  131. UserID = student.UserID,
  132. DifferentDynamicType = (int)CF_ChangeType.Repeat,
  133. Reason = (int)CF_ChangeReason.PoorPerformance,
  134. InSchoolStatusID = student.InSchoolStatusID,
  135. StudentStatus = student.StudentStatus,
  136. StandardID = student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID,
  137. ClassmajorID = student.ClassmajorID,
  138. ApplyTypeID = (int)CF_ChangeApplyType.BatchRepeat,
  139. ApplyRemark = "成绩太差,超过4门成绩不及格",
  140. Remark = "成绩太差,超过4门成绩不及格"
  141. };
  142. DifferentDynamicServices.Value.AddOrUpdateDifferentDynamic(differentDynamicView);
  143. });
  144. }
  145. public void Process(IList<Guid> idList)
  146. {
  147. var startStatus = this.GetStartStatus();
  148. var endStatusList = this.GetBackpointStatus();
  149. var correctEndStatus = this.GetCorrectEndStatus();
  150. var differentDynamicList = this.BatchRepeatDAL
  151. .GetBatchRepeatProcessView(x => idList.Contains(x.StudentChangeID)
  152. && x.AfterClassmajorID == null).ToList();
  153. ActionView actionView = null;
  154. if (differentDynamicList.Any(x => x.EntityApprovalStatus == startStatus || x.EntityApprovalStatus == correctEndStatus || endStatusList.Contains(x.EntityApprovalStatus))
  155. || idList.Any(x => !differentDynamicList.Any(w => w.EntityID == x)))
  156. {
  157. throw new Exception("只能审核已提交的数据,所选的记录中有其他状态的数据,无法审核。");
  158. }
  159. if (differentDynamicList.Any(x => x.AfterClassmajorID == null))
  160. {
  161. throw new Exception("学生" + string.Join("、", differentDynamicList.Where(x => x.AfterClassmajorID == null).Select(x => x.Name)) + "找不到可留级的班,请检查班级设置。");
  162. }
  163. if (differentDynamicList.Count > 0)
  164. {
  165. actionView = this.GetActionView(differentDynamicList.First().EntityID, CustomPrincipal.Current.UserID)
  166. .OrderBy(x => x.Sort).FirstOrDefault();
  167. }
  168. else
  169. {
  170. return;
  171. }
  172. foreach (var differentDynamic in differentDynamicList)
  173. {
  174. this.DifferentDynamicServices.Value.AddOrUpdateDifferentDynamic(differentDynamic);
  175. }
  176. var approveIDList = differentDynamicList.Select(x => x.EntityID).Distinct().ToList();
  177. this.Approve(approveIDList, CustomPrincipal.Current.UserID, actionView.ActionID);
  178. }
  179. public void Approve(IList<Guid> idList)
  180. {
  181. var startStatus = this.GetStartStatus();
  182. var endStatusList = this.GetBackpointStatus();
  183. var correctEndStatus = this.GetCorrectEndStatus();
  184. var differentDynamicList = this.BatchRepeatDAL
  185. .GetBatchRepeatProcessView(x => idList.Contains(x.StudentChangeID)
  186. && x.AfterClassmajorID != null).ToList();
  187. ActionView actionView = null;
  188. if (differentDynamicList.Any(x => x.EntityApprovalStatus == startStatus || x.EntityApprovalStatus == correctEndStatus || endStatusList.Contains(x.EntityApprovalStatus))
  189. || idList.Any(x => !differentDynamicList.Any(w => w.EntityID == x)))
  190. {
  191. throw new Exception("只能审核已处理的数据,所选的记录中有其他状态的数据,无法审核。");
  192. }
  193. if (differentDynamicList.Count > 0)
  194. {
  195. actionView = this.GetActionView(differentDynamicList.First().EntityID, CustomPrincipal.Current.UserID)
  196. .OrderBy(x => x.Sort).FirstOrDefault();
  197. }
  198. else
  199. {
  200. return;
  201. }
  202. var approveIDList = differentDynamicList.Select(x => x.EntityID).Distinct().ToList();
  203. this.Approve(approveIDList, CustomPrincipal.Current.UserID, actionView.ActionID);
  204. }
  205. }
  206. }