ClassroomReserveServices.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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.Entities;
  9. using EMIS.ViewModel;
  10. using EMIS.ViewModel.SchedulingManage.SchedulingSettings;
  11. using EMIS.ViewModel.UniversityManage.ClassroomManage;
  12. using EMIS.DataLogic.SchedulingManage.SchedulingSettings;
  13. namespace EMIS.CommonLogic.SchedulingManage.SchedulingSettings
  14. {
  15. public class ClassroomReserveServices : BaseServices, IClassroomReserveServices
  16. {
  17. public ClassroomReserveDAL ClassroomReserveDAL { get; set; }
  18. /// <summary>
  19. /// 查询对应的教室预留信息ClassroomReserveView
  20. /// </summary>
  21. /// <param name="configuretView"></param>
  22. /// <param name="campusID"></param>
  23. /// <param name="buildingsInfoID"></param>
  24. /// <param name="classroomName"></param>
  25. /// <param name="classroomTypeID"></param>
  26. /// <param name="isConcurrentUse"></param>
  27. /// <param name="isAvailable"></param>
  28. /// <param name="pageIndex"></param>
  29. /// <param name="pageSize"></param>
  30. /// <returns></returns>
  31. public IGridResultSet<ClassroomReserveView> GetClassroomReserveViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? buildingsInfoID,
  32. string classroomName, int? classroomTypeID, int? isConcurrentUse, int? isAvailable, int pageIndex, int pageSize)
  33. {
  34. //教室预留
  35. Expression<Func<ES_ClassroomReserve, bool>> expClassroomReserve = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  36. expClassroomReserve = expClassroomReserve.And(x => x.IsReserved == true);
  37. var query = ClassroomReserveDAL.GetClassroomReserveViewQueryable(expClassroomReserve);
  38. if (campusID.HasValue)
  39. {
  40. //建筑信息对应的校区
  41. query = query.Where(x => x.CampusID == campusID);
  42. }
  43. if (buildingsInfoID.HasValue)
  44. {
  45. //建筑信息
  46. query = query.Where(x => x.BuildingsInfoID == buildingsInfoID);
  47. }
  48. if (!string.IsNullOrEmpty(classroomName) && classroomName != "-1")
  49. {
  50. //教室名称
  51. query = query.Where(x => x.ClassroomName == classroomName);
  52. }
  53. if (classroomTypeID.HasValue)
  54. {
  55. //教室类型(模糊查询)
  56. query = query.Where(x => x.CF_ClassroomType.Select(w => w.ClassroomType).Contains(classroomTypeID));
  57. }
  58. if (isConcurrentUse.HasValue)
  59. {
  60. //可否多班教学
  61. if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsYes)
  62. {
  63. query = query.Where(x => x.IsConcurrentUse == true);
  64. }
  65. if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsNo)
  66. {
  67. query = query.Where(x => x.IsConcurrentUse != true);
  68. }
  69. }
  70. if (isAvailable.HasValue)
  71. {
  72. //是否可用
  73. if (isAvailable.Value == (int)CF_GeneralPurpose.IsYes)
  74. {
  75. query = query.Where(x => x.IsAvailable == true);
  76. }
  77. if (isAvailable.Value == (int)CF_GeneralPurpose.IsNo)
  78. {
  79. query = query.Where(x => x.IsAvailable != true);
  80. }
  81. }
  82. //查询条件
  83. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  84. {
  85. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  86. }
  87. return this.GetQueryByDataRangeByCampus(query)
  88. .OrderBy(x => x.CampusNo.Length).ThenBy(x => x.CampusNo)
  89. .ThenBy(x => x.BuildingsInfoCode.Length).ThenBy(x => x.BuildingsInfoCode)
  90. .ThenBy(x => x.ClassroomCode.Length).ThenBy(x => x.ClassroomCode).ThenBy(x => x.RoomUseID)
  91. .ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode)
  92. .ToGridResultSet<ClassroomReserveView>(pageIndex, pageSize);
  93. }
  94. /// <summary>
  95. /// 查询对应的教室预留信息List
  96. /// </summary>
  97. /// <param name="configuretView"></param>
  98. /// <param name="campusID"></param>
  99. /// <param name="buildingsInfoID"></param>
  100. /// <param name="classroomName"></param>
  101. /// <param name="classroomTypeID"></param>
  102. /// <param name="isConcurrentUse"></param>
  103. /// <param name="isAvailable"></param>
  104. /// <returns></returns>
  105. public IList<ClassroomReserveView> GetClassroomReserveViewList(ConfiguretView configuretView, Guid? campusID, Guid? buildingsInfoID,
  106. string classroomName, int? classroomTypeID, int? isConcurrentUse, int? isAvailable)
  107. {
  108. //教室预留
  109. Expression<Func<ES_ClassroomReserve, bool>> expClassroomReserve = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  110. expClassroomReserve = expClassroomReserve.And(x => x.IsReserved == true);
  111. var query = ClassroomReserveDAL.GetClassroomReserveViewQueryable(expClassroomReserve);
  112. if (campusID.HasValue)
  113. {
  114. //建筑信息对应的校区
  115. query = query.Where(x => x.CampusID == campusID);
  116. }
  117. if (buildingsInfoID.HasValue)
  118. {
  119. //建筑信息
  120. query = query.Where(x => x.BuildingsInfoID == buildingsInfoID);
  121. }
  122. if (!string.IsNullOrEmpty(classroomName) && classroomName != "-1")
  123. {
  124. //教室名称
  125. query = query.Where(x => x.ClassroomName == classroomName);
  126. }
  127. if (classroomTypeID.HasValue)
  128. {
  129. //教室类型(模糊查询)
  130. query = query.Where(x => x.CF_ClassroomType.Select(w => w.ClassroomType).Contains(classroomTypeID));
  131. }
  132. if (isConcurrentUse.HasValue)
  133. {
  134. //可否多班教学
  135. if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsYes)
  136. {
  137. query = query.Where(x => x.IsConcurrentUse == true);
  138. }
  139. if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsNo)
  140. {
  141. query = query.Where(x => x.IsConcurrentUse != true);
  142. }
  143. }
  144. if (isAvailable.HasValue)
  145. {
  146. //是否可用
  147. if (isAvailable.Value == (int)CF_GeneralPurpose.IsYes)
  148. {
  149. query = query.Where(x => x.IsAvailable == true);
  150. }
  151. if (isAvailable.Value == (int)CF_GeneralPurpose.IsNo)
  152. {
  153. query = query.Where(x => x.IsAvailable != true);
  154. }
  155. }
  156. //查询条件
  157. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  158. {
  159. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  160. }
  161. return this.GetQueryByDataRangeByCampus(query)
  162. .OrderBy(x => x.CampusNo.Length).ThenBy(x => x.CampusNo)
  163. .ThenBy(x => x.BuildingsInfoCode.Length).ThenBy(x => x.BuildingsInfoCode)
  164. .ThenBy(x => x.ClassroomCode.Length).ThenBy(x => x.ClassroomCode).ThenBy(x => x.RoomUseID)
  165. .ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode)
  166. .ToList();
  167. }
  168. /// <summary>
  169. /// 查询对应的教室预留信息ES_ClassroomReserve(根据教室预留ID)
  170. /// </summary>
  171. /// <param name="classroomReserveID"></param>
  172. /// <returns></returns>
  173. public ES_ClassroomReserve GetClassroomReserve(Guid? classroomReserveID)
  174. {
  175. try
  176. {
  177. var query = ClassroomReserveDAL.ClassroomReserveRepository.GetList(x => x.ClassroomReserveID == classroomReserveID);
  178. return query.SingleOrDefault();
  179. }
  180. catch (Exception ex)
  181. {
  182. throw new Exception(ex.Message);
  183. }
  184. }
  185. /// <summary>
  186. /// 查询对应的教室预留信息ClassroomReserveView(根据教室预留ID)
  187. /// </summary>
  188. /// <param name="classroomReserveID"></param>
  189. /// <returns></returns>
  190. public ClassroomReserveView GetClassroomReserveView(Guid? classroomReserveID)
  191. {
  192. try
  193. {
  194. var query = ClassroomReserveDAL.GetClassroomReserveViewQueryable(x => x.ClassroomReserveID == classroomReserveID);
  195. return query.SingleOrDefault();
  196. }
  197. catch (Exception ex)
  198. {
  199. throw new Exception(ex.Message);
  200. }
  201. }
  202. /// <summary>
  203. /// 编辑(新增、修改)
  204. /// </summary>
  205. /// <param name="classroomReserveView"></param>
  206. public void ClassroomReserveEdit(ClassroomReserveView classroomReserveView)
  207. {
  208. try
  209. {
  210. //查询数据库进行验证
  211. var classroomReserveVerify = ClassroomReserveDAL.ClassroomReserveRepository
  212. .GetList(x => x.ClassroomReserveID != classroomReserveView.ClassroomReserveID
  213. && x.ClassroomID == classroomReserveView.ClassroomID).SingleOrDefault();
  214. if (classroomReserveVerify == null)
  215. {
  216. //数据有误验证
  217. if (classroomReserveView.ClassroomReserveID != Guid.Empty)
  218. {
  219. var classroomReserve = ClassroomReserveDAL.ClassroomReserveRepository
  220. .GetList(x => x.ClassroomReserveID == classroomReserveView.ClassroomReserveID).SingleOrDefault();
  221. if (classroomReserve == null)
  222. {
  223. throw new Exception("数据有误,请核查。");
  224. }
  225. else
  226. {
  227. //表示修改
  228. classroomReserve.ClassroomID = classroomReserveView.ClassroomID;
  229. classroomReserve.IsReserved = true;
  230. SetModifyStatus(classroomReserve);
  231. }
  232. }
  233. else
  234. {
  235. //表示新增
  236. var newClassroomReserve = new ES_ClassroomReserve();
  237. newClassroomReserve.ClassroomReserveID = Guid.NewGuid();
  238. newClassroomReserve.ClassroomID = classroomReserveView.ClassroomID;
  239. newClassroomReserve.IsReserved = true;
  240. SetNewStatus(newClassroomReserve);
  241. UnitOfWork.Add(newClassroomReserve);
  242. }
  243. }
  244. else
  245. {
  246. throw new Exception("已存在相同的教室预留信息,请核查。");
  247. }
  248. //事务提交
  249. UnitOfWork.Commit();
  250. }
  251. catch (Exception ex)
  252. {
  253. throw new Exception(ex.Message);
  254. }
  255. }
  256. /// <summary>
  257. /// 教室预留信息批量新增(预留)
  258. /// </summary>
  259. /// <param name="classroomIDList"></param>
  260. /// <param name="classroomReserveView"></param>
  261. /// <returns></returns>
  262. public string ClassroomReserveBatchAdd(List<Guid?> classroomIDList, ClassroomReserveView classroomReserveView)
  263. {
  264. try
  265. {
  266. //查询对应的教室预留信息List
  267. var classroomReserveList = ClassroomReserveDAL.ClassroomReserveRepository
  268. .GetList(x => classroomIDList.Contains(x.ClassroomID)).ToList();
  269. int success = 0; //成功
  270. int fail = 0; //失败
  271. string tipMessage = null; //提示消息
  272. List<ES_ClassroomReserve> classroomReserveInList = new List<ES_ClassroomReserve>();
  273. foreach (var classroomID in classroomIDList)
  274. {
  275. var classroomReserveVerify = classroomReserveList.Where(x => x.ClassroomID == classroomID).SingleOrDefault();
  276. if (classroomReserveVerify == null)
  277. {
  278. //新增
  279. var newClassroomReserve = new ES_ClassroomReserve();
  280. newClassroomReserve.ClassroomReserveID = Guid.NewGuid();
  281. newClassroomReserve.ClassroomID = classroomID;
  282. newClassroomReserve.IsReserved = true;
  283. SetNewStatus(newClassroomReserve);
  284. classroomReserveInList.Add(newClassroomReserve);
  285. success++;
  286. }
  287. else
  288. {
  289. //表示已存在相同的教室预留信息
  290. fail++;
  291. }
  292. }
  293. //批量插入
  294. UnitOfWork.BulkInsert<ES_ClassroomReserve>(classroomReserveInList);
  295. if (success > 0 && fail <= 0)
  296. {
  297. tipMessage = success + "条";
  298. }
  299. else
  300. {
  301. tipMessage = success + "条," + fail + "条失败,原因:已存在相同的教室预留信息,请检查";
  302. }
  303. return tipMessage;
  304. }
  305. catch (Exception ex)
  306. {
  307. throw new Exception(ex.Message);
  308. }
  309. }
  310. /// <summary>
  311. /// 查询未预留的教室信息ClassroomView
  312. /// </summary>
  313. /// <param name="configuretView"></param>
  314. /// <param name="campusID"></param>
  315. /// <param name="buildingsInfoID"></param>
  316. /// <param name="classroomName"></param>
  317. /// <param name="classroomTypeID"></param>
  318. /// <param name="isConcurrentUse"></param>
  319. /// <param name="isAvailable"></param>
  320. /// <param name="pageIndex"></param>
  321. /// <param name="pageSize"></param>
  322. /// <returns></returns>
  323. public IGridResultSet<ClassroomView> GetClassroomViewNoReserveGrid(ConfiguretView configuretView, Guid? campusID, Guid? buildingsInfoID,
  324. string classroomName, int? classroomTypeID, int? isConcurrentUse, int? isAvailable, int pageIndex, int pageSize)
  325. {
  326. //教室信息
  327. Expression<Func<CF_Classroom, bool>> expClassroom = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  328. if (buildingsInfoID.HasValue)
  329. {
  330. //建筑信息
  331. expClassroom = expClassroom.And(x => x.BuildingsInfoID == buildingsInfoID);
  332. }
  333. if (!string.IsNullOrEmpty(classroomName) && classroomName != "-1")
  334. {
  335. //教室名称
  336. expClassroom = expClassroom.And(x => x.Name == classroomName);
  337. }
  338. if (classroomTypeID.HasValue)
  339. {
  340. //教室类型(模糊查询)
  341. expClassroom = expClassroom.And(x => x.CF_ClassroomType.Select(w => w.ClassroomType).Contains(classroomTypeID));
  342. }
  343. if (isConcurrentUse.HasValue)
  344. {
  345. //可否多班教学
  346. if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsYes)
  347. {
  348. expClassroom = expClassroom.And(x => x.IsConcurrentUse == true);
  349. }
  350. if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsNo)
  351. {
  352. expClassroom = expClassroom.And(x => x.IsConcurrentUse != true);
  353. }
  354. }
  355. if (isAvailable.HasValue)
  356. {
  357. //是否可用
  358. if (isAvailable.Value == (int)CF_GeneralPurpose.IsYes)
  359. {
  360. expClassroom = expClassroom.And(x => x.IsAvailable == true);
  361. }
  362. if (isAvailable.Value == (int)CF_GeneralPurpose.IsNo)
  363. {
  364. expClassroom = expClassroom.And(x => x.IsAvailable != true);
  365. }
  366. }
  367. var query = ClassroomReserveDAL.GetClassroomViewNoReserveQueryable(expClassroom);
  368. if (campusID.HasValue)
  369. {
  370. //建筑信息对应的校区
  371. query = query.Where(x => x.CampusID == campusID);
  372. }
  373. //查询条件
  374. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  375. {
  376. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  377. }
  378. return this.GetQueryByDataRangeByCampus(query)
  379. .OrderBy(x => x.CampusCode.Length).ThenBy(x => x.CampusCode)
  380. .ThenBy(x => x.BuildingsInfoCode.Length).ThenBy(x => x.BuildingsInfoCode)
  381. .ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ThenBy(x => x.RoomUseID)
  382. .ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode)
  383. .ToGridResultSet<ClassroomView>(pageIndex, pageSize);
  384. }
  385. /// <summary>
  386. /// 查询未预留的教室信息List
  387. /// </summary>
  388. /// <param name="configuretView"></param>
  389. /// <param name="campusID"></param>
  390. /// <param name="buildingsInfoID"></param>
  391. /// <param name="classroomName"></param>
  392. /// <param name="classroomTypeID"></param>
  393. /// <param name="isConcurrentUse"></param>
  394. /// <param name="isAvailable"></param>
  395. /// <returns></returns>
  396. public IList<ClassroomView> GetClassroomViewNoReserveList(ConfiguretView configuretView, Guid? campusID, Guid? buildingsInfoID,
  397. string classroomName, int? classroomTypeID, int? isConcurrentUse, int? isAvailable)
  398. {
  399. //教室信息
  400. Expression<Func<CF_Classroom, bool>> expClassroom = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  401. if (buildingsInfoID.HasValue)
  402. {
  403. //建筑信息
  404. expClassroom = expClassroom.And(x => x.BuildingsInfoID == buildingsInfoID);
  405. }
  406. if (!string.IsNullOrEmpty(classroomName) && classroomName != "-1")
  407. {
  408. //教室名称
  409. expClassroom = expClassroom.And(x => x.Name == classroomName);
  410. }
  411. if (classroomTypeID.HasValue)
  412. {
  413. //教室类型(模糊查询)
  414. expClassroom = expClassroom.And(x => x.CF_ClassroomType.Select(w => w.ClassroomType).Contains(classroomTypeID));
  415. }
  416. if (isConcurrentUse.HasValue)
  417. {
  418. //可否多班教学
  419. if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsYes)
  420. {
  421. expClassroom = expClassroom.And(x => x.IsConcurrentUse == true);
  422. }
  423. if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsNo)
  424. {
  425. expClassroom = expClassroom.And(x => x.IsConcurrentUse != true);
  426. }
  427. }
  428. if (isAvailable.HasValue)
  429. {
  430. //是否可用
  431. if (isAvailable.Value == (int)CF_GeneralPurpose.IsYes)
  432. {
  433. expClassroom = expClassroom.And(x => x.IsAvailable == true);
  434. }
  435. if (isAvailable.Value == (int)CF_GeneralPurpose.IsNo)
  436. {
  437. expClassroom = expClassroom.And(x => x.IsAvailable != true);
  438. }
  439. }
  440. var query = ClassroomReserveDAL.GetClassroomViewNoReserveQueryable(expClassroom);
  441. if (campusID.HasValue)
  442. {
  443. //建筑信息对应的校区
  444. query = query.Where(x => x.CampusID == campusID);
  445. }
  446. //查询条件
  447. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  448. {
  449. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  450. }
  451. return this.GetQueryByDataRangeByCampus(query)
  452. .OrderBy(x => x.CampusCode.Length).ThenBy(x => x.CampusCode)
  453. .ThenBy(x => x.BuildingsInfoCode.Length).ThenBy(x => x.BuildingsInfoCode)
  454. .ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ThenBy(x => x.RoomUseID)
  455. .ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode)
  456. .ToList();
  457. }
  458. /// <summary>
  459. /// 删除(解除)
  460. /// </summary>
  461. /// <param name="classroomReserveIDs"></param>
  462. /// <returns></returns>
  463. public bool ClassroomReserveDelete(List<Guid?> classroomReserveIDs)
  464. {
  465. try
  466. {
  467. UnitOfWork.Delete<ES_ClassroomReserve>(x => classroomReserveIDs.Contains(x.ClassroomReserveID));
  468. UnitOfWork.Commit();
  469. return true;
  470. }
  471. catch (Exception)
  472. {
  473. throw;
  474. }
  475. }
  476. }
  477. }