GraduationConditionPackageServices.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.GraduationManage.GraduationSetting;
  6. using EMIS.ViewModel.GraduationManage.GraduationSetting;
  7. using Bowin.Common.Linq.Entity;
  8. using Bowin.Common.Linq;
  9. using EMIS.ViewModel;
  10. using EMIS.Entities;
  11. using EMIS.ViewModel.CacheManage;
  12. using System.Linq.Expressions;
  13. namespace EMIS.CommonLogic.GraduationManage.GraduationSetting
  14. {
  15. public class GraduationConditionPackageServices : BaseServices, IGraduationConditionPackageServices
  16. {
  17. public GraduationConditionPackageDAL GraduationConditionPackageDAL { get; set; }
  18. /// <summary>
  19. /// 查询对应的毕业公式信息View(只查询毕业公式信息,不查询毕业公式对应的毕业条件)
  20. /// </summary>
  21. /// <param name="configuretView"></param>
  22. /// <param name="isDefault"></param>
  23. /// <param name="pageIndex"></param>
  24. /// <param name="pageSize"></param>
  25. /// <returns></returns>
  26. public IGridResultSet<GraduationConditionPackageView> GetGradConditionPackageViewGrid(ConfiguretView configuretView, int? isDefault, int pageIndex, int pageSize)
  27. {
  28. //毕业公式
  29. Expression<Func<ER_GraduationConditionPackage, bool>> exp = (x => true);
  30. if (isDefault.HasValue)
  31. {
  32. if (isDefault == 1)
  33. {
  34. exp = exp.And(x => x.IsDefault.Value == true);
  35. }
  36. if (isDefault == 0)
  37. {
  38. exp = exp.And(x => x.IsDefault.Value != true);
  39. }
  40. }
  41. var query = GraduationConditionPackageDAL.GetGraduationConditionPackageQueryable(exp);
  42. //查询条件
  43. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  44. {
  45. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  46. }
  47. return query.OrderByDescending(x => x.Title).ThenBy(x => x.IsDefault)
  48. .ToGridResultSet<GraduationConditionPackageView>(pageIndex, pageSize);
  49. }
  50. /// <summary>
  51. /// 查询对应的毕业公式信息List
  52. /// </summary>
  53. /// <param name="configuretView"></param>
  54. /// <param name="isDefault"></param>
  55. /// <returns></returns>
  56. public List<GraduationConditionPackageView> GetGradConditionPackageViewList(ConfiguretView configuretView, int? isDefault)
  57. {
  58. //毕业公式
  59. Expression<Func<ER_GraduationConditionPackage, bool>> exp = (x => true);
  60. if (isDefault.HasValue)
  61. {
  62. if (isDefault == 1)
  63. {
  64. exp = exp.And(x => x.IsDefault.Value == true);
  65. }
  66. if (isDefault == 0)
  67. {
  68. exp = exp.And(x => x.IsDefault.Value != true);
  69. }
  70. }
  71. var query = GraduationConditionPackageDAL.GetGraduationConditionPackageQueryable(exp);
  72. //查询条件
  73. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  74. {
  75. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  76. }
  77. return query.OrderByDescending(x => x.Title).ThenBy(x => x.IsDefault).ToList();
  78. }
  79. /// <summary>
  80. /// 根据毕业公式ID查询对应的毕业公式信息GraduationConditionPackageView
  81. /// </summary>
  82. /// <param name="GraduationConditionPackageID"></param>
  83. /// <returns></returns>
  84. public GraduationConditionPackageView GetGraduationConditionPackageView(Guid? GraduationConditionPackageID)
  85. {
  86. try
  87. {
  88. var query = GraduationConditionPackageDAL.GetGraduationConditionPackageQueryable(x => x.GraduationConditionPackageID == GraduationConditionPackageID).SingleOrDefault();
  89. return query;
  90. }
  91. catch (Exception ex)
  92. {
  93. throw new Exception(ex.Message);
  94. }
  95. }
  96. /// <summary>
  97. /// 根据毕业公式ID查询对应的毕业条件信息List
  98. /// </summary>
  99. /// <param name="GraduationConditionPackageID"></param>
  100. /// <returns></returns>
  101. public List<GraduationConditionView> GetGraduationConditionList(Guid? GraduationConditionPackageID)
  102. {
  103. var query = GraduationConditionPackageDAL.GraduationConditionQueryable(x => x.GraduationConditionPackageID == GraduationConditionPackageID);
  104. return query.OrderBy(x => x.OrderNo).ToList();
  105. }
  106. /// <summary>
  107. /// 查询毕业公式中未存在的毕业条件信息View
  108. /// </summary>
  109. /// <param name="configuretView"></param>
  110. /// <param name="graduationConditionPackageID"></param>
  111. /// <param name="isCurrent"></param>
  112. /// <param name="pageIndex"></param>
  113. /// <param name="pageSize"></param>
  114. /// <returns></returns>
  115. public IGridResultSet<GraduationConditionView> GetGraduationConditionNoViewGrid(ConfiguretView configuretView, Guid? graduationConditionPackageID, int? isCurrent, int pageIndex, int pageSize)
  116. {
  117. //毕业条件
  118. Expression<Func<ER_GraduationCondition, bool>> expGraduationCondition = (x => true);
  119. if (isCurrent.HasValue)
  120. {
  121. if (isCurrent == 1)
  122. {
  123. expGraduationCondition = expGraduationCondition.And(x => x.RecordStatus >= (int)SYS_STATUS.USABLE);
  124. }
  125. if (isCurrent == 0)
  126. {
  127. expGraduationCondition = expGraduationCondition.And(x => x.RecordStatus <= (int)SYS_STATUS.UNUSABLE);
  128. }
  129. }
  130. var query = GraduationConditionPackageDAL.GetGraduationConditionNoQueryable(expGraduationCondition, graduationConditionPackageID);
  131. //查询条件
  132. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  133. {
  134. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  135. }
  136. return query.OrderBy(x => x.OrderNo).ToGridResultSet<GraduationConditionView>(pageIndex, pageSize);
  137. }
  138. /// <summary>
  139. /// 查询毕业公式中未存在的毕业条件信息List
  140. /// </summary>
  141. /// <param name="configuretView"></param>
  142. /// <param name="graduationConditionPackageID"></param>
  143. /// <param name="isCurrent"></param>
  144. /// <returns></returns>
  145. public IList<GraduationConditionView> GetGraduationConditionNoViewList(ConfiguretView configuretView, Guid? graduationConditionPackageID, int? isCurrent)
  146. {
  147. //毕业条件
  148. Expression<Func<ER_GraduationCondition, bool>> expGraduationCondition = (x => true);
  149. if (isCurrent.HasValue)
  150. {
  151. if (isCurrent == 1)
  152. {
  153. expGraduationCondition = expGraduationCondition.And(x => x.RecordStatus >= (int)SYS_STATUS.USABLE);
  154. }
  155. if (isCurrent == 0)
  156. {
  157. expGraduationCondition = expGraduationCondition.And(x => x.RecordStatus <= (int)SYS_STATUS.UNUSABLE);
  158. }
  159. }
  160. var query = GraduationConditionPackageDAL.GetGraduationConditionNoQueryable(expGraduationCondition, graduationConditionPackageID);
  161. //查询条件
  162. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  163. {
  164. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  165. }
  166. return query.OrderBy(x => x.OrderNo).ToList();
  167. }
  168. /// <summary>
  169. /// 编辑(新增、修改,业务主键:公式名称)
  170. /// 注:判断是否默认状态(同一种学生类别,只有一种默认公式)
  171. /// 暂时不考虑当公式被引用时,不可修改公式中条件的情况
  172. /// </summary>
  173. /// <param name="graduationConditionPackageView"></param>
  174. /// <param name="graduationConditionViewList"></param>
  175. public void GraduationConditionPackageEdit(GraduationConditionPackageView graduationConditionPackageView, IList<GraduationConditionView> graduationConditionViewList)
  176. {
  177. try
  178. {
  179. var graduationConditionPackageVerification = GraduationConditionPackageDAL.GraduationConditionPackageRepository.GetList(x => x.GraduationConditionPackageID != graduationConditionPackageView.GraduationConditionPackageID && x.Title == graduationConditionPackageView.Title).SingleOrDefault();
  180. var graduationConditionIDList = graduationConditionViewList.Select(x => x.GraduationConditionID).ToList();
  181. var graduationConditionList = GraduationConditionPackageDAL.GraduationConditionRepository.GetList(x => graduationConditionIDList.Contains(x.GraduationConditionID)).ToList();
  182. if (graduationConditionPackageVerification == null)
  183. {
  184. //数据有误验证
  185. if (graduationConditionPackageView.GraduationConditionPackageID != Guid.Empty)
  186. {
  187. var graduationConditionPackage = GraduationConditionPackageDAL.GraduationConditionPackageRepository.GetList(x => x.GraduationConditionPackageID == graduationConditionPackageView.GraduationConditionPackageID).SingleOrDefault();
  188. if (graduationConditionPackage == null)
  189. {
  190. throw new Exception("数据有误,请核查");
  191. }
  192. else
  193. {
  194. //表示修改
  195. ////注:当毕业申请、毕业审核、毕业名单中有引用相关的毕业公式时,不可对相应的毕业公式进行修改--是否默认列除外
  196. ////根据毕业公式查询对应的毕业申请、毕业审核、毕业名单信息(外键引用)
  197. //var graduationApplyList = GraduationConditionPackageDAL.GraduationApplyRepository
  198. // .GetList(x => x.GraduationConditionPackageID == graduationConditionPackageView.GraduationConditionPackageID).ToList();
  199. //判断是否默认状态(同一种学生类别,只能启用一种默认公式)
  200. if (graduationConditionPackageView.IsDefault)
  201. {
  202. var graduationConditionPackageList = GraduationConditionPackageDAL.GraduationConditionPackageRepository.GetList(x => x.StudentType == graduationConditionPackageView.StudentTypeID
  203. && x.IsDefault.Value && x.GraduationConditionPackageID != graduationConditionPackageView.GraduationConditionPackageID).ToList();
  204. graduationConditionPackageList.ForEach(x => x.IsDefault = false);
  205. }
  206. graduationConditionPackage.Title = graduationConditionPackageView.Title;
  207. graduationConditionPackage.StudentType = graduationConditionPackageView.StudentTypeID;
  208. graduationConditionPackage.IsDefault = graduationConditionPackageView.IsDefault;
  209. SetModifyStatus(graduationConditionPackage);
  210. ////查询毕业公式对应的毕业条件信息
  211. //var gradPackageConditionList = GraduationConditionPackageDAL
  212. // .GraduationConditionQueryable(x => x.GraduationConditionPackageID == graduationConditionPackageView.GraduationConditionPackageID)
  213. // .ToList();
  214. ////查询毕业公式对应的毕业条件IDList
  215. //var gradPackageConditionIDList = gradPackageConditionList.Select(x => x.GraduationConditionID).ToList();
  216. ////先删除毕业公式对应的全部毕业条件信息,再对选择的毕业条件进行新增
  217. //graduationConditionPackage.ER_GraduationCondition
  218. // .RemoveWhere(x => gradPackageConditionIDList.Contains(x.GraduationConditionID));
  219. //物理删除(暂时将上述逻辑删除代码注释)
  220. UnitOfWork.Delete(graduationConditionPackage, (x => x.ER_GraduationCondition));
  221. //对应的毕业条件
  222. if (graduationConditionViewList != null && graduationConditionViewList.Count() > 0)
  223. {
  224. foreach (var graduationCondition in graduationConditionList)
  225. {
  226. graduationConditionPackage.ER_GraduationCondition.Add(graduationCondition);
  227. }
  228. }
  229. }
  230. }
  231. else
  232. {
  233. //表示新增
  234. //判断是否默认状态(同一种学生类别,只能启用一种默认公式)
  235. if (graduationConditionPackageView.IsDefault)
  236. {
  237. var graduationConditionPackageList = GraduationConditionPackageDAL
  238. .GraduationConditionPackageRepository
  239. .GetList(x => x.StudentType == graduationConditionPackageView.StudentTypeID && x.IsDefault.Value)
  240. .ToList();
  241. graduationConditionPackageList.ForEach(x => x.IsDefault = false);
  242. }
  243. ER_GraduationConditionPackage graduationConditionPackage = new ER_GraduationConditionPackage();
  244. graduationConditionPackage.GraduationConditionPackageID = Guid.NewGuid();
  245. graduationConditionPackage.Title = graduationConditionPackageView.Title;
  246. graduationConditionPackage.StudentType = graduationConditionPackageView.StudentTypeID;
  247. graduationConditionPackage.IsDefault = graduationConditionPackageView.IsDefault;
  248. SetNewStatus(graduationConditionPackage);
  249. UnitOfWork.Add(graduationConditionPackage);
  250. //对应的毕业条件
  251. if (graduationConditionViewList != null && graduationConditionViewList.Count() > 0)
  252. {
  253. foreach (var graduationCondition in graduationConditionList)
  254. {
  255. graduationConditionPackage.ER_GraduationCondition.Add(graduationCondition);
  256. }
  257. }
  258. }
  259. //事务提交
  260. UnitOfWork.Commit();
  261. }
  262. else
  263. {
  264. throw new Exception("已存在相同的毕业公式,请核查");
  265. }
  266. }
  267. catch (Exception ex)
  268. {
  269. throw new Exception(ex.Message);
  270. }
  271. }
  272. /// <summary>
  273. /// 删除(当对应的毕业公式被引用时,不可删除--毕业公式、对应的毕业条件)
  274. /// </summary>
  275. /// <param name="graduationConditionPackageIDs"></param>
  276. /// <returns></returns>
  277. public bool GraduationConditionPackageDelete(List<Guid?> graduationConditionPackageIDs)
  278. {
  279. try
  280. {
  281. //根据毕业公式查询对应的毕业申请、毕业审核、毕业名单信息(外键引用)
  282. var graduationApplyList = GraduationConditionPackageDAL.GraduationApplyRepository
  283. .GetList(x => graduationConditionPackageIDs.Contains(x.GraduationConditionPackageID)).ToList();
  284. if (graduationApplyList != null && graduationApplyList.Count() > 0)
  285. {
  286. throw new Exception("存在与其有关联的数据,如:毕业申请、毕业审核、毕业名单等");
  287. }
  288. //查询相应的毕业公式及对应的毕业条件信息List
  289. var graduationConditionPackageList = GraduationConditionPackageDAL.GraduationConditionPackageRepository
  290. .GetList(x => graduationConditionPackageIDs.Contains(x.GraduationConditionPackageID), x => x.ER_GraduationCondition)
  291. .ToList();
  292. foreach (var graduationConditionPackage in graduationConditionPackageList)
  293. {
  294. //物理删除
  295. UnitOfWork.Delete(graduationConditionPackage, (x => x.ER_GraduationCondition));
  296. UnitOfWork.Delete<ER_GraduationConditionPackage>(x => x.GraduationConditionPackageID == graduationConditionPackage.GraduationConditionPackageID);
  297. }
  298. UnitOfWork.Commit();
  299. return true;
  300. }
  301. catch (Exception ex)
  302. {
  303. throw new Exception(ex.Message);
  304. }
  305. }
  306. /// <summary>
  307. /// 根据学生类别查询对应的默认毕业公式信息View(GraduationConditionPackageView)
  308. /// </summary>
  309. /// <param name="studentType"></param>
  310. /// <returns></returns>
  311. public GraduationConditionPackageView GetGradConditionPackageIsDefaultView(int? studentType)
  312. {
  313. try
  314. {
  315. //毕业公式
  316. Expression<Func<ER_GraduationConditionPackage, bool>> exp = (x => true);
  317. exp = exp.And(x => x.IsDefault.Value == true);
  318. exp = exp.And(x => x.StudentType == studentType);
  319. var graduationConditionPackageView = GraduationConditionPackageDAL
  320. .GetGraduationConditionPackageQueryable(exp).SingleOrDefault();
  321. return graduationConditionPackageView;
  322. }
  323. catch (Exception ex)
  324. {
  325. throw new Exception(ex.Message);
  326. }
  327. }
  328. }
  329. }