ScoreConvertByApplyServices.cs 19 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.ViewModel.ScoreManage;
  8. using EMIS.ViewModel;
  9. using EMIS.CommonLogic.SystemServices;
  10. using EMIS.Entities;
  11. using System.Linq.Expressions;
  12. using EMIS.DataLogic.ScoreManage;
  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 class ScoreConvertByApplyServices : BaseWorkflowServices<ER_ScoreConvertByApply>, IScoreConvertByApplyServices, IFileUploadServices
  20. {
  21. public StudentScoreDAL studentScoreDAL { get; set; }
  22. public ScoreConvertByApplyDAL scoreConvertByApplyDAL { get; set; }
  23. public ISchoolYearServices schoolYearServices { get; set; }
  24. public IParameterServices parameterServices { get; set; }
  25. public ExecutablePlanDAL ExecutablePlanDAL { get; set; }
  26. public IStudentScoreServices studentScoreServices { get; set; }
  27. public IGridResultSet<ScoreConvertByApplyView> GetScoreConvertByApplyViewGrid(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID,
  28. int? yearID, int? standardID, Guid? classmajorID, Guid? coursematerialID, int? recordStatus, int? pageIndex, int? pageSize)
  29. {
  30. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  31. var statusViewList = this.GetStatusViewList();
  32. Expression<Func<ER_ScoreConvertByApply, bool>> exp = (x => true);
  33. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  34. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  35. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  36. if (schoolyearID.HasValue)
  37. {
  38. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  39. }
  40. if (collegeID.HasValue)
  41. {
  42. facultyExp = facultyExp.And(x => x.CollegeID == collegeID);
  43. }
  44. if (yearID.HasValue)
  45. {
  46. gradeExp = gradeExp.And(x => x.GradeID == yearID);
  47. }
  48. if (standardID.HasValue)
  49. {
  50. facultyExp = facultyExp.And(x => x.StandardID == standardID);
  51. }
  52. if (classmajorID.HasValue)
  53. {
  54. classExp = classExp.And(x => x.ClassmajorID == classmajorID.Value);
  55. }
  56. if (coursematerialID.HasValue)
  57. {
  58. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  59. }
  60. if (recordStatus.HasValue)
  61. {
  62. exp = exp.And(x => x.RecordStatus == recordStatus);
  63. }
  64. //学生登录只看到自己的信息
  65. if (curUser.IsStudent)
  66. {
  67. exp = exp.And(x => x.UserID == curUser.UserID);
  68. }
  69. var query = scoreConvertByApplyDAL.GetScoreConvertByApplyViewQueryable(exp, facultyExp, gradeExp, classExp);
  70. if (!string.IsNullOrEmpty(conditionView.ConditionValue))
  71. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue.Trim());
  72. query = this.GetQueryByDataRangeByCollege(query);
  73. query = query.OrderByDescending(x => x.SchoolyearCode)
  74. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo)
  75. .ThenBy(x => x.StandardID)
  76. .ThenBy(x => x.ClassmajorNo)
  77. .ThenBy(x => x.LoginID);
  78. var result = query.ToGridResultSet(pageIndex, pageSize);
  79. result.rows.ForEach(x => x.RecordStatusDesc = statusViewList.Where(w => w.ID == x.RecordStatus).Select(w => w.Name).FirstOrDefault());
  80. return result;
  81. }
  82. public List<ScoreConvertByApplyView> GetScoreConvertByApplyViewList(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID,
  83. int? yearID, int? standardID, Guid? classmajorID, Guid? coursematerialID, int? recordStatus, List<Guid?> idList)
  84. {
  85. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  86. var statusViewList = this.GetStatusViewList();
  87. Expression<Func<ER_ScoreConvertByApply, bool>> exp = (x => true);
  88. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  89. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  90. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  91. if (schoolyearID.HasValue)
  92. {
  93. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  94. }
  95. if (collegeID.HasValue)
  96. {
  97. facultyExp = facultyExp.And(x => x.CollegeID == collegeID);
  98. }
  99. if (yearID.HasValue)
  100. {
  101. gradeExp = gradeExp.And(x => x.GradeID == yearID);
  102. }
  103. if (standardID.HasValue)
  104. {
  105. facultyExp = facultyExp.And(x => x.StandardID == standardID);
  106. }
  107. if (classmajorID.HasValue)
  108. {
  109. classExp = classExp.And(x => x.ClassmajorID == classmajorID.Value);
  110. }
  111. if (coursematerialID.HasValue)
  112. {
  113. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  114. }
  115. if (recordStatus.HasValue)
  116. {
  117. exp = exp.And(x => x.RecordStatus == recordStatus);
  118. }
  119. if (idList != null && idList.Count > 0)
  120. {
  121. exp = exp.And(x => idList.Contains(x.ScoreConvertByApplyID));
  122. }
  123. //学生登录只看到自己的信息
  124. if (curUser.IsStudent)
  125. {
  126. exp = exp.And(x => x.UserID == curUser.UserID);
  127. }
  128. var query = scoreConvertByApplyDAL.GetScoreConvertByApplyViewQueryable(exp, facultyExp, gradeExp, classExp);
  129. if (!string.IsNullOrEmpty(conditionView.ConditionValue))
  130. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue.Trim());
  131. query = this.GetQueryByDataRangeByCollege(query);
  132. query = query.OrderByDescending(x => x.SchoolyearCode)
  133. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo)
  134. .ThenBy(x => x.StandardID)
  135. .ThenBy(x => x.ClassmajorNo)
  136. .ThenBy(x => x.LoginID);
  137. var result = query.ToList();
  138. result.ForEach(x => x.RecordStatusDesc = statusViewList.Where(w => w.ID == x.RecordStatus).Select(w => w.Name).FirstOrDefault());
  139. return result;
  140. }
  141. public ScoreConvertByApplyView GetScoreConvertByApplyView(Guid? scoreConvertByApplyID)
  142. {
  143. var statusViewList = this.GetStatusViewList();
  144. var scoreConvertByApplyView = this.scoreConvertByApplyDAL.GetScoreConvertByApplyViewQueryable(x => x.ScoreConvertByApplyID == scoreConvertByApplyID,
  145. (x => true), (x => true), (x => true)).FirstOrDefault();
  146. if (scoreConvertByApplyView != null)
  147. {
  148. scoreConvertByApplyView.RecordStatusDesc = statusViewList.Where(x => x.ID == scoreConvertByApplyView.RecordStatus).Select(x => x.Name).FirstOrDefault();
  149. }
  150. return scoreConvertByApplyView;
  151. }
  152. public void Save(ScoreConvertByApplyView scoreConvertByApplyView, List<FileUploadView> fileList)
  153. {
  154. try
  155. {
  156. var statusViewList = this.GetStatusViewList();
  157. var status = this.GetStartStatus();
  158. var returnStatus = this.GetBackpointStatus();
  159. var schoolyear = schoolYearServices.GetCurrentSchoolYear();
  160. ER_ScoreConvertByApply dbScoreConvert = scoreConvertByApplyDAL.scoreConvertByApplyRepository.Entities.Where(x =>
  161. x.ScoreConvertByApplyID == scoreConvertByApplyView.ScoreConvertByApplyID
  162. && x.UserID == scoreConvertByApplyView.UserID
  163. && x.ScoreConvertByApplyID != scoreConvertByApplyView.ScoreConvertByApplyID).FirstOrDefault();
  164. if (dbScoreConvert != null)
  165. {
  166. throw new Exception("该课程已经申请过认定,不能重复申请。");
  167. }
  168. ER_ScoreConvertByApply scoreConvert = null;
  169. List<ER_ScoreConvertByApplyAttachment> addAttachmentList = new List<ER_ScoreConvertByApplyAttachment>();
  170. var dbScoreConvertByApply = scoreConvertByApplyDAL.scoreConvertByApplyRepository.GetSingle(x => x.ScoreConvertByApplyID == scoreConvertByApplyView.ScoreConvertByApplyID);
  171. if (dbScoreConvertByApply == null)
  172. {
  173. scoreConvert = new ER_ScoreConvertByApply();
  174. scoreConvert.ScoreConvertByApplyID = Guid.NewGuid();
  175. SetNewStatus(scoreConvert);
  176. UnitOfWork.Add(scoreConvert);
  177. if (fileList != null && fileList.Count > 0)
  178. {
  179. foreach (var file in fileList)
  180. {
  181. ER_ScoreConvertByApplyAttachment attachment = new ER_ScoreConvertByApplyAttachment();
  182. attachment.ScoreConvertByApplyAttachmentID = Guid.NewGuid();
  183. attachment.ScoreConvertByApplyID = scoreConvert.ScoreConvertByApplyID;
  184. attachment.Name = file.FileName;
  185. attachment.Url = file.FileUrl;
  186. this.SetNewStatus(attachment);
  187. scoreConvert.ER_ScoreConvertByApplyAttachment.Add(attachment);
  188. }
  189. }
  190. }
  191. else
  192. {
  193. scoreConvert = this.scoreConvertByApplyDAL.scoreConvertByApplyRepository
  194. .GetSingle(x => x.ScoreConvertByApplyID == scoreConvertByApplyView.ScoreConvertByApplyID);
  195. if (scoreConvert.RecordStatus != status && !returnStatus.Contains(scoreConvert.RecordStatus))
  196. {
  197. throw new Exception("该信息处于待审核或已通过状态,不能修改");
  198. }
  199. if (scoreConvert == null)
  200. {
  201. throw new Exception("当前编辑的记录可能已被其他人删除。");
  202. }
  203. SetModifyStatus(scoreConvert);
  204. if (scoreConvertByApplyView.IsChangeAttachment == 1)
  205. {
  206. UnitOfWork.Remove<ER_ScoreConvertByApplyAttachment>(x => x.ScoreConvertByApplyID == scoreConvertByApplyView.ScoreConvertByApplyID);
  207. if (fileList != null && fileList.Count > 0)
  208. {
  209. foreach (var file in fileList)
  210. {
  211. ER_ScoreConvertByApplyAttachment attachment = new ER_ScoreConvertByApplyAttachment();
  212. attachment.ScoreConvertByApplyAttachmentID = Guid.NewGuid();
  213. attachment.ScoreConvertByApplyID = scoreConvert.ScoreConvertByApplyID;
  214. attachment.Name = file.FileName;
  215. attachment.Url = file.FileUrl;
  216. this.SetNewStatus(attachment);
  217. scoreConvert.ER_ScoreConvertByApplyAttachment.Add(attachment);
  218. //addAttachmentList.Add(attachment);
  219. }
  220. }
  221. }
  222. }
  223. scoreConvert.SchoolyearID = schoolyear.SchoolYearID;
  224. scoreConvert.UserID = scoreConvertByApplyView.UserID;
  225. scoreConvert.CoursematerialID = scoreConvertByApplyView.CoursematerialID;
  226. scoreConvert.TotalScore = scoreConvertByApplyView.TotalScore;
  227. scoreConvert.Reason = scoreConvertByApplyView.Reason;
  228. UnitOfWork.Commit();
  229. }
  230. catch (Exception)
  231. {
  232. throw;
  233. }
  234. }
  235. public void Delete(IList<Guid?> scoreConvertByApplyIDList)
  236. {
  237. if (scoreConvertByApplyIDList.Count > 0)
  238. {
  239. var canDeleteStatus = new List<int?>();
  240. canDeleteStatus.Add(this.GetStartStatus());
  241. canDeleteStatus.AddRange(this.GetBackpointStatus());
  242. var canDeleteStatusDesc = this.GetStatusViewList().Where(x => canDeleteStatus.Contains(x.ID)).Select(x => x.Name);
  243. var scoreConvertByApplyList = scoreConvertByApplyDAL.scoreConvertByApplyRepository.GetList(x => scoreConvertByApplyIDList.Contains(x.ScoreConvertByApplyID)).ToList();
  244. if (scoreConvertByApplyList.Any(x => !canDeleteStatus.Contains(x.RecordStatus)))
  245. {
  246. throw new Exception("只能删除状态为" + string.Join("、", canDeleteStatusDesc) + "的记录。");
  247. }
  248. UnitOfWork.Delete<ER_ScoreConvertByApplyAttachment>(x => scoreConvertByApplyIDList.Contains(x.ScoreConvertByApplyID));
  249. UnitOfWork.Delete<ER_ScoreConvertByApply>(x => scoreConvertByApplyIDList.Contains(x.ScoreConvertByApplyID));
  250. }
  251. }
  252. public List<FileUploadView> GetFileList(Guid? formID)
  253. {
  254. //var socDetailAttachment = SOCDAL.SOCDetailAttachmentRepository.GetSingle(x => x.SOCDetailID == formID);
  255. var fileList = scoreConvertByApplyDAL.GetScoreConvertByApplyAttachmentView(x => x.ScoreConvertByApplyID == formID).ToList();
  256. return fileList;
  257. }
  258. public void Submit(List<Guid> scoreConvertByReplaceIDList, Guid? userID)
  259. {
  260. try
  261. {
  262. this.StartUp(scoreConvertByReplaceIDList, userID.Value);
  263. }
  264. catch (Exception)
  265. {
  266. throw;
  267. }
  268. }
  269. public void ScoreConvertByApplyApprove(List<Guid> idList, Guid userID, Guid actionID, string comment)
  270. {
  271. try
  272. {
  273. this.Approve(idList, userID, actionID, comment);
  274. }
  275. catch (Exception)
  276. {
  277. throw;
  278. }
  279. }
  280. public IGridResultSet<FileUploadView> GetAttachment(Guid? scoreConvertByApplyID, int? pageIndex, int? pageSize)
  281. {
  282. var attachment = scoreConvertByApplyDAL.GetScoreConvertByApplyAttachmentView(x => x.ScoreConvertByApplyID == scoreConvertByApplyID);
  283. return attachment.ToGridResultSet(pageIndex, pageSize);
  284. }
  285. public void OnApproveEnd(List<Guid> scoreConvertByApplyIDList, Guid? userID)
  286. {
  287. //获取默认绩点公式
  288. var gradePointFormula = scoreConvertByApplyDAL.GetDefaultGradePointFormula().FirstOrDefault();
  289. //ER_GradePointFormula
  290. var scoreConvertByApplyList = scoreConvertByApplyDAL.scoreConvertByApplyRepository.GetList(x => scoreConvertByApplyIDList.Contains(x.ScoreConvertByApplyID)).ToList();
  291. var selectKeyList = scoreConvertByApplyList.Select(x => new { x.UserID, CoursematerialID = x.CoursematerialID }).ToList();
  292. //var submitedScoreList = studentScoreDAL.submitedScoreRepository.Entities.SelectByKeys(selectKeyList);
  293. //var submitedScoreIDList = submitedScoreList.Select(x => (Guid?)x.SubmitedScoreID);
  294. //var submitedScoreDetailList = studentScoreDAL.SubmitedScoreDetailRepository.GetList(x => submitedScoreIDList.Contains(x.SubmitedScoreID)).ToList();
  295. //var finallyScoreList = studentScoreDAL.FinallyScoreRepository.Entities.SelectByKeys(selectKeyList);
  296. //var finallyScoreIDList = finallyScoreList.Select(x => (Guid?)x.FinallyScoreID);
  297. //var finallyScoreDetailList = studentScoreDAL.FinallyScoreDetailRepository.GetList(x => finallyScoreIDList.Contains(x.FinallyScoreID)).ToList();
  298. var lastCourseStarttermViewList = ExecutablePlanDAL.GetLastCourseStarttermViewQueryable().SelectByKeys(selectKeyList);
  299. //var insertSubmitedScoreBackupList = new List<ER_ScoreConvertedSubmitedScore>();
  300. //var insertSubmitedScoreDetailBackupList = new List<ER_ScoreConvertedSubmitedScoreDetail>();
  301. var insertSubmitedScoreList = new List<ER_SubmitedScore>();
  302. var insertSubmitedScoreDetailList = new List<ER_SubmitedScoreDetail>();
  303. foreach (var scoreConvertByApply in scoreConvertByApplyList)
  304. {
  305. var submitedScore = lastCourseStarttermViewList.FirstOrDefault(x => x.UserID == scoreConvertByApply.UserID && x.CoursematerialID == scoreConvertByApply.CoursematerialID);
  306. var insertSubmitedScore = new ER_SubmitedScore
  307. {
  308. SubmitedScoreID = Guid.NewGuid(),
  309. SchoolyearID = submitedScore.SchoolyearID,
  310. SchoolyearNumID = submitedScore.SchoolyearNumID,
  311. DepartmentID = submitedScore.DepartmentID,
  312. ClassName = submitedScore.ClassName,
  313. CoursematerialID = submitedScore.CoursematerialID,
  314. CourseTypeID = submitedScore.CourseTypeID,
  315. ExamsCategoryID = (int)EMIS.ViewModel.CF_ExamsCategory.FinalExam,
  316. ExaminationModeID = submitedScore.ExaminationModeID,
  317. HandleModeID = submitedScore.HandleModeID,
  318. Credit = submitedScore.Credit,
  319. TotalHours = submitedScore.TotalHours,
  320. ResultTypeID = submitedScore.ResultTypeID,
  321. CreatorUserID = userID,
  322. IsEntry = true,
  323. ExaminationType = (int)EMIS.ViewModel.CF_ExaminationType.FinalExamination,
  324. StarttermID = submitedScore.StarttermID,
  325. UserID = submitedScore.UserID,
  326. ExamsStateID = (int)CF_ExamsState.NormalExams,
  327. TotalScore = scoreConvertByApply.TotalScore,
  328. ScoreCredit = scoreConvertByApply.TotalScore >= 60 ? submitedScore.Credit : 0,
  329. GradePoint = gradePointFormula == null ? 0 : (scoreConvertByApply.TotalScore >= gradePointFormula.GradePointlimit ? (1 + gradePointFormula.GradePointFloor * (scoreConvertByApply.TotalScore - gradePointFormula.GradePointlimit)) : 0),
  330. Remark = Const.ER_SCORECONVERT_BYREPLACE_SCOREREMARK,
  331. RecordStatus = (int)SYS_STATUS.USABLE,
  332. CreateUserID = userID,
  333. CreateTime = DateTime.Now,
  334. ModifyUserID = userID,
  335. ModifyTime = DateTime.Now
  336. };
  337. insertSubmitedScoreList.Add(insertSubmitedScore);
  338. }
  339. var insertSubmitedScoreIDList = insertSubmitedScoreList.Select(x => x.SubmitedScoreID).ToList();
  340. using (var scope = new TransactionScope(TransactionScopeOption.Required))
  341. {
  342. UnitOfWork.BulkInsert(insertSubmitedScoreList);
  343. studentScoreServices.RefreshFinallyScoreBySubmitedScoreID(insertSubmitedScoreIDList);
  344. scope.Complete();
  345. }
  346. }
  347. }
  348. }