EvaluationTableServices.cs 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 Bowin.Common.Linq;
  12. namespace EMIS.CommonLogic.EvaluationManage
  13. {
  14. public class EvaluationTableServices : BaseServices, IEvaluationTableServices
  15. {
  16. public EvaluationTableDAL evaluationTableDAL { get; set; }
  17. /// <summary>
  18. /// 查询评价表信息
  19. /// </summary>
  20. /// <param name="configuretView">查询条件实体</param>
  21. /// <param name="tableType">评价类型</param>
  22. /// <param name="evaluationType">参评类型</param>
  23. /// <param name="pageIndex">页码</param>
  24. /// <param name="pageSize">显示页数</param>
  25. /// <returns></returns>
  26. public IGridResultSet<EvaluationTableView> GetEvaluationTableViewGrid(ConfiguretView configuretView, Guid? evaluationType, Guid? evaluationIntType, int? openStatus, int pageIndex, int pageSize)
  27. {
  28. var query = evaluationTableDAL.GetEvaluationTableQueryable(x => true);
  29. if (evaluationIntType.HasValue && evaluationIntType != Guid.Empty)
  30. {
  31. query = query.Where(x => x.EvaluationIntTypeID == evaluationIntType);
  32. }
  33. if (evaluationType.HasValue && evaluationType != Guid.Empty)
  34. {
  35. query = query.Where(x => x.TypeID == evaluationType);
  36. }
  37. if (openStatus >= 0)
  38. {
  39. query = query.Where(x => x.IsEnabled == openStatus);
  40. }
  41. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  42. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.EvaluationType).OrderBy(x => x.Code).ToGridResultSet<EvaluationTableView>(pageIndex, pageSize);
  43. return query.OrderBy(x => x.EvaluationType).OrderBy(x => x.Code).ToGridResultSet<EvaluationTableView>(pageIndex, pageSize);
  44. }
  45. /// <summary>
  46. /// 查询评价表信息
  47. /// </summary>
  48. /// <param name="configuretView">查询条件实体</param>
  49. /// <param name="tableType">评价类型</param>
  50. /// <param name="evaluationType">参评类型</param>
  51. /// <returns></returns>
  52. public List<EvaluationTableView> GetEvaluationTableViewList(ConfiguretView configuretView, Guid? evaluationType, Guid? evaluationIntType, int? openStatus)
  53. {
  54. var query = evaluationTableDAL.GetEvaluationTableQueryable(x => true);
  55. if (evaluationIntType.HasValue && evaluationIntType != Guid.Empty)
  56. {
  57. query = query.Where(x => x.EvaluationIntTypeID == evaluationIntType);
  58. }
  59. if (evaluationType.HasValue && evaluationType != Guid.Empty)
  60. {
  61. query = query.Where(x => x.TypeID == evaluationType);
  62. }
  63. if (openStatus >= 0)
  64. {
  65. query = query.Where(x => x.IsEnabled == openStatus);
  66. }
  67. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  68. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.CreateTime).ToList();
  69. return query.OrderByDescending(x => x.CreateTime).ToList();
  70. }
  71. /// <summary>
  72. /// 获取评价表信息
  73. /// </summary>
  74. /// <param name="tableID">主键ID</param>
  75. /// <returns></returns>
  76. public EM_EvaluationTable GetEvaluationTable(Guid? tableID)
  77. {
  78. //查询条件
  79. Expression<Func<EM_EvaluationTable, bool>> expression = (x => x.EvaluationTableID == tableID.Value);
  80. return evaluationTableDAL.evaluationTableRepository.GetSingle(expression);
  81. }
  82. /// <summary>
  83. /// 获取评价表信息
  84. /// </summary>
  85. /// <param name="Name">评价表名</param>
  86. /// <returns></returns>
  87. public EM_EvaluationTable GetEvaluationTable(string Name)
  88. {
  89. //查询条件
  90. Expression<Func<EM_EvaluationTable, bool>> expression = (x => x.Name == Name);
  91. return evaluationTableDAL.evaluationTableRepository.GetSingle(expression);
  92. }
  93. /// <summary>
  94. /// 获取评价表信息
  95. /// </summary>
  96. /// <param name="tableID">主键ID</param>
  97. /// <returns></returns>
  98. public EvaluationTableView GetEvaluationTableView(Guid? tableID)
  99. {
  100. EvaluationTableView evaluationTableView = new EvaluationTableView();
  101. if (tableID.HasValue && tableID != Guid.Empty)
  102. evaluationTableView = evaluationTableDAL.GetEvaluationTableQueryable(x => true).Where(x => x.TableID == tableID).FirstOrDefault();
  103. return evaluationTableView;
  104. }
  105. /// <summary>
  106. /// 添加
  107. /// </summary>
  108. /// <param name="evaluationTable">实体</param>
  109. /// <returns></returns>
  110. public bool EvaluationTableAdd(EM_EvaluationTable evaluationTable)
  111. {
  112. try
  113. {
  114. UnitOfWork.Add(evaluationTable);
  115. UnitOfWork.Commit();
  116. return true;
  117. }
  118. catch (Exception)
  119. {
  120. throw;
  121. }
  122. }
  123. /// <summary>
  124. /// 修改
  125. /// </summary>
  126. /// <param name="evaluationTable">实体</param>
  127. /// <returns></returns>
  128. public bool EvaluationTableUpdate(EM_EvaluationTable evaluationTable)
  129. {
  130. try
  131. {
  132. UnitOfWork.Update(evaluationTable);
  133. UnitOfWork.Commit();
  134. return true;
  135. }
  136. catch (Exception)
  137. {
  138. throw;
  139. }
  140. }
  141. /// <summary>
  142. /// 删除
  143. /// </summary>
  144. /// <param name="tableIDs"></param>
  145. /// <returns></returns>
  146. public bool EvaluationTableDelete(List<Guid> tableIDs)
  147. {
  148. try
  149. {
  150. UnitOfWork.Delete<EM_EvaluationTable>(x => tableIDs.Contains(x.EvaluationTableID));
  151. UnitOfWork.Commit();
  152. return true;
  153. }
  154. catch (Exception)
  155. {
  156. throw;
  157. }
  158. }
  159. public bool ValidateEvaluationTable(Guid? tableID, string name, string code)
  160. {
  161. if (string.IsNullOrWhiteSpace(code))
  162. {
  163. throw new Exception("评价表编号不能为空!");
  164. }
  165. if (string.IsNullOrWhiteSpace(name))
  166. {
  167. throw new Exception("评价表名不能为空!");
  168. }
  169. code = code.Trim();
  170. name = name.Trim();
  171. Expression<Func<EM_EvaluationTable, bool>> codeFilter = w => w.Code == code;
  172. Expression<Func<EM_EvaluationTable, bool>> nameFilter = w => w.Name == name;
  173. if (tableID.HasValue && tableID != Guid.Empty) //编辑状态
  174. {
  175. codeFilter = codeFilter.And(w => w.EvaluationTableID != tableID);
  176. nameFilter = nameFilter.And(w => w.EvaluationTableID != tableID);
  177. }
  178. var hasCode = evaluationTableDAL.evaluationTableRepository.Entities.Any(codeFilter);
  179. if (hasCode)
  180. {
  181. throw new Exception("评价表编号已存在!");
  182. }
  183. var hasName = evaluationTableDAL.evaluationTableRepository.Entities.Any(nameFilter);
  184. if (hasName)
  185. {
  186. throw new Exception("评价表名已存在!");
  187. }
  188. return true;
  189. }
  190. public void SaveOrUpdateEvaluationTable(EvaluationTableView model)
  191. {
  192. ValidateEvaluationTable(model.TableID, model.Name, model.Code);
  193. var user = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  194. EM_EvaluationTable entity;
  195. var entityList = evaluationTableDAL.evaluationTableRepository.Entities.Where(x => x.EvaluationIntTypeID == model.EvaluationIntTypeID && x.EvaluationTypeID == model.TypeID).ToList();
  196. if (model.TableID.HasValue && model.TableID != Guid.Empty)
  197. {
  198. //entity = entityList.FirstOrDefault(x => x.TableID == model.TableID);
  199. entity = GetEvaluationTable(model.TableID);
  200. entityList.Remove(entity);//移除
  201. entity.Code = model.Code;
  202. entity.Name = model.Name;
  203. entity.EvaluationIntTypeID = model.EvaluationIntTypeID;
  204. entity.EvaluationTypeID = model.TypeID;
  205. entity.Weight = model.Weight;
  206. entity.Remark = model.Remark;
  207. entity.ModifyUserID = user.UserID;
  208. entity.ModifyTime = DateTime.Now;
  209. entity.IsEnabled = model.IsEnabled == (int)CF_YesOrNoStatus.Yes ? true : false;
  210. UnitOfWork.Update(entity);
  211. }
  212. else
  213. {
  214. entity = new EM_EvaluationTable();
  215. entity.EvaluationTableID = Guid.NewGuid();
  216. entity.Code = model.Code;
  217. entity.Name = model.Name;
  218. entity.EvaluationIntTypeID = model.EvaluationIntTypeID;
  219. entity.EvaluationTypeID = model.TypeID;
  220. entity.Weight = model.Weight;
  221. entity.Remark = model.Remark;
  222. entity.ModifyUserID = user.UserID;
  223. entity.ModifyTime = DateTime.Now;
  224. entity.CreateTime = DateTime.Now;
  225. entity.CreateUserID = user.UserID;
  226. entity.IsEnabled = model.IsEnabled == (int)CF_YesOrNoStatus.Yes ? true : false;
  227. UnitOfWork.Add(entity);
  228. }
  229. if (entity.IsEnabled == true)
  230. {
  231. entityList.ForEach(item => item.IsEnabled = false);
  232. }
  233. UnitOfWork.Commit();
  234. }
  235. }
  236. }