123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- 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<Guid> 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);
- }
- }
- /// <summary>
- /// 更新教学任务班表 处理状态
- /// </summary>
- /// <param name="educationMissionClassIDs"></param>
- public void EducationMissionClassUpdateTeacher(EducationMissionClassView educationMissionClassView, List<EducationMissionClassTeacherListView> 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<EM_MissionClassTeacher>(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<ES_EducationSchedulingTeacher>(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);
- });
- }
- /// <summary>
- /// 更新教学任务班表 处理状态
- /// </summary>
- /// <param name="educationMissionClassIDs"></param>
- 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();
- }
- }
- }
- }
|