CheckingResultServices.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using System.Transactions;
  7. using Bowin.Common.Linq;
  8. using Bowin.Common.Linq.Entity;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.StudentManage.OnlineChecking;
  12. using EMIS.DataLogic.StudentManage.OnlineChecking;
  13. using EMIS.CommonLogic.SystemServices;
  14. namespace EMIS.CommonLogic.StudentWeb.InfoCenter
  15. {
  16. public class CheckingResultServices : BaseWorkflowServices<CF_StudentContrast>, ICheckingResultServices
  17. {
  18. public Lazy<CheckingCollectDAL> CheckingCollectDAL { get; set; }
  19. /// <summary>
  20. /// 查询对应的校对结果信息CheckingHistoryView
  21. /// </summary>
  22. /// <param name="configuretView"></param>
  23. /// <param name="userID"></param>
  24. /// <param name="checkingTypeID"></param>
  25. /// <param name="approvalStatus"></param>
  26. /// <param name="pageIndex"></param>
  27. /// <param name="pageSize"></param>
  28. /// <returns></returns>
  29. public IGridResultSet<CheckingHistoryView> GetStudentCheckingResultViewGrid(ConfiguretView configuretView, Guid? userID, int? checkingTypeID, int? approvalStatus, int pageIndex, int pageSize)
  30. {
  31. var approveStatusList = this.GetStatusViewList();
  32. var startStatusID = this.GetStartStatus();
  33. Expression<Func<CF_StudentRecordChangeHistory, bool>> expStudentRecordChangeHistory = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  34. if (checkingTypeID.HasValue)
  35. {
  36. expStudentRecordChangeHistory = expStudentRecordChangeHistory.And(x => x.CheckingTypeID == checkingTypeID);
  37. }
  38. Expression<Func<CF_StudentContrast, bool>> expStudentContrast = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  39. expStudentContrast = expStudentContrast.And(x => x.UserID == userID);
  40. expStudentContrast = expStudentContrast.And(x => x.ApprovalStatus != startStatusID);
  41. if (approvalStatus.HasValue)
  42. {
  43. expStudentContrast = expStudentContrast.And(x => x.ApprovalStatus == approvalStatus);
  44. }
  45. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  46. expStudent = expStudent.And(x => x.UserID == userID);
  47. var query = CheckingCollectDAL.Value.GetCheckingHistoryViewQueryable(expStudentRecordChangeHistory, expStudentContrast, expStudent);
  48. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  49. {
  50. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  51. }
  52. var result = query.OrderBy(x => x.ColumnName).OrderByDescending(x => x.ApprovalTime).ToGridResultSet<CheckingHistoryView>(pageIndex, pageSize);
  53. result.rows.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name);
  54. return result;
  55. }
  56. /// <summary>
  57. /// 查询对应的校对结果信息List
  58. /// </summary>
  59. /// <param name="configuretView"></param>
  60. /// <param name="userID"></param>
  61. /// <param name="checkingTypeID"></param>
  62. /// <param name="approvalStatus"></param>
  63. /// <returns></returns>
  64. public IList<CheckingHistoryView> GetStudentCheckingResultViewList(ConfiguretView configuretView, Guid? userID, int? checkingTypeID, int? approvalStatus)
  65. {
  66. var approveStatusList = this.GetStatusViewList();
  67. var startStatusID = this.GetStartStatus();
  68. Expression<Func<CF_StudentRecordChangeHistory, bool>> expStudentRecordChangeHistory = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  69. if (checkingTypeID.HasValue)
  70. {
  71. expStudentRecordChangeHistory = expStudentRecordChangeHistory.And(x => x.CheckingTypeID == checkingTypeID);
  72. }
  73. Expression<Func<CF_StudentContrast, bool>> expStudentContrast = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  74. expStudentContrast = expStudentContrast.And(x => x.UserID == userID);
  75. expStudentContrast = expStudentContrast.And(x => x.ApprovalStatus != startStatusID);
  76. if (approvalStatus.HasValue)
  77. {
  78. expStudentContrast = expStudentContrast.And(x => x.ApprovalStatus == approvalStatus);
  79. }
  80. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  81. expStudent = expStudent.And(x => x.UserID == userID);
  82. var query = CheckingCollectDAL.Value.GetCheckingHistoryViewQueryable(expStudentRecordChangeHistory, expStudentContrast, expStudent);
  83. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  84. {
  85. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  86. }
  87. var result = query.OrderBy(x => x.ColumnName).OrderByDescending(x => x.ApprovalTime).ToList();
  88. result.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name);
  89. return result;
  90. }
  91. /// <summary>
  92. /// 查询对应的校对结果信息CheckingHistoryView
  93. /// </summary>
  94. /// <param name="studentRecordChangeHistoryID"></param>
  95. /// <returns></returns>
  96. public CheckingHistoryView GetStudentCheckingResultView(Guid? studentRecordChangeHistoryID)
  97. {
  98. try
  99. {
  100. Expression<Func<CF_StudentRecordChangeHistory, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  101. exp = exp.And(x => x.StudentRecordChangeHistoryID == studentRecordChangeHistoryID);
  102. var query = CheckingCollectDAL.Value.GetCheckingHistoryViewQueryable(exp).SingleOrDefault();
  103. return query;
  104. }
  105. catch (Exception ex)
  106. {
  107. throw new Exception(ex.Message);
  108. }
  109. }
  110. /// <summary>
  111. /// 撤消
  112. /// </summary>
  113. /// <param name="studentRecordChangeHistoryIDs"></param>
  114. /// <param name="userID"></param>
  115. /// <returns></returns>
  116. public bool StudentCheckingResultCancel(List<Guid?> studentRecordChangeHistoryIDs, Guid userID)
  117. {
  118. try
  119. {
  120. var checkingHistoryViewList = CheckingCollectDAL.Value.GetCheckingHistoryViewQueryable(x => studentRecordChangeHistoryIDs.Contains(x.StudentRecordChangeHistoryID)).ToList();
  121. var studentContrastIDList = checkingHistoryViewList.Select(x => x.StudentContrastID).Distinct().ToList();
  122. var studentRecordChangeHistoryList = CheckingCollectDAL.Value.StudentRecordChangeHistoryRepository.GetList(x => studentContrastIDList.Contains(x.StudentContrastID)).ToList();
  123. var studentCstList = CheckingCollectDAL.Value.StudentContrastRepository.GetList(x => studentContrastIDList.Contains(x.StudentContrastID), (x => x.CF_StudentProfileContrast), (x => x.CF_StudentContactContrast), (x => x.CF_StudentAccountContrast), (x => x.CF_RecruitstudentsContrast), (x => x.Sys_UserContrast)).ToList();
  124. bool isUserCst = false;
  125. bool isStudentCst = false;
  126. bool isStuProfileCst = false;
  127. bool isStuContactCst = false;
  128. bool isStuAccountCst = false;
  129. bool isStuRecruitCst = false;
  130. List<Guid> studentContrastIDCalList = new List<Guid>();
  131. List<Sys_UserContrast> userCstUpList = new List<Sys_UserContrast>();
  132. List<CF_StudentContrast> studentCstUpList = new List<CF_StudentContrast>();
  133. List<CF_StudentProfileContrast> studentProfileCstUpList = new List<CF_StudentProfileContrast>();
  134. List<CF_StudentContactContrast> studentContactCstUpList = new List<CF_StudentContactContrast>();
  135. List<CF_StudentAccountContrast> studentAccountCstUpList = new List<CF_StudentAccountContrast>();
  136. List<CF_RecruitstudentsContrast> recruitstudentsCstUpList = new List<CF_RecruitstudentsContrast>();
  137. var checkingHistoryViewGroupByDictionary = checkingHistoryViewList.GroupBy(x => x.StudentContrastID).ToDictionary(x => x.Key.Value, x => x.DefaultIfEmpty());
  138. foreach (var checkingHistoryViewGroupBy in checkingHistoryViewGroupByDictionary)
  139. {
  140. if (!studentContrastIDCalList.Any(x => x == checkingHistoryViewGroupBy.Key))
  141. {
  142. var stuHisList = studentRecordChangeHistoryList.Where(x => x.StudentContrastID == checkingHistoryViewGroupBy.Key && !studentRecordChangeHistoryIDs.Contains(x.StudentRecordChangeHistoryID)).ToList();
  143. if (stuHisList != null && stuHisList.Count() > 0)
  144. {
  145. isUserCst = false;
  146. isStudentCst = false;
  147. isStuProfileCst = false;
  148. isStuContactCst = false;
  149. isStuAccountCst = false;
  150. isStuRecruitCst = false;
  151. var studentCst = studentCstList.Where(x => x.StudentContrastID == checkingHistoryViewGroupBy.Key).SingleOrDefault();
  152. foreach (var checkingHistoryView in checkingHistoryViewGroupBy.Value)
  153. {
  154. var userCstProperty = typeof(Sys_UserContrast).GetProperties().Where(x => x.Name.ToLower() == checkingHistoryView.ColumnName.ToLower()).SingleOrDefault();
  155. if (userCstProperty != null)
  156. {
  157. userCstProperty.SetValue(studentCst.Sys_UserContrast, checkingHistoryView.CheckingBeforeValue, null);
  158. isUserCst = true;
  159. }
  160. var studentCstProperty = typeof(CF_StudentContrast).GetProperties().Where(x => x.Name.ToLower() == checkingHistoryView.ColumnName.ToLower()).SingleOrDefault();
  161. if (studentCstProperty != null)
  162. {
  163. studentCstProperty.SetValue(studentCst, checkingHistoryView.CheckingBeforeValue, null);
  164. isStudentCst = true;
  165. }
  166. var studentProfileCstProperty = typeof(CF_StudentProfileContrast).GetProperties().Where(x => x.Name.ToLower() == checkingHistoryView.ColumnName.ToLower()).SingleOrDefault();
  167. if (studentProfileCstProperty != null)
  168. {
  169. studentProfileCstProperty.SetValue(studentCst.CF_StudentProfileContrast, checkingHistoryView.CheckingBeforeValue, null);
  170. isStuProfileCst = true;
  171. }
  172. var studentContactCstProperty = typeof(CF_StudentContactContrast).GetProperties().Where(x => x.Name.ToLower() == checkingHistoryView.ColumnName.ToLower()).SingleOrDefault();
  173. if (studentContactCstProperty != null)
  174. {
  175. studentContactCstProperty.SetValue(studentCst.CF_StudentContactContrast, checkingHistoryView.CheckingBeforeValue, null);
  176. isStuContactCst = true;
  177. }
  178. var studentAccountCstProperty = typeof(CF_StudentAccountContrast).GetProperties().Where(x => x.Name.ToLower() == checkingHistoryView.ColumnName.ToLower()).SingleOrDefault();
  179. if (studentAccountCstProperty != null)
  180. {
  181. studentAccountCstProperty.SetValue(studentCst.CF_StudentAccountContrast, checkingHistoryView.CheckingBeforeValue, null);
  182. isStuAccountCst = true;
  183. }
  184. var recruitstudentsCstProperty = typeof(CF_RecruitstudentsContrast).GetProperties().Where(x => x.Name.ToLower() == checkingHistoryView.ColumnName.ToLower()).SingleOrDefault();
  185. if (recruitstudentsCstProperty != null)
  186. {
  187. recruitstudentsCstProperty.SetValue(studentCst.CF_RecruitstudentsContrast, checkingHistoryView.CheckingBeforeValue, null);
  188. isStuRecruitCst = true;
  189. }
  190. }
  191. if (isUserCst)
  192. {
  193. studentCst.Sys_UserContrast.ModifyUserID = userID;
  194. studentCst.Sys_UserContrast.ModifyTime = DateTime.Now;
  195. userCstUpList.Add(studentCst.Sys_UserContrast);
  196. }
  197. if (isStudentCst)
  198. {
  199. studentCst.ModifyUserID = userID;
  200. studentCst.ModifyTime = DateTime.Now;
  201. studentCstUpList.Add(studentCst);
  202. }
  203. if (isStuProfileCst)
  204. {
  205. studentCst.CF_StudentProfileContrast.ModifyUserID = userID;
  206. studentCst.CF_StudentProfileContrast.ModifyTime = DateTime.Now;
  207. studentProfileCstUpList.Add(studentCst.CF_StudentProfileContrast);
  208. }
  209. if (isStuContactCst)
  210. {
  211. studentCst.CF_StudentContactContrast.ModifyUserID = userID;
  212. studentCst.CF_StudentContactContrast.ModifyTime = DateTime.Now;
  213. studentContactCstUpList.Add(studentCst.CF_StudentContactContrast);
  214. }
  215. if (isStuAccountCst)
  216. {
  217. studentCst.CF_StudentAccountContrast.ModifyUserID = userID;
  218. studentCst.CF_StudentAccountContrast.ModifyTime = DateTime.Now;
  219. studentAccountCstUpList.Add(studentCst.CF_StudentAccountContrast);
  220. }
  221. if (isStuRecruitCst)
  222. {
  223. studentCst.CF_RecruitstudentsContrast.ModifyUserID = userID;
  224. studentCst.CF_RecruitstudentsContrast.ModifyTime = DateTime.Now;
  225. recruitstudentsCstUpList.Add(studentCst.CF_RecruitstudentsContrast);
  226. }
  227. }
  228. else
  229. {
  230. studentContrastIDCalList.Add(checkingHistoryViewGroupBy.Key);
  231. }
  232. }
  233. }
  234. TransactionOptions transactionOption = new TransactionOptions();
  235. transactionOption.IsolationLevel = System.Transactions.IsolationLevel.Serializable;
  236. transactionOption.Timeout = new TimeSpan(0, 3, 0);
  237. using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, transactionOption))
  238. {
  239. if (userCstUpList != null && userCstUpList.Count() > 0)
  240. {
  241. UnitOfWork.BatchUpdate(userCstUpList);
  242. }
  243. if (studentCstUpList != null && studentCstUpList.Count() > 0)
  244. {
  245. UnitOfWork.BatchUpdate(studentCstUpList);
  246. }
  247. if (studentProfileCstUpList != null && studentProfileCstUpList.Count() > 0)
  248. {
  249. UnitOfWork.BatchUpdate(studentProfileCstUpList);
  250. }
  251. if (studentContactCstUpList != null && studentContactCstUpList.Count() > 0)
  252. {
  253. UnitOfWork.BatchUpdate(studentContactCstUpList);
  254. }
  255. if (studentAccountCstUpList != null && studentAccountCstUpList.Count() > 0)
  256. {
  257. UnitOfWork.BatchUpdate(studentAccountCstUpList);
  258. }
  259. if (recruitstudentsCstUpList != null && recruitstudentsCstUpList.Count() > 0)
  260. {
  261. UnitOfWork.BatchUpdate(recruitstudentsCstUpList);
  262. }
  263. UnitOfWork.Delete<CF_StudentRecordChangeHistory>(x => studentRecordChangeHistoryIDs.Contains(x.StudentRecordChangeHistoryID));
  264. UnitOfWork.Delete<CF_RecruitstudentsSource>(x => studentContrastIDCalList.Contains(x.StudentContrastID));
  265. UnitOfWork.Delete<CF_RecruitstudentsContrast>(x => studentContrastIDCalList.Contains(x.StudentContrastID));
  266. UnitOfWork.Delete<CF_StudentAccountSource>(x => studentContrastIDCalList.Contains(x.StudentContrastID));
  267. UnitOfWork.Delete<CF_StudentAccountContrast>(x => studentContrastIDCalList.Contains(x.StudentContrastID));
  268. UnitOfWork.Delete<CF_StudentContactSource>(x => studentContrastIDCalList.Contains(x.StudentContrastID));
  269. UnitOfWork.Delete<CF_StudentContactContrast>(x => studentContrastIDCalList.Contains(x.StudentContrastID));
  270. UnitOfWork.Delete<CF_StudentProfileSource>(x => studentContrastIDCalList.Contains(x.StudentContrastID));
  271. UnitOfWork.Delete<CF_StudentProfileContrast>(x => studentContrastIDCalList.Contains(x.StudentContrastID));
  272. UnitOfWork.Delete<Sys_UserSource>(x => studentContrastIDCalList.Contains(x.StudentContrastID));
  273. UnitOfWork.Delete<Sys_UserContrast>(x => studentContrastIDCalList.Contains(x.StudentContrastID));
  274. UnitOfWork.Delete<CF_StudentSource>(x => studentContrastIDCalList.Contains(x.StudentContrastID));
  275. UnitOfWork.Delete<CF_StudentContrast>(x => studentContrastIDCalList.Contains(x.StudentContrastID));
  276. ts.Complete();
  277. }
  278. return true;
  279. }
  280. catch (Exception)
  281. {
  282. throw;
  283. }
  284. }
  285. }
  286. }