NewStudentCollegeServices.cs 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  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.Data;
  8. using System.IO;
  9. using System.Transactions;
  10. using Bowin.Common.Utility;
  11. using Bowin.Common.Linq;
  12. using Bowin.Common.Linq.Entity;
  13. using EMIS.Utility;
  14. using EMIS.Entities;
  15. using EMIS.ViewModel;
  16. using EMIS.ViewModel.CacheManage;
  17. using EMIS.ViewModel.EnrollManage.NewStudentManage;
  18. using EMIS.DataLogic.EnrollManage.NewStudentManage;
  19. namespace EMIS.CommonLogic.EnrollManage.NewStudentManage
  20. {
  21. public class NewStudentCollegeServices : BaseServices, INewStudentCollegeServices
  22. {
  23. public NewStudentDAL NewStudentDAL { get; set; }
  24. /// <summary>
  25. /// 查询新生分配信息View
  26. /// </summary>
  27. /// <param name="configuretView"></param>
  28. /// <param name="campusID"></param>
  29. /// <param name="collegeID"></param>
  30. /// <param name="gradeID"></param>
  31. /// <param name="standardID"></param>
  32. /// <param name="educationID"></param>
  33. /// <param name="learningformID"></param>
  34. /// <param name="learnSystem"></param>
  35. /// <param name="isPhoto"></param>
  36. /// <param name="pageIndex"></param>
  37. /// <param name="pageSize"></param>
  38. /// <returns></returns>
  39. public IGridResultSet<NewStudentView> GetNewStudentCollegeViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID,
  40. int? standardID, int? educationID, int? learningformID, string learnSystem, int? isPhoto, int pageIndex, int pageSize)
  41. {
  42. Expression<Func<CF_NewStudent, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  43. exp = exp.And(x => x.AssignStatus == (int)CF_AssignStatus.PreAssigned);
  44. if (collegeID.HasValue)
  45. {
  46. exp = exp.And(x => x.CollegeID == collegeID);
  47. }
  48. if (gradeID.HasValue)
  49. {
  50. exp = exp.And(x => x.GradeID == gradeID);
  51. }
  52. if (isPhoto.HasValue)
  53. {
  54. if (isPhoto.Value == (int)CF_GeneralExist.Have)
  55. {
  56. exp = exp.And(x => x.RecruitPictureUrl != null && x.RecruitPictureUrl != "");
  57. }
  58. if (isPhoto.Value == (int)CF_GeneralExist.No)
  59. {
  60. exp = exp.And(x => x.RecruitPictureUrl == null || x.RecruitPictureUrl == "");
  61. }
  62. }
  63. var query = NewStudentDAL.GetNewStudentCollegeViewQueryable(exp);
  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).OrderBy(x => x.OrderNo).ToGridResultSet<NewStudentView>(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="isPhoto"></param>
  105. /// <returns></returns>
  106. public IList<NewStudentView> GetNewStudentCollegeViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID,
  107. int? standardID, int? educationID, int? learningformID, string learnSystem, int? isPhoto)
  108. {
  109. Expression<Func<CF_NewStudent, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  110. exp = exp.And(x => x.AssignStatus == (int)CF_AssignStatus.PreAssigned);
  111. if (collegeID.HasValue)
  112. {
  113. exp = exp.And(x => x.CollegeID == collegeID);
  114. }
  115. if (gradeID.HasValue)
  116. {
  117. exp = exp.And(x => x.GradeID == gradeID);
  118. }
  119. if (isPhoto.HasValue)
  120. {
  121. if (isPhoto.Value == (int)CF_GeneralExist.Have)
  122. {
  123. exp = exp.And(x => x.RecruitPictureUrl != null && x.RecruitPictureUrl != "");
  124. }
  125. if (isPhoto.Value == (int)CF_GeneralExist.No)
  126. {
  127. exp = exp.And(x => x.RecruitPictureUrl == null || x.RecruitPictureUrl == "");
  128. }
  129. }
  130. var query = NewStudentDAL.GetNewStudentCollegeViewQueryable(exp);
  131. if (campusID.HasValue)
  132. {
  133. query = query.Where(x => x.CampusID == campusID);
  134. }
  135. if (standardID.HasValue)
  136. {
  137. query = query.Where(x => x.StandardID == standardID);
  138. }
  139. if (educationID.HasValue)
  140. {
  141. query = query.Where(x => x.EducationID == educationID);
  142. }
  143. if (learningformID.HasValue)
  144. {
  145. query = query.Where(x => x.LearningformID == learningformID);
  146. }
  147. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  148. {
  149. var LearnSystems = Convert.ToDecimal(learnSystem);
  150. query = query.Where(x => x.LearnSystem == LearnSystems);
  151. }
  152. //查询条件
  153. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  154. {
  155. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  156. }
  157. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeID)
  158. .ThenBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).OrderBy(x => x.OrderNo).ToList();
  159. }
  160. /// <summary>
  161. /// 查询未分配新生名单信息View
  162. /// </summary>
  163. /// <param name="configuretView"></param>
  164. /// <param name="gradeID"></param>
  165. /// <param name="standardID"></param>
  166. /// <param name="educationID"></param>
  167. /// <param name="learningformID"></param>
  168. /// <param name="learnSystem"></param>
  169. /// <param name="pageIndex"></param>
  170. /// <param name="pageSize"></param>
  171. /// <returns></returns>
  172. public IGridResultSet<NewStudentView> GetUnAssignNewStudentViewGrid(ConfiguretView configuretView, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int pageIndex, int pageSize)
  173. {
  174. Expression<Func<CF_NewStudent, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  175. exp = exp.And(x => x.AssignStatus == (int)CF_AssignStatus.NotAssigned);
  176. if (gradeID.HasValue)
  177. {
  178. exp = exp.And(x => x.GradeID == gradeID);
  179. }
  180. var query = NewStudentDAL.GetNewStudentViewQueryable(exp);
  181. if (standardID.HasValue)
  182. {
  183. query = query.Where(x => x.StandardID == standardID);
  184. }
  185. if (educationID.HasValue)
  186. {
  187. query = query.Where(x => x.EducationID == educationID);
  188. }
  189. if (learningformID.HasValue)
  190. {
  191. query = query.Where(x => x.LearningformID == learningformID);
  192. }
  193. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  194. {
  195. var LearnSystems = Convert.ToDecimal(learnSystem);
  196. query = query.Where(x => x.LearnSystem == LearnSystems);
  197. }
  198. //查询条件
  199. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  200. {
  201. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  202. }
  203. return query.OrderByDescending(x => x.GradeID).ThenBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID)
  204. .ThenBy(x => x.LearnSystem).ToGridResultSet<NewStudentView>(pageIndex, pageSize);
  205. }
  206. /// <summary>
  207. /// 查询未分配新生名单信息List
  208. /// </summary>
  209. /// <param name="configuretView"></param>
  210. /// <param name="gradeID"></param>
  211. /// <param name="standardID"></param>
  212. /// <param name="educationID"></param>
  213. /// <param name="learningformID"></param>
  214. /// <param name="learnSystem"></param>
  215. /// <returns></returns>
  216. public IList<NewStudentView> GetUnAssignNewStudentViewList(ConfiguretView configuretView, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem)
  217. {
  218. Expression<Func<CF_NewStudent, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  219. exp = exp.And(x => x.AssignStatus == (int)CF_AssignStatus.NotAssigned);
  220. if (gradeID.HasValue)
  221. {
  222. exp = exp.And(x => x.GradeID == gradeID);
  223. }
  224. var query = NewStudentDAL.GetNewStudentViewQueryable(exp);
  225. if (standardID.HasValue)
  226. {
  227. query = query.Where(x => x.StandardID == standardID);
  228. }
  229. if (educationID.HasValue)
  230. {
  231. query = query.Where(x => x.EducationID == educationID);
  232. }
  233. if (learningformID.HasValue)
  234. {
  235. query = query.Where(x => x.LearningformID == learningformID);
  236. }
  237. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  238. {
  239. var LearnSystems = Convert.ToDecimal(learnSystem);
  240. query = query.Where(x => x.LearnSystem == LearnSystems);
  241. }
  242. //查询条件
  243. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  244. {
  245. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  246. }
  247. return query.OrderByDescending(x => x.GradeID).ThenBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID)
  248. .ThenBy(x => x.LearnSystem).ToList();
  249. }
  250. /// <summary>
  251. /// 查询对应的新生分配信息NewStudentView
  252. /// </summary>
  253. /// <param name="newStudentID"></param>
  254. /// <returns></returns>
  255. public NewStudentView GetNewStudentCollegeView(Guid? newStudentID)
  256. {
  257. try
  258. {
  259. Expression<Func<CF_NewStudent, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  260. exp = exp.And(x => x.AssignStatus == (int)CF_AssignStatus.PreAssigned);
  261. exp = exp.And(x => x.NewStudentID == newStudentID);
  262. var query = NewStudentDAL.GetNewStudentCollegeViewQueryable(exp).SingleOrDefault();
  263. return query;
  264. }
  265. catch (Exception ex)
  266. {
  267. throw new Exception(ex.Message);
  268. }
  269. }
  270. /// <summary>
  271. /// 导入分配
  272. /// </summary>
  273. /// <param name="cellheader"></param>
  274. /// <param name="inCount"></param>
  275. /// <param name="upCount"></param>
  276. /// <param name="errdataList"></param>
  277. /// <param name="errCount"></param>
  278. /// <param name="sourcePhysicalPath"></param>
  279. public void NewStudentAssignCollegeImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount, out List<NewStudentView> errdataList, out int? errCount, string sourcePhysicalPath)
  280. {
  281. try
  282. {
  283. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  284. List<NewStudentView> errList = new List<NewStudentView>();
  285. // 1.1解析文件,存放到一个List集合里
  286. cellheader.Remove("ErrorMessage");//移除“未导入原因”列(ErrorMessage)
  287. List<NewStudentView> enlist = NpoiExcelHelper.ExcelToEntityList<NewStudentView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
  288. cellheader.Add("ErrorMessage", "未导入原因");
  289. //对List集合进行有效性校验
  290. if (enlist.Count() <= 0)
  291. {
  292. throw new Exception("Excel文件数据为空,请检查。");
  293. }
  294. Regex reg = null; //正则表达式
  295. inCount = 0; //导入个数
  296. upCount = 0; //更新个数
  297. errCount = 0; //失败个数
  298. string errorMsgStr = ""; //错误信息
  299. List<CF_NewStudent> newStudentInList = new List<CF_NewStudent>();
  300. List<CF_NewStudent> newStudentUpList = new List<CF_NewStudent>();
  301. //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
  302. //年级
  303. var gradeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Grade).ToList();
  304. //院系所代码
  305. var collegeNoList = enlist.Where(x => !string.IsNullOrEmpty(x.CollegeNo)).Select(x => x.CollegeNo).ToList();
  306. //院系所
  307. var collegeList = NewStudentDAL.CollegeRepository.GetList(x => true, x => x.CF_CollegeProfile).ToList();
  308. //姓名
  309. var nameList = enlist.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).ToList();
  310. //身份证号
  311. var iDNumberList = enlist.Where(x => !string.IsNullOrEmpty(x.IDNumber)).Select(x => x.IDNumber).ToList();
  312. //年级
  313. var gradeIDList = enlist.Where(x => !string.IsNullOrEmpty(x.GradeStr)).Select(x => x.GradeStr).ToList();
  314. //新生名单(由于需要和Excel中数据进行比对,数据太多就会报异常,所以需要先查询出来)
  315. var newStudentAllList = NewStudentDAL.NewStudentRepository.GetList(x => true).ToList();
  316. //对比后的newStudentList
  317. var newStudentList = newStudentAllList.Where(x => nameList.Contains(x.Name) && iDNumberList.Contains(x.IDNumber) && gradeIDList.Contains(x.GradeID.ToString())).ToList();
  318. //招生专业(用于检测是否开设相对应的专业:专业信息、年级、院系所)
  319. var recruitSpecialtyList = NewStudentDAL.RecruitSpecialtyRepository.GetList(x => gradeIDList.Contains(x.GradeID.ToString())).ToList();
  320. //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
  321. for (int i = 0; i < enlist.Count; i++)
  322. {
  323. NewStudentView en = enlist[i]; //Excel表数据视图
  324. CF_NewStudent newStudent = new CF_NewStudent(); //新生信息实体
  325. //序号
  326. if (string.IsNullOrEmpty(en.OrderNoStr))
  327. {
  328. errCount++;
  329. errorMsgStr = "序号不能为空";
  330. en.ErrorMessage = errorMsgStr;
  331. errList.Add(en);
  332. errorMsg.AppendLine(errorMsgStr);
  333. continue;
  334. }
  335. else
  336. {
  337. reg = new Regex(@"^[1-9]\d*|0$"); //序号字段正则表达式()
  338. if (!reg.IsMatch(en.OrderNoStr))
  339. {
  340. errCount++;
  341. errorMsgStr = "序号格式不正确,请检查(自然数)";
  342. en.ErrorMessage = errorMsgStr;
  343. errList.Add(en);
  344. errorMsg.AppendLine(errorMsgStr);
  345. continue;
  346. }
  347. else
  348. {
  349. //序号
  350. newStudent.OrderNo = Convert.ToInt32(en.OrderNoStr);
  351. }
  352. }
  353. //身份证号
  354. if (string.IsNullOrEmpty(en.IDNumber))
  355. {
  356. errCount++;
  357. errorMsgStr = "身份证号不能为空";
  358. en.ErrorMessage = errorMsgStr;
  359. errList.Add(en);
  360. errorMsg.AppendLine(errorMsgStr);
  361. continue;
  362. }
  363. else
  364. {
  365. //reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //身份证号正则表达式
  366. //if (!reg.IsMatch(en.IDNumber))
  367. //{
  368. // errCount++;
  369. // errorMsgStr = "身份证号格式不正确,请检查";
  370. // en.ErrorMessage = errorMsgStr;
  371. // errList.Add(en);
  372. // errorMsg.AppendLine(errorMsgStr);
  373. // continue;
  374. //}
  375. //else
  376. //{
  377. // //身份证号
  378. // newStudent.IDNumber = en.IDNumber.Trim();
  379. //}
  380. newStudent.IDNumber = en.IDNumber.Trim();
  381. }
  382. //姓名
  383. if (string.IsNullOrEmpty(en.Name))
  384. {
  385. errCount++;
  386. errorMsgStr = "姓名不能为空";
  387. en.ErrorMessage = errorMsgStr;
  388. errList.Add(en);
  389. errorMsg.AppendLine(errorMsgStr);
  390. continue;
  391. }
  392. else
  393. {
  394. //姓名
  395. newStudent.Name = en.Name.Trim();
  396. }
  397. //年级
  398. if (string.IsNullOrEmpty(en.GradeStr))
  399. {
  400. errCount++;
  401. errorMsgStr = "年级不能为空";
  402. en.ErrorMessage = errorMsgStr;
  403. errList.Add(en);
  404. errorMsg.AppendLine(errorMsgStr);
  405. continue;
  406. }
  407. else
  408. {
  409. var grade = gradeList.Where(x => x.Name == en.GradeStr.Trim()).SingleOrDefault();
  410. if (grade == null)
  411. {
  412. errCount++;
  413. errorMsgStr = "年级不存在,请检查";
  414. en.ErrorMessage = errorMsgStr;
  415. errList.Add(en);
  416. errorMsg.AppendLine(errorMsgStr);
  417. continue;
  418. }
  419. else
  420. {
  421. //年级ID
  422. newStudent.GradeID = grade.Value;
  423. }
  424. }
  425. //院系所代码
  426. if (string.IsNullOrEmpty(en.CollegeNo))
  427. {
  428. errCount++;
  429. errorMsgStr = RSL.Get("CollegeCode") + "不能为空";
  430. en.ErrorMessage = errorMsgStr;
  431. errList.Add(en);
  432. errorMsg.AppendLine(errorMsgStr);
  433. continue;
  434. }
  435. else
  436. {
  437. var college = collegeList.Where(x => x.No == en.CollegeNo.Trim()).SingleOrDefault();
  438. if (college == null)
  439. {
  440. errCount++;
  441. errorMsgStr = RSL.Get("CollegeCode") + "不存在,请检查";
  442. en.ErrorMessage = errorMsgStr;
  443. errList.Add(en);
  444. errorMsg.AppendLine(errorMsgStr);
  445. continue;
  446. }
  447. else
  448. {
  449. if (college.CF_CollegeProfile == null)
  450. {
  451. errCount++;
  452. errorMsgStr = RSL.Get("CollegeCode") + "所属的单位类别有误,请检查";
  453. en.ErrorMessage = errorMsgStr;
  454. errList.Add(en);
  455. errorMsg.AppendLine(errorMsgStr);
  456. continue;
  457. }
  458. else if (college.CF_CollegeProfile.UnitCategoryID != (int)CF_UnitCategory.College)
  459. {
  460. errCount++;
  461. errorMsgStr = RSL.Get("CollegeCode") + "所属的单位类别有误,请检查";
  462. en.ErrorMessage = errorMsgStr;
  463. errList.Add(en);
  464. errorMsg.AppendLine(errorMsgStr);
  465. continue;
  466. }
  467. //院系所ID
  468. newStudent.CollegeID = college.CollegeID;
  469. }
  470. }
  471. ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉)
  472. //for (int j = i + 1; j < enlist.Count; j++)
  473. //{
  474. // NewStudentView enA = enlist[j];
  475. // //根据Excel表中的业务主键进行去重(身份证号、姓名、年级唯一)
  476. // if (en.IDNumber == enA.IDNumber && en.Name == enA.Name && en.YearID == enA.YearID)
  477. // {
  478. // //用于标识Excel表中的重复记录(由于是批量进行插入数据表)
  479. // }
  480. //}
  481. //由于新生管理模块中存在新生分配的业务,在进行新生信息新增时,
  482. //需要对新生分配、录取名单中的信息进行提示性验证(业务主键:身份证号、姓名、年级唯一)
  483. //处理方法:进行Excel导入时,对新生分配、录取名单中的信息提示性验证(当错误信息抛出)
  484. //注:(未分配-1,预分配-2,已分配-3)
  485. //数据表重复性验证,此为名单归站功能(身份证号、姓名、年级唯一)
  486. CF_NewStudent newStudentEnetey = newStudentList.Where(x => x.IDNumber == newStudent.IDNumber
  487. && x.Name == newStudent.Name && x.GradeID == newStudent.GradeID).FirstOrDefault();
  488. if (newStudentEnetey == null)
  489. {
  490. errCount++;
  491. errorMsgStr = "此归站名单不存在,请检查";
  492. en.ErrorMessage = errorMsgStr;
  493. errList.Add(en);
  494. errorMsg.AppendLine(errorMsgStr);
  495. continue;
  496. }
  497. else
  498. {
  499. var recruitSpecialty = recruitSpecialtyList.Where(x => x.GradeID == newStudent.GradeID
  500. && x.SpecialtyID == newStudentEnetey.SpecialtyID && x.CollegeID == newStudent.CollegeID).FirstOrDefault();
  501. //名单归站时,需对招生专业进行验证
  502. if (recruitSpecialty == null)
  503. {
  504. errCount++;
  505. errorMsgStr = "归站失败,此归站名单未开设相关的招生专业,请检查";
  506. en.ErrorMessage = errorMsgStr;
  507. errList.Add(en);
  508. errorMsg.AppendLine(errorMsgStr);
  509. continue;
  510. }
  511. else
  512. {
  513. //由于新生管理模块中存在新生分配的业务,只更新分配状态为:未分配-1、预分配-2
  514. //分配状态为:未分配-1,预分配-2,已分配-3
  515. if (newStudentEnetey.AssignStatus == (int)CF_AssignStatus.Assigned)
  516. {
  517. errCount++;
  518. errorMsgStr = "归站失败,录取名单信息中已存在此归站名单";
  519. en.ErrorMessage = errorMsgStr;
  520. errList.Add(en);
  521. errorMsg.AppendLine(errorMsgStr);
  522. continue;
  523. }
  524. else
  525. {
  526. //(Excel有重复时,以最后一条记录的更新为准)
  527. if (newStudentEnetey.CollegeID.HasValue)
  528. {
  529. //更新
  530. newStudentEnetey.OrderNo = newStudent.OrderNo;
  531. newStudentEnetey.CollegeID = newStudent.CollegeID;
  532. newStudentEnetey.AssignStatus = (int)CF_AssignStatus.PreAssigned; //预分配
  533. SetModifyStatus(newStudentEnetey);
  534. newStudentUpList.Add(newStudentEnetey);
  535. upCount++;
  536. }
  537. else
  538. {
  539. //归站
  540. newStudentEnetey.OrderNo = newStudent.OrderNo;
  541. newStudentEnetey.CollegeID = newStudent.CollegeID;
  542. newStudentEnetey.AssignStatus = (int)CF_AssignStatus.PreAssigned; //预分配
  543. SetModifyStatus(newStudentEnetey);
  544. newStudentUpList.Add(newStudentEnetey);
  545. inCount++;
  546. }
  547. }
  548. }
  549. }
  550. }
  551. //批量统一提交更新
  552. if (newStudentUpList != null && newStudentUpList.Count() > 0)
  553. {
  554. UnitOfWork.BatchUpdate(newStudentUpList); //批量更新
  555. }
  556. errdataList = errList.Distinct().ToList(); //错误列表List
  557. }
  558. catch (Exception)
  559. {
  560. throw;
  561. }
  562. }
  563. /// <summary>
  564. /// 名单分配确定
  565. /// 注:需对招生专业进行验证
  566. /// </summary>
  567. /// <param name="collegeID"></param>
  568. /// <param name="newStudentIDList"></param>
  569. /// <returns></returns>
  570. public string NewStudentAssignCollegeConfirm(Guid? collegeID, List<Guid?> newStudentIDList)
  571. {
  572. try
  573. {
  574. //查询新生信息
  575. var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => newStudentIDList.Contains(x.NewStudentID) && x.AssignStatus == (int)CF_AssignStatus.NotAssigned).ToList();
  576. //查询招生专业信息
  577. var recruitSpecialtyList = NewStudentDAL.RecruitSpecialtyRepository.GetList(x => x.CollegeID == collegeID).ToList();
  578. int success = 0; //成功
  579. int fail = 0; //失败
  580. string tipMessage = null; //提示消息
  581. List<CF_NewStudent> newStudentUpList = new List<CF_NewStudent>();
  582. foreach (var newStudentID in newStudentIDList)
  583. {
  584. var newStudent = newStudentList.Where(x => x.NewStudentID == newStudentID).SingleOrDefault();
  585. if (newStudent == null)
  586. {
  587. throw new Exception("数据有误,请检查。");
  588. }
  589. else
  590. {
  591. var recruitSpecialty = recruitSpecialtyList.Where(x => x.SpecialtyID == newStudent.SpecialtyID
  592. && x.GradeID == newStudent.GradeID && x.CollegeID == collegeID).SingleOrDefault();
  593. if (recruitSpecialty == null)
  594. {
  595. fail++;
  596. }
  597. else
  598. {
  599. newStudent.CollegeID = collegeID;
  600. newStudent.AssignStatus = (int)CF_AssignStatus.PreAssigned;
  601. SetModifyStatus(newStudent);
  602. newStudentUpList.Add(newStudent);
  603. success++;
  604. }
  605. }
  606. }
  607. //批量统一提交更新
  608. if (newStudentUpList != null && newStudentUpList.Count() > 0)
  609. {
  610. UnitOfWork.BatchUpdate(newStudentUpList);
  611. }
  612. if (success > 0 && fail <= 0)
  613. {
  614. tipMessage = success + "条";
  615. }
  616. else
  617. {
  618. tipMessage = success + "条," + fail + "条失败,原因:选择分配的" + RSL.Get("College") + ",未开设相应的招生专业,请检查";
  619. }
  620. return tipMessage;
  621. }
  622. catch (Exception ex)
  623. {
  624. throw new Exception(ex.Message);
  625. }
  626. }
  627. /// <summary>
  628. /// 删除照片(批量删除)
  629. /// </summary>
  630. /// <param name="newStudentIDs"></param>
  631. /// <returns></returns>
  632. public bool PicDelete(List<Guid?> newStudentIDs)
  633. {
  634. try
  635. {
  636. List<string> photoUrlList = new List<string>();
  637. List<CF_NewStudent> newStudentUpList = new List<CF_NewStudent>();
  638. var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => newStudentIDs.Contains(x.NewStudentID) && x.AssignStatus == (int)CF_AssignStatus.PreAssigned).ToList();
  639. foreach (var newStudent in newStudentList)
  640. {
  641. if (newStudent != null)
  642. {
  643. if (!string.IsNullOrEmpty(newStudent.RecruitPictureUrl))
  644. {
  645. photoUrlList.Add(newStudent.RecruitPictureUrl);
  646. newStudent.RecruitPictureUrl = null;
  647. newStudentUpList.Add(newStudent);
  648. }
  649. }
  650. }
  651. using (TransactionScope ts = new TransactionScope())
  652. {
  653. foreach (var photoUrl in photoUrlList)
  654. {
  655. FileUploadHelper.DeleteFile(photoUrl);
  656. }
  657. if (newStudentUpList != null && newStudentUpList.Count() > 0)
  658. {
  659. UnitOfWork.BatchUpdate(newStudentUpList);
  660. }
  661. ts.Complete();
  662. }
  663. return true;
  664. }
  665. catch (Exception)
  666. {
  667. throw;
  668. }
  669. }
  670. /// <summary>
  671. /// 取消分配
  672. /// </summary>
  673. /// <param name="NewStudentIDList"></param>
  674. /// <returns></returns>
  675. public string NewStudentCollegeCancleAssign(List<Guid?> NewStudentIDList)
  676. {
  677. try
  678. {
  679. var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => NewStudentIDList.Contains(x.NewStudentID) && x.AssignStatus == (int)CF_AssignStatus.PreAssigned).ToList();
  680. int success = 0; //成功
  681. string tipMessage = null; //提示消息
  682. List<CF_NewStudent> newStudentUpList = new List<CF_NewStudent>();
  683. foreach (var newStudent in newStudentList)
  684. {
  685. //newStudent.RecruitPictureUrl = null;
  686. newStudent.CollegeID = null;
  687. newStudent.AssignStatus = (int)CF_AssignStatus.NotAssigned;
  688. SetModifyStatus(newStudent);
  689. newStudentUpList.Add(newStudent);
  690. success++;
  691. }
  692. //批量统一提交更新
  693. if (newStudentUpList != null && newStudentUpList.Count() > 0)
  694. {
  695. UnitOfWork.BatchUpdate(newStudentUpList);
  696. }
  697. tipMessage = success + "条";
  698. return tipMessage;
  699. }
  700. catch (Exception ex)
  701. {
  702. throw new Exception(ex.Message);
  703. }
  704. }
  705. /// <summary>
  706. /// 提交(需对招生专业进行验证,再提交,同时生成录取通知书编号(默认:年级+院系所代码+5位流水号))
  707. /// 注:个性化生成录取通知书编号(暂不考虑)
  708. /// </summary>
  709. /// <param name="NewStudentIDList"></param>
  710. /// <returns></returns>
  711. public string NewStudentCollegeSubmitAssign(List<Guid?> NewStudentIDList)
  712. {
  713. try
  714. {
  715. //查询新生信息(注意排序)
  716. var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => NewStudentIDList.Contains(x.NewStudentID)
  717. && x.AssignStatus == (int)CF_AssignStatus.PreAssigned).OrderByDescending(x => x.GradeID).ThenBy(x => x.CollegeID)
  718. .ThenBy(x => x.ExamineeNum.Length).ThenBy(x => x.ExamineeNum);
  719. //查询对应的院系所IDList
  720. var collegeIDList = newStudentList.Where(x => !string.IsNullOrEmpty(x.CollegeID.ToString())).Select(x => x.CollegeID).Distinct().ToList();
  721. //查询院系所信息
  722. var collegeList = NewStudentDAL.CollegeRepository.GetList(x => true).ToList();
  723. //查询招生专业信息
  724. var recruitSpecialtyList = NewStudentDAL.RecruitSpecialtyRepository.GetList(x => collegeIDList.Contains(x.CollegeID)).ToList();
  725. //查询各院系所最大的录取通知编号(只查询已分配状态的信息--录取名单)
  726. var maxCollegeEnrollmentList = NewStudentDAL.GetEnrollmentNo(x => collegeIDList.Contains(x.CollegeID) && x.AssignStatus == (int)CF_AssignStatus.Assigned).ToList();
  727. long startEnrollmentNo = 0; //初始录取通知书编号
  728. long newEnrollmentNo = 0; //新生成的录取通知书编号
  729. int total = 0; //年级+院系所长度
  730. int success = 0; //成功
  731. int fail = 0; //失败
  732. string tipMessage = null; //提示消息
  733. //新生信息提交List
  734. var newStudentUpList = new List<CF_NewStudent>();
  735. foreach (var newStudent in newStudentList)
  736. {
  737. var recruitSpecialty = recruitSpecialtyList.Where(x => x.SpecialtyID == newStudent.SpecialtyID && x.GradeID == newStudent.GradeID && x.CollegeID == newStudent.CollegeID).SingleOrDefault();
  738. if (recruitSpecialty == null)
  739. {
  740. fail++;
  741. }
  742. else
  743. {
  744. //查询对应院系的最大的录取通知编号(根据年级、院系所查询)
  745. var maxCollegeEnrollment = maxCollegeEnrollmentList.Where(x => x.GradeID == newStudent.GradeID && x.CollegeID == newStudent.CollegeID).SingleOrDefault();
  746. //查询新生信息提交List中是否有重复的信息(业务主键:年级、院系所)
  747. var newStudentRepeatList = newStudentUpList.Where(x => x.GradeID == newStudent.GradeID && x.CollegeID == newStudent.CollegeID).ToList();
  748. //表示当前院系所无对应的录取通知书编号,此时应为初始编号(年级+院系所代码+5位流水号)
  749. if (maxCollegeEnrollment == null)
  750. {
  751. //查询院系所代码
  752. var college = collegeList.Where(x => x.CollegeID == newStudent.CollegeID).SingleOrDefault();
  753. //生成初始录取通知书编号
  754. total = (newStudent.GradeID.ToString() + college.No).Length;
  755. startEnrollmentNo = Convert.ToInt64((newStudent.GradeID.ToString() + college.No).PadRight(total + 4, '0') + "1");
  756. //表示提交的信息中无重复信息(业务主键:年级、院系所)
  757. if (newStudentRepeatList.Count() <= 0)
  758. {
  759. //初始录取通知书编号
  760. newEnrollmentNo = startEnrollmentNo;
  761. }
  762. else
  763. {
  764. //提交信息中重复数据的最大录取通知书编号+1,作为下一个录取通知书编号
  765. newEnrollmentNo = Convert.ToInt64(newStudentRepeatList.OrderByDescending(x => Convert.ToInt64(x.EnrollmentNo)).FirstOrDefault().EnrollmentNo) + 1;
  766. }
  767. }
  768. else
  769. {
  770. //表示提交的信息中无重复信息(业务主键:年级、院系所)
  771. if (newStudentRepeatList.Count() <= 0)
  772. {
  773. //数据表中的最大录取通知书编号+1,作为下一个录取通知书编号
  774. newEnrollmentNo = Convert.ToInt64(maxCollegeEnrollment.EnrollmentNo) + 1;
  775. }
  776. else
  777. {
  778. //提交信息中重复数据的最大录取通知书编号+1,作为下一个录取通知书编号
  779. newEnrollmentNo = Convert.ToInt64(newStudentRepeatList.OrderByDescending(x => Convert.ToInt64(x.EnrollmentNo)).FirstOrDefault().EnrollmentNo) + 1;
  780. }
  781. }
  782. //录取通知书编号
  783. newStudent.EnrollmentNo = newEnrollmentNo.ToString();
  784. newStudent.AssignStatus = (int)CF_AssignStatus.Assigned; //已分配
  785. SetModifyStatus(newStudent);
  786. newStudentUpList.Add(newStudent);
  787. success++;
  788. }
  789. }
  790. //批量统一提交更新
  791. if (newStudentUpList != null && newStudentUpList.Count() > 0)
  792. {
  793. UnitOfWork.BatchUpdate(newStudentUpList);
  794. }
  795. if (success > 0 && fail <= 0)
  796. {
  797. tipMessage = success + "条";
  798. }
  799. else
  800. {
  801. tipMessage = success + "条," + fail + "条失败,原因:提交的信息中存在," + RSL.Get("College") + "未开设相应的招生专业信息,请检查";
  802. }
  803. return tipMessage;
  804. }
  805. catch (Exception ex)
  806. {
  807. throw new Exception(ex.Message);
  808. }
  809. }
  810. /// <summary>
  811. /// 导入照片
  812. /// </summary>
  813. /// <param name="photoPaths"></param>
  814. /// <param name="importPicType"></param>
  815. /// <param name="inCount"></param>
  816. /// <param name="errCount"></param>
  817. /// <param name="errDataTable"></param>
  818. public void NewStudentCollegePicImport(IList<string> photoPaths, string importPicType, out int? inCount, out int? errCount, out DataTable errDataTable)
  819. {
  820. try
  821. {
  822. var mapList = photoPaths.Select(s => new
  823. {
  824. PhotoInfo = Path.GetFileName(s).Trim(),
  825. PhotoName = Path.GetFileNameWithoutExtension(s).Trim(),
  826. PhotoPath = s,
  827. }).ToArray();
  828. var photoNameList = mapList.Select(s => s.PhotoName).Distinct().ToList();
  829. inCount = 0;
  830. errCount = 0;
  831. errDataTable = new DataTable();
  832. List<CF_NewStudent> newStudentUpList = new List<CF_NewStudent>();
  833. if (importPicType.Equals("ExamineeNum"))
  834. {
  835. var newPhotoNameList = new List<string>();
  836. foreach (var photoName in photoNameList)
  837. {
  838. var photoNameStart = photoName.Substring(0, 1);
  839. if (photoNameStart.Equals("F") || photoNameStart.Equals("Z"))
  840. {
  841. newPhotoNameList.Add(photoName.Substring(1));
  842. }
  843. }
  844. errDataTable.Columns.Add("PhotoInfo", typeof(string));
  845. errDataTable.Columns.Add("ExamineeNum", typeof(string));
  846. errDataTable.Columns.Add("ErrorMessage", typeof(string));
  847. var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => x.AssignStatus == (int)CF_AssignStatus.PreAssigned && (photoNameList.Contains(x.ExamineeNum) || newPhotoNameList.Contains(x.ExamineeNum))).ToList();
  848. foreach (var map in mapList)
  849. {
  850. var photoNameStart = map.PhotoName.Substring(0, 1);
  851. if (photoNameStart.Equals("F") || photoNameStart.Equals("Z"))
  852. {
  853. var newStudent = newStudentList.Where(x => x.ExamineeNum == map.PhotoName || x.ExamineeNum == map.PhotoName.Substring(1)).SingleOrDefault();
  854. if (newStudent == null)
  855. {
  856. DataRow errDataRow = errDataTable.NewRow();
  857. errDataRow["PhotoInfo"] = map.PhotoInfo;
  858. errDataRow["ExamineeNum"] = map.PhotoName;
  859. errDataRow["ErrorMessage"] = "不存在对应的考生号(" + map.PhotoName + ")";
  860. errDataTable.Rows.Add(errDataRow);
  861. errCount++;
  862. }
  863. else
  864. {
  865. newStudent.RecruitPictureUrl = map.PhotoPath;
  866. this.SetModifyStatus(newStudent);
  867. newStudentUpList.Add(newStudent);
  868. inCount++;
  869. }
  870. }
  871. else
  872. {
  873. var newStudent = newStudentList.Where(x => x.ExamineeNum == map.PhotoName).SingleOrDefault();
  874. if (newStudent == null)
  875. {
  876. DataRow errDataRow = errDataTable.NewRow();
  877. errDataRow["PhotoInfo"] = map.PhotoInfo;
  878. errDataRow["ExamineeNum"] = map.PhotoName;
  879. errDataRow["ErrorMessage"] = "不存在对应的考生号(" + map.PhotoName + ")";
  880. errDataTable.Rows.Add(errDataRow);
  881. errCount++;
  882. }
  883. else
  884. {
  885. newStudent.RecruitPictureUrl = map.PhotoPath;
  886. this.SetModifyStatus(newStudent);
  887. newStudentUpList.Add(newStudent);
  888. inCount++;
  889. }
  890. }
  891. }
  892. }
  893. else if (importPicType.Equals("IDNumber"))
  894. {
  895. errDataTable.Columns.Add("PhotoInfo", typeof(string));
  896. errDataTable.Columns.Add("IDNumber", typeof(string));
  897. errDataTable.Columns.Add("ErrorMessage", typeof(string));
  898. var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => x.AssignStatus == (int)CF_AssignStatus.PreAssigned && photoNameList.Contains(x.IDNumber)).ToList();
  899. foreach (var map in mapList)
  900. {
  901. var newStudentVerifyList = newStudentList.Where(x => x.IDNumber == map.PhotoName).ToList();
  902. if (newStudentVerifyList != null && newStudentVerifyList.Count() > 1)
  903. {
  904. DataRow errDataRow = errDataTable.NewRow();
  905. errDataRow["PhotoInfo"] = map.PhotoInfo;
  906. errDataRow["IDNumber"] = map.PhotoName;
  907. errDataRow["ErrorMessage"] = "存在多个对应的证件号码(" + map.PhotoName + ")";
  908. errDataTable.Rows.Add(errDataRow);
  909. errCount++;
  910. }
  911. else
  912. {
  913. if (newStudentVerifyList != null && newStudentVerifyList.Count() == 1)
  914. {
  915. var newStudent = newStudentVerifyList.Where(x => x.IDNumber == map.PhotoName).SingleOrDefault();
  916. if (newStudent == null)
  917. {
  918. DataRow errDataRow = errDataTable.NewRow();
  919. errDataRow["PhotoInfo"] = map.PhotoInfo;
  920. errDataRow["IDNumber"] = map.PhotoName;
  921. errDataRow["ErrorMessage"] = "不存在对应的证件号码(" + map.PhotoName + ")";
  922. errDataTable.Rows.Add(errDataRow);
  923. errCount++;
  924. }
  925. else
  926. {
  927. newStudent.RecruitPictureUrl = map.PhotoPath;
  928. this.SetModifyStatus(newStudent);
  929. newStudentUpList.Add(newStudent);
  930. inCount++;
  931. }
  932. }
  933. else
  934. {
  935. DataRow errDataRow = errDataTable.NewRow();
  936. errDataRow["PhotoInfo"] = map.PhotoInfo;
  937. errDataRow["IDNumber"] = map.PhotoName;
  938. errDataRow["ErrorMessage"] = "不存在对应的证件号码(" + map.PhotoName + ")";
  939. errDataTable.Rows.Add(errDataRow);
  940. errCount++;
  941. }
  942. }
  943. }
  944. }
  945. if (newStudentUpList != null && newStudentUpList.Count() > 0)
  946. {
  947. UnitOfWork.BatchUpdate<CF_NewStudent>(newStudentUpList);
  948. }
  949. }
  950. catch (Exception)
  951. {
  952. throw;
  953. }
  954. }
  955. /// <summary>
  956. /// 招生信息Excel导入(预分配,需根据省招专业相关信息进行匹配--个性化)
  957. /// </summary>
  958. /// <param name="cellheader"></param>
  959. /// <param name="inCount"></param>
  960. /// <param name="upCount"></param>
  961. /// <param name="errdataList"></param>
  962. /// <param name="errCount"></param>
  963. /// <param name="sourcePhysicalPath"></param>
  964. public virtual void NewStudentCollegeImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount, out List<NewStudentView> errdataList, out int? errCount, string sourcePhysicalPath)
  965. {
  966. //根据各高校个性化要求进行配置
  967. throw new Exception("招生信息导入配置有误(根据个性化要求进行配置),请检查");
  968. }
  969. }
  970. }