MinorGraduationConditionPackageServices.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq.Entity;
  6. using EMIS.ViewModel.MinorGraduation.MinorGraduationSetting;
  7. using EMIS.ViewModel;
  8. using Bowin.Common.Linq;
  9. using System.Linq.Expressions;
  10. using EMIS.Entities;
  11. using EMIS.DataLogic.MinorGraduation.MinorGraduationSetting;
  12. namespace EMIS.CommonLogic.MinorGraduation.MinorGraduationSetting
  13. {
  14. public class MinorGraduationConditionPackageServices : BaseServices, IMinorGraduationConditionPackageServices
  15. {
  16. public MinorGraduationConditionPackageDAL minorGraduationConditionPackageDAL { get; set; }
  17. /// <summary>
  18. /// 查询辅修毕业公式信息
  19. /// </summary>
  20. /// <param name="configuretView"></param>
  21. /// <param name="isDefault"></param>
  22. /// <param name="pageIndex"></param>
  23. /// <param name="pageSize"></param>
  24. /// <returns></returns>
  25. public IGridResultSet<MinorGraduationConditionPackageView> GetMinorGraduationConditionPackageViewGrid(ConfiguretView configuretView,int? isDefault, int pageIndex, int pageSize)
  26. {
  27. Expression<Func<ER_MinorGraduationConditionPackage, bool>> exp = (x => true);
  28. if (isDefault.HasValue)
  29. {
  30. if (isDefault == 1)
  31. {
  32. exp = exp.And(x => x.IsDefault.Value == true);
  33. }
  34. if (isDefault == 0)
  35. {
  36. exp = exp.And(x => x.IsDefault.Value != true);
  37. }
  38. }
  39. var query = minorGraduationConditionPackageDAL.GetMinorGraduationConditionPackageQueryable(exp);
  40. //查询条件
  41. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  42. {
  43. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  44. }
  45. return query.OrderByDescending(x => x.IsDefault).ThenBy(x => x.Title.Length).ThenBy(x => x.Title)
  46. .ToGridResultSet<MinorGraduationConditionPackageView>(pageIndex, pageSize);
  47. }
  48. /// <summary>
  49. /// 查询辅修毕业公式信息List
  50. /// </summary>
  51. /// <param name="configuretView"></param>
  52. /// <param name="isDefault"></param>
  53. /// <returns></returns>
  54. public List<MinorGraduationConditionPackageView> GetMinorGraduationConditionPackageViewList(ConfiguretView configuretView, int? isDefault, List<Guid?> idList)
  55. {
  56. //毕业公式
  57. Expression<Func<ER_MinorGraduationConditionPackage, bool>> exp = (x => true);
  58. if (isDefault.HasValue)
  59. {
  60. if (isDefault == 1)
  61. {
  62. exp = exp.And(x => x.IsDefault.Value == true);
  63. }
  64. if (isDefault == 0)
  65. {
  66. exp = exp.And(x => x.IsDefault.Value != true);
  67. }
  68. }
  69. if (idList != null && idList.Count > 0)
  70. {
  71. exp = exp.And(x => idList.Contains(x.MinorGraduationConditionPackageID));
  72. }
  73. var query = minorGraduationConditionPackageDAL.GetMinorGraduationConditionPackageQueryable(exp);
  74. //查询条件
  75. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  76. {
  77. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  78. }
  79. return query.OrderByDescending(x => x.IsDefault)
  80. .ThenBy(x => x.Title.Length).ThenBy(x => x.Title).ToList();
  81. }
  82. public MinorGraduationConditionPackageView GetDefaultMinorGraduationConditionPackageView()
  83. {
  84. var query = minorGraduationConditionPackageDAL.GetMinorGraduationConditionPackageQueryable(x => x.IsDefault == true);
  85. return query.FirstOrDefault();
  86. }
  87. /// <summary>
  88. /// 查询单个辅修毕业公式(根据ID)
  89. /// </summary>
  90. /// <param name="GraduationConditionPackageID"></param>
  91. /// <returns></returns>
  92. public MinorGraduationConditionPackageView GetMinorGraduationConditionPackageView(Guid? minorGraduationConditionPackageID)
  93. {
  94. try
  95. {
  96. var query = minorGraduationConditionPackageDAL
  97. .GetMinorGraduationConditionPackageQueryable(x => x.MinorGraduationConditionPackageID == minorGraduationConditionPackageID)
  98. .SingleOrDefault();
  99. return query;
  100. }
  101. catch (Exception ex)
  102. {
  103. throw new Exception(ex.Message);
  104. }
  105. }
  106. /// <summary>
  107. /// 根据辅修毕业公式ID查询对应的辅修毕业条件信息List
  108. /// </summary>
  109. /// <param name="GraduationConditionPackageID"></param>
  110. /// <returns></returns>
  111. public List<MinorGraduationConditionView> GetMinorGraduationConditionViewList(Guid? minorGraduationConditionPackageID)
  112. {
  113. var query = minorGraduationConditionPackageDAL
  114. .MinorGraduationConditionQueryable(x => x.MinorGraduationConditionPackageID == minorGraduationConditionPackageID);
  115. return query.OrderBy(x => x.Title.Length).ThenBy(x => x.Title).ToList();
  116. }
  117. public void MinorGraduationConditionPackageEdit(MinorGraduationConditionPackageView minorGraduationConditionPackageView,
  118. IList<MinorGraduationConditionView> minorGraduationConditionViewList)
  119. {
  120. try
  121. {
  122. //查询数据库进行验证
  123. var minorGraduationConditionPackageVerification = minorGraduationConditionPackageDAL.minorGraduationConditionPackageRepository
  124. .GetList(x => x.MinorGraduationConditionPackageID != minorGraduationConditionPackageView.MinorGraduationConditionPackageID
  125. && x.Title == minorGraduationConditionPackageView.Title)
  126. .SingleOrDefault();
  127. //列表页面对应的毕业条件IDList
  128. var minorGraduationConditionIDList = minorGraduationConditionViewList.Select(x => x.MinorGraduationConditionID).ToList();
  129. //列表页面对应的毕业条件信息List
  130. var minorGraduationConditionList = minorGraduationConditionPackageDAL.minorGraduationConditionRepository
  131. .GetList(x => minorGraduationConditionIDList.Contains(x.MinorGraduationConditionID)).ToList();
  132. if (minorGraduationConditionPackageVerification == null)
  133. {
  134. //数据有误验证
  135. if (minorGraduationConditionPackageView.MinorGraduationConditionPackageID != Guid.Empty)
  136. {
  137. var minorGraduationConditionPackage = minorGraduationConditionPackageDAL.minorGraduationConditionPackageRepository
  138. .GetList(x => x.MinorGraduationConditionPackageID == minorGraduationConditionPackageView.MinorGraduationConditionPackageID)
  139. .SingleOrDefault();
  140. if (minorGraduationConditionPackage == null)
  141. {
  142. throw new Exception("数据有误,请核查");
  143. }
  144. else
  145. {
  146. //表示修改
  147. ////注:当毕业申请、毕业审核、毕业名单中有引用相关的毕业公式时,不可对相应的毕业公式进行修改--是否默认列除外
  148. ////根据毕业公式查询对应的毕业申请、毕业审核、毕业名单信息(外键引用)
  149. //var graduationApplyList = GraduationConditionPackageDAL.GraduationApplyRepository
  150. // .GetList(x => x.GraduationConditionPackageID == graduationConditionPackageView.GraduationConditionPackageID).ToList();
  151. //判断是否默认状态(同一种学生类别,只能启用一种默认公式)
  152. if (minorGraduationConditionPackageView.IsDefault)
  153. {
  154. var minorGraduationConditionPackageList = minorGraduationConditionPackageDAL
  155. .minorGraduationConditionPackageRepository
  156. .GetList(x => x.StudentType == minorGraduationConditionPackageView.StudentTypeID && x.IsDefault.Value
  157. && x.MinorGraduationConditionPackageID != minorGraduationConditionPackageView.MinorGraduationConditionPackageID)
  158. .ToList();
  159. minorGraduationConditionPackageList.ForEach(x => x.IsDefault = false);
  160. }
  161. minorGraduationConditionPackage.Title = minorGraduationConditionPackageView.Title;
  162. minorGraduationConditionPackage.StudentType = minorGraduationConditionPackageView.StudentTypeID;
  163. minorGraduationConditionPackage.IsDefault = minorGraduationConditionPackageView.IsDefault;
  164. SetModifyStatus(minorGraduationConditionPackage);
  165. ////查询毕业公式对应的毕业条件信息
  166. //var gradPackageConditionList = GraduationConditionPackageDAL
  167. // .GraduationConditionQueryable(x => x.GraduationConditionPackageID == graduationConditionPackageView.GraduationConditionPackageID)
  168. // .ToList();
  169. ////查询毕业公式对应的毕业条件IDList
  170. //var gradPackageConditionIDList = gradPackageConditionList.Select(x => x.GraduationConditionID).ToList();
  171. ////先删除毕业公式对应的全部毕业条件信息,再对选择的毕业条件进行新增
  172. //graduationConditionPackage.ER_GraduationCondition
  173. // .RemoveWhere(x => gradPackageConditionIDList.Contains(x.GraduationConditionID));
  174. //删除
  175. UnitOfWork.Delete(minorGraduationConditionPackage, (x => x.ER_MinorGraduationCondition));
  176. //对应的毕业条件
  177. if (minorGraduationConditionViewList != null && minorGraduationConditionViewList.Count() > 0)
  178. {
  179. foreach (var minorGraduationCondition in minorGraduationConditionList)
  180. {
  181. minorGraduationConditionPackage.ER_MinorGraduationCondition.Add(minorGraduationCondition);
  182. }
  183. }
  184. }
  185. }
  186. else
  187. {
  188. //表示新增
  189. //判断是否默认状态(同一种学生类别,只能启用一种默认公式)
  190. if (minorGraduationConditionPackageView.IsDefault)
  191. {
  192. var graduationConditionPackageList = minorGraduationConditionPackageDAL
  193. .minorGraduationConditionPackageRepository
  194. .GetList(x => x.StudentType == minorGraduationConditionPackageView.StudentTypeID && x.IsDefault.Value)
  195. .ToList();
  196. graduationConditionPackageList.ForEach(x => x.IsDefault = false);
  197. }
  198. ER_MinorGraduationConditionPackage minorGraduationConditionPackage = new ER_MinorGraduationConditionPackage();
  199. minorGraduationConditionPackage.MinorGraduationConditionPackageID = Guid.NewGuid();
  200. minorGraduationConditionPackage.Title = minorGraduationConditionPackageView.Title;
  201. minorGraduationConditionPackage.StudentType = minorGraduationConditionPackageView.StudentTypeID;
  202. minorGraduationConditionPackage.IsDefault = minorGraduationConditionPackageView.IsDefault;
  203. SetNewStatus(minorGraduationConditionPackage);
  204. //对应的毕业条件
  205. if (minorGraduationConditionViewList != null && minorGraduationConditionViewList.Count() > 0)
  206. {
  207. foreach (var minorGraduationCondition in minorGraduationConditionList)
  208. {
  209. minorGraduationConditionPackage.ER_MinorGraduationCondition.Add(minorGraduationCondition);
  210. }
  211. }
  212. UnitOfWork.Add(minorGraduationConditionPackage);
  213. }
  214. //事务提交
  215. UnitOfWork.Commit();
  216. }
  217. else
  218. {
  219. throw new Exception("已存在相同的辅修毕业公式,请核查");
  220. }
  221. }
  222. catch (Exception ex)
  223. {
  224. throw new Exception(ex.Message);
  225. }
  226. }
  227. /// <summary>
  228. /// 删除(当对应的毕业公式被引用时,不可删除--毕业公式、对应的毕业条件)
  229. /// </summary>
  230. /// <param name="graduationConditionPackageIDs"></param>
  231. /// <returns></returns>
  232. public bool MinorGraduationConditionPackageDelete(List<Guid?> minorGraduationConditionPackageIDs)
  233. {
  234. try
  235. {
  236. //查找公式是否被引用
  237. var minorGraduationApplyList = minorGraduationConditionPackageDAL.minorGraduationApplyRepository
  238. .GetList(x => minorGraduationConditionPackageIDs.Contains(x.MinorGraduationConditionPackageID)).ToList();
  239. if (minorGraduationApplyList != null && minorGraduationApplyList.Count() > 0)
  240. {
  241. throw new Exception("选择的公式已经被引用,不能删除");
  242. }
  243. //查询相应的毕业公式及对应的毕业条件信息List
  244. var minorGraduationConditionPackageList = minorGraduationConditionPackageDAL.minorGraduationConditionPackageRepository
  245. .GetList(x => minorGraduationConditionPackageIDs.Contains(x.MinorGraduationConditionPackageID), x => x.ER_MinorGraduationCondition)
  246. .ToList();
  247. foreach (var minorGraduationConditionPackage in minorGraduationConditionPackageList)
  248. {
  249. //删除
  250. UnitOfWork.Delete(minorGraduationConditionPackage, (x => x.ER_MinorGraduationCondition));
  251. UnitOfWork.Delete<ER_MinorGraduationConditionPackage>(x => x.MinorGraduationConditionPackageID == minorGraduationConditionPackage.MinorGraduationConditionPackageID);
  252. }
  253. UnitOfWork.Commit();
  254. return true;
  255. }
  256. catch (Exception ex)
  257. {
  258. throw new Exception(ex.Message);
  259. }
  260. }
  261. }
  262. }