ExamineApplyServices.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.StudentSystem.MyGrade;
  6. using EMIS.ViewModel.Students;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.DataLogic.StudentSystem.ExamineApply;
  9. using EMIS.ViewModel.ExaminationApply;
  10. using EMIS.CommonLogic.SystemServices;
  11. using EMIS.Entities;
  12. using EMIS.DataLogic.Repositories;
  13. using EMIS.DataLogic.ExaminationApply;
  14. using EMIS.CommonLogic.CalendarManage;
  15. using EMIS.ViewModel;
  16. using EMIS.DataLogic.ScoreManage;
  17. using System.Transactions;
  18. using EMIS.DataLogic.SelectCourse;
  19. using EMIS.ViewModel.ScoreManage;
  20. using System.Linq.Expressions;
  21. using Bowin.Common.Linq;
  22. using EMIS.DataLogic.StudentSystem.StudentMaterial;
  23. namespace EMIS.CommonLogic.Students
  24. {
  25. public class ExamineApplyServices : BaseWorkflowServices<EX_ExaminationRegistration>, IExamineApplyServices
  26. {
  27. public Lazy<ISchoolYearServices> SchoolYearServices { get; set; }
  28. public ExamineApplyDAL ExamineApplyDAL { get; set; }
  29. public StudentRecordDAL studentRecordDAL { get; set; }
  30. public ExaminationRegistrationRepository RegistrationRepository { get; set; }
  31. public SubjectCountLimitDAL SubjectCountLimitDAL { get; set; }
  32. public OpenControlDAL OpenControlDAL { get; set; }
  33. public GrademajorRepository gradeRepository { get; set; }
  34. public LevelScoreDAL levelScoreDAL { get; set; }
  35. public LevelSettingDAL levelSettingDAL { get; set; }
  36. public ExaminationSubjectCollegeControlDAL examinationSubjectCollegeControlDAL { get; set; }
  37. public DictionaryItemRepository dictionaryItemRepository { get; set; }
  38. public IGridResultSet<ExaminationApplyView> GetExaminationSubjectList(Guid UserID)
  39. {
  40. return ExamineApplyDAL.GetExaminationSubjectList(UserID).Where(x=>x.EndDate.Value.AddDays(1)>=DateTime.Now).OrderBy(x => x.EndDate).ThenBy(x => x.StartDate).ThenBy(x => x.ExaminationDate).AsQueryable<ExaminationApplyView>().ToGridResultSet();
  41. }
  42. public void ApplySubmit(Guid examinationSubjectID, Guid UserID)
  43. {
  44. var student = studentRecordDAL.GetStudentByStudentNo(UserID);
  45. if (student.PhotoUrl == null)
  46. {
  47. throw new Exception("您没有照片,请先上传照片后再报名");
  48. }
  49. var currentSchoolyear = SchoolYearServices.Value.GetCurrentSchoolYear();
  50. //学生报名限制加上已报考且成绩“合格”以上禁止重复报考的限制
  51. var TotalScore = levelScoreDAL.levelScoreRepository.Entities.Where(x => x.UserID == UserID && x.ExaminationSubjectID == examinationSubjectID).OrderByDescending(x => x.TotalScore).FirstOrDefault();
  52. if (TotalScore != null)
  53. {
  54. //以合格、及格为关键字查询过级等级分数
  55. var passLevel = levelSettingDAL.levelSettingRepository.Entities.Where(x => x.ExaminationSubjectID == examinationSubjectID && (x.LevelName == "合格" || x.LevelName == "及格")).FirstOrDefault();
  56. if (passLevel != null && passLevel.MinScore <= TotalScore.TotalScore)
  57. throw new Exception("已报考过该科目,并且成绩合格,不能重复报考");
  58. }
  59. //找到该学生的年级
  60. int? gradeYear = gradeRepository.Entities.Where(x => x.Code == student.GradeCode).FirstOrDefault().GradeID;
  61. var subject = ExamineApplyDAL.SubjectRepository.GetSingle(x => x.ExaminationSubjectID == examinationSubjectID,
  62. x => x.EX_ExaminationRegistration.Select(w => w.CF_Student.CF_Classmajor.CF_Grademajor));
  63. //,x => x.ER_LevelScore);//.Where(q => q.UserID == UserID)
  64. var schoolyearNum = (currentSchoolyear.Value - student.StartSchoolyearValue - (currentSchoolyear.SchoolcodeID == student.StartSchoolcodeID ? 0 : 1)) / 2 + 1;
  65. var subjectCountLimit = SubjectCountLimitDAL.ExaminationSubjectCountLimitRepository.GetSingle(x => x.Years == schoolyearNum
  66. && x.EX_ExaminationType.EX_ExaminationSubject.Any(w => w.ExaminationSubjectID == examinationSubjectID)
  67. && x.FacultymajorID == student.FacultymajorID && x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  68. int? sameSchoolNumRegistCount = 0;
  69. //if (subjectCountLimit == null)
  70. //{
  71. // sameSchoolNumRegistCount = RegistrationRepository.GetList(x => x.UserID == UserID && x.SchoolyearID == currentSchoolyear.SchoolYearID)
  72. // .Count();
  73. //}
  74. if (subjectCountLimit != null)//else
  75. {
  76. sameSchoolNumRegistCount = RegistrationRepository.GetList(x => x.UserID == UserID && x.SchoolyearID == currentSchoolyear.SchoolYearID && x.EX_ExaminationSubject.ExaminationTypeID == subjectCountLimit.ExaminationTypeID)
  77. .Count();
  78. }
  79. var openControl = OpenControlDAL.ExaminationOpenControlRepository.GetSingle(x => x.SchoolyearNumID == schoolyearNum
  80. && x.ExaminationSubjectID == examinationSubjectID
  81. && x.StudentType == student.StudentType && x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  82. //当该考试科目存在要求通过的科目时,要判断该学生要求通过的科目成绩是否达到最低通过分,如英语六级要求英语四级达到60分时
  83. if (subject.PreposeSubjectID != null && subject.PreposeSubjectID != Guid.Empty)
  84. { //先判断是否有要求通过科目
  85. var preposeSubject = ExamineApplyDAL.SubjectRepository.Entities.Where(x => x.ExaminationSubjectID == subject.PreposeSubjectID).FirstOrDefault();
  86. if (preposeSubject == null)
  87. throw new Exception("找不到【" + subject.Name + "】所对应的要求通过科目。");
  88. //判断该学生的要求通过科目的成绩是否存在
  89. //var score = levelScoreDAL.levelScoreRepository.Entities.Where(x => x.ExaminationSubjectID == subject.PreposeSubjectID && x.UserID == UserID).FirstOrDefault();
  90. var score = levelScoreDAL.levelScoreRepository.Entities.Where(x => x.EX_ExaminationSubject.Name == preposeSubject.Name && x.UserID == UserID).OrderByDescending(x => x.TotalScore).FirstOrDefault();
  91. if (score == null)
  92. throw new Exception("找不到要求通过的科目【" + preposeSubject.Name + "】的成绩。");
  93. else
  94. { //找到该学生要求通过成绩后,判断分数是否达到通过的最低分
  95. if (score.TotalScore < subject.PreposeScoreLimit)
  96. throw new Exception("达不到要求通过科目【" + preposeSubject.Name + "】的最低分,不能报名");
  97. }
  98. }
  99. //var examinationSubjectCollegeControl = examinationSubjectCollegeControlDAL.GetExaminationSubjectCollegeControlView(x => x.ExaminationSubjectID == examinationSubjectID && x.FacultymajorID == student.FacultymajorID && x.SchoolyearNumID == schoolyearNum, x => true, x => true).FirstOrDefault();
  100. //if (examinationSubjectCollegeControl != null)
  101. //{
  102. // throw new Exception(examinationSubjectCollegeControl.FacultymajorName + "专业");
  103. //}
  104. using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }))
  105. {
  106. //统计出某科目除当前学生外,与其同级的学生报名数,也就是某科目某学年除当前学生外的报名数
  107. var studentCount = subject.EX_ExaminationRegistration.Where(x => x.CF_Student.UserID != UserID && x.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == gradeYear && x.SchoolyearID == currentSchoolyear.SchoolYearID).Count();
  108. //同一个学生同一个考试科目考试学年学期相同则认为报名重复
  109. var isRegisted = subject.EX_ExaminationRegistration.Any(x => x.CF_Student.UserID == UserID && x.ExaminationSchoolyearID == subject.SchoolyearID);
  110. if (isRegisted)
  111. {
  112. throw new Exception("你已报名该科目,不能再报名。");
  113. }
  114. //该考试科目当前学年学期总报名人数
  115. int studentRegistCount = RegistrationRepository.GetList(x => x.SchoolyearID == currentSchoolyear.SchoolYearID && x.EX_ExaminationSubject.ExaminationSubjectID == subject.ExaminationSubjectID)
  116. .Count();
  117. if (subjectCountLimit != null && sameSchoolNumRegistCount >= subjectCountLimit.SubjectCountLimit && (subjectCountLimit.SubjectCountLimit ?? 0) != 0)
  118. {
  119. throw new Exception("你报考该类型的科目数量已经达到门数上限,本学年不能再报名。");
  120. }
  121. //if (openControl == null)
  122. //{
  123. // throw new Exception("没有开放控制,不能报名。");
  124. //}
  125. //开放控制某一年级人数限定判断
  126. if (openControl != null)
  127. {
  128. if (studentCount >= openControl.PeopleNumLimit && (openControl.PeopleNumLimit ?? 0) != 0)
  129. {
  130. throw new Exception("该科目同一年级报考人数已达上限,不能再报考");
  131. }
  132. }
  133. //科目最大报名人数
  134. if (studentRegistCount >= subject.PeopleNumLimit)
  135. {
  136. throw new Exception("该科目最大报名人数已达上限,不能再报考");
  137. }
  138. if (DateTime.Now.Date > openControl.EndDate || DateTime.Now.Date < openControl.StartDate)
  139. {
  140. throw new Exception("不在报名时间内,不能报名。");
  141. }
  142. EX_ExaminationRegistration regist = new EX_ExaminationRegistration();
  143. regist.ExaminationRegistrationID = Guid.NewGuid();
  144. regist.ExaminationSubjectID = examinationSubjectID;
  145. regist.CertificatesType = student.CertificatesType;
  146. regist.IDNumber = student.IDNumber;
  147. regist.UserID = student.UserID;
  148. regist.RecordStatus = 1;
  149. regist.ExaminationSchoolyearID = subject.SchoolyearID;//报名时加入科目考试学年学期
  150. regist.SchoolyearID = currentSchoolyear.SchoolYearID;
  151. regist.CreateUserID = UserID;
  152. regist.CreateTime = DateTime.Now;
  153. RegistrationRepository.UnitOfWork.Add(regist);
  154. RegistrationRepository.UnitOfWork.Commit();
  155. ts.Complete();
  156. }
  157. }
  158. public void ApplyCancel(List<Guid> examinationRegistrationIDList)
  159. {
  160. try
  161. {
  162. var currentSchoolyear = SchoolYearServices.Value.GetCurrentSchoolYear();
  163. foreach (var id in examinationRegistrationIDList)
  164. {
  165. var examinationRegistration = RegistrationRepository.Entities.Where(x => x.ExaminationRegistrationID == id).FirstOrDefault();
  166. if (examinationRegistration != null)
  167. {
  168. var subject = ExamineApplyDAL.SubjectRepository.GetSingle(x => x.ExaminationSubjectID == examinationRegistration.ExaminationSubjectID, (x => x.EX_ExaminationOpenControl));
  169. if (subject != null)
  170. {
  171. var student = studentRecordDAL.GetStudentByStudentNo(examinationRegistration.UserID.Value);
  172. var schoolyearNum = (currentSchoolyear.Value - student.StartSchoolyearValue - (currentSchoolyear.SchoolcodeID == student.StartSchoolcodeID ? 0 : 1)) / 2 + 1;
  173. if (schoolyearNum <= 0)
  174. throw new Exception("撤销失败,找不到该学生对应年级数。");
  175. var examinationOpenControl = subject.EX_ExaminationOpenControl.Where(x => x.SchoolyearNumID == schoolyearNum).FirstOrDefault();
  176. if(examinationOpenControl!=null)
  177. {
  178. if (examinationOpenControl.EndDate < DateTime.Now.Date)
  179. {
  180. throw new Exception("已过报名截止时间,不能进行撤销操作。");
  181. }
  182. else
  183. //UnitOfWork.Delete<EX_ExaminationRegistration>(x => x.ExaminationRegistrationID==id);
  184. UnitOfWork.Remove<EX_ExaminationRegistration>(x => x.ExaminationRegistrationID == id);
  185. }
  186. else
  187. throw new Exception("撤销失败,找不到该学生对应年级的开放控制。");
  188. }
  189. }
  190. }
  191. //UnitOfWork.Delete<EX_ExaminationRegistration>(x => examinationRegistrationIDList.Contains(x.ExaminationRegistrationID));
  192. UnitOfWork.Commit();
  193. }
  194. catch (Exception)
  195. {
  196. throw;
  197. }
  198. }
  199. public IGridResultSet<ExaminationRegisView> GetExaminationRegisterList(Guid UserID)
  200. {
  201. var result = ExamineApplyDAL.GetExaminationRegisterList(UserID).OrderByDescending(x => x.SchoolYearCode).ThenBy(x => x.Name).ThenBy(x => x.ExaminationDate).AsQueryable<ExaminationRegisView>().ToGridResultSet();
  202. return result;
  203. }
  204. public ExaminationApplyView GetExaminationApplyViewByExaminationSubjectID(Guid? ExaminationSubjectID)
  205. {
  206. var result = ExamineApplyDAL.GetExaminationApplyView(ExaminationSubjectID);
  207. if (result.Count > 0)
  208. {
  209. return result.FirstOrDefault();
  210. }
  211. else {
  212. return null;
  213. }
  214. }
  215. public IGridResultSet<LevelScoreView> GetLevelScoreViewAndRegisterList(Guid? UserID, Guid? SchoolYearID, int pageIndex, int pageSize)
  216. {
  217. Expression<Func<ER_LevelScore, bool>> lelexp = x => true;
  218. Expression<Func<EX_ExaminationRegistration, bool>> erexp = x => true;
  219. if(UserID.HasValue)
  220. {
  221. lelexp = lelexp.And(x => x.UserID == UserID);
  222. erexp = erexp.And(x => x.UserID == UserID);
  223. }
  224. if(SchoolYearID.HasValue)
  225. {
  226. lelexp = lelexp.And(x => x.SchoolyearID == SchoolYearID);
  227. erexp = erexp.And(x => x.SchoolyearID == SchoolYearID);
  228. }
  229. var query = ExamineApplyDAL.GetLevelScoreViewAndRegisterList(lelexp, erexp);
  230. var queryLevelName = levelSettingDAL.GetLevelSettingViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  231. var result = query.OrderByDescending(x => x.SchoolyearCode).ToGridResultSet<LevelScoreView>(pageIndex, pageSize);
  232. result.rows.ForEach(x =>
  233. x.LevelName = x.TotalScore == null ? "":(queryLevelName.Where(t =>
  234. t.MaxScore >= x.TotalScore &&
  235. t.MinScore <= x.TotalScore &&
  236. t.ExaminationSubjectName == x.ExaminationSubjectName).OrderByDescending(o => o.MaxScore).ThenByDescending(o => o.MinScore).Select(w => w.LevelName).FirstOrDefault()));
  237. return result;
  238. }
  239. public Dictionary<int, string> GetPolitics()
  240. {
  241. Dictionary<int, string> Politics = new Dictionary<int, string>();
  242. var query = from dic in dictionaryItemRepository.GetList(x => x.DictionaryCode == "CF_Politics")
  243. select new
  244. {
  245. dic.Value,
  246. dic.Code,
  247. dic.Name
  248. };
  249. query.ToList().ForEach(x =>
  250. {
  251. Politics.Add(x.Value.Value, x.Name);
  252. });
  253. return Politics;
  254. }
  255. public Dictionary<int, string> GetHealthState()
  256. {
  257. Dictionary<int, string> HealthState = new Dictionary<int, string>();
  258. var query = from dic in dictionaryItemRepository.GetList(x => x.DictionaryCode == "CF_HealthState")
  259. select new
  260. {
  261. dic.Value,
  262. dic.Code,
  263. dic.Name
  264. };
  265. query.ToList().ForEach(x =>
  266. {
  267. HealthState.Add(x.Value.Value, x.Name);
  268. });
  269. return HealthState;
  270. }
  271. }
  272. }