ExamineApplyServices.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.ViewModel.Students;
  6. using Bowin.Common.Linq.Entity;
  7. using EMIS.DataLogic.StudentSystem.ExamineApply;
  8. using EMIS.ViewModel.ExaminationApply;
  9. using EMIS.CommonLogic.SystemServices;
  10. using EMIS.Entities;
  11. using EMIS.DataLogic.Repositories;
  12. using EMIS.DataLogic.StudentSystem.StudentMaterial;
  13. using EMIS.DataLogic.ExaminationApply;
  14. using EMIS.CommonLogic.CalendarManage;
  15. using EMIS.ViewModel;
  16. using System.Transactions;
  17. using EMIS.DataLogic.Common.Students;
  18. using EMIS.ViewModel.Cache;
  19. using System.Linq.Expressions;
  20. using Bowin.Common.Linq;
  21. using EMIS.DataLogic.ScoreManage;
  22. using EMIS.ViewModel.FeeManage;
  23. using EMIS.Utility.FormValidate;
  24. namespace EMIS.CommonLogic.Students
  25. {
  26. public class ExamineApplyServices : BaseServices, IExamineApplyServices
  27. {
  28. public Lazy<ISchoolYearServices> SchoolYearServices { get; set; }
  29. public IUserServices userServices { get; set; }
  30. public ExamineApplyDAL ExamineApplyDAL { get; set; }
  31. public ExaminationTypeDAL ExaminationTypeDAL { get; set; }
  32. public StudentRecordDAL studentRecordDAL { get; set; }
  33. public ExaminationRegistrationRepository RegistrationRepository { get; set; }
  34. //public SubjectCountLimitDAL SubjectCountLimitDAL { get; set; }
  35. //public OpenControlDAL OpenControlDAL { get; set; }
  36. public GrademajorRepository gradeRepository { get; set; }
  37. public StudentsDAL StudentsDAL { get; set; }
  38. public ExaminationSubjectDAL ExaminationSubjectDAL { get; set; }
  39. public ResitDAL ResitDAL { get; set; }
  40. //public LevelScoreDAL levelScoreDAL { get; set; }
  41. //public LevelSettingDAL levelSettingDAL { get; set; }
  42. //public ExaminationSubjectCollegeControlDAL examinationSubjectCollegeControlDAL { get; set; }
  43. public IGridResultSet<ExaminationApplyView> GetExaminationSubjectList(Guid UserID)
  44. {
  45. Expression<Func<EX_ExaminationBatch, bool>> batchExp = (x => true);
  46. Expression<Func<EX_ExaminationProject, bool>> projectExp = (x => true);
  47. Expression<Func<ER_ExaminationScore, bool>> scoreExp = (x => true);
  48. Expression<Func<CF_Facultymajor, bool>> facutyExp = (x => true);
  49. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  50. Expression<Func<CF_Student, bool>> studentExp = (x => true);
  51. scoreExp = scoreExp.And(x => x.UserID == UserID);
  52. var resitquery = ResitDAL.GetResitViewQueryable(batchExp, projectExp, scoreExp, facutyExp, gradeExp, studentExp).ToList();
  53. var examinationScoreList = ResitDAL.ExaminationScoreRepository.GetList(x => x.UserID == UserID, (x => x.EX_ExaminationBatchProject));
  54. Dictionary<Guid?, string> ProjectFeeIDAndFeeType = new Dictionary<Guid?, string>();
  55. var query = ExamineApplyDAL.GetExaminationSubjectList(UserID).ToList();
  56. var ExaminationProjectFeeIDList = query.Select(x => x.ExaminationProjectFeeID).ToList();
  57. var projectIDList = query.Select(x => x.ExaminationProjectID).ToList();
  58. var examinationProjectSubjectList = ExaminationSubjectDAL.examinationProjectSubjectRepository.Entities.Where(x => projectIDList.Contains(x.ExaminationProjectID)).ToList();
  59. //Dictionary<int?, int?> canResitCountDic = new Dictionary<int?, int?>();
  60. List<int?> cannotResitSubject = new List<int?>();
  61. List<Guid?> cannotResitProject = new List<Guid?>();
  62. examinationProjectSubjectList.ForEach(x =>
  63. {
  64. if (resitquery.Where(y => y.ExaminationProjectID == x.ExaminationProjectID && y.ExaminationSubjectID == x.ExaminationSubjectID).Count() > x.ResitCount)
  65. {
  66. cannotResitSubject.Add(x.ExaminationSubjectID);
  67. cannotResitProject.Add(x.ExaminationProjectID);
  68. }
  69. });
  70. //examinationProjectSubjectList.GroupBy(x => new { x.ExaminationSubjectID, x.ExaminationProjectID }).ToList().ForEach(x =>
  71. //{
  72. // if (resitquery.Where(y => y.ExaminationSubjectID == x.Key.ExaminationSubjectID && y.ExaminationProjectID == x.Key.ExaminationProjectID).Count() >= x.Count())
  73. // {
  74. // cannotResitProject.Add(x.Key.ExaminationProjectID);
  75. // }
  76. //});
  77. var FeeTypeByProjectFeeViewList = ExamineApplyDAL.GetFeeTypeByProjectFeeView(x => ExaminationProjectFeeIDList.Contains(x.ExaminationProjectFeeID)).ToList();
  78. var FeeType = from a in FeeTypeByProjectFeeViewList.Where(x => x.IsResit == false || (!cannotResitProject.Contains(x.ExaminationProjectID) && x.IsResit == true && resitquery.Where(y => y.ExaminationProjectID == x.ExaminationProjectID).Count() > 0 && examinationScoreList.Where(z => z.EX_ExaminationBatchProject.ExaminationProjectID == x.ExaminationProjectID).Count() > 0 && examinationScoreList.Where(z => z.EX_ExaminationBatchProject.ExaminationProjectID == x.ExaminationProjectID).Max(z => z.Expire) > DateTime.Now))
  79. group a by a.ExaminationProjectFeeID
  80. into ga
  81. select new
  82. {
  83. ExaminationProjectFeeID = ga.Key,
  84. FeeTypeStr = String.Join(";\r\n", ga.Select(x => x.FeeTypeName).ToArray()),
  85. };
  86. foreach (var a in FeeType.ToList())
  87. {
  88. ProjectFeeIDAndFeeType.Add(a.ExaminationProjectFeeID, a.FeeTypeStr);
  89. }
  90. query.ForEach(x => {
  91. foreach (var a in ProjectFeeIDAndFeeType)
  92. {
  93. if (x.ExaminationProjectFeeID == a.Key)
  94. {
  95. x.FeeTypeListStr = a.Value;
  96. }
  97. }
  98. });
  99. //var examinationProjectFeeTypeList = ExaminationSubjectDAL.examinationProjectFeeTypeRepository.GetList(x => ExaminationProjectFeeIDList.Contains(x.ExaminationProjectFeeID) && x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  100. return query.Where(x => x.EndDate.Value.AddDays(1) >= DateTime.Now && x.StartDate <= DateTime.Now).OrderBy(x => x.EndDate).ThenBy(x => x.StartDate).ThenBy(x => x.ExaminationDate).AsQueryable<ExaminationApplyView>().ToGridResultSet();
  101. }
  102. public StudentListView GetRegisterViewByExaminationBatchProjectID(Guid? examinationBatchProjectID, Guid? userID)
  103. {
  104. Expression<Func<EX_ExaminationBatch, bool>> batchExp = (x => true);
  105. Expression<Func<EX_ExaminationProject, bool>> projectExp = (x => true);
  106. Expression<Func<ER_ExaminationScore, bool>> scoreExp = (x => true);
  107. Expression<Func<CF_Facultymajor, bool>> facutyExp = (x => true);
  108. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  109. Expression<Func<CF_Student, bool>> studentExp = (x => true);
  110. var registView = StudentsDAL.GetRegustViewQueryable(x => x.UserID == userID).FirstOrDefault();
  111. var query = ExamineApplyDAL.GetRegisterViewByExaminationBatchProjectID(examinationBatchProjectID, userID);
  112. scoreExp = scoreExp.And(x => x.UserID == userID);
  113. scoreExp = scoreExp.And(x => x.EX_ExaminationBatchProject.ExaminationProjectID == query.ExaminationProjectID);
  114. //获取要报名的项目是否有补考记录
  115. var resitquery = ResitDAL.GetResitViewQueryable(batchExp, projectExp, scoreExp, facutyExp, gradeExp, studentExp).ToList();
  116. var examinationProjectSubjectList = ExaminationSubjectDAL.examinationProjectSubjectRepository.Entities.Where(x => x.ExaminationProjectID == query.ExaminationProjectID).ToList();
  117. var examinationScore = ResitDAL.ExaminationScoreRepository.Entities.Where(x => x.EX_ExaminationBatchProject.ExaminationProjectID == query.ExaminationProjectID).OrderByDescending(x => x.Expire).FirstOrDefault();
  118. //Dictionary<int?, int?> canResitCountDic = new Dictionary<int?, int?>();
  119. List<int?> cannotResitSubject = new List<int?>();
  120. examinationProjectSubjectList.ForEach(x =>
  121. {
  122. if (x.ResitCount != null && resitquery.Where(y => y.ExaminationSubjectID == x.ExaminationSubjectID).Count() > x.ResitCount)
  123. {
  124. cannotResitSubject.Add(x.ExaminationSubjectID);
  125. }
  126. });
  127. //examinationProjectSubjectList.GroupBy(x => x.ExaminationSubjectID).ToList().ForEach(x =>
  128. //{
  129. // if (resitquery.Where(y => y.ExaminationSubjectID == x.Key).Count() >= x.Count())
  130. // {
  131. // cannotResitSubject.Add(x.Key);
  132. // }
  133. //});
  134. var examinationProjectFeeID = query.ExaminationProjectFeeID;
  135. var examinationProjectFeeTypeList = ExaminationSubjectDAL.examinationProjectFeeTypeRepository.GetList(x => x.ExaminationProjectFeeID == examinationProjectFeeID && x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  136. //.Where(x => x.IsResit == false || (resitquery.Where(y => y.Expire >= DateTime.Now).Count() > 0 && x.IsResit == true))
  137. .ToList();
  138. //List<int?> feeTypeIDList = examinationProjectFeeTypeList.Select(x => x.FeeTypeID).Distinct().ToList();
  139. Dictionary<string, string> feeTypeDic = new Dictionary<string, string>();
  140. //如果缴费项目是补考,并且存在一个考试科目补考次数已经达到或者超过限制的次数,则不能报名补考的缴费项
  141. //如果没有对应的补考成绩,不能报名缴费项目是补考的
  142. foreach (var feeType in examinationProjectFeeTypeList.Where(x => x.IsResit == false || (x.IsResit == true && cannotResitSubject.Count() == 0 && resitquery.Count() > 0 && examinationScore != null && examinationScore.Expire > DateTime.Now)).OrderBy(x => x.FeeTypeID))
  143. {
  144. string feeTypeName = IdNameExt.GetDictionaryItem(DictionaryItem.EX_ExaminationProjectFeeType.ToString())
  145. .Where(x => x.Value == feeType.FeeTypeID)
  146. .Select(x => x.Name).FirstOrDefault();
  147. string feeTypeValue = feeTypeName + "(" + feeType.Fee.ToString() + ")";
  148. feeTypeDic.Add(feeType.FeeTypeID.ToString(), feeTypeValue);
  149. }
  150. query.FeeTypeList = feeTypeDic;
  151. query.RegistView = registView;
  152. query.CertificatesType = registView.CertificatesType;
  153. return query;
  154. }
  155. public StudentListView StudentRegister(StudentListView studentListView, Guid? userID)
  156. {
  157. try
  158. {
  159. Expression<Func<EX_ExaminationBatch, bool>> batchExp = (x => true);
  160. Expression<Func<EX_ExaminationProject, bool>> projectExp = (x => true);
  161. Expression<Func<ER_ExaminationScore, bool>> scoreExp = (x => true);
  162. Expression<Func<CF_Facultymajor, bool>> facutyExp = (x => true);
  163. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  164. Expression<Func<CF_Student, bool>> studentExp = (x => true);
  165. var student = StudentsDAL.GetStudentQueryable(x => x.UserID == userID).FirstOrDefault();
  166. var currentSchoolyear = ExamineApplyDAL.schoolyearRepository.Entities.Where(x => x.IsCurrent == true).FirstOrDefault();
  167. var studentGra = StudentsDAL.GrademajorRepository.Entities.Where(x => x.GrademajorID == student.GradeMajorID).FirstOrDefault();
  168. var graSchoolYear = ExamineApplyDAL.schoolyearRepository.Entities.Where(x => x.SchoolcodeID == studentGra.SchoolcodeID && x.Years == studentGra.SchoolyearID).FirstOrDefault();
  169. int? studentSchoolyearNumID = null;//如果是社会人员,无法判断是第几学年
  170. if (graSchoolYear != null) {
  171. studentSchoolyearNumID = ((currentSchoolyear.Value - graSchoolYear.Value - (currentSchoolyear.SchoolcodeID == studentGra.SchoolcodeID ? 0 : 1)) / 2 + 1);
  172. }
  173. //是否有收费标准对应收费项的配置
  174. var ExaminationProjectFeeType = ExaminationSubjectDAL.examinationProjectFeeTypeRepository.GetSingle(x => x.ExaminationProjectFeeID == studentListView.ExaminationProjectFeeID && x.FeeTypeID == studentListView.FeeTypeID);
  175. if (ExaminationProjectFeeType == null)
  176. {
  177. throw new Exception("找不到收费标准对应的收费项,请先设置。");
  178. }
  179. var examinationBatchProject = ExamineApplyDAL.examinationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchID == studentListView.ExaminationBatchID && x.ExaminationProjectID == studentListView.ExaminationProjectID).FirstOrDefault();
  180. var examinationProjectCountLimitControlList = ExamineApplyDAL.examinationProjectCountLimitRepository.Entities.ToList();
  181. //获取所有已报名的名单(不包含已退费)
  182. var dbstudentListView = ExaminationSubjectDAL.GetStudentListView(x => x.RecordStatus != (int)EX_ExaminationRegistrationStatus.Refunded, x => true, x => true, x => true);
  183. var registerCount = dbstudentListView.Where(y => y.ExaminationBatchProjectID == examinationBatchProject.ExaminationBatchProjectID).Count();
  184. //&& y.ExaminationProjectFeeTypeID == ExaminationProjectFeeType.ExaminationProjectFeeTypeID
  185. //项目报名人数限制
  186. if (examinationBatchProject != null && registerCount >= examinationBatchProject.MaxRegistCount)
  187. {
  188. throw new Exception("该项目报名人数已达上限。");
  189. }
  190. //考试类型控制(年级专业对应的考试类型报名门数限制)
  191. var myRegisterCount = dbstudentListView.Where(x => x.UserID == userID && x.ExaminationTypeID == studentListView.ExaminationTypeID).Count();
  192. EX_ExaminationProjectCountLimit examinationProjectCountLimitControl = null;
  193. if(studentSchoolyearNumID != null)//如果不是校内学生,没有学年则无需判断
  194. {
  195. examinationProjectCountLimitControl = examinationProjectCountLimitControlList.Where(x => x.ExaminationTypeID == studentListView.ExaminationTypeID && (x.StandardID == student.StandardID || x.StandardID == null) && (x.SchoolyearNumID == studentSchoolyearNumID || x.SchoolyearNumID == null)).FirstOrDefault();
  196. }
  197. if (examinationProjectCountLimitControl != null && myRegisterCount >= examinationProjectCountLimitControl.SubjectCountLimit)
  198. {
  199. throw new Exception("该考试类型报考门数已达上限。");
  200. }
  201. //List<EX_ExaminationRegistration> RegistrationList = new List<EX_ExaminationRegistration>();
  202. //var ExaminationBatchProject = ExaminationSubjectDAL.examinationBatchProjectRepository.GetList(x => x.ExaminationProjectID == studentListView.ExaminationProjectID && x.ExaminationBatchID == studentListView.ExaminationBatchID).FirstOrDefault();
  203. //是否已报名
  204. var dbstudentRegistration = ExaminationSubjectDAL.examinationRegistrationRepository.GetList(x => x.ExaminationProjectFeeTypeID == ExaminationProjectFeeType.ExaminationProjectFeeTypeID && x.ExaminationBatchProjectID == examinationBatchProject.ExaminationBatchProjectID && x.UserID == userID && x.RecordStatus != (int)EX_ExaminationRegistrationStatus.Refunded).FirstOrDefault();
  205. if (dbstudentRegistration != null)
  206. {
  207. throw new Exception("该项目已报名。");
  208. }
  209. //报考限定通过项目
  210. var ExaminationProject = ExamineApplyDAL.examinationProjectRepository.GetSingle(x => x.ExaminationProjectID == studentListView.ExaminationProjectID);
  211. if (ExaminationProject.PreposeProjectID != null)
  212. {
  213. var PreposeProject = ExamineApplyDAL.examinationProjectRepository.GetSingle(x => x.ExaminationProjectID == ExaminationProject.PreposeProjectID);
  214. var IsPassedList = ExamineApplyDAL.GetPreposeProjectIsPass(ExaminationProject.PreposeProjectID, userID);
  215. if (!IsPassedList.Contains(true) || IsPassedList.Count == 0 || IsPassedList == null)
  216. {
  217. throw new Exception("该项目报名需要先通过" + PreposeProject.Name + "。");
  218. }
  219. }
  220. //如果报名的收费项是补考的收费项,那么判断报名的项目对应的科目是否有设置补考次数,有则做限制,是否已有补考的成绩,有才能进行报名
  221. if (ExaminationProjectFeeType.IsResit.Value)
  222. {
  223. scoreExp = scoreExp.And(x => x.UserID == userID);
  224. scoreExp = scoreExp.And(x => x.EX_ExaminationBatchProject.ExaminationProjectID == studentListView.ExaminationProjectID);
  225. var resitquery = ResitDAL.GetResitViewQueryable(batchExp, projectExp, scoreExp, facutyExp, gradeExp, studentExp).ToList();
  226. var examinationProjectSubjectList = ExaminationSubjectDAL.examinationProjectSubjectRepository.Entities.Where(x => x.ExaminationProjectID == studentListView.ExaminationProjectID).ToList();
  227. List<int?> cannotResitSubject = new List<int?>();
  228. examinationProjectSubjectList.ForEach(x =>
  229. {
  230. if (x.ResitCount != null && resitquery.Where(y => y.ExaminationSubjectID == x.ExaminationSubjectID).Count() > x.ResitCount)
  231. {
  232. cannotResitSubject.Add(x.ExaminationSubjectID);
  233. }
  234. });
  235. if (resitquery.Count() == 0 || cannotResitSubject.Count() > 0)
  236. {
  237. throw new Exception("没有补考成绩或者超过补考次数,无法报名补考收费项");
  238. }
  239. //ExaminationProjectFeeType.
  240. }
  241. EX_ExaminationRegistration examinationRegistration = new EX_ExaminationRegistration();
  242. //确认个人信息
  243. using (TransactionScope ts = new TransactionScope())
  244. {
  245. if (studentListView.RegistView != null)
  246. {
  247. studentListView.RegistView.UserID = userID;
  248. studentListView.RegistView.CertificatesType = studentListView.CertificatesType;
  249. userServices.StudentRegist(studentListView.RegistView);
  250. }
  251. examinationRegistration.ExaminationBatchProjectID = examinationBatchProject.ExaminationBatchProjectID;
  252. examinationRegistration.ExaminationProjectFeeTypeID = ExaminationProjectFeeType.ExaminationProjectFeeTypeID;
  253. examinationRegistration.ExaminationRegistrationConfirmID = studentListView.ExaminationRegistrationConfirmID;
  254. //examinationRegistration.SchoolyearID = studentListView.SchoolyearID;
  255. examinationRegistration.Fee = ExaminationProjectFeeType.Fee;
  256. //examinationRegistration.Remark = studentListView.Remark;
  257. examinationRegistration.ExaminationRegistrationID = Guid.NewGuid();
  258. examinationRegistration.UserID = userID;
  259. examinationRegistration.RecordStatus = (int)SYS_STATUS.USABLE;
  260. examinationRegistration.CreateUserID = userID;
  261. examinationRegistration.CreateTime = DateTime.Now;
  262. examinationRegistration.ModifyUserID = userID;
  263. examinationRegistration.ModifyTime = DateTime.Now;
  264. //this.SetNewStatus(examinationRegistration);
  265. //RegistrationList.Add(examinationRegistration);
  266. UnitOfWork.Add(examinationRegistration);
  267. UnitOfWork.Commit();
  268. ts.Complete();
  269. }
  270. var register = ExaminationSubjectDAL.GetStudentListView(x => x.ExaminationRegistrationID == examinationRegistration.ExaminationRegistrationID, x => true, x => true, x => true).FirstOrDefault();
  271. var isOnlinePayControl = false;
  272. var examinationBatchProjectPersonControl = ExaminationSubjectDAL.examinationBatchProjectPersonControlRepository.Entities.Where(x => x.UserID == userID && x.ExaminationBatchProjectID == register.ExaminationBatchProjectID).FirstOrDefault();
  273. var examinationBatchProjectControlList = ExaminationSubjectDAL.examinationBatchProjectControlRepository.Entities.Where(x => x.ExaminationBatchProjectID == register.ExaminationBatchProjectID &&
  274. x.ExaminationProjectFeeID == register.ExaminationProjectFeeID && (x.SchoolyearID == student.Years || x.SchoolyearID == null) && (x.StandardID == student.StandardID || x.StandardID == null)
  275. && (x.CollegeID == student.CollegeID || x.CollegeID == null)).ToList();
  276. Dictionary<Guid?, int?> dicControl = new Dictionary<Guid?, int?>();
  277. if (examinationBatchProjectPersonControl != null)
  278. {
  279. isOnlinePayControl = examinationBatchProjectPersonControl.IsOnlinePay == null ? false : examinationBatchProjectPersonControl.IsOnlinePay.Value;
  280. }
  281. else if (examinationBatchProjectControlList != null)
  282. {
  283. if (examinationBatchProjectControlList.Count() > 1)
  284. {
  285. foreach(var projectControl in examinationBatchProjectControlList)
  286. {
  287. int? count = 0;
  288. if (projectControl.CollegeID != null)
  289. {
  290. count++;
  291. }
  292. if (projectControl.SchoolyearID != null)
  293. {
  294. count++;
  295. }
  296. if (projectControl.StandardID != null)
  297. {
  298. count++;
  299. }
  300. dicControl.Add(projectControl.ExaminationBatchProjectControlID, count);
  301. }
  302. var control = examinationBatchProjectControlList.Where(x => x.ExaminationBatchProjectControlID == dicControl.OrderByDescending(y => y.Value).FirstOrDefault().Key).FirstOrDefault();
  303. isOnlinePayControl = control.IsOnlinePay == null ? false : control.IsOnlinePay.Value;
  304. }
  305. else {
  306. isOnlinePayControl = examinationBatchProjectControlList.FirstOrDefault().IsOnlinePay == null ? false : examinationBatchProjectControlList.FirstOrDefault().IsOnlinePay.Value;
  307. }
  308. }
  309. register.IsOnlinePay = isOnlinePayControl;
  310. return register;
  311. }
  312. catch (Exception)
  313. {
  314. throw;
  315. }
  316. }
  317. /// <summary>
  318. /// 待缴费的数据取消报名需要进行判断
  319. /// </summary>
  320. /// <param name="examinationRegistrationIDList"></param>
  321. public void CheckCanCancelOnline(List<Guid> examinationRegistrationIDList)
  322. {
  323. try
  324. {
  325. //var examinationProjectCountLimitControlList = ExamineApplyDAL.examinationProjectCountLimitRepository.Entities.ToList();
  326. //var studentListView = ExaminationSubjectDAL.GetStudentListView(x => true, x => true, x => true, x => true);
  327. var personalControlList = ExamineApplyDAL.examinationBatchProjectPersonControlRepository.Entities.ToList();
  328. var dbExaminationRegistrationList = ExaminationSubjectDAL.GetStudentListView(x => examinationRegistrationIDList.Contains(x.ExaminationRegistrationID), x => true, x => true, x => true).ToList();
  329. dbExaminationRegistrationList.ForEach(x =>
  330. {
  331. var personalControl = personalControlList.Where(y => y.UserID == x.UserID && y.ExaminationBatchProjectID == x.ExaminationBatchProjectID && y.ExaminationProjectFeeID == x.ExaminationProjectFeeID).FirstOrDefault();
  332. //var registerCount = studentListView.Where(y => y.ExaminationBatchProjectID == x.ExaminationBatchProjectID && y.ExaminationProjectFeeTypeID == x.ExaminationProjectFeeTypeID).Count();
  333. //var examinationProjectCountLimitControl = examinationProjectCountLimitControlList.Where(y => y.ExaminationTypeID == x.ExaminationTypeID && y.StandardID == x.StandardID && y.SchoolyearNumID == x.SchoolyearNumID).FirstOrDefault();
  334. //if(examinationProjectCountLimitControl.SubjectCountLimit)
  335. //if (x.RecordStatus != (int)EX_ExaminationRegistrationStatus.ForPay && x.RecordStatus != (int)EX_ExaminationRegistrationStatus.Paid)
  336. //{
  337. // throw new Exception("只有待缴费或者已缴费的报名项目才能取消报名。");
  338. //}
  339. if (x.ExaminationRegistrationConfirmID != null)
  340. {
  341. throw new Exception("待缴费的数据,只有未打包确认才能取消报名。");
  342. }
  343. if (personalControl != null)
  344. {
  345. if (personalControl.EndDate.Value.AddDays(1) < DateTime.Now)
  346. {
  347. throw new Exception("待缴费的数据,只有在报名时间范围内才能取消报名。");
  348. }
  349. }
  350. else if (x.EndDate.Value.AddDays(1) < DateTime.Now)
  351. {
  352. throw new Exception("待缴费的数据,只有在报名时间范围内才能取消报名。");
  353. }
  354. });
  355. //var wechatPayList = ExaminationSubjectDAL.wechatPayListRepository.Entities.Where(x => examinationRegistrationIDList.Contains(x.ExaminationRegistrationID.Value)).ToList();
  356. //foreach (var wechatpay in wechatPayList)
  357. //{
  358. // var examinationRegistration = dbExaminationRegistrationList.FirstOrDefault(x => x.ExaminationRegistrationID == wechatpay.ExaminationRegistrationID);
  359. // WechatHelper
  360. //}
  361. //UnitOfWork.Delete<CF_WechatPayList>(x => examinationRegistrationIDList.Contains(x.ExaminationRegistrationID.Value));
  362. //UnitOfWork.Delete<EX_ExaminationRegistration>(x => examinationRegistrationIDList.Contains(x.ExaminationRegistrationID));
  363. }
  364. catch (Exception)
  365. {
  366. throw;
  367. }
  368. }
  369. public void ChangeAndDelete(List<Guid> changeID, List<Guid> deleteID)
  370. {
  371. try
  372. {
  373. var changeList = ExaminationSubjectDAL.examinationRegistrationRepository.Entities.Where(x => changeID.Contains(x.ExaminationRegistrationID)).ToList();
  374. changeList.ForEach(x =>
  375. {
  376. x.RecordStatus = (int)EX_ExaminationRegistrationStatus.OnRefund;
  377. });
  378. this.UnitOfWork.Commit();
  379. UnitOfWork.Delete<CF_WechatPayList>(x => deleteID.Contains(x.ExaminationRegistrationID.Value));
  380. UnitOfWork.Delete<EX_ExaminationRegistration>(x => deleteID.Contains(x.ExaminationRegistrationID));
  381. }
  382. catch (Exception)
  383. {
  384. throw;
  385. }
  386. }
  387. public List<CF_WechatPayList> GetWechatPayListByExaminationRegistrationID(List<Guid> examinationRegistrationIDList)
  388. {
  389. return ExaminationSubjectDAL.wechatPayListRepository.Entities.Where(x => examinationRegistrationIDList.Contains(x.ExaminationRegistrationID.Value)).ToList();
  390. }
  391. public List<ExaminationRegistrationPayView> GetExaminationRegistrationPayViewByRegistrationID(List<Guid> examinationRegistrationIDList)
  392. {
  393. return ExaminationSubjectDAL.GetExaminationRegistrationPayViewQueryable(x => examinationRegistrationIDList.Contains(x.ExaminationRegistrationID)).ToList();
  394. }
  395. public ExaminationRegistrationPayView GetExaminationRegistrationPayViewByRegistrationID(Guid examinationRegistrationID)
  396. {
  397. return ExaminationSubjectDAL.GetExaminationRegistrationPayViewQueryable(x => x.ExaminationRegistrationID == examinationRegistrationID).FirstOrDefault();
  398. }
  399. public IGridResultSet<ExaminationRegisView> GetExaminationRegisterList(Guid UserID)
  400. {
  401. var result = ExamineApplyDAL.GetExaminationRegisterList(UserID).OrderBy(x => x.EndDate).ThenBy(x => x.StartDate).ThenBy(x => x.ExaminationDate).AsQueryable<ExaminationRegisView>().ToGridResultSet();
  402. return result;
  403. }
  404. public void CheckCanPay(Guid examinationRegistrationID)
  405. {
  406. var registration = ExamineApplyDAL.examinationRegistrationRepository.GetSingle(x => x.ExaminationRegistrationID == examinationRegistrationID, (x => x.EX_ExaminationProjectFeeType),
  407. (x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor));
  408. if (registration.RecordStatus != (int)EX_ExaminationRegistrationStatus.ForPay && registration.RecordStatus != (int)EX_ExaminationRegistrationStatus.Paying)
  409. {
  410. throw new Exception("当前报名的考试并非待支付状态,不能支付。");
  411. }
  412. if (registration.ExaminationRegistrationConfirmID.HasValue)
  413. {
  414. throw new Exception("当前报名的考试已产生确认单,不能在线支付,请线下进行支付。");
  415. }
  416. if (registration.EX_ExaminationProjectFeeType == null)
  417. {
  418. throw new Exception("数据错误,请联系系统管理员。");
  419. }
  420. var personalControl = ExamineApplyDAL.examinationBatchProjectPersonControlRepository.GetSingle(x => x.ExaminationBatchProjectID == registration.ExaminationBatchProjectID
  421. && x.UserID == registration.UserID && x.ExaminationProjectFeeID == registration.EX_ExaminationProjectFeeType.ExaminationProjectFeeID);
  422. var batchControl = ExamineApplyDAL.examinationBatchProjectControlRepository.GetSingle(x => x.ExaminationBatchProjectID == registration.ExaminationBatchProjectID
  423. && x.ExaminationProjectFeeID == registration.EX_ExaminationProjectFeeType.ExaminationProjectFeeID && x.SchoolyearID == registration.CF_Student.CF_Classmajor.CF_Grademajor.SchoolyearID
  424. && x.StandardID == registration.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID
  425. && x.CollegeID == registration.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID);
  426. var allControl = ExamineApplyDAL.examinationBatchProjectControlRepository.GetSingle(x => x.ExaminationBatchProjectID == registration.ExaminationBatchProjectID
  427. && x.ExaminationProjectFeeID == registration.EX_ExaminationProjectFeeType.ExaminationProjectFeeID && x.SchoolyearID == null
  428. && x.StandardID == null && x.CollegeID == null);
  429. var batchProject = ExamineApplyDAL.examinationBatchProjectRepository.GetSingle(x => x.ExaminationBatchProjectID == registration.ExaminationBatchProjectID);
  430. if (personalControl != null)
  431. {
  432. if (personalControl.IsOnlinePay != true)
  433. {
  434. throw new Exception("该次报名不支持线上缴费,请线下进行支付。");
  435. }
  436. if (personalControl.StartDate > DateTime.Now || personalControl.EndDate.Value.AddDays(1) <= DateTime.Now)
  437. {
  438. throw new Exception("当前时间不在该次报名缴费时间范围,无法进行缴费。");
  439. }
  440. }
  441. else
  442. {
  443. if (batchControl != null)
  444. {
  445. if (batchControl.IsOnlinePay != true)
  446. {
  447. throw new Exception("该次报名不支持线上缴费,请线下进行支付。");
  448. }
  449. if (batchProject.StartDate > DateTime.Now || batchProject.EndDate.Value.AddDays(1) <= DateTime.Now)
  450. {
  451. throw new Exception("当前时间不在该次报名缴费时间范围,无法进行缴费。");
  452. }
  453. }
  454. else
  455. {
  456. if (allControl != null)
  457. {
  458. if (allControl.IsOnlinePay != true)
  459. {
  460. throw new Exception("该次报名不支持线上缴费,请线下进行支付。");
  461. }
  462. if (batchProject.StartDate > DateTime.Now || batchProject.EndDate.Value.AddDays(1) <= DateTime.Now)
  463. {
  464. throw new Exception("当前时间不在该次报名缴费时间范围,无法进行缴费。");
  465. }
  466. }
  467. }
  468. }
  469. }
  470. /// <summary>
  471. /// 获取考试类型下拉(根据学年学期)
  472. /// </summary>
  473. /// <param name="configuretView"></param>
  474. /// <param name="schoolyearID"></param>
  475. /// <param name="pageIndex"></param>
  476. /// <param name="pageSize"></param>
  477. /// <returns></returns>
  478. public IGridResultSet<ExaminationTypeView> GetExaminationTypeViewForComboGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? examinationBatchID, int pageIndex, int pageSize)
  479. {
  480. Expression<Func<EX_ExaminationBatchProject, bool>> ebpexp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  481. if (schoolyearID.HasValue)
  482. {
  483. ebpexp = ebpexp.And(x => x.EX_ExaminationBatch.SchoolyearID == schoolyearID);
  484. }
  485. if (examinationBatchID.HasValue)
  486. {
  487. ebpexp = ebpexp.And(x => x.ExaminationBatchID == examinationBatchID);
  488. }
  489. var query = ExaminationTypeDAL.GetExaminationTypeViewBySchoolyearID(ebpexp);
  490. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  491. {
  492. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  493. }
  494. return query.Distinct().OrderBy(x => x.Name).ToGridResultSet<ExaminationTypeView>(pageIndex, pageSize);
  495. }
  496. public IGridResultSet<ExaminationTypeView> GetCanRegisterExaminationTypeView(Guid? userID)
  497. {
  498. var subjectList = this.GetExaminationSubjectList(userID.Value);
  499. var examinationTypeIDList = subjectList.rows.Select(x => x.ExaminationTypeID).ToList();
  500. Expression<Func<EX_ExaminationType, bool>> exp = x => true;
  501. exp = exp.And(x => examinationTypeIDList.Contains(x.ExaminationTypeID));
  502. var examinationTypeList = ExaminationTypeDAL.GetExaminationTypeView(exp);
  503. return examinationTypeList.ToGridResultSet<ExaminationTypeView>();
  504. }
  505. public bool CheckIsOnlinePay(Guid? examinationRegistrationID)
  506. {
  507. var isOnline = false;
  508. var examinationRegistration = ExamineApplyDAL.examinationRegistrationRepository.Entities.Where(x => x.ExaminationRegistrationID == examinationRegistrationID).FirstOrDefault();
  509. var projectControl = GetProjectControlByRegistration(examinationRegistrationID);
  510. var personControl = ExamineApplyDAL.examinationBatchProjectPersonControlRepository.Entities.Where(x => x.ExaminationBatchProjectID == examinationRegistration.ExaminationBatchProjectID && x.UserID == examinationRegistration.UserID).FirstOrDefault();
  511. if (projectControl.IsOnlinePay.Value || (personControl != null && personControl.IsOnlinePay.Value))
  512. {
  513. isOnline = true;
  514. }
  515. else
  516. {
  517. isOnline = false;
  518. }
  519. return isOnline;
  520. }
  521. public EX_ExaminationBatchProjectControl GetProjectControlByRegistration(Guid? examinationRegistrationID)
  522. {
  523. //var isOnlinePay = false;
  524. var examinationRegistration = ExamineApplyDAL.examinationRegistrationRepository.Entities.Where(x => x.ExaminationRegistrationID == examinationRegistrationID).FirstOrDefault();
  525. var student = StudentsDAL.GetStudentQueryable(x => x.UserID == examinationRegistration.UserID, x => true, x => true).FirstOrDefault();
  526. var projectControl = ExamineApplyDAL.examinationBatchProjectControlRepository.Entities
  527. .Where(x => x.ExaminationBatchProjectID == examinationRegistration.ExaminationBatchProjectID
  528. && x.ExaminationProjectFeeID == examinationRegistration.ExaminationProjectFeeTypeID && (x.CollegeID == null || x.CollegeID == student.CollegeID)
  529. && (x.StandardID == null || x.StandardID == student.StandardID) &&( x.SchoolyearID == null || x.SchoolyearID == student.Years))
  530. .FirstOrDefault();
  531. return projectControl;
  532. }
  533. public void RefundApply(RefundView refundView, List<Guid> examinationRegistrationIDs)
  534. {
  535. try
  536. {
  537. List<EX_ExaminationRegistration> examinationRegistrationList = ExamineApplyDAL.examinationRegistrationRepository.Entities.Where(x => examinationRegistrationIDs.Contains(x.ExaminationRegistrationID)).ToList();
  538. examinationRegistrationList.ForEach(x =>
  539. {
  540. x.RefundUserID = CustomPrincipal.Current == null ? x.UserID: CustomPrincipal.Current.UserID;
  541. x.RefundTime = DateTime.Now;
  542. x.BankName = refundView.BankName;
  543. x.CardNo = refundView.CardNo;
  544. x.RefundReason = refundView.RefundReason;
  545. x.RecordStatus = (int)EX_ExaminationRegistrationStatus.RefundApply;
  546. });
  547. UnitOfWork.BatchUpdate<EX_ExaminationRegistration>(examinationRegistrationList);
  548. }
  549. catch (Exception)
  550. {
  551. throw;
  552. }
  553. }
  554. public RefundView GetRefundViewByUserID(Guid? userID)
  555. {
  556. RefundView refundView = new RefundView();
  557. var stu = ExamineApplyDAL.StudentAccountRepository.Entities.Where(x => x.UserID == userID).FirstOrDefault();
  558. refundView.BankName = stu.BankName;
  559. refundView.CardNo = stu.CardNo;
  560. return refundView;
  561. }
  562. }
  563. }