NewStudentEnterServices.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.Entities;
  6. using EMIS.ViewModel;
  7. using EMIS.CommonLogic.SystemServices;
  8. namespace EMIS.ExtensionLogic.ServiceLogic.EnrollManage
  9. {
  10. public class NewStudentEnterServices : EMIS.CommonLogic.EnrollManage.NewStudentManage.NewStudentEnterServices
  11. {
  12. /// <summary>
  13. /// 流水号生成Services
  14. /// </summary>
  15. public Lazy<ISerialNumberServices> SerialNumberServices { get; set; }
  16. /// <summary>
  17. /// 手动分配班级和生成学号(广东松山)
  18. /// 注:暂不支持院系专业分方向、年级专业分方向分班、分学号
  19. /// </summary>
  20. /// <param name="newStudentIDList"></param>
  21. /// <param name="classmajorID"></param>
  22. /// <returns></returns>
  23. public override string NewStudentEnterAssignClass(List<Guid?> newStudentIDList, Guid? classmajorID)
  24. {
  25. //分配规则如下(根据新生实际报到人数进行分班,每个专业设置多少个小班,以教务处数据为主):
  26. //1、男女比例均衡;
  27. //2、各地区人数比例均衡;
  28. //3、高考成绩各分数段比例均衡;
  29. //4、同一宿舍的序号能连续编排在一起;
  30. //5、女生少的班级建议女生排在前面,男生少的班级建议男生排在前面,男女生比例相差不悬殊的建议混排;
  31. //6、每个小班人数必须控制在60人以内,最好55人以下;
  32. //学号(11位)=班级编号+2位流水号(按学生录取通知书编号、宿舍编号排序后顺序取学号)
  33. try
  34. {
  35. var studentNoTotal = EMIS.Utility.Const.LOCAL_SETTING_LOGINIDTOTAL;
  36. if (studentNoTotal == null)
  37. {
  38. throw new Exception("学号总位数未配置,请检查。");
  39. }
  40. //查询录取名单信息(已分配状态)
  41. var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => newStudentIDList.Contains(x.NewStudentID) && x.AssignStatus == (int)CF_AssignStatus.Assigned)
  42. .OrderBy(x => x.EnrollmentNo).ThenBy(x => x.Dormitory).OrderBy(x => x.OrderNo).ToList();
  43. //年级ID
  44. var gradeIDList = newStudentList.Where(x => !string.IsNullOrEmpty(x.GradeID.ToString())).Select(x => x.GradeID).ToList();
  45. //专业信息ID
  46. var specialtyIDList = newStudentList.Where(x => !string.IsNullOrEmpty(x.SpecialtyID.ToString())).Select(x => x.SpecialtyID).ToList();
  47. //院系所ID
  48. var collegeIDList = newStudentList.Where(x => !string.IsNullOrEmpty(x.CollegeID.ToString())).Select(x => x.CollegeID).ToList();
  49. //查询专业信息
  50. var specialtyList = NewStudentDAL.SpecialtyRepository.GetList(x => specialtyIDList.Contains(x.SpecialtyID)).ToList();
  51. //查询招生专业信息(暂时不需对招生专业进行验证)
  52. var recruitSpecialtyAllList = NewStudentDAL.RecruitSpecialtyRepository.GetList(x => true).ToList();
  53. //查询招生专业
  54. var recruitSpecialtyList = recruitSpecialtyAllList.Where(x => gradeIDList.Contains(x.GradeID) && specialtyIDList.Contains(x.SpecialtyID) && collegeIDList.Contains(x.CollegeID)).ToList();
  55. //查询对应的院系专业信息
  56. var facultymajorList = NewStudentDAL.GetFacultymajorByNewStudent(x => newStudentIDList.Contains(x.NewStudentID)).ToList();
  57. //院系专业ID
  58. var facultymajorIDList = facultymajorList.Where(x => !string.IsNullOrEmpty(x.FacultymajorID.ToString())).Select(x => x.FacultymajorID).ToList();
  59. //查询对应的年级专业信息
  60. var grademajorList = NewStudentDAL.GetGrademajorByNewStudent(x => newStudentIDList.Contains(x.NewStudentID), x => facultymajorIDList.Contains(x.FacultymajorID)).ToList();
  61. //年级专业ID
  62. var grademajorIDList = grademajorList.Where(x => !string.IsNullOrEmpty(x.GrademajorID.ToString())).Select(x => x.GrademajorID).ToList();
  63. //查询对应的班级信息
  64. var classmajorList = NewStudentDAL.GetClassmajorByNewStudent(x => newStudentIDList.Contains(x.NewStudentID), x => facultymajorIDList.Contains(x.FacultymajorID), x => grademajorIDList.Contains(x.GrademajorID)).ToList();
  65. //班级信息ID
  66. var classmajorIDList = classmajorList.Where(x => !string.IsNullOrEmpty(x.ClassmajorID.ToString())).Select(x => x.ClassmajorID).ToList();
  67. //查询各班级信息中最大的学号(新生信息表、学生信息表)
  68. var maxStudentNoList = NewStudentDAL.GetMaxStudentNoClass(x => classmajorIDList.Contains(x.ClassmajorID)).ToList();
  69. int classmajorfail = 0;
  70. int fail = 0;
  71. int success = 0;
  72. string tipMessage = null;
  73. long startStudentNo = 0;
  74. long newStudentNo = 0;
  75. List<CF_NewStudent> newStudentUpList = new List<CF_NewStudent>();
  76. foreach (var newStudent in newStudentList)
  77. {
  78. //需要对选择的班级信息分别进行验证(一一对应的情况下,才可分配班级及生成学号)
  79. //查询班级信息(根据新生ID、选择的班级信息ID查询)
  80. var classmajorVerify = classmajorList.Where(x => x.NewStudentID == newStudent.NewStudentID && x.ClassmajorID == classmajorID).SingleOrDefault();
  81. //判断对应的班级信息
  82. if (classmajorVerify != null)
  83. {
  84. //判断当选择的信息中存在班级信息或学号等情况(只要两者之中有一个存在,将不考虑生成)
  85. if (newStudent.ClassmajorID.HasValue || !string.IsNullOrEmpty(newStudent.StudentNo))
  86. {
  87. //表示不生成
  88. fail++;
  89. continue;
  90. }
  91. else
  92. {
  93. //查询对应班级信息中最大的学号(新生信息表、学生信息表)
  94. var maxStudentNo = maxStudentNoList.Where(x => x.ClassmajorID == classmajorID).SingleOrDefault();
  95. //查询选择生成的录取名单List中是否有分配到同一班级的信息
  96. var newStudentRepeatList = newStudentUpList.Where(x => x.ClassmajorID == classmajorID).ToList();
  97. //初始学号(班级编号+流水号,不够学号总位数的用0填充,可在此处通过个性化配置来定义学号生成规则)
  98. startStudentNo = Convert.ToInt64(classmajorVerify.ClassmajorNo.PadRight(Convert.ToInt32(studentNoTotal) - 1, '0') + "1");
  99. //表示当前班级无对应的学号,此时应为初始学号(班级编号+2位流水号,需匹配Web.config配置)
  100. if (maxStudentNo == null)
  101. {
  102. //表示无相同班级的信息
  103. if (newStudentRepeatList.Count <= 0)
  104. {
  105. //初始学号
  106. newStudentNo = startStudentNo;
  107. }
  108. else
  109. {
  110. //相同班级的信息中最大学号+1,作为下一个学号
  111. newStudentNo = Convert.ToInt64(newStudentRepeatList.OrderByDescending(x => Convert.ToInt64(x.StudentNo)).FirstOrDefault().StudentNo) + 1;
  112. }
  113. }
  114. else
  115. {
  116. //表示无相同班级的信息
  117. if (newStudentRepeatList.Count <= 0)
  118. {
  119. //数据表中的最大学号+1,作为下一个学号(需考虑异动情况下产生的学号)
  120. var classmajorNo = maxStudentNo.StudentNo.Substring(0, maxStudentNo.StudentNo.Trim().Length - 2);
  121. if (classmajorNo == classmajorVerify.ClassmajorNo.Trim())
  122. {
  123. //表示学号为相同班级编号下学号
  124. newStudentNo = Convert.ToInt64(maxStudentNo.StudentNo) + 1;
  125. }
  126. else
  127. {
  128. //表示学号为不相同班级编号下学号,此时应为初始学号
  129. newStudentNo = startStudentNo;
  130. }
  131. }
  132. else
  133. {
  134. //相同班级的信息中最大学号+1,作为下一个学号
  135. newStudentNo = Convert.ToInt64(newStudentRepeatList.OrderByDescending(x => Convert.ToInt64(x.StudentNo)).FirstOrDefault().StudentNo) + 1;
  136. }
  137. }
  138. newStudent.ClassmajorID = classmajorID;
  139. newStudent.StudentNo = newStudentNo.ToString();
  140. SetModifyStatus(newStudent);
  141. newStudentUpList.Add(newStudent);
  142. success++;
  143. }
  144. }
  145. else
  146. {
  147. //表示选择的班级信息不相符,无法分班及生成学号
  148. classmajorfail++;
  149. continue;
  150. }
  151. }
  152. //批量更新
  153. if (newStudentUpList != null && newStudentUpList.Count() > 0)
  154. {
  155. UnitOfWork.BatchUpdate(newStudentUpList);
  156. }
  157. if (classmajorfail <= 0 && fail <= 0)
  158. {
  159. tipMessage = success + "条录取名单的学号";
  160. }
  161. else
  162. {
  163. if (classmajorfail <= 0 && fail > 0)
  164. {
  165. tipMessage = success + "个学号,失败" + fail + "条,原因:班级信息或学号已存在,如需生成请初始化后重新生成";
  166. }
  167. else if (classmajorfail > 0 && fail <= 0)
  168. {
  169. tipMessage = success + "个学号," + classmajorfail + "条由于与选择的班级信息不相符,无法生成,请核查";
  170. }
  171. else
  172. {
  173. tipMessage = success + "个学号," + fail + "条由于班级信息或学号已存在无法生成," + classmajorfail + "条由于与选择的班级信息不相符,无法生成,请核查";
  174. }
  175. }
  176. return tipMessage;
  177. }
  178. catch (Exception ex)
  179. {
  180. throw new Exception(ex.Message);
  181. }
  182. }
  183. /// <summary>
  184. /// 自动分配班级和生成学号(广东松山)
  185. /// 注:暂不支持院系专业分方向、年级专业分方向分班、分学号
  186. /// </summary>
  187. /// <param name="newStudentIDList"></param>
  188. /// <returns></returns>
  189. public override string NewStudentEnterAutoAssignClass(List<Guid?> newStudentIDList)
  190. {
  191. //分配规则如下(根据新生实际报到人数进行分班,每个专业设置多少个小班,以教务处数据为主):
  192. //1、男女比例均衡;
  193. //2、各地区人数比例均衡;
  194. //3、高考成绩各分数段比例均衡;
  195. //4、同一宿舍的序号能连续编排在一起;
  196. //5、女生少的班级建议女生排在前面,男生少的班级建议男生排在前面,男女生比例相差不悬殊的建议混排;
  197. //6、每个小班人数必须控制在60人以内,最好55人以下;
  198. //学号(11位)=班级编号+2位流水号(按学生录取通知书编号、宿舍编号排序后顺序取学号)
  199. try
  200. {
  201. var studentNoTotal = EMIS.Utility.Const.LOCAL_SETTING_LOGINIDTOTAL;
  202. if (studentNoTotal == null)
  203. {
  204. throw new Exception("学号总位数未配置,请检查。");
  205. }
  206. //查询录取名单信息(已分配状态)
  207. var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => newStudentIDList.Contains(x.NewStudentID) && x.AssignStatus == (int)CF_AssignStatus.Assigned)
  208. .OrderBy(x => x.EnrollmentNo).ThenBy(x => x.Dormitory).OrderBy(x => x.OrderNo).ToList();
  209. //年级ID
  210. var gradeIDList = newStudentList.Where(x => !string.IsNullOrEmpty(x.GradeID.ToString())).Select(x => x.GradeID).ToList();
  211. //专业信息ID
  212. var specialtyIDList = newStudentList.Where(x => !string.IsNullOrEmpty(x.SpecialtyID.ToString())).Select(x => x.SpecialtyID).ToList();
  213. //院系所ID
  214. var collegeIDList = newStudentList.Where(x => !string.IsNullOrEmpty(x.CollegeID.ToString())).Select(x => x.CollegeID).ToList();
  215. //查询专业信息
  216. var specialtyList = NewStudentDAL.SpecialtyRepository.GetList(x => specialtyIDList.Contains(x.SpecialtyID)).ToList();
  217. //查询招生专业信息(暂时不需对招生专业进行验证)
  218. var recruitSpecialtyAllList = NewStudentDAL.RecruitSpecialtyRepository.GetList(x => true).ToList();
  219. //查询招生专业
  220. var recruitSpecialtyList = recruitSpecialtyAllList.Where(x => gradeIDList.Contains(x.GradeID) && specialtyIDList.Contains(x.SpecialtyID) && collegeIDList.Contains(x.CollegeID)).ToList();
  221. //查询对应的院系专业信息
  222. var facultymajorList = NewStudentDAL.GetFacultymajorByNewStudent(x => newStudentIDList.Contains(x.NewStudentID)).ToList();
  223. //院系专业ID
  224. var facultymajorIDList = facultymajorList.Where(x => !string.IsNullOrEmpty(x.FacultymajorID.ToString())).Select(x => x.FacultymajorID).ToList();
  225. //查询对应的年级专业信息
  226. var grademajorList = NewStudentDAL.GetGrademajorByNewStudent(x => newStudentIDList.Contains(x.NewStudentID), x => facultymajorIDList.Contains(x.FacultymajorID)).ToList();
  227. //年级专业ID
  228. var grademajorIDList = grademajorList.Where(x => !string.IsNullOrEmpty(x.GrademajorID.ToString())).Select(x => x.GrademajorID).ToList();
  229. //查询对应的班级信息
  230. var classmajorList = NewStudentDAL.GetClassmajorByNewStudent(x => newStudentIDList.Contains(x.NewStudentID), x => facultymajorIDList.Contains(x.FacultymajorID), x => grademajorIDList.Contains(x.GrademajorID)).ToList();
  231. //班级信息ID
  232. var classmajorIDList = classmajorList.Where(x => !string.IsNullOrEmpty(x.ClassmajorID.ToString())).Select(x => x.ClassmajorID).ToList();
  233. //查询各班级信息中最大的学号(新生信息表、学生信息表)
  234. var maxStudentNoList = NewStudentDAL.GetMaxStudentNoClass(x => classmajorIDList.Contains(x.ClassmajorID)).ToList();
  235. int facultymajorfail = 0;
  236. int grademajorfail = 0;
  237. int classmajorfail = 0;
  238. int fail = 0;
  239. int success = 0;
  240. string tipMessage = null;
  241. long startStudentNo = 0;
  242. long newStudentNo = 0;
  243. List<CF_NewStudent> newStudentUpList = new List<CF_NewStudent>();
  244. foreach (var newStudent in newStudentList)
  245. {
  246. //需要对院系专业、年级专业、班级信息分别进行验证(一一对应的情况下,才可自动分配班级及生成学号)
  247. //查询院系专业
  248. var facultymajorVerify = facultymajorList.Where(x => x.NewStudentID == newStudent.NewStudentID).ToList();
  249. //判断对应的院系专业
  250. if (facultymajorVerify != null && facultymajorVerify.Count() > 0)
  251. {
  252. if (facultymajorVerify.Count() == 1)
  253. {
  254. //查询年级专业
  255. var grademajorVerify = grademajorList.Where(x => x.NewStudentID == newStudent.NewStudentID).ToList();
  256. //判断对应的年级专业
  257. if (grademajorVerify != null && grademajorVerify.Count() > 0)
  258. {
  259. if (grademajorVerify.Count() == 1)
  260. {
  261. //查询班级信息
  262. var classmajorVerify = classmajorList.Where(x => x.NewStudentID == newStudent.NewStudentID).ToList();
  263. //判断对应的班级信息
  264. if (classmajorVerify != null && classmajorVerify.Count() > 0)
  265. {
  266. if (classmajorVerify.Count() == 1)
  267. {
  268. //判断当选择的信息中存在班级信息或学号等情况(只要两者之中有一个存在,将不考虑生成)
  269. if (newStudent.ClassmajorID.HasValue || !string.IsNullOrEmpty(newStudent.StudentNo))
  270. {
  271. //表示不生成
  272. fail++;
  273. continue;
  274. }
  275. else
  276. {
  277. //对可分配的班级信息及学号进行查询
  278. //查询对应班级信息中最大的学号(新生信息表、学生信息表)
  279. var specialtyClass = classmajorVerify.Where(x => x.NewStudentID == newStudent.NewStudentID).SingleOrDefault();
  280. var maxStudentNo = maxStudentNoList.Where(x => x.ClassmajorID == specialtyClass.ClassmajorID).SingleOrDefault();
  281. //查询选择生成的录取名单List中是否有分配到同一班级的信息
  282. var newStudentRepeatList = newStudentUpList.Where(x => x.ClassmajorID == specialtyClass.ClassmajorID).ToList();
  283. //初始学号(班级编号+流水号,不够学号总位数的用0填充,可在此处通过个性化配置来定义学号生成规则)
  284. startStudentNo = Convert.ToInt64(specialtyClass.ClassmajorNo.PadRight(Convert.ToInt32(studentNoTotal) - 1, '0') + "1");
  285. //表示当前班级无对应的学号,此时应为初始学号(班级编号+2位流水号,需匹配Web.config配置)
  286. if (maxStudentNo == null)
  287. {
  288. //表示无相同班级的信息
  289. if (newStudentRepeatList.Count <= 0)
  290. {
  291. //初始学号
  292. newStudentNo = startStudentNo;
  293. }
  294. else
  295. {
  296. //相同班级的信息中最大学号+1,作为下一个学号
  297. newStudentNo = Convert.ToInt64(newStudentRepeatList.OrderByDescending(x => Convert.ToInt64(x.StudentNo)).FirstOrDefault().StudentNo) + 1;
  298. }
  299. }
  300. else
  301. {
  302. //表示无相同班级的信息
  303. if (newStudentRepeatList.Count <= 0)
  304. {
  305. //数据表中的最大学号+1,作为下一个学号(需考虑异动情况下产生的学号)
  306. var classmajorNo = maxStudentNo.StudentNo.Substring(0, maxStudentNo.StudentNo.Trim().Length - 2);
  307. if (classmajorNo == specialtyClass.ClassmajorNo.Trim())
  308. {
  309. //表示学号为相同班级编号下学号
  310. newStudentNo = Convert.ToInt64(maxStudentNo.StudentNo) + 1;
  311. }
  312. else
  313. {
  314. //表示学号为不相同班级编号下学号,此时应为初始学号
  315. newStudentNo = startStudentNo;
  316. }
  317. }
  318. else
  319. {
  320. //相同班级的信息中最大学号+1,作为下一个学号
  321. newStudentNo = Convert.ToInt64(newStudentRepeatList.OrderByDescending(x => Convert.ToInt64(x.StudentNo)).FirstOrDefault().StudentNo) + 1;
  322. }
  323. }
  324. newStudent.ClassmajorID = specialtyClass.ClassmajorID;
  325. newStudent.StudentNo = newStudentNo.ToString();
  326. SetModifyStatus(newStudent);
  327. newStudentUpList.Add(newStudent);
  328. success++;
  329. }
  330. }
  331. else
  332. {
  333. //表示对应的班级信息存在多个,无法确定对应的班级信息(可在此处进行扩展,针对专业分方向的情况)
  334. classmajorfail++;
  335. continue;
  336. }
  337. }
  338. else
  339. {
  340. //表示对应的班级信息不存在,无法分班及生成学号
  341. classmajorfail++;
  342. continue;
  343. }
  344. }
  345. else
  346. {
  347. //表示对应的年级专业信息存在多个,无法确定对应的年级专业(可在此处进行扩展,针对专业分方向的情况)
  348. grademajorfail++;
  349. continue;
  350. }
  351. }
  352. else
  353. {
  354. //表示对应的年级专业信息不存在,无法分班及生成学号
  355. grademajorfail++;
  356. continue;
  357. }
  358. }
  359. else
  360. {
  361. //表示对应的院系专业信息存在多个,无法确定对应的院系专业(可在此处进行扩展,针对专业分方向的情况)
  362. facultymajorfail++;
  363. continue;
  364. }
  365. }
  366. else
  367. {
  368. //表示对应的院系专业信息不存在,无法分班及生成学号
  369. facultymajorfail++;
  370. continue;
  371. }
  372. }
  373. //批量更新
  374. if (newStudentUpList != null && newStudentUpList.Count() > 0)
  375. {
  376. UnitOfWork.BatchUpdate(newStudentUpList);
  377. }
  378. if (facultymajorfail <= 0 && grademajorfail <= 0 && fail <= 0)
  379. {
  380. tipMessage = success + "个学号";
  381. }
  382. else
  383. {
  384. if (facultymajorfail <= 0 && grademajorfail <= 0 && classmajorfail <= 0 && fail > 0)
  385. {
  386. tipMessage = success + "个学号,失败" + fail + "条,原因:班级信息或学号已存在,如需生成请初始化后重新生成";
  387. }
  388. else if (facultymajorfail > 0 && grademajorfail <= 0 && classmajorfail <= 0 && fail <= 0)
  389. {
  390. tipMessage = success + "个学号," + facultymajorfail + "条由于院系专业信息的原因无法生成,请核查";
  391. }
  392. else if (facultymajorfail <= 0 && grademajorfail > 0 && classmajorfail <= 0 && fail <= 0)
  393. {
  394. tipMessage = success + "个学号," + grademajorfail + "条由于年级专业信息的原因无法生成,请核查";
  395. }
  396. else if (facultymajorfail <= 0 && grademajorfail <= 0 && classmajorfail > 0 && fail <= 0)
  397. {
  398. tipMessage = success + "个学号," + classmajorfail + "条由于班级信息的原因无法生成(不存在),请核查";
  399. }
  400. else
  401. {
  402. tipMessage = success + "个学号," + fail + "条由于班级信息或学号已存在无法生成," + facultymajorfail + "条由于院系专业信息的原因无法生成," +
  403. grademajorfail + "条由于年级专业信息的原因无法生成," + classmajorfail + "条由于班级信息的原因无法生成(不存在),请核查";
  404. }
  405. }
  406. return tipMessage;
  407. }
  408. catch (Exception ex)
  409. {
  410. throw new Exception(ex.Message);
  411. }
  412. }
  413. }
  414. }