ExaminationSuspensionServices.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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 ExaminationSuspensionServices : BaseWorkflowServices<ER_ExaminationSuspension>, IExaminationSuspensionServices
  17. {
  18. public ExaminationSuspensionDAL ExaminationSuspensionDAL { get; set; }
  19. public FinalExaminationDAL FinalExaminationDAL { get; set; }
  20. public Lazy<IScoreServices> ScoreServices { get; set; }
  21. public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.ScoreManage.ExaminationSuspensionView> GetExaminationSuspensionGridView(
  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_ExaminationSuspension, 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.ExaminationSuspensionDAL.GetExaminationSuspensionViewQueryable(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. var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus);
  78. if (currentStatus != null)
  79. {
  80. x.RecordStatusName = currentStatus.Name;
  81. }
  82. else
  83. {
  84. x.RecordStatusName = "";
  85. }
  86. });
  87. return result;
  88. }
  89. public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.ScoreManage.ExaminationSuspensionView> GetExaminationSuspensionStudentGridView(
  90. ViewModel.ConfiguretView conditions, Guid? userID = null, int? pageIndex = null, int? pageSize = null)
  91. {
  92. Expression<Func<ER_ExaminationSuspension, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  93. var statusList = this.GetStatusViewList();
  94. if (userID.HasValue)
  95. {
  96. exp = exp.And(x => x.UserID == userID);
  97. }
  98. var query = this.ExaminationSuspensionDAL.GetExaminationSuspensionViewQueryable(exp);
  99. if (!string.IsNullOrEmpty(conditions.ConditionValue))
  100. {
  101. query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue);
  102. }
  103. var result = query.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Year).ThenBy(x => x.StandardID).ToGridResultSet(pageIndex, pageSize);
  104. result.rows.ForEach(x =>
  105. {
  106. var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus);
  107. if (currentStatus != null)
  108. {
  109. x.RecordStatusName = currentStatus.Name;
  110. }
  111. else
  112. {
  113. x.RecordStatusName = "";
  114. }
  115. });
  116. return result;
  117. }
  118. public List<ViewModel.ScoreManage.ExaminationSuspensionView> GetExaminationSuspensionViewList(ViewModel.ConfiguretView conditions,
  119. Guid? schoolyearID, Guid? collegeID, int? year, int? standardID, Guid? classmajorID, int? examsCatagoryID, int? recordStatus,
  120. int? learningformID, int? education,string LearnSystem)
  121. {
  122. var statusList = this.GetStatusViewList();
  123. Expression<Func<ER_ExaminationSuspension, 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.ExaminationSuspensionDAL.GetExaminationSuspensionViewQueryable(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.ExaminationSuspensionView> GetExaminationSuspensionViewStudentList(ViewModel.ConfiguretView conditions,
  187. Guid? userID)
  188. {
  189. Expression<Func<ER_ExaminationSuspension, 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.ExaminationSuspensionDAL.GetExaminationSuspensionViewQueryable(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.ExaminationSuspensionView GetExaminationSuspensionView(Guid examinationSuspensionID)
  216. {
  217. var statusList = this.GetStatusViewList();
  218. var examinationSuspensionView = this.ExaminationSuspensionDAL.GetExaminationSuspensionViewQueryable(x => x.ExaminationSuspensionID == examinationSuspensionID)
  219. .FirstOrDefault();
  220. if (examinationSuspensionView != null)
  221. {
  222. var recordStatus = statusList.FirstOrDefault(x => x.ID == examinationSuspensionView.RecordStatus);
  223. if (recordStatus != null)
  224. {
  225. examinationSuspensionView.RecordStatusName = recordStatus.Name;
  226. }
  227. }
  228. return examinationSuspensionView;
  229. }
  230. public void Save(ViewModel.ScoreManage.ExaminationSuspensionView examinationSuspensionView)
  231. {
  232. int? endStatus = this.GetCorrectEndStatus();
  233. var dupSuspension = this.ExaminationSuspensionDAL.ExaminationSuspensionRepository
  234. .GetSingle(x => x.UserID == examinationSuspensionView.UserID && x.SchoolyearID == examinationSuspensionView.SchoolyearID
  235. && x.CoursematerialID == examinationSuspensionView.CoursematerialID && x.ExamsCategoryID == examinationSuspensionView.ExamsCategoryID && x.RecordStatus != endStatus);
  236. ER_ExaminationSuspension examinationSuspension = this.ExaminationSuspensionDAL.ExaminationSuspensionRepository
  237. .GetSingle(x => x.ExaminationSuspensionID == examinationSuspensionView.ExaminationSuspensionID);
  238. if (examinationSuspension == null)
  239. {
  240. if (dupSuspension != null)
  241. {
  242. throw new Exception("该科目在这个学期已经申请过缓考,请勿重复申请。");
  243. }
  244. examinationSuspension = new ER_ExaminationSuspension();
  245. examinationSuspension.ExaminationSuspensionID = Guid.NewGuid();
  246. this.SetNewStatus(examinationSuspension);
  247. examinationSuspension.RecordStatus = this.GetStartStatus();
  248. this.UnitOfWork.Add(examinationSuspension);
  249. }
  250. else
  251. {
  252. if (dupSuspension != null && dupSuspension.ExaminationSuspensionID != examinationSuspension.ExaminationSuspensionID && dupSuspension.RecordStatus != endStatus)
  253. {
  254. throw new Exception("该科目在这个学期已经申请过缓考,请勿重复申请。");
  255. }
  256. this.SetModifyStatus(examinationSuspension);
  257. }
  258. examinationSuspension.UserID = examinationSuspensionView.UserID;
  259. examinationSuspension.SchoolyearID = examinationSuspensionView.SchoolyearID;
  260. examinationSuspension.CoursematerialID = examinationSuspensionView.CoursematerialID;
  261. examinationSuspension.ExamsCategoryID = examinationSuspensionView.ExamsCategoryID;
  262. examinationSuspension.Reason = examinationSuspensionView.Reason;
  263. this.UnitOfWork.Commit();
  264. }
  265. public void Delete(IList<Guid> examinationSuspensionIDList)
  266. {
  267. this.UnitOfWork.Remove<ER_ExaminationSuspension>(x => examinationSuspensionIDList.Contains(x.ExaminationSuspensionID));
  268. this.UnitOfWork.Commit();
  269. }
  270. public IGridResultSet<ViewModel.ScoreManage.ExaminationSuspensionCoursematerialView> GetExaminationSuspensionCoursematerialGridView(
  271. ConfiguretView conditions, int? pageIndex = null, int? pageSize = null)
  272. {
  273. var userID = CustomPrincipal.Current.UserID;
  274. Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolyearExp = (x => x.IsCurrent == true);
  275. Expression<Func<EMIS.Entities.CF_Student, bool>> studentExp = (x => x.UserID == userID);
  276. var query = this.ExaminationSuspensionDAL.GetExaminationSuspensionCoursematerialViewQueryable(schoolyearExp, studentExp);
  277. if (!string.IsNullOrEmpty(conditions.ConditionValue))
  278. {
  279. query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue);
  280. }
  281. var result = query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.CourseName).ToGridResultSet(pageIndex, pageSize);
  282. return result;
  283. }
  284. public IGridResultSet<ViewModel.ScoreManage.ExaminationSuspensionCoursematerialView> GetExaminationSuspensionCoursematerialGridViewForTeacher(
  285. ConfiguretView conditions, Guid? UserID, int? pageIndex = null, int? pageSize = null)
  286. {
  287. Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolyearExp = (x => x.IsCurrent == true);
  288. Expression<Func<EMIS.Entities.CF_Student, bool>> studentExp = (x => true);
  289. if (UserID.HasValue)
  290. {
  291. studentExp=(x=>x.UserID== UserID);
  292. }
  293. var query = this.ExaminationSuspensionDAL.GetExaminationSuspensionCoursematerialViewQueryable(schoolyearExp, studentExp);
  294. if (!string.IsNullOrEmpty(conditions.ConditionValue))
  295. {
  296. query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue);
  297. }
  298. query = query.Distinct();
  299. var result = query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.CourseName).ToGridResultSet(pageIndex, pageSize);
  300. return result;
  301. }
  302. public void OnApproveEnd(List<Guid> examinationSuspensionIDList, Guid? userID)
  303. {
  304. ScoreServices.Value.RefreshExaminationSuspensionState(examinationSuspensionIDList);
  305. }
  306. public void OnApproveEnds(List<Guid> examinationSuspensionIDList, Guid? userID)
  307. {
  308. ScoreServices.Value.RefreshCancelExaminationSuspensionState(examinationSuspensionIDList);
  309. }
  310. public List<ViewModel.ScoreManage.ExaminationSuspensionView> GetExaminationSuspensionViewListByFinalExamination(Guid? finalExaminationID)
  311. {
  312. var endStatus = this.GetStatusViewList().FirstOrDefault(x => x.Description == "[End]");
  313. int? endStatusID = null;
  314. if (endStatus != null)
  315. {
  316. endStatusID = endStatus.ID;
  317. }
  318. var finalExaminationView = FinalExaminationDAL.GetFinalExaminationViewQueryable(x => x.FinalExaminationID == finalExaminationID).FirstOrDefault();
  319. if (finalExaminationView == null)
  320. {
  321. return new List<ViewModel.ScoreManage.ExaminationSuspensionView>();
  322. }
  323. Expression<Func<ER_ExaminationSuspension, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  324. && x.SchoolyearID == finalExaminationView.SchoolyearID && x.CoursematerialID == finalExaminationView.CoursematerialID
  325. && x.ExamsCategoryID == finalExaminationView.ExamsCategoryID && x.RecordStatus == endStatusID);
  326. var statusList = this.GetStatusViewList();
  327. var query = this.ExaminationSuspensionDAL.GetExaminationSuspensionViewQueryable(exp);
  328. var result = query.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Year).ThenBy(x => x.StandardID).ToList();
  329. result.ForEach(x =>
  330. {
  331. var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus);
  332. if (currentStatus != null)
  333. {
  334. x.RecordStatusName = currentStatus.Name;
  335. }
  336. else
  337. {
  338. x.RecordStatusName = "";
  339. }
  340. });
  341. return result;
  342. }
  343. public void Cancel(List<Guid> examinationSuspensionIDList, Guid userID, string comment)
  344. {
  345. var endStatusID = GetEndStatusID();
  346. var examinationSuspensionList = ExaminationSuspensionDAL.ExaminationSuspensionRepository
  347. .GetList(x => examinationSuspensionIDList.Contains(x.ExaminationSuspensionID)).ToList();
  348. if (examinationSuspensionList.Any(x => x.RecordStatus != endStatusID))
  349. {
  350. throw new Exception("只能撤回已通过状态的记录。");
  351. }
  352. var actionViewList = this.GetActionView(examinationSuspensionIDList[0], userID);
  353. var actionView = actionViewList.FirstOrDefault();
  354. this.Approve(examinationSuspensionIDList, userID, actionView.ActionID, comment);
  355. }
  356. public int? GetEndStatusID()
  357. {
  358. var endStatus = this.GetStatusViewList().FirstOrDefault(x => x.Description.Contains("[End]"));
  359. if (endStatus != null)
  360. {
  361. return endStatus.ID;
  362. }
  363. else
  364. {
  365. return null;
  366. }
  367. }
  368. }
  369. }