ScoreConvertByReplaceServices.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq;
  6. using Bowin.Common.Linq.Entity;
  7. using EMIS.CommonLogic.SystemServices;
  8. using EMIS.Entities;
  9. using EMIS.ViewModel.ScoreManage;
  10. using EMIS.ViewModel;
  11. using EMIS.DataLogic.ScoreManage;
  12. using System.Linq.Expressions;
  13. using EMIS.CommonLogic.CalendarManage;
  14. using System.Transactions;
  15. using EMIS.DataLogic.EducationManage;
  16. using EMIS.Utility;
  17. namespace EMIS.CommonLogic.ScoreManage
  18. {
  19. public partial class ScoreConvertByReplaceServices : BaseWorkflowServices<ER_ScoreConvertByReplace>, IScoreConvertByReplaceServices
  20. {
  21. public StudentScoreDAL StudentScoreDAL { get; set; }
  22. public ScoreConvertByReplaceDAL ScoreConvertByReplaceDAL { get; set; }
  23. public ExecutablePlanDAL ExecutablePlanDAL { get; set; }
  24. public Lazy<ISchoolYearServices> SchoolYearServices { get; set; }
  25. public Lazy<IParameterServices> ParameterServices { get; set; }
  26. public Lazy<IStudentScoreServices> StudentScoreServices { get; set; }
  27. public IGridResultSet<ScoreConvertByReplaceView> GetScoreConvertByReplaceViewGrid(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID,
  28. int? yearID, int? standardID, Guid? classmajorID, Guid? targetCoursematerialID, int? recordStatus, int? pageIndex, int? pageSize)
  29. {
  30. var statusViewList = this.GetStatusViewList();
  31. Expression<Func<ER_ScoreConvertByReplace, bool>> exp = (x => true);
  32. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  33. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  34. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  35. if (schoolyearID.HasValue)
  36. {
  37. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  38. }
  39. if (collegeID.HasValue)
  40. {
  41. facultyExp = facultyExp.And(x => x.CollegeID == collegeID);
  42. }
  43. if (yearID.HasValue)
  44. {
  45. gradeExp = gradeExp.And(x => x.GradeID == yearID);
  46. }
  47. if (standardID.HasValue)
  48. {
  49. facultyExp = facultyExp.And(x => x.StandardID == standardID);
  50. }
  51. if (classmajorID.HasValue)
  52. {
  53. classExp = classExp.And(x => x.ClassmajorID == classmajorID.Value);
  54. }
  55. if (targetCoursematerialID.HasValue)
  56. {
  57. exp = exp.And(x => x.TargetCoursematerialID == targetCoursematerialID);
  58. }
  59. if (recordStatus.HasValue)
  60. {
  61. exp = exp.And(x => x.RecordStatus == recordStatus);
  62. }
  63. var query = ScoreConvertByReplaceDAL.GetScoreConvertByReplaceViewQueryable(exp, facultyExp, gradeExp, classExp);
  64. if (!string.IsNullOrEmpty(conditionView.ConditionValue))
  65. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue.Trim());
  66. query = this.GetQueryByDataRangeByCollege(query);
  67. query = query.OrderByDescending(x => x.SchoolyearCode)
  68. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo)
  69. .ThenBy(x => x.YearID)
  70. .ThenBy(x => x.StandardID)
  71. .ThenBy(x => x.ClassmajorNo)
  72. .ThenBy(x => x.LoginID);
  73. var result = query.ToGridResultSet(pageIndex, pageSize);
  74. result.rows.ForEach(x => x.RecordStatusDesc = statusViewList.Where(w => w.ID == x.RecordStatus).Select(w => w.Name).FirstOrDefault());
  75. return result;
  76. }
  77. public List<ScoreConvertByReplaceView> GetScoreConvertByReplaceViewList(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID,
  78. int? yearID, int? standardID, Guid? classmajorID, Guid? targetCoursematerialID, int? recordStatus)
  79. {
  80. var statusViewList = this.GetStatusViewList();
  81. Expression<Func<ER_ScoreConvertByReplace, bool>> exp = (x => true);
  82. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  83. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  84. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  85. if (schoolyearID.HasValue)
  86. {
  87. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  88. }
  89. if (collegeID.HasValue)
  90. {
  91. facultyExp = facultyExp.And(x => x.CollegeID == collegeID);
  92. }
  93. if (yearID.HasValue)
  94. {
  95. gradeExp = gradeExp.And(x => x.GradeID == yearID);
  96. }
  97. if (standardID.HasValue)
  98. {
  99. facultyExp = facultyExp.And(x => x.StandardID == standardID);
  100. }
  101. if (classmajorID.HasValue)
  102. {
  103. classExp = classExp.And(x => x.ClassmajorID == classmajorID.Value);
  104. }
  105. if (targetCoursematerialID.HasValue)
  106. {
  107. exp = exp.And(x => x.TargetCoursematerialID == targetCoursematerialID);
  108. }
  109. if (recordStatus.HasValue)
  110. {
  111. exp = exp.And(x => x.RecordStatus == recordStatus);
  112. }
  113. var query = ScoreConvertByReplaceDAL.GetScoreConvertByReplaceViewQueryable(exp, facultyExp, gradeExp, classExp);
  114. if (!string.IsNullOrEmpty(conditionView.ConditionValue))
  115. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue.Trim());
  116. query = this.GetQueryByDataRangeByCollege(query);
  117. query = query.OrderByDescending(x => x.SchoolyearCode)
  118. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo)
  119. .ThenBy(x => x.YearID)
  120. .ThenBy(x => x.StandardID)
  121. .ThenBy(x => x.ClassmajorNo)
  122. .ThenBy(x => x.LoginID);
  123. var result = query.ToList();
  124. result.ForEach(x => x.RecordStatusDesc = statusViewList.Where(w => w.ID == x.RecordStatus).Select(w => w.Name).FirstOrDefault());
  125. return result;
  126. }
  127. public ScoreConvertByReplaceView GetScoreConvertByReplaceView(Guid? scoreConvertByReplaceID)
  128. {
  129. var statusViewList = this.GetStatusViewList();
  130. var scoreConvertByReplaceView = this.ScoreConvertByReplaceDAL.GetScoreConvertByReplaceViewQueryable(x => x.ScoreConvertByReplaceID == scoreConvertByReplaceID,
  131. (x => true), (x => true), (x => true)).FirstOrDefault();
  132. if (scoreConvertByReplaceView != null)
  133. {
  134. scoreConvertByReplaceView.RecordStatusDesc = statusViewList.Where(x => x.ID == scoreConvertByReplaceView.RecordStatus).Select(x => x.Name).FirstOrDefault();
  135. }
  136. return scoreConvertByReplaceView;
  137. }
  138. public void Save(ScoreConvertByReplaceView scoreConvertByReplaceView)
  139. {
  140. try
  141. {
  142. var schoolyear = SchoolYearServices.Value.GetCurrentSchoolYear();
  143. ER_ScoreConvertByReplace dupScoreConvert = ScoreConvertByReplaceDAL.ScoreConvertByReplaceRepository.Entities.Where(x =>
  144. x.SourceCoursematerialID == scoreConvertByReplaceView.SourceCoursematerialID
  145. && x.UserID == scoreConvertByReplaceView.UserID
  146. && x.ScoreConvertByReplaceID != scoreConvertByReplaceView.ScoreConvertByReplaceID).FirstOrDefault();
  147. if (dupScoreConvert != null)
  148. {
  149. throw new Exception("该课程已经申请过认定,不能重复申请。");
  150. }
  151. ER_ScoreConvertByReplace scoreConvert = null;
  152. if (scoreConvertByReplaceView.ScoreConvertByReplaceID == null || scoreConvertByReplaceView.ScoreConvertByReplaceID == Guid.Empty)
  153. {
  154. scoreConvert = new ER_ScoreConvertByReplace();
  155. scoreConvert.ScoreConvertByReplaceID = Guid.NewGuid();
  156. SetNewStatus(scoreConvert);
  157. UnitOfWork.Add(scoreConvert);
  158. }
  159. else
  160. {
  161. scoreConvert = this.ScoreConvertByReplaceDAL.ScoreConvertByReplaceRepository
  162. .GetSingle(x => x.ScoreConvertByReplaceID == scoreConvertByReplaceView.ScoreConvertByReplaceID);
  163. if (scoreConvert == null)
  164. {
  165. throw new Exception("当前编辑的认定记录可能已被其他人删除。");
  166. }
  167. SetModifyStatus(scoreConvert);
  168. }
  169. scoreConvert.SchoolyearID = schoolyear.SchoolYearID;
  170. scoreConvert.UserID = scoreConvertByReplaceView.UserID;
  171. scoreConvert.SourceCoursematerialID = scoreConvertByReplaceView.SourceCoursematerialID;
  172. scoreConvert.TotalScore = scoreConvertByReplaceView.TotalScore;
  173. scoreConvert.TargetCoursematerialID = scoreConvertByReplaceView.TargetCoursematerialID;
  174. scoreConvert.Reason = scoreConvertByReplaceView.Reason;
  175. UnitOfWork.Commit();
  176. }
  177. catch (Exception)
  178. {
  179. throw;
  180. }
  181. }
  182. public void Delete(IList<Guid?> scoreConvertByReplaceIDList)
  183. {
  184. if (scoreConvertByReplaceIDList.Count > 0)
  185. {
  186. var canDeleteStatus = new List<int?>();
  187. canDeleteStatus.Add(this.GetStartStatus());
  188. canDeleteStatus.AddRange(this.GetBackpointStatus());
  189. var canDeleteStatusDesc = this.GetStatusViewList().Where(x => canDeleteStatus.Contains(x.ID)).Select(x => x.Name);
  190. var scoreConvertByReplaceList = ScoreConvertByReplaceDAL.ScoreConvertByReplaceRepository.GetList(x => scoreConvertByReplaceIDList.Contains(x.ScoreConvertByReplaceID)).ToList();
  191. if (scoreConvertByReplaceList.Any(x => !canDeleteStatus.Contains(x.RecordStatus)))
  192. {
  193. throw new Exception("只能删除状态为" + string.Join("、", canDeleteStatusDesc) + "的记录。");
  194. }
  195. UnitOfWork.Delete<ER_ScoreConvertByReplace>(x => scoreConvertByReplaceIDList.Contains(x.ScoreConvertByReplaceID));
  196. }
  197. }
  198. public void OnApproveEnd(List<Guid> scoreConvertByReplaceIDList, Guid? userID)
  199. {
  200. int? retakeExamsCategoryID = ParameterServices.Value.GetParameterValue<int>(CF_ParameterType.RetakeExamsCatagoryID);
  201. var scoreConvertByReplaceList = this.ScoreConvertByReplaceDAL.ScoreConvertByReplaceRepository
  202. .GetList(x => scoreConvertByReplaceIDList.Contains(x.ScoreConvertByReplaceID)).ToList();
  203. var selectKeyList = scoreConvertByReplaceList.Select(x => new { x.UserID, CoursematerialID = x.SourceCoursematerialID }).ToList();
  204. var targetSelectKeyList = scoreConvertByReplaceList.Select(x => new { x.UserID, CoursematerialID = x.TargetCoursematerialID }).ToList();
  205. var submitedScoreList = StudentScoreDAL.submitedScoreRepository.Entities.SelectByKeys(selectKeyList);
  206. var submitedScoreIDList = submitedScoreList.Select(x => (Guid?)x.SubmitedScoreID);
  207. var submitedScoreDetailList = StudentScoreDAL.SubmitedScoreDetailRepository.GetList(x => submitedScoreIDList.Contains(x.SubmitedScoreID)).ToList();
  208. var finallyScoreList = StudentScoreDAL.FinallyScoreRepository.Entities.SelectByKeys(selectKeyList);
  209. var finallyScoreIDList = finallyScoreList.Select(x => (Guid?)x.FinallyScoreID);
  210. var finallyScoreDetailList = StudentScoreDAL.FinallyScoreDetailRepository.GetList(x => finallyScoreIDList.Contains(x.FinallyScoreID)).ToList();
  211. //这个方法比较可疑,不知道技术上能否实现(主要是EF产生的语句有自动命名的问题,端点调)
  212. var lastCourseStarttermViewList = ExecutablePlanDAL.GetLastCourseStarttermViewQueryable().SelectByKeys(targetSelectKeyList);
  213. var insertSubmitedScoreBackupList = new List<ER_ScoreConvertedSubmitedScore>();
  214. var insertSubmitedScoreDetailBackupList = new List<ER_ScoreConvertedSubmitedScoreDetail>();
  215. var insertSubmitedScoreList = new List<ER_SubmitedScore>();
  216. var insertSubmitedScoreDetailList = new List<ER_SubmitedScoreDetail>();
  217. foreach (var submitedScore in submitedScoreList)
  218. {
  219. var scoreConvertByReplace = scoreConvertByReplaceList.FirstOrDefault(x => x.UserID == submitedScore.UserID && x.SourceCoursematerialID == submitedScore.CoursematerialID);
  220. #region 备份已提交成绩主表
  221. var scoreConvertedSubmitedScore = new ER_ScoreConvertedSubmitedScore
  222. {
  223. ScoreConvertedSubmitedScoreID = Guid.NewGuid(),
  224. ScoreConvertByReplaceID = scoreConvertByReplace.ScoreConvertByReplaceID,
  225. SchoolyearID = submitedScore.SchoolyearID,
  226. SchoolyearNumID = submitedScore.SchoolyearNumID,
  227. FinalExaminationID = submitedScore.FinalExaminationID,
  228. DepartmentID = submitedScore.DepartmentID,
  229. ClassName = submitedScore.ClassName,
  230. CoursematerialID = submitedScore.CoursematerialID,
  231. CourseTypeID = submitedScore.CourseTypeID,
  232. ExamsCategoryID = submitedScore.ExamsCategoryID,
  233. ExaminationModeID = submitedScore.ExaminationModeID,
  234. HandleModeID = submitedScore.HandleModeID,
  235. Credit = submitedScore.Credit,
  236. Totalhours = submitedScore.TotalHours,
  237. ExamsDatetime = submitedScore.ExamsDatetime,
  238. ResultTypeID = submitedScore.ResultTypeID,
  239. CreatorUserID = submitedScore.CreatorUserID,
  240. EntryDeadlineTime = submitedScore.EntryDeadlineTime,
  241. IsEntry = submitedScore.IsEntry,
  242. ExaminationType = submitedScore.ExaminationType,
  243. StarttermID = submitedScore.StarttermID,
  244. UserID = submitedScore.UserID,
  245. ExamsStateID = submitedScore.ExamsStateID,
  246. TotalScore = submitedScore.TotalScore,
  247. ScoreCredit = submitedScore.ScoreCredit,
  248. GradePoint = submitedScore.GradePoint,
  249. Remark = submitedScore.Remark,
  250. RecordStatus = submitedScore.RecordStatus,
  251. CreateTime = submitedScore.CreateTime,
  252. CreateUserID = submitedScore.CreateUserID,
  253. ModifyUserID = submitedScore.ModifyUserID,
  254. ModifyTime = submitedScore.ModifyTime
  255. };
  256. insertSubmitedScoreBackupList.Add(scoreConvertedSubmitedScore);
  257. #endregion
  258. #region 备份已提交成绩明细
  259. var curSubmitedScoreDetailList = submitedScoreDetailList.Where(x => x.SubmitedScoreID == submitedScore.SubmitedScoreID).ToList();
  260. foreach (var detail in curSubmitedScoreDetailList)
  261. {
  262. insertSubmitedScoreDetailBackupList.Add(new ER_ScoreConvertedSubmitedScoreDetail
  263. {
  264. ScoreConvertedSubmitedScoreDetailID = Guid.NewGuid(),
  265. ScoreConvertedSubmitedScoreID = scoreConvertedSubmitedScore.ScoreConvertedSubmitedScoreID,
  266. ScoreTypeID = detail.ScoreTypeID,
  267. Score = detail.Score,
  268. RecordStatus = detail.RecordStatus,
  269. CreateTime = detail.CreateTime,
  270. CreateUserID = detail.CreateUserID,
  271. ModifyUserID = detail.ModifyUserID,
  272. ModifyTime = detail.ModifyTime
  273. });
  274. }
  275. #endregion
  276. }
  277. foreach (var finallyScore in finallyScoreList)
  278. {
  279. var scoreConvertByReplace = scoreConvertByReplaceList.FirstOrDefault(x => x.UserID == finallyScore.UserID && x.SourceCoursematerialID == finallyScore.CoursematerialID);
  280. var lastCourseStarttermView = lastCourseStarttermViewList.FirstOrDefault(x => x.UserID == finallyScore.UserID && x.CoursematerialID == scoreConvertByReplace.TargetCoursematerialID);
  281. #region 添加新的已提交成绩
  282. var insertSubmitedScore = new ER_SubmitedScore
  283. {
  284. SubmitedScoreID = Guid.NewGuid(),
  285. SchoolyearID = finallyScore.SchoolyearID,
  286. SchoolyearNumID = lastCourseStarttermView.SchoolyearNumID,
  287. DepartmentID = lastCourseStarttermView.DepartmentID,
  288. ClassName = lastCourseStarttermView.ClassName,
  289. CoursematerialID = lastCourseStarttermView.CoursematerialID,
  290. CourseTypeID = lastCourseStarttermView.CourseTypeID,
  291. ExamsCategoryID = (int)EMIS.ViewModel.CF_ExamsCategory.FinalExam,
  292. ExaminationModeID = lastCourseStarttermView.ExaminationModeID,
  293. HandleModeID = lastCourseStarttermView.HandleModeID,
  294. Credit = lastCourseStarttermView.Credit,
  295. TotalHours = lastCourseStarttermView.TotalHours,
  296. ResultTypeID = lastCourseStarttermView.ResultTypeID,
  297. CreatorUserID = userID,
  298. IsEntry = true,
  299. ExaminationType = (int)EMIS.ViewModel.CF_ExaminationType.FinalExamination,
  300. StarttermID = lastCourseStarttermView.StarttermID,
  301. UserID = lastCourseStarttermView.UserID,
  302. ExamsStateID = (int)CF_ExamsState.NormalExams,
  303. TotalScore = finallyScore.TotalScore,
  304. ScoreCredit = finallyScore.ScoreCredit > 0 ? lastCourseStarttermView.Credit : 0,
  305. GradePoint = finallyScore.GradePoint,
  306. Remark = Const.ER_SCORECONVERT_BYREPLACE_SCOREREMARK,
  307. RecordStatus = (int)SYS_STATUS.USABLE,
  308. CreateUserID = userID,
  309. CreateTime = DateTime.Now,
  310. ModifyUserID = userID,
  311. ModifyTime = DateTime.Now
  312. };
  313. #endregion
  314. #region 添加新的已提交成绩明细
  315. var curFinallyScoreDetailList = finallyScoreDetailList.Where(x => x.FinallyScoreID == finallyScore.FinallyScoreID).ToList();
  316. foreach (var detail in curFinallyScoreDetailList)
  317. {
  318. insertSubmitedScoreDetailList.Add(new ER_SubmitedScoreDetail
  319. {
  320. SubmitedScoreDetailID = Guid.NewGuid(),
  321. SubmitedScoreID = insertSubmitedScore.SubmitedScoreID,
  322. ScoreTypeID = detail.ScoreTypeID,
  323. Score = detail.Score,
  324. RecordStatus = detail.RecordStatus,
  325. CreateTime = detail.CreateTime,
  326. CreateUserID = detail.CreateUserID,
  327. ModifyUserID = detail.ModifyUserID,
  328. ModifyTime = detail.ModifyTime
  329. });
  330. }
  331. #endregion
  332. insertSubmitedScoreList.Add(insertSubmitedScore);
  333. }
  334. var insertSubmitedScoreIDList = insertSubmitedScoreList.Select(x => x.SubmitedScoreID).ToList();
  335. using (var scope = new TransactionScope(TransactionScopeOption.Required))
  336. {
  337. UnitOfWork.BulkInsert(insertSubmitedScoreBackupList);
  338. UnitOfWork.BulkInsert(insertSubmitedScoreDetailBackupList);
  339. UnitOfWork.Delete<ER_SubmitedScoreDetail>(x => submitedScoreIDList.Contains(x.SubmitedScoreID));
  340. UnitOfWork.Delete<ER_SubmitedScore>(x => submitedScoreIDList.Contains(x.SubmitedScoreID));
  341. UnitOfWork.Delete<ER_FinallyScoreDetail>(x => finallyScoreIDList.Contains(x.FinallyScoreID));
  342. UnitOfWork.Delete<ER_FinallyScore>(x => finallyScoreIDList.Contains(x.FinallyScoreID));
  343. UnitOfWork.BulkInsert(insertSubmitedScoreList);
  344. UnitOfWork.BulkInsert(insertSubmitedScoreDetailList);
  345. StudentScoreServices.Value.RefreshFinallyScoreBySubmitedScoreID(insertSubmitedScoreIDList);
  346. scope.Complete();
  347. }
  348. }
  349. }
  350. }