StudentMinorRegistApplyServices.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq.Entity;
  6. using EMIS.ViewModel.MinorManage.MinorApply;
  7. using EMIS.ViewModel;
  8. using System.Linq.Expressions;
  9. using EMIS.Entities;
  10. using Bowin.Common.Linq;
  11. using EMIS.DataLogic.MinorManage.MinorApply;
  12. using EMIS.DataLogic.MinorManage.MinorSetting;
  13. using EMIS.CommonLogic.CalendarManage;
  14. using EMIS.Utility;
  15. using EMIS.ViewModel.MinorManage.MinorSetting;
  16. using System.Transactions;
  17. using EMIS.CommonLogic.SystemServices;
  18. using EMIS.ViewModel.MinorManage.MinorPlanManage;
  19. using EMIS.DataLogic.MinorManage.MinorPlanManage;
  20. namespace EMIS.CommonLogic.MinorManage.MinorApply
  21. {
  22. public class StudentMinorRegistApplyServices : BaseWorkflowServices<EM_StudentMinorRegist>, IStudentMinorRegistApplyServices
  23. {
  24. public StudentMinorRegistApplyDAL studentMinorRegistApplyDAL { get; set; }
  25. public MinorStandardSettingDAL minorStandardSettingDAL { get; set; }
  26. public MinorControlDAL minorControlDAL { get; set; }
  27. public ISchoolYearServices schoolYearServices { get; set; }
  28. public MinorConditionDAL minorConditionDAL { get; set; }
  29. public MinorPlanApplyDAL minorPlanApplyDAL { get; set; }
  30. public IGridResultSet<GrademinorView> GetGrademinorViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID, int? yearID, int? minorStandardID, int pageIndex, int pageSize)
  31. {
  32. var user = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  33. var applyStatusList = this.GetStatusViewList();
  34. var returnStatus = applyStatusList.Where(x => x.Description.Contains("BP")).FirstOrDefault().ID;
  35. var standardID = studentMinorRegistApplyDAL.GetStandardIDListByUserID(user.UserID);
  36. List<int?> minorStandardIDList = new List<int?>();
  37. if (standardID.HasValue)
  38. {
  39. var squery = minorStandardSettingDAL.GetMinorStandardSettingViewQueryable(x => x.StandardID == standardID);
  40. if (squery.Count() > 0)
  41. {
  42. minorStandardIDList = squery.Select(x => x.MinorStandardID).ToList();
  43. }
  44. }
  45. Expression<Func<CF_Grademinor, bool>> exp = x => true;
  46. //只显示已开放状态的辅修专业对应的信息
  47. //exp = exp.And(x => x.RecordStatus == (int)CF_GrademinorStatus.Opened);
  48. if (schoolyearID.HasValue)
  49. {
  50. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  51. }
  52. if (collegeID.HasValue)
  53. {
  54. exp = exp.And(x => x.CollegeID == collegeID);
  55. }
  56. if (yearID.HasValue)
  57. {
  58. exp = exp.And(x => x.YearID == yearID);
  59. }
  60. if (minorStandardID.HasValue)
  61. {
  62. exp = exp.And(x => x.StandardID == minorStandardID);
  63. }
  64. if (minorStandardIDList.Count <= 0)
  65. {
  66. exp = exp.And(x => x.StandardID == null);
  67. }
  68. else
  69. {
  70. exp = exp.And(x => minorStandardIDList.Contains(x.StandardID));
  71. }
  72. var query = studentMinorRegistApplyDAL.GetMinorClassViewQueryable(exp, user.UserID, returnStatus);
  73. //学生报名界面显示已报名的辅修信息,还有已开放的辅修信息
  74. query = query.Where(x => x.OpenStatus == (int)CF_GrademinorStatus.Opened || x.RecordStatus != null);
  75. //列表查询条件
  76. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  77. {
  78. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  79. }
  80. var schoolYear = schoolYearServices.GetSchoolYearIsCurrent(true);
  81. var control = studentMinorRegistApplyDAL.GetMinorControlViewByUserIDAndSchoolyear(user.UserID, schoolYear.SchoolyearID);
  82. var canSelect = true;
  83. var result = query.OrderByDescending(x => x.SchoolyearCode).ToGridResultSet(pageIndex, pageSize);
  84. if (control != null)
  85. {
  86. if (DateTime.Now < control.FirstOrDefault().StartDate || DateTime.Now > control.FirstOrDefault().EndDate)
  87. {
  88. result.rows.ForEach(x => x.CanSelect = false);
  89. }
  90. result.rows.ForEach(x => x.MinorControlID = control.FirstOrDefault().MinorControlID);
  91. result.rows.ForEach(x => x.StartDate = control.FirstOrDefault().StartDate);
  92. result.rows.ForEach(x => x.EndDate = control.FirstOrDefault().EndDate);
  93. }
  94. else{
  95. result.rows.ForEach(x => x.CanSelect = false);
  96. }
  97. if (query.Any(x => x.CanSelect == false))
  98. {
  99. result.rows.ForEach(x => x.CanSelect = false);
  100. }
  101. result.rows.ForEach(x => x.RecordStatusStr = x.RecordStatus != null ? applyStatusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name : "");
  102. result.rows.ForEach(x => x.CanSelect = x.OpenStatus != (int)CF_GrademinorStatus.Opened ? false : x.CanSelect);
  103. result.rows.ForEach(x => x.CanSelect = (x.OperateText == "已报满" || x.OperateText == "已报名") ? false : x.CanSelect);
  104. return result;
  105. }
  106. public void Apply(Guid GrademinorID)
  107. {
  108. try
  109. {
  110. //using (TransactionScope ts = new TransactionScope())
  111. //{
  112. Expression<Func<ER_MinorControl, bool>> exp = x => true;
  113. var user = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  114. var schoolYear = schoolYearServices.GetSchoolYearIsCurrent(true);
  115. //开放控制验证
  116. var control = studentMinorRegistApplyDAL.GetMinorControlViewByUserIDAndSchoolyear(user.UserID, schoolYear.SchoolyearID);
  117. if (control != null)
  118. {
  119. var con = control.FirstOrDefault();
  120. if (DateTime.Now < con.StartDate || DateTime.Now > con.EndDate)
  121. {
  122. throw new Exception("不在辅修报名开放时间内");
  123. }
  124. }
  125. //辅修专业验证
  126. var grademinor = studentMinorRegistApplyDAL.grademinorRepository.GetSingle(x => x.GrademinorID == GrademinorID);
  127. if (grademinor != null)
  128. {
  129. if (grademinor.RecordStatus != (int)CF_GrademinorStatus.Opened)
  130. {
  131. throw new Exception("该辅修专业不处于已开放状态,不能进行报名");
  132. }
  133. }
  134. //辅修条件验证
  135. Expression<Func<ER_MinorCondition, bool>> mcdexp = x => x.RecordStatus >= (int)SYS_STATUS.USABLE;
  136. var query = minorConditionDAL.GetMinorConditionViewQueryable(mcdexp);
  137. bool isPass = true;
  138. foreach (var minorCondition in query)
  139. {
  140. var retValue = ReflectorHelper.RunMethod(minorCondition.MethodFullName, user.UserID);
  141. if (!(bool)retValue)
  142. {
  143. //表示条件不通过
  144. isPass = false;
  145. //终止循环
  146. break;
  147. }
  148. }
  149. if (!isPass)
  150. {
  151. throw new Exception("辅修条件不通过");
  152. }
  153. //查询对应的工作流程环节状态信息View
  154. var approveStatusList = this.GetStatusViewList();
  155. if (approveStatusList == null || approveStatusList.Count() <= 0)
  156. {
  157. throw new Exception("工作流平台中,辅修报名流程未配置,请核查");
  158. }
  159. //查询工作流程开始环节状态
  160. var approveStartStatus = this.GetStartStatus();
  161. if (approveStartStatus == null)
  162. {
  163. throw new Exception("工作流平台中,辅修报名流程开始环节未配置,请核查");
  164. }
  165. var action = this.GetActionView();
  166. var actionID = action.Where(x => x.Pid == approveStartStatus).FirstOrDefault().ActionID;
  167. EM_StudentMinorRegist studentMinorRegist = new EM_StudentMinorRegist();
  168. studentMinorRegist.StudentMinorRegistID = Guid.NewGuid();
  169. studentMinorRegist.SchoolyearID = schoolYear.SchoolyearID;
  170. studentMinorRegist.GrademinorID = GrademinorID;
  171. studentMinorRegist.UserID = user.UserID;
  172. studentMinorRegist.RecordStatus = approveStartStatus;
  173. studentMinorRegist.CreateTime = DateTime.Now;
  174. studentMinorRegist.CreateUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID;
  175. studentMinorRegist.ModifyTime = DateTime.Now;
  176. studentMinorRegist.ModifyUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID;
  177. UnitOfWork.Add(studentMinorRegist);
  178. UnitOfWork.Commit();
  179. List<Guid> idList = new List<Guid>();
  180. idList.Add(studentMinorRegist.StudentMinorRegistID);
  181. this.StartUp(idList, user.UserID,"");
  182. // ts.Complete();
  183. //}
  184. }
  185. catch (Exception)
  186. {
  187. throw;
  188. }
  189. }
  190. public IGridResultSet<MinorPlanApplyView> existStandardAndMinorSpecialtyCourseViewGrid(Guid? grademinorID, int pageIndex, int pageSize)
  191. {
  192. var gradeMinorApplicationID = minorPlanApplyDAL.GrademinorRepository.GetSingle(x => x.GrademinorID == grademinorID).GrademinorApplicationID;
  193. Expression<Func<CF_GrademinorApplication, bool>> exp = (x => x.GradeMinorApplicationID == gradeMinorApplicationID);
  194. var query = minorPlanApplyDAL.existStandardAndMinorSpecialtyCourseView(exp);
  195. return this.GetQueryByDataRangeByCollege(query)
  196. .OrderBy(x => x.StarttermID).ThenBy(x => x.CourseCode)
  197. .ToGridResultSet<MinorPlanApplyView>(pageIndex, pageSize);
  198. }
  199. public string GetMinorApplyDateTime(Guid? schoolyearID)
  200. {
  201. var user = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  202. var minorcontrolquery = studentMinorRegistApplyDAL.GetMinorControlViewByUserIDAndSchoolyear(user.UserID, schoolyearID.Value);
  203. if (minorcontrolquery == null)
  204. {
  205. return "未开放";
  206. }
  207. else
  208. {
  209. var minorcontrol = studentMinorRegistApplyDAL.GetMinorControlViewByUserIDAndSchoolyear(user.UserID, schoolyearID.Value).FirstOrDefault();
  210. if (minorcontrol.StartDate > DateTime.Now)
  211. {
  212. return Convert.ToDateTime(minorcontrol.StartDate).ToString("yyyy-MM-dd hh:mm:ss")
  213. + " 至 " + Convert.ToDateTime(minorcontrol.EndDate).ToString("yyyy-MM-dd hh:mm:ss")
  214. + " (即将开始)";
  215. }
  216. else if (minorcontrol.EndDate < DateTime.Now)
  217. {
  218. return Convert.ToDateTime(minorcontrol.StartDate).ToString("yyyy-MM-dd hh:mm:ss")
  219. + " 至 " + Convert.ToDateTime(minorcontrol.EndDate).ToString("yyyy-MM-dd hh:mm:ss")
  220. + " (报名结束)";
  221. }
  222. else
  223. {
  224. return Convert.ToDateTime(minorcontrol.StartDate).ToString("yyyy-MM-dd hh:mm:ss")
  225. + " 至 " + Convert.ToDateTime(minorcontrol.EndDate).ToString("yyyy-MM-dd hh:mm:ss")
  226. + " (开始报名)";
  227. }
  228. }
  229. }
  230. }
  231. }