EvaluationTargetServices.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Common.EvaluationManage;
  6. using Bowin.Common.Linq.Entity;
  7. using EMIS.Entities;
  8. using EMIS.ViewModel;
  9. using System.Linq.Expressions;
  10. using EMIS.ViewModel.EvaluationManage;
  11. using EMIS.CommonLogic.SystemServices;
  12. using Bowin.Common.Linq;
  13. namespace EMIS.CommonLogic.EvaluationManage
  14. {
  15. public class EvaluationTargetServices : BaseServices, IEvaluationTargetServices
  16. {
  17. public EvaluationTargetDAL evaluationTargetDAL { get; set; }
  18. public ISerialNumberServices SerialNumberServices { get; set; }
  19. /// <summary>
  20. /// 查询评价指标信息
  21. /// </summary>
  22. /// <param name="configuretView">查询条件实体</param>
  23. /// <param name="tableID">评价表名ID</param>
  24. /// <param name="normID">评分标准ID</param>
  25. /// <param name="pageIndex">页码</param>
  26. /// <param name="pageSize">显示页数</param>
  27. /// <returns></returns>
  28. public IGridResultSet<EvaluationTargetView> GetEvaluationTargetViewGrid(ConfiguretView configuretView, Guid? tableID, Guid? normID, int pageIndex, int pageSize)
  29. {
  30. var query = evaluationTargetDAL.GetEvaluationTargetQueryable(x => true);
  31. if (tableID.HasValue && tableID != Guid.Empty)
  32. query = query.Where(x => x.TableID == tableID);
  33. if (normID.HasValue && normID != Guid.Empty)
  34. query = query.Where(x => x.NormID == normID);
  35. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  36. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.Code).OrderBy(x => x.OrderID).ToGridResultSet<EvaluationTargetView>(pageIndex, pageSize);
  37. return query.OrderBy(x => x.Code).OrderBy(x => x.OrderID).ToGridResultSet<EvaluationTargetView>(pageIndex, pageSize);
  38. }
  39. /// <summary>
  40. /// 查询评价指标信息
  41. /// </summary>
  42. /// <param name="configuretView">查询条件实体</param>
  43. /// <param name="tableID">评价表名ID</param>
  44. /// <param name="normID">评分标准ID</param>
  45. /// <returns></returns>
  46. public List<EvaluationTargetView> GetEvaluationTargetViewList(ConfiguretView configuretView, Guid? tableID, Guid? normID)
  47. {
  48. var query = evaluationTargetDAL.GetEvaluationTargetQueryable(x => true);
  49. if (tableID.HasValue && tableID != Guid.Empty)
  50. query = query.Where(x => x.TableID == tableID);
  51. if (normID.HasValue && normID != Guid.Empty)
  52. query = query.Where(x => x.NormID == normID);
  53. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  54. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.OrderID).ToList();
  55. return query.OrderBy(x => x.OrderID).ToList();
  56. }
  57. /// <summary>
  58. /// 获取评价指标信息
  59. /// </summary>
  60. /// <param name="targetID">主键ID</param>
  61. /// <returns></returns>
  62. public EM_EvaluationTarget GetEvaluationTarget(Guid? targetID)
  63. {
  64. //查询条件
  65. Expression<Func<EM_EvaluationTarget, bool>> expression = (x => x.EvaluationTargetID == targetID.Value);
  66. return evaluationTargetDAL.evaluationTargetRepository.GetSingle(expression);
  67. }
  68. /// <summary>
  69. /// 获取评分标准信息
  70. /// </summary>
  71. /// <param name="Name">评价指标名称</param>
  72. /// <returns></returns>
  73. public EMIS.Entities.EM_EvaluationTarget GetEvaluationTarget(string Name)
  74. {
  75. //查询条件
  76. Expression<Func<EMIS.Entities.EM_EvaluationTarget, bool>> expression = (x => x.Name == Name);
  77. return evaluationTargetDAL.evaluationTargetRepository.GetSingle(expression);
  78. }
  79. /// <summary>
  80. /// 获取评价指标信息
  81. /// </summary>
  82. /// <param name="targetID">主键ID</param>
  83. /// <returns></returns>
  84. public EvaluationTargetView GetEvaluationTargetView(Guid? targetID)
  85. {
  86. EvaluationTargetView evaluationTargetView = new EvaluationTargetView();
  87. if (targetID.HasValue && targetID != Guid.Empty)
  88. evaluationTargetView = evaluationTargetDAL.GetEvaluationTargetQueryable(x => true).Where(x => x.TargetID == targetID).FirstOrDefault();
  89. return evaluationTargetView;
  90. }
  91. /// <summary>
  92. /// 添加
  93. /// </summary>
  94. /// <param name="evaluationTarget">实体</param>
  95. /// <returns></returns>
  96. public bool EvaluationTargetAdd(EM_EvaluationTarget evaluationTarget)
  97. {
  98. try
  99. {
  100. UnitOfWork.Add(evaluationTarget);
  101. UnitOfWork.Commit();
  102. return true;
  103. }
  104. catch (Exception)
  105. {
  106. throw;
  107. }
  108. }
  109. /// <summary>
  110. /// 修改
  111. /// </summary>
  112. /// <param name="evaluationTarget">实体</param>
  113. /// <returns></returns>
  114. public bool EvaluationTargetUpdate(EM_EvaluationTarget evaluationTarget)
  115. {
  116. try
  117. {
  118. UnitOfWork.Update(evaluationTarget);
  119. UnitOfWork.Commit();
  120. return true;
  121. }
  122. catch (Exception)
  123. {
  124. throw;
  125. }
  126. }
  127. /// <summary>
  128. /// 删除
  129. /// </summary>
  130. /// <param name="targetIDs"></param>
  131. /// <returns></returns>
  132. public bool EvaluationTargetDelete(List<Guid> targetIDs)
  133. {
  134. try
  135. {
  136. UnitOfWork.Delete<EM_EvaluationTarget>(x => targetIDs.Contains(x.EvaluationTargetID));
  137. UnitOfWork.Commit();
  138. return true;
  139. }
  140. catch (Exception)
  141. {
  142. throw;
  143. }
  144. }
  145. /// <summary>
  146. /// 验证
  147. /// </summary>
  148. /// <param name="targetID"></param>
  149. /// <param name="code"></param>
  150. /// <param name="name"></param>
  151. public void Verification(Guid targetID, string code, string name)
  152. {
  153. var sameCode = evaluationTargetDAL.evaluationTargetRepository.GetSingle(x => x.Code == code && x.EvaluationTargetID != targetID);
  154. if (sameCode != null)
  155. {
  156. throw new Exception("评价指标代码已存在,请重新输入!");
  157. }
  158. var sameName = evaluationTargetDAL.evaluationTargetRepository.GetSingle(x => x.Name == name && x.EvaluationTargetID != targetID);
  159. if (sameName != null)
  160. {
  161. throw new Exception("评价指标名称已存在,请重新输入!");
  162. }
  163. }
  164. public bool ValidateEvaluationTarget(EvaluationTargetView model)
  165. {
  166. if (string.IsNullOrWhiteSpace(model.Name))
  167. {
  168. throw new Exception("指标名称不能为空!");
  169. }
  170. if (!model.TableID.HasValue || model.TableID == Guid.Empty)
  171. {
  172. throw new Exception("评价表不能为空!");
  173. }
  174. model.Name = model.Name.Trim();
  175. Expression<Func<EM_EvaluationTarget, bool>> nameFilter = w => w.Name == model.Name && w.EvaluationTableID == model.TableID;
  176. if (model.TargetID.HasValue && model.TargetID != Guid.Empty) //编辑状态
  177. {
  178. nameFilter = nameFilter.And(w => w.EvaluationTargetID != model.TargetID);
  179. }
  180. var hasName = evaluationTargetDAL.evaluationTargetRepository.Entities.Any(nameFilter);
  181. if (hasName)
  182. {
  183. throw new Exception("指标名称已存在!");
  184. }
  185. //var table = evaluationTargetDAL.evaluationTableRepository.GetSingle(w => w.TableID == model.TableID);
  186. //if (model.Weight > table.Weight || model.Weight < 0)
  187. //{
  188. // throw new Exception("指标权重 必须在0到" + table.Weight + "之间!");
  189. //}
  190. //var weightSum = evaluationTargetDAL.evaluationTargetRepository.GetList(w => w.TableID == model.TableID).Sum(s => s.Weight ?? 0);
  191. //weightSum += model.Weight.Value;
  192. //if (weightSum > table.Weight)
  193. //{
  194. // throw new Exception("指标权重 之和(" + weightSum + ")必须等于" + table.Weight + "!");
  195. //}
  196. return true;
  197. }
  198. public void SaveOrUpdateEvaluationTarget(EvaluationTargetView model)
  199. {
  200. ValidateEvaluationTarget(model);
  201. var user = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  202. EM_EvaluationTarget entity = new EM_EvaluationTarget();
  203. if (!model.TargetID.HasValue || model.TargetID == Guid.Empty)
  204. {
  205. var table = evaluationTargetDAL.evaluationTableRepository.GetSingle(w => w.EvaluationTableID == model.TableID);
  206. entity.EvaluationTargetID = Guid.NewGuid();
  207. entity.Code = SerialNumberServices.SetSN(table.Code);
  208. entity.CreateTime = DateTime.Now;
  209. entity.CreateUserID = user.UserID;
  210. UnitOfWork.Add(entity);
  211. }
  212. else
  213. {
  214. entity = GetEvaluationTarget(model.TargetID);
  215. Guid? tableID = entity.EvaluationTableID;
  216. if (evaluationTargetDAL.evaluationEnterRepository.Entities.Any(x => x.EM_EvaluationTable.EvaluationTableID == tableID))
  217. {
  218. throw new Exception("该信息已经被使用不能进行修改");
  219. }
  220. }
  221. entity.Name = model.Name;
  222. entity.EvaluationTableID = model.TableID;
  223. entity.EvaluationNormID = model.NormID;
  224. entity.OrderNo = model.OrderID;
  225. entity.Weight = model.Weight;
  226. entity.Remark = model.Remark;
  227. entity.ModifyUserID = user.UserID;
  228. entity.ModifyTime = DateTime.Now;
  229. UnitOfWork.Commit();
  230. }
  231. public IList<EM_EvaluationTarget> GetEvaluationTargetList(List<Guid> targetIDs)
  232. {
  233. return evaluationTargetDAL.evaluationTargetRepository.GetList(x => targetIDs.Contains(x.EvaluationTargetID)).ToList();
  234. }
  235. public IList<EM_EvaluationProject> GetEvaluationProjectList(Guid targetID)
  236. {
  237. return evaluationTargetDAL.evaluationProjectRepository.GetList(x => x.EvaluationTargetID == targetID).ToList();
  238. }
  239. }
  240. }