EvaluationProjectServices.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 EvaluationProjectServices : BaseServices, IEvaluationProjectServices
  16. {
  17. public EvaluationProjectDAL evaluationProjectDAL { get; set; }
  18. public ISerialNumberServices SerialNumberServices { get; set; }
  19. /// <summary>
  20. /// 查询评价项目信息
  21. /// </summary>
  22. /// <param name="configuretView">查询条件实体</param>
  23. /// <param name="targetID">评价指标</param>
  24. /// <param name="tableID">评价表</param>
  25. /// <param name="normID">评价标准</param>
  26. /// <param name="pageIndex">页码</param>
  27. /// <param name="pageSize">显示页数</param>
  28. /// <returns></returns>
  29. public IGridResultSet<EvaluationProjectView> GetEvaluationProjectViewGrid(ConfiguretView configuretView, Guid? targetID, Guid? tableID, Guid? normID, int pageIndex, int pageSize)
  30. {
  31. var query = evaluationProjectDAL.GetEvaluationProjectQueryable(x => true);
  32. if (targetID.HasValue && targetID != Guid.Empty)
  33. query = query.Where(x => x.TargetID == targetID);
  34. if (tableID.HasValue && tableID != Guid.Empty)
  35. query = query.Where(x => x.TableID == tableID);
  36. if (normID.HasValue && normID != Guid.Empty)
  37. query = query.Where(x => x.NormID == normID);
  38. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  39. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.Code).OrderBy(x => x.OrderID).ToGridResultSet<EvaluationProjectView>(pageIndex, pageSize);
  40. return query.OrderBy(x => x.Code).OrderBy(x => x.OrderID).ToGridResultSet<EvaluationProjectView>(pageIndex, pageSize);
  41. }
  42. /// <summary>
  43. /// 查询评价项目信息
  44. /// </summary>
  45. /// <param name="configuretView">查询条件实体</param>
  46. /// <param name="targetID">评价指标</param>
  47. /// <param name="tableID">评价表</param>
  48. /// <param name="normID">评价标准</param>
  49. /// <returns></returns>
  50. public List<EvaluationProjectView> GetEvaluationProjectViewList(ConfiguretView configuretView, Guid? targetID, Guid? tableID, Guid? normID)
  51. {
  52. var query = evaluationProjectDAL.GetEvaluationProjectQueryable(x => true);
  53. if (targetID.HasValue && targetID != Guid.Empty)
  54. query = query.Where(x => x.TargetID == targetID);
  55. if (tableID.HasValue && tableID != Guid.Empty)
  56. query = query.Where(x => x.TableID == tableID);
  57. if (normID.HasValue && normID != Guid.Empty)
  58. query = query.Where(x => x.NormID == normID);
  59. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  60. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.OrderID).ToList();
  61. return query.OrderBy(x => x.OrderID).ToList();
  62. }
  63. /// <summary>
  64. /// 获取评价项目信息
  65. /// </summary>
  66. /// <param name="projectID">主键ID</param>
  67. /// <returns></returns>
  68. public EM_EvaluationProject GetEvaluationProject(Guid? projectID)
  69. {
  70. //查询条件
  71. Expression<Func<EM_EvaluationProject, bool>> expression = (x => x.EvaluationProjectID == projectID.Value);
  72. return evaluationProjectDAL.evaluationProjectRepository.GetSingle(expression);
  73. }
  74. /// <summary>
  75. /// 获取评价项目信息
  76. /// </summary>
  77. /// <param name="Name">项目名称</param>
  78. /// <returns></returns>
  79. public EM_EvaluationProject GetEvaluationProject(string Name)
  80. {
  81. //查询条件
  82. Expression<Func<EM_EvaluationProject, bool>> expression = (x => x.Name == Name);
  83. return evaluationProjectDAL.evaluationProjectRepository.GetSingle(expression);
  84. }
  85. /// <summary>
  86. /// 获取评价项目信息
  87. /// </summary>
  88. /// <param name="projectID">主键ID</param>
  89. /// <returns></returns>
  90. public EvaluationProjectView GetEvaluationProjectView(Guid? projectID)
  91. {
  92. EvaluationProjectView evaluationProjectView = new EvaluationProjectView();
  93. if (projectID.HasValue)
  94. evaluationProjectView = evaluationProjectDAL.GetEvaluationProjectQueryable(x => true).Where(x => x.ProjectID == projectID).FirstOrDefault();
  95. return evaluationProjectView;
  96. }
  97. public void SaveOrUpdateEvaluationProject(EvaluationProjectView model)
  98. {
  99. ValidateEvaluationProject(model);
  100. var user = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  101. EM_EvaluationProject entity;
  102. if (!model.ProjectID.HasValue || model.ProjectID == Guid.Empty)
  103. {
  104. var targer = evaluationProjectDAL.evaluationTargetRepository.GetSingle(w => w.EvaluationTargetID == model.TargetID);
  105. entity = new EM_EvaluationProject();
  106. entity.EvaluationProjectID = Guid.NewGuid();
  107. entity.Code = SerialNumberServices.SetSN(targer.Code);
  108. entity.CreateTime = DateTime.Now;
  109. entity.CreateUserID = user.UserID;
  110. UnitOfWork.Add(entity);
  111. }
  112. else
  113. {
  114. entity = GetEvaluationProject(model.ProjectID);
  115. Guid? tableID = evaluationProjectDAL.evaluationTargetRepository.GetList(x => x.EvaluationTargetID == entity.EvaluationTargetID).FirstOrDefault().EvaluationTableID;
  116. //评价表被使用,不能修改
  117. if (evaluationProjectDAL.evaluationEnterRepository.Entities.Any(x => x.EM_EvaluationTable.EvaluationTableID == tableID))
  118. {
  119. throw new Exception("该信息已经被使用不能进行修改");
  120. }
  121. }
  122. entity.Name = model.Name;
  123. entity.EvaluationTargetID = model.TargetID;
  124. entity.OrderNo = model.OrderID;
  125. entity.Weight = model.Weight;
  126. entity.Remark = model.Remark;
  127. entity.ModifyUserID = user.UserID;
  128. entity.ModifyTime = DateTime.Now;
  129. UnitOfWork.Commit();
  130. }
  131. /// <summary>
  132. /// 添加
  133. /// </summary>
  134. /// <param name="evaluationProject">实体</param>
  135. /// <returns></returns>
  136. public bool EvaluationProjectAdd(EM_EvaluationProject evaluationProject)
  137. {
  138. try
  139. {
  140. UnitOfWork.Add(evaluationProject);
  141. UnitOfWork.Commit();
  142. return true;
  143. }
  144. catch (Exception)
  145. {
  146. throw;
  147. }
  148. }
  149. /// <summary>
  150. /// 修改
  151. /// </summary>
  152. /// <param name="evaluationProject">实体</param>
  153. /// <returns></returns>
  154. public bool EvaluationProjectUpdate(EM_EvaluationProject evaluationProject)
  155. {
  156. try
  157. {
  158. UnitOfWork.Update(evaluationProject);
  159. UnitOfWork.Commit();
  160. return true;
  161. }
  162. catch (Exception)
  163. {
  164. throw;
  165. }
  166. }
  167. /// <summary>
  168. /// 删除
  169. /// </summary>
  170. /// <param name="projectIDs"></param>
  171. /// <returns></returns>
  172. public bool EvaluationProjectDelete(List<Guid> projectIDs)
  173. {
  174. try
  175. {
  176. UnitOfWork.Delete<EM_EvaluationProject>(x => projectIDs.Contains(x.EvaluationProjectID));
  177. UnitOfWork.Commit();
  178. return true;
  179. }
  180. catch (Exception)
  181. {
  182. throw;
  183. }
  184. }
  185. public bool ValidateEvaluationProject(EvaluationProjectView model)
  186. {
  187. if (string.IsNullOrWhiteSpace(model.Name))
  188. {
  189. throw new Exception("项目名称不能为空!");
  190. }
  191. model.Name = model.Name.Trim();
  192. if (evaluationProjectDAL.evaluationProjectRepository.GetList(x => x.Name == model.Name && x.EM_EvaluationTarget.EvaluationTableID == model.TableID
  193. && x.EvaluationProjectID != model.ProjectID).Count() > 0)
  194. {
  195. throw new Exception("项目名称对应的评价表已存在!");
  196. }
  197. // Expression<Func<EM_EvaluationProject, bool>> nameFilter = w => w.Name == model.Name;
  198. //if (model.ProjectID.HasValue && model.ProjectID != Guid.Empty) //编辑状态
  199. //{
  200. // EM_EvaluationProject evaluationProjectEntity = evaluationProjectDAL.evaluationProjectRepository.GetSingle(x => x.ProjectID == model.ProjectID, (x => x.EM_EvaluationTarget));
  201. // if (model.Name == evaluationProjectEntity.Name && model.TableID == evaluationProjectEntity.EM_EvaluationTarget.TableID && evaluationProjectEntity != null)
  202. // {
  203. // throw new Exception("项目名称对应的评价表已存在!");
  204. // }
  205. //}
  206. return true;
  207. }
  208. }
  209. }