ScoreConvertByLevelServices.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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.ScoreManage;
  7. using EMIS.ViewModel;
  8. using EMIS.DataLogic.ScoreManage;
  9. using System.Linq.Expressions;
  10. using EMIS.Entities;
  11. using Bowin.Common.Linq;
  12. using EMIS.DataLogic.EducationManage;
  13. using EMIS.CommonLogic.SystemServices;
  14. using EMIS.Utility;
  15. namespace EMIS.CommonLogic.ScoreManage
  16. {
  17. public class ScoreConvertByLevelServices : BaseServices,IScoreConvertByLevelServices
  18. {
  19. public ScoreConvertByApplyDAL scoreConvertByApplyDAL { get; set; }
  20. public ScoreConvertByLevelDAL ScoreConvertByLevelDAL { get; set; }
  21. public ExecutablePlanDAL ExecutablePlanDAL { get; set; }
  22. public LevelScoreDAL levelScoreDAL { get; set; }
  23. public StudentScoreDAL studentScoreDAL { get; set; }
  24. public Lazy<IParameterServices> ParameterServices { get; set; }
  25. public LevelSettingDAL levelSettingDAL { get; set; }
  26. public Lazy<IStudentScoreServices> StudentScoreServices { get; set; }
  27. public IGridResultSet<ScoreConvertByLevelView> GetUniteMaintainViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID, int? yearID, int? standardID, Guid? classmajorID, Guid? coursematerialID, int pageIndex, int pageSize)
  28. {
  29. Expression<Func<ER_ScoreConvertByLevelScore, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  30. if (schoolyearID.HasValue)
  31. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  32. if (collegeID.HasValue)
  33. exp = exp.And(x => x.ER_LevelScore.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
  34. if (yearID.HasValue)
  35. exp = exp.And(x => x.ER_LevelScore.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == yearID);
  36. if (standardID.HasValue)
  37. exp = exp.And(x => x.ER_LevelScore.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
  38. if (classmajorID.HasValue)
  39. exp = exp.And(x => x.ER_LevelScore.CF_Student.ClassmajorID == classmajorID);
  40. if (coursematerialID.HasValue)
  41. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  42. var query = ScoreConvertByLevelDAL.GetScoreConvertByLevelViewQueryable(exp);
  43. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  44. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  45. return this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query)).OrderByDescending(x => x.SchoolyearCode)
  46. .ThenBy(x => x.CollegeName).ThenBy(x => x.StandardID).ThenBy(x => x.ClassmajorName).ToGridResultSet<ScoreConvertByLevelView>(pageIndex, pageSize);
  47. }
  48. public List<ScoreConvertByLevelView> GetScoreConvertByLevelView_Excel(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID, int? yearID, int? standardID, Guid? classmajorID, Guid? coursematerialID, List<Guid?> ScoreConvertByLevelScoreIDList)
  49. {
  50. Expression<Func<ER_ScoreConvertByLevelScore, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  51. if (schoolyearID.HasValue)
  52. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  53. if (collegeID.HasValue)
  54. exp = exp.And(x => x.ER_LevelScore.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
  55. if (yearID.HasValue)
  56. exp = exp.And(x => x.ER_LevelScore.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == yearID);
  57. if (standardID.HasValue)
  58. exp = exp.And(x => x.ER_LevelScore.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
  59. if (classmajorID.HasValue)
  60. exp = exp.And(x => x.ER_LevelScore.CF_Student.ClassmajorID == classmajorID);
  61. if (coursematerialID.HasValue)
  62. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  63. if(ScoreConvertByLevelScoreIDList!=null)
  64. exp = exp.And(x => ScoreConvertByLevelScoreIDList.Contains(x.ScoreConvertByLevelScoreID));
  65. var query = ScoreConvertByLevelDAL.GetScoreConvertByLevelViewQueryable(exp);
  66. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  67. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  68. return this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query)).OrderByDescending(x => x.SchoolyearCode)
  69. .ThenBy(x => x.CollegeName).ThenBy(x => x.StandardID).ThenBy(x => x.ClassmajorName).ToList();
  70. }
  71. public string Save(ScoreConvertByLevelView scoreConvertByLevelView)
  72. {
  73. //获取默认绩点公式
  74. var gradePointFormula = scoreConvertByApplyDAL.GetDefaultGradePointFormula().FirstOrDefault();
  75. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  76. //获取当前学年学期
  77. var SchoolyearID=ScoreConvertByLevelDAL.SchoolyearRepository.Entities.Where(x=>x.IsCurrent==true).FirstOrDefault();
  78. //获取过级成绩
  79. Expression<Func<ER_LevelScore, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  80. if (scoreConvertByLevelView.SchoolyearID.HasValue)
  81. exp = exp.And(x => x.SchoolyearID == scoreConvertByLevelView.SchoolyearID);
  82. if(scoreConvertByLevelView.CollegeID.HasValue)
  83. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.CollegeID == scoreConvertByLevelView.CollegeID);
  84. if (scoreConvertByLevelView.Year.HasValue && scoreConvertByLevelView.Year!=-1)
  85. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == scoreConvertByLevelView.Year);
  86. if (scoreConvertByLevelView.StandardID.HasValue && scoreConvertByLevelView.StandardID!=-1)
  87. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == scoreConvertByLevelView.StandardID);
  88. if(scoreConvertByLevelView.ClassmajorID.HasValue)
  89. exp = exp.And(x => x.CF_Student.CF_Classmajor.ClassmajorID == scoreConvertByLevelView.ClassmajorID);
  90. if (scoreConvertByLevelView.ExaminationFormID.HasValue && scoreConvertByLevelView.ExaminationFormID!=-1)
  91. exp = exp.And(x => x.EX_ExaminationSubject.ExaminationFormID == scoreConvertByLevelView.ExaminationFormID);
  92. if (scoreConvertByLevelView.ExaminationTypeID.HasValue)
  93. exp = exp.And(x => x.EX_ExaminationSubject.ExaminationTypeID == scoreConvertByLevelView.ExaminationTypeID);
  94. if (scoreConvertByLevelView.LevelScoreID.HasValue)
  95. exp = exp.And(x => x.ExaminationSubjectID == scoreConvertByLevelView.LevelScoreID);
  96. var LevelScoreList = levelScoreDAL.GetLevelScoreViewQueryable(exp).ToList();
  97. var queryLevelName = levelSettingDAL.GetLevelSettingViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  98. //获取课程
  99. int? retakeExamsCategoryID = ParameterServices.Value.GetParameterValue<int>(CF_ParameterType.RetakeExamsCatagoryID);
  100. var selectKeyList = LevelScoreList.Select(x => new { x.UserID, CoursematerialID = scoreConvertByLevelView.CoursematerialID }).ToList();
  101. var lastCourseStarttermViewList = ExecutablePlanDAL.GetLastCourseStarttermViewQueryable().SelectByKeys(selectKeyList);
  102. //获取现有数据
  103. var nowScoreConvertByLevelScore = ScoreConvertByLevelDAL.ScoreConvertByLevelScoreRepository.GetList(x => true).ToList();
  104. //处理数据
  105. List<ER_ScoreConvertByLevelScore> insertList = new List<ER_ScoreConvertByLevelScore>();
  106. List<ER_SubmitedScore> insertSubList = new List<ER_SubmitedScore>();
  107. List<ER_SubmitedScoreDetail> insertSubDetailList = new List<ER_SubmitedScoreDetail>();
  108. var scoreDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
  109. foreach (var level in LevelScoreList)
  110. {
  111. var UserLevelScore = LevelScoreList.Where(x => x.UserID == level.UserID).OrderByDescending(x => x.TotalScore).FirstOrDefault();
  112. var LevelPassScore=queryLevelName.Where(x=>x.ExaminationSubjectName==UserLevelScore.ExaminationSubjectName&&x.MinScore<=UserLevelScore.TotalScore&&x.MaxScore>=UserLevelScore.TotalScore).FirstOrDefault();
  113. var UserInCoursematerial = lastCourseStarttermViewList.Where(x => x.UserID == level.UserID).FirstOrDefault();
  114. var isExist = insertList.Where(x => x.LevelScoreID == UserLevelScore.LevelScoreID).FirstOrDefault();
  115. var isExists = nowScoreConvertByLevelScore.Where(x => x.LevelScoreID == UserLevelScore.LevelScoreID && x.CoursematerialID == scoreConvertByLevelView.CoursematerialID).FirstOrDefault();
  116. if (isExists==null)
  117. {
  118. if (isExist == null && UserLevelScore != null && UserInCoursematerial != null)
  119. {
  120. //插入已提交成绩表
  121. ER_SubmitedScore submitedScore = new ER_SubmitedScore();
  122. submitedScore.SubmitedScoreID = Guid.NewGuid();
  123. submitedScore.SchoolyearID = SchoolyearID.SchoolyearID;
  124. submitedScore.SchoolyearNumID = UserInCoursematerial.SchoolyearNumID;
  125. submitedScore.DepartmentID = UserInCoursematerial.DepartmentID;
  126. submitedScore.ClassName = UserInCoursematerial.ClassName;
  127. submitedScore.CoursematerialID = UserInCoursematerial.CoursematerialID;
  128. submitedScore.CourseTypeID = UserInCoursematerial.CourseTypeID;
  129. submitedScore.ExamsCategoryID = (int)EMIS.ViewModel.CF_ExamsCategory.FinalExam;
  130. submitedScore.ExaminationModeID = UserInCoursematerial.ExaminationModeID;
  131. submitedScore.HandleModeID = UserInCoursematerial.HandleModeID;
  132. submitedScore.Credit = UserInCoursematerial.Credit;
  133. submitedScore.TotalHours = UserInCoursematerial.TotalHours;
  134. submitedScore.ResultTypeID = UserInCoursematerial.ResultTypeID;
  135. submitedScore.CreatorUserID = curUser.UserID;
  136. submitedScore.IsEntry = true;
  137. submitedScore.ExaminationType = (int)EMIS.ViewModel.CF_ExaminationType.FinalExamination;
  138. submitedScore.StarttermID = UserInCoursematerial.StarttermID;
  139. submitedScore.UserID = UserInCoursematerial.UserID;
  140. submitedScore.ExamsStateID = (int)CF_ExamsState.NormalExams;
  141. submitedScore.TotalScore = UserLevelScore.TotalScore;
  142. if(LevelPassScore!=null){
  143. if(LevelPassScore.LevelName=="不合格"){
  144. submitedScore.ScoreCredit = 0;
  145. submitedScore.GradePoint = 0;
  146. }
  147. else
  148. {
  149. submitedScore.ScoreCredit = UserInCoursematerial.Credit;
  150. submitedScore.GradePoint = gradePointFormula == null ? 0 : (UserLevelScore.TotalScore >= gradePointFormula.GradePointlimit ? (1 + gradePointFormula.GradePointFloor * (UserLevelScore.TotalScore - gradePointFormula.GradePointlimit)) : 0);
  151. }
  152. }
  153. submitedScore.Remark = Const.ER_SCORECONVERT_BYREPLACE_SCOREREMARK;
  154. submitedScore.RecordStatus = (int)SYS_STATUS.USABLE;
  155. submitedScore.CreateUserID = curUser.UserID;
  156. submitedScore.CreateTime = DateTime.Now;
  157. submitedScore.ModifyUserID = curUser.UserID;
  158. submitedScore.ModifyTime = DateTime.Now;
  159. insertSubList.Add(submitedScore);
  160. foreach (var scoreDynamicType in scoreDynamicTypes)
  161. {
  162. ER_SubmitedScoreDetail SubmitedScoreDetail = new ER_SubmitedScoreDetail();
  163. SubmitedScoreDetail.SubmitedScoreDetailID = Guid.NewGuid();
  164. SubmitedScoreDetail.ScoreTypeID = scoreDynamicType.Value;
  165. SubmitedScoreDetail.SubmitedScoreID = submitedScore.SubmitedScoreID;
  166. SubmitedScoreDetail.Score = null;
  167. SetNewStatus(SubmitedScoreDetail);
  168. insertSubDetailList.Add(SubmitedScoreDetail);
  169. }
  170. //插入统一认定表
  171. ER_ScoreConvertByLevelScore ScoreConvertByLevelScore = new ER_ScoreConvertByLevelScore();
  172. ScoreConvertByLevelScore.ScoreConvertByLevelScoreID = Guid.NewGuid();
  173. ScoreConvertByLevelScore.SchoolyearID = SchoolyearID.SchoolyearID;
  174. ScoreConvertByLevelScore.LevelScoreID = UserLevelScore.LevelScoreID;
  175. ScoreConvertByLevelScore.CoursematerialID = scoreConvertByLevelView.CoursematerialID;
  176. ScoreConvertByLevelScore.TotalScore = UserLevelScore.TotalScore;
  177. SetNewStatus(ScoreConvertByLevelScore);
  178. ScoreConvertByLevelScore.ER_SubmitedScore.Add(submitedScore);
  179. insertList.Add(ScoreConvertByLevelScore);
  180. }
  181. }
  182. }
  183. UnitOfWork.BulkInsert(insertList);
  184. UnitOfWork.BulkInsert(insertSubList);
  185. UnitOfWork.BulkInsert(insertList,x=>x.ER_SubmitedScore);
  186. UnitOfWork.BulkInsert(insertSubDetailList);
  187. UnitOfWork.Commit();
  188. var insertSubIDList = insertSubList.Select(x => x.SubmitedScoreID).ToList();
  189. StudentScoreServices.Value.RefreshFinallyScoreBySubmitedScoreID(insertSubIDList);
  190. var success = "保存成功:一共替换了" + insertList.Count()+"条";
  191. return success;
  192. }
  193. public void Delete(List<Guid?> ScoreConvertByLevelScoreIDList)
  194. {
  195. try
  196. {
  197. var ScoreConvertByLevelScoreList = ScoreConvertByLevelDAL.ScoreConvertByLevelScoreRepository.GetList(x => ScoreConvertByLevelScoreIDList.Contains(x.ScoreConvertByLevelScoreID),(x=>x.ER_SubmitedScore)).ToList();
  198. List<Guid?> submitedScoerIDList = new List<Guid?>();
  199. foreach (var ScoreConvertByLevelScore in ScoreConvertByLevelScoreList)
  200. {
  201. var submitedScoerID = ScoreConvertByLevelScore.ER_SubmitedScore.Select(x => x.SubmitedScoreID).FirstOrDefault();
  202. //ScoreConvertByLevelScore.ER_SubmitedScore = new HashSet<ER_SubmitedScore>();
  203. submitedScoerIDList.Add(submitedScoerID);
  204. }
  205. StudentScoreServices.Value.RefreshFinallyScoreBeforeDelete(x => submitedScoerIDList.Contains(x.SubmitedScoreID));
  206. UnitOfWork.Delete(ScoreConvertByLevelScoreList,(x=>x.ER_SubmitedScore));
  207. UnitOfWork.Delete(ScoreConvertByLevelScoreList);
  208. UnitOfWork.Delete<ER_SubmitedScoreDetail>(x => submitedScoerIDList.Contains(x.SubmitedScoreID));
  209. UnitOfWork.Delete<ER_SubmitedScore>(x => submitedScoerIDList.Contains(x.SubmitedScoreID));
  210. UnitOfWork.Commit();
  211. }
  212. catch (Exception)
  213. {
  214. throw;
  215. }
  216. }
  217. }
  218. }