using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.EducationManage; using EMIS.ViewModel; using System.Linq.Expressions; using EMIS.Entities; using EMIS.DataLogic.EducationManage; using EMIS.CommonLogic.SchedulingManage.ScheduleApproval; using EMIS.Utility.FormValidate; using EMIS.ViewModel.EducationSchedule; using EMIS.ViewModel.SchedulingManage.ScheduleApproval; namespace EMIS.CommonLogic.EducationManage { public class EducationSchedulingClassServices : BaseServices, IEducationSchedulingClassServices { public EducationSchedulingClassDAL EducationSchedulingClassDAL { get; set; } public Lazy CollegeScheduleApprovalServices { get; set; } /// /// 获取完整结构的任务班视图的方法,主要是要组合教师列表和上课周列表 /// /// /// /// /// /// /// /// public IGridResultSet GetEducationSchedulingClassView(ConfiguretView configuretView, Expression> exp, Expression> resultExp = null, Func, Expression>, IQueryable> dataRangeFunc = null, int? pageIndex = null, int? pageSize = null) { var educationSchedulingClassViewQueryable = EducationSchedulingClassDAL.GetEducationSchedulingClassViewQueryable(exp); var classMajorQueryable = EducationSchedulingClassDAL.GetClassmajorQueryable(exp); var teacherViewQueryable = EducationSchedulingClassDAL.GetTeacherViewQueryable(exp); var educationMissionClassSettingQueryable = EducationSchedulingClassDAL.GetEducationMissionClassSettingQueryable(exp); var courseProcessQueryable = EducationSchedulingClassDAL.GetCourseProcessViewQueryable(exp); var courseProcessTeacherQueryable = this.EducationSchedulingClassDAL.GetCourseProcessTeacherViewQueryable(exp); if (resultExp != null) { educationSchedulingClassViewQueryable = educationSchedulingClassViewQueryable.Where(resultExp); } if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { educationSchedulingClassViewQueryable = educationSchedulingClassViewQueryable .DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); } if (dataRangeFunc != null) { educationSchedulingClassViewQueryable = dataRangeFunc .Invoke(educationSchedulingClassViewQueryable, null); } IGridResultSet result; List teacherViewList; List educationMissionClassSettingList; List classMajorList; List courseProcessList; var startStatus = CollegeScheduleApprovalServices.Value.GetStartStatus(); var collegeScheduleApprovalViewList = new List(); if (pageIndex.HasValue && pageSize.HasValue) { result = educationSchedulingClassViewQueryable.OrderBy(x => x.EducationMissionClassOrderNo) .ToGridResultSet(pageIndex, pageSize); //var isCanApprove = CollegeScheduleApprovalServices.Value.IsCanApprove(collegeStatus.CollegeScheduleStatusID, CustomPrincipal.Current.UserID); collegeScheduleApprovalViewList = CollegeScheduleApprovalServices.Value.GetCollegeScheduleApprovalViewList( result.rows.GroupBy(x => new { x.CourseCollegeID, x.SchoolYearID }) .Select(x => new CollegeSchoolyearView { CollegeID = x.Key.CourseCollegeID.Value, SchoolyearID = x.Key.SchoolYearID.Value }).ToList() ); //由于分页后数据量较少,可以考虑用Contains方法在数据库端筛选一下,不分页的情况就不要了 var educationMissionClassIDList = result.rows.Select(x => x.EducationMissionClassID).ToList(); teacherViewList = teacherViewQueryable.Where(x => educationMissionClassIDList.Contains(x.EducationMissionClassID)).ToList(); classMajorList = classMajorQueryable.Where(x => educationMissionClassIDList.Contains(x.EducationMissionClassID)).ToList(); educationMissionClassSettingList = educationMissionClassSettingQueryable .Where(x => educationMissionClassIDList.Contains(x.EducationMissionClassID)).ToList(); courseProcessList = courseProcessQueryable.Where(x => educationMissionClassIDList.Contains(x.EducationMissionClassID)).ToList(); var courseProcessTeacherViewList = courseProcessTeacherQueryable.Where(x => educationMissionClassIDList.Contains(x.EducationMissionClassID)).Distinct().ToList(); courseProcessList.ForEach(x => x.CourseProcessTeacherViewList = courseProcessTeacherViewList.Where(w => w.CourseProcessID == x.CourseProcessID) .OrderBy(w => w.TeachingMethod).ThenBy(w => w.Name).ToList()); } else { var list = educationSchedulingClassViewQueryable.ToList(); result = new GridResultSet() { rows = list, total = list.Count }; collegeScheduleApprovalViewList = CollegeScheduleApprovalServices.Value.GetCollegeScheduleApprovalViewList( result.rows.GroupBy(x => new { x.CourseCollegeID, x.SchoolYearID }) .Select(x => new CollegeSchoolyearView { CollegeID = x.Key.CourseCollegeID.Value, SchoolyearID = x.Key.SchoolYearID.Value }).ToList() ); teacherViewList = teacherViewQueryable.ToList(); classMajorList = classMajorQueryable.ToList(); educationMissionClassSettingList = educationMissionClassSettingQueryable.ToList(); courseProcessList = courseProcessQueryable.ToList(); var courseProcessTeacherViewList = courseProcessTeacherQueryable.Distinct().ToList(); courseProcessList.ForEach(x => x.CourseProcessTeacherViewList = courseProcessTeacherViewList.Where(w => w.CourseProcessID == x.CourseProcessID) .OrderBy(w => w.TeachingMethod).ThenBy(w => w.Name).ToList()); } var submitedCollegeScheduleApprovalViewList = collegeScheduleApprovalViewList.Where(x => x.CollegeScheduleStatusID.HasValue).ToList(); result.rows.ForEach(x => { var collegeScheduleApprovalView = submitedCollegeScheduleApprovalViewList.FirstOrDefault(w => w.CollegeID == x.CourseCollegeID && w.SchoolyearID == x.SchoolYearID); x.TeacherTeachingViewList = teacherViewList .Where(w => x.EducationMissionClassID == w.EducationMissionClassID) .Select(w => (BaseTeacherTeachingView)w) .OrderBy(w => w.TeachingMethod).ThenBy(w => w.Name).ToList(); x.WeeklyNumList = educationMissionClassSettingList.Where(w => x.EducationMissionClassID == w.EducationMissionClassID) .Select(w => w.WeeklyNum).Distinct().ToList(); x.ClassMajorIDList = classMajorList.Where(w => x.EducationMissionClassID == w.EducationMissionClassID) .Select(w => w.ClassMajor.ClassmajorID).Distinct().ToList(); x.CourseProcessViewList = courseProcessList.Where(w => x.EducationMissionClassID == w.EducationMissionClassID).ToList(); x.IsCanEdit = x.IsCanEdit && (collegeScheduleApprovalView == null || collegeScheduleApprovalView.RecordStatus == startStatus); }); return result; } public List GetEducationSchedulingClassViewList(Guid schoolYearID, IList collegeIDList) { return this.GetEducationSchedulingClassView(new ConfiguretView(), (x => collegeIDList.Contains(x.EM_EducationMissionClass.EM_EducationMission.CF_Department.CollegeID) && x.EM_EducationMissionClass.EM_EducationMission.SchoolyearID == schoolYearID && x.EM_EducationMissionClass.RecordStatus != (int)EM_EducationMissionClassStatus.NotSubmitted )).rows; } public List GetEducationSchedulingClassStudentViewList(Guid schoolYearID, IList collegeIDList) { return EducationSchedulingClassDAL.GetEducationSchedulingClassStudentViewQueryable((x => collegeIDList.Contains(x.EM_EducationMissionClass.EM_EducationMission.CF_Department.CollegeID) && x.EM_EducationMissionClass.EM_EducationMission.SchoolyearID == schoolYearID && x.EM_EducationMissionClass.RecordStatus != (int)EM_EducationMissionClassStatus.NotSubmitted )).ToList(); } public List GetEducationSchedulingClassViewList(Guid schoolYearID, Guid classMajorID) { return this.GetEducationSchedulingClassView(new ConfiguretView(), (x => x.EM_EducationMissionClass.CF_Classmajor.Any(w => w.ClassmajorID == classMajorID) && x.EM_EducationMissionClass.EM_EducationMission.SchoolyearID == schoolYearID && x.EM_EducationMissionClass.RecordStatus != (int)EM_EducationMissionClassStatus.NotSubmitted), null, this.GetQueryByDataRangeByDepartment).rows; } public List GetDepartmentEducationSchedulingClassViewList(Guid schoolYearID, Guid departmentID, IList handleModeList) { return this.GetEducationSchedulingClassView(new ConfiguretView(), (x => x.EM_EducationMissionClass.EM_EducationMission.DepartmentID == departmentID && x.EM_EducationMissionClass.EM_EducationMission.SchoolyearID == schoolYearID && handleModeList.Contains(x.EM_EducationMissionClass.HandleModeID) && x.EM_EducationMissionClass.RecordStatus != (int)EM_EducationMissionClassStatus.NotSubmitted), null, this.GetQueryByDataRangeByDepartment).rows; } public EducationSchedulingClassScheduleView GetEducationSchedulingClassView(Guid educationSchedulingClassID) { return this.GetEducationSchedulingClassView(new ConfiguretView(), (x => x.EducationSchedulingClassID == educationSchedulingClassID)).rows.FirstOrDefault(); } } }