CollegePriorityServices.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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.Entity;
  7. using Bowin.Common.Linq;
  8. using EMIS.Utility;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.SchedulingManage;
  12. using EMIS.DataLogic.SchedulingManage.SchedulingSettings;
  13. using EMIS.ViewModel.UniversityManage.AdministrativeOrgan;
  14. namespace EMIS.CommonLogic.SchedulingManage.SchedulingSettings
  15. {
  16. public class CollegePriorityServices : BaseServices, ICollegePriorityServices
  17. {
  18. public CollegePriorityDAL CollegePriorityDAL { get; set; }
  19. /// <summary>
  20. /// 查询院系控制信息CollegePriorityView
  21. /// </summary>
  22. /// <param name="configuretView"></param>
  23. /// <param name="campusID"></param>
  24. /// <param name="collegeID"></param>
  25. /// <param name="dateRange"></param>
  26. /// <param name="pageIndex"></param>
  27. /// <param name="pageSize"></param>
  28. /// <returns></returns>
  29. public IGridResultSet<CollegePriorityView> GetCollegePriorityViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, DateTime? dateRange, int pageIndex, int pageSize)
  30. {
  31. Expression<Func<ES_CollegePriority, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  32. if (collegeID.HasValue)
  33. {
  34. exp = exp.And(x => x.CollegeID == collegeID);
  35. }
  36. if (dateRange.HasValue)
  37. {
  38. exp = exp.And(x => x.StartDate <= dateRange);
  39. }
  40. if (dateRange.HasValue)
  41. {
  42. exp = exp.And(x => x.EndDate >= dateRange);
  43. }
  44. var query = CollegePriorityDAL.GetCollegePriorityViewQueryable(exp);
  45. if (campusID.HasValue)
  46. {
  47. query = query.Where(x => x.CampusID == campusID);
  48. }
  49. //查询条件
  50. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  51. {
  52. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  53. }
  54. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.Priority).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToGridResultSet<CollegePriorityView>(pageIndex, pageSize);
  55. }
  56. /// <summary>
  57. /// 查询院系控制信息List
  58. /// </summary>
  59. /// <param name="configuretView"></param>
  60. /// <param name="campusID"></param>
  61. /// <param name="collegeID"></param>
  62. /// <param name="dateRange"></param>
  63. /// <returns></returns>
  64. public IList<CollegePriorityView> GetCollegePriorityViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, DateTime? dateRange)
  65. {
  66. Expression<Func<ES_CollegePriority, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  67. if (collegeID.HasValue)
  68. {
  69. exp = exp.And(x => x.CollegeID == collegeID);
  70. }
  71. if (dateRange.HasValue)
  72. {
  73. exp = exp.And(x => x.StartDate <= dateRange);
  74. }
  75. if (dateRange.HasValue)
  76. {
  77. exp = exp.And(x => x.EndDate >= dateRange);
  78. }
  79. var query = CollegePriorityDAL.GetCollegePriorityViewQueryable(exp);
  80. if (campusID.HasValue)
  81. {
  82. query = query.Where(x => x.CampusID == campusID);
  83. }
  84. //查询条件
  85. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  86. {
  87. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  88. }
  89. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.Priority).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToList();
  90. }
  91. /// <summary>
  92. /// 查询对应的院系控制信息CollegePriorityView
  93. /// </summary>
  94. /// <param name="collegePriorityID"></param>
  95. /// <returns></returns>
  96. public CollegePriorityView GetCollegePriorityView(Guid? collegePriorityID)
  97. {
  98. try
  99. {
  100. var query = CollegePriorityDAL.GetCollegePriorityViewQueryable(x => x.CollegePriorityID == collegePriorityID).SingleOrDefault();
  101. return query;
  102. }
  103. catch (Exception ex)
  104. {
  105. throw new Exception(ex.Message);
  106. }
  107. }
  108. /// <summary>
  109. /// 编辑(新增、修改)
  110. /// </summary>
  111. /// <param name="collegePriorityView"></param>
  112. public void CollegePriorityEdit(CollegePriorityView collegePriorityView)
  113. {
  114. try
  115. {
  116. //查询数据库进行验证
  117. var collegePriorityVerify = CollegePriorityDAL.CollegePriorityRepository.GetList(x => x.CollegePriorityID != collegePriorityView.CollegePriorityID
  118. && x.CollegeID == collegePriorityView.CollegeID).SingleOrDefault();
  119. if (collegePriorityVerify == null)
  120. {
  121. //数据有误验证
  122. if (collegePriorityView.CollegePriorityID != Guid.Empty)
  123. {
  124. var collegePriority = CollegePriorityDAL.CollegePriorityRepository
  125. .GetList(x => x.CollegePriorityID == collegePriorityView.CollegePriorityID).SingleOrDefault();
  126. if (collegePriority == null)
  127. {
  128. throw new Exception("数据有误,请核查。");
  129. }
  130. else
  131. {
  132. //表示修改
  133. collegePriority.CollegeID = collegePriorityView.CollegeID;
  134. collegePriority.Priority = collegePriorityView.Priority;
  135. collegePriority.StartDate = collegePriorityView.StartDate;
  136. collegePriority.EndDate = collegePriorityView.EndDate;
  137. SetModifyStatus(collegePriority);
  138. }
  139. }
  140. else
  141. {
  142. //表示新增
  143. var newCollegePriority = new ES_CollegePriority();
  144. newCollegePriority.CollegePriorityID = Guid.NewGuid();
  145. newCollegePriority.CollegeID = collegePriorityView.CollegeID;
  146. newCollegePriority.Priority = collegePriorityView.Priority;
  147. newCollegePriority.StartDate = collegePriorityView.StartDate;
  148. newCollegePriority.EndDate = collegePriorityView.EndDate;
  149. SetNewStatus(newCollegePriority);
  150. UnitOfWork.Add(newCollegePriority);
  151. }
  152. }
  153. else
  154. {
  155. throw new Exception("已存在相同的院系控制信息,请核查。");
  156. }
  157. //事务提交
  158. UnitOfWork.Commit();
  159. }
  160. catch (Exception ex)
  161. {
  162. throw new Exception(ex.Message);
  163. }
  164. }
  165. /// <summary>
  166. /// 院系控制信息批量新增
  167. /// </summary>
  168. /// <param name="collegeIDList"></param>
  169. /// <param name="collegePriorityView"></param>
  170. /// <returns></returns>
  171. public string CollegePriorityBatchAdd(List<Guid?> collegeIDList, CollegePriorityView collegePriorityView)
  172. {
  173. try
  174. {
  175. //查询对应的院系控制信息List
  176. var collegePriorityList = CollegePriorityDAL.CollegePriorityRepository.GetList(x => collegeIDList.Contains(x.CollegeID)).ToList();
  177. int success = 0; //成功
  178. int fail = 0; //失败
  179. string tipMessage = null; //提示消息
  180. List<ES_CollegePriority> collegePriorityInList = new List<ES_CollegePriority>();
  181. foreach (var collegeID in collegeIDList)
  182. {
  183. var collegePriorityVerify = collegePriorityList.Where(x => x.CollegeID == collegeID).SingleOrDefault();
  184. if (collegePriorityVerify == null)
  185. {
  186. //新增
  187. var newCollegePriority = new ES_CollegePriority();
  188. newCollegePriority.CollegePriorityID = Guid.NewGuid();
  189. newCollegePriority.CollegeID = collegeID;
  190. newCollegePriority.Priority = collegePriorityView.Priority;
  191. newCollegePriority.StartDate = collegePriorityView.StartDate;
  192. newCollegePriority.EndDate = collegePriorityView.EndDate;
  193. SetNewStatus(newCollegePriority);
  194. collegePriorityInList.Add(newCollegePriority);
  195. success++;
  196. }
  197. else
  198. {
  199. //表示已存在相同的院系控制信息
  200. fail++;
  201. }
  202. }
  203. //批量插入
  204. UnitOfWork.BulkInsert<ES_CollegePriority>(collegePriorityInList);
  205. if (success > 0 && fail <= 0)
  206. {
  207. tipMessage = success + "条";
  208. }
  209. else
  210. {
  211. tipMessage = success + "条," + fail + "条失败,原因:已存在相同的院系控制信息,请检查";
  212. }
  213. return tipMessage;
  214. }
  215. catch (Exception ex)
  216. {
  217. throw new Exception(ex.Message);
  218. }
  219. }
  220. /// <summary>
  221. /// 查询院系控制中未新增的院系所信息CollegeView
  222. /// </summary>
  223. /// <param name="configuretView"></param>
  224. /// <param name="campusID"></param>
  225. /// <param name="collegeID"></param>
  226. /// <param name="unitCategoryID"></param>
  227. /// <param name="pageIndex"></param>
  228. /// <param name="pageSize"></param>
  229. /// <returns></returns>
  230. public IGridResultSet<CollegeView> GetCollegeViewNoAddGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? unitCategoryID, int pageIndex, int pageSize)
  231. {
  232. //院系所信息
  233. Expression<Func<CF_College, bool>> expCollege = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  234. if (campusID.HasValue)
  235. {
  236. expCollege = expCollege.And(x => x.CampusID == campusID);
  237. }
  238. if (collegeID.HasValue)
  239. {
  240. expCollege = expCollege.And(x => x.CollegeID == collegeID);
  241. }
  242. if (unitCategoryID.HasValue)
  243. {
  244. expCollege = expCollege.And(x => x.CF_CollegeProfile.UnitCategoryID == unitCategoryID);
  245. }
  246. //院系控制
  247. Expression<Func<ES_CollegePriority, bool>> expCollegePriority = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  248. if (collegeID.HasValue)
  249. {
  250. expCollegePriority = expCollegePriority.And(x => x.CollegeID == collegeID);
  251. }
  252. var query = CollegePriorityDAL.GetCollegeViewNoAddQueryable(expCollege, expCollegePriority);
  253. //查询条件
  254. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  255. {
  256. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  257. }
  258. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.No.Length).ThenBy(x => x.No).ToGridResultSet<CollegeView>(pageIndex, pageSize);
  259. }
  260. /// <summary>
  261. /// 查询院系控制中未新增的院系所信息List
  262. /// </summary>
  263. /// <param name="configuretView"></param>
  264. /// <param name="campusID"></param>
  265. /// <param name="collegeID"></param>
  266. /// <param name="unitCategoryID"></param>
  267. /// <returns></returns>
  268. public IList<CollegeView> GetCollegeViewNoAddList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? unitCategoryID)
  269. {
  270. //院系所信息
  271. Expression<Func<CF_College, bool>> expCollege = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  272. if (campusID.HasValue)
  273. {
  274. expCollege = expCollege.And(x => x.CampusID == campusID);
  275. }
  276. if (collegeID.HasValue)
  277. {
  278. expCollege = expCollege.And(x => x.CollegeID == collegeID);
  279. }
  280. if (unitCategoryID.HasValue)
  281. {
  282. expCollege = expCollege.And(x => x.CF_CollegeProfile.UnitCategoryID == unitCategoryID);
  283. }
  284. //院系控制
  285. Expression<Func<ES_CollegePriority, bool>> expCollegePriority = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  286. if (collegeID.HasValue)
  287. {
  288. expCollegePriority = expCollegePriority.And(x => x.CollegeID == collegeID);
  289. }
  290. var query = CollegePriorityDAL.GetCollegeViewNoAddQueryable(expCollege, expCollegePriority);
  291. //查询条件
  292. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  293. {
  294. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  295. }
  296. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.No.Length).ThenBy(x => x.No).ToList();
  297. }
  298. /// <summary>
  299. /// 删除
  300. /// </summary>
  301. /// <param name="collegePriorityIDs"></param>
  302. /// <returns></returns>
  303. public bool CollegePriorityDelete(List<Guid?> collegePriorityIDs)
  304. {
  305. try
  306. {
  307. UnitOfWork.Delete<ES_CollegePriority>(x => collegePriorityIDs.Contains(x.CollegePriorityID));
  308. UnitOfWork.Commit();
  309. return true;
  310. }
  311. catch (Exception)
  312. {
  313. throw;
  314. }
  315. }
  316. }
  317. }