ExaminationTeacherServices.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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.TeacherManage;
  9. using EMIS.DataLogic.ExaminationManage;
  10. using EMIS.Entities;
  11. using EMIS.ViewModel;
  12. using EMIS.ViewModel.UniversityManage.TeacherManage;
  13. using EMIS.CommonLogic.EducationSchedule;
  14. namespace EMIS.CommonLogic.ExaminationManage
  15. {
  16. public class ExaminationTeacherServices : BaseServices, IExaminationTeacherServices
  17. {
  18. public StaffDAL StaffDAL { get; set; }
  19. public ExaminationTeacherDAL ExaminationTeacherDAL { get; set; }
  20. public ExaminationPlanDAL ExaminationPlanDAL { get; set; }
  21. public Lazy<IScheduleServices> ScheduleServices { get; set; }
  22. public IGridResultSet<StaffView> GetStaffViewList(ConfiguretView teacherView,
  23. Guid? campusID, Guid? collegeID, Guid? departmentID, int pageIndex, int pageSize)
  24. {
  25. Expression<Func<CF_Staff, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.EX_ExaminationTeacher.Count() > 0);
  26. if (campusID.HasValue)
  27. {
  28. exp = exp.And(x => x.CF_College.CampusID == campusID);
  29. }
  30. if (collegeID.HasValue)
  31. {
  32. exp = exp.And(x => x.CollegeID == collegeID);
  33. }
  34. if (departmentID.HasValue)
  35. {
  36. exp = exp.And(x => x.DepartmentID == departmentID);
  37. }
  38. var q = StaffDAL.GetStaffViewQueryable(exp);
  39. if (!string.IsNullOrEmpty(teacherView.ConditionValue) && !string.IsNullOrEmpty(teacherView.Attribute))
  40. q = q.DynamicWhere(teacherView.Attribute, teacherView.Condition, teacherView.ConditionValue);
  41. return GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.CollegeName).ThenByDescending(x => x.IncumbencyState).ThenByDescending(x => x.Name)
  42. .ToGridResultSet<StaffView>(pageIndex, pageSize);
  43. }
  44. public IList<StaffView> GetStaffViewList(ConfiguretView teacherView, Guid? campusID, Guid? collegeID, Guid? departmentID)
  45. {
  46. Expression<Func<CF_Staff, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.EX_ExaminationTeacher.Count() > 0);
  47. if (campusID.HasValue)
  48. {
  49. exp = exp.And(x => x.CF_College.CampusID == campusID);
  50. }
  51. if (collegeID.HasValue)
  52. {
  53. exp = exp.And(x => x.CollegeID == collegeID);
  54. }
  55. if (departmentID.HasValue)
  56. {
  57. exp = exp.And(x => x.DepartmentID == departmentID);
  58. }
  59. var q = StaffDAL.GetStaffViewQueryable(exp);
  60. if (!string.IsNullOrEmpty(teacherView.ConditionValue) && !string.IsNullOrEmpty(teacherView.Attribute))
  61. q = q.DynamicWhere(teacherView.Attribute, teacherView.Condition, teacherView.ConditionValue);
  62. return GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.CollegeName).ThenByDescending(x => x.IncumbencyState).ThenByDescending(x => x.Name)
  63. .ToList();
  64. }
  65. public void Add(IList<Guid?> userIDList)
  66. {
  67. foreach (var userID in userIDList)
  68. {
  69. var examinationTeacherEntity = ExaminationTeacherDAL.ExaminationTeacherRepository.GetSingle(x => x.UserID == userID);
  70. if (examinationTeacherEntity == null)
  71. {
  72. examinationTeacherEntity = new EX_ExaminationTeacher();
  73. examinationTeacherEntity.ExaminationTeacherID = Guid.NewGuid();
  74. examinationTeacherEntity.UserID = userID;
  75. this.SetNewStatus(examinationTeacherEntity);
  76. UnitOfWork.Add(examinationTeacherEntity);
  77. }
  78. }
  79. UnitOfWork.Commit();
  80. }
  81. public void Delete(IList<Guid?> userIDList)
  82. {
  83. if (userIDList.Count > 0)
  84. {
  85. UnitOfWork.Delete<EX_ExaminationTeacher>(x => userIDList.Contains(x.UserID));
  86. }
  87. }
  88. public IGridResultSet<StaffView> GetAvailableStaffViewList(ConfiguretView teacherView, Guid examinationPlanID, Guid classroomID, Guid? campusID, Guid? collegeID,
  89. Guid? departmentID, int pageIndex, int pageSize)
  90. {
  91. Expression<Func<CF_Staff, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.EX_ExaminationTeacher.Count() > 0);
  92. if (campusID.HasValue)
  93. {
  94. exp = exp.And(x => x.CF_College.CampusID == campusID);
  95. }
  96. if (collegeID.HasValue)
  97. {
  98. exp = exp.And(x => x.CollegeID == collegeID);
  99. }
  100. if (departmentID.HasValue)
  101. {
  102. exp = exp.And(x => x.DepartmentID == departmentID);
  103. }
  104. var examinationPlan = ExaminationPlanDAL.ExaminationPlanRepository.GetSingle(x => x.ExaminationPlanID == examinationPlanID);
  105. var scheduleDateTimeList = new List<StartEndTimeView> {
  106. new StartEndTimeView { StartTime = examinationPlan.ExaminationDate.Value.Add(examinationPlan.StartTime.Value)
  107. , EndTime = examinationPlan.ExaminationDate.Value.Add(examinationPlan.EndTime.Value) }
  108. };
  109. var schedulingList = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewForExaminationTeacher(examinationPlan.SchoolyearID.Value,
  110. scheduleDateTimeList);
  111. var scheduledTeacherIDList = schedulingList.SelectMany(x => x.TeacherList).Select(x => x.UserID).Distinct().ToList();
  112. exp = exp.And(x => !scheduledTeacherIDList.Contains(x.UserID));
  113. var q = ExaminationTeacherDAL.GetAvailableStaffView((x => x.ExaminationPlanID == examinationPlanID), classroomID, exp);
  114. if (!string.IsNullOrEmpty(teacherView.ConditionValue) && !string.IsNullOrEmpty(teacherView.Attribute))
  115. q = q.DynamicWhere(teacherView.Attribute, teacherView.Condition, teacherView.ConditionValue);
  116. return GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.CollegeName).ThenByDescending(x => x.IncumbencyState).ThenByDescending(x => x.Name)
  117. .ToGridResultSet<StaffView>(pageIndex, pageSize);
  118. }
  119. public IGridResultSet<StaffView> GetAddAvailableStaffViewList(ConfiguretView teacherView, Guid classroomID, Guid? campusID, Guid? collegeID,
  120. Guid? departmentID, int pageIndex, int pageSize)
  121. {
  122. Expression<Func<CF_Staff, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.EX_ExaminationTeacher.Count() > 0);
  123. if (campusID.HasValue)
  124. {
  125. exp = exp.And(x => x.CF_College.CampusID == campusID);
  126. }
  127. if (collegeID.HasValue)
  128. {
  129. exp = exp.And(x => x.CollegeID == collegeID);
  130. }
  131. if (departmentID.HasValue)
  132. {
  133. exp = exp.And(x => x.DepartmentID == departmentID);
  134. }
  135. var q = ExaminationTeacherDAL.GetAvailableStaffView((x => true), classroomID, exp);
  136. if (!string.IsNullOrEmpty(teacherView.ConditionValue) && !string.IsNullOrEmpty(teacherView.Attribute))
  137. q = q.DynamicWhere(teacherView.Attribute, teacherView.Condition, teacherView.ConditionValue);
  138. return GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.CollegeName).ThenByDescending(x => x.IncumbencyState).ThenByDescending(x => x.Name)
  139. .ToGridResultSet<StaffView>(pageIndex, pageSize);
  140. }
  141. public IGridResultSet<StaffView> GetAvailableStaffViewGdssList(ConfiguretView teacherView, Guid schoolyearID, DateTime examinationDate,
  142. TimeSpan startTime, TimeSpan endTime, Guid classroomID, Guid? campusID, Guid? collegeID, Guid? departmentID, int pageIndex, int pageSize)
  143. {
  144. Expression<Func<CF_Staff, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.EX_ExaminationTeacher.Count() > 0);
  145. if (campusID.HasValue)
  146. {
  147. exp = exp.And(x => x.CF_College.CampusID == campusID);
  148. }
  149. if (collegeID.HasValue)
  150. {
  151. exp = exp.And(x => x.CollegeID == collegeID);
  152. }
  153. if (departmentID.HasValue)
  154. {
  155. exp = exp.And(x => x.DepartmentID == departmentID);
  156. }
  157. var scheduleDateTimeList = new List<StartEndTimeView> {
  158. new StartEndTimeView { StartTime = examinationDate.Add(startTime)
  159. , EndTime = examinationDate.Add(endTime) }
  160. };
  161. var schedulingList = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewForExaminationTeacher(schoolyearID,
  162. scheduleDateTimeList);
  163. var scheduledTeacherIDList = schedulingList.SelectMany(x => x.TeacherList).Select(x => x.UserID).Distinct().ToList();
  164. exp = exp.And(x => !scheduledTeacherIDList.Contains(x.UserID));
  165. var q = ExaminationTeacherDAL.GetAvailableStaffViewGdss((x => x.SchoolyearID == schoolyearID && x.ExaminationDate == examinationDate
  166. && x.StartTime <= endTime && x.EndTime >= startTime), classroomID, exp);
  167. if (!string.IsNullOrEmpty(teacherView.ConditionValue) && !string.IsNullOrEmpty(teacherView.Attribute))
  168. q = q.DynamicWhere(teacherView.Attribute, teacherView.Condition, teacherView.ConditionValue);
  169. return GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.CollegeName).ThenByDescending(x => x.IncumbencyState).ThenByDescending(x => x.Name)
  170. .ToGridResultSet<StaffView>(pageIndex, pageSize);
  171. }
  172. }
  173. }