NewStudentEnterServices.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Transactions;
  6. using Bowin.Common.Utility;
  7. using EMIS.Entities;
  8. using EMIS.Utility;
  9. using EMIS.ViewModel;
  10. namespace EMIS.ExtensionLogic.ServiceLogic.EnrollManage
  11. {
  12. public class NewStudentEnterServices : EMIS.CommonLogic.EnrollManage.NewStudentManage.NewStudentEnterServices
  13. {
  14. /// <summary>
  15. /// 提交(河北工大)
  16. /// 注:需判断对应的录取照片是否存在、是否已分班且生成学号,并对学生信息进行验证,如:考生号或准考证号唯一、学号唯一
  17. /// </summary>
  18. /// <param name="newStudentIDList"></param>
  19. /// <returns></returns>
  20. public override string NewStudentEnterSubmit(List<Guid?> newStudentIDList)
  21. {
  22. try
  23. {
  24. //查询相关Web.config配置
  25. if (EMIS.Utility.Const.LOCAL_SETTING_PlanningGraduateDateSpringMonth == null)
  26. {
  27. throw new Exception("预计毕业月(春季、上学期入学月)未配置,请检查。");
  28. }
  29. if (EMIS.Utility.Const.LOCAL_SETTING_PlanningGraduateDateSpringDay == null)
  30. {
  31. throw new Exception("预计毕业日(春季、上学期入学日)未配置,请检查。");
  32. }
  33. if (EMIS.Utility.Const.LOCAL_SETTING_PlanningGraduateDateAutumnMonth == null)
  34. {
  35. throw new Exception("预计毕业月(秋季、下学期入学月)未配置,请检查。");
  36. }
  37. if (EMIS.Utility.Const.LOCAL_SETTING_PlanningGraduateDateAutumnDay == null)
  38. {
  39. throw new Exception("预计毕业日(秋季、下学期入学日)未配置,请检查。");
  40. }
  41. //查询录取名单信息(已分配状态)
  42. var newStudentEnterList = NewStudentDAL.NewStudentRepository.GetList(x => newStudentIDList.Contains(x.NewStudentID) && x.AssignStatus == (int)CF_AssignStatus.Assigned).ToList();
  43. //查询班级信息ID为空的录取名单(注:如果有班级信息,对应的专业班级一定存在(无需验证是否有专业班级))
  44. var classIDVerifyList = newStudentEnterList.Where(x => string.IsNullOrEmpty(x.ClassmajorID.ToString())).ToList();
  45. if (classIDVerifyList != null && classIDVerifyList.Count() > 0)
  46. {
  47. throw new Exception("选择提交的名单中存在未分班的数据,请检查。");
  48. }
  49. //查询学号为空的录取名单
  50. var studentNoVerifyList = newStudentEnterList.Where(x => string.IsNullOrEmpty(x.StudentNo)).ToList();
  51. if (studentNoVerifyList != null && studentNoVerifyList.Count() > 0)
  52. {
  53. throw new Exception("选择提交的名单中存在未生成学号的数据,请检查。");
  54. }
  55. //有疑义名单判断
  56. if (newStudentEnterList.Any(x => x.IsDoubt == true))
  57. {
  58. throw new Exception("选择提交的名单中存在有疑议的数据,请检查。");
  59. }
  60. //已提交状态判断
  61. if (newStudentEnterList.Any(x => x.RecordStatus == (int)EMIS.ViewModel.CF_NewStudentEnterStatus.Submitted))
  62. {
  63. throw new Exception("选择提交的名单中存在已提交的数据,请检查。");
  64. }
  65. //查询录取照片为空的录取名单
  66. var pictureUrlVerifyList = newStudentEnterList.Where(x => string.IsNullOrEmpty(x.RecruitPictureUrl)).ToList();
  67. if (pictureUrlVerifyList != null && pictureUrlVerifyList.Count() > 0)
  68. {
  69. throw new Exception("选择提交的名单中存在录取照片不存在的数据,请检查。");
  70. }
  71. //年级
  72. var gradeIDList = newStudentEnterList.Where(x => !string.IsNullOrEmpty(x.GradeID.ToString())).Select(x => x.GradeID).ToList();
  73. //考生号
  74. var examineeNumList = newStudentEnterList.Where(x => !string.IsNullOrEmpty(x.ExamineeNum)).Select(x => x.ExamineeNum).ToList();
  75. ////准考证号
  76. //var admissionTicketNoList = newStudentEnterList.Where(x => !string.IsNullOrEmpty(x.AdmissionTicketNo)).Select(x => x.AdmissionTicketNo).ToList();
  77. //身份证号
  78. var iDNumberList = newStudentEnterList.Where(x => !string.IsNullOrEmpty(x.IDNumber)).Select(x => x.IDNumber).ToList();
  79. //学号
  80. var studentNoList = newStudentEnterList.Where(x => !string.IsNullOrEmpty(x.StudentNo)).Select(x => x.StudentNo).ToList();
  81. //查询学年学期信息(验证对应的年级专业的入学学期与Web.config配置是否一致,有班级信息相应的学年学期信息一定存在)
  82. //如不致,以年级专业对应的入学学期为准
  83. var schoolyearVerifyList = NewStudentDAL.SchoolyearRepository.GetList(x => gradeIDList.Contains(x.Years)).ToList();
  84. //班级信息ID
  85. var classIDList = newStudentEnterList.Where(x => !string.IsNullOrEmpty(x.ClassmajorID.ToString())).Select(x => x.ClassmajorID).ToList();
  86. ////查询学生信息(用于验证考生号、准考证号)
  87. //var studentVerifyList = NewStudentDAL.RecruitstudentsRepository.GetList(x => examineeNumList.Contains(x.ExamineeNum) || admissionTicketNoList.Contains(x.AdmissionTicketNo)).ToList();
  88. //查询学生信息(用于验证考生号)
  89. var studentVerifyList = NewStudentDAL.RecruitstudentsRepository.GetList(x => examineeNumList.Contains(x.ExamineeNum)).ToList();
  90. //查询用户信息(用于验证学号)
  91. var userVerifyList = NewStudentDAL.UserRepository.GetList(x => studentNoList.Contains(x.LoginID)).ToList();
  92. //查询班级信息(用于验证班级)
  93. var classMajorVerifyList = NewStudentDAL.ClassmajorRepository.GetList(x => classIDList.Contains(x.ClassmajorID)).ToList();
  94. //年级专业ID(根据班级信息ID)
  95. var classMajorIDList = classMajorVerifyList.Where(x => !string.IsNullOrEmpty(x.GrademajorID.ToString())).Select(x => x.GrademajorID).ToList();
  96. //查询年级专业(根据年级专业ID)
  97. var gradeMajorVerifyList = NewStudentDAL.GrademajorRepository.GetList(x => classMajorIDList.Contains(x.GrademajorID)).ToList();
  98. //查询年级专业的毕业学期ID(根据年级专业ID)
  99. var gradschoolyearIDList = NewStudentDAL.GrademajorRepository.GetList(x => classMajorIDList.Contains(x.GrademajorID)).Select(x => x.GraduateSchoolyearID).ToList();
  100. //查询毕业学期(用于验证毕业学期)
  101. var gradschoolyearVerifyList = NewStudentDAL.SchoolyearRepository.GetList(x => gradschoolyearIDList.Contains(x.SchoolyearID)).ToList();
  102. //查询毕业学期对应的毕业日期List
  103. var graduateDateList = NewStudentDAL.GraduateSchoolyearRepository.GetList(x => true).ToList();
  104. //查询学生用户密码规则定义
  105. var passwordParameter = NewStudentDAL.ParameterRepository.GetSingle(x => x.ParameterTypeID == (int)ViewModel.CF_ParameterType.StudentInitPassword);
  106. //查询学生角色信息
  107. var roleList = NewStudentDAL.RoleRepository.GetList(x => x.TypeID == (int)SYS_RoleType.Student, (x => x.CF_StudentRole)).ToList();
  108. int studentfail = 0;
  109. int studentNofail = 0;
  110. int success = 0;
  111. string tipMessage = null;
  112. List<CF_NewStudent> newStudentUpList = new List<CF_NewStudent>();
  113. List<Sys_User> userInList = new List<Sys_User>();
  114. List<CF_Student> studentInList = new List<CF_Student>();
  115. List<CF_StudentProfile> studentProfileInList = new List<CF_StudentProfile>();
  116. List<CF_StudentContact> studentContactInList = new List<CF_StudentContact>();
  117. List<CF_StudentAccount> studentAccountInList = new List<CF_StudentAccount>();
  118. List<CF_Recruitstudents> studentRecruitInList = new List<CF_Recruitstudents>();
  119. //List<CF_StudentFamily> studentFamilyInList = new List<CF_StudentFamily>();
  120. //List<CF_StudentExperience> studentExperienceInList = new List<CF_StudentExperience>();
  121. foreach (var newStudentEnter in newStudentEnterList)
  122. {
  123. Sys_User user = new Sys_User();
  124. CF_Student student = new CF_Student();
  125. CF_StudentProfile studentProfile = new CF_StudentProfile();
  126. CF_StudentContact studentContact = new CF_StudentContact();
  127. CF_StudentAccount studentAccount = new CF_StudentAccount();
  128. CF_Recruitstudents studentRecruit = new CF_Recruitstudents();
  129. //CF_StudentFamily studentFamily = new CF_StudentFamily();
  130. //CF_StudentExperience studentExperience = new CF_StudentExperience();
  131. //验证考生号
  132. var examineeNumVerify = studentVerifyList.Where(x => x.ExamineeNum == newStudentEnter.ExamineeNum).SingleOrDefault();
  133. if (examineeNumVerify == null)
  134. {
  135. ////验证准考证号
  136. //if (!string.IsNullOrEmpty(newStudentEnter.AdmissionTicketNo))
  137. //{
  138. // var admissionTicketNoVerify = studentVerifyList.Where(x => x.AdmissionTicketNo == newStudentEnter.AdmissionTicketNo).SingleOrDefault();
  139. // if (admissionTicketNoVerify != null)
  140. // {
  141. // //准考证号验证不通过
  142. // studentfail++;
  143. // continue;
  144. // }
  145. //}
  146. //考生号验证通过,验证学号
  147. var userVerify = userVerifyList.Where(x => x.LoginID == newStudentEnter.StudentNo).SingleOrDefault();
  148. if (userVerify == null)
  149. {
  150. //学号验证通过
  151. user.UserID = Guid.NewGuid();
  152. user.LoginID = newStudentEnter.StudentNo;
  153. user.Name = newStudentEnter.Name;
  154. if (passwordParameter == null)
  155. {
  156. user.Password = ("A" + newStudentEnter.StudentNo).MD5();
  157. }
  158. else
  159. {
  160. if (passwordParameter.Value != null)
  161. {
  162. user.Password = passwordParameter.Value;
  163. }
  164. else
  165. {
  166. user.Password = ("A" + newStudentEnter.StudentNo).MD5();
  167. }
  168. }
  169. SetNewStatus(user, (int)SYS_STATUS.USABLE);
  170. userInList.Add(user);
  171. user.Sys_Role = new HashSet<Sys_Role>();
  172. roleList = roleList.Where(x => x.CF_StudentRole.StudentType == (int)CF_STUDENTTYPE.DefaultType).ToList();
  173. if (roleList != null && roleList.Count > 0)
  174. {
  175. roleList.ForEach(x => user.Sys_Role.Add(x));
  176. }
  177. student.UserID = user.UserID;
  178. student.ClassmajorID = newStudentEnter.ClassmajorID;
  179. student.SexID = newStudentEnter.SexID;
  180. student.BirthDate = newStudentEnter.BirthDate;
  181. student.NationID = newStudentEnter.NationID;
  182. student.PoliticsID = newStudentEnter.PoliticsID;
  183. student.CertificatesType = newStudentEnter.CertificatesType;
  184. student.IDNumber = newStudentEnter.IDNumber;
  185. student.StudentType = (int)CF_STUDENTTYPE.DefaultType;
  186. student.InSchoolStatusID = (int)CF_InschoolStatus.InSchool;
  187. student.StudentStatus = (int)CF_StudentStatus.Registration;
  188. student.StudentCardNo = user.LoginID;
  189. student.PhotoUrl = null;
  190. //对应的班级信息
  191. var classMajor = classMajorVerifyList.Where(x => x.ClassmajorID == newStudentEnter.ClassmajorID).SingleOrDefault();
  192. //对应的年级专业的毕业学期
  193. var gradeMajor = gradeMajorVerifyList.Where(x => x.GrademajorID == classMajor.GrademajorID).SingleOrDefault();
  194. if (gradeMajor != null)
  195. {
  196. //查询对应毕业学期信息
  197. var gradschoolyear = gradschoolyearVerifyList.Where(x => x.SchoolyearID == gradeMajor.GraduateSchoolyearID).SingleOrDefault();
  198. if (gradschoolyear != null)
  199. {
  200. //预计毕业日期
  201. student.PlanningGraduateDate = PlanningGraduateDateHelper.GetPlanningGraduateDate(gradschoolyear.FirstWeek);
  202. }
  203. else
  204. {
  205. //预计毕业日期
  206. student.PlanningGraduateDate = null;
  207. }
  208. //查询对应的毕业日期
  209. var graduateDate = graduateDateList.Where(x => x.SchoolyearID == gradeMajor.GraduateSchoolyearID).SingleOrDefault();
  210. if (graduateDate != null)
  211. {
  212. //毕业日期
  213. student.GraduateDate = graduateDate.GraduateDate;
  214. }
  215. else
  216. {
  217. //毕业日期
  218. student.GraduateDate = null;
  219. }
  220. }
  221. else
  222. {
  223. //预计毕业日期
  224. student.PlanningGraduateDate = null;
  225. //毕业日期
  226. student.GraduateDate = null;
  227. }
  228. student.GraduateCardNo = null;
  229. student.ReplaceGraduateNo = null;
  230. student.DegreeStatus = false;
  231. student.GraduationPictureUrl = null;
  232. student.Career = null;
  233. student.IsPhotoComparison = false;
  234. student.IsProofread = false;
  235. student.Remark = newStudentEnter.Remark;
  236. SetNewStatus(student, (int)SYS_STATUS.USABLE);
  237. studentInList.Add(student);
  238. studentProfile.UserID = user.UserID;
  239. studentProfile.UsedName = null;
  240. studentProfile.LiteracyLevelID = null;
  241. studentProfile.CultureModelID = null;
  242. studentProfile.IsDreamProject = false;
  243. studentProfile.Country = "中国";
  244. studentProfile.Place = null;
  245. studentProfile.BornPlace = null;
  246. studentProfile.HealthStateID = null;
  247. studentProfile.BloodGroup = null;
  248. studentProfile.Specialty = null;
  249. studentProfile.Height = null;
  250. studentProfile.Weight = null;
  251. studentProfile.DirectorName = null;
  252. SetNewStatus(studentProfile, (int)SYS_STATUS.USABLE);
  253. studentProfileInList.Add(studentProfile);
  254. studentContact.UserID = user.UserID;
  255. studentContact.Email = null;
  256. studentContact.Telephone = newStudentEnter.Telephone;
  257. studentContact.Mobile = newStudentEnter.Telephone;
  258. studentContact.ZIPCode = newStudentEnter.ZIPCode;
  259. studentContact.WeChatNum = null;
  260. studentContact.QQ = null;
  261. studentContact.HomeAddress = null;
  262. studentContact.WorkUnit = null;
  263. studentContact.Address = newStudentEnter.Address;
  264. studentContact.Recipient = newStudentEnter.Name;
  265. studentContact.Dormitory = null;
  266. SetNewStatus(studentContact, (int)SYS_STATUS.USABLE);
  267. studentContactInList.Add(studentContact);
  268. studentAccount.UserID = user.UserID;
  269. studentAccount.CardNo = null;
  270. studentAccount.BankName = null;
  271. SetNewStatus(studentAccount, (int)SYS_STATUS.USABLE);
  272. studentAccountInList.Add(studentAccount);
  273. studentRecruit.UserID = user.UserID;
  274. studentRecruit.ExamineeNum = newStudentEnter.ExamineeNum;
  275. studentRecruit.AdmissionTicketNo = newStudentEnter.AdmissionTicketNo;
  276. studentRecruit.ExamineeType = null;
  277. //查询对应入学学年学期
  278. var enterSchoolYear = schoolyearVerifyList.Where(x => x.Years == newStudentEnter.GradeID && x.SchoolcodeID == classMajor.CF_Grademajor.SemesterID).SingleOrDefault();
  279. if (enterSchoolYear != null)
  280. {
  281. studentRecruit.EnteringSchoolYearID = enterSchoolYear.SchoolyearID;
  282. }
  283. else
  284. {
  285. studentRecruit.EnteringSchoolYearID = null;
  286. }
  287. studentRecruit.EntranceDate = newStudentEnter.EntranceDate;
  288. studentRecruit.Score = newStudentEnter.Score;
  289. studentRecruit.EntranceWayID = newStudentEnter.EntranceWayID;
  290. studentRecruit.FeaturesID = newStudentEnter.FeaturesID;
  291. studentRecruit.TerritorialID = newStudentEnter.TerritorialID;
  292. studentRecruit.Area = null;
  293. studentRecruit.RecruitPictureUrl = newStudentEnter.RecruitPictureUrl;
  294. SetNewStatus(studentRecruit, (int)SYS_STATUS.USABLE);
  295. studentRecruitInList.Add(studentRecruit);
  296. //studentFamily.StudentFamilyID = Guid.NewGuid();
  297. //studentFamily.UserID = user.UserID;
  298. //SetNewStatus(studentFamily, (int)SYS_STATUS.USABLE);
  299. //studentFamilyInList.Add(studentFamily);
  300. //studentExperience.StudentExperienceID = Guid.NewGuid();
  301. //studentExperience.UserID = user.UserID;
  302. //SetNewStatus(studentExperience, (int)SYS_STATUS.USABLE);
  303. //studentExperienceInList.Add(studentExperience);
  304. //获取提交成功的录取名单信息(用于做其它的处理,如:删除、更新等)
  305. newStudentEnter.RecordStatus = (int)CF_NewStudentEnterStatus.Submitted;
  306. SetModifyStatus(newStudentEnter);
  307. newStudentUpList.Add(newStudentEnter);
  308. success++;
  309. }
  310. else
  311. {
  312. //学号验证不通过
  313. studentNofail++;
  314. continue;
  315. }
  316. }
  317. else
  318. {
  319. //考生号验证不通过
  320. studentfail++;
  321. continue;
  322. }
  323. }
  324. using (TransactionScope ts = new TransactionScope())
  325. {
  326. //批量插入
  327. UnitOfWork.BulkInsert<Sys_User>(userInList);
  328. UnitOfWork.BulkInsert(userInList, (x => x.Sys_Role)); //插入相应的关系表
  329. UnitOfWork.BulkInsert<CF_Student>(studentInList);
  330. UnitOfWork.BulkInsert<CF_StudentProfile>(studentProfileInList);
  331. UnitOfWork.BulkInsert<CF_StudentContact>(studentContactInList);
  332. UnitOfWork.BulkInsert<CF_StudentAccount>(studentAccountInList);
  333. UnitOfWork.BulkInsert<CF_Recruitstudents>(studentRecruitInList);
  334. //UnitOfWork.BulkInsert<CF_StudentFamily>(studentFamilyInList);
  335. //UnitOfWork.BulkInsert<CF_StudentExperience>(studentExperienceInList);
  336. //刷新对应的学生相关信息
  337. StudentServices.Value.AddStudentEnd(studentInList.Select(x => x.UserID).ToList());
  338. //提交成功后,更新相应的录取名单状态
  339. if (newStudentUpList != null && newStudentUpList.Count() > 0)
  340. {
  341. UnitOfWork.BatchUpdate(newStudentUpList); //批量更新
  342. }
  343. ts.Complete();
  344. }
  345. if (studentfail <= 0 && studentNofail <= 0)
  346. {
  347. tipMessage = success + "条录取名单进入学生信息库";
  348. }
  349. else
  350. {
  351. if (studentNofail > 0 && studentfail <= 0)
  352. {
  353. tipMessage = success + "条录取名单进入学生信息库," + studentNofail + "条录取名单提交失败,原因:学号已存在,请检查";
  354. }
  355. else if (studentNofail <= 0 && studentfail > 0)
  356. {
  357. tipMessage = success + "条录取名单进入学生信息库," + studentfail + "条录取名单提交失败,原因:考生号或准考证号已存在,请检查";
  358. }
  359. else
  360. {
  361. tipMessage = success + "条录取名单进入学生信息库," + studentNofail + "条录取名单由于学号已存在提交失败," + studentfail + "条录取名单由于考生号或准考证号已存在提交失败,请检查";
  362. }
  363. }
  364. return tipMessage;
  365. }
  366. catch (Exception ex)
  367. {
  368. throw new Exception(ex.Message);
  369. }
  370. }
  371. }
  372. }