EvaluationTargetServices.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using Bowin.Common.Linq;
  7. using Bowin.Common.Data;
  8. using Bowin.Common.Linq.Entity;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.EvaluationManage.EvaluationTable;
  12. using EMIS.DataLogic.EvaluationManage.EvaluationTable;
  13. namespace EMIS.CommonLogic.EvaluationManage.EvaluationTable
  14. {
  15. public class EvaluationTargetServices : BaseServices, IEvaluationTargetServices
  16. {
  17. public EvaluationTargetDAL EvaluationTargetDAL { get; set; }
  18. /// <summary>
  19. /// 查询对应的评价指标信息View
  20. /// </summary>
  21. /// <param name="configuretView"></param>
  22. /// <param name="evaluationParticipateTypeID"></param>
  23. /// <param name="evaluationTypeID"></param>
  24. /// <param name="evaluationTableID"></param>
  25. /// <param name="evaluationNormID"></param>
  26. /// <param name="pageIndex"></param>
  27. /// <param name="pageSize"></param>
  28. /// <returns></returns>
  29. public IGridResultSet<EvaluationTargetView> GetEvaluationTargetViewGrid(ConfiguretView configuretView, Guid? evaluationParticipateTypeID, Guid? evaluationTypeID, Guid? evaluationTableID, Guid? evaluationNormID, int pageIndex, int pageSize)
  30. {
  31. Expression<Func<EM_EvaluationTarget, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  32. if (evaluationTableID.HasValue)
  33. {
  34. exp = exp.And(x => x.EvaluationTableID == evaluationTableID);
  35. }
  36. if (evaluationNormID.HasValue)
  37. {
  38. exp = exp.And(x => x.EvaluationNormID == evaluationNormID);
  39. }
  40. var query = EvaluationTargetDAL.GetEvaluationTargetViewQueryable(exp);
  41. if (evaluationParticipateTypeID.HasValue)
  42. {
  43. query = query.Where(x => x.EvaluationParticipateTypeID == evaluationParticipateTypeID);
  44. }
  45. if (evaluationTypeID.HasValue)
  46. {
  47. query = query.Where(x => x.EvaluationTypeID == evaluationTypeID);
  48. }
  49. //查询条件
  50. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  51. {
  52. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  53. }
  54. return query.OrderBy(x => x.EvaluationTableCode.Length).ThenBy(x => x.EvaluationTableCode).ThenBy(x => x.OrderNo).ToGridResultSet<EvaluationTargetView>(pageIndex, pageSize);
  55. }
  56. /// <summary>
  57. /// 查询对应的评价指标信息List
  58. /// </summary>
  59. /// <param name="configuretView"></param>
  60. /// <param name="evaluationParticipateTypeID"></param>
  61. /// <param name="evaluationTypeID"></param>
  62. /// <param name="evaluationTableID"></param>
  63. /// <param name="evaluationNormID"></param>
  64. /// <returns></returns>
  65. public IList<EvaluationTargetView> GetEvaluationTargetViewList(ConfiguretView configuretView, Guid? evaluationParticipateTypeID, Guid? evaluationTypeID, Guid? evaluationTableID, Guid? evaluationNormID)
  66. {
  67. Expression<Func<EM_EvaluationTarget, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  68. if (evaluationTableID.HasValue)
  69. {
  70. exp = exp.And(x => x.EvaluationTableID == evaluationTableID);
  71. }
  72. if (evaluationNormID.HasValue)
  73. {
  74. exp = exp.And(x => x.EvaluationNormID == evaluationNormID);
  75. }
  76. var query = EvaluationTargetDAL.GetEvaluationTargetViewQueryable(exp);
  77. if (evaluationParticipateTypeID.HasValue)
  78. {
  79. query = query.Where(x => x.EvaluationParticipateTypeID == evaluationParticipateTypeID);
  80. }
  81. if (evaluationTypeID.HasValue)
  82. {
  83. query = query.Where(x => x.EvaluationTypeID == evaluationTypeID);
  84. }
  85. //查询条件
  86. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  87. {
  88. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  89. }
  90. return query.OrderBy(x => x.EvaluationTableCode.Length).ThenBy(x => x.EvaluationTableCode).ThenBy(x => x.OrderNo).ToList();
  91. }
  92. /// <summary>
  93. /// 查询对应的评价指标信息List
  94. /// </summary>
  95. /// <param name="evaluationTargetIDList"></param>
  96. /// <returns></returns>
  97. public IList<EM_EvaluationTarget> GetEvaluationTargetList(List<Guid?> evaluationTargetIDList)
  98. {
  99. Expression<Func<EM_EvaluationTarget, bool>> expEvaluationTarget = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  100. expEvaluationTarget = expEvaluationTarget.And(x => evaluationTargetIDList.Contains(x.EvaluationTargetID));
  101. var query = EvaluationTargetDAL.EvaluationTargetRepository.GetList(expEvaluationTarget);
  102. return query.OrderBy(x => x.Code.Length).ThenBy(x => x.Code).ThenBy(x => x.OrderNo).ToList();
  103. }
  104. /// <summary>
  105. /// 查询对应的评价指标信息EvaluationTargetView
  106. /// </summary>
  107. /// <param name="evaluationTargetID"></param>
  108. /// <returns></returns>
  109. public EvaluationTargetView GetEvaluationTargetView(Guid? evaluationTargetID)
  110. {
  111. try
  112. {
  113. Expression<Func<EM_EvaluationTarget, bool>> exp = (x => x.EvaluationTargetID == evaluationTargetID);
  114. var query = EvaluationTargetDAL.GetEvaluationTargetViewQueryable(exp).SingleOrDefault();
  115. return query;
  116. }
  117. catch (Exception ex)
  118. {
  119. throw new Exception(ex.Message);
  120. }
  121. }
  122. /// <summary>
  123. /// 编辑
  124. /// </summary>
  125. /// <param name="evaluationTargetView"></param>
  126. public void EvaluationTargetEdit(EvaluationTargetView evaluationTargetView)
  127. {
  128. try
  129. {
  130. var evaluationTargetVerify = EvaluationTargetDAL.EvaluationTargetRepository.GetList(x => x.EvaluationTargetID != evaluationTargetView.EvaluationTargetID && x.Code == evaluationTargetView.Code.Trim()).SingleOrDefault();
  131. if (evaluationTargetVerify == null)
  132. {
  133. if (evaluationTargetView.EvaluationTargetID != Guid.Empty)
  134. {
  135. var evaluationTarget = EvaluationTargetDAL.EvaluationTargetRepository.GetList(x => x.EvaluationTargetID == evaluationTargetView.EvaluationTargetID).SingleOrDefault();
  136. if (evaluationTarget == null)
  137. {
  138. throw new Exception("数据有误,请核查。");
  139. }
  140. else
  141. {
  142. //表示修改
  143. evaluationTarget.OrderNo = evaluationTargetView.OrderNo;
  144. evaluationTarget.Code = evaluationTargetView.Code.Trim();
  145. evaluationTarget.Name = evaluationTargetView.Name.Trim();
  146. evaluationTarget.EvaluationTableID = evaluationTargetView.EvaluationTableID;
  147. evaluationTarget.EvaluationNormID = evaluationTargetView.EvaluationNormID;
  148. evaluationTarget.Weight = evaluationTargetView.Weight;
  149. evaluationTarget.Remark = evaluationTargetView.Remark;
  150. SetModifyStatus(evaluationTarget);
  151. }
  152. }
  153. else
  154. {
  155. //表示新增
  156. var newEvaluationTarget = new EM_EvaluationTarget();
  157. newEvaluationTarget.EvaluationTargetID = Guid.NewGuid();
  158. newEvaluationTarget.OrderNo = evaluationTargetView.OrderNo;
  159. newEvaluationTarget.Code = evaluationTargetView.Code.Trim();
  160. newEvaluationTarget.Name = evaluationTargetView.Name.Trim();
  161. newEvaluationTarget.EvaluationTableID = evaluationTargetView.EvaluationTableID;
  162. newEvaluationTarget.EvaluationNormID = evaluationTargetView.EvaluationNormID;
  163. newEvaluationTarget.Weight = evaluationTargetView.Weight;
  164. newEvaluationTarget.Remark = evaluationTargetView.Remark;
  165. SetNewStatus(newEvaluationTarget);
  166. UnitOfWork.Add(newEvaluationTarget);
  167. }
  168. }
  169. else
  170. {
  171. throw new Exception("已存在相同的评价指标信息(指标编号唯一),请核查。");
  172. }
  173. UnitOfWork.Commit();
  174. }
  175. catch (Exception ex)
  176. {
  177. throw new Exception(ex.Message);
  178. }
  179. }
  180. /// <summary>
  181. /// 删除
  182. /// </summary>
  183. /// <param name="evaluationTargetIDs"></param>
  184. /// <returns></returns>
  185. public bool EvaluationTargetDelete(List<Guid?> evaluationTargetIDs)
  186. {
  187. try
  188. {
  189. UnitOfWork.Delete<EM_EvaluationTarget>(x => evaluationTargetIDs.Contains(x.EvaluationTargetID));
  190. return true;
  191. }
  192. catch (Exception)
  193. {
  194. throw;
  195. }
  196. }
  197. }
  198. }