CertisfierDistributeServices.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Common.Specialtymanage;
  6. using EMIS.Entities;
  7. using Bowin.Common.Linq;
  8. using Bowin.Common.Linq.Entity;
  9. using EMIS.ViewModel.Specialtymanage;
  10. using EMIS.ViewModel;
  11. using System.Text.RegularExpressions;
  12. using Bowin.Common.Utility;
  13. using EMIS.ViewModel.Cache;
  14. using EMIS.Utility;
  15. using System.Linq.Expressions;
  16. using EMIS.DataLogic.ExamManage;
  17. using EMIS.DataLogic.CerificateManage;
  18. using EMIS.CommonLogic.SystemServices;
  19. using EMIS.ViewModel.CerificateManage;
  20. using EMIS.DataLogic.Repositories;
  21. namespace EMIS.CommonLogic.CerificateManage
  22. {
  23. public class CertisfierDistributeServices : BaseServices, ICertisfierDistributeServices
  24. {
  25. public ProjectScoreRepository ProjectScoreRepository { get; set; }
  26. public CertisfierDistributeDAL Logic { get; set; }
  27. public ISerialNumberServices SerialNumberService { get; set; }
  28. public IGridResultSet<ExamBatchProjectView> GetExamProjectListViewGrid(int pageIndex, int pageSize, params EMIS.ViewModel.ConfiguretView[] configuretViews)
  29. {
  30. System.Linq.Expressions.Expression<Func<ER_CertisfierDistribute, bool>> expCampus = (x => true);
  31. var query = Logic.GetCerificateViewListOnlyGenerated(expCampus, x => true, x => true, x => true, x => true);
  32. //查询条件
  33. foreach (var configuretView in configuretViews)
  34. {
  35. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  36. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  37. }
  38. var result = query.OrderBy(x => x.ExaminationProjectID).GroupBy(x => new
  39. {
  40. x.ExaminationProjectID,
  41. x.ProjectName,
  42. }).Select(x => new ExamBatchProjectView()
  43. {
  44. ExaminationProjectID = x.Key.ExaminationProjectID.Value,
  45. Name = x.Key.ProjectName,
  46. });
  47. return result
  48. .OrderBy(x => x.ExaminationProjectID)
  49. .ToGridResultSet<ExamBatchProjectView>(pageIndex, pageSize);
  50. }
  51. public object GetCertisfierListViewGrid(ConfiguretView examinationSubjectView, Guid? schoolyearID,
  52. Guid? examinationProjectID, Guid? collegeID, int? schoolAreaID, int? year, Guid? classmajorID, int? standardID, int? distributeTypeID, int? recordStatus,
  53. Guid? userid,int pageIndex, int pageSize)
  54. {
  55. Expression<Func<ER_CertisfierDistribute, bool>> expCertisfier = (x => true);
  56. Expression<Func<CF_College, bool>> expcol = (x => true);
  57. Expression<Func<CF_Grademajor, bool>> expgra = (x => true);
  58. Expression<Func<CF_Classmajor, bool>> expcla = (x => true);
  59. Expression<Func<CF_Facultymajor, bool>> expfac = (x => true);
  60. if (schoolyearID.HasValue)
  61. {
  62. expCertisfier = expCertisfier.And(x => x.SchoolyearID == schoolyearID);
  63. }
  64. if (examinationProjectID.HasValue)
  65. {
  66. expCertisfier = expCertisfier.And(x => x.ExaminationProjectID == examinationProjectID);
  67. }
  68. if (collegeID.HasValue)
  69. {
  70. expcol = expcol.And(x => x.CollegeID == collegeID);
  71. }
  72. if (schoolAreaID.HasValue)
  73. {
  74. expgra = expgra.And(x => x.SchoolAreaID == schoolAreaID);
  75. }
  76. if (year.HasValue)
  77. {
  78. expgra = expgra.And(x => x.SchoolyearID == year);
  79. }
  80. if (classmajorID.HasValue)
  81. {
  82. expcla = expcla.And(x => x.ClassmajorID == classmajorID);
  83. }
  84. if (standardID.HasValue)
  85. {
  86. expfac = expfac.And(x => x.StandardID == standardID);
  87. }
  88. if (distributeTypeID.HasValue)
  89. {
  90. expCertisfier = expCertisfier.And(x => x.DistributeTypeID == distributeTypeID);
  91. }
  92. if (recordStatus.HasValue)
  93. {
  94. expCertisfier = expCertisfier.And(x => x.RecordStatus == recordStatus);
  95. }
  96. if (userid.HasValue)
  97. {
  98. expCertisfier = expCertisfier.And(x => x.UserID == userid);
  99. }
  100. var query = Logic.GetCerificateViewListOnlyGenerated(expCertisfier, expcol, expgra, expcla, expfac);
  101. if (!string.IsNullOrEmpty(examinationSubjectView.ConditionValue) && !string.IsNullOrEmpty(examinationSubjectView.Attribute))
  102. query = query.DynamicWhere(examinationSubjectView.Attribute, examinationSubjectView.Condition, examinationSubjectView.ConditionValue);
  103. query = this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query));
  104. int Count = query.Count();
  105. int Already = query.Where(x => x.RecordStatus == (int)ER_CertisfierDistributeStatus.Complete).Count();
  106. int NotReceived = query.Where(x => x.RecordStatus == (int)ER_CertisfierDistributeStatus.Waiting).Count();
  107. var pages = query.OrderBy(x => x.RecordStatus).ThenByDescending(x => x.SchoolYearCode).ThenBy(x => x.ProjectName).ThenBy(x => x.SaveNo.Length).ThenBy(x => x.SaveNo).ThenBy(x => x.ClassmajorName).ThenBy(x => x.IDNumber)
  108. .ToGridResultSet<EMIS.ViewModel.CerificateView>(pageIndex, pageSize);
  109. return new { Count = Count, Already = Already, NotReceived = NotReceived, rows = pages.rows, pages.total };
  110. //return query.OrderBy(x => x.Schoolyear).ThenByDescending(x => x.Years).ThenBy(x => x.IDNumber).ToGridResultSet<CerificateView>(pageIndex, pageSize);
  111. }
  112. public ViewModel.CerificateView GetView(Guid? ViewID)
  113. {
  114. Expression<Func<ER_CertisfierDistribute, bool>> expCertisfier = (x => true);
  115. if (ViewID.HasValue)
  116. {
  117. expCertisfier = expCertisfier.And(x => x.CertisfierDistributeID == ViewID);
  118. }
  119. var query = Logic.GetCerificateViewListOnlyGenerated(expCertisfier, x => true, x => true, x => true, x => true).FirstOrDefault();
  120. return query;
  121. }
  122. public void Edit(ViewModel.CerificateView view)
  123. {
  124. UnitOfWork.Delete<ER_CertisfierDistribute>(q => q.CertisfierDistributeID == view.CertisfierDistributeID);
  125. Logic.DistributeRepository.UnitOfWork.Commit();
  126. }
  127. public void UpdateCertisfierDistributeType(ViewModel.CerificateView view)
  128. {
  129. Logic.DistributeRepository.UnitOfWork.Update<ER_CertisfierDistribute>(x => new ER_CertisfierDistribute()
  130. {
  131. DistributeTypeID = view.DistributeTypeID,
  132. ContactPerson = view.DistributeTypeID == (int)ER_CertisfierDistributeType.Self ? null : (view.DistributeTypeID == (int)ER_CertisfierDistributeType.Entrust ? view.EntrustDistributer : view.ContactPerson),
  133. ContactNo = view.DistributeTypeID == (int)ER_CertisfierDistributeType.Self ? null : (view.DistributeTypeID == (int)ER_CertisfierDistributeType.Entrust ? view.ContactNo : view.MailContactNo),
  134. ContactIDNo = view.ContactIDNo,
  135. Address = view.Address,
  136. ModifyTime = DateTime.Now,
  137. },
  138. x => view.CertisfierDistributeID == x.CertisfierDistributeID);
  139. UnitOfWork.Commit();
  140. }
  141. public ViewModel.CerificateView GetView(System.Linq.Expressions.Expression<Func<Entities.ER_CertisfierDistribute, bool>> expCampus)
  142. {
  143. var query = Logic.GetCerificateViewListOnlyGenerated(expCampus, x => true, x => true, x => true, x => true).SingleOrDefault();
  144. return query;
  145. }
  146. public List<CerificateView> GetList(ConfiguretView examinationSubjectView, Guid? schoolyearID,
  147. Guid? examinationProjectID, Guid? collegeID, int? schoolAreaID, int? year, Guid? classmajorID, int? standardID, int? distributeTypeID, int? recordStatus,
  148. List<Guid?> ids)
  149. {
  150. Expression<Func<ER_CertisfierDistribute, bool>> expCertisfier = (x => true);
  151. Expression<Func<CF_College, bool>> expcol = (x => true);
  152. Expression<Func<CF_Grademajor, bool>> expgra = (x => true);
  153. Expression<Func<CF_Classmajor, bool>> expcla = (x => true);
  154. Expression<Func<CF_Facultymajor, bool>> expfac = (x => true);
  155. if (schoolyearID.HasValue)
  156. {
  157. expCertisfier = expCertisfier.And(x => x.SchoolyearID == schoolyearID);
  158. }
  159. if (examinationProjectID.HasValue)
  160. {
  161. expCertisfier = expCertisfier.And(x => x.ExaminationProjectID == examinationProjectID);
  162. }
  163. if (collegeID.HasValue)
  164. {
  165. expcol = expcol.And(x => x.CollegeID == collegeID);
  166. }
  167. if (schoolAreaID.HasValue)
  168. {
  169. expgra = expgra.And(x => x.SchoolAreaID == schoolAreaID);
  170. }
  171. if (year.HasValue)
  172. {
  173. expgra = expgra.And(x => x.SchoolyearID == year);
  174. }
  175. if (classmajorID.HasValue)
  176. {
  177. expcla = expcla.And(x => x.ClassmajorID == classmajorID);
  178. }
  179. if (standardID.HasValue)
  180. {
  181. expfac = expfac.And(x => x.StandardID == standardID);
  182. }
  183. if (distributeTypeID.HasValue)
  184. {
  185. expCertisfier = expCertisfier.And(x => x.DistributeTypeID == distributeTypeID);
  186. }
  187. if (recordStatus.HasValue)
  188. {
  189. expCertisfier = expCertisfier.And(x => x.RecordStatus == recordStatus);
  190. }
  191. if (ids.Count() > 0)
  192. {
  193. expCertisfier = expCertisfier.And(x => ids.Contains(x.CertisfierDistributeID));
  194. }
  195. //if (userid.HasValue)
  196. //{
  197. // expCertisfier = expCertisfier.And(x => x.UserID == userid);
  198. //}
  199. var query = Logic.GetCerificateViewListOnlyGenerated(expCertisfier, expcol, expgra, expcla, expfac);
  200. if (!string.IsNullOrEmpty(examinationSubjectView.ConditionValue) && !string.IsNullOrEmpty(examinationSubjectView.Attribute))
  201. query = query.DynamicWhere(examinationSubjectView.Attribute, examinationSubjectView.Condition, examinationSubjectView.ConditionValue);
  202. return query.OrderBy(x => x.RecordStatus).ThenByDescending(x => x.SchoolYearCode).ThenBy(x => x.ProjectName).ThenBy(x => x.SaveNo.Length).ThenBy(x => x.SaveNo).ThenBy(x => x.ClassmajorName).ThenBy(x => x.IDNumber).ToList();
  203. }
  204. public bool Delete(List<Guid?> IDs)
  205. {
  206. UnitOfWork.Delete<ER_CertisfierDistribute>(x => IDs.Contains(x.CertisfierDistributeID));
  207. UnitOfWork.Commit();
  208. return true;
  209. }
  210. public bool OpenDistribute(List<Guid?> IDs)
  211. {
  212. //var list = ProjectScoreRepository.GetList(x => IDs.Contains(x.ProjectScoreID)).ToList();
  213. //var distributeList = Logic.GetCertisfierDistributByProjectScore(x => IDs.Contains(x.ProjectScoreID)).ToList();
  214. //if (distributeList.Any(x => x.RecordStatus != (int)ER_CertisfierDistributeStatus.Making))
  215. //{
  216. // throw new Exception("证书已经开放领取,不能重复开放。");
  217. //}
  218. ////判断是否已经有证书领取表的记录,没有则新增,有则更改状态
  219. //foreach (var item in list)
  220. //{
  221. // var distribute = distributeList.SingleOrDefault(x => x.ExaminationProjectID == item.ExaminationProjectID && x.UserID == item.UserID);
  222. // if (distribute == null)
  223. // {
  224. // distribute = new ER_CertisfierDistribute()
  225. // {
  226. // UserID = item.UserID,
  227. // CertisfierDistributeID = Guid.NewGuid(),
  228. // ExaminationProjectID = item.ExaminationProjectID,
  229. // DistributeTypeID = (int)ER_CertisfierDistributeType.Self
  230. // };
  231. // SetNewStatus<ER_CertisfierDistribute>(distribute);
  232. // distribute.RecordStatus = (int)ER_CertisfierDistributeStatus.Waiting;
  233. // UnitOfWork.Add(distribute);
  234. // }
  235. // else if (distribute.RecordStatus == (int)ER_CertisfierDistributeStatus.Making)
  236. // {
  237. // distribute.RecordStatus = (int)ER_CertisfierDistributeStatus.Waiting;
  238. // }
  239. //}
  240. try
  241. {
  242. var list = Logic.DistributeRepository.Entities.Where(x => IDs.Contains(x.CertisfierDistributeID)).ToList();
  243. list.ForEach(x => {
  244. x.RecordStatus = (int)ER_CertisfierDistributeStatus.Waiting;
  245. x.DistributeTypeID = (int)ER_CertisfierDistributeType.Self;
  246. });
  247. UnitOfWork.Commit();
  248. return true;
  249. }
  250. catch (Exception)
  251. {
  252. throw;
  253. }
  254. }
  255. public bool CancelOpenDistribute(List<Guid?> IDs)
  256. {
  257. var hasCantCancel = Logic.DistributeRepository.Entities.Any(x => IDs.Contains(x.CertisfierDistributeID) && x.RecordStatus != (int)ER_CertisfierDistributeStatus.Waiting);
  258. if (hasCantCancel)
  259. {
  260. throw new Exception("只能撤销待领证状态的信息。");
  261. }
  262. Logic.DistributeRepository.UnitOfWork.Update<ER_CertisfierDistribute>(x => new ER_CertisfierDistribute() { RecordStatus = (int)ER_CertisfierDistributeStatus.Making, DistributeTypeID = null, Distributer = null, DistributeTime = null, No = null }, x => IDs.Contains(x.CertisfierDistributeID));
  263. UnitOfWork.Commit();
  264. return true;
  265. }
  266. public bool CancelDistribute(List<Guid?> IDs)
  267. {
  268. var hasCantCancel = Logic.DistributeRepository.Entities.Any(x => IDs.Contains(x.CertisfierDistributeID) && x.RecordStatus != (int)ER_CertisfierDistributeStatus.Complete);
  269. if (hasCantCancel)
  270. {
  271. throw new Exception("只能撤销已领证状态的信息。");
  272. }
  273. Logic.DistributeRepository.UnitOfWork.Update<ER_CertisfierDistribute>(x => new ER_CertisfierDistribute() { RecordStatus = (int)ER_CertisfierDistributeStatus.Waiting, Distributer = null, DistributeTime = null, No = null }, x => IDs.Contains(x.CertisfierDistributeID));
  274. UnitOfWork.Commit();
  275. return true;
  276. }
  277. public bool ConfirmDistribute(List<Guid?> IDs, string Distributer)
  278. {
  279. var list = Logic.DistributeRepository.Entities.Where(x => IDs.Contains(x.CertisfierDistributeID)).ToList();
  280. var nowTime = DateTime.Now;
  281. var distributeNo = SerialNumberService.SetDialySN(Const.EX_CERTISFIERDISTRIBUTE_NO_PREFIX, 3)
  282. .Replace(Const.EX_CERTISFIERDISTRIBUTE_NO_PREFIX, Const.EX_CERTISFIERDISTRIBUTE_NO_PREFIX + DateTime.Today.ToString("yyMMdd"));
  283. //更新状态为待领取的
  284. foreach (var distribute in list)
  285. {
  286. if (distribute.RecordStatus == (int)ER_CertisfierDistributeStatus.Complete)
  287. {
  288. throw new Exception("待领证状态下的数据才能确认领取,如果需要重新确认领取,请先进行撤销领取操作");
  289. }
  290. if (distribute.RecordStatus == (int)ER_CertisfierDistributeStatus.Making)
  291. {
  292. throw new Exception("只有待领证状态下的数据才能确认领取");
  293. }
  294. if (distribute != null && distribute.RecordStatus == (int)ER_CertisfierDistributeStatus.Waiting)
  295. {
  296. distribute.RecordStatus = (int)ER_CertisfierDistributeStatus.Complete;
  297. distribute.Distributer = Distributer;
  298. distribute.DistributeTime = nowTime;
  299. distribute.No = distributeNo;
  300. //SerialNumberService.GetSN("LQ", 3, DateTime.Now.ToString("yyMMdd"));
  301. }
  302. }
  303. UnitOfWork.Commit();
  304. return true;
  305. }
  306. /// <summary>
  307. /// Excel导入
  308. /// </summary>
  309. /// <param name="cellheader"></param>
  310. /// <param name="inCount"></param>
  311. /// <param name="upCount"></param>
  312. /// <param name="errdataList"></param>
  313. /// <param name="errCount"></param>
  314. /// <param name="sourcePhysicalPath"></param>
  315. public void Import(Dictionary<string, string> cellheader, out int? inCount, out int? upCount,
  316. out List<CerificateView> errdataList, out int? errCount, string sourcePhysicalPath)
  317. {
  318. try
  319. {
  320. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  321. List<CerificateView> errList = new List<CerificateView>();
  322. // 1.1解析文件,存放到一个List集合里
  323. cellheader.Remove("ErrorMessage");//移除“未导入原因”列(ErrorMessage)
  324. List<CerificateView> enlist = NpoiExcelHelper.ExcelToEntityList<CerificateView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
  325. cellheader.Add("ErrorMessage", "未导入原因");
  326. //对List集合进行有效性校验
  327. if (enlist.Count() <= 0)
  328. {
  329. throw new Exception("Excel文件数据为空,请检查。");
  330. }
  331. Regex reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //学制字段正则表达式()
  332. inCount = 0; //导入个数
  333. upCount = 0; //更新个数
  334. errCount = 0; //失败个数
  335. string errorMsgStr = ""; //错误信息
  336. List<CerificateView> upList = new List<CerificateView>(); //专业信息update实体List
  337. //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
  338. for (int i = 0; i < enlist.Count; i++)
  339. {
  340. CerificateView en = enlist[i]; //Excel表数据视图
  341. CF_Specialty specialty = new CF_Specialty(); //专业信息实体
  342. //证件号码
  343. if (string.IsNullOrEmpty(en.IDNumber))
  344. {
  345. errCount++;
  346. errorMsgStr = "证件号码不能为空";
  347. en.ErrorMessage = errorMsgStr;
  348. errList.Add(en);
  349. errorMsg.AppendLine(errorMsgStr);
  350. continue;
  351. }
  352. //考试项目
  353. if (string.IsNullOrEmpty(en.ProjectName))
  354. {
  355. errCount++;
  356. errorMsgStr = "考试项目不能为空";
  357. en.ErrorMessage = errorMsgStr;
  358. errList.Add(en);
  359. errorMsg.AppendLine(errorMsgStr);
  360. continue;
  361. }
  362. //邮寄单号
  363. if (string.IsNullOrEmpty(en.DeliveryNoteNo))
  364. {
  365. errCount++;
  366. errorMsgStr = "邮寄单号不能为空";
  367. en.ErrorMessage = errorMsgStr;
  368. errList.Add(en);
  369. errorMsg.AppendLine(errorMsgStr);
  370. continue;
  371. }
  372. var entity = Logic.GetCerificateViewListOnlyGenerated(x => true, x => true, x => true, x => true, x => true).Where(x => x.ProjectName == en.ProjectName && x.IDNumber == en.IDNumber).FirstOrDefault();
  373. if (entity == null)
  374. {
  375. errCount++;
  376. errorMsgStr = "找不到考试项目和对应的学生";
  377. en.ErrorMessage = errorMsgStr;
  378. errList.Add(en);
  379. errorMsg.AppendLine(errorMsgStr);
  380. continue;
  381. }
  382. if (entity.RecordStatus == (int)ER_CertisfierDistributeStatus.Making)
  383. {
  384. errCount++;
  385. errorMsgStr = "制证中不允许导入";
  386. en.ErrorMessage = errorMsgStr;
  387. errList.Add(en);
  388. errorMsg.AppendLine(errorMsgStr);
  389. continue;
  390. }
  391. UnitOfWork.Update<ER_CertisfierDistribute>(x => new ER_CertisfierDistribute() { DeliveryNoteNo = en.DeliveryNoteNo, ContactPerson = en.ContactPerson, ContactNo = en.ContactNo, Address = en.Address, RecordStatus = (int)ER_CertisfierDistributeStatus.Complete }, x => x.CertisfierDistributeID == entity.CertisfierDistributeID);
  392. upCount++;
  393. }
  394. UnitOfWork.Commit();
  395. errdataList = errList.Distinct().ToList(); //错误列表List
  396. }
  397. catch (Exception ex)
  398. {
  399. //目前会出现,由于错误信息字符太长,无法抛出弹出框的问题
  400. throw new Exception(ex.Message);
  401. }
  402. }
  403. public IGridResultSet<CertificateMobileView> GetCertificateMobileViewGrid(int? pageIndex, int? pageSize, Guid userID)
  404. {
  405. Expression<Func<ER_ProjectScore, bool>> exp = (x => x.UserID == userID);
  406. Expression<Func<ER_ProjectScore, bool>> detailExp = (x => true);
  407. var certificateViewList = this.Logic.GetCertificateMobileViewQueryable(exp)
  408. .OrderBy(x => x.DistributeStatusID).ToGridResultSet(pageIndex, pageSize);
  409. if (pageSize.HasValue && pageIndex.HasValue)
  410. {
  411. var projectScoreIDList = certificateViewList.rows.Select(x => x.ProjectScoreID).ToList();
  412. //detailExp = (x => projectScoreIDList.Contains(x.ProjectScoreID));
  413. }
  414. else
  415. {
  416. detailExp = exp;
  417. }
  418. //var scoreList = this.Logic.GetCertificateMobileScoreViewQueryable(exp).ToList();
  419. //certificateViewList.rows.ForEach(x =>
  420. //{
  421. // var curScoreList = scoreList.Where(w => w.ExaminationProjectID == x.ExaminationProjectID).ToList();
  422. // x.ScoreViewList = curScoreList;
  423. //});
  424. return certificateViewList;
  425. }
  426. /// <summary>
  427. /// 存放编号导入
  428. /// </summary>
  429. /// <param name="cellheader"></param>
  430. /// <param name="inCount"></param>
  431. /// <param name="upCount"></param>
  432. /// <param name="errdataList"></param>
  433. /// <param name="errCount"></param>
  434. /// <param name="sourcePhysicalPath"></param>
  435. public void NumberImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount,
  436. out List<CerificateView> errdataList, out int? errCount, string sourcePhysicalPath)
  437. {
  438. try
  439. {
  440. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  441. List<CerificateView> errList = new List<CerificateView>();
  442. var CerificateList = Logic.DistributeRepository.Entities.ToList();
  443. var CerificateViewList = Logic.GetCerificateViewListOnlyGenerated(x => true, x => true, x => true, x => true, x => true).ToList();
  444. var ProjectList = Logic.ExaminationProjectRepository.Entities.ToList();
  445. var studentList = Logic.StudentRepository.Entities.ToList();
  446. var userList = Logic.UserRepository.Entities.ToList();
  447. // 1.1解析文件,存放到一个List集合里
  448. cellheader.Remove("ErrorMessage");//移除“未导入原因”列(ErrorMessage)
  449. List<CerificateView> enlist = NpoiExcelHelper.ExcelToEntityList<CerificateView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
  450. cellheader.Add("ErrorMessage", "未导入原因");
  451. //对List集合进行有效性校验
  452. if (enlist.Count() <= 0)
  453. {
  454. throw new Exception("Excel文件数据为空,请检查。");
  455. }
  456. Regex reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //学制字段正则表达式()
  457. inCount = 0; //导入个数
  458. upCount = 0; //更新个数
  459. errCount = 0; //失败个数
  460. string errorMsgStr = ""; //错误信息
  461. List<ER_CertisfierDistribute> upList = new List<ER_CertisfierDistribute>(); //专业信息update实体List
  462. //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
  463. for (int i = 0; i < enlist.Count; i++)
  464. {
  465. CerificateView en = enlist[i]; //Excel表数据视图
  466. //证件号码
  467. if (string.IsNullOrEmpty(en.IDNumber))
  468. {
  469. errCount++;
  470. errorMsgStr = "证件号码不能为空";
  471. en.ErrorMessage = errorMsgStr;
  472. errList.Add(en);
  473. errorMsg.AppendLine(errorMsgStr);
  474. continue;
  475. }
  476. else if (!studentList.Any(x => x.IDNumber.Trim() == en.IDNumber.Trim()))
  477. {
  478. errCount++;
  479. errorMsgStr = "学生不存在,请检查证件号码";
  480. en.ErrorMessage = errorMsgStr;
  481. errList.Add(en);
  482. errorMsg.AppendLine(errorMsgStr);
  483. continue;
  484. }
  485. //考试项目
  486. if (string.IsNullOrEmpty(en.ProjectName))
  487. {
  488. errCount++;
  489. errorMsgStr = "考试项目不能为空";
  490. en.ErrorMessage = errorMsgStr;
  491. errList.Add(en);
  492. errorMsg.AppendLine(errorMsgStr);
  493. continue;
  494. }
  495. else if (!ProjectList.Any(x => x.Name.Trim() == en.ProjectName.Trim()))
  496. {
  497. errCount++;
  498. errorMsgStr = "考试项目不存在,请检查考试项目名称";
  499. en.ErrorMessage = errorMsgStr;
  500. errList.Add(en);
  501. errorMsg.AppendLine(errorMsgStr);
  502. continue;
  503. }
  504. var entity = CerificateViewList.Where(x => x.ProjectName.Trim() == en.ProjectName.Trim() && x.IDNumber.Trim() == en.IDNumber.Trim()).FirstOrDefault();
  505. if (entity == null)
  506. {
  507. errCount++;
  508. errorMsgStr = "找不到考试项目和对应的学生,请检查该学生是否有该项目的证书";
  509. en.ErrorMessage = errorMsgStr;
  510. errList.Add(en);
  511. errorMsg.AppendLine(errorMsgStr);
  512. continue;
  513. }
  514. if (entity.RecordStatus == (int)ER_CertisfierDistributeStatus.Making || entity.RecordStatus == null)
  515. {
  516. errCount++;
  517. errorMsgStr = "制证中的证书无法导入存放编号";
  518. en.ErrorMessage = errorMsgStr;
  519. errList.Add(en);
  520. errorMsg.AppendLine(errorMsgStr);
  521. continue;
  522. }
  523. //if (entity.RecordStatus == (int)ER_CertisfierDistributeStatus.Making)
  524. //{
  525. // errCount++;
  526. // errorMsgStr = "制证中不允许导入";
  527. // en.ErrorMessage = errorMsgStr;
  528. // errList.Add(en);
  529. // errorMsg.AppendLine(errorMsgStr);
  530. // continue;
  531. //}
  532. //UnitOfWork.Update<ER_CertisfierDistribute>(x => new ER_CertisfierDistribute() { DeliveryNoteNo = en.DeliveryNoteNo, ContactPerson = en.ContactPerson, ContactNo = en.ContactNo, Address = en.Address, RecordStatus = (int)ER_CertisfierDistributeStatus.Complete }, x => x.CertisfierDistributeID == entity.CertisfierDistributeID);
  533. //CerificateList.FirstOrDefault(x => x.)
  534. var Cerificate = CerificateList.FirstOrDefault(x => x.ExaminationProjectID == entity.ExaminationProjectID && x.UserID == entity.UserID);
  535. Cerificate.SaveNo = en.SaveNo;
  536. upList.Add(Cerificate);
  537. upCount++;
  538. }
  539. UnitOfWork.BatchUpdate(upList);
  540. errdataList = errList.Distinct().ToList(); //错误列表List
  541. }
  542. catch (Exception ex)
  543. {
  544. //目前会出现,由于错误信息字符太长,无法抛出弹出框的问题
  545. throw new Exception(ex.Message);
  546. }
  547. }
  548. }
  549. }