using EMIS.CommonLogic.EducationManagement; using EMIS.DataLogic.Repositories; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.EducationManagement; using EMIS.ViewModel.UniversityManage.TeacherManage; using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.EducationSchedule; using EMIS.ViewModel.EducationManage; using EMIS.DataLogic.SchedulingManage.SchedulingSettings; namespace EMIS.CommonLogic.EducationManagement { public partial class EducationMissionClassServices : BaseServices, IEducationMissionClassServices { public EducationSchedulingDAL EducationSchedulingDAL { get; set; } public StaffRepository StaffRepository { get; set; } public ClassroomScheduleSettingDAL ClassroomScheduleSettingDAL { get; set; } public ClassroomReserveDAL classroomReserveDAL { get; set; } public CollegeClassroomDAL collegeClassroomDAL { get; set; } private void CheckTeacherIsAvailable(EducationMissionClassView educationMissionClassView, List teacherIDList, int? weekday = null, Guid? CoursesTimeID = null) { var notAvailableTeacherMessage = ""; var teacherIsOnWorkList = this.EducationSchedulingDAL.CheckTeacherIsOnWork(x => x.EM_EducationSchedulingClass.EducationMissionClassID == educationMissionClassView.EducationMissionClassID, (x => teacherIDList.Contains(x.UserID))).ToList(); if (teacherIsOnWorkList.Count > 0) { teacherIsOnWorkList.ForEach(x => notAvailableTeacherMessage += string.Format("任务班在{1}第{2}节课有课,但教师{0}在该节次不能排课。\n", x.Name, x.WeekdayDesc, x.Times)); } var teacherIsBusyList = this.EducationSchedulingDAL.CheckTeacherIsBusy(x => x.EM_EducationSchedulingClass.EducationMissionClassID == educationMissionClassView.EducationMissionClassID, (x => teacherIDList.Contains(x.UserID))).ToList(); if (teacherIsBusyList.Count > 0) { teacherIsBusyList.ForEach(x => notAvailableTeacherMessage += string.Format("任务班在{1}第{2}节课有课,但教师{0}在该节次在其他班级有课,不能排课。\n", x.Name, x.WeekdayDesc, x.Times)); } if (!string.IsNullOrEmpty(notAvailableTeacherMessage)) { throw new Exception(notAvailableTeacherMessage); } } /// /// 更新教学任务班表 处理状态 /// /// public void EducationMissionClassUpdateTeacher(EducationMissionClassView educationMissionClassView, List teacherList) { if (educationMissionClassView.EducationMissionClassID != null && educationMissionClassView.EducationMissionClassID != Guid.Empty) { var userList = teacherList.Select(w => w.UserID).ToList(); CheckTeacherIsAvailable(educationMissionClassView, userList); var courseProcessList = educationMissionClassDAL.CourseProcessRepository.GetList(x => x.EducationMissionClassID == educationMissionClassView.EducationMissionClassID, (x => x.EM_CourseProcessTeacher)).ToList(); #region 修改教学任务的任课老师 UnitOfWork.Remove(p => p.MissionClassID == educationMissionClassView.EducationMissionClassID); //如果该用户在任课老师表中不存在、写入进去 teacherList.ForEach(x => { EM_MissionClassTeacher missionClassTeacherEntity = new EM_MissionClassTeacher(); missionClassTeacherEntity.MissionClassTeacherID = Guid.NewGuid(); missionClassTeacherEntity.MissionClassID = educationMissionClassView.EducationMissionClassID; missionClassTeacherEntity.UserID = x.UserID; missionClassTeacherEntity.TeachType = x.TeachingMethod ?? (int)EM_TeachingMethod.Lecturer; SetNewStatus(missionClassTeacherEntity); UnitOfWork.Add(missionClassTeacherEntity); }); #endregion #region 修改课程进度的老师 var newCourseProcessList = courseProcessList.GroupBy(x => new { x.EducationMissionClassID, x.Week, x.ClassroomID, x.ClassroomTypeID }) .Select((x) => new { x.Key.EducationMissionClassID, x.Key.Week, Times = x.Sum(w => w.Times), x.Key.ClassroomID, x.Key.ClassroomTypeID }).ToList(); courseProcessList.ForEach(x => { UnitOfWork.RemoveRange(x.EM_CourseProcessTeacher); UnitOfWork.Remove(x); }); newCourseProcessList.ForEach(x => { var newCourseProcess = new EM_CourseProcess { CourseProcessID = Guid.NewGuid(), EducationMissionClassID = x.EducationMissionClassID, Week = x.Week, Times = x.Times, ClassroomTypeID = x.ClassroomTypeID, ClassroomID = x.ClassroomID }; this.SetNewStatus(newCourseProcess); UnitOfWork.Add(newCourseProcess); teacherList.ForEach(w => { EM_CourseProcessTeacher courseProcessTeacher = new EM_CourseProcessTeacher(); courseProcessTeacher.CourseProcessTeacherID = Guid.NewGuid(); courseProcessTeacher.CourseProcessID = newCourseProcess.CourseProcessID; courseProcessTeacher.UserID = w.UserID; courseProcessTeacher.TeachType = w.TeachingMethod ?? (int)EM_TeachingMethod.Lecturer; SetNewStatus(courseProcessTeacher); UnitOfWork.Add(courseProcessTeacher); }); }); #endregion #region 修改排课的老师 var schedulingList = this.EducationSchedulingDAL.EducationSchedulingRepository.GetList(x => x.EM_EducationSchedulingClass.EducationMissionClassID == educationMissionClassView.EducationMissionClassID, (x => x.ES_EducationSchedulingTeacher)).ToList(); schedulingList.ForEach(x => { UnitOfWork.Remove(p => p.EducationSchedulingID == x.EducationSchedulingID); //如果该用户在任课老师表中不存在、写入进去 teacherList.ForEach(w => { ES_EducationSchedulingTeacher educationSchedulingTeacherEntity = new ES_EducationSchedulingTeacher(); educationSchedulingTeacherEntity.EducationSchedulingTeacherID = Guid.NewGuid(); educationSchedulingTeacherEntity.EducationSchedulingID = x.EducationSchedulingID; educationSchedulingTeacherEntity.UserID = w.UserID; educationSchedulingTeacherEntity.TeachingMethod = w.TeachingMethod ?? (int)EM_TeachingMethod.Lecturer; SetNewStatus(educationSchedulingTeacherEntity); UnitOfWork.Add(educationSchedulingTeacherEntity); }); }); #endregion UnitOfWork.Commit(); } } private void SetEducationMissionClassClassroomID(EM_EducationMissionClass EducationMissionClass, EducationMissionClassView educationMissionClassView) { EducationMissionClass.ClassroomID = educationMissionClassView.ClassroomID; EducationMissionClass.ClassroomTypeID = educationMissionClassView.ClassroomTypeID; SetModifyStatus(EducationMissionClass); EducationMissionClass.EM_CourseProcess.ToList().ForEach(x => { x.ClassroomID = educationMissionClassView.ClassroomID; x.ClassroomTypeID = educationMissionClassView.ClassroomTypeID; SetModifyStatus(x); }); } /// /// 更新教学任务班表 处理状态 /// /// public void EducationMissionClassUpdateClassRoom(EducationMissionClassView educationMissionClassView) { if (educationMissionClassView.EducationMissionClassID != null && educationMissionClassView.EducationMissionClassID != Guid.Empty) { var EducationMissionClass=this.GetEducationMissionClass(educationMissionClassView.EducationMissionClassID); var educationMission = educationMissionClassDAL.GetEducationMissionClassViewQueryble(x => x.EducationMissionClassID == educationMissionClassView.EducationMissionClassID).FirstOrDefault(); if (educationMissionClassView.ApprovalStatus != (int)EM_EducationMissionClassStatus.Scheduled) { SetEducationMissionClassClassroomID(EducationMissionClass, educationMissionClassView); } else { var ClassRoomType = this.ClassroomScheduleDAL.ClassroomDAL.Value.ClassroomRepository.Entities.Where(x => x.ClassroomID == educationMissionClassView.ClassroomID).FirstOrDefault(); if (ClassRoomType.IsConcurrentUse == true) { var before = this.EducationSchedulingDAL.EducationSchedulingRepository.GetList (x => x.EM_EducationSchedulingClass.EducationMissionClassID == educationMissionClassView.EducationMissionClassID, (x => x.ES_EducationSchedulingWeekNum)).ToList(); foreach (var EducationScheduling in before) { //ES_EducationScheduling EducationSchedulings = new ES_EducationScheduling(); //EducationSchedulings.EducationSchedulingID = EducationScheduling.EducationSchedulingID; //EducationSchedulings.SchoolyearID = EducationScheduling.SchoolyearID; //EducationSchedulings.EducationSchedulingClassID = EducationScheduling.EducationSchedulingClassID; //EducationSchedulings.Weekday = EducationScheduling.Weekday; //EducationSchedulings.CoursesTimeID = EducationScheduling.CoursesTimeID; EducationScheduling.ClassroomID = educationMissionClassView.ClassroomID; //EducationSchedulings.IsAuto = EducationSchedulings.IsAuto; SetModifyStatus(EducationScheduling); UnitOfWork.Commit(); } SetEducationMissionClassClassroomID(EducationMissionClass, educationMissionClassView); } else { if (educationMission.ClassNum > ClassRoomType.Totalseating) { throw new Exception("该教室座位数不够不能设置!"); } var before = this.EducationSchedulingDAL.EducationSchedulingRepository.GetList (x => x.EM_EducationSchedulingClass.EducationMissionClassID == educationMissionClassView.EducationMissionClassID, (x => x.ES_EducationSchedulingWeekNum)).ToList(); var order = this.EducationSchedulingDAL.EducationSchedulingRepository.GetList (x => x.EducationSchedulingClassID != educationMissionClassView.EducationMissionClassID && x.ClassroomID == educationMissionClassView.ClassroomID,(x => x.ES_EducationSchedulingWeekNum)).ToList(); foreach (ES_EducationScheduling educationScheduling in order) { if (before.Any(x => x.SchoolyearID == educationScheduling.SchoolyearID)) { foreach (ES_EducationSchedulingWeekNum weeks in educationScheduling.ES_EducationSchedulingWeekNum) { if (before.Any(x => x.ES_EducationSchedulingWeekNum.Any(w => w.WeekNum == weeks.WeekNum) && x.Weekday == educationScheduling.Weekday && x.CoursesTimeID == educationScheduling.CoursesTimeID)) { throw new Exception("该教室已被占用!"); } } } } //var EducationSchedulingID = before.Select(x => x.EducationSchedulingID).ToList(); //var WeekDay = before.Select(x => x.Weekday).ToList(); //var SchoolyearID = before.Select(x => x.SchoolyearID).Distinct().ToList(); //var Week = before.Select(x => x.ES_EducationSchedulingWeekNum).ToList(); //var CoursesTimeID = before.Select(x => x.CoursesTimeID).ToList(); //var beforeWeekNum = this.EducationSchedulingDAL.EducationSchedulingWeekNumRepository.GetList(x => EducationSchedulingID.Contains((Guid)x.EducationSchedulingID)).Select(x=>x.WeekNum).Distinct().ToList(); //var after = this.EducationSchedulingDAL.EducationSchedulingRepository.GetList // (x => !EducationSchedulingID.Contains(x.EducationSchedulingID) && // WeekDay.Contains(x.Weekday) && SchoolyearID.Contains(x.SchoolyearID) // && x.ClassroomID == educationMissionClassView.ClassroomID // && CoursesTimeID.Contains(x.CoursesTimeID) // ).ToList(); //var afterEducationSchedulingID = after.Select(x=>x.EducationSchedulingID).ToList(); //var afterWeekNum = this.EducationSchedulingDAL.EducationSchedulingWeekNumRepository.GetList(x => afterEducationSchedulingID.Contains((Guid)x.EducationSchedulingID)).Select(x => x.WeekNum).Distinct().ToList(); //int isok = 0; //for (int i = 0; i < afterWeekNum.Count();i++ ) //{ // if (beforeWeekNum.Contains(afterWeekNum[i])) // { // isok++; // } //} var classroomTime= ClassroomScheduleSettingDAL.GetArrangementViewQueryable(educationMissionClassView.ClassroomID).ToList(); var classroomReserve = classroomReserveDAL.GetClassroomReserveViewQueryable(x => x.ClassroomID == educationMissionClassView.ClassroomID); var collegeClassroom = collegeClassroomDAL.GetCollegeClassroomViewQueryable(x => x.ClassroomID == educationMissionClassView.ClassroomID && x.CollegeID == educationMission.CollegeID).FirstOrDefault(); if (collegeClassroom==null) { throw new Exception("该教室不属于该教学任务的院系所不能设置!"); } //if (after.Count == 0 && isok == 0) //{ foreach (var EducationScheduling in before) { var isokTime = classroomTime.Where(x => x.CoursesTimeID == EducationScheduling.CoursesTimeID && x.Weekday == EducationScheduling.Weekday && x.IsOnWork == true).FirstOrDefault(); if (isokTime != null) { throw new Exception("该教室不在可排时间内不能设置!"); } var isReserve = classroomReserve.Where(x => x.ClassroomID == educationMissionClassView.ClassroomID && x.IsReserve == true).FirstOrDefault(); if (isReserve != null) { throw new Exception("该教室已经被预留不能设置!"); } EducationScheduling.ClassroomID = educationMissionClassView.ClassroomID; SetModifyStatus(EducationScheduling); UnitOfWork.Commit(); } SetEducationMissionClassClassroomID(EducationMissionClass, educationMissionClassView); //} //else //{ // throw new Exception("该教室已被占用!"); //} } } UnitOfWork.Commit(); } } } }