RecruitSpecialtyServices.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using System.Transactions;
  8. using Bowin.Common.Utility;
  9. using Bowin.Common.Linq;
  10. using Bowin.Common.Linq.Entity;
  11. using EMIS.Utility;
  12. using EMIS.Entities;
  13. using EMIS.ViewModel;
  14. using EMIS.ViewModel.CacheManage;
  15. using EMIS.ViewModel.EnrollManage.SpecialtyManage;
  16. using EMIS.DataLogic.EnrollManage.SpecialtyManage;
  17. namespace EMIS.CommonLogic.EnrollManage.SpecialtyManage
  18. {
  19. public class RecruitSpecialtyServices : BaseServices, IRecruitSpecialtyServices
  20. {
  21. public RecruitSpecialtyDAL recruitSpecialtyDAL { get; set; }
  22. public Lazy<ISpecialtyApplyServices> SpecialtyApplyServices { get; set; }
  23. /// <summary>
  24. /// 查询对应的招生专业信息View
  25. /// </summary>
  26. /// <param name="configuretView"></param>
  27. /// <param name="campusID"></param>
  28. /// <param name="collegeID"></param>
  29. /// <param name="gradeID"></param>
  30. /// <param name="standardID"></param>
  31. /// <param name="educationID"></param>
  32. /// <param name="learningformID"></param>
  33. /// <param name="learnSystem"></param>
  34. /// <param name="isGenerated"></param>
  35. /// <param name="pageIndex"></param>
  36. /// <param name="pageSize"></param>
  37. /// <returns></returns>
  38. public IGridResultSet<RecruitSpecialtyView> GetRecruitSpecialtyViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID,
  39. int? educationID, int? learningformID, string learnSystem, int? isGenerated, int pageIndex, int pageSize)
  40. {
  41. //招生专业
  42. Expression<Func<CF_RecruitSpecialty, bool>> expRecruitSpecialty = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  43. if (collegeID.HasValue)
  44. {
  45. expRecruitSpecialty = expRecruitSpecialty.And(x => x.CollegeID == collegeID);
  46. }
  47. if (gradeID.HasValue)
  48. {
  49. expRecruitSpecialty = expRecruitSpecialty.And(x => x.GradeID == gradeID);
  50. }
  51. if (isGenerated.HasValue)
  52. {
  53. //生成状态
  54. if (isGenerated.Value == (int)CF_GeneralPurpose.IsYes)
  55. {
  56. expRecruitSpecialty = expRecruitSpecialty.And(x => x.isGenerated == true);
  57. }
  58. if (isGenerated.Value == (int)CF_GeneralPurpose.IsNo)
  59. {
  60. expRecruitSpecialty = expRecruitSpecialty.And(x => x.isGenerated != true);
  61. }
  62. }
  63. var query = recruitSpecialtyDAL.GetRecruitSpecialtyViewQueryable(expRecruitSpecialty);
  64. if (campusID.HasValue)
  65. {
  66. query = query.Where(x => x.CampusID == campusID);
  67. }
  68. if (standardID.HasValue)
  69. {
  70. query = query.Where(x => x.StandardID == standardID);
  71. }
  72. if (educationID.HasValue)
  73. {
  74. query = query.Where(x => x.EducationID == educationID);
  75. }
  76. if (learningformID.HasValue)
  77. {
  78. query = query.Where(x => x.LearningformID == learningformID);
  79. }
  80. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  81. {
  82. var LearnSystems = Convert.ToDecimal(learnSystem);
  83. query = query.Where(x => x.LearnSystem == LearnSystems);
  84. }
  85. //查询条件
  86. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  87. {
  88. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  89. }
  90. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeID)
  91. .ThenBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ToGridResultSet<RecruitSpecialtyView>(pageIndex, pageSize);
  92. }
  93. /// <summary>
  94. /// 查询对应的招生专业信息List
  95. /// </summary>
  96. /// <param name="configuretView"></param>
  97. /// <param name="campusID"></param>
  98. /// <param name="collegeID"></param>
  99. /// <param name="gradeID"></param>
  100. /// <param name="standardID"></param>
  101. /// <param name="educationID"></param>
  102. /// <param name="learningformID"></param>
  103. /// <param name="learnSystem"></param>
  104. /// <param name="isGenerated"></param>
  105. /// <returns></returns>
  106. public IList<RecruitSpecialtyView> GetRecruitSpecialtyViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID,
  107. int? educationID, int? learningformID, string learnSystem, int? isGenerated)
  108. {
  109. //招生专业
  110. Expression<Func<CF_RecruitSpecialty, bool>> expRecruitSpecialty = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  111. if (collegeID.HasValue)
  112. {
  113. expRecruitSpecialty = expRecruitSpecialty.And(x => x.CollegeID == collegeID);
  114. }
  115. if (gradeID.HasValue)
  116. {
  117. expRecruitSpecialty = expRecruitSpecialty.And(x => x.GradeID == gradeID);
  118. }
  119. if (isGenerated.HasValue)
  120. {
  121. //生成状态
  122. if (isGenerated.Value == (int)CF_GeneralPurpose.IsYes)
  123. {
  124. expRecruitSpecialty = expRecruitSpecialty.And(x => x.isGenerated == true);
  125. }
  126. if (isGenerated.Value == (int)CF_GeneralPurpose.IsNo)
  127. {
  128. expRecruitSpecialty = expRecruitSpecialty.And(x => x.isGenerated != true);
  129. }
  130. }
  131. var query = recruitSpecialtyDAL.GetRecruitSpecialtyViewQueryable(expRecruitSpecialty);
  132. if (campusID.HasValue)
  133. {
  134. query = query.Where(x => x.CampusID == campusID);
  135. }
  136. if (standardID.HasValue)
  137. {
  138. query = query.Where(x => x.StandardID == standardID);
  139. }
  140. if (educationID.HasValue)
  141. {
  142. query = query.Where(x => x.EducationID == educationID);
  143. }
  144. if (learningformID.HasValue)
  145. {
  146. query = query.Where(x => x.LearningformID == learningformID);
  147. }
  148. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  149. {
  150. var LearnSystems = Convert.ToDecimal(learnSystem);
  151. query = query.Where(x => x.LearnSystem == LearnSystems);
  152. }
  153. //查询条件
  154. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  155. {
  156. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  157. }
  158. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeID)
  159. .ThenBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ToList();
  160. }
  161. /// <summary>
  162. /// 查询对应的招生专业信息CF_RecruitSpecialty
  163. /// </summary>
  164. /// <param name="recruitSpecialtyID"></param>
  165. /// <returns></returns>
  166. public CF_RecruitSpecialty GetRecruitSpecialtyInfo(Guid? recruitSpecialtyID)
  167. {
  168. try
  169. {
  170. var query = recruitSpecialtyDAL.recruitSpecialtyRepository.GetList(x => x.RecruitSpecialtyID == recruitSpecialtyID).SingleOrDefault();
  171. return query;
  172. }
  173. catch (Exception ex)
  174. {
  175. throw new Exception(ex.Message);
  176. }
  177. }
  178. /// <summary>
  179. /// 查询对应的招生专业信息RecruitSpecialtyView
  180. /// </summary>
  181. /// <param name="recruitSpecialtyID"></param>
  182. /// <returns></returns>
  183. public RecruitSpecialtyView GetRecruitSpecialtyView(Guid? recruitSpecialtyID)
  184. {
  185. try
  186. {
  187. var query = recruitSpecialtyDAL.GetRecruitSpecialtyViewQueryable(x => x.RecruitSpecialtyID == recruitSpecialtyID).SingleOrDefault();
  188. return query;
  189. }
  190. catch (Exception ex)
  191. {
  192. throw new Exception(ex.Message);
  193. }
  194. }
  195. /// <summary>
  196. /// 招生专业批量新增(业务主键:专业信息ID、年级、学期、院系所)
  197. /// </summary>
  198. /// <param name="specialtyIDList"></param>
  199. /// <param name="recruitSpecialtyView"></param>
  200. /// <returns></returns>
  201. public string RecruitSpecialtyBatchAdd(List<Guid?> specialtyIDList, RecruitSpecialtyView recruitSpecialtyView)
  202. {
  203. try
  204. {
  205. var endStatusID = SpecialtyApplyServices.Value.GetCorrectEndStatus();
  206. if (endStatusID == null)
  207. {
  208. throw new Exception("工作流平台中,招生专业流程结束环节未配置,请核查");
  209. }
  210. //招生专业
  211. Expression<Func<CF_RecruitSpecialty, bool>> expRecruitSpecialty = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  212. expRecruitSpecialty = expRecruitSpecialty.And(x => specialtyIDList.Contains(x.SpecialtyID));
  213. //查询对应的招生专业信息List
  214. var recruitSpecialtyList = recruitSpecialtyDAL.recruitSpecialtyRepository.GetList(expRecruitSpecialty).ToList();
  215. int success = 0;
  216. int fail = 0;
  217. string tipMessage = null;
  218. List<CF_RecruitSpecialty> recruitSpecialtyInList = new List<CF_RecruitSpecialty>();
  219. foreach (var specialtyID in specialtyIDList)
  220. {
  221. var recruitSpecialtyVerify = recruitSpecialtyList.Where(x => x.SpecialtyID == specialtyID && x.CollegeID == recruitSpecialtyView.CollegeID
  222. && x.GradeID == recruitSpecialtyView.GradeID && x.SemesterID == recruitSpecialtyView.SemesterID).SingleOrDefault();
  223. if (recruitSpecialtyVerify == null)
  224. {
  225. //新增
  226. var recruitSpecialty = new CF_RecruitSpecialty();
  227. recruitSpecialty.RecruitSpecialtyID = Guid.NewGuid();
  228. recruitSpecialty.SpecialtyApplyID = null;
  229. recruitSpecialty.SpecialtyID = specialtyID;
  230. recruitSpecialty.CollegeID = recruitSpecialtyView.CollegeID;
  231. recruitSpecialty.GradeID = recruitSpecialtyView.GradeID;
  232. recruitSpecialty.SemesterID = recruitSpecialtyView.SemesterID;
  233. recruitSpecialty.ApprovalStatus = endStatusID;
  234. recruitSpecialty.isGenerated = false;
  235. recruitSpecialty.Remark = recruitSpecialtyView.Remark;
  236. SetNewStatus(recruitSpecialty);
  237. recruitSpecialtyInList.Add(recruitSpecialty);
  238. success++;
  239. }
  240. else
  241. {
  242. //表示已存在相同的招生专业信息
  243. fail++;
  244. }
  245. }
  246. //批量插入
  247. UnitOfWork.BulkInsert<CF_RecruitSpecialty>(recruitSpecialtyInList);
  248. if (success > 0 && fail <= 0)
  249. {
  250. tipMessage = success + "条";
  251. }
  252. else
  253. {
  254. tipMessage = success + "条," + fail + "条失败,原因:已存在相同的招生专业信息,请检查";
  255. }
  256. return tipMessage;
  257. }
  258. catch (Exception ex)
  259. {
  260. throw new Exception(ex.Message);
  261. }
  262. }
  263. /// <summary>
  264. /// 查询招生专业中未新增的专业信息SpecialtyView
  265. /// </summary>
  266. /// <param name="configuretView"></param>
  267. /// <param name="collegeID"></param>
  268. /// <param name="gradeID"></param>
  269. /// <param name="semesterID"></param>
  270. /// <param name="standardID"></param>
  271. /// <param name="educationID"></param>
  272. /// <param name="learningformID"></param>
  273. /// <param name="learnSystem"></param>
  274. /// <param name="scienceclassID"></param>
  275. /// <param name="pageIndex"></param>
  276. /// <param name="pageSize"></param>
  277. /// <returns></returns>
  278. public IGridResultSet<SpecialtyView> GetSpecialtyViewNoAdd(ConfiguretView configuretView, Guid? collegeID, int? gradeID, int? semesterID, int? standardID,
  279. int? educationID, int? learningformID, string learnSystem, int? scienceclassID, int pageIndex, int pageSize)
  280. {
  281. //专业信息(只查询启用状态的专业信息)
  282. Expression<Func<CF_Specialty, bool>> expSpecialty = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  283. if (standardID.HasValue)
  284. {
  285. expSpecialty = expSpecialty.And(x => x.StandardID == standardID);
  286. }
  287. if (educationID.HasValue)
  288. {
  289. expSpecialty = expSpecialty.And(x => x.EducationID == educationID);
  290. }
  291. if (learningformID.HasValue)
  292. {
  293. expSpecialty = expSpecialty.And(x => x.LearningformID == learningformID);
  294. }
  295. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  296. {
  297. var LearnSystems = Convert.ToDecimal(learnSystem);
  298. expSpecialty = expSpecialty.And(x => x.LearnSystem == LearnSystems);
  299. }
  300. if (scienceclassID.HasValue)
  301. {
  302. expSpecialty = expSpecialty.And(x => x.ScienceclassID == scienceclassID);
  303. }
  304. //招生专业
  305. Expression<Func<CF_RecruitSpecialty, bool>> expRecruitSpecialty = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  306. if (collegeID.HasValue)
  307. {
  308. expRecruitSpecialty = expRecruitSpecialty.And(x => x.CollegeID == collegeID);
  309. }
  310. if (gradeID.HasValue)
  311. {
  312. expRecruitSpecialty = expRecruitSpecialty.And(x => x.GradeID == gradeID);
  313. }
  314. if (semesterID.HasValue)
  315. {
  316. expRecruitSpecialty = expRecruitSpecialty.And(x => x.SemesterID == semesterID);
  317. }
  318. var query = recruitSpecialtyDAL.GetSpecialtyViewNoAddQueryable(expSpecialty, expRecruitSpecialty);
  319. //查询条件
  320. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  321. {
  322. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  323. }
  324. return query.OrderBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ToGridResultSet<SpecialtyView>(pageIndex, pageSize);
  325. }
  326. /// <summary>
  327. /// 编辑(新增、修改,业务主键:专业信息ID、院系所、年级、学期)
  328. /// </summary>
  329. /// <param name="recruitSpecialtyView"></param>
  330. public void RecruitSpecialtyEdit(RecruitSpecialtyView recruitSpecialtyView)
  331. {
  332. try
  333. {
  334. var endStatusID = SpecialtyApplyServices.Value.GetCorrectEndStatus();
  335. if (endStatusID == null)
  336. {
  337. throw new Exception("工作流平台中,招生专业流程结束环节未配置,请核查");
  338. }
  339. //查询数据库进行验证
  340. var recruitSpecialtyVerification = recruitSpecialtyDAL.recruitSpecialtyRepository.GetList(x => x.RecruitSpecialtyID != recruitSpecialtyView.RecruitSpecialtyID
  341. && x.SpecialtyID == recruitSpecialtyView.SpecialtyID && x.CollegeID == recruitSpecialtyView.CollegeID
  342. && x.GradeID == recruitSpecialtyView.GradeID && x.SemesterID == recruitSpecialtyView.SemesterID).SingleOrDefault();
  343. if (recruitSpecialtyVerification == null)
  344. {
  345. //数据有误验证
  346. if (recruitSpecialtyView.RecruitSpecialtyID != Guid.Empty)
  347. {
  348. var recruitSpecialty = recruitSpecialtyDAL.recruitSpecialtyRepository.GetList(x => x.RecruitSpecialtyID == recruitSpecialtyView.RecruitSpecialtyID).SingleOrDefault();
  349. if (recruitSpecialty == null)
  350. {
  351. throw new Exception("数据有误,请核查");
  352. }
  353. else
  354. {
  355. //表示修改
  356. recruitSpecialty.Remark = recruitSpecialtyView.Remark;
  357. SetModifyStatus(recruitSpecialty);
  358. }
  359. }
  360. else
  361. {
  362. //表示新增
  363. var recruitSpecialty = new CF_RecruitSpecialty();
  364. recruitSpecialty.RecruitSpecialtyID = Guid.NewGuid();
  365. recruitSpecialty.SpecialtyApplyID = null;
  366. recruitSpecialty.SpecialtyID = recruitSpecialtyView.SpecialtyID;
  367. recruitSpecialty.CollegeID = recruitSpecialtyView.CollegeID;
  368. recruitSpecialty.GradeID = recruitSpecialtyView.GradeID;
  369. recruitSpecialty.SemesterID = recruitSpecialtyView.SemesterID;
  370. recruitSpecialty.ApprovalStatus = endStatusID;
  371. recruitSpecialty.isGenerated = false;
  372. recruitSpecialty.Remark = recruitSpecialtyView.Remark;
  373. SetNewStatus(recruitSpecialty);
  374. UnitOfWork.Add(recruitSpecialty);
  375. }
  376. }
  377. else
  378. {
  379. throw new Exception("已存在相同的招生专业信息(专业信息、" + RSL.Get("College") + "、年级、学期唯一),请核查");
  380. }
  381. //事务提交
  382. UnitOfWork.Commit();
  383. }
  384. catch (Exception ex)
  385. {
  386. throw new Exception(ex.Message);
  387. }
  388. }
  389. /// <summary>
  390. /// 专业班级生成(由于各高校生成规则不同,需分版本—个性化配置)
  391. /// </summary>
  392. /// <param name="recruitSpecialtyIDs"></param>
  393. /// <returns></returns>
  394. public virtual string GenerateClass(List<Guid?> recruitSpecialtyIDs)
  395. {
  396. //根据各高校个性化要求进行配置
  397. throw new Exception("生成规则配置有误(根据个性化要求进行配置),请检查");
  398. }
  399. /// <summary>
  400. /// 删除(需根据业务主键删除对应的流程结束专业申请信息)
  401. /// </summary>
  402. /// <param name="recruitSpecialtyIDList"></param>
  403. /// <returns></returns>
  404. public bool RecruitSpecialtyDelete(List<Guid?> recruitSpecialtyIDList)
  405. {
  406. try
  407. {
  408. //查询招生专业工作流程线束环节状态
  409. var endStatusID = SpecialtyApplyServices.Value.GetCorrectEndStatus();
  410. if (endStatusID == null)
  411. {
  412. throw new Exception("工作流平台中,招生专业流程结束环节未配置,请核查");
  413. }
  414. //查询对应的招生专业信息List
  415. var recruitSpecialtyList = this.recruitSpecialtyDAL.recruitSpecialtyRepository.GetList(x => recruitSpecialtyIDList.Contains(x.RecruitSpecialtyID)).ToList();
  416. //招生专业中对应的专业信息IDList
  417. var specialtyIDList = recruitSpecialtyList.Select(x => x.SpecialtyID).ToList();
  418. //查询对应的专业申请信息List
  419. var specialtyApplyList = recruitSpecialtyDAL.specialtyApplyRepository.GetList(x => specialtyIDList.Contains(x.SpecialtyID)).ToList();
  420. //查询专业申请信息List(流程结束)
  421. List<Guid> specialtyApplyIDList = new List<Guid>();
  422. foreach (var recruitSpecialty in recruitSpecialtyList)
  423. {
  424. //查询专业申请信息
  425. var specialtyApply = specialtyApplyList.Where(x => x.SpecialtyID == recruitSpecialty.SpecialtyID && x.CollegeID == recruitSpecialty.CollegeID
  426. && x.GradeID == recruitSpecialty.GradeID && x.SemesterID == recruitSpecialty.SemesterID && x.ApprovalStatus == endStatusID).SingleOrDefault();
  427. if (specialtyApply != null)
  428. {
  429. specialtyApplyIDList.Add(specialtyApply.SpecialtyApplyID);
  430. }
  431. }
  432. using (TransactionScope ts = new TransactionScope())
  433. {
  434. if (recruitSpecialtyIDList != null && recruitSpecialtyIDList.Count() > 0)
  435. {
  436. UnitOfWork.Delete<CF_RecruitSpecialty>(x => recruitSpecialtyIDList.Contains(x.RecruitSpecialtyID));
  437. }
  438. if (specialtyApplyIDList != null && specialtyApplyIDList.Count() > 0)
  439. {
  440. UnitOfWork.Delete<CF_SpecialtyApply>(x => specialtyApplyIDList.Contains(x.SpecialtyApplyID));
  441. }
  442. ts.Complete();
  443. }
  444. return true;
  445. }
  446. catch (Exception)
  447. {
  448. throw;
  449. }
  450. }
  451. /// <summary>
  452. /// Excel导入
  453. /// </summary>
  454. /// <param name="cellheader"></param>
  455. /// <param name="inCount"></param>
  456. /// <param name="upCount"></param>
  457. /// <param name="errdataList"></param>
  458. /// <param name="errCount"></param>
  459. /// <param name="sourcePhysicalPath"></param>
  460. public void RecruitSpecialtyImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount, out List<RecruitSpecialtyView> errdataList, out int? errCount, string sourcePhysicalPath)
  461. {
  462. try
  463. {
  464. //查询招生专业工作流程结束环节状态
  465. var endStatusID = SpecialtyApplyServices.Value.GetCorrectEndStatus();
  466. if (endStatusID == null)
  467. {
  468. throw new Exception("工作流平台中,招生专业流程结束环节未配置,请核查");
  469. }
  470. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  471. List<RecruitSpecialtyView> errList = new List<RecruitSpecialtyView>();
  472. // 1.1解析文件,存放到一个List集合里
  473. cellheader.Remove("ErrorMessage");//移除“未导入原因”列(ErrorMessage)
  474. List<RecruitSpecialtyView> enlist = NpoiExcelHelper.ExcelToEntityList<RecruitSpecialtyView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
  475. cellheader.Add("ErrorMessage", "未导入原因");
  476. //对List集合进行有效性校验
  477. if (enlist.Count() <= 0)
  478. {
  479. throw new Exception("Excel文件数据为空,请检查。");
  480. }
  481. Regex reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //学制字段正则表达式()
  482. inCount = 0; //导入个数
  483. upCount = 0; //更新个数
  484. errCount = 0; //失败个数
  485. string errorMsgStr = ""; //错误信息
  486. List<CF_RecruitSpecialty> recruitSpecialtyInList = new List<CF_RecruitSpecialty>();
  487. List<CF_RecruitSpecialty> recruitSpecialtyUpList = new List<CF_RecruitSpecialty>();
  488. //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
  489. //专业代码、专业名称、专业ID(Value)
  490. var standardList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Standard).ToList();
  491. //培养层次(所修学历)
  492. var educationList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Education).ToList();
  493. //学习形式
  494. var learningFormList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Learningform).ToList();
  495. //院系所代码
  496. var collegeNoList = enlist.Where(x => !string.IsNullOrEmpty(x.CollegeNo)).Select(x => x.CollegeNo).ToList();
  497. //对应的院系所信息
  498. var collegeList = recruitSpecialtyDAL.collegeRepository.GetList(x => collegeNoList.Contains(x.No), x => x.CF_CollegeProfile).ToList();
  499. //GradeStr
  500. var gradeStrList = enlist.Where(x => !string.IsNullOrEmpty(x.GradeStr)).Select(x => x.GradeStr).ToList();
  501. //年级
  502. var gradeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Grade).ToList();
  503. //学期
  504. var semesterList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Semester).ToList();
  505. //专业信息
  506. var specialtyList = recruitSpecialtyDAL.specialtyRepository.GetList(x => true).ToList();
  507. //招生专业
  508. var recruitSpecialtyList = recruitSpecialtyDAL.recruitSpecialtyRepository.GetList(x => gradeStrList.Contains(x.GradeID.ToString())).ToList();
  509. //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
  510. for (int i = 0; i < enlist.Count; i++)
  511. {
  512. RecruitSpecialtyView en = enlist[i]; //Excel表数据视图
  513. var recruitSpecialty = new CF_RecruitSpecialty(); //招生专业实体
  514. //专业代码
  515. if (string.IsNullOrEmpty(en.StandardCode))
  516. {
  517. errCount++;
  518. errorMsgStr = "专业代码不能为空";
  519. en.ErrorMessage = errorMsgStr;
  520. errList.Add(en);
  521. errorMsg.AppendLine(errorMsgStr);
  522. continue;
  523. }
  524. else
  525. {
  526. var standardCode = standardList.Where(x => x.Code == en.StandardCode.Trim()).FirstOrDefault();
  527. if (standardCode == null)
  528. {
  529. errCount++;
  530. errorMsgStr = "专业代码不存在,请检查";
  531. en.ErrorMessage = errorMsgStr;
  532. errList.Add(en);
  533. errorMsg.AppendLine(errorMsgStr);
  534. continue;
  535. }
  536. else
  537. {
  538. //专业代码
  539. }
  540. }
  541. //专业名称
  542. if (string.IsNullOrEmpty(en.StandardName))
  543. {
  544. errCount++;
  545. errorMsgStr = "专业名称不能为空";
  546. en.ErrorMessage = errorMsgStr;
  547. errList.Add(en);
  548. errorMsg.AppendLine(errorMsgStr);
  549. continue;
  550. }
  551. else
  552. {
  553. var standardName = standardList.Where(x => x.Name == en.StandardName.Trim()).FirstOrDefault();
  554. if (standardName == null)
  555. {
  556. errCount++;
  557. errorMsgStr = "专业名称不存在,请检查";
  558. en.ErrorMessage = errorMsgStr;
  559. errList.Add(en);
  560. errorMsg.AppendLine(errorMsgStr);
  561. continue;
  562. }
  563. else
  564. {
  565. //专业名称
  566. }
  567. }
  568. //专业代码与专业名称查询专业ID(Value)
  569. if (string.IsNullOrEmpty(en.StandardCode) || string.IsNullOrEmpty(en.StandardName))
  570. {
  571. errCount++;
  572. errorMsgStr = "专业代码或专业名称不能为空";
  573. en.ErrorMessage = errorMsgStr;
  574. errList.Add(en);
  575. errorMsg.AppendLine(errorMsgStr);
  576. continue;
  577. }
  578. else
  579. {
  580. var standardID = standardList.Where(x => x.Code == en.StandardCode.Trim() && x.Name == en.StandardName.Trim()).SingleOrDefault();
  581. if (standardID == null)
  582. {
  583. errCount++;
  584. errorMsgStr = "专业代码与专业名称对应的元素值不存在,请检查";
  585. en.ErrorMessage = errorMsgStr;
  586. errList.Add(en);
  587. errorMsg.AppendLine(errorMsgStr);
  588. continue;
  589. }
  590. else
  591. {
  592. //专业ID(Value)
  593. en.StandardID = standardID.Value;
  594. }
  595. }
  596. //培养层次(所修学历)
  597. if (string.IsNullOrEmpty(en.EducationStr))
  598. {
  599. errCount++;
  600. errorMsgStr = RSL.Get("EducationID") + "不能为空";
  601. en.ErrorMessage = errorMsgStr;
  602. errList.Add(en);
  603. errorMsg.AppendLine(errorMsgStr);
  604. continue;
  605. }
  606. else
  607. {
  608. var education = educationList.Where(x => x.Name == en.EducationStr.Trim()).SingleOrDefault();
  609. if (education == null)
  610. {
  611. errCount++;
  612. errorMsgStr = RSL.Get("EducationID") + "不存在,请检查";
  613. en.ErrorMessage = errorMsgStr;
  614. errList.Add(en);
  615. errorMsg.AppendLine(errorMsgStr);
  616. continue;
  617. }
  618. else
  619. {
  620. //培养层次
  621. en.EducationID = education.Value;
  622. }
  623. }
  624. //学习形式
  625. if (string.IsNullOrEmpty(en.LearningformStr))
  626. {
  627. errCount++;
  628. errorMsgStr = "学习形式不能为空";
  629. en.ErrorMessage = errorMsgStr;
  630. errList.Add(en);
  631. errorMsg.AppendLine(errorMsgStr);
  632. continue;
  633. }
  634. else
  635. {
  636. var learningForm = learningFormList.Where(x => x.Name == en.LearningformStr.Trim()).SingleOrDefault();
  637. if (learningForm == null)
  638. {
  639. errCount++;
  640. errorMsgStr = "学习形式不存在,请检查";
  641. en.ErrorMessage = errorMsgStr;
  642. errList.Add(en);
  643. errorMsg.AppendLine(errorMsgStr);
  644. continue;
  645. }
  646. else
  647. {
  648. //学习形式
  649. en.LearningformID = learningForm.Value;
  650. }
  651. }
  652. //学制
  653. if (string.IsNullOrEmpty(en.LearnSystemStr))
  654. {
  655. errCount++;
  656. errorMsgStr = "学制不能为空";
  657. en.ErrorMessage = errorMsgStr;
  658. errList.Add(en);
  659. errorMsg.AppendLine(errorMsgStr);
  660. continue;
  661. }
  662. else
  663. {
  664. if (!reg.IsMatch(en.LearnSystemStr))
  665. {
  666. errCount++;
  667. errorMsgStr = "学制格式不正确,请检查";
  668. en.ErrorMessage = errorMsgStr;
  669. errList.Add(en);
  670. errorMsg.AppendLine(errorMsgStr);
  671. continue;
  672. }
  673. else
  674. {
  675. //学制
  676. en.LearnSystem = Convert.ToDecimal(en.LearnSystemStr);
  677. }
  678. }
  679. //专业信息查询
  680. var specialty = specialtyList.Where(x => x.StandardID == en.StandardID && x.EducationID == en.EducationID && x.LearningformID == en.LearningformID && x.LearnSystem == en.LearnSystem).SingleOrDefault();
  681. //专业信息ID
  682. if (specialty == null)
  683. {
  684. errCount++;
  685. errorMsgStr = "专业信息不存在,请检查";
  686. en.ErrorMessage = errorMsgStr;
  687. errList.Add(en);
  688. errorMsg.AppendLine(errorMsgStr);
  689. continue;
  690. }
  691. else
  692. {
  693. //查询专业信息(启用、禁用状态)
  694. if (specialty.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  695. {
  696. recruitSpecialty.SpecialtyID = specialty.SpecialtyID;
  697. }
  698. else
  699. {
  700. recruitSpecialty.SpecialtyID = specialty.SpecialtyID;
  701. errCount++;
  702. errorMsgStr = "专业信息为禁用状态,请检查";
  703. en.ErrorMessage = errorMsgStr;
  704. errList.Add(en);
  705. errorMsg.AppendLine(errorMsgStr);
  706. continue;
  707. }
  708. }
  709. //院系所代码
  710. if (string.IsNullOrEmpty(en.CollegeNo))
  711. {
  712. errCount++;
  713. errorMsgStr = RSL.Get("CollegeCode") + "不能为空";
  714. en.ErrorMessage = errorMsgStr;
  715. errList.Add(en);
  716. errorMsg.AppendLine(errorMsgStr);
  717. continue;
  718. }
  719. else
  720. {
  721. var college = collegeList.Where(x => x.No == en.CollegeNo.Trim()).SingleOrDefault();
  722. if (college == null)
  723. {
  724. errCount++;
  725. errorMsgStr = RSL.Get("CollegeCode") + "不存在,请检查";
  726. en.ErrorMessage = errorMsgStr;
  727. errList.Add(en);
  728. errorMsg.AppendLine(errorMsgStr);
  729. continue;
  730. }
  731. else
  732. {
  733. if (college.CF_CollegeProfile == null)
  734. {
  735. errCount++;
  736. errorMsgStr = RSL.Get("CollegeCode") + "所属的单位类别有误,请检查";
  737. en.ErrorMessage = errorMsgStr;
  738. errList.Add(en);
  739. errorMsg.AppendLine(errorMsgStr);
  740. continue;
  741. }
  742. else if (college.CF_CollegeProfile.UnitCategoryID != (int)CF_UnitCategory.College)
  743. {
  744. errCount++;
  745. errorMsgStr = RSL.Get("CollegeCode") + "所属的单位类别有误,请检查";
  746. en.ErrorMessage = errorMsgStr;
  747. errList.Add(en);
  748. errorMsg.AppendLine(errorMsgStr);
  749. continue;
  750. }
  751. //院系所ID
  752. recruitSpecialty.CollegeID = college.CollegeID;
  753. }
  754. }
  755. //年级
  756. if (string.IsNullOrEmpty(en.GradeStr))
  757. {
  758. errCount++;
  759. errorMsgStr = "年级不能为空";
  760. en.ErrorMessage = errorMsgStr;
  761. errList.Add(en);
  762. errorMsg.AppendLine(errorMsgStr);
  763. continue;
  764. }
  765. else
  766. {
  767. var grade = gradeList.Where(x => x.Name == en.GradeStr.Trim()).SingleOrDefault();
  768. if (grade == null)
  769. {
  770. errCount++;
  771. errorMsgStr = "年级不存在,请检查";
  772. en.ErrorMessage = errorMsgStr;
  773. errList.Add(en);
  774. errorMsg.AppendLine(errorMsgStr);
  775. continue;
  776. }
  777. else
  778. {
  779. //年级
  780. recruitSpecialty.GradeID = grade.Value;
  781. }
  782. }
  783. //学期
  784. if (string.IsNullOrEmpty(en.SemesterStr))
  785. {
  786. errCount++;
  787. errorMsgStr = "学期不能为空";
  788. en.ErrorMessage = errorMsgStr;
  789. errList.Add(en);
  790. errorMsg.AppendLine(errorMsgStr);
  791. continue;
  792. }
  793. else
  794. {
  795. var semester = semesterList.Where(x => x.Name == en.SemesterStr.Trim()).SingleOrDefault();
  796. if (semester == null)
  797. {
  798. errCount++;
  799. errorMsgStr = "学期不存在,请检查";
  800. en.ErrorMessage = errorMsgStr;
  801. errList.Add(en);
  802. errorMsg.AppendLine(errorMsgStr);
  803. continue;
  804. }
  805. else
  806. {
  807. //学期
  808. recruitSpecialty.SemesterID = semester.Value;
  809. }
  810. }
  811. //备注
  812. recruitSpecialty.Remark = en.Remark;
  813. ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉)
  814. //for (int j = i + 1; j < enlist.Count; j++)
  815. //{
  816. // RecruitSpecialtyView enA = enlist[j];
  817. // //根据Excel表中的业务主键进行去重(专业代码、专业名称、学制、培养层次(所修学历)、学习形式、年级、学期、院系所代码唯一)
  818. // if (en.StandardCode == enA.StandardCode && en.StandardName == enA.StandardName
  819. // && en.LearnSystemStr == enA.LearnSystemStr
  820. // && en.EducationStr == enA.EducationStr
  821. // && en.LearningformStr == enA.LearningformStr
  822. // && en.GradeStr == enA.GradeStr
  823. // && en.SemesterStr == enA.SemesterStr
  824. // && en.CollegeNo == enA.CollegeNo)
  825. // {
  826. // //用于标识Excel表中的重复记录(由于是批量进行插入数据表)
  827. // }
  828. //}
  829. //由于招生专业表与专业申请表不同,招生专业新增时,需进行处理(目前采用方法一进行处理)
  830. //处理方法一:目前已在工作流审核处理通过时,进行了相关处理(采用更新的方式)
  831. //处理方法二:可在此处进行判断处理,以Excel错误数据方式进行抛出,提示信息:数据重复,工作流程中已存在此数据
  832. //数据表重复性验证(专业信息ID、年级、学期、院系所ID唯一)
  833. var recruitSpecialtyVerify = recruitSpecialtyList.Where(x => x.GradeID == recruitSpecialty.GradeID && x.SemesterID == recruitSpecialty.SemesterID
  834. && x.SpecialtyID == recruitSpecialty.SpecialtyID && x.CollegeID == recruitSpecialty.CollegeID).SingleOrDefault();
  835. if (recruitSpecialtyVerify == null)
  836. {
  837. //新增
  838. if (!recruitSpecialtyInList.Any(x => x.GradeID == recruitSpecialty.GradeID && x.SemesterID == recruitSpecialty.SemesterID
  839. && x.SpecialtyID == recruitSpecialty.SpecialtyID && x.CollegeID == recruitSpecialty.CollegeID))
  840. {
  841. recruitSpecialty.RecruitSpecialtyID = Guid.NewGuid();
  842. recruitSpecialty.SpecialtyApplyID = null;
  843. recruitSpecialty.ApprovalStatus = endStatusID;
  844. recruitSpecialty.isGenerated = false;
  845. SetNewStatus(recruitSpecialty);
  846. recruitSpecialtyInList.Add(recruitSpecialty);
  847. inCount++;
  848. }
  849. else
  850. {
  851. //Excel表重复性验证
  852. //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑)
  853. inCount++;
  854. }
  855. }
  856. else
  857. {
  858. //更新(Excel有重复时,以最后一条记录的更新为准)
  859. recruitSpecialtyVerify.Remark = recruitSpecialty.Remark;
  860. SetModifyStatus(recruitSpecialtyVerify);
  861. recruitSpecialtyUpList.Add(recruitSpecialtyVerify);
  862. upCount++;
  863. }
  864. }
  865. using (TransactionScope ts = new TransactionScope())
  866. {
  867. if (recruitSpecialtyInList != null && recruitSpecialtyInList.Count() > 0)
  868. {
  869. UnitOfWork.BulkInsert(recruitSpecialtyInList);
  870. }
  871. if (recruitSpecialtyUpList != null && recruitSpecialtyUpList.Count() > 0)
  872. {
  873. UnitOfWork.BatchUpdate(recruitSpecialtyUpList);
  874. }
  875. ts.Complete();
  876. }
  877. errdataList = errList.Distinct().ToList();
  878. }
  879. catch (Exception)
  880. {
  881. throw;
  882. }
  883. }
  884. }
  885. }