CompletionListServices.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using System.Text.RegularExpressions;
  7. using Bowin.Common.Utility;
  8. using Bowin.Common.Linq;
  9. using Bowin.Common.Linq.Entity;
  10. using EMIS.Entities;
  11. using EMIS.ViewModel;
  12. using EMIS.ViewModel.GraduationManage.GraduationManage;
  13. using EMIS.DataLogic.GraduationManage.GraduationManage;
  14. using EMIS.CommonLogic.CalendarManage;
  15. using EMIS.CommonLogic.SystemServices;
  16. using EMIS.CommonLogic.StudentManage.StudentStatistics;
  17. namespace EMIS.CommonLogic.GraduationManage.CompletionManage
  18. {
  19. public class CompletionListServices : BaseWorkflowServices<ER_GraduationApply>, ICompletionListServices
  20. {
  21. public GraduationApplyDAL GraduationApplyDAL { get; set; }
  22. public Lazy<IInSchoolSettingServices> InSchoolSettingServices { get; set; }
  23. public Lazy<ISchoolYearServices> SchoolYearServices { get; set; }
  24. /// <summary>
  25. /// 查询结业名单信息View
  26. /// </summary>
  27. /// <param name="configuretView"></param>
  28. /// <param name="gradSchoolyearID"></param>
  29. /// <param name="campusID"></param>
  30. /// <param name="collegeID"></param>
  31. /// <param name="yearID"></param>
  32. /// <param name="standardID"></param>
  33. /// <param name="educationID"></param>
  34. /// <param name="learningformID"></param>
  35. /// <param name="learnSystem"></param>
  36. /// <param name="graduationTypeID"></param>
  37. /// <param name="educationTypeID"></param>
  38. /// <param name="inSchoolStatus"></param>
  39. /// <param name="pageIndex"></param>
  40. /// <param name="pageSize"></param>
  41. /// <returns></returns>
  42. public IGridResultSet<GraduationApplyView> GetCompletionListViewGrid(ConfiguretView configuretView, Guid? gradSchoolyearID,
  43. Guid? campusID, Guid? collegeID, int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem,
  44. int? graduationTypeID, int? educationTypeID, int? inSchoolStatus, int pageIndex, int pageSize)
  45. {
  46. var approveStatusList = this.GetStatusViewList();
  47. var endApproveStatusID = this.GetCorrectEndStatus();
  48. //毕业申请
  49. Expression<Func<ER_GraduationApply, bool>> expGraduationApply = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  50. expGraduationApply = expGraduationApply.And(x => x.ApprovalStatus == endApproveStatusID);
  51. //毕业结论
  52. expGraduationApply = expGraduationApply.And(x => x.GraduationResult == (int)ER_GraduationResult.Completion);
  53. if (gradSchoolyearID.HasValue)
  54. {
  55. //毕业学期(实际的毕业学期)
  56. expGraduationApply = expGraduationApply.And(x => x.GraduatingSemesterID == gradSchoolyearID);
  57. }
  58. if (graduationTypeID.HasValue)
  59. {
  60. //毕业类型
  61. expGraduationApply = expGraduationApply.And(x => x.GraduationTypeID == graduationTypeID);
  62. }
  63. //学生信息
  64. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  65. if (inSchoolStatus != null && inSchoolStatus > -1)
  66. {
  67. var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
  68. if (inSchoolStatus == 1)
  69. {
  70. //表示在校
  71. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  72. }
  73. if (inSchoolStatus == 0)
  74. {
  75. //不在校
  76. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  77. }
  78. }
  79. ////在校状态(结业)
  80. //expStudent = expStudent.And(x => x.InSchoolStatusID == (int)CF_InschoolStatus.Complete);
  81. var query = GraduationApplyDAL.GetGraduationApplyViewQueryable(expGraduationApply, expStudent);
  82. if (campusID.HasValue)
  83. {
  84. query = query.Where(x => x.CampusID == campusID);
  85. }
  86. if (collegeID.HasValue)
  87. {
  88. query = query.Where(x => x.CollegeID == collegeID);
  89. }
  90. if (yearID.HasValue)
  91. {
  92. query = query.Where(x => x.SchoolyearID == yearID);
  93. }
  94. if (standardID.HasValue)
  95. {
  96. query = query.Where(x => x.StandardID == standardID);
  97. }
  98. if (educationID.HasValue)
  99. {
  100. query = query.Where(x => x.EducationID == educationID);
  101. }
  102. if (learningformID.HasValue)
  103. {
  104. query = query.Where(x => x.LearningformID == learningformID);
  105. }
  106. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  107. {
  108. var LearnSystems = Convert.ToDecimal(learnSystem);
  109. query = query.Where(x => x.LearnSystem == LearnSystems);
  110. }
  111. if (educationTypeID.HasValue)
  112. {
  113. //培养类型
  114. query = query.Where(x => x.EducationTypeID == educationTypeID);
  115. }
  116. //查询条件
  117. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  118. {
  119. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  120. }
  121. var result = this.GetQueryByDataRangeByCollege(query)
  122. .OrderBy(x => x.ClassNo.Length)
  123. .ThenBy(x => x.ClassNo).ThenBy(x => x.StudentNo.Length)
  124. .ThenBy(x => x.StudentNo).ThenBy(x => x.GraduatingSemesterValue)
  125. .ToGridResultSet<GraduationApplyView>(pageIndex, pageSize);
  126. result.rows.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name);
  127. return result;
  128. }
  129. /// <summary>
  130. /// 查询结业名单信息List
  131. /// </summary>
  132. /// <param name="configuretView"></param>
  133. /// <param name="gradSchoolyearID"></param>
  134. /// <param name="campusID"></param>
  135. /// <param name="collegeID"></param>
  136. /// <param name="yearID"></param>
  137. /// <param name="standardID"></param>
  138. /// <param name="educationID"></param>
  139. /// <param name="learningformID"></param>
  140. /// <param name="learnSystem"></param>
  141. /// <param name="graduationTypeID"></param>
  142. /// <param name="educationTypeID"></param>
  143. /// <param name="inSchoolStatus"></param>
  144. /// <returns></returns>
  145. public List<GraduationApplyView> GetCompletionListViewList(ConfiguretView configuretView, Guid? gradSchoolyearID,
  146. Guid? campusID, Guid? collegeID, int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem,
  147. int? graduationTypeID, int? educationTypeID, int? inSchoolStatus)
  148. {
  149. var approveStatusList = this.GetStatusViewList();
  150. var endApproveStatusID = this.GetCorrectEndStatus();
  151. //毕业申请
  152. Expression<Func<ER_GraduationApply, bool>> expGraduationApply = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  153. expGraduationApply = expGraduationApply.And(x => x.ApprovalStatus == endApproveStatusID);
  154. //毕业结论
  155. expGraduationApply = expGraduationApply.And(x => x.GraduationResult == (int)ER_GraduationResult.Completion);
  156. if (gradSchoolyearID.HasValue)
  157. {
  158. //毕业学期(实际的毕业学期)
  159. expGraduationApply = expGraduationApply.And(x => x.GraduatingSemesterID == gradSchoolyearID);
  160. }
  161. if (graduationTypeID.HasValue)
  162. {
  163. //毕业类型
  164. expGraduationApply = expGraduationApply.And(x => x.GraduationTypeID == graduationTypeID);
  165. }
  166. //学生信息
  167. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  168. if (inSchoolStatus != null && inSchoolStatus > -1)
  169. {
  170. var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
  171. if (inSchoolStatus == 1)
  172. {
  173. //表示在校
  174. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  175. }
  176. if (inSchoolStatus == 0)
  177. {
  178. //不在校
  179. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  180. }
  181. }
  182. ////在校状态(结业)
  183. //expStudent = expStudent.And(x => x.InSchoolStatusID == (int)CF_InschoolStatus.Complete);
  184. var query = GraduationApplyDAL.GetGraduationApplyViewQueryable(expGraduationApply, expStudent);
  185. if (campusID.HasValue)
  186. {
  187. query = query.Where(x => x.CampusID == campusID);
  188. }
  189. if (collegeID.HasValue)
  190. {
  191. query = query.Where(x => x.CollegeID == collegeID);
  192. }
  193. if (yearID.HasValue)
  194. {
  195. query = query.Where(x => x.SchoolyearID == yearID);
  196. }
  197. if (standardID.HasValue)
  198. {
  199. query = query.Where(x => x.StandardID == standardID);
  200. }
  201. if (educationID.HasValue)
  202. {
  203. query = query.Where(x => x.EducationID == educationID);
  204. }
  205. if (learningformID.HasValue)
  206. {
  207. query = query.Where(x => x.LearningformID == learningformID);
  208. }
  209. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  210. {
  211. var LearnSystems = Convert.ToDecimal(learnSystem);
  212. query = query.Where(x => x.LearnSystem == LearnSystems);
  213. }
  214. if (educationTypeID.HasValue)
  215. {
  216. //培养类型
  217. query = query.Where(x => x.EducationTypeID == educationTypeID);
  218. }
  219. //查询条件
  220. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  221. {
  222. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  223. }
  224. var result = this.GetQueryByDataRangeByCollege(query)
  225. .OrderBy(x => x.ClassNo.Length)
  226. .ThenBy(x => x.ClassNo).ThenBy(x => x.StudentNo.Length)
  227. .ThenBy(x => x.StudentNo).ThenBy(x => x.GraduatingSemesterValue)
  228. .ToList();
  229. result.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name);
  230. return result;
  231. }
  232. /// <summary>
  233. /// 查询对应的结业名单信息GraduationApplyView
  234. /// </summary>
  235. /// <param name="graduationApplyID"></param>
  236. /// <returns></returns>
  237. public GraduationApplyView GetCompletionListView(Guid? graduationApplyID)
  238. {
  239. try
  240. {
  241. var graduationListView = GraduationApplyDAL.GetGraduationApplyViewQueryable(x => x.GraduationApplyID == graduationApplyID)
  242. .SingleOrDefault();
  243. return graduationListView;
  244. }
  245. catch (Exception ex)
  246. {
  247. throw new Exception(ex.Message);
  248. }
  249. }
  250. /// <summary>
  251. /// 编辑(新增、修改,业务主键:学生信息ID、流程结束状态(已通过))
  252. /// </summary>
  253. /// <param name="graduationApplyView"></param>
  254. public void CompletionListEdit(GraduationApplyView graduationApplyView)
  255. {
  256. try
  257. {
  258. //查询对应的工作流程环节状态信息View
  259. var approveStatusList = this.GetStatusViewList();
  260. if (approveStatusList == null || approveStatusList.Count() <= 0)
  261. {
  262. throw new Exception("工作流平台中,毕业处理流程未配置,请核查。");
  263. }
  264. //查询工作流程开始环节状态
  265. var approveStartStatusID = this.GetStartStatus();
  266. if (approveStartStatusID == null)
  267. {
  268. throw new Exception("工作流平台中,毕业处理流程开始环节未配置,请核查。");
  269. }
  270. //查询工作流程结束环节状态
  271. var approveEndStatusID = this.GetCorrectEndStatus();
  272. if (approveEndStatusID == null)
  273. {
  274. throw new Exception("工作流平台中,毕业处理流程结束环节未配置,请核查。");
  275. }
  276. //查询当前启用的学年学期View
  277. var currentSchoolYearView = SchoolYearServices.Value.GetCurrentSchoolYear();
  278. if (currentSchoolYearView == null)
  279. {
  280. throw new Exception("未设置启用的学年学期,请设置。");
  281. }
  282. //查询数据库进行验证
  283. var graduationApplyVerify = GraduationApplyDAL.GraduationApplyRepository
  284. .GetList(x => x.GraduationApplyID != graduationApplyView.GraduationApplyID
  285. && x.UserID == graduationApplyView.UserID
  286. && x.ApprovalStatus == approveEndStatusID)
  287. .SingleOrDefault();
  288. if (graduationApplyVerify == null)
  289. {
  290. if (!string.IsNullOrEmpty(graduationApplyView.GraduateCardNo))
  291. {
  292. //查询数据库进行验证(结业证书编号唯一)
  293. var graduateCardNoVerify = GraduationApplyDAL.StudentRepository
  294. .GetList(x => x.UserID != graduationApplyView.UserID
  295. && x.GraduateCardNo == graduationApplyView.GraduateCardNo).SingleOrDefault();
  296. if (graduateCardNoVerify != null)
  297. {
  298. throw new Exception("已存在此结业证书编号(重复),请检查。");
  299. }
  300. }
  301. //查询毕业学期对应的毕业学期信息
  302. var graduateSchoolyear = GraduationApplyDAL.GraduateSchoolyearRepository
  303. .GetList(x => x.SchoolyearID == graduationApplyView.GraduatingSemesterID).SingleOrDefault();
  304. //数据有误验证
  305. if (graduationApplyView.GraduationApplyID != Guid.Empty)
  306. {
  307. var graduationApply = GraduationApplyDAL.GraduationApplyRepository
  308. .GetList(x => x.GraduationApplyID == graduationApplyView.GraduationApplyID, (x => x.CF_Student))
  309. .SingleOrDefault();
  310. if (graduationApply == null)
  311. {
  312. throw new Exception("数据有误,请核查。");
  313. }
  314. else
  315. {
  316. //表示修改
  317. if (graduationApply.ApprovalStatus == approveEndStatusID)
  318. {
  319. //毕业名单信息
  320. graduationApply.Remark = graduationApplyView.Remark;
  321. SetModifyStatus(graduationApply);
  322. //更新对应的学生信息
  323. graduationApply.CF_Student.GraduateCardNo = graduationApplyView.GraduateCardNo;
  324. //毕业日期
  325. if (graduateSchoolyear != null)
  326. {
  327. if (graduationApply.CF_Student.GraduateDate == null)
  328. {
  329. graduationApply.CF_Student.GraduateDate = graduateSchoolyear.GraduateDate;
  330. }
  331. }
  332. this.SetModifyStatus(graduationApply.CF_Student);
  333. }
  334. else
  335. {
  336. throw new Exception("数据有误,请核查(只能修改已通过状态的信息)。");
  337. }
  338. }
  339. }
  340. else
  341. {
  342. //查询对应的学生信息
  343. var student = GraduationApplyDAL.StudentRepository
  344. .GetList(x => x.UserID == graduationApplyView.UserID).SingleOrDefault();
  345. //表示新增
  346. ER_GraduationApply graduationApply = new ER_GraduationApply();
  347. graduationApply.GraduationApplyID = Guid.NewGuid();
  348. graduationApply.UserID = graduationApplyView.UserID;
  349. graduationApply.GraduationTypeID = graduationApplyView.GraduationTypeID;
  350. graduationApply.GraduatingSemesterID = graduationApplyView.GraduatingSemesterID;
  351. graduationApply.ApplySchoolyearID = currentSchoolYearView.SchoolYearID;
  352. graduationApply.GraduationConditionPackageID = graduationApplyView.GraduationConditionPackageID;
  353. graduationApply.BeforeInSchoolStatusID = student.InSchoolStatusID;
  354. graduationApply.BeforeStudentStatusID = student.StudentStatus;
  355. graduationApply.ApprovalStatus = approveEndStatusID;
  356. graduationApply.GraduationResult = (int)ER_GraduationResult.Completion;
  357. graduationApply.ApprovalResult = graduationApplyView.ApprovalResult;
  358. graduationApply.Remark = graduationApplyView.Remark;
  359. SetNewStatus(graduationApply);
  360. UnitOfWork.Add(graduationApply);
  361. //更新对应的学生信息
  362. student.InSchoolStatusID = (int)CF_InschoolStatus.Complete;
  363. student.StudentStatus = (int)CF_StudentStatus.Complete;
  364. student.GraduateCardNo = graduationApplyView.GraduateCardNo;
  365. //毕业日期
  366. if (graduateSchoolyear != null)
  367. {
  368. if (student.GraduateDate == null)
  369. {
  370. student.GraduateDate = graduateSchoolyear.GraduateDate;
  371. }
  372. }
  373. this.SetModifyStatus(student);
  374. }
  375. }
  376. else
  377. {
  378. if (graduationApplyVerify.GraduationResult == (int)ER_GraduationResult.Completion)
  379. {
  380. throw new Exception("此名单在结业名单中已存在,请核查。");
  381. }
  382. else if (graduationApplyVerify.GraduationResult == (int)ER_GraduationResult.Graduation)
  383. {
  384. throw new Exception("此名单在毕业名单中已存在,请核查。");
  385. }
  386. else
  387. {
  388. throw new Exception("数据异常(毕业结论为空),请核查。");
  389. }
  390. }
  391. //事务提交
  392. UnitOfWork.Commit();
  393. }
  394. catch (Exception ex)
  395. {
  396. throw new Exception(ex.Message);
  397. }
  398. }
  399. /// <summary>
  400. /// 删除(事务处理)
  401. /// 注:需考虑对应的在校状态、毕结业证书编号等信息的处理
  402. /// </summary>
  403. /// <param name="graduationApplyIDs"></param>
  404. /// <returns></returns>
  405. public bool CompletionListDelete(List<Guid?> graduationApplyIDs)
  406. {
  407. try
  408. {
  409. //查询对应的学位申请信息List
  410. var degreeApplyList = GraduationApplyDAL.DegreeApplyRepository
  411. .GetList(x => graduationApplyIDs.Contains(x.GraduationApplyID)).ToList();
  412. if (degreeApplyList != null && degreeApplyList.Count() > 0)
  413. {
  414. throw new Exception("请先删除与其关联的数据,如:学位申请、学位审核、学位名单等");
  415. }
  416. //查询对应的毕业申请信息List
  417. var graduationApplyList = GraduationApplyDAL.GraduationApplyRepository
  418. .GetList(x => graduationApplyIDs.Contains(x.GraduationApplyID), (x => x.CF_Student))
  419. .ToList();
  420. //更新对应的学生信息(如:在校状态、学籍状态、毕结业证书编号、毕业日期),同时删除对应的结业名单信息
  421. graduationApplyList.ForEach(x =>
  422. {
  423. x.CF_Student.InSchoolStatusID = x.BeforeInSchoolStatusID;
  424. x.CF_Student.StudentStatus = x.BeforeStudentStatusID;
  425. x.CF_Student.GraduateCardNo = null;
  426. x.CF_Student.GraduateDate = null;
  427. this.SetModifyStatus(x.CF_Student);
  428. UnitOfWork.Remove(x);
  429. });
  430. UnitOfWork.Commit();
  431. return true;
  432. }
  433. catch (Exception ex)
  434. {
  435. throw new Exception(ex.Message);
  436. }
  437. }
  438. /// <summary>
  439. /// 结业证书编号Excel导入
  440. /// </summary>
  441. /// <param name="cellheader"></param>
  442. /// <param name="inCount"></param>
  443. /// <param name="upCount"></param>
  444. /// <param name="errdataList"></param>
  445. /// <param name="errCount"></param>
  446. /// <param name="sourcePhysicalPath"></param>
  447. public void CompletionNoImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount,
  448. out List<GraduationApplyView> errdataList, out int? errCount, string sourcePhysicalPath)
  449. {
  450. try
  451. {
  452. //查询工作流程结束环节状态
  453. var approveEndStatusID = this.GetCorrectEndStatus();
  454. if (approveEndStatusID == null)
  455. {
  456. throw new Exception("工作流平台中,毕业处理流程结束环节未配置,请核查。");
  457. }
  458. //查询培养类型设置信息List
  459. var educationTypeSettingList = GraduationApplyDAL.EducationTypeSettingRepository
  460. .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  461. if (educationTypeSettingList == null || educationTypeSettingList.Count() <= 0)
  462. {
  463. throw new Exception("培养类型设置未设置,请设置。");
  464. }
  465. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  466. List<GraduationApplyView> errList = new List<GraduationApplyView>();
  467. // 1.1解析文件,存放到一个List集合里
  468. cellheader.Remove("ErrorMessage");//移除“未导入原因”列(ErrorMessage)
  469. List<GraduationApplyView> enlist = NpoiExcelHelper
  470. .ExcelToEntityList<GraduationApplyView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
  471. cellheader.Add("ErrorMessage", "未导入原因");
  472. //对List集合进行有效性校验
  473. if (enlist.Count() <= 0)
  474. {
  475. throw new Exception("Excel文件数据为空,请检查。");
  476. }
  477. Regex reg = null; //正则表达式
  478. //DateTime result; //用于返回判断日期字段格式
  479. inCount = 0; //导入个数
  480. upCount = 0; //更新个数
  481. errCount = 0; //失败个数
  482. string errorMsgStr = ""; //错误信息
  483. List<ER_GraduationApply> newGraduationApplyInList = new List<ER_GraduationApply>();
  484. List<CF_Student> newStudentUpList = new List<CF_Student>();
  485. //移除StuUpList
  486. List<CF_Student> removeStuUpList = new List<CF_Student>();
  487. //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
  488. //毕业申请
  489. Expression<Func<ER_GraduationApply, bool>> expGraduationApply = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  490. expGraduationApply = expGraduationApply.And(x => x.ApprovalStatus == approveEndStatusID);
  491. //毕业结论(结业)
  492. expGraduationApply = expGraduationApply.And(x => x.GraduationResult == (int)ER_GraduationResult.Completion);
  493. //查询对应的结业名单信息ViewList
  494. var completionListViewList = GraduationApplyDAL.GetGraduationApplyViewQueryable(expGraduationApply).ToList();
  495. //查询对应的学生信息IDList
  496. var userIDList = completionListViewList.Select(x => x.UserID).ToList();
  497. //学号List
  498. var studentNoList = enlist.Where(x => !string.IsNullOrEmpty(x.StudentNo)).Select(x => x.StudentNo).ToList();
  499. //对比后的studentNoCompletionListViewList
  500. var studentNoCompletionListViewList = completionListViewList.Where(x => studentNoList.Contains(x.StudentNo)).ToList();
  501. //查询对应的学生信息List
  502. var studentList = GraduationApplyDAL.StudentRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  503. //结业名单中的学生信息List
  504. var completionStudentList = studentList.Where(x => userIDList.Contains(x.UserID)).ToList();
  505. //结业证书编号List
  506. var completionNoList = enlist.Where(x => !string.IsNullOrEmpty(x.GraduateCardNo)).Select(x => x.GraduateCardNo).ToList();
  507. //对比后的completionNoStudentList
  508. var completionNoStudentList = studentList.Where(x => completionNoList.Contains(x.GraduateCardNo)).ToList();
  509. //查询对应的毕业学期信息List
  510. var graduateSchoolyearList = GraduationApplyDAL.GraduateSchoolyearRepository
  511. .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  512. //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
  513. for (int i = 0; i < enlist.Count; i++)
  514. {
  515. GraduationApplyView en = enlist[i]; //Excel表数据视图
  516. ER_GraduationApply newGraduationApply = new ER_GraduationApply();
  517. CF_Student newStudent = new CF_Student();
  518. //学号
  519. if (string.IsNullOrEmpty(en.StudentNo))
  520. {
  521. errCount++;
  522. errorMsgStr = "学号不能为空";
  523. en.ErrorMessage = errorMsgStr;
  524. errList.Add(en);
  525. errorMsg.AppendLine(errorMsgStr);
  526. continue;
  527. }
  528. else
  529. {
  530. var studentNoGraduationApplyViewList = studentNoCompletionListViewList
  531. .Where(x => x.StudentNo == en.StudentNo).ToList();
  532. if (studentNoGraduationApplyViewList.Count() > 1)
  533. {
  534. errCount++;
  535. errorMsgStr = "对应的学号存在多个结业名单信息,请检查";
  536. en.ErrorMessage = errorMsgStr;
  537. errList.Add(en);
  538. errorMsg.AppendLine(errorMsgStr);
  539. continue;
  540. }
  541. else
  542. {
  543. var studentNoGraduationApplyView = studentNoGraduationApplyViewList
  544. .Where(x => x.StudentNo == en.StudentNo).SingleOrDefault();
  545. if (studentNoGraduationApplyView == null)
  546. {
  547. errCount++;
  548. errorMsgStr = "对应的学号中不存在相应的结业名单信息,请检查";
  549. en.ErrorMessage = errorMsgStr;
  550. errList.Add(en);
  551. errorMsg.AppendLine(errorMsgStr);
  552. continue;
  553. }
  554. else
  555. {
  556. //学生信息ID
  557. newStudent.UserID = studentNoGraduationApplyView.UserID.Value;
  558. newGraduationApply.UserID = studentNoGraduationApplyView.UserID;
  559. newGraduationApply.GraduatingSemesterID = studentNoGraduationApplyView.GraduatingSemesterID;
  560. }
  561. }
  562. }
  563. //结业证书编号
  564. if (string.IsNullOrEmpty(en.GraduateCardNo))
  565. {
  566. errCount++;
  567. errorMsgStr = "结业证书编号不能为空";
  568. en.ErrorMessage = errorMsgStr;
  569. errList.Add(en);
  570. errorMsg.AppendLine(errorMsgStr);
  571. continue;
  572. }
  573. else
  574. {
  575. reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母)
  576. if (!reg.IsMatch(en.GraduateCardNo))
  577. {
  578. errCount++;
  579. errorMsgStr = "结业证书编号格式不正确,请检查(数字或英文字母)";
  580. en.ErrorMessage = errorMsgStr;
  581. errList.Add(en);
  582. errorMsg.AppendLine(errorMsgStr);
  583. continue;
  584. }
  585. else
  586. {
  587. var completionNoStudentViewList = completionNoStudentList
  588. .Where(x => x.UserID != newStudent.UserID && x.GraduateCardNo == en.GraduateCardNo.Trim()).ToList();
  589. if (completionNoStudentViewList.Count() > 1)
  590. {
  591. errCount++;
  592. errorMsgStr = "对应的结业证书编号存在多个学生信息中(重复),请检查";
  593. en.ErrorMessage = errorMsgStr;
  594. errList.Add(en);
  595. errorMsg.AppendLine(errorMsgStr);
  596. continue;
  597. }
  598. else
  599. {
  600. var completionNoStudentView = completionNoStudentViewList
  601. .Where(x => x.GraduateCardNo == en.GraduateCardNo.Trim()).SingleOrDefault();
  602. if (completionNoStudentView == null)
  603. {
  604. newStudent.GraduateCardNo = en.GraduateCardNo.Trim();
  605. }
  606. else
  607. {
  608. errCount++;
  609. errorMsgStr = "对应的结业证书编号已存在学生信息中(重复),请检查";
  610. en.ErrorMessage = errorMsgStr;
  611. errList.Add(en);
  612. errorMsg.AppendLine(errorMsgStr);
  613. continue;
  614. }
  615. }
  616. }
  617. }
  618. ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉)
  619. //for (int j = i + 1; j < enlist.Count; j++)
  620. //{
  621. // GraduationApplyView enA = enlist[j];
  622. // //根据Excel表中的业务主键进行去重(学号或学生信息ID唯一)
  623. // if (en.StudentNo == enA.StudentNo || en.UserID == enA.UserID)
  624. // {
  625. // //用于标识Excel表中的重复记录(由于是批量进行插入数据表)
  626. // }
  627. //}
  628. //数据表重复性验证(学号或学生信息ID唯一)
  629. var completionStudentVerification = completionStudentList
  630. .Where(x => x.UserID == newStudent.UserID).SingleOrDefault();
  631. //查询毕业学期对应的毕业学期信息
  632. var graduateSchoolyear = graduateSchoolyearList
  633. .Where(x => x.SchoolyearID == newGraduationApply.GraduatingSemesterID).SingleOrDefault();
  634. if (completionStudentVerification == null)
  635. {
  636. //由于前面已做相应判断,此处代码暂时无效
  637. //新增
  638. if (!newGraduationApplyInList.Any(x => x.UserID == newStudent.UserID))
  639. {
  640. //ER_GraduationApply表
  641. inCount++;
  642. }
  643. else
  644. {
  645. //Excel表重复性验证
  646. //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑)
  647. inCount++;
  648. }
  649. }
  650. else
  651. {
  652. //注:结业证书编号唯一
  653. //更新(Excel中有重复时,以数据重复抛出到失败数据文件中进行处理,不进行更新)
  654. if (!removeStuUpList.Any(x => x.GraduateCardNo == en.GraduateCardNo.Trim()))
  655. {
  656. if (!newStudentUpList.Any(x => x.GraduateCardNo == en.GraduateCardNo.Trim()))
  657. {
  658. completionStudentVerification.GraduateCardNo = newStudent.GraduateCardNo;
  659. //毕业日期
  660. if (graduateSchoolyear != null)
  661. {
  662. if (completionStudentVerification.GraduateDate == null)
  663. {
  664. completionStudentVerification.GraduateDate = graduateSchoolyear.GraduateDate;
  665. }
  666. }
  667. SetModifyStatus(completionStudentVerification);
  668. newStudentUpList.Add(completionStudentVerification);
  669. upCount++;
  670. }
  671. else
  672. {
  673. var stuUpList = newStudentUpList.Where(x => x.GraduateCardNo == en.GraduateCardNo.Trim()).ToList();
  674. foreach (var stuUp in stuUpList)
  675. {
  676. errCount++;
  677. errorMsgStr = "结业证书编号重复,请检查";
  678. en.ErrorMessage = errorMsgStr;
  679. errList.Add(new GraduationApplyView()
  680. {
  681. StudentNo = en.StudentNo,
  682. GraduateCardNo = en.GraduateCardNo,
  683. ErrorMessage = en.ErrorMessage
  684. });
  685. errorMsg.AppendLine(errorMsgStr);
  686. newStudentUpList.Remove(stuUp);
  687. removeStuUpList.Add(stuUp);
  688. upCount--;
  689. }
  690. errCount++;
  691. errorMsgStr = "结业证书编号重复,请检查";
  692. en.ErrorMessage = errorMsgStr;
  693. errList.Add(en);
  694. errorMsg.AppendLine(errorMsgStr);
  695. continue;
  696. }
  697. }
  698. else
  699. {
  700. errCount++;
  701. errorMsgStr = "结业证书编号重复,请检查";
  702. en.ErrorMessage = errorMsgStr;
  703. errList.Add(en);
  704. errorMsg.AppendLine(errorMsgStr);
  705. continue;
  706. }
  707. }
  708. }
  709. //移除Up
  710. if (removeStuUpList != null && removeStuUpList.Count() > 0)
  711. {
  712. foreach (var removeStuUp in removeStuUpList)
  713. {
  714. newStudentUpList.Remove(removeStuUp);
  715. }
  716. }
  717. //批量统一提交更新
  718. if (newStudentUpList != null && newStudentUpList.Count() > 0)
  719. {
  720. ////事务提交
  721. //UnitOfWork.Commit();
  722. UnitOfWork.BatchUpdate(newStudentUpList);
  723. }
  724. errdataList = errList.Distinct().ToList(); //错误列表List
  725. }
  726. catch (Exception ex)
  727. {
  728. //目前会出现,由于错误信息字符太长,无法抛出弹出框的问题
  729. throw new Exception(ex.Message);
  730. }
  731. }
  732. }
  733. }