ExaminationExemptionServices.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using Bowin.Common.Linq;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.CommonLogic.SystemServices;
  9. using EMIS.Entities;
  10. using EMIS.DataLogic.ScoreManage;
  11. using EMIS.ViewModel;
  12. using EMIS.CommonLogic.CalendarManage;
  13. using EMIS.Utility.FormValidate;
  14. namespace EMIS.CommonLogic.ScoreManage
  15. {
  16. public class ExaminationExemptionServices : BaseWorkflowServices<ER_ExaminationExemption>, IExaminationExemptionServices
  17. {
  18. public ExaminationExemptionDAL ExaminationExemptionDAL { get; set; }
  19. public FinalExaminationDAL FinalExaminationDAL { get; set; }
  20. public Lazy<IScoreServices> ScoreServices { get; set; }
  21. public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.ScoreManage.ExaminationExemptionView> GetExaminationExemptionGridView(
  22. ViewModel.ConfiguretView conditions, Guid? schoolyearID, Guid? collegeID, int? year, int? standardID, Guid? classmajorID,
  23. int? examsCatagoryID, int? recordStatus,int? learningformID, int? education,string LearnSystem, int? pageIndex = null, int? pageSize = null)
  24. {
  25. var statusList = this.GetStatusViewList();
  26. Expression<Func<ER_ExaminationExemption, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  27. var startStatus = this.GetStartStatus();
  28. var userID = CustomPrincipal.Current.UserID;
  29. exp = exp.And(x => x.RecordStatus != startStatus || (x.RecordStatus == startStatus && x.CreateUserID == userID));
  30. if (schoolyearID.HasValue)
  31. {
  32. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  33. }
  34. if (collegeID.HasValue)
  35. {
  36. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
  37. }
  38. if (year.HasValue)
  39. {
  40. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == year);
  41. }
  42. if (standardID.HasValue)
  43. {
  44. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
  45. }
  46. if (classmajorID.HasValue)
  47. {
  48. exp = exp.And(x => x.CF_Student.ClassmajorID == classmajorID);
  49. }
  50. if (examsCatagoryID.HasValue)
  51. {
  52. exp = exp.And(x => x.ExamsCategoryID == examsCatagoryID);
  53. }
  54. if (recordStatus.HasValue)
  55. {
  56. exp = exp.And(x => x.RecordStatus == recordStatus);
  57. }
  58. if (learningformID.HasValue)
  59. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID);
  60. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  61. {
  62. var LearnSystems = Convert.ToDecimal(LearnSystem);
  63. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems);
  64. }
  65. if (education.HasValue)
  66. {
  67. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == education.Value);
  68. }
  69. var query = this.ExaminationExemptionDAL.GetExaminationExemptionViewQueryable(exp);
  70. if (!string.IsNullOrEmpty(conditions.ConditionValue))
  71. {
  72. query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue);
  73. }
  74. query = this.GetQueryByDataRangeByCollege(query);
  75. var result = query.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Year).ThenBy(x => x.StandardID).ToGridResultSet(pageIndex, pageSize);
  76. result.rows.ForEach(x =>
  77. {
  78. var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus);
  79. if (currentStatus != null)
  80. {
  81. x.RecordStatusName = currentStatus.Name;
  82. }
  83. else
  84. {
  85. x.RecordStatusName = "";
  86. }
  87. });
  88. return result;
  89. }
  90. public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.ScoreManage.ExaminationExemptionView> GetExaminationExemptionStudentGridView(
  91. ViewModel.ConfiguretView conditions, Guid? userID = null, int? pageIndex = null, int? pageSize = null)
  92. {
  93. Expression<Func<ER_ExaminationExemption, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  94. var statusList = this.GetStatusViewList();
  95. if (userID.HasValue)
  96. {
  97. exp = exp.And(x => x.UserID == userID);
  98. }
  99. var query = this.ExaminationExemptionDAL.GetExaminationExemptionViewQueryable(exp);
  100. if (!string.IsNullOrEmpty(conditions.ConditionValue))
  101. {
  102. query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue);
  103. }
  104. var result = query.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Year).ThenBy(x => x.StandardID).ToGridResultSet(pageIndex, pageSize);
  105. result.rows.ForEach(x =>
  106. {
  107. var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus);
  108. if (currentStatus != null)
  109. {
  110. x.RecordStatusName = currentStatus.Name;
  111. }
  112. else
  113. {
  114. x.RecordStatusName = "";
  115. }
  116. });
  117. return result;
  118. }
  119. public List<ViewModel.ScoreManage.ExaminationExemptionView> GetExaminationExemptionViewList(ViewModel.ConfiguretView conditions,
  120. Guid? schoolyearID, Guid? collegeID, int? year, int? standardID, Guid? classmajorID, int? examsCatagoryID, int? recordStatus,int? learningformID, int? education,string LearnSystem)
  121. {
  122. var statusList = this.GetStatusViewList();
  123. Expression<Func<ER_ExaminationExemption, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  124. var startStatus = this.GetStartStatus();
  125. exp = exp.And(x => x.RecordStatus != startStatus);
  126. if (schoolyearID.HasValue)
  127. {
  128. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  129. }
  130. if (collegeID.HasValue)
  131. {
  132. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
  133. }
  134. if (year.HasValue)
  135. {
  136. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == year);
  137. }
  138. if (standardID.HasValue)
  139. {
  140. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
  141. }
  142. if (classmajorID.HasValue)
  143. {
  144. exp = exp.And(x => x.CF_Student.ClassmajorID == classmajorID);
  145. }
  146. if (examsCatagoryID.HasValue)
  147. {
  148. exp = exp.And(x => x.ExamsCategoryID == examsCatagoryID);
  149. }
  150. if (recordStatus.HasValue)
  151. {
  152. exp = exp.And(x => x.RecordStatus == recordStatus);
  153. }
  154. if (learningformID.HasValue)
  155. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID);
  156. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  157. {
  158. var LearnSystems = Convert.ToDecimal(LearnSystem);
  159. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems);
  160. }
  161. if (education.HasValue)
  162. {
  163. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == education.Value);
  164. }
  165. var query = this.ExaminationExemptionDAL.GetExaminationExemptionViewQueryable(exp);
  166. if (!string.IsNullOrEmpty(conditions.ConditionValue))
  167. {
  168. query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue);
  169. }
  170. query = this.GetQueryByDataRangeByCollege(query);
  171. var result = query.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Year).ThenBy(x => x.StandardID).ToList();
  172. result.ForEach(x =>
  173. {
  174. var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus);
  175. if (currentStatus != null)
  176. {
  177. x.RecordStatusName = currentStatus.Name;
  178. }
  179. else
  180. {
  181. x.RecordStatusName = "";
  182. }
  183. });
  184. return result;
  185. }
  186. public List<ViewModel.ScoreManage.ExaminationExemptionView> GetExaminationExemptionViewStudentList(ViewModel.ConfiguretView conditions,
  187. Guid? userID)
  188. {
  189. Expression<Func<ER_ExaminationExemption, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  190. var statusList = this.GetStatusViewList();
  191. if (userID.HasValue)
  192. {
  193. exp = exp.And(x => x.UserID == userID);
  194. }
  195. var query = this.ExaminationExemptionDAL.GetExaminationExemptionViewQueryable(exp);
  196. if (!string.IsNullOrEmpty(conditions.ConditionValue))
  197. {
  198. query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue);
  199. }
  200. var result = query.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Year).ThenBy(x => x.StandardID).ToList();
  201. result.ForEach(x =>
  202. {
  203. var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus);
  204. if (currentStatus != null)
  205. {
  206. x.RecordStatusName = currentStatus.Name;
  207. }
  208. else
  209. {
  210. x.RecordStatusName = "";
  211. }
  212. });
  213. return result;
  214. }
  215. public EMIS.ViewModel.ScoreManage.ExaminationExemptionView GetExaminationExemptionView(Guid examinationExemptionID)
  216. {
  217. var statusList = this.GetStatusViewList();
  218. var examinationExemptionView = this.ExaminationExemptionDAL.GetExaminationExemptionViewQueryable(x => x.ExaminationExemptionID == examinationExemptionID)
  219. .FirstOrDefault();
  220. if (examinationExemptionView != null)
  221. {
  222. var recordStatus = statusList.FirstOrDefault(x => x.ID == examinationExemptionView.RecordStatus);
  223. if (recordStatus != null)
  224. {
  225. examinationExemptionView.RecordStatusName = recordStatus.Name;
  226. }
  227. }
  228. return examinationExemptionView;
  229. }
  230. public void Save(ViewModel.ScoreManage.ExaminationExemptionView examinationExemptionView)
  231. {
  232. var dupExemption = this.ExaminationExemptionDAL.ExaminationExemptionRepository
  233. .GetSingle(x => x.UserID == examinationExemptionView.UserID && x.SchoolyearID == examinationExemptionView.SchoolyearID
  234. && x.CoursematerialID == examinationExemptionView.CoursematerialID && x.ExamsCategoryID == examinationExemptionView.ExamsCategoryID);
  235. ER_ExaminationExemption examinationExemption = this.ExaminationExemptionDAL.ExaminationExemptionRepository
  236. .GetSingle(x => x.ExaminationExemptionID == examinationExemptionView.ExaminationExemptionID);
  237. if (examinationExemption == null)
  238. {
  239. if (dupExemption != null)
  240. {
  241. throw new Exception("该科目在这个学期已经申请过免考,请勿重复申请。");
  242. }
  243. examinationExemption = new ER_ExaminationExemption();
  244. examinationExemption.ExaminationExemptionID = Guid.NewGuid();
  245. this.SetNewStatus(examinationExemption);
  246. examinationExemption.RecordStatus = this.GetStartStatus();
  247. this.UnitOfWork.Add(examinationExemption);
  248. }
  249. else
  250. {
  251. if (dupExemption != null && dupExemption.ExaminationExemptionID != examinationExemption.ExaminationExemptionID)
  252. {
  253. throw new Exception("该科目在这个学期已经申请过免考,请勿重复申请。");
  254. }
  255. this.SetModifyStatus(examinationExemption);
  256. }
  257. examinationExemption.UserID = examinationExemptionView.UserID;
  258. examinationExemption.SchoolyearID = examinationExemptionView.SchoolyearID;
  259. examinationExemption.CoursematerialID = examinationExemptionView.CoursematerialID;
  260. examinationExemption.ExamsCategoryID = examinationExemptionView.ExamsCategoryID;
  261. examinationExemption.Reason = examinationExemptionView.Reason;
  262. this.UnitOfWork.Commit();
  263. }
  264. public void Delete(IList<Guid> examinationExemptionIDList)
  265. {
  266. this.UnitOfWork.Remove<ER_ExaminationExemption>(x => examinationExemptionIDList.Contains(x.ExaminationExemptionID));
  267. this.UnitOfWork.Commit();
  268. }
  269. public IGridResultSet<ViewModel.ScoreManage.ExaminationExemptionCoursematerialView> GetExaminationExemptionCoursematerialGridView(
  270. ConfiguretView conditions, int? pageIndex = null, int? pageSize = null)
  271. {
  272. var userID = CustomPrincipal.Current.UserID;
  273. Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolyearExp = (x => x.IsCurrent == true);
  274. Expression<Func<EMIS.Entities.CF_Student, bool>> studentExp = (x => x.UserID == userID);
  275. var query = this.ExaminationExemptionDAL.GetExaminationExemptionCoursematerialViewQueryable(schoolyearExp, studentExp);
  276. if (!string.IsNullOrEmpty(conditions.ConditionValue))
  277. {
  278. query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue);
  279. }
  280. var result = query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.CourseName).ToGridResultSet(pageIndex, pageSize);
  281. return result;
  282. }
  283. public IGridResultSet<ViewModel.ScoreManage.ExaminationExemptionCoursematerialView> GetExaminationExemptionCoursematerialGridViewForTeacher(
  284. ConfiguretView conditions,Guid? UserID, int? pageIndex = null, int? pageSize = null)
  285. {
  286. Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolyearExp = (x => x.IsCurrent == true);
  287. Expression<Func<EMIS.Entities.CF_Student, bool>> studentExp = (x => true);
  288. if (UserID.HasValue)
  289. {
  290. studentExp = (x => x.UserID == UserID);
  291. }
  292. var query = this.ExaminationExemptionDAL.GetExaminationExemptionCoursematerialViewQueryable(schoolyearExp, studentExp);
  293. if (!string.IsNullOrEmpty(conditions.ConditionValue))
  294. {
  295. query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue);
  296. }
  297. var result = query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.CourseName).ToGridResultSet(pageIndex, pageSize);
  298. return result;
  299. }
  300. public void OnApproveEnd(List<Guid> examinationExemptionIDList, Guid? userID)
  301. {
  302. ScoreServices.Value.RefreshExaminationExemptionState(examinationExemptionIDList);
  303. }
  304. public void OnRollback(List<Guid> examinationExemptionIDList, Guid? userID)
  305. {
  306. ScoreServices.Value.RefreshCancelExaminationExemptionState(examinationExemptionIDList);
  307. }
  308. public List<ViewModel.ScoreManage.ExaminationExemptionView> GetExaminationExemptionViewListByFinalExamination(Guid? finalExaminationID)
  309. {
  310. var endStatus = this.GetCorrectEndStatus();
  311. var finalExaminationView = FinalExaminationDAL.GetFinalExaminationViewQueryable(x => x.FinalExaminationID == finalExaminationID).FirstOrDefault();
  312. if (finalExaminationView == null)
  313. {
  314. return new List<ViewModel.ScoreManage.ExaminationExemptionView>();
  315. }
  316. Expression<Func<ER_ExaminationExemption, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  317. && x.SchoolyearID == finalExaminationView.SchoolyearID && x.CoursematerialID == finalExaminationView.CoursematerialID
  318. && x.ExamsCategoryID == finalExaminationView.ExamsCategoryID && x.RecordStatus == 3);
  319. var statusList = this.GetStatusViewList();
  320. var query = this.ExaminationExemptionDAL.GetExaminationExemptionViewQueryable(exp);
  321. var result = query.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Year).ThenBy(x => x.StandardID).ToList();
  322. result.ForEach(x =>
  323. {
  324. var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus);
  325. if (currentStatus != null)
  326. {
  327. x.RecordStatusName = currentStatus.Name;
  328. }
  329. else
  330. {
  331. x.RecordStatusName = "";
  332. }
  333. });
  334. return result;
  335. }
  336. public void Cancel(List<Guid> examinationExemptionIDList, Guid userID, string comment)
  337. {
  338. var endStatusID = GetEndStatusID();
  339. var examinationExemptionList = ExaminationExemptionDAL.ExaminationExemptionRepository
  340. .GetList(x => examinationExemptionIDList.Contains(x.ExaminationExemptionID)).ToList();
  341. if (examinationExemptionList.Any(x => x.RecordStatus != endStatusID))
  342. {
  343. throw new Exception("只能撤回已通过状态的记录。");
  344. }
  345. var actionViewList = this.GetActionView(examinationExemptionIDList[0], userID);
  346. var actionView = actionViewList.FirstOrDefault();
  347. this.Approve(examinationExemptionIDList, userID, actionView.ActionID, comment);
  348. }
  349. public int? GetEndStatusID()
  350. {
  351. var endStatus = this.GetStatusViewList().FirstOrDefault(x => x.Description.Contains("[End]"));
  352. if (endStatus != null)
  353. {
  354. return endStatus.ID;
  355. }
  356. else
  357. {
  358. return null;
  359. }
  360. }
  361. }
  362. }