BatchQuitServices.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. using EMIS.Utility;
  17. namespace EMIS.CommonLogic.Students
  18. {
  19. public class BatchQuitServices : BaseWorkflowServices<CF_DifferentDynamic>, IBatchQuitServices
  20. {
  21. public Lazy<IDifferentDynamicServices> DifferentDynamicServices { get; set; }
  22. public Lazy<ISchoolYearServices> SchoolYearServices { get; set; }
  23. public DifferentDynamicDAL DifferentDynamicDAL { get; set; }
  24. public IGridResultSet<DifferentDynamicView> GetDifferentDynamicViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID,
  25. Guid? collegeID, int? year, int? standard, int? education, int? learningform, int? differentDynamicStatus, int pageIndex, int pageSize)
  26. {
  27. var statusList = this.GetStatusViewList();
  28. Expression<Func<CF_DifferentDynamic, bool>> filter = (x => x.ChangeApplyTypeID == (int)CF_ChangeApplyType.BatchQuit);
  29. Expression<Func<CF_College, bool>> collegeFilter = (x => true);
  30. Expression<Func<CF_Facultymajor, bool>> facultyFilter = (x => true);
  31. Expression<Func<CF_Grademajor, bool>> gradeFilter = (x => true);
  32. if (schoolyearID.HasValue)
  33. {
  34. filter = filter.And(x => x.SchoolyearID == schoolyearID);
  35. }
  36. if (campusID.HasValue)
  37. {
  38. collegeFilter = collegeFilter.And(x => x.CampusID == campusID);
  39. }
  40. if (collegeID.HasValue)
  41. {
  42. collegeFilter = collegeFilter.And(x => x.CollegeID == collegeID);
  43. }
  44. if (year.HasValue)
  45. {
  46. gradeFilter = gradeFilter.And(x => x.GradeID == year);
  47. }
  48. if (standard.HasValue)
  49. {
  50. facultyFilter = facultyFilter.And(x => x.StandardID == standard);
  51. }
  52. if (education.HasValue)
  53. {
  54. facultyFilter = facultyFilter.And(x => x.EducationID == education);
  55. }
  56. if (learningform.HasValue)
  57. {
  58. facultyFilter = facultyFilter.And(x => x.LearningformID == learningform);
  59. }
  60. if (differentDynamicStatus.HasValue)
  61. {
  62. filter = filter.And(x => x.ApprovalStatus == differentDynamicStatus);
  63. }
  64. var query = DifferentDynamicDAL.GetDifferentDynamicQueryable(filter, gradeFilter, facultyFilter, collegeFilter);
  65. query = GetQueryByDataRangeByCollege(query);
  66. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  67. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  68. query = query.OrderByDescending(w => w.SchoolyearCode).ThenByDescending(w => w.EntityCreateTime).ThenBy(w => w.LoginID);
  69. var result = query.ToGridResultSet(pageIndex, pageSize);
  70. result.rows.ForEach(x => x.ApprovalStatusName = statusList.Where(w => w.ID == x.EntityApprovalStatus).Select(w => w.Name).FirstOrDefault());
  71. return result;
  72. }
  73. public List<DifferentDynamicView> GetDifferentDynamicViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, int? year, int? standard, int? education, int? learningform, int? differentDynamicStatus)
  74. {
  75. var statusList = this.GetStatusViewList();
  76. Expression<Func<CF_DifferentDynamic, bool>> filter = (x => x.ChangeApplyTypeID == (int)CF_ChangeApplyType.BatchQuit);
  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 = DifferentDynamicDAL.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. var differentDynamicView = new DifferentDynamicView()
  127. {
  128. EntityID = Guid.Empty,
  129. SchoolyearID = schoolyear.SchoolYearID,
  130. UserID = student.UserID,
  131. DifferentDynamicType = (int)CF_ChangeType.Quit,
  132. Reason = (int)CF_ChangeReason.AutoQuit,
  133. InSchoolStatusID = student.InSchoolStatusID,
  134. StudentStatus = student.StudentStatus,
  135. StandardID = student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID,
  136. ClassmajorID = student.ClassmajorID,
  137. AfterInSchoolStatusID = (int)CF_InschoolStatus.Quited,
  138. AfterStudentStatus = (int)CF_StudentStatus.Cancel,
  139. ApplyTypeID = (int)CF_ChangeApplyType.BatchQuit,
  140. ApplyRemark = "自动退学",
  141. Remark = "自动退学"
  142. };
  143. DifferentDynamicServices.Value.AddOrUpdateDifferentDynamic(differentDynamicView);
  144. });
  145. }
  146. public void Approve(IList<Guid> idList)
  147. {
  148. var collegeApproveStatusList = this.GetStatusViewList()
  149. .Where(x => x.Description.Contains(Const.CF_STUDENTCHANGE_COLLEGEAPPROVE_FLAG)).ToList();
  150. var collegeApproveStatusIDList = collegeApproveStatusList.Select(x => x.ID).ToList();
  151. var differentDynamicList = this.DifferentDynamicDAL.DifferentDynamicRepository.GetList(x => idList.Contains(x.StudentChangeID)).ToList();
  152. ActionView actionView = null;
  153. Guid actionID;
  154. if (differentDynamicList.Any(x => !collegeApproveStatusIDList.Contains(x.ApprovalStatus)))
  155. {
  156. throw new Exception(string.Format("只能审核{0}状态的数据,所选的记录中有其他状态的数据,无法审核。",
  157. string.Join("、", collegeApproveStatusList.Select(x => x.Name))));
  158. }
  159. if (differentDynamicList.Count > 0)
  160. {
  161. actionView = this.GetActionView(differentDynamicList.First().StudentChangeID, CustomPrincipal.Current.UserID)
  162. .OrderBy(x => x.Sort).FirstOrDefault();
  163. actionID = actionView.ActionID;
  164. }
  165. else
  166. {
  167. return;
  168. }
  169. var differentDynamicIDList = differentDynamicList.Select(x => x.StudentChangeID).Distinct().ToList();
  170. this.Approve(differentDynamicIDList, CustomPrincipal.Current.UserID, actionID);
  171. }
  172. }
  173. }