RoomSettingServices.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.DataLogic.UniversityManage.ClassroomManage;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.UniversityManage.ClassroomManage;
  12. using EMIS.DataLogic.ExaminationManage;
  13. using EMIS.ViewModel.ExaminationApply;
  14. using EMIS.CommonLogic.EducationSchedule;
  15. namespace EMIS.CommonLogic.ExaminationManage
  16. {
  17. public class RoomSettingServices : BaseServices, IRoomSettingServices
  18. {
  19. public ClassroomDAL ClassroomDAL { get; set; }
  20. public RoomSettingDAL RoomSettingDAL { get; set; }
  21. public ExaminationPlanDAL ExaminationPlanDAL { get; set; }
  22. public Lazy<IScheduleServices> ScheduleServices { get; set; }
  23. public Lazy<IClassroomExcessiveUseServices> ClassroomExcessiveUseServices { get; set; }
  24. public IGridResultSet<ClassroomView> GetClassroomViewList(ViewModel.ConfiguretView roomSettingView, Guid? campusID, Guid? buildingsInfoID,
  25. bool? isAvailable, int pageIndex, int pageSize)
  26. {
  27. Expression<Func<CF_Classroom, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.EX_ExaminationRoomSetting.Count() > 0);
  28. if (campusID.HasValue)
  29. {
  30. exp = exp.And(x => x.CF_BuildingsInfo.CampusID == campusID);
  31. }
  32. if (buildingsInfoID.HasValue)
  33. {
  34. exp = exp.And(x => x.BuildingsInfoID == buildingsInfoID);
  35. }
  36. if (isAvailable.HasValue)
  37. {
  38. exp = exp.And(x => x.IsAvailable == isAvailable);
  39. }
  40. var q = ClassroomDAL.GetClassroomViewQueryable(exp);
  41. if (!string.IsNullOrEmpty(roomSettingView.ConditionValue) && !string.IsNullOrEmpty(roomSettingView.Attribute))
  42. q = q.DynamicWhere(roomSettingView.Attribute, roomSettingView.Condition, roomSettingView.ConditionValue);
  43. return GetQueryByDataRangeByCampus(q).OrderByDescending(x => x.IsAvailable).ThenByDescending(x => x.BuildingsInfoName)
  44. .ThenByDescending(x => x.Name)
  45. .ToGridResultSet<ClassroomView>(pageIndex, pageSize);
  46. }
  47. public Bowin.Common.Linq.Entity.IGridResultSet<ExaminationClassroomView> GetAvailableClassroomViewList(ViewModel.ConfiguretView roomSettingView,
  48. Guid examinationPlanID, Guid? examinationRoomLayoutID, int pageIndex, int pageSize)
  49. {
  50. Expression<Func<CF_Classroom, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  51. var examinationPlan = ExaminationPlanDAL.ExaminationPlanRepository.GetSingle(x => x.ExaminationPlanID == examinationPlanID);
  52. var scheduleDateTimeList = new List<StartEndTimeView> {
  53. new StartEndTimeView { StartTime = examinationPlan.ExaminationDate.Value.Add(examinationPlan.StartTime.Value)
  54. , EndTime = examinationPlan.ExaminationDate.Value.Add(examinationPlan.EndTime.Value) }
  55. };
  56. var schedulingList = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewByDateTimeList(examinationPlan.SchoolyearID.Value,
  57. scheduleDateTimeList);
  58. var scheduledClassroomIDList = schedulingList.Select(x => x.ClassroomID).Distinct().ToList();
  59. exp = exp.And(x => !scheduledClassroomIDList.Contains(x.ClassroomID));
  60. var q = RoomSettingDAL.GetAvailableClassroomView((x => x.ExaminationPlanID == examinationPlanID),
  61. (x => x.ExaminationRoomLayoutID == examinationRoomLayoutID), exp);
  62. if (!string.IsNullOrEmpty(roomSettingView.ConditionValue) && !string.IsNullOrEmpty(roomSettingView.Attribute))
  63. q = q.DynamicWhere(roomSettingView.Attribute, roomSettingView.Condition, roomSettingView.ConditionValue);
  64. q = q.Where(x => x.IsAvailable == true);
  65. return GetQueryByDataRangeByCampus(q).OrderByDescending(x => x.IsAvailable)
  66. .ThenByDescending(x => x.BuildingsInfoName).ThenByDescending(x => x.Name)
  67. .ToGridResultSet(pageIndex, pageSize);
  68. }
  69. public IGridResultSet<ExaminationClassroomView> GetAddAvailableClassroomViewList(ConfiguretView roomSettingView, int pageIndex, int pageSize)
  70. {
  71. Expression<Func<CF_Classroom, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  72. var q = RoomSettingDAL.GetAvailableClassroomView((x => true), (x => true), exp);
  73. if (!string.IsNullOrEmpty(roomSettingView.ConditionValue) && !string.IsNullOrEmpty(roomSettingView.Attribute))
  74. q = q.DynamicWhere(roomSettingView.Attribute, roomSettingView.Condition, roomSettingView.ConditionValue);
  75. q = q.Where(x => x.IsAvailable == true);
  76. return GetQueryByDataRangeByCampus(q).OrderByDescending(x => x.IsAvailable).OrderByDescending(x => x.BuildingsInfoName).OrderByDescending(x => x.Name)
  77. .ToGridResultSet(pageIndex, pageSize);
  78. }
  79. public IList<ClassroomView> GetClassroomViewList(ViewModel.ConfiguretView roomSettingView, Guid? campusID, Guid? buildingsInfoID, bool? isAvailable)
  80. {
  81. Expression<Func<CF_Classroom, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.EX_ExaminationRoomSetting.Count() > 0);
  82. if (campusID.HasValue)
  83. {
  84. exp = exp.And(x => x.CF_BuildingsInfo.CampusID == campusID);
  85. }
  86. if (buildingsInfoID.HasValue)
  87. {
  88. exp = exp.And(x => x.BuildingsInfoID == buildingsInfoID);
  89. }
  90. if (isAvailable.HasValue)
  91. {
  92. exp = exp.And(x => x.IsAvailable == isAvailable);
  93. }
  94. var q = ClassroomDAL.GetClassroomViewQueryable(exp);
  95. if (!string.IsNullOrEmpty(roomSettingView.ConditionValue) && !string.IsNullOrEmpty(roomSettingView.Attribute))
  96. q = q.DynamicWhere(roomSettingView.Attribute, roomSettingView.Condition, roomSettingView.ConditionValue);
  97. return GetQueryByDataRangeByCampus(q).OrderByDescending(x => x.IsAvailable)
  98. .ThenByDescending(x => x.BuildingsInfoName)
  99. .ThenByDescending(x => x.Name)
  100. .ToList();
  101. }
  102. public void Add(IList<Guid?> classroomIDList)
  103. {
  104. foreach (var classroomID in classroomIDList)
  105. {
  106. var roomSettingEntity = RoomSettingDAL.ExaminationRoomSettingRepository.GetSingle(x => x.ClassroomID == classroomID);
  107. if (roomSettingEntity == null)
  108. {
  109. roomSettingEntity = new EX_ExaminationRoomSetting();
  110. roomSettingEntity.ExaminationRoomSettingID = Guid.NewGuid();
  111. roomSettingEntity.ClassroomID = classroomID;
  112. this.SetNewStatus(roomSettingEntity);
  113. UnitOfWork.Add(roomSettingEntity);
  114. }
  115. }
  116. UnitOfWork.Commit();
  117. }
  118. public void Delete(IList<Guid?> classroomIDList)
  119. {
  120. if (classroomIDList.Count > 0)
  121. {
  122. UnitOfWork.Delete<EX_ExaminationRoomSetting>(x => classroomIDList.Contains(x.ClassroomID));
  123. }
  124. }
  125. public IGridResultSet<ExaminationClassroomView> GetAvailableClassroomViewGdssList(ConfiguretView roomSettingView, Guid examinationPlanID,
  126. Guid? buildingsInfoID, DateTime examinationDate, TimeSpan startTime, TimeSpan endTime, int studentCount, int pageIndex, int pageSize)
  127. {
  128. Expression<Func<EX_ExaminationPlan, bool>> otherExaminationPlanExp = (x => x.ExaminationPlanID != examinationPlanID
  129. && x.ExaminationDate == examinationDate && x.EndTime >= startTime && x.StartTime <= endTime);
  130. Expression<Func<CF_Classroom, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  131. var examinationPlan = ExaminationPlanDAL.ExaminationPlanRepository.GetSingle(x => x.ExaminationPlanID == examinationPlanID);
  132. var scheduleDateTimeList = new List<StartEndTimeView> {
  133. new StartEndTimeView { StartTime = examinationDate.Add(startTime)
  134. , EndTime = examinationDate.Add(endTime) }
  135. };
  136. var schedulingList = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewByDateTimeList(examinationPlan.SchoolyearID.Value,
  137. scheduleDateTimeList);
  138. var excessiveUseList = this.ClassroomExcessiveUseServices.Value.GetClassroomExcessiveUseWeekNumViewByDateTimeList(
  139. examinationPlan.SchoolyearID.Value,
  140. scheduleDateTimeList);
  141. var scheduledClassroomIDList = schedulingList.Select(x => x.ClassroomID)
  142. .Concat(excessiveUseList.Select(x => x.ClassroomID)).Distinct().ToList();
  143. exp = exp.And(x => !scheduledClassroomIDList.Contains(x.ClassroomID));
  144. if (buildingsInfoID.HasValue)
  145. {
  146. exp = exp.And(x => x.BuildingsInfoID == buildingsInfoID);
  147. }
  148. var q = RoomSettingDAL.GetAvailableClassroomViewGdss(otherExaminationPlanExp, exp, studentCount);
  149. if (!string.IsNullOrEmpty(roomSettingView.ConditionValue) && !string.IsNullOrEmpty(roomSettingView.Attribute))
  150. q = q.DynamicWhere(roomSettingView.Attribute, roomSettingView.Condition, roomSettingView.ConditionValue);
  151. q = q.Where(x => x.IsAvailable == true);
  152. return GetQueryByDataRangeByCampus(q).OrderByDescending(x => x.IsAvailable)
  153. .ThenByDescending(x => x.BuildingsInfoName).ThenByDescending(x => x.Name)
  154. .ToGridResultSet(pageIndex, pageSize);
  155. }
  156. }
  157. }