using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Linq.Expressions; using System.Text; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.EducationSchedule; using EMIS.ViewModel; using EMIS.Entities; using EMIS.CommonLogic.SystemServices; using EMIS.DataLogic.EducationSchedule; using EMIS.ViewModel.EducationManage; using EMIS.Utility.FormValidate; using System.Transactions; using EMIS.CommonLogic.CalendarManage; using EMIS.ViewModel.CalendarManage; using EMIS.CommonLogic.ExaminationManage; using EMIS.DataLogic.Repositories; using EMIS.DataLogic.ExaminationManage; using EMIS.ViewModel.ExaminationManage; namespace EMIS.CommonLogic.EducationSchedule { public class EducationSchedulingAdjustmentServices : BaseWorkflowServices, IEducationSchedulingAdjustmentServices { public EducationSchedulingDAL EducationSchedulingDAL { get; set; } public EducationSchedulingAdjustmentDAL EducationSchedulingAdjustmentDAL { get; set; } public EducationSchedulingStopDAL EducationSchedulingStopDAL { get; set; } public ExaminationPlanDAL ExaminationPlanDAL { get; set; } public Lazy ScheduleServices { get; set; } public Lazy SchoolYearServices { get; set; } public Lazy CoursesTimeServices { get; set; } public Lazy EducationSchedulingStopServices { get; set; } public void Save(ScheduleAdjustmentEditView scheduleAdjustmentView) { ES_EducationScheduling educationSchedule; if (scheduleAdjustmentView.EducationSchedulingID.HasValue) { educationSchedule = this.EducationSchedulingDAL.EducationSchedulingRepository.GetSingle(x => x.EducationSchedulingID == scheduleAdjustmentView.EducationSchedulingID, (x => x.EM_EducationSchedulingClass), (x => x.ES_EducationSchedulingTeacher)); } else { educationSchedule = this.EducationSchedulingDAL.EducationSchedulingRepository.GetSingle(x => x.EM_EducationSchedulingClass.EducationMissionClassID == scheduleAdjustmentView.EducationMissionClassID && x.Weekday == scheduleAdjustmentView.Weekday && x.CoursesTimeID == scheduleAdjustmentView.CoursesTimeID && x.ES_EducationSchedulingWeekNum.Any(w => scheduleAdjustmentView.WeekNum == w.WeekNum), (x => x.EM_EducationSchedulingClass), (x => x.ES_EducationSchedulingTeacher)); } if (educationSchedule == null) { throw new Exception("所选排课记录不存在,请退出重新选择。"); } var startStatusID = this.GetStartStatus(); var backpointStatusList = this.GetBackpointStatus(); var scheduleAdjustment = new ES_EducationSchedulingAdjustment(); if (scheduleAdjustmentView.EducationSchedulingAdjustmentID != Guid.Empty) { scheduleAdjustment = this.EducationSchedulingAdjustmentDAL.EducationSchedulingAdjustmentRepository .GetSingle(x => x.EducationSchedulingAdjustmentID == scheduleAdjustmentView.EducationSchedulingAdjustmentID, (x => x.ES_EducationSchedulingAdjustmentTeacher), (x => x.ES_EducationSchedulingAdjustmentToTeacher)); if (scheduleAdjustment == null) { throw new Exception("数据已经被删除,请退出重新选择。"); } if (scheduleAdjustment.RecordStatus != startStatusID && !backpointStatusList.Contains(scheduleAdjustment.RecordStatus)) { throw new Exception("数据已提交,不能修改。"); } this.SetModifyStatus(scheduleAdjustment); } else { scheduleAdjustment.EducationSchedulingAdjustmentID = Guid.NewGuid(); this.SetNewStatus(scheduleAdjustment); scheduleAdjustment.RecordStatus = startStatusID; this.UnitOfWork.Add(scheduleAdjustment); } scheduleAdjustment.EducationMissionClassID = educationSchedule.EM_EducationSchedulingClass.EducationMissionClassID; scheduleAdjustment.Weekday = scheduleAdjustmentView.Weekday; scheduleAdjustment.CoursesTimeID = scheduleAdjustmentView.CoursesTimeID; scheduleAdjustment.ClassroomTypeID = scheduleAdjustmentView.ClassroomTypeID; scheduleAdjustment.ClassroomID = scheduleAdjustmentView.ClassroomID; scheduleAdjustment.UserID = scheduleAdjustmentView.UserID; scheduleAdjustment.ToWeekday = scheduleAdjustmentView.ToWeekday; scheduleAdjustment.ToCoursesTimeID = scheduleAdjustmentView.ToCoursesTimeID; scheduleAdjustment.ToClassroomTypeID = scheduleAdjustmentView.ToClassroomTypeID; scheduleAdjustment.ToClassroomID = scheduleAdjustmentView.ToClassroomID; scheduleAdjustment.ToUserID = scheduleAdjustmentView.ToUserID; scheduleAdjustment.WeekNum = scheduleAdjustmentView.WeekNum; scheduleAdjustment.ToWeekNum = scheduleAdjustmentView.ToWeekNum; scheduleAdjustment.ES_EducationSchedulingAdjustmentTeacher = new HashSet(); foreach (var teacher in educationSchedule.ES_EducationSchedulingTeacher) { var fromTeacher = new ES_EducationSchedulingAdjustmentTeacher(); fromTeacher.EducationSchedulingAdjustmentTeacherID = Guid.NewGuid(); fromTeacher.EducationSchedulingAdjustmentID = scheduleAdjustment.EducationSchedulingAdjustmentID; fromTeacher.UserID = teacher.UserID; fromTeacher.TeachingMethod = teacher.TeachingMethod; this.SetNewStatus(fromTeacher); scheduleAdjustment.ES_EducationSchedulingAdjustmentTeacher.Add(fromTeacher); } scheduleAdjustment.ES_EducationSchedulingAdjustmentToTeacher = new HashSet(); foreach (var teacher in educationSchedule.ES_EducationSchedulingTeacher) { var toTeacher = new ES_EducationSchedulingAdjustmentToTeacher(); toTeacher.EducationSchedulingAdjustmentToTeacherID = Guid.NewGuid(); toTeacher.EducationSchedulingAdjustmentID = scheduleAdjustment.EducationSchedulingAdjustmentID; toTeacher.UserID = (teacher.UserID == scheduleAdjustment.UserID && scheduleAdjustment.ToUserID.HasValue) ? scheduleAdjustment.ToUserID : teacher.UserID; toTeacher.TeachingMethod = teacher.TeachingMethod; this.SetNewStatus(toTeacher); scheduleAdjustment.ES_EducationSchedulingAdjustmentToTeacher.Add(toTeacher); } this.UnitOfWork.Commit(); } public IGridResultSet GetScheduleAdjustmentViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? coursematerialID, Guid? collegeID, Guid? userID, Guid? classroomID, Guid? applyUserID, DateTime? startTime, DateTime? endTime, int? recordStatus, int? pageIndex, int? pageSize) { var statusList = this.GetStatusViewList(); Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> missionExp = (x => true); Expression> missionClassExp = (x => true); Expression> staffExp = (x => true); if (schoolyearID.HasValue) { missionExp = missionExp.And(x => x.SchoolyearID == schoolyearID); } if (coursematerialID.HasValue) { missionClassExp = missionClassExp.And(x => x.CoursematerialID == coursematerialID); } if (collegeID.HasValue) { staffExp = staffExp.And(x => x.CollegeID == collegeID); } if (userID.HasValue) { exp = exp.And(x => x.ES_EducationSchedulingAdjustmentTeacher.Any(y => y.UserID == userID)); //staffExp = staffExp.And(x => x.UserID == userID); } if (classroomID.HasValue) { exp = exp.And(x => x.ClassroomID == classroomID); } if (applyUserID.HasValue) { exp = exp.And(x => x.CreateUserID == applyUserID); } if (startTime.HasValue) { exp = exp.And(x => x.ApplyTime >= startTime); } if (endTime.HasValue) { var correctEndTime = endTime.Value.Date.AddDays(1); exp = exp.And(x => x.ApplyTime < correctEndTime); } if (recordStatus.HasValue) { exp = exp.And(x => x.RecordStatus == recordStatus); } var query = this.EducationSchedulingAdjustmentDAL.GetScheduleAdjustmentViewQueryable(exp, missionExp, missionClassExp, staffExp); var teacherQuery = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingAdjustmentTeacherQueryable( exp, missionExp, missionClassExp, staffExp); var toTeacherQuery = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingAdjustmentToTeacherQueryable( exp, missionExp, missionClassExp, staffExp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); query = this.GetQueryByDataRange(query, (x => x.UserID)); var resultQuery = query.OrderByDescending(x => x.SchoolyearCode) .ThenByDescending(x => x.ApplyTime).ThenBy(x => x.ApplyUserID).ThenBy(x => x.WeekNum).ThenBy(x => x.Weekday) .ThenBy(x => x.StartTimes); var result = resultQuery.ToGridResultSet(pageIndex, pageSize); if (pageIndex.HasValue && pageSize.HasValue) { var adjustmentIDList = result.rows.Select(x => (Guid?)x.EducationSchedulingAdjustmentID).ToList(); var teacherList = teacherQuery.Where(x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)) .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name) .ToList(); var toTeacherList = toTeacherQuery.Where(x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)) .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList(); result.rows.ForEach(x => { x.TeacherNames = string.Join(",", teacherList .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID) .Select(w => w.Name)); x.ToTeacherNames = string.Join(",", toTeacherList .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID) .Select(w => w.Name)); x.RecordStatusName = statusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name; }); } else { var teacherList = teacherQuery .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList(); var toTeacherList = toTeacherQuery .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList(); result.rows.ForEach(x => { x.TeacherNames = string.Join(",", teacherList .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID) .Select(w => w.Name)); x.ToTeacherNames = string.Join(",", toTeacherList .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID) .Select(w => w.Name)); x.RecordStatusName = statusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name; }); } return result; } public List GetScheduleAdjustmentViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? coursematerialID, Guid? collegeID, Guid? userID, Guid? classroomID, Guid? applyUserID, DateTime? startTime, DateTime? endTime, int? recordStatus) { return this.GetScheduleAdjustmentViewList(configuretView, schoolyearID, coursematerialID, collegeID, userID, classroomID, applyUserID, startTime, endTime, recordStatus, null, null).rows; } public void OnApproved(List scheduleAdjustmentIDList, Guid userID) { var scheduleAdjustmentList = EducationSchedulingAdjustmentDAL.EducationSchedulingAdjustmentRepository .GetList(x => scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID), (x => x.ES_EducationSchedulingAdjustmentTeacher), (x => x.ES_EducationSchedulingAdjustmentToTeacher)).ToList(); var endStatusID = this.GetCorrectEndStatus(); var startStatusID = this.GetStartStatus(); var backpointStatusList = this.GetBackpointStatus(); var submitedStatusList = this.GetStatusViewList().Where(x => x.ID != startStatusID && x.ID != endStatusID && !backpointStatusList.Contains(x.ID)).Select(x => x.ID).ToList(); var currentSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear(); var adjustmentList = this.EducationSchedulingAdjustmentDAL.EducationSchedulingAdjustmentRepository .GetList(x => scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID), (x => x.CoursesTimeID_Nav), (x => x.ToCoursesTimeID_Nav), (x => x.EM_EducationMissionClass.EM_EducationSchedulingClass.Select(w => w.CF_Student))).ToList(); var stopApprovedStatus = this.EducationSchedulingStopServices.Value.GetCorrectEndStatus().Value; var stopList = this.EducationSchedulingStopDAL.GetEducationSchedulingAdjustmentStopView(x => scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID), stopApprovedStatus).ToList(); if (adjustmentList.Any(x => SchoolYearServices.Value.IsTimePassed( currentSchoolyear, x.WeekNum, x.Weekday, x.CoursesTimeID_Nav.StartHour, x.CoursesTimeID_Nav.StartMinutes) && !stopList.Any(w => w.IsStop && w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID)) || adjustmentList.Any(x => SchoolYearServices.Value.IsTimePassed( currentSchoolyear, x.ToWeekNum, x.ToWeekday, x.ToCoursesTimeID_Nav.StartHour, x.ToCoursesTimeID_Nav.StartMinutes))) { throw new Exception("调整前后的时间均不能早于当前时间,请核对。"); } var adjustmentQuery = this.EducationSchedulingDAL .GetConflictAdjustmentSchedule(x => scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID), submitedStatusList); var adjustmentConflictList = this.EducationSchedulingDAL.GetSelfClassroomConflictQueryable(adjustmentQuery).ToList() .Concat(this.EducationSchedulingDAL.GetSelfTeacherConflictQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetSelfStudentConflictQueryable(adjustmentQuery).ToList() .GroupBy(w => new { w.EducationSchedulingWeekNumID, w.EducationSchedulingAdjustmentID }) .Select(w => w.FirstOrDefault()).ToList()) .Concat(this.EducationSchedulingDAL.GetSelfConflictQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetClassroomSeatConflictQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetClassroomReserveQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetClassroomScheduleConflicQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetClassroomConflicQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetClassroomExcessiveUseQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetClassroomAdjustmentConflictQueryable(adjustmentQuery, submitedStatusList).ToList()) .Concat(this.EducationSchedulingDAL.GetCourseScheduleConflictQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetTeacherScheduleConflictQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetTeacherConflictQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetTeacherAdjustmentConflictQueryable(adjustmentQuery, submitedStatusList).ToList()) .Concat(this.EducationSchedulingDAL.GetStudentScheduleConflictQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetStudentConflictQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetStudentAdjustmentConflictQueryable(adjustmentQuery, submitedStatusList).ToList()).ToList(); var dateList = SchoolYearServices.Value.GetDateByCoursesTime(currentSchoolyear.SchoolYearID ?? Guid.Empty, adjustmentList.Select(x => new FullCoursesTimeView { WeekNum = x.ToWeekNum, Weekday = x.ToWeekday }).ToList()); var examinationPlanList = ExaminationPlanDAL.GetExaminationPlanView(x => dateList.Contains(x.ExaminationDate ?? DateTime.MinValue) && x.SchoolyearID == currentSchoolyear.SchoolYearID && x.RecordStatus == (int)EX_ExaminationPlanStatus.Submitted).ToList(); var examinationPlanIDList = examinationPlanList.Select(x => x.ExaminationPlanID).ToList(); var examinationRoomLayoutViewList = ExaminationPlanDAL.GetExaminationRoomLayoutView(x => examinationPlanIDList.Contains((Guid)x.ExaminationPlanID)).ToList(); examinationPlanList.ForEach(x => x.ExaminationRoomLayoutView = new HashSet(examinationRoomLayoutViewList.Where(y => y.ExaminationPlanID == x.ExaminationPlanID))); var firstWeek = currentSchoolyear.FirstWeek.Value.AddDays(1 - (int)currentSchoolyear.FirstWeek.Value.DayOfWeek); adjustmentConflictList = adjustmentConflictList.Concat( adjustmentList.Where(x => examinationPlanList.Any(w => SchoolYearServices.Value.GetStartEndTimeByCourseTime(firstWeek, new FullCoursesTimeView { WeekNum = x.ToWeekNum, Weekday = x.ToWeekday, CoursesTimeID = x.ToCoursesTimeID, StartHour = x.ToCoursesTimeID_Nav.StartHour, StartMinute = x.ToCoursesTimeID_Nav.StartMinutes, EndHour = x.ToCoursesTimeID_Nav.EndHour, EndMinute = x.ToCoursesTimeID_Nav.EndMinutes }).IsOverlap(w.ExaminationDate.Value.Add(w.StartTime.Value), w.ExaminationDate.Value.Add(w.EndTime.Value)) && w.ExaminationRoomLayoutView.Select(v => (Guid?)v.ClassroomID).Contains(x.ToClassroomID)) ).Select(x => new EducationSchedulingConflictView { EducationSchedulingAdjustmentID = x.EducationSchedulingAdjustmentID, EducationMissionClassName = x.EM_EducationMissionClass.Name, WeekNum = x.WeekNum, Weekday = x.Weekday, StartTimes = x.CoursesTimeID_Nav.StartTimes, EndTimes = x.CoursesTimeID_Nav.EndTimes, ClassroomID = x.ClassroomID, Reason = "教室在该节次安排了考试。" }).ToList()).Concat( adjustmentList.Where(x => examinationPlanList.Any(w => SchoolYearServices.Value.GetStartEndTimeByCourseTime(firstWeek, new FullCoursesTimeView { WeekNum = x.ToWeekNum, Weekday = x.ToWeekday, CoursesTimeID = x.ToCoursesTimeID, StartHour = x.ToCoursesTimeID_Nav.StartHour, StartMinute = x.ToCoursesTimeID_Nav.StartMinutes, EndHour = x.ToCoursesTimeID_Nav.EndHour, EndMinute = x.ToCoursesTimeID_Nav.EndMinutes }).IsOverlap(w.ExaminationDate.Value.Add(w.StartTime.Value), w.ExaminationDate.Value.Add(w.EndTime.Value)) && w.ExaminationRoomLayoutView .SelectMany(v => v.Sys_User).Select(v => (Guid?)v.UserID).Contains(x.ToUserID)) ).Select(x => new EducationSchedulingConflictView { EducationSchedulingAdjustmentID = x.EducationSchedulingAdjustmentID, EducationMissionClassName = x.EM_EducationMissionClass.Name, WeekNum = x.WeekNum, Weekday = x.Weekday, StartTimes = x.CoursesTimeID_Nav.StartTimes, EndTimes = x.CoursesTimeID_Nav.EndTimes, ClassroomID = x.ClassroomID, Reason = "教师在该节次安排了考试。" }).ToList()).Concat( adjustmentList.Where(x => examinationPlanList.Any(w => SchoolYearServices.Value.GetStartEndTimeByCourseTime(firstWeek, new FullCoursesTimeView { WeekNum = x.ToWeekNum, Weekday = x.ToWeekday, CoursesTimeID = x.ToCoursesTimeID, StartHour = x.ToCoursesTimeID_Nav.StartHour, StartMinute = x.ToCoursesTimeID_Nav.StartMinutes, EndHour = x.ToCoursesTimeID_Nav.EndHour, EndMinute = x.ToCoursesTimeID_Nav.EndMinutes }).IsOverlap(w.ExaminationDate.Value.Add(w.StartTime.Value), w.ExaminationDate.Value.Add(w.EndTime.Value)) && w.ExaminationRoomLayoutView .SelectMany(v => v.EX_ExaminationRoomStudent).Select(v => v.UserID) .Intersect(x.EM_EducationMissionClass.EM_EducationSchedulingClass.SelectMany(v => v.CF_Student).Select(v => (Guid?)v.UserID)).Count() > 0) ).Select(x => new EducationSchedulingConflictView { EducationSchedulingAdjustmentID = x.EducationSchedulingAdjustmentID, EducationMissionClassName = x.EM_EducationMissionClass.Name, WeekNum = x.WeekNum, Weekday = x.Weekday, StartTimes = x.CoursesTimeID_Nav.StartTimes, EndTimes = x.CoursesTimeID_Nav.EndTimes, ClassroomID = x.ClassroomID, Reason = "学生在该节次安排了考试。" }).ToList()).ToList(); if (adjustmentConflictList.Count > 0) { var errorMessage = string.Join(";", adjustmentConflictList.Select(x => string.Format("{0}第{1}周星期{2}的{3}-{4}节调整失败,原因:{5}", x.EducationMissionClassName, x.WeekNum, WeekDayView.GetWeekdayName(x.Weekday), x.StartTimes, x.EndTimes, x.Reason) )); throw new Exception(errorMessage); } var educationSchedulingList = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingQueryableByAdjustment(x => scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)).Include(x => x.EM_EducationSchedulingClass).ToList(); var educationSchedulingWeekNumList = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingWeekNumQueryableByAdjustment(x => scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)).ToList(); var educationSchedulingTeacherList = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingTeacherQueryableByAdjustment(x => scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)).ToList(); var newEducationSchedulingList = this.EducationSchedulingAdjustmentDAL.GetNewEducationSchedulingQueryableByAdjustment(x => scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)).Include(x => x.EM_EducationSchedulingClass).ToList(); var newEducationSchedulingWeekNumList = this.EducationSchedulingAdjustmentDAL.GetNewEducationSchedulingWeekNumQueryableByAdjustment(x => scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)).ToList(); var newEducationSchedulingTeacherList = this.EducationSchedulingAdjustmentDAL.GetNewEducationSchedulingTeacherQueryableByAdjustment(x => scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)).ToList(); List insertEducationSchedulingList = new List(); List insertEducationSchedulingTeacherList = new List(); List insertEducationSchedulingWeekNumList = new List(); List deleteEducationSchedulingList = new List(); List deleteEducationSchedulingTeacherList = new List(); List deleteEducationSchedulingWeekNumList = new List(); foreach (var scheduleAdjustment in scheduleAdjustmentList) { var educationScheduling = educationSchedulingList .FirstOrDefault(x => x.Weekday == scheduleAdjustment.Weekday && x.CoursesTimeID == scheduleAdjustment.CoursesTimeID && x.EM_EducationSchedulingClass.EducationMissionClassID == scheduleAdjustment.EducationMissionClassID && educationSchedulingTeacherList.Any(w => w.EducationSchedulingID == x.EducationSchedulingID && w.UserID == scheduleAdjustment.UserID) && educationSchedulingWeekNumList.Any(w => w.EducationSchedulingID == x.EducationSchedulingID && scheduleAdjustment.WeekNum == w.WeekNum)); var curEducationSchedulingTeacherList = educationSchedulingTeacherList .Where(w => w.EducationSchedulingID == educationScheduling.EducationSchedulingID) .ToList(); var curEducationSchedulingWeekNumList = educationSchedulingWeekNumList .Where(w => w.EducationSchedulingID == educationScheduling.EducationSchedulingID) .ToList(); if (educationScheduling != null) { var toTeacherList = scheduleAdjustment.ES_EducationSchedulingAdjustmentToTeacher.Select(x => new CourseProcessTeacherView { UserID = x.UserID ?? Guid.Empty, TeachingMethod = x.TeachingMethod }).ToList(); ES_EducationScheduling newEducationScheduling; var curNewEducationSchedulingList = newEducationSchedulingList .Where(x => x.Weekday == scheduleAdjustment.ToWeekday && x.CoursesTimeID == scheduleAdjustment.ToCoursesTimeID && x.EM_EducationSchedulingClass.EducationMissionClassID == scheduleAdjustment.EducationMissionClassID && x.ClassroomID == scheduleAdjustment.ToClassroomID).ToList(); newEducationScheduling = curNewEducationSchedulingList.FirstOrDefault(x => string.Join(",", newEducationSchedulingTeacherList.Where(w => x.EducationSchedulingID == w.EducationSchedulingID) .Select(w => w.UserID.ToString() + "," + w.TeachingMethod).OrderBy(w => w)) == string.Join(",", toTeacherList.Select(w => w.UserID.ToString() + "," + w.TeachingMethod).OrderBy(w => w))); if (newEducationScheduling == null) { newEducationScheduling = new ES_EducationScheduling { EducationSchedulingID = Guid.NewGuid(), SchoolyearID = educationScheduling.SchoolyearID, EducationSchedulingClassID = educationScheduling.EducationSchedulingClassID, EM_EducationSchedulingClass = educationScheduling.EM_EducationSchedulingClass, Weekday = scheduleAdjustment.ToWeekday, CoursesTimeID = scheduleAdjustment.ToCoursesTimeID, ClassroomID = scheduleAdjustment.ToClassroomID }; toTeacherList.ForEach(x => { var educationSchedulingTeacher = new ES_EducationSchedulingTeacher { EducationSchedulingTeacherID = Guid.NewGuid(), EducationSchedulingID = newEducationScheduling.EducationSchedulingID, UserID = x.UserID, TeachingMethod = x.TeachingMethod }; this.SetNewStatus(educationSchedulingTeacher); insertEducationSchedulingTeacherList.Add(educationSchedulingTeacher); newEducationSchedulingTeacherList.Add(educationSchedulingTeacher); }); this.SetNewStatus(newEducationScheduling); insertEducationSchedulingList.Add(newEducationScheduling); newEducationSchedulingList.Add(newEducationScheduling); } var curNewEducationSchedulingWeekNumList = newEducationSchedulingWeekNumList.Where(x => x.EducationSchedulingID == newEducationScheduling.EducationSchedulingID).ToList(); if (curNewEducationSchedulingWeekNumList.Any(w => scheduleAdjustment.ToWeekNum == w.WeekNum && w.EducationSchedulingID != educationScheduling.EducationSchedulingID)) { throw new Exception("调整后的课程周次冲突,请检查课表。"); } var educationSchedulingWeekNum = new ES_EducationSchedulingWeekNum { EducationSchedulingWeekNumID = Guid.NewGuid(), EducationSchedulingID = newEducationScheduling.EducationSchedulingID, WeekNum = scheduleAdjustment.ToWeekNum }; this.SetNewStatus(educationSchedulingWeekNum); insertEducationSchedulingWeekNumList.Add(educationSchedulingWeekNum); newEducationSchedulingWeekNumList.Add(educationSchedulingWeekNum); deleteEducationSchedulingWeekNumList.AddRange(curEducationSchedulingWeekNumList.Where(x => x.EducationSchedulingID == educationScheduling.EducationSchedulingID && x.WeekNum == scheduleAdjustment.WeekNum).ToList()); educationSchedulingWeekNumList.RemoveAll(x => x.EducationSchedulingID == educationScheduling.EducationSchedulingID && x.WeekNum == scheduleAdjustment.WeekNum); curEducationSchedulingWeekNumList.RemoveAll(x => x.EducationSchedulingID == educationScheduling.EducationSchedulingID && x.WeekNum == scheduleAdjustment.WeekNum); newEducationSchedulingWeekNumList.RemoveAll(x => x.EducationSchedulingID == educationScheduling.EducationSchedulingID && x.WeekNum == scheduleAdjustment.WeekNum); if (curEducationSchedulingWeekNumList.Count == 0) { deleteEducationSchedulingTeacherList.AddRange(curEducationSchedulingTeacherList); deleteEducationSchedulingList.Add(educationScheduling); } } else { throw new Exception("原先选定的课程已经被调整。"); } } using (var scope = new TransactionScope()) { UnitOfWork.BulkInsert(insertEducationSchedulingList); UnitOfWork.BulkInsert(insertEducationSchedulingTeacherList); UnitOfWork.BulkInsert(insertEducationSchedulingWeekNumList); UnitOfWork.Delete(deleteEducationSchedulingWeekNumList); UnitOfWork.Delete(deleteEducationSchedulingTeacherList); UnitOfWork.Delete(deleteEducationSchedulingList); scope.Complete(); } } public ScheduleAdjustmentEditView GetScheduleAdjustmentEditView(Guid educationAdjustmentSchedulingID) { var result = this.EducationSchedulingAdjustmentDAL .GetScheduleAdjustmentEditViewQueryable(x => x.EducationSchedulingAdjustmentID == educationAdjustmentSchedulingID, (x => true), (x => true), (x => true)).FirstOrDefault(); return result; } public void Delete(IList adjustmentIDList) { var startStatus = this.GetStartStatus(); var submitedAdjustmentList = this.EducationSchedulingAdjustmentDAL.EducationSchedulingAdjustmentRepository .GetList(x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID) && x.RecordStatus != startStatus).ToList(); if (submitedAdjustmentList.Count > 0) { throw new Exception("所选记录当中存在已经提交的记录,无法删除。"); } var nullableAdjustmentIDList = adjustmentIDList.Select(x => (Guid?)x).ToList(); this.UnitOfWork.Delete(x => nullableAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)); this.UnitOfWork.Delete(x => nullableAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)); this.UnitOfWork.Delete(x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)); } public void Submit(IList adjustmentIDList, Guid userID) { var startStatusID = this.GetStartStatus(); var endStatusID = this.GetCorrectEndStatus(); var backpointStatusList = this.GetBackpointStatus(); var submitedStatusList = this.GetStatusViewList().Where(x => x.ID != startStatusID && x.ID != endStatusID && !backpointStatusList.Contains(x.ID)).Select(x => x.ID).ToList(); var currentSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear(); var adjustmentList = this.EducationSchedulingAdjustmentDAL.EducationSchedulingAdjustmentRepository .GetList(x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID), (x => x.CoursesTimeID_Nav), (x => x.ToCoursesTimeID_Nav), (x => x.EM_EducationMissionClass.EM_EducationSchedulingClass.Select(w => w.CF_Student))).ToList(); if (adjustmentList.Any(x => x.RecordStatus != startStatusID && !backpointStatusList.Contains(x.RecordStatus))) { throw new Exception("只能提交已提交和已退回的记录。"); } var stopApprovedStatus = this.EducationSchedulingStopServices.Value.GetCorrectEndStatus().Value; var stopList = this.EducationSchedulingStopDAL.GetEducationSchedulingAdjustmentStopView(x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID), stopApprovedStatus).ToList(); if (adjustmentList.Any(x => SchoolYearServices.Value.IsTimePassed( currentSchoolyear, x.WeekNum, x.Weekday, x.CoursesTimeID_Nav.StartHour, x.CoursesTimeID_Nav.StartMinutes) && !stopList.Any(w => w.IsStop && w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID)) || adjustmentList.Any(x => SchoolYearServices.Value.IsTimePassed( currentSchoolyear, x.ToWeekNum, x.ToWeekday, x.ToCoursesTimeID_Nav.StartHour, x.ToCoursesTimeID_Nav.StartMinutes))) { throw new Exception("调整前后的时间均不能早于当前时间,请核对。"); } var adjustmentQuery = this.EducationSchedulingDAL.GetConflictAdjustmentSchedule(x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID), submitedStatusList); var adjustmentConflictList = //提交的各调整记录之间的教室冲突 this.EducationSchedulingDAL.GetSelfClassroomConflictQueryable(adjustmentQuery).ToList() //提交的各调整记录之间的教师冲突 .Concat(this.EducationSchedulingDAL.GetSelfTeacherConflictQueryable(adjustmentQuery).ToList()) //提交的各调整记录之间的学生冲突 .Concat(this.EducationSchedulingDAL.GetSelfStudentConflictQueryable(adjustmentQuery).ToList() .GroupBy(w => new { w.EducationSchedulingWeekNumID, w.EducationSchedulingAdjustmentID }) .Select(w => w.FirstOrDefault()).ToList()) //提交的各调整记录之间的同一节课的重复调动冲突 .Concat(this.EducationSchedulingDAL.GetSelfConflictQueryable(adjustmentQuery).ToList()) //座位不足冲突 .Concat(this.EducationSchedulingDAL.GetClassroomSeatConflictQueryable(adjustmentQuery).ToList()) //教室预留冲突 .Concat(this.EducationSchedulingDAL.GetClassroomReserveQueryable(adjustmentQuery).ToList()) //教室可排时间冲突 .Concat(this.EducationSchedulingDAL.GetClassroomScheduleConflicQueryable(adjustmentQuery).ToList()) //教室课表冲突 .Concat(this.EducationSchedulingDAL.GetClassroomConflicQueryable(adjustmentQuery).ToList()) //教室占用冲突 .Concat(this.EducationSchedulingDAL.GetClassroomExcessiveUseQueryable(adjustmentQuery).ToList()) //教室被他人调课占用冲突 .Concat(this.EducationSchedulingDAL.GetClassroomAdjustmentConflictQueryable(adjustmentQuery, submitedStatusList).ToList()) //课程可排时间冲突 .Concat(this.EducationSchedulingDAL.GetCourseScheduleConflictQueryable(adjustmentQuery).ToList()) //教师可排时间冲突 .Concat(this.EducationSchedulingDAL.GetTeacherScheduleConflictQueryable(adjustmentQuery).ToList()) //教师课表冲突 .Concat(this.EducationSchedulingDAL.GetTeacherConflictQueryable(adjustmentQuery).ToList()) //教师被他人调课占用冲突 .Concat(this.EducationSchedulingDAL.GetTeacherAdjustmentConflictQueryable(adjustmentQuery, submitedStatusList).ToList()) //班级可排时间冲突 .Concat(this.EducationSchedulingDAL.GetStudentScheduleConflictQueryable(adjustmentQuery).ToList()) //学生课表冲突 .Concat(this.EducationSchedulingDAL.GetStudentConflictQueryable(adjustmentQuery).ToList()) //学生被他人调课占用冲突 .Concat(this.EducationSchedulingDAL.GetStudentAdjustmentConflictQueryable(adjustmentQuery, submitedStatusList).ToList()) .ToList(); var dateList = SchoolYearServices.Value.GetDateByCoursesTime(currentSchoolyear.SchoolYearID ?? Guid.Empty, adjustmentList.Select(x => new FullCoursesTimeView { WeekNum = x.ToWeekNum, Weekday = x.ToWeekday }).ToList()); var examinationPlanList = ExaminationPlanDAL.GetExaminationPlanView(x => dateList.Contains(x.ExaminationDate ?? DateTime.MinValue) && x.SchoolyearID == currentSchoolyear.SchoolYearID && x.RecordStatus == (int)EX_ExaminationPlanStatus.Submitted).ToList(); var examinationPlanIDList = examinationPlanList.Select(x => x.ExaminationPlanID).ToList(); var examinationRoomLayoutViewList = ExaminationPlanDAL.GetExaminationRoomLayoutView(x => examinationPlanIDList.Contains((Guid)x.ExaminationPlanID)).ToList(); examinationPlanList.ForEach(x => x.ExaminationRoomLayoutView = new HashSet(examinationRoomLayoutViewList.Where(y => y.ExaminationPlanID == x.ExaminationPlanID))); var firstWeek = currentSchoolyear.FirstWeek.Value.AddDays(1 - (int)currentSchoolyear.FirstWeek.Value.DayOfWeek); //学年学期还有问题,应该按照提交的记录找出他们的学年学期 adjustmentConflictList = adjustmentConflictList.Concat( adjustmentList.Where(x => examinationPlanList.Any(w => SchoolYearServices.Value.GetStartEndTimeByCourseTime(firstWeek, new FullCoursesTimeView { WeekNum = x.ToWeekNum, Weekday = x.ToWeekday, CoursesTimeID = x.ToCoursesTimeID, StartHour = x.ToCoursesTimeID_Nav.StartHour, StartMinute = x.ToCoursesTimeID_Nav.StartMinutes, EndHour = x.ToCoursesTimeID_Nav.EndHour, EndMinute = x.ToCoursesTimeID_Nav.EndMinutes }).IsOverlap(w.ExaminationDate.Value.Add(w.StartTime.Value), w.ExaminationDate.Value.Add(w.EndTime.Value)) && w.ExaminationRoomLayoutView.Select(v => (Guid?)v.ClassroomID).Contains(x.ToClassroomID)) ).Select(x => new EducationSchedulingConflictView { EducationSchedulingAdjustmentID = x.EducationSchedulingAdjustmentID, EducationMissionClassName = x.EM_EducationMissionClass.Name, WeekNum = x.WeekNum, Weekday = x.Weekday, StartTimes = x.CoursesTimeID_Nav.StartTimes, EndTimes = x.CoursesTimeID_Nav.EndTimes, ClassroomID = x.ClassroomID, Reason = "教室在该节次安排了考试。" }).ToList()).Concat( adjustmentList.Where(x => examinationPlanList.Any(w => SchoolYearServices.Value.GetStartEndTimeByCourseTime(firstWeek, new FullCoursesTimeView { WeekNum = x.ToWeekNum, Weekday = x.ToWeekday, CoursesTimeID = x.ToCoursesTimeID, StartHour = x.ToCoursesTimeID_Nav.StartHour, StartMinute = x.ToCoursesTimeID_Nav.StartMinutes, EndHour = x.ToCoursesTimeID_Nav.EndHour, EndMinute = x.ToCoursesTimeID_Nav.EndMinutes }).IsOverlap(w.ExaminationDate.Value.Add(w.StartTime.Value), w.ExaminationDate.Value.Add(w.EndTime.Value)) && w.ExaminationRoomLayoutView .SelectMany(v => v.Sys_User).Select(v => (Guid?)v.UserID).Contains(x.ToUserID)) ).Select(x => new EducationSchedulingConflictView { EducationSchedulingAdjustmentID = x.EducationSchedulingAdjustmentID, EducationMissionClassName = x.EM_EducationMissionClass.Name, WeekNum = x.WeekNum, Weekday = x.Weekday, StartTimes = x.CoursesTimeID_Nav.StartTimes, EndTimes = x.CoursesTimeID_Nav.EndTimes, ClassroomID = x.ClassroomID, Reason = "教师在该节次安排了考试。" }).ToList()).Concat( adjustmentList.Where(x => examinationPlanList.Any(w => SchoolYearServices.Value.GetStartEndTimeByCourseTime(firstWeek, new FullCoursesTimeView { WeekNum = x.ToWeekNum, Weekday = x.ToWeekday, CoursesTimeID = x.ToCoursesTimeID, StartHour = x.ToCoursesTimeID_Nav.StartHour, StartMinute = x.ToCoursesTimeID_Nav.StartMinutes, EndHour = x.ToCoursesTimeID_Nav.EndHour, EndMinute = x.ToCoursesTimeID_Nav.EndMinutes }).IsOverlap(w.ExaminationDate.Value.Add(w.StartTime.Value), w.ExaminationDate.Value.Add(w.EndTime.Value)) && w.ExaminationRoomLayoutView .SelectMany(v => v.EX_ExaminationRoomStudent).Select(v => v.UserID) .Intersect(x.EM_EducationMissionClass.EM_EducationSchedulingClass.SelectMany(v => v.CF_Student).Select(v => (Guid?)v.UserID)).Count() > 0) ).Select(x => new EducationSchedulingConflictView { EducationSchedulingAdjustmentID = x.EducationSchedulingAdjustmentID, EducationMissionClassName = x.EM_EducationMissionClass.Name, WeekNum = x.WeekNum, Weekday = x.Weekday, StartTimes = x.CoursesTimeID_Nav.StartTimes, EndTimes = x.CoursesTimeID_Nav.EndTimes, ClassroomID = x.ClassroomID, Reason = "学生在该节次安排了考试。" }).ToList()).ToList(); if (adjustmentConflictList.Count > 0) { var errorMessage = string.Join(";", adjustmentConflictList.Select(x => string.Format("{0}第{1}周{2}的{3}-{4}节调整失败,原因:{5}", x.EducationMissionClassName, x.WeekNum, WeekDayView.GetWeekdayName(x.Weekday), x.StartTimes, x.EndTimes, x.Reason) )); throw new Exception(errorMessage); } var notSubmitList = adjustmentList.Where(x => x.RecordStatus == startStatusID).Select(x => x.EducationSchedulingAdjustmentID).ToList(); var submitedList = adjustmentList.Where(x => x.RecordStatus != startStatusID).Select(x => x.EducationSchedulingAdjustmentID).ToList(); if (notSubmitList.Count > 0) { this.StartUp(notSubmitList, userID); } if (submitedList.Count > 0) { var action = this.GetActionView(submitedList.First(), userID).FirstOrDefault(); if (action != null) { this.Approve(submitedList, userID, action.ActionID); } } var nowTime = DateTime.Now; UnitOfWork.Update((x => new ES_EducationSchedulingAdjustment { ApplyUserID = userID, ApplyTime = nowTime }), (x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID))); } public IGridResultSet GetScheduleAdjustmentViewApproveList(ConfiguretView configuretView, Guid? schoolyearID, Guid? coursematerialID, Guid? collegeID, Guid? userID, Guid? classroomID, Guid? applyUserID, DateTime? startTime, DateTime? endTime, int? recordStatus, int? pageIndex, int? pageSize) { var statusList = this.GetStatusViewList(); Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> missionExp = (x => true); Expression> missionClassExp = (x => true); Expression> staffExp = (x => true); if (schoolyearID.HasValue) { missionExp = missionExp.And(x => x.SchoolyearID == schoolyearID); } if (coursematerialID.HasValue) { missionClassExp = missionClassExp.And(x => x.CoursematerialID == coursematerialID); } if (collegeID.HasValue) { staffExp = staffExp.And(x => x.CollegeID == collegeID); } if (userID.HasValue) { exp = exp.And(x => x.ES_EducationSchedulingAdjustmentTeacher.Any(y => y.UserID == userID)); //staffExp = staffExp.And(x => x.UserID == userID); } if (classroomID.HasValue) { exp = exp.And(x => x.ClassroomID == classroomID); } if (applyUserID.HasValue) { exp = exp.And(x => x.CreateUserID == applyUserID); } if (startTime.HasValue) { exp = exp.And(x => x.ApplyTime >= startTime); } if (endTime.HasValue) { var correctEndTime = endTime.Value.Date.AddDays(1); exp = exp.And(x => x.ApplyTime < correctEndTime); } if (recordStatus.HasValue) { exp = exp.And(x => x.RecordStatus == recordStatus); } var query = this.EducationSchedulingAdjustmentDAL.GetScheduleAdjustmentViewQueryable(exp, missionExp, missionClassExp, staffExp); var teacherQuery = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingAdjustmentTeacherQueryable( exp, missionExp, missionClassExp, staffExp); var toTeacherQuery = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingAdjustmentToTeacherQueryable( exp, missionExp, missionClassExp, staffExp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); query = this.GetQueryByDataRangeByDepartment(query); var resultQuery = query.OrderByDescending(x => x.SchoolyearCode) .ThenByDescending(x => x.ApplyTime).ThenBy(x => x.ApplyUserID).ThenBy(x => x.WeekNum).ThenBy(x => x.Weekday) .ThenBy(x => x.StartTimes); var result = resultQuery.ToGridResultSet(pageIndex, pageSize); if (pageIndex.HasValue && pageSize.HasValue) { var adjustmentIDList = result.rows.Select(x => (Guid?)x.EducationSchedulingAdjustmentID).ToList(); var teacherList = teacherQuery.Where(x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)) .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name) .ToList(); var toTeacherList = toTeacherQuery.Where(x => adjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)) .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList(); result.rows.ForEach(x => { x.TeacherNames = string.Join(",", teacherList .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID) .Select(w => w.Name)); x.ToTeacherNames = string.Join(",", toTeacherList .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID) .Select(w => w.Name)); x.RecordStatusName = statusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name; }); } else { var teacherList = teacherQuery .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList(); var toTeacherList = toTeacherQuery .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList(); result.rows.ForEach(x => { x.TeacherNames = string.Join(",", teacherList .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID) .Select(w => w.Name)); x.ToTeacherNames = string.Join(",", toTeacherList .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID) .Select(w => w.Name)); x.RecordStatusName = statusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name; }); } return result; } public List GetScheduleAdjustmentViewApproveList(ConfiguretView configuretView, Guid? schoolyearID, Guid? coursematerialID, Guid? collegeID, Guid? userID, Guid? classroomID, Guid? applyUserID, DateTime? startTime, DateTime? endTime, int? recordStatus) { return this.GetScheduleAdjustmentViewApproveList(configuretView, schoolyearID, coursematerialID, collegeID, userID, classroomID, applyUserID, startTime, endTime, recordStatus, null, null).rows; } public List GetScheduleAdjustmentViewList(IList scheduleAdjustmentIDList) { if (scheduleAdjustmentIDList.Count == 0) { throw new Exception("请选择需要查询的调课记录。"); } var statusList = this.GetStatusViewList(); Expression> exp = (x => scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)); var query = this.EducationSchedulingAdjustmentDAL.GetScheduleAdjustmentViewQueryable(exp, (x => true), (x => true), (x => true)); var teacherQuery = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingAdjustmentTeacherQueryable( exp, (x => true), (x => true), (x => true)); var toTeacherQuery = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingAdjustmentToTeacherQueryable( exp, (x => true), (x => true), (x => true)); query = this.GetQueryByDataRange(query, (x => x.UserID)); var resultQuery = query.OrderByDescending(x => x.SchoolyearCode) .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo) .ThenBy(x => x.CourseName).ThenBy(x => x.UserName); var result = resultQuery.ToList(); var teacherList = teacherQuery .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList(); var toTeacherList = toTeacherQuery .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList(); result.ForEach(x => { x.TeacherNames = string.Join(",", teacherList .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID) .Select(w => w.Name)); x.ToTeacherNames = string.Join(",", toTeacherList .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID) .Select(w => w.Name)); x.RecordStatusName = statusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name; }); return result; } public List GetScheduleAdjustmentViewApproveList(IList scheduleAdjustmentIDList) { if (scheduleAdjustmentIDList.Count == 0) { throw new Exception("请选择需要查询的调课记录。"); } var statusList = this.GetStatusViewList(); Expression> exp = (x => scheduleAdjustmentIDList.Contains(x.EducationSchedulingAdjustmentID)); var query = this.EducationSchedulingAdjustmentDAL.GetScheduleAdjustmentViewQueryable(exp, (x => true), (x => true), (x => true)); var teacherQuery = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingAdjustmentTeacherQueryable( exp, (x => true), (x => true), (x => true)); var toTeacherQuery = this.EducationSchedulingAdjustmentDAL.GetEducationSchedulingAdjustmentToTeacherQueryable( exp, (x => true), (x => true), (x => true)); query = this.GetQueryByDataRangeByDepartment(query); var resultQuery = query.OrderByDescending(x => x.SchoolyearCode) .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo) .ThenBy(x => x.CourseName).ThenBy(x => x.UserName); var result = resultQuery.ToList(); var teacherList = teacherQuery .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList(); var toTeacherList = toTeacherQuery .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList(); result.ForEach(x => { x.TeacherNames = string.Join(",", teacherList .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID) .Select(w => w.Name)); x.ToTeacherNames = string.Join(",", toTeacherList .Where(w => w.EducationSchedulingAdjustmentID == x.EducationSchedulingAdjustmentID) .Select(w => w.Name)); x.RecordStatusName = statusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name; }); return result; } public void BatchSave(IList educationSchedulingWeekNumIDList, Guid fromUserID, int? toWeekNum, int? toWeekday, Guid? toUserID, Guid? toCoursesTimeID, int? toClassroomType, Guid? toClassroom) { var startStatusID = this.GetStartStatus(); var endStatusID = this.GetCorrectEndStatus(); var backpointStatusList = this.GetBackpointStatus(); var submitedStatusList = this.GetStatusViewList().Where(x => x.ID != startStatusID && x.ID != endStatusID && !backpointStatusList.Contains(x.ID)).Select(x => x.ID).ToList(); var currentSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear(); var toCourseTime = this.CoursesTimeServices.Value.GetCoursesTime(toCoursesTimeID); var weekNumList = this.EducationSchedulingDAL.EducationSchedulingWeekNumRepository.GetList(x => educationSchedulingWeekNumIDList.Contains(x.EducationSchedulingWeekNumID), (x => x.ES_EducationScheduling.EM_CoursesTime)).ToList(); var stopApprovedStatus = this.EducationSchedulingStopServices.Value.GetCorrectEndStatus().Value; var stopList = this.EducationSchedulingStopDAL.GetEducationSchedulingWeekNumStopView(x => educationSchedulingWeekNumIDList.Contains(x.EducationSchedulingWeekNumID), stopApprovedStatus).ToList(); if (weekNumList.Any(x => SchoolYearServices.Value.IsTimePassed( currentSchoolyear, x.WeekNum, x.ES_EducationScheduling.Weekday, x.ES_EducationScheduling.EM_CoursesTime.StartHour, x.ES_EducationScheduling.EM_CoursesTime.StartMinutes) && !stopList.Any(w => w.IsStop && w.EducationSchedulingWeekNumID == x.EducationSchedulingWeekNumID)) || ( toCourseTime != null && toWeekNum != null && toWeekday != null && SchoolYearServices.Value.IsTimePassed( currentSchoolyear, toWeekNum, toWeekday, toCourseTime.StartHour, toCourseTime.StartMinutes) )) { throw new Exception("调整前后的时间均不能早于当前时间,请核对。"); } var adjustmentQuery = this.EducationSchedulingDAL.GetConflictAdjustmentSchedule(x => educationSchedulingWeekNumIDList.Contains(x.EducationSchedulingWeekNumID), submitedStatusList, fromUserID, toWeekNum, toWeekday, toUserID, toCoursesTimeID, toClassroom); var adjustmentConflictList = this.EducationSchedulingDAL.GetSelfClassroomConflictQueryable(adjustmentQuery).ToList() .Concat(this.EducationSchedulingDAL.GetSelfTeacherConflictQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetSelfStudentConflictQueryable(adjustmentQuery).ToList() .GroupBy(w => new { w.EducationSchedulingWeekNumID, w.EducationSchedulingAdjustmentID }) .Select(w => w.FirstOrDefault()).ToList()) .Concat(this.EducationSchedulingDAL.GetSelfConflictQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetClassroomSeatConflictQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetClassroomReserveQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetClassroomScheduleConflicQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetClassroomConflicQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetClassroomExcessiveUseQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetClassroomAdjustmentConflictQueryable(adjustmentQuery, submitedStatusList).ToList()) .Concat(this.EducationSchedulingDAL.GetCourseScheduleConflictQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetTeacherScheduleConflictQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetTeacherConflictQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetTeacherAdjustmentConflictQueryable(adjustmentQuery, submitedStatusList).ToList()) .Concat(this.EducationSchedulingDAL.GetStudentScheduleConflictQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetStudentConflictQueryable(adjustmentQuery).ToList()) .Concat(this.EducationSchedulingDAL.GetStudentAdjustmentConflictQueryable(adjustmentQuery, submitedStatusList).ToList()) .Concat(this.EducationSchedulingDAL.GetArrangementsQueryable(adjustmentQuery).ToList()).ToList(); //var adjustmentConflictList = this.EducationSchedulingDAL.GetConflictAdjustmentSchedule(x => educationSchedulingWeekNumIDList.Contains(x.EducationSchedulingWeekNumID), // submitedStatusList, fromUserID, toWeekNum, toWeekday, toUserID, toCoursesTimeID, toClassroom).ToList(); var educationSchedulingWeekNumList = this.EducationSchedulingDAL.EducationSchedulingWeekNumRepository .GetList(x => educationSchedulingWeekNumIDList.Contains(x.EducationSchedulingWeekNumID), (x => x.ES_EducationScheduling.EM_CoursesTime), (x => x.ES_EducationScheduling.EM_EducationSchedulingClass.EM_EducationMissionClass), (x => x.ES_EducationScheduling.ES_EducationSchedulingTeacher)).ToList(); var dateList = SchoolYearServices.Value.GetDateByCoursesTime(currentSchoolyear.SchoolYearID ?? Guid.Empty, educationSchedulingWeekNumList.GroupBy(x => new FullCoursesTimeView { WeekNum = toWeekNum.HasValue ? toWeekNum : x.WeekNum, Weekday = toWeekday.HasValue ? toWeekday : x.ES_EducationScheduling.Weekday }).Select(x => x.Key).ToList()); var examinationPlanList = ExaminationPlanDAL.GetExaminationPlanView(x => dateList.Contains(x.ExaminationDate ?? DateTime.MinValue) && x.SchoolyearID == currentSchoolyear.SchoolYearID && x.RecordStatus == (int)EX_ExaminationPlanStatus.Submitted).ToList(); var examinationPlanIDList = examinationPlanList.Select(x => x.ExaminationPlanID).ToList(); var examinationRoomLayoutViewList = ExaminationPlanDAL.GetExaminationRoomLayoutView(x => examinationPlanIDList.Contains((Guid)x.ExaminationPlanID)).ToList(); examinationPlanList.ForEach(x => x.ExaminationRoomLayoutView = new HashSet(examinationRoomLayoutViewList.Where(y => y.ExaminationPlanID == x.ExaminationPlanID))); var firstWeek = currentSchoolyear.FirstWeek.Value.AddDays(1 - (int)currentSchoolyear.FirstWeek.Value.DayOfWeek); //学年学期还有问题,应该按照提交的记录找出他们的学年学期 adjustmentConflictList = adjustmentConflictList.Concat( educationSchedulingWeekNumList.Where(x => examinationPlanList.Any(w => SchoolYearServices.Value.GetStartEndTimeByCourseTime(firstWeek, new FullCoursesTimeView { WeekNum = toWeekNum.HasValue ? toWeekNum : x.WeekNum, Weekday = toWeekday.HasValue ? toWeekday : x.ES_EducationScheduling.Weekday, CoursesTimeID = toCoursesTimeID.HasValue ? toCoursesTimeID : x.ES_EducationScheduling.CoursesTimeID, StartHour = toCoursesTimeID.HasValue ? toCourseTime.StartHour : x.ES_EducationScheduling.EM_CoursesTime.StartHour, StartMinute = toCoursesTimeID.HasValue ? toCourseTime.StartMinutes : x.ES_EducationScheduling.EM_CoursesTime.StartMinutes, EndHour = toCoursesTimeID.HasValue ? toCourseTime.EndHour : x.ES_EducationScheduling.EM_CoursesTime.EndHour, EndMinute = toCoursesTimeID.HasValue ? toCourseTime.EndMinutes : x.ES_EducationScheduling.EM_CoursesTime.EndMinutes }).IsOverlap(w.ExaminationDate.Value.Add(w.StartTime.Value), w.ExaminationDate.Value.Add(w.EndTime.Value)) && w.ExaminationRoomLayoutView.Select(v => (Guid?)v.ClassroomID) .Contains((toClassroom.HasValue ? toClassroom : x.ES_EducationScheduling.ClassroomID))) ).Select(x => new EducationSchedulingConflictView { EducationSchedulingWeekNumID = x.EducationSchedulingWeekNumID, EducationSchedulingAdjustmentID = null, EducationMissionClassName = x.ES_EducationScheduling.EM_EducationSchedulingClass.EM_EducationMissionClass.Name, WeekNum = x.WeekNum, Weekday = x.ES_EducationScheduling.Weekday, StartTimes = x.ES_EducationScheduling.EM_CoursesTime.StartTimes, EndTimes = x.ES_EducationScheduling.EM_CoursesTime.EndTimes, ClassroomID = x.ES_EducationScheduling.ClassroomID, Reason = "教室在该节次安排了考试。" }).ToList()).Concat( educationSchedulingWeekNumList.Where(x => examinationPlanList.Any(w => SchoolYearServices.Value.GetStartEndTimeByCourseTime(firstWeek, new FullCoursesTimeView { WeekNum = toWeekNum.HasValue ? toWeekNum : x.WeekNum, Weekday = toWeekday.HasValue ? toWeekday : x.ES_EducationScheduling.Weekday, CoursesTimeID = toCoursesTimeID.HasValue ? toCoursesTimeID : x.ES_EducationScheduling.CoursesTimeID, StartHour = toCoursesTimeID.HasValue ? toCourseTime.StartHour : x.ES_EducationScheduling.EM_CoursesTime.StartHour, StartMinute = toCoursesTimeID.HasValue ? toCourseTime.StartMinutes : x.ES_EducationScheduling.EM_CoursesTime.StartMinutes, EndHour = toCoursesTimeID.HasValue ? toCourseTime.EndHour : x.ES_EducationScheduling.EM_CoursesTime.EndHour, EndMinute = toCoursesTimeID.HasValue ? toCourseTime.EndMinutes : x.ES_EducationScheduling.EM_CoursesTime.EndMinutes }).IsOverlap(w.ExaminationDate.Value.Add(w.StartTime.Value), w.ExaminationDate.Value.Add(w.EndTime.Value)) && w.ExaminationRoomLayoutView .SelectMany(v => v.Sys_User).Select(v => (Guid?)v.UserID) .Intersect( x.ES_EducationScheduling.ES_EducationSchedulingTeacher .Select(v => (toUserID.HasValue ? (v.UserID == fromUserID ? toUserID : (Guid?)v.UserID) : (Guid?)v.UserID)) ).Count() > 0) ).Select(x => new EducationSchedulingConflictView { EducationSchedulingWeekNumID = x.EducationSchedulingWeekNumID, EducationSchedulingAdjustmentID = null, EducationMissionClassName = x.ES_EducationScheduling.EM_EducationSchedulingClass.EM_EducationMissionClass.Name, WeekNum = x.WeekNum, Weekday = x.ES_EducationScheduling.Weekday, StartTimes = x.ES_EducationScheduling.EM_CoursesTime.StartTimes, EndTimes = x.ES_EducationScheduling.EM_CoursesTime.EndTimes, ClassroomID = x.ES_EducationScheduling.ClassroomID, Reason = "教师在该节次安排了考试。" }).ToList()).Concat( educationSchedulingWeekNumList.Where(x => examinationPlanList.Any(w => SchoolYearServices.Value.GetStartEndTimeByCourseTime(firstWeek, new FullCoursesTimeView { WeekNum = toWeekNum.HasValue ? toWeekNum : x.WeekNum, Weekday = toWeekday.HasValue ? toWeekday : x.ES_EducationScheduling.Weekday, CoursesTimeID = toCoursesTimeID.HasValue ? toCoursesTimeID : x.ES_EducationScheduling.CoursesTimeID, StartHour = toCoursesTimeID.HasValue ? toCourseTime.StartHour : x.ES_EducationScheduling.EM_CoursesTime.StartHour, StartMinute = toCoursesTimeID.HasValue ? toCourseTime.StartMinutes : x.ES_EducationScheduling.EM_CoursesTime.StartMinutes, EndHour = toCoursesTimeID.HasValue ? toCourseTime.EndHour : x.ES_EducationScheduling.EM_CoursesTime.EndHour, EndMinute = toCoursesTimeID.HasValue ? toCourseTime.EndMinutes : x.ES_EducationScheduling.EM_CoursesTime.EndMinutes }).IsOverlap(w.ExaminationDate.Value.Add(w.StartTime.Value), w.ExaminationDate.Value.Add(w.EndTime.Value)) && w.ExaminationRoomLayoutView .SelectMany(v => v.EX_ExaminationRoomStudent).Select(v => v.UserID) .Intersect(x.ES_EducationScheduling.EM_EducationSchedulingClass.CF_Student.Select(v => (Guid?)v.UserID)).Count() > 0) ).Select(x => new EducationSchedulingConflictView { EducationSchedulingWeekNumID = x.EducationSchedulingWeekNumID, EducationSchedulingAdjustmentID = null, EducationMissionClassName = x.ES_EducationScheduling.EM_EducationSchedulingClass.EM_EducationMissionClass.Name, WeekNum = x.WeekNum, Weekday = x.ES_EducationScheduling.Weekday, StartTimes = x.ES_EducationScheduling.EM_CoursesTime.StartTimes, EndTimes = x.ES_EducationScheduling.EM_CoursesTime.EndTimes, ClassroomID = x.ES_EducationScheduling.ClassroomID, Reason = "学生在该节次安排了考试。" }).ToList()).ToList(); if (adjustmentConflictList.Count > 0) { var errorMessage = string.Join(";", adjustmentConflictList.Select(x => string.Format("{0}第{1}周星期{2}的{3}-{4}节调整失败,原因:{5}", x.EducationMissionClassName, x.WeekNum, WeekDayView.GetWeekdayName(x.Weekday), x.StartTimes, x.EndTimes, x.Reason) )); throw new Exception(errorMessage); } if (educationSchedulingWeekNumList.Count != educationSchedulingWeekNumIDList.Count) { throw new Exception("所选部分排课记录不存在,可能已经被修改,请重新查询排课列表并选择。"); } List insertList = new List(); List fromTeacherInsertList = new List(); List toTeacherInsertList = new List(); foreach (var educationSchedulingWeekNum in educationSchedulingWeekNumList) { var scheduleAdjustment = new ES_EducationSchedulingAdjustment(); { scheduleAdjustment.EducationSchedulingAdjustmentID = Guid.NewGuid(); this.SetNewStatus(scheduleAdjustment); scheduleAdjustment.RecordStatus = startStatusID; insertList.Add(scheduleAdjustment); } scheduleAdjustment.EducationMissionClassID = educationSchedulingWeekNum .ES_EducationScheduling .EM_EducationSchedulingClass .EducationMissionClassID; scheduleAdjustment.Weekday = educationSchedulingWeekNum .ES_EducationScheduling .Weekday; scheduleAdjustment.CoursesTimeID = educationSchedulingWeekNum .ES_EducationScheduling .CoursesTimeID; scheduleAdjustment.ClassroomTypeID = educationSchedulingWeekNum .ES_EducationScheduling .EM_EducationSchedulingClass .EM_EducationMissionClass .ClassroomTypeID; scheduleAdjustment.ClassroomID = educationSchedulingWeekNum .ES_EducationScheduling .ClassroomID; scheduleAdjustment.UserID = fromUserID; scheduleAdjustment.ToWeekday = toWeekday.HasValue ? toWeekday : educationSchedulingWeekNum .ES_EducationScheduling .Weekday; scheduleAdjustment.ToCoursesTimeID = toCoursesTimeID.HasValue ? toCoursesTimeID : educationSchedulingWeekNum .ES_EducationScheduling .CoursesTimeID; scheduleAdjustment.ToClassroomTypeID = toClassroomType.HasValue ? toClassroomType : educationSchedulingWeekNum .ES_EducationScheduling .EM_EducationSchedulingClass .EM_EducationMissionClass .ClassroomTypeID; scheduleAdjustment.ToClassroomID = toClassroom.HasValue ? toClassroom : educationSchedulingWeekNum .ES_EducationScheduling .ClassroomID; scheduleAdjustment.ToUserID = toUserID.HasValue ? toUserID : fromUserID; scheduleAdjustment.WeekNum = educationSchedulingWeekNum.WeekNum; scheduleAdjustment.ToWeekNum = toWeekNum.HasValue ? toWeekNum : educationSchedulingWeekNum.WeekNum; foreach (var teacher in educationSchedulingWeekNum.ES_EducationScheduling.ES_EducationSchedulingTeacher) { var fromTeacher = new ES_EducationSchedulingAdjustmentTeacher(); fromTeacher.EducationSchedulingAdjustmentTeacherID = Guid.NewGuid(); fromTeacher.EducationSchedulingAdjustmentID = scheduleAdjustment.EducationSchedulingAdjustmentID; fromTeacher.UserID = teacher.UserID; fromTeacher.TeachingMethod = teacher.TeachingMethod; this.SetNewStatus(fromTeacher); fromTeacherInsertList.Add(fromTeacher); } foreach (var teacher in educationSchedulingWeekNum.ES_EducationScheduling.ES_EducationSchedulingTeacher) { var toTeacher = new ES_EducationSchedulingAdjustmentToTeacher(); toTeacher.EducationSchedulingAdjustmentToTeacherID = Guid.NewGuid(); toTeacher.EducationSchedulingAdjustmentID = scheduleAdjustment.EducationSchedulingAdjustmentID; toTeacher.UserID = (teacher.UserID == scheduleAdjustment.UserID && scheduleAdjustment.ToUserID.HasValue) ? scheduleAdjustment.ToUserID : teacher.UserID; toTeacher.TeachingMethod = teacher.TeachingMethod; this.SetNewStatus(toTeacher); toTeacherInsertList.Add(toTeacher); } } using (var scope = new TransactionScope()) { UnitOfWork.BulkInsert(insertList); UnitOfWork.BulkInsert(fromTeacherInsertList); UnitOfWork.BulkInsert(toTeacherInsertList); scope.Complete(); } } } }