ScoreParameterSettingServices.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.ScoreManage;
  6. using EMIS.ViewModel.ScoreManage;
  7. using EMIS.Entities;
  8. namespace EMIS.CommonLogic.ScoreManage
  9. {
  10. public class ScoreParameterSettingServices : BaseServices, IScoreParameterSettingServices
  11. {
  12. public FinalExaminationDAL FinalExaminationDAL { get; set; }
  13. public ScoreParameterSettingDAL scoreParameterSettingDAL { get; set; }
  14. public ScoreParameterCollegeSettingDAL ScoreParameterCollegeSettingDAL { get; set; }
  15. public ScoreDAL scoreDAL { get; set; }
  16. public List<ViewModel.ScoreManage.ScoreParameterSettingView> GetScoreParameterSettingViewGrid()
  17. {
  18. return scoreParameterSettingDAL.GetScoreParameterSettingViewQueryable().ToList();
  19. }
  20. /// <summary>
  21. /// 添加
  22. /// </summary>
  23. /// <param name="listScoreParameterSetting"></param>
  24. public void ScoreParameterSettingServicesAdd(List<ScoreParameterSettingView> listScoreParameterSetting)
  25. {
  26. try
  27. {
  28. UnitOfWork.Delete<ER_ScoreParameterSetting>(x=>true);
  29. listScoreParameterSetting.ToList().ForEach(x =>
  30. {
  31. var detail = new ER_ScoreParameterSetting();
  32. detail.ScoreParameterSettingID = Guid.NewGuid();
  33. detail.ExamsTypeID = x.ExamsTypeID;
  34. detail.CourseTypeID = x.CourseTypeID;
  35. detail.ScoreFormulaID = x.ScoreFormulaID;
  36. detail.IsTotalFormula = x.IsTotalFormula;
  37. detail.CreditFormulaID = x.CreditFormulaID;
  38. detail.IsCreditFormula = x.IsCreditFormula;
  39. detail.GradePointFormulaID = x.GradePointFormulaID;
  40. detail.IsGradePointFormula = x.IsGradePointFormula;
  41. this.SetNewStatus(detail);
  42. UnitOfWork.Add(detail);
  43. });
  44. this.UnitOfWork.Commit();
  45. }
  46. catch (Exception)
  47. {
  48. throw;
  49. }
  50. }
  51. /// <summary>
  52. /// 获取优先设置
  53. /// </summary>
  54. /// <param name="examsTypeID">考试类型</param>
  55. /// <param name="courseTypeID">课程类型</param>
  56. /// <returns></returns>
  57. public ScoreParameterSettingView GetScoreParameterSettingList(Guid? finalExaminationID)
  58. {
  59. var finalExaminationView = FinalExaminationDAL.GetFinalExaminationViewQueryable(x => x.FinalExaminationID == finalExaminationID).FirstOrDefault();
  60. if (finalExaminationView == null)
  61. {
  62. throw new Exception("获取公式设置失败,找不到对应的期末设定。");
  63. }
  64. var studentScoreList = scoreDAL.ScoreRepository.GetList(x => x.FinalExaminationID == finalExaminationID).ToList();
  65. var ScoreParameterSettingList=GetScoreParameterSettingList(finalExaminationView.CollegeID, finalExaminationView.GradeYearID, finalExaminationView.ExamsCategoryID, finalExaminationView.CourseTypeID);
  66. if (studentScoreList.Count>0)
  67. {
  68. foreach (var studentScore in studentScoreList)
  69. {
  70. if (studentScore.RecordStatus== (int)EMIS.ViewModel.SYS_STATUS.UNUSABLE)
  71. {
  72. ScoreParameterSettingList.IsTotalFormula = false;
  73. ScoreParameterSettingList.IsCreditFormula = false;
  74. ScoreParameterSettingList.IsGradePointFormula = false;
  75. break;
  76. }
  77. }
  78. }
  79. return ScoreParameterSettingList;
  80. }
  81. public ScoreParameterSettingView GetScoreParameterSettingList(Guid? collegeID, int? year, int? examsCategoryID, int? courseTypeID)
  82. {
  83. ScoreParameterSettingView scoreParameterSetting = new ScoreParameterSettingView();
  84. List<ScoreParameterSettingView> commonScoreParameterSettingList = this.GetScoreParameterSettingViewGrid().ToList(); ;
  85. List<ScoreParameterSettingView> collegeScoreParameterSettingList = commonScoreParameterSettingList;
  86. //获取各院系的个性化设置,优先获取指定了自己院系的设置
  87. var collegeScoreParameterSetting = this.ScoreParameterCollegeSettingDAL
  88. .GetScoreParameterCollegeSettingViewQueryable(x => x.Years == year
  89. && x.CollegeID == collegeID).FirstOrDefault();
  90. //找不到再找该年级的通用设置
  91. if (collegeScoreParameterSetting == null)
  92. {
  93. collegeScoreParameterSetting = this.ScoreParameterCollegeSettingDAL
  94. .GetScoreParameterCollegeSettingViewQueryable(x => x.Years == year
  95. && x.CollegeID == null).FirstOrDefault();
  96. }
  97. //有可能以上两种都没有,所以要判断一下
  98. if (collegeScoreParameterSetting != null)
  99. {
  100. collegeScoreParameterSettingList = this.ScoreParameterCollegeSettingDAL
  101. .GetScoreParameterSettingViewQueryable(x => x.ScoreParameterCollegeSettingID == collegeScoreParameterSetting.ScoreParameterCollegeSettingID)
  102. .ToList();
  103. }
  104. //总分公式、学分公式和绩点公式是分开读取的,未必来源于同一条设置
  105. #region 先找总分公式
  106. #region 按个性化设置先找
  107. var totalScoreParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID
  108. && x.ExamsTypeID == examsCategoryID && x.ScoreFormulaID != null);
  109. if (totalScoreParameterSetting == null)
  110. {
  111. totalScoreParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID
  112. && x.ExamsTypeID == null && x.ScoreFormulaID != null);
  113. }
  114. if (totalScoreParameterSetting == null)
  115. {
  116. totalScoreParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null
  117. && x.ExamsTypeID == examsCategoryID && x.ScoreFormulaID != null);
  118. }
  119. if (totalScoreParameterSetting == null)
  120. {
  121. totalScoreParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null && x.ExamsTypeID == null);
  122. }
  123. scoreParameterSetting.ScoreFormulaID = totalScoreParameterSetting.ScoreFormulaID;
  124. scoreParameterSetting.IsTotalFormula = totalScoreParameterSetting.IsTotalFormula;
  125. #endregion
  126. #region 再按通用设置找
  127. if (scoreParameterSetting.ScoreFormulaID == null)
  128. {
  129. totalScoreParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID
  130. && x.ExamsTypeID == examsCategoryID && x.ScoreFormulaID != null);
  131. if (totalScoreParameterSetting == null)
  132. {
  133. totalScoreParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID
  134. && x.ExamsTypeID == null && x.ScoreFormulaID != null);
  135. }
  136. if (totalScoreParameterSetting == null)
  137. {
  138. totalScoreParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null
  139. && x.ExamsTypeID == examsCategoryID && x.ScoreFormulaID != null);
  140. }
  141. if (totalScoreParameterSetting == null)
  142. {
  143. totalScoreParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null && x.ExamsTypeID == null);
  144. }
  145. scoreParameterSetting.ScoreFormulaID = totalScoreParameterSetting.ScoreFormulaID;
  146. scoreParameterSetting.IsTotalFormula = totalScoreParameterSetting.IsTotalFormula;
  147. }
  148. #endregion
  149. #endregion
  150. #region 再找学分公式
  151. #region 按个性化设置先找
  152. var creditParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID
  153. && x.ExamsTypeID == examsCategoryID && x.CreditFormulaID != null);
  154. if (creditParameterSetting == null)
  155. {
  156. creditParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID
  157. && x.ExamsTypeID == null && x.CreditFormulaID != null);
  158. }
  159. if (creditParameterSetting == null)
  160. {
  161. creditParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null
  162. && x.ExamsTypeID == examsCategoryID && x.CreditFormulaID != null);
  163. }
  164. if (creditParameterSetting == null)
  165. {
  166. creditParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null && x.ExamsTypeID == null);
  167. }
  168. scoreParameterSetting.CreditFormulaID = creditParameterSetting.CreditFormulaID;
  169. scoreParameterSetting.IsCreditFormula = creditParameterSetting.IsCreditFormula;
  170. #endregion
  171. #region 再按通用设置找
  172. if (scoreParameterSetting.CreditFormulaID == null)
  173. {
  174. creditParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID
  175. && x.ExamsTypeID == examsCategoryID && x.CreditFormulaID != null);
  176. if (creditParameterSetting == null)
  177. {
  178. creditParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID
  179. && x.ExamsTypeID == null && x.CreditFormulaID != null);
  180. }
  181. if (creditParameterSetting == null)
  182. {
  183. creditParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null
  184. && x.ExamsTypeID == examsCategoryID && x.CreditFormulaID != null);
  185. }
  186. if (creditParameterSetting == null)
  187. {
  188. creditParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null && x.ExamsTypeID == null);
  189. }
  190. scoreParameterSetting.CreditFormulaID = creditParameterSetting.CreditFormulaID;
  191. scoreParameterSetting.IsCreditFormula = creditParameterSetting.IsCreditFormula;
  192. }
  193. #endregion
  194. #endregion
  195. #region 再找绩点公式
  196. #region 按个性化设置先找
  197. var gradePointParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID
  198. && x.ExamsTypeID == examsCategoryID && x.GradePointFormulaID != null);
  199. if (gradePointParameterSetting == null)
  200. {
  201. gradePointParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID
  202. && x.ExamsTypeID == null && x.GradePointFormulaID != null);
  203. }
  204. if (gradePointParameterSetting == null)
  205. {
  206. gradePointParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null
  207. && x.ExamsTypeID == examsCategoryID && x.GradePointFormulaID != null);
  208. }
  209. if (gradePointParameterSetting == null)
  210. {
  211. gradePointParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null && x.ExamsTypeID == null);
  212. }
  213. scoreParameterSetting.GradePointFormulaID = gradePointParameterSetting.GradePointFormulaID;
  214. scoreParameterSetting.IsGradePointFormula = gradePointParameterSetting.IsGradePointFormula;
  215. #endregion
  216. #region 再按通用设置找
  217. if (scoreParameterSetting.GradePointFormulaID == null)
  218. {
  219. gradePointParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID
  220. && x.ExamsTypeID == examsCategoryID && x.GradePointFormulaID != null);
  221. if (gradePointParameterSetting == null)
  222. {
  223. gradePointParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID
  224. && x.ExamsTypeID == null && x.GradePointFormulaID != null);
  225. }
  226. if (gradePointParameterSetting == null)
  227. {
  228. gradePointParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null
  229. && x.ExamsTypeID == examsCategoryID && x.GradePointFormulaID != null);
  230. }
  231. if (gradePointParameterSetting == null)
  232. {
  233. gradePointParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null && x.ExamsTypeID == null);
  234. }
  235. scoreParameterSetting.GradePointFormulaID = gradePointParameterSetting.GradePointFormulaID;
  236. scoreParameterSetting.IsGradePointFormula = gradePointParameterSetting.IsGradePointFormula;
  237. }
  238. #endregion
  239. #endregion
  240. return scoreParameterSetting;
  241. }
  242. }
  243. }