EducationMissionOpenControlServices.cs 17 KB

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