ScoreFormulaServices.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.ScoreManage;
  6. using Bowin.Common.Linq.Entity;
  7. using EMIS.Entities;
  8. using EMIS.ViewModel;
  9. using EMIS.ViewModel.ScoreManage;
  10. using EMIS.DataLogic.Repositories;
  11. namespace EMIS.CommonLogic.ScoreManage
  12. {
  13. public class ScoreFormulaServices : BaseServices, IScoreFormulaServices
  14. {
  15. public CustomScoreFormulaRepository CustomScoreFormulaRepository { get; set; }
  16. public ScoreFormulaDAL scoreFormulaDAL { get; set; }
  17. /// <summary>
  18. /// 查询成绩公式设置列表
  19. /// </summary>
  20. /// <param name="name"></param>
  21. /// <param name="pageIndex"></param>
  22. /// <param name="pageSize"></param>
  23. /// <returns></returns>
  24. public Bowin.Common.Linq.Entity.IGridResultSet<Entities.ER_ScoreFormula> GetScoreFormulaGrid(string name, int pageIndex, int pageSize)
  25. {
  26. var query = scoreFormulaDAL.scoreFormulaRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  27. if (!string.IsNullOrEmpty(name))
  28. query = query.Where(x => name.Contains(x.Name));
  29. return query.OrderByDescending(x => x.CreateTime).ToGridResultSet<ER_ScoreFormula>(pageIndex, pageSize);
  30. }
  31. /// <summary>
  32. /// 查询成绩公式设置列表
  33. /// </summary>
  34. /// <param name="name"></param>
  35. /// <param name="pageIndex"></param>
  36. /// <param name="pageSize"></param>
  37. /// <returns></returns>
  38. public List<Entities.ER_ScoreFormula> GetScoreFormulaList(string name)
  39. {
  40. var query = scoreFormulaDAL.scoreFormulaRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE, (x => x.ER_ScoreFormulaDetail));
  41. if (!string.IsNullOrEmpty(name))
  42. query = query.Where(x => name.Contains(x.Name));
  43. return query.OrderByDescending(x => x.CreateTime).ToList();
  44. }
  45. // <summary>
  46. /// 查询成绩公式设置列表
  47. /// </summary>
  48. /// <param name="name"></param>
  49. /// <param name="pageIndex"></param>
  50. /// <param name="pageSize"></param>
  51. /// <returns></returns>
  52. public List<ScoreFormulaDropdownView> GetScoreFormulaDropdownViewList(string name)
  53. {
  54. var query = scoreFormulaDAL.scoreFormulaRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE, (x => x.ER_ScoreFormulaDetail));
  55. if (!string.IsNullOrEmpty(name))
  56. query = query.Where(x => name.Contains(x.Name));
  57. var list = query.OrderByDescending(x => x.CreateTime).ToList();
  58. var result = new List<ScoreFormulaDropdownView>();
  59. list.ForEach(x => result.Add(new ScoreFormulaDropdownView
  60. {
  61. ScoreFormulaID = x.ScoreFormulaID,
  62. Name = x.Name,
  63. ScoreFormulaDetail = x.ER_ScoreFormulaDetail.Select(w => new ScoreFormulaDropdownDetailView
  64. {
  65. ScoreFormulaDetailID = w.ScoreFormulaDetailID,
  66. ScoreFormulaID = w.ScoreFormulaID,
  67. ScoreType = w.ScoreType,
  68. Percentage = w.Percentage,
  69. IsRequirePass = w.IsRequirePass,
  70. PassScore=w.PassScore
  71. }).ToList()
  72. }));
  73. return result;
  74. }
  75. /// <summary>
  76. /// 添加
  77. /// </summary>
  78. /// <param name="scoreFormulaView"></param>
  79. public void ScoreFormulaAdd(ScoreFormulaView scoreFormulaView, List<ScoreFormulaDropdownDetailView> scoreFormulaDetailList)
  80. {
  81. try
  82. {
  83. ER_ScoreFormula scoreFormula = null;
  84. if (scoreFormulaView.ScoreFormulaID == null || scoreFormulaView.ScoreFormulaID == Guid.Empty)
  85. {
  86. scoreFormula = new ER_ScoreFormula();
  87. scoreFormula.ScoreFormulaID = Guid.NewGuid();
  88. scoreFormula.Name = scoreFormulaView.Name;
  89. SetNewStatus(scoreFormula);
  90. UnitOfWork.Add(scoreFormula);
  91. scoreFormula.ER_ScoreFormulaDetail = new HashSet<ER_ScoreFormulaDetail>();
  92. foreach (var scoreDetail in scoreFormulaDetailList)
  93. {
  94. if (scoreDetail.IsRequirePass == true && scoreDetail.PassScore == null)
  95. {
  96. throw new Exception("勾选必须通过的项没有设置必须通过成绩!");
  97. }
  98. ER_ScoreFormulaDetail scoreFormulaDetail = new ER_ScoreFormulaDetail();
  99. scoreFormulaDetail.ScoreFormulaDetailID = Guid.NewGuid();
  100. scoreFormulaDetail.ScoreFormulaID = scoreFormula.ScoreFormulaID;
  101. scoreFormulaDetail.ScoreType = scoreDetail.ScoreType;
  102. scoreFormulaDetail.Percentage = scoreDetail.Percentage;
  103. scoreFormulaDetail.IsRequirePass = scoreDetail.IsRequirePass;
  104. if (scoreDetail.PassScoreStr != "" && scoreDetail.PassScoreStr != null)
  105. {
  106. scoreFormulaDetail.PassScore = Convert.ToDecimal(scoreDetail.PassScoreStr);
  107. }
  108. else {
  109. scoreFormulaDetail.PassScore = null;
  110. }
  111. SetNewStatus(scoreFormulaDetail);
  112. UnitOfWork.Add(scoreFormulaDetail);
  113. }
  114. }
  115. else
  116. {
  117. scoreFormula = GetScoreFormula(scoreFormulaView.ScoreFormulaID);
  118. if(scoreFormula == null)
  119. throw new Exception("未找到相对应的成绩公式设置!");
  120. scoreFormula.Name = scoreFormulaView.Name;
  121. SetModifyStatus(scoreFormula);
  122. scoreFormula.ER_ScoreFormulaDetail = new HashSet<ER_ScoreFormulaDetail>();
  123. foreach (var scoreDetail in scoreFormulaDetailList)
  124. {
  125. if (scoreDetail.IsRequirePass == true && scoreDetail.PassScore == null)
  126. {
  127. throw new Exception("勾选必须通过的项没有设置必须通过成绩!");
  128. }
  129. ER_ScoreFormulaDetail scoreFormulaDetail = new ER_ScoreFormulaDetail();
  130. scoreFormulaDetail.ScoreFormulaDetailID = Guid.NewGuid();
  131. scoreFormulaDetail.ScoreFormulaID = scoreFormula.ScoreFormulaID;
  132. scoreFormulaDetail.ScoreType = scoreDetail.ScoreType;
  133. scoreFormulaDetail.Percentage = scoreDetail.Percentage;
  134. scoreFormulaDetail.IsRequirePass = scoreDetail.IsRequirePass;
  135. if (scoreDetail.PassScoreStr != "" && scoreDetail.PassScoreStr != null)
  136. {
  137. scoreFormulaDetail.PassScore = Convert.ToDecimal(scoreDetail.PassScoreStr);
  138. }
  139. else
  140. {
  141. scoreFormulaDetail.PassScore = null;
  142. }
  143. SetNewStatus(scoreFormulaDetail);
  144. UnitOfWork.Add(scoreFormulaDetail);
  145. }
  146. }
  147. UnitOfWork.Commit();
  148. }
  149. catch (Exception)
  150. {
  151. throw;
  152. }
  153. }
  154. /// <summary>
  155. /// 删除
  156. /// </summary>
  157. /// <param name="scoreFormulaIDs"></param>
  158. public void ScoreFormulaDelete(List<Guid> scoreFormulaIDs)
  159. {
  160. try
  161. {
  162. if (scoreFormulaIDs.Count > 0)
  163. {
  164. UnitOfWork.Delete<ER_ScoreFormula>(x => scoreFormulaIDs.Contains(x.ScoreFormulaID));
  165. }
  166. }
  167. catch (Exception)
  168. {
  169. throw;
  170. }
  171. }
  172. /// <summary>
  173. /// 根据ID获取成绩公式设置
  174. /// </summary>
  175. /// <param name="scoreFormulaID"></param>
  176. /// <returns></returns>
  177. public ER_ScoreFormula GetScoreFormula(Guid? scoreFormulaID)
  178. {
  179. return scoreFormulaDAL.scoreFormulaRepository.GetSingle(x => x.ScoreFormulaID == scoreFormulaID, (x => x.ER_ScoreFormulaDetail));
  180. }
  181. /// <summary>
  182. /// 根据成绩公式设置ID查询明细
  183. /// </summary>
  184. /// <param name="scoreFormulaID"></param>
  185. /// <returns></returns>
  186. public List<ER_ScoreFormulaDetail> GetScoreFormulaDetailList(Guid? scoreFormulaID)
  187. {
  188. if (scoreFormulaID == null)
  189. {
  190. return new List<ER_ScoreFormulaDetail>();
  191. }
  192. return scoreFormulaDAL.scoreFormulaDetailRepository
  193. .GetList(x => x.ScoreFormulaID == scoreFormulaID).OrderBy(x => x.ScoreType).ToList();
  194. }
  195. /// <summary>
  196. /// 根据成绩公式设置ID查询明细
  197. /// </summary>
  198. /// <param name="scoreFormulaID"></param>
  199. /// <returns></returns>
  200. public List<ScoreFormulaDropdownDetailView> GetScoreFormulaDetailListByScoreFormulaID(Guid? scoreFormulaID)
  201. {
  202. if (scoreFormulaID == null)
  203. {
  204. return new List<ScoreFormulaDropdownDetailView>();
  205. }
  206. return scoreFormulaDAL.GetScoreFormulaDetailViewQueryableByID(scoreFormulaID.Value).ToList();
  207. }
  208. public List<ER_CustomScoreFormula> GetCustomerScoreFormula()
  209. {
  210. return this.CustomScoreFormulaRepository.Entities.ToList();
  211. }
  212. }
  213. }