using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.EducationSchedule; using EMIS.ViewModel; using EMIS.DataLogic.EducationSchedule; using EMIS.Entities; using EMIS.CommonLogic.SystemServices; using System.Linq.Expressions; namespace EMIS.CommonLogic.EducationSchedule { public class EducationSchedulingStopServices : BaseWorkflowServices, IEducationSchedulingStopServices { public EducationSchedulingDAL EducationSchedulingDAL { get; set; } public EducationSchedulingStopDAL EducationSchedulingStopDAL { get; set; } public IGridResultSet GetEducationSchedulingStopViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? coursematerialID, Guid? collegeID, Guid? userID, int? WeekNum, int? WeekDay, Guid? CoursesTimeID, Guid? ClassroomID, Guid? applyUserID, DateTime? starDate, DateTime? endDate, 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); exp = exp.And(x => x.ES_EducationSchedulingStopTeacher.AsQueryable().Any( this.GetDataRageExpression(w => w.UserID))); if (schoolyearID.HasValue) { missionExp = missionExp.And(x => x.SchoolyearID == schoolyearID); } if (coursematerialID.HasValue) { missionClassExp = missionClassExp.And(x => x.CoursematerialID == coursematerialID); } if (collegeID.HasValue) { exp = exp.And(x => x.ES_EducationSchedulingStopTeacher.Any(w => w.CF_Staff.CollegeID == collegeID)); } if (userID.HasValue) { exp = exp.And(x => x.ES_EducationSchedulingStopTeacher.Any(w => w.UserID == userID)); } if(WeekNum.HasValue) { exp = exp.And(x => x.WeekNum == WeekNum); } if (WeekDay.HasValue) { exp = exp.And(x => x.Weekday == WeekDay); } if (CoursesTimeID.HasValue) { exp = exp.And(x => x.CoursesTimeID == CoursesTimeID); } if (ClassroomID.HasValue) { exp = exp.And(x => x.ClassroomID == ClassroomID); } if(applyUserID.HasValue) { exp = exp.And(x => x.CreateUserID == applyUserID); } if(starDate.HasValue) { exp = exp.And(x => x.ApplyTime >= starDate); } if (endDate.HasValue) { exp = exp.And(x => x.ApplyTime <= endDate.Value.AddDays(1)); } if (starDate.HasValue && endDate.HasValue) { exp = exp.And(x => x.ApplyTime >= starDate && x.ApplyTime <= endDate.Value.AddDays(1)); } if (recordStatus.HasValue) { exp = exp.And(x => x.RecordStatus == recordStatus); } var query = this.EducationSchedulingStopDAL.GetEducationSchedulingStopViewQueryable(exp, missionExp, missionClassExp); var teacherQuery = this.EducationSchedulingStopDAL.GetEducationSchedulingStopTeacherViewQueryable( exp, missionExp, missionClassExp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); var resultQuery = query.OrderByDescending(x => x.ApplyTime) .ThenBy(x => x.applyUserName); var result = resultQuery.ToGridResultSet(pageIndex, pageSize); if (pageIndex.HasValue && pageSize.HasValue) { var stopIDList = result.rows.Select(x => (Guid?)x.EducationSchedulingStopID).ToList(); var teacherList = teacherQuery.Where(x => stopIDList.Contains(x.EducationSchedulingStopID)) .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name) .ToList(); result.rows.ForEach(x => { x.TeacherList = teacherList .Where(w => w.EducationSchedulingStopID == x.EducationSchedulingStopID).ToList(); x.RecordStatusName = statusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name; }); } else { var teacherList = teacherQuery .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList(); result.rows.ForEach(x => { x.TeacherList = teacherList .Where(w => w.EducationSchedulingStopID == x.EducationSchedulingStopID).ToList(); x.RecordStatusName = statusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name; }); } return result; } public List GetEducationSchedulingStopViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? coursematerialID, Guid? collegeID, Guid? userID, int? weekNum, int? weekDay, Guid? coursesTimeID, Guid? classroomID, Guid? applyUserID, DateTime? starDate, DateTime? endDate, int? recordStatus) { return this.GetEducationSchedulingStopViewList(configuretView, schoolyearID, coursematerialID, collegeID, userID, weekNum, weekDay, coursesTimeID, classroomID, applyUserID, starDate, endDate, recordStatus, null, null).rows; } public EducationSchedulingStopView GetEducationSchedulingStopView(Guid educationSchedulingStopID) { var result = this.EducationSchedulingStopDAL .GetEducationSchedulingStopViewQueryable(x => x.EducationSchedulingStopID == educationSchedulingStopID, (x => true), (x => true)).FirstOrDefault(); var educationSchedule = this.EducationSchedulingDAL.EducationSchedulingRepository.GetSingle(x => x.EM_EducationSchedulingClass.EducationMissionClassID == result.EducationMissionClassID && x.Weekday == result.Weekday && x.CoursesTimeID == result.CoursesTimeID && x.ES_EducationSchedulingWeekNum.Any(w => w.WeekNum == result.WeekNum), (x => x.ES_EducationSchedulingWeekNum)); if (educationSchedule == null) { throw new Exception("无法读取停课记录,记录指定的课程安排已被移动或删除。"); } result.ScheduleWeekNumList = educationSchedule.ES_EducationSchedulingWeekNum.Select(w => w.WeekNum) .ToList(); return result; } public void Save(EducationSchedulingStopView educationSchedulingStopView) { ES_EducationScheduling educationSchedule; educationSchedule = this.EducationSchedulingDAL.EducationSchedulingRepository.GetSingle(x => x.EM_EducationSchedulingClass.EducationMissionClassID == educationSchedulingStopView.EducationMissionClassID && x.Weekday == educationSchedulingStopView.Weekday && x.CoursesTimeID == educationSchedulingStopView.CoursesTimeID && x.ES_EducationSchedulingWeekNum.Any(w => w.WeekNum == educationSchedulingStopView.WeekNum), (x => x.EM_EducationSchedulingClass), (x => x.ES_EducationSchedulingTeacher)); if (educationSchedule == null) { throw new Exception("所选排课记录不存在,请退出重新选择。"); } var startStatusID = this.GetStartStatus(); var backpointStatusList = this.GetBackpointStatus(); var scheduleStop = new ES_EducationSchedulingStop(); if (educationSchedulingStopView.EducationSchedulingStopID != Guid.Empty) { scheduleStop = this.EducationSchedulingStopDAL.EducationSchedulingStopRepository .GetSingle(x => x.EducationSchedulingStopID == educationSchedulingStopView.EducationSchedulingStopID, (x => x.ES_EducationSchedulingStopTeacher)); if (scheduleStop == null) { throw new Exception("数据已经被删除,请退出重新选择。"); } if (scheduleStop.RecordStatus != startStatusID && !backpointStatusList.Contains(scheduleStop.RecordStatus)) { throw new Exception("数据已提交,不能修改。"); } this.SetModifyStatus(scheduleStop); } else { scheduleStop.EducationSchedulingStopID = Guid.NewGuid(); this.SetNewStatus(scheduleStop); scheduleStop.RecordStatus = startStatusID; this.UnitOfWork.Add(scheduleStop); } scheduleStop.EducationMissionClassID = educationSchedule.EM_EducationSchedulingClass.EducationMissionClassID; scheduleStop.Weekday = educationSchedulingStopView.Weekday; scheduleStop.WeekNum = educationSchedulingStopView.WeekNum; scheduleStop.CoursesTimeID = educationSchedulingStopView.CoursesTimeID; scheduleStop.ClassroomID = educationSchedulingStopView.ClassroomID; if (educationSchedulingStopView.UserID.HasValue) { scheduleStop.ES_EducationSchedulingStopTeacher = new HashSet(); if (educationSchedule.ES_EducationSchedulingTeacher.Any(x => x.UserID == educationSchedulingStopView.UserID && x.TeachingMethod == (int)EM_TeachingMethod.Lecturer)) { foreach (var teacher in educationSchedule.ES_EducationSchedulingTeacher) { var fromTeacher = new ES_EducationSchedulingStopTeacher(); fromTeacher.EducationSchedulingStopTeacherID = Guid.NewGuid(); fromTeacher.EducationSchedulingStopID = scheduleStop.EducationSchedulingStopID; fromTeacher.UserID = teacher.UserID; fromTeacher.TeachingMethod = teacher.TeachingMethod; this.SetNewStatus(fromTeacher); scheduleStop.ES_EducationSchedulingStopTeacher.Add(fromTeacher); } } else { var teacher = educationSchedule.ES_EducationSchedulingTeacher.FirstOrDefault(x => x.UserID == educationSchedulingStopView.UserID); var fromTeacher = new ES_EducationSchedulingStopTeacher { EducationSchedulingStopTeacherID = Guid.NewGuid(), EducationSchedulingStopID = scheduleStop.EducationSchedulingStopID, UserID = teacher.UserID, TeachingMethod = teacher.TeachingMethod }; this.SetNewStatus(fromTeacher); scheduleStop.ES_EducationSchedulingStopTeacher.Add(fromTeacher); } } this.UnitOfWork.Commit(); } public void StopSave( List id,Guid? userID) { List educationScheduleWeekNumList = new List(); List educationScheduleList = new List(); List educationSchedulingStopList = new List(); List educationSchedulingStopTeacherList = new List(); educationScheduleWeekNumList = this.EducationSchedulingDAL.EducationSchedulingWeekNumRepository.GetList(x => id.Contains(x.EducationSchedulingWeekNumID)).ToList(); var educationScheduleIDs=educationScheduleWeekNumList.Select(x=>x.EducationSchedulingID).ToList(); educationScheduleList = this.EducationSchedulingDAL.EducationSchedulingRepository.GetList(x => educationScheduleIDs.Contains(x.EducationSchedulingID), (x=>x.EM_EducationSchedulingClass),(x=>x.ES_EducationSchedulingTeacher)).ToList(); educationSchedulingStopList = this.EducationSchedulingStopDAL.EducationSchedulingStopRepository.GetList(x => true).ToList(); educationSchedulingStopTeacherList = this.EducationSchedulingStopDAL.EducationSchedulingStopTeacherRepository.GetList(x => true).ToList(); foreach (var educationScheduleWeek in educationScheduleWeekNumList) { var educationSchedule = educationScheduleList.Where(x => x.EducationSchedulingID == educationScheduleWeek.EducationSchedulingID).FirstOrDefault(); if (educationSchedule != null) { var ise = educationSchedulingStopList.Where( x => x.EducationMissionClassID == educationSchedule.EM_EducationSchedulingClass.EducationMissionClassID && x.Weekday == educationSchedule.Weekday && x.WeekNum == educationScheduleWeek.WeekNum && x.CoursesTimeID == educationSchedule.CoursesTimeID && x.ClassroomID == educationSchedule.ClassroomID ).ToList(); if (ise.Count>0) { foreach(var isee in ise){ var iset = educationSchedulingStopTeacherList.Where(x => x.UserID == userID && x.EducationSchedulingStopID == isee.EducationSchedulingStopID).FirstOrDefault(); if (iset != null) { throw new Exception("存在重复数据请勿重复申请。"); } } } var startStatusID = this.GetStartStatus(); var backpointStatusList = this.GetBackpointStatus(); var scheduleStop = new ES_EducationSchedulingStop(); scheduleStop.EducationSchedulingStopID = Guid.NewGuid(); this.SetNewStatus(scheduleStop); scheduleStop.RecordStatus = startStatusID; this.UnitOfWork.Add(scheduleStop); scheduleStop.EducationMissionClassID = educationSchedule.EM_EducationSchedulingClass.EducationMissionClassID; scheduleStop.Weekday = educationSchedule.Weekday; scheduleStop.WeekNum = educationScheduleWeek.WeekNum; scheduleStop.CoursesTimeID = educationSchedule.CoursesTimeID; scheduleStop.ClassroomID = educationSchedule.ClassroomID; scheduleStop.ES_EducationSchedulingStopTeacher = new HashSet(); if (educationSchedule.ES_EducationSchedulingTeacher.Any(x => x.UserID == userID && x.TeachingMethod == (int)EM_TeachingMethod.Lecturer)) { foreach (var teacher in educationSchedule.ES_EducationSchedulingTeacher) { var fromTeacher = new ES_EducationSchedulingStopTeacher(); fromTeacher.EducationSchedulingStopTeacherID = Guid.NewGuid(); fromTeacher.EducationSchedulingStopID = scheduleStop.EducationSchedulingStopID; fromTeacher.UserID = teacher.UserID; fromTeacher.TeachingMethod = teacher.TeachingMethod; this.SetNewStatus(fromTeacher); scheduleStop.ES_EducationSchedulingStopTeacher.Add(fromTeacher); } } else { var teacher = educationSchedule.ES_EducationSchedulingTeacher.FirstOrDefault(x => x.UserID == userID); var fromTeacher = new ES_EducationSchedulingStopTeacher { EducationSchedulingStopTeacherID = Guid.NewGuid(), EducationSchedulingStopID = scheduleStop.EducationSchedulingStopID, UserID = teacher.UserID, TeachingMethod = teacher.TeachingMethod }; this.SetNewStatus(fromTeacher); scheduleStop.ES_EducationSchedulingStopTeacher.Add(fromTeacher); } } } this.UnitOfWork.Commit(); } public IGridResultSet GetEducationSchedulingStopApproveList(ConfiguretView configuretView, Guid? schoolyearID, Guid? coursematerialID, Guid? collegeID, Guid? userID, int? weekNum, int? weekDay, Guid? coursesTimeID, Guid? classroomID, Guid? applyUserID, DateTime? starDate, DateTime? endDate, int? recordStatus, int? pageIndex, int? pageSize) { var statusList = this.GetStatusViewList(); //var appprovalStatusList = this.GetApproveStatusViewList().Select(x => x.ID).ToList(); Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> missionExp = (x => true); Expression> missionClassExp = (x => true); exp = exp.And(x => x.ES_EducationSchedulingStopTeacher.AsQueryable().Any( this.GetDataRageExpression(w => w.UserID)) //&& appprovalStatusList.Contains(x.RecordStatus) ); if (schoolyearID.HasValue) { missionExp = missionExp.And(x => x.SchoolyearID == schoolyearID); } if (coursematerialID.HasValue) { missionClassExp = missionClassExp.And(x => x.CoursematerialID == coursematerialID); } if (collegeID.HasValue) { exp = exp.And(x => x.ES_EducationSchedulingStopTeacher.Any(w => w.CF_Staff.CollegeID == collegeID)); } if (userID.HasValue) { exp = exp.And(x => x.ES_EducationSchedulingStopTeacher.Any(w => w.UserID == userID)); } if (weekNum.HasValue) { exp = exp.And(x => x.WeekNum == weekNum); } if (weekDay.HasValue) { exp = exp.And(x => x.Weekday == weekDay); } if (coursesTimeID.HasValue) { exp = exp.And(x => x.CoursesTimeID == coursesTimeID); } if (classroomID.HasValue) { exp = exp.And(x => x.ClassroomID == classroomID); } if (applyUserID.HasValue) { exp = exp.And(x => x.CreateUserID == applyUserID); } if (starDate.HasValue) { exp = exp.And(x => x.ApplyTime >= starDate); } if (endDate.HasValue) { exp = exp.And(x => x.ApplyTime <= endDate.Value.AddDays(1)); } if (starDate.HasValue && endDate.HasValue) { exp = exp.And(x => x.ApplyTime >= starDate && x.ApplyTime <= endDate.Value.AddDays(1)); } if (recordStatus.HasValue) { exp = exp.And(x => x.RecordStatus == recordStatus); } var query = this.EducationSchedulingStopDAL.GetEducationSchedulingStopViewQueryable(exp, missionExp, missionClassExp); var teacherQuery = this.EducationSchedulingStopDAL.GetEducationSchedulingStopTeacherViewQueryable( exp, missionExp, missionClassExp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); var resultQuery = query.OrderByDescending(x => x.ApplyTime) .ThenBy(x => x.applyUserName); var result = resultQuery.ToGridResultSet(pageIndex, pageSize); if (pageIndex.HasValue && pageSize.HasValue) { var stopIDList = result.rows.Select(x => (Guid?)x.EducationSchedulingStopID).ToList(); var teacherList = teacherQuery.Where(x => stopIDList.Contains(x.EducationSchedulingStopID)) .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name) .ToList(); result.rows.ForEach(x => { x.TeacherList = teacherList .Where(w => w.EducationSchedulingStopID == x.EducationSchedulingStopID).ToList(); x.RecordStatusName = statusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name; }); } else { var teacherList = teacherQuery .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList(); result.rows.ForEach(x => { x.TeacherList = teacherList .Where(w => w.EducationSchedulingStopID == x.EducationSchedulingStopID).ToList(); x.RecordStatusName = statusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name; }); } return result; } public List GetEducationSchedulingStopApproveList(ConfiguretView configuretView, Guid? schoolyearID, Guid? coursematerialID, Guid? collegeID, Guid? userID, int? weekNum, int? weekDay, Guid? coursesTimeID, Guid? classroomID, Guid? applyUserID, DateTime? starDate, DateTime? endDate,int? recordStatus) { return this.GetEducationSchedulingStopApproveList(configuretView, schoolyearID, coursematerialID, collegeID, userID, weekNum, weekDay, coursesTimeID, classroomID, applyUserID, starDate, endDate, recordStatus,null,null).rows; } public void Delete(IList educationSchedulingStopIDList) { var startStatus = this.GetStartStatus(); var submitedAdjustmentList = this.EducationSchedulingStopDAL.EducationSchedulingStopRepository .GetList(x => educationSchedulingStopIDList.Contains(x.EducationSchedulingStopID) && x.RecordStatus != startStatus).ToList(); if (submitedAdjustmentList.Count > 0) { throw new Exception("所选记录当中存在已经提交的记录,无法删除。"); } var nullableStopIDList = educationSchedulingStopIDList.Select(x => (Guid?)x).ToList(); this.UnitOfWork.Delete(x => nullableStopIDList.Contains(x.EducationSchedulingStopID)); this.UnitOfWork.Delete(x => nullableStopIDList.Contains(x.EducationSchedulingStopID)); } public void Submit(IList educationSchedulingStopIDList, Guid userID) { var startStatus = this.GetStartStatus(); var backpointStatusList = this.GetBackpointStatus(); var adjustmentList = this.EducationSchedulingStopDAL.EducationSchedulingStopRepository .GetList(x => educationSchedulingStopIDList.Contains(x.EducationSchedulingStopID)); if (adjustmentList.Any(x => x.RecordStatus != startStatus && !backpointStatusList.Contains(x.RecordStatus))) { throw new Exception("只能提交已提交和已退回的记录。"); } var notSubmitList = adjustmentList.Where(x => x.RecordStatus == startStatus).Select(x => x.EducationSchedulingStopID).ToList(); var submitedList = adjustmentList.Where(x => x.RecordStatus != startStatus).Select(x => x.EducationSchedulingStopID).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_EducationSchedulingStop { ApplyUserID = userID, ApplyTime = nowTime }), (x => educationSchedulingStopIDList.Contains(x.EducationSchedulingStopID))); } public List GetEducationSchedulingStopViewList(IList schedulingStopIDList) { if (schedulingStopIDList.Count == 0) { throw new Exception("请选择需要查询的停课记录。"); } var statusList = this.GetStatusViewList(); Expression> exp = (x => schedulingStopIDList.Contains(x.EducationSchedulingStopID)); exp = exp.And(x => x.ES_EducationSchedulingStopTeacher.AsQueryable().Any( this.GetDataRageExpression(w => w.UserID))); var query = this.EducationSchedulingStopDAL.GetEducationSchedulingStopViewQueryable(exp, (x => true), (x => true)); var teacherQuery = this.EducationSchedulingStopDAL.GetEducationSchedulingStopTeacherViewQueryable( exp, (x => true), (x => true)); var resultQuery = query.OrderByDescending(x => x.SchoolyearCode) .ThenBy(x => x.CourseName); var result = resultQuery.ToList(); var teacherList = teacherQuery .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList(); result.ForEach(x => { x.TeacherList = teacherList .Where(w => w.EducationSchedulingStopID == x.EducationSchedulingStopID).ToList(); x.RecordStatusName = statusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name; }); return result; } public List GetEducationSchedulingStopApproveList(IList schedulingStopIDList) { if (schedulingStopIDList.Count == 0) { throw new Exception("请选择需要查询的停课记录。"); } var statusList = this.GetStatusViewList(); Expression> exp = (x => schedulingStopIDList.Contains(x.EducationSchedulingStopID)); exp = exp.And(x => x.ES_EducationSchedulingStopTeacher.AsQueryable().Any( this.GetDataRageExpression(w => w.UserID)) //&& appprovalStatusList.Contains(x.RecordStatus) ); var query = this.EducationSchedulingStopDAL.GetEducationSchedulingStopViewQueryable(exp, (x => true), (x => true)); var teacherQuery = this.EducationSchedulingStopDAL.GetEducationSchedulingStopTeacherViewQueryable( exp, (x => true), (x => true)); var resultQuery = query.OrderByDescending(x => x.SchoolyearCode) .ThenBy(x => x.CourseName); var result = resultQuery.ToList(); var teacherList = teacherQuery .OrderBy(x => x.TeachingMethod).ThenBy(x => x.Name).ToList(); result.ForEach(x => { x.TeacherList = teacherList .Where(w => w.EducationSchedulingStopID == x.EducationSchedulingStopID).ToList(); x.RecordStatusName = statusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name; }); return result; } } }