using EMIS.DataLogic.SelectCourse.SelectCourseResult; using EMIS.Entities; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.SelectCourse.SelectCourseResult; using EMIS.ViewModel.Students; using EMIS.Utility; using EMIS.ViewModel.SelectCourse; using EMIS.DataLogic.SelectCourse; using EMIS.DataLogic.UniversityManage.SpecialtyClassManage; using EMIS.DataLogic.EducationManage; using EMIS.DataLogic.Repositories; using Bowin.Common.Linq; using EMIS.ViewModel; namespace EMIS.CommonLogic.SelectCourse.SelectCourseResult { public class SelectCourseResultServices : BaseServices, ISelectCourseResultServices { public EducationMissionClassDAL educationMissionClassDAL { get; set; } public MissionClassTeacherRepository missionClassTeacherRepository { get; set; } public SelectCourseResultDAL SelectCourseResultDAL { get; set; } public OptionalCourseSettingDAL optionalCourseSettingDAL { get; set; } public ClassmajorDAL classmajorDAL { get; set; } public ExecutablePlanDAL ExecutablePlanDAL { get; set; } public OptionalCourseSettingDAL OptionalCourseSettingDAL { get; set; } public OpenControlSettingDAL OpenControlSettingDAL { get; set; } public ExecutableFreeSelectionCouseDAL ExecutableFreeSelectionCouseDAL { get; set; } public IStudentSelectCourseServices IStudentSelectCourseServices { get; set; } public IGridResultSet GetSelectCourseResultViewList (ViewModel.ConfiguretView configuretView, Guid? schoolYearID, Guid? collegeID, Guid? courseID, int? courseTypeID, int? selectCourseTypeID, int? isCreated, int? isOpened, int pageIndex, int pageSize) { Expression> eocExp = (x => true); Expression> efcExp = (x => true); var query = SelectCourseResultDAL.GetSelectCourseResultViewQueryable(eocExp, efcExp); var query1 = SelectCourseResultDAL.GetSelectCourseResultTeacher(eocExp, efcExp); var query2 = SelectCourseResultDAL.GetSelectCourseResultTeachingMode(eocExp, efcExp); if (schoolYearID.HasValue) { query = query.Where(x => x.SchoolyearID == schoolYearID); query1 = query1.Where(x => x.SchoolyearID == schoolYearID); efcExp.And(x => x.SchoolyearID == schoolYearID); } if (collegeID.HasValue) { query = query.Where(x => x.CollegeID == collegeID); efcExp.And(x => x.CF_Department.CollegeID == collegeID); } if (courseID.HasValue) { query = query.Where(x => x.CoursematerialID == courseID); efcExp.And(x => x.EM_FreeSelectionCouse.CoursematerialID == courseID); } if (courseTypeID.HasValue) { query = query.Where(x => x.CourseTypeID == courseTypeID); query1 = query1.Where(x => x.CourseTypeID == courseTypeID); efcExp.And(x => x.CourseTypeID == courseTypeID); } if (selectCourseTypeID.HasValue) { query = query.Where(x => x.SelectCourseType == selectCourseTypeID); query1 = query1.Where(x => x.SelectCourseType == selectCourseTypeID); } if (isCreated.HasValue) { query = query.Where(x => x.RecordStatus == isCreated); efcExp.And(x => x.RecordStatus == isCreated); //if (isCreated == (int)EMIS.ViewModel.CF_GeneralPurpose.IsYes) // query = query.Where(x => x.RecordStatus == (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Created); //else if (isCreated == (int)EMIS.ViewModel.CF_GeneralPurpose.IsNo) // query = query.Where(x => x.RecordStatus != (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Created); } if (isOpened.HasValue) { query = query.Where(x => x.IsOpened == (isOpened == 1 ? true : false)); //query1 = query1.Where(x => x.IsOpened == (isOpened == 1 ? true : false)); } //未提交状态不显示 query = query.Where(x => x.RecordStatus > (int)EMIS.ViewModel.EM_SelectCourseResultStatus.NotOpen); query1 = query1.Where(x => x.RecordStatus > (int)EMIS.ViewModel.EM_SelectCourseResultStatus.NotOpen); query2 = query2.Where(x => x.RecordStatus > (int)EMIS.ViewModel.EM_SelectCourseResultStatus.NotOpen); //任选具体上课时间 var queryScheduling = SelectCourseResultDAL.GetScheduling(efcExp).ToList(); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SelectCourseType).ToGridResultSet(pageIndex, pageSize); var teacher = query1.ToList().OrderBy(x => x.SelectCourseType); var teachingMode = query2.ToList().OrderBy(x => x.SelectCourseType); result.rows.ForEach(x => x.TeacherName = string.Join(",", teacher.Where(w => w.ID == x.ID).Select(w => w.TeacherName))); if (queryScheduling.Count > 0) { var schedulingList = IStudentSelectCourseServices.GetWeekdayTimesSegmentName(queryScheduling); result.rows.ForEach(x => { var list = schedulingList.Where(w => w.ID == x.ID); x.WeekdayTimesSegmentName = string.Join(";", list.OrderBy(w => w.Weekday).Select(w => w.WeekdayTimesSegmentName)); }); } return result; } public List GetSelectCourseResultViewList (ViewModel.ConfiguretView configuretView, Guid? schoolYearID, Guid? collegeID, Guid? courseID, int? courseTypeID, int? selectCourseTypeID, int? isCreated, int? isOpened) { Expression> eocExp = (x => true); Expression> efcExp = (x => true); var query = SelectCourseResultDAL.GetSelectCourseResultViewQueryable(eocExp, efcExp); var query1 = SelectCourseResultDAL.GetSelectCourseResultTeacher(eocExp, efcExp); if (schoolYearID.HasValue) { query = query.Where(x => x.SchoolyearID == schoolYearID); query1 = query1.Where(x => x.SchoolyearID == schoolYearID); } if (collegeID.HasValue) { query = query.Where(x => x.CollegeID == collegeID); } if (courseID.HasValue) { query = query.Where(x => x.CoursematerialID == courseID); } if (courseTypeID.HasValue) { query = query.Where(x => x.CourseTypeID == courseTypeID); query1 = query1.Where(x => x.CourseTypeID == courseTypeID); } if (selectCourseTypeID.HasValue) { query = query.Where(x => x.SelectCourseType == selectCourseTypeID); query1 = query1.Where(x => x.SelectCourseType == selectCourseTypeID); } if (isCreated.HasValue) { query = query.Where(x => x.RecordStatus == isCreated); //if (isCreated == (int)EMIS.ViewModel.CF_GeneralPurpose.IsYes) // query = query.Where(x => x.RecordStatus == (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Created); //else if (isCreated == (int)EMIS.ViewModel.CF_GeneralPurpose.IsNo) // query = query.Where(x => x.RecordStatus != (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Created); } if (isOpened.HasValue) { query = query.Where(x => x.IsOpened == (isOpened == 1 ? true : false)); query1 = query1.Where(x => x.IsOpened == (isOpened == 1 ? true : false)); } //未提交状态不显示 query = query.Where(x => x.RecordStatus > (int)EMIS.ViewModel.EM_SelectCourseResultStatus.NotOpen); query1 = query1.Where(x => x.RecordStatus > (int)EMIS.ViewModel.EM_SelectCourseResultStatus.NotOpen); //任选具体上课时间 var queryScheduling = SelectCourseResultDAL.GetScheduling(efcExp).ToList(); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); var teacher = query1.ToList().OrderBy(x => x.SelectCourseType); var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SelectCourseType).ToList(); result.ForEach(x => x.TeacherName = string.Join(",", teacher.Where(w => w.ID == x.ID).Select(w => w.TeacherName))); if (queryScheduling.Count > 0) { var schedulingList = IStudentSelectCourseServices.GetWeekdayTimesSegmentName(queryScheduling); result.ForEach(x => { var list = schedulingList.Where(w => w.ID == x.ID); x.WeekdayTimesSegmentName = string.Join(";", list.OrderBy(w => w.Weekday).Select(w => w.WeekdayTimesSegmentName)); }); } return result; } public IGridResultSet GetSelectCourseStudentViewGrid(Guid ID, string type, int pageIndex, int pageSize) { if (type == "0") { var query = OptionalCourseSettingDAL.GetSelectCourseStudent(x => x.ExecutableOptionalCourseID == ID).OrderBy(x => x.LoginID).ToGridResultSet(1, null); //var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.LoginID).ToGridResultSet(pageIndex, pageSize); //return result; return query; } else { var query = OptionalCourseSettingDAL.GetSelectCourseStudent1(x => x.ExecutableFreeSelectionCouseID == ID).OrderBy(x => x.LoginID).ToGridResultSet(1, null); //var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.LoginID).ToGridResultSet(pageIndex, pageSize); //return result; return query; } } /// /// 学生选课名单,区分限选学生和任选学生(0-限选,1-任选) /// /// /// /// public List GetSelectCourseStudentViewList(Guid ID, string type) { if (type == "0") { var result = OptionalCourseSettingDAL.GetSelectCourseStudent(x => x.ExecutableOptionalCourseID == ID).OrderBy(x => x.LoginID).ToList(); return result; } else { var result = OptionalCourseSettingDAL.GetSelectCourseStudent1(x => x.ExecutableFreeSelectionCouseID == ID).OrderBy(x => x.LoginID).ToList(); return result; } } /// /// 生成教学任务班,Type为0时生成限选,1生成任选 /// /// /// /// public void ChooseEducationMissionClass(List executablePlanIDs, string Type) { if (Type == "0") GenerateEducationMissionClassOptionalCourse(executablePlanIDs); else GenerateEducationMissionClassFreeSelection(executablePlanIDs); } /// /// 取消开班 /// /// /// /// public void CancelEducationMissionClass(List executablePlanIDs) { List ExecutableOptionalCourse = new List(); List ExecutableFreeSelectionCouse = new List(); var OptionalCourseList = SelectCourseResultDAL.ExecutableOptionalCourseRepository.GetList(x => executablePlanIDs.Contains(x.ExecutableOptionalCourseID)).ToList(); var FreeSelectionList = SelectCourseResultDAL.ExecutableFreeSelectionCouseRepository.GetList(x => executablePlanIDs.Contains(x.ExecutableFreeSelectionCouseID)).ToList(); foreach (var OptionalCourse in OptionalCourseList) { OptionalCourse.RecordStatus = (int)EMIS.ViewModel.EM_SelectCourseResultStatus.CancleCreate; ExecutableOptionalCourse.Add(OptionalCourse); } foreach (var FreeSelection in FreeSelectionList) { FreeSelection.RecordStatus = (int)EMIS.ViewModel.EM_SelectCourseResultStatus.CancleCreate; ExecutableFreeSelectionCouse.Add(FreeSelection); } UnitOfWork.Commit(); } /// /// 生成限选教学任务班 /// /// /// public void GenerateEducationMissionClassOptionalCourse(List executableOptionalCourseIDs) { try { var executableOptionalCourseList = OptionalCourseSettingDAL.ExecutableOptionalCourseRepository.GetList(x => executableOptionalCourseIDs.Contains(x.ExecutableOptionalCourseID), (x => x.CF_Grademajor.CF_Classmajor), (x => x.CF_Classmajor), (x => x.CF_Student), //(x => x.CF_Schoolyear), (x => x.EM_ExecutableOptionalCourseTeachingMode), (x => x.EM_ExecutableOptionalCourseTeacher), (x => x.EM_ExecutableOptionalCourseTeachingSetting), (x => x.EM_OptionalCoursePlan.EM_Coursematerial), (x => x.EM_OptionalCoursePlan.EM_Coursematerial.EM_ClassGrouping.EM_ClassGroupingSettings), (x => x.CF_Grademajor.CF_Facultymajor), (x => x.EM_OptionalCoursePlan.CF_Department) ).ToList(); //不是“未开班”状态不能开班 var submitedList = executableOptionalCourseList.Where(x => x.RecordStatus != (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Opened && x.RecordStatus != (int)EMIS.ViewModel.EM_SelectCourseResultStatus.CancleCreate).ToList(); if (submitedList.Count > 0) { throw new Exception("不是“已开放”状态不能进行开班,请核查。"); } //开放时间未结束,不能进行开班 var OpenControlSettingGrademajorIDList = executableOptionalCourseList.Select(w => w.GrademajorID); //找到要开班的所有年级专业 var OpenControlSettingList = OpenControlSettingDAL.SelectCourseOpenControlSettingRepository.Entities.Where(x => OpenControlSettingGrademajorIDList.Contains(x.GrademajorID)).ToList(); //找到年级专业对应的开放结束时间 //验证同一学年学期同一课程下,是否有重复学生 var valid = OptionalCourseSettingDAL.GetDuplicateOptionCourseViewQueryable(x => executableOptionalCourseIDs.Contains(x.ExecutableOptionalCourseID)).ToList(); if (valid.Count > 0) { List validMessageList = new List(); for (int i = 0; i < valid.Count; i++) { validMessageList.Add("任务班【" + valid[i].SourceName + "】和【" + valid[i].DestinationName + "】有重复的学生,请核查。"); } if (valid.Count > 0) { throw new Exception(string.Join(",", validMessageList)); } } //判断是否有设置授课方式 var noTeachingModeTypeList = executableOptionalCourseList.Where(x => x.EM_ExecutableOptionalCourseTeachingMode.Count == 0) .Concat(executableOptionalCourseList.Where(x => !x.EM_ExecutableOptionalCourseTeachingMode.Any(w => w.TeachingModeID != null))).ToList(); if (noTeachingModeTypeList.Count > 0) { throw new Exception("没有设置授课方式的计划不能提交,请核查。"); } var existsMissionClassStudentList = this.optionalCourseSettingDAL.GetEducationMissionClassStudentByExecutableOptionalCourseID(executableOptionalCourseIDs).ToList(); var grademajorIDs = executableOptionalCourseList.Select(x => x.GrademajorID) .ToList(); //var queryclassmajorList = classmajorDAL.classmajorRepository.GetList(x => grademajorIDs.Contains(x.GrademajorID), // (x => x.CF_Student)).ToList(); var resultMissionList = new List(); var resultMissionClassList = new List(); var resultMissionClassTeachingSettingList = new List(); var resultSchedulingClassList = new List(); var resultTeacherList = new List(); var noStudentList = executableOptionalCourseList.Where(x => x.CF_Student.Count == 0).Select(x => x.DefaultClassName).ToList(); if (noStudentList.Count > 0) { throw new Exception("任务班" + string.Join(",", noStudentList) + "没有报名的学生,请核查!"); } if (executableOptionalCourseList.Count > 0) { executableOptionalCourseList.ForEach(x => x.RecordStatus = (int)EMIS.ViewModel.EM_ExecuteStatus.Submited); string coursematerialName = ""; var courseNames = executableOptionalCourseList.Where(x => x.EM_OptionalCoursePlan.EM_Coursematerial != null && x.EM_OptionalCoursePlan.EM_Coursematerial.EM_ClassGrouping == null).Select(x => x.EM_OptionalCoursePlan.EM_Coursematerial.CourseName).Distinct().ToArray(); coursematerialName = string.Join(",", courseNames); if (courseNames.Length > 0) { throw new Exception("以下计划所对应的课程并未设置上课类型,无法确定任务班的分班方式,请到课程资料菜单完成设置后再次进行提交:\r\n" + coursematerialName); } } var query = ( from eop in ( //先找出上课类型没有设置的授课方式,然后单独成一个班 (from eop in executableOptionalCourseList where eop.EM_ExecutableOptionalCourseTeachingMode .Any(x => !eop.EM_OptionalCoursePlan.EM_Coursematerial .EM_ClassGrouping .EM_ClassGroupingSettings.Select(w => w.TeachingModeID).Contains(x.TeachingModeID)) select new { ExecutableOptionalCourse = eop, TeachingMode = eop.EM_ExecutableOptionalCourseTeachingMode .FirstOrDefault(x => !eop.EM_OptionalCoursePlan.EM_Coursematerial .EM_ClassGrouping .EM_ClassGroupingSettings.Select(w => w.TeachingModeID).Contains(x.TeachingModeID)) .TeachingModeID }) //接下来对除理论班之外的其他分班设置进行匹配,如果该专业课程有这个授课方式的话,就单独再分一个班 .Concat( from eop in executableOptionalCourseList from tmt in eop.EM_ExecutableOptionalCourseTeachingMode from cgs in eop.EM_OptionalCoursePlan.EM_Coursematerial.EM_ClassGrouping.EM_ClassGroupingSettings where tmt.TeachingModeID == cgs.TeachingModeID select new { ExecutableOptionalCourse = eop, TeachingMode = cgs.TeachingModeID })) join dtm in DictionaryHelper.GetDictionaryValue(ViewModel.DictionaryItem.CF_TeachingMode) on eop.TeachingMode equals dtm.Value group dtm by new { //Classmajor = sp.Classmajor, ExecutableOptionalCourse = eop.ExecutableOptionalCourse } into g select new { ExecutableOptionalCourse = g.Key.ExecutableOptionalCourse, Classmajor = g.Key.ExecutableOptionalCourse.CF_Classmajor, TeachingMode = g.Select(x => x).ToList(), Teacher = g.Key.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeacher, Student = g.Key.ExecutableOptionalCourse.CF_Student, //选此课的学生 } ); var missionDataList = query.ToList(); for (int i = 0; i < missionDataList.Count; i++) { var mission = missionDataList[i]; EM_EducationMission educationMission = new EM_EducationMission(); educationMission.EducationMissionID = Guid.NewGuid(); educationMission.ClassName = mission.ExecutableOptionalCourse.DefaultClassName; educationMission.DepartmentID = mission.ExecutableOptionalCourse.DepartmentID; educationMission.CollegeID = mission.ExecutableOptionalCourse.CF_Grademajor.CF_Facultymajor.CollegeID; educationMission.SchoolyearID = mission.ExecutableOptionalCourse.SchoolyearID; SetNewStatus(educationMission); resultMissionList.Add(educationMission); foreach (var tm in mission.TeachingMode) { EM_EducationMissionClass educationMissionClass = new EM_EducationMissionClass(); educationMissionClass.EducationMissionClassID = Guid.NewGuid(); educationMissionClass.MainScheduleClassID = mission.Classmajor.OrderBy(x => x.No).FirstOrDefault().ClassmajorID; educationMissionClass.OrderNo = 0; educationMissionClass.EducationMissionID = educationMission.EducationMissionID; educationMissionClass.Name = mission.ExecutableOptionalCourse.DefaultClassName; educationMissionClass.TeachingModeID = tm.Value; if (mission.TeachingMode.Count > 0) { educationMissionClass.Name += "【" + tm.Name + "】"; } educationMissionClass.OptionalCourseTypeID = (int)CF_CourseSelectType.OptionalCourse; educationMissionClass.CoursematerialID = mission.ExecutableOptionalCourse.EM_OptionalCoursePlan.CoursematerialID; educationMissionClass.CourseStructureID = mission.ExecutableOptionalCourse.CourseStructureID; educationMissionClass.CourseCategoryID = mission.ExecutableOptionalCourse.CourseCategoryID; educationMissionClass.CourseTypeID = mission.ExecutableOptionalCourse.CourseTypeID; educationMissionClass.CourseQualityID = mission.ExecutableOptionalCourse.CourseQualityID; educationMissionClass.ExaminationModeID = mission.ExecutableOptionalCourse.ExaminationModeID; educationMissionClass.TeachinglanguageID = mission.ExecutableOptionalCourse.TeachinglanguageID; educationMissionClass.HandleModeID = (int)CF_HandleMode.SelectionCourse; educationMissionClass.IsNeedMaterial = false; educationMissionClass.CF_Classmajor = mission.Classmajor; educationMissionClass.ResultTypeID = mission.ExecutableOptionalCourse.ResultTypeID; foreach (var list in mission.Teacher.Select(x => new { x.UserID, x.TeachingMethod })) { EM_MissionClassTeacher teacher = new EM_MissionClassTeacher(); teacher.MissionClassTeacherID = Guid.NewGuid(); teacher.MissionClassID = educationMissionClass.EducationMissionClassID; teacher.TeachType = list.TeachingMethod; teacher.UserID = list.UserID; SetNewStatus(teacher); educationMissionClass.EM_MissionClassTeacher.Add(teacher); resultTeacherList.Add(teacher); } //educationMissionClass.EM_MissionClassTeacher = mission.Teacher; SetNewStatus(educationMissionClass); educationMissionClass.RecordStatus = (int)EMIS.ViewModel.CF_ApprovalStatus.NotSubmitted; //插入教学设置 EM_EducationMissionClassTeachingSetting educationMissionClassTeachingSetting = new EM_EducationMissionClassTeachingSetting(); educationMissionClassTeachingSetting.EducationMissionClassID = educationMissionClass.EducationMissionClassID; educationMissionClassTeachingSetting.Credit = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.Credit; educationMissionClassTeachingSetting.TheoryCourse = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.TheoryCourse; educationMissionClassTeachingSetting.Practicehours = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.Practicehours; educationMissionClassTeachingSetting.Trialhours = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.Trialhours; educationMissionClassTeachingSetting.WeeklyNum = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.WeeklyNum; educationMissionClassTeachingSetting.TheoryWeeklyNum = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.TheoryWeeklyNum; educationMissionClassTeachingSetting.PracticeWeeklyNum = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.PracticeWeeklyNum; educationMissionClassTeachingSetting.TrialWeeklyNum = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.TrialWeeklyNum; educationMissionClassTeachingSetting.StartWeeklyNum = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.StartWeeklyNum; educationMissionClassTeachingSetting.EndWeeklyNum = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.EndWeeklyNum; educationMissionClassTeachingSetting.WeeklyHours = mission.ExecutableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting.WeeklyHours; //插入排课班 EM_EducationSchedulingClass educationSchedulingClass = new EM_EducationSchedulingClass(); educationSchedulingClass.EducationSchedulingClassID = Guid.NewGuid(); educationSchedulingClass.EducationMissionClassID = educationMissionClass.EducationMissionClassID; educationSchedulingClass.TaskGroupName = "1班"; SetNewStatus(educationSchedulingClass); List educationMissionClassUserIDs = existsMissionClassStudentList .Where(x => x.CoursematerialID == educationMissionClass.CoursematerialID && x.SchoolyearID == educationMission.SchoolyearID && x.HandleModeID == educationMissionClass.HandleModeID && x.CourseSelectTypeID == educationMissionClass.OptionalCourseTypeID).Select(x => x.UserID.Value).ToList(); //查询要开班的教学任务班对应学生 List missionUserIDs = mission.Student.Select(x => x.UserID).ToList(); //添加排课任务班学生(先查出要开班的学生与已存在的排课班对应学生的差集,排除重复学生,分班后删除再重新开班时存在重复学生) educationSchedulingClass.CF_Student = new HashSet(mission.Student.Where(x => missionUserIDs.Except(educationMissionClassUserIDs).Contains(x.UserID))); //选此课的学生 resultMissionClassList.Add(educationMissionClass); resultMissionClassTeachingSettingList.Add(educationMissionClassTeachingSetting); resultSchedulingClassList.Add(educationSchedulingClass); } mission.ExecutableOptionalCourse.RecordStatus = (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Created; } UnitOfWork.BulkInsert(resultMissionList); UnitOfWork.BulkInsert(resultMissionClassList); UnitOfWork.BulkInsert(resultMissionClassTeachingSettingList); UnitOfWork.BulkInsert(resultMissionClassList, (x => x.CF_Classmajor)); UnitOfWork.BulkInsert(resultMissionClassList, (x => x.EM_MissionClassTeacher)); UnitOfWork.BulkInsert(resultTeacherList); UnitOfWork.BulkInsert(resultSchedulingClassList); UnitOfWork.BulkInsert(resultSchedulingClassList, (x => x.CF_Student)); UnitOfWork.Commit(); } catch (Exception) { throw; } } /// /// 生成任选教学任务班 /// /// /// public void GenerateEducationMissionClassFreeSelection(List executableFreeSelectionCourseIDs) { try { var executableFreeSelectionCourseList = OptionalCourseSettingDAL.ExecutableFreeSelectionCouseRepository.GetList(x => executableFreeSelectionCourseIDs.Contains(x.ExecutableFreeSelectionCouseID), (x => x.CF_Student), (x => x.EM_ExecutableFreeSelectionCouseTeachingMode), (x => x.EM_ExecutableFreeSelectionCouseTeacher), (x => x.EM_ExecutableFreeSelectionCouseTeachingSetting), (x => x.EM_FreeSelectionCouse.EM_Coursematerial), (x => x.EM_FreeSelectionCouse.EM_Coursematerial.EM_ClassGrouping.EM_ClassGroupingSettings), (x => x.EM_ExecutableFreeSelectionCouseScheduling), (x => x.CF_Department) ).ToList(); var submitedList = executableFreeSelectionCourseList.Where(x => x.RecordStatus != (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Opened && x.RecordStatus != (int)EMIS.ViewModel.EM_SelectCourseResultStatus.CancleCreate).ToList(); if (submitedList.Count > 0) { throw new Exception("不是已开放状态不能进行开班,请核查。"); } var noTeachingModeTypeList = executableFreeSelectionCourseList.Where(x => x.EM_ExecutableFreeSelectionCouseTeachingMode.Count == 0) .Concat(executableFreeSelectionCourseList.Where(x => !x.EM_ExecutableFreeSelectionCouseTeachingMode.Any(w => w.TeachingModeID != null))).ToList(); if (noTeachingModeTypeList.Count > 0) { throw new Exception("没有设置授课方式的计划不能提交,请核查。"); } var noSchedulingList = executableFreeSelectionCourseList.Where(x => x.EM_ExecutableFreeSelectionCouseScheduling.Count == 0).FirstOrDefault(); if (noSchedulingList != null) throw new Exception(noSchedulingList.DefaultClassName + "缺少排课信息,不能开班"); var resultMissionList = new List(); //教学任务 var resultMissionClassList = new List(); //教学任务班 var resultMissionClassTeachingSettingList = new List(); var resultEducationSchedulingClassList = new List(); //排课班表 var resultTeacherList = new List(); //教学任务班任课老师表 var resultEducationSchedulingList = new List(); //排课课表 var resultEducationSchedulingTeacherList = new List(); //排课老师表 var resultEducationSchedulingWeekNumList = new List(); //排课周次表 var resultCourseProcessList = new List(); //课程进度 var resultCourseProcessTeacherList = new List(); //课程进度任课老师表 var resultEducationMissionClassSettingsList = new List(); //任务班设置表 var noStudentList = executableFreeSelectionCourseList.Where(x => x.CF_Student.Count == 0).Select(x => x.DefaultClassName).ToList(); if (noStudentList.Count > 0) { throw new Exception("任务班" + string.Join(",", noStudentList) + "未分配学生!"); } if (executableFreeSelectionCourseList.Count > 0) { executableFreeSelectionCourseList.ForEach(x => x.RecordStatus = (int)EMIS.ViewModel.EM_ExecuteStatus.Submited); string coursematerialName = ""; var courseNames = executableFreeSelectionCourseList.Where(x => x.EM_FreeSelectionCouse.EM_Coursematerial != null && x.EM_FreeSelectionCouse.EM_Coursematerial.EM_ClassGrouping == null).Select(x => x.EM_FreeSelectionCouse.EM_Coursematerial.CourseName).Distinct().ToArray(); coursematerialName = string.Join(",", courseNames); if (courseNames.Length > 0) { throw new Exception("以下计划所对应的课程并未设置上课类型,无法确定任务班的分班方式,请到课程资料菜单完成设置后再次进行提交:\r\n" + coursematerialName); } } var query = ( from efsc in ( //先找出上课类型没有设置的授课方式,然后单独成一个班 (from efsc in executableFreeSelectionCourseList where efsc.EM_ExecutableFreeSelectionCouseTeachingMode .Any(x => !efsc.EM_FreeSelectionCouse.EM_Coursematerial .EM_ClassGrouping .EM_ClassGroupingSettings.Select(w => w.TeachingModeID).Contains(x.TeachingModeID)) select new { ExecutableFreeSelectionCourse = efsc, TeachingMode = efsc.EM_ExecutableFreeSelectionCouseTeachingMode .FirstOrDefault(x => !efsc.EM_FreeSelectionCouse.EM_Coursematerial .EM_ClassGrouping .EM_ClassGroupingSettings.Select(w => w.TeachingModeID).Contains(x.TeachingModeID)) .TeachingModeID }) //接下来对除理论班之外的其他分班设置进行匹配,如果该专业课程有这个授课方式的话,就单独再分一个班 .Concat( from efsc in executableFreeSelectionCourseList from tmt in efsc.EM_ExecutableFreeSelectionCouseTeachingMode from cgs in efsc.EM_FreeSelectionCouse.EM_Coursematerial.EM_ClassGrouping.EM_ClassGroupingSettings where tmt.TeachingModeID == cgs.TeachingModeID select new { ExecutableFreeSelectionCourse = efsc, TeachingMode = cgs.TeachingModeID })) join dtm in DictionaryHelper.GetDictionaryValue(ViewModel.DictionaryItem.CF_TeachingMode) on efsc.TeachingMode equals dtm.Value group dtm by new { ExecutableFreeSelectionCourse = efsc.ExecutableFreeSelectionCourse } into g select new { ExecutableFreeSelectionCourse = g.Key.ExecutableFreeSelectionCourse, TeachingSetting = g.Key.ExecutableFreeSelectionCourse.EM_ExecutableFreeSelectionCouseTeachingSetting, TeachingMode = g.Select(x => x).ToList(), Teacher = g.Key.ExecutableFreeSelectionCourse.EM_ExecutableFreeSelectionCouseTeacher, Scheduling = g.Key.ExecutableFreeSelectionCourse.EM_ExecutableFreeSelectionCouseScheduling, Student = g.Key.ExecutableFreeSelectionCourse.CF_Student, //选此课的学生 } ); var missionDataList = query.ToList(); for (int i = 0; i < missionDataList.Count; i++) { var mission = missionDataList[i]; EM_EducationMission educationMission = new EM_EducationMission(); educationMission.EducationMissionID = Guid.NewGuid(); educationMission.ClassName = mission.ExecutableFreeSelectionCourse.DefaultClassName; educationMission.DepartmentID = mission.ExecutableFreeSelectionCourse.DepartmentID; educationMission.SchoolyearID = mission.ExecutableFreeSelectionCourse.SchoolyearID; educationMission.CollegeID = mission.ExecutableFreeSelectionCourse.CF_Department.CollegeID; SetNewStatus(educationMission); //educationMission.CF_Classmajor.Add(mission.Classmajor); resultMissionList.Add(educationMission); foreach (var tm in mission.TeachingMode) { var executableFreeSelectionCouseScheduling = mission.ExecutableFreeSelectionCourse.EM_ExecutableFreeSelectionCouseScheduling.FirstOrDefault(); EM_EducationMissionClass educationMissionClass = new EM_EducationMissionClass(); educationMissionClass.EducationMissionClassID = Guid.NewGuid(); educationMissionClass.OrderNo = 0; educationMissionClass.EducationMissionID = educationMission.EducationMissionID; educationMissionClass.Name = mission.ExecutableFreeSelectionCourse.DefaultClassName; //educationMissionClass.Name = mission.Classmajor.Name + "-" + mission.ExecutablePlan.EM_FreeSelectionCouse.EM_Coursematerial.CourseName; educationMissionClass.TeachingModeID = tm.Value; if (mission.TeachingMode.Count > 0) { educationMissionClass.Name += "【" + tm.Name + "】"; } //educationMissionClass.OptionalCourseTypeID = null; educationMissionClass.OptionalCourseTypeID = (int)CF_CourseSelectType.FreeSelectionCourse; educationMissionClass.CoursematerialID = mission.ExecutableFreeSelectionCourse.EM_FreeSelectionCouse.CoursematerialID; educationMissionClass.CourseStructureID = mission.ExecutableFreeSelectionCourse.CourseStructureID; educationMissionClass.CourseCategoryID = mission.ExecutableFreeSelectionCourse.CourseCategoryID; educationMissionClass.CourseTypeID = mission.ExecutableFreeSelectionCourse.CourseTypeID; educationMissionClass.CourseQualityID = mission.ExecutableFreeSelectionCourse.CourseQualityID; educationMissionClass.ExaminationModeID = mission.ExecutableFreeSelectionCourse.ExaminationModeID; educationMissionClass.TeachinglanguageID = mission.ExecutableFreeSelectionCourse.TeachinglanguageID; educationMissionClass.HandleModeID = mission.ExecutableFreeSelectionCourse.HandleModeID; educationMissionClass.IsNeedMaterial = mission.ExecutableFreeSelectionCourse.IsNeedMaterial; educationMissionClass.ResultTypeID = mission.ExecutableFreeSelectionCourse.ResultTypeID; SetNewStatus(educationMissionClass); educationMissionClass.RecordStatus = (int)EMIS.ViewModel.EM_EducationMissionClassStatus.Scheduled; //插入教学设置 EM_EducationMissionClassTeachingSetting educationMissionClassTeachingSetting = new EM_EducationMissionClassTeachingSetting(); educationMissionClassTeachingSetting.EducationMissionClassID = educationMissionClass.EducationMissionClassID; educationMissionClassTeachingSetting.Credit = mission.TeachingSetting.Credit; educationMissionClassTeachingSetting.TheoryCourse = mission.TeachingSetting.TheoryCourse; educationMissionClassTeachingSetting.Practicehours = mission.TeachingSetting.Practicehours; educationMissionClassTeachingSetting.Trialhours = mission.TeachingSetting.Trialhours; educationMissionClassTeachingSetting.WeeklyNum = mission.TeachingSetting.WeeklyNum; educationMissionClassTeachingSetting.TheoryWeeklyNum = mission.TeachingSetting.TheoryWeeklyNum; educationMissionClassTeachingSetting.PracticeWeeklyNum = mission.TeachingSetting.PracticeWeeklyNum; educationMissionClassTeachingSetting.TrialWeeklyNum = mission.TeachingSetting.TrialWeeklyNum; educationMissionClassTeachingSetting.StartWeeklyNum = mission.TeachingSetting.StartWeeklyNum; educationMissionClassTeachingSetting.EndWeeklyNum = mission.TeachingSetting.EndWeeklyNum; educationMissionClassTeachingSetting.WeeklyHours = mission.TeachingSetting.WeeklyHours; foreach (var list in mission.Teacher.Select(x => new { x.UserID, x.TeachingMethod })) { EM_MissionClassTeacher teacher = new EM_MissionClassTeacher(); teacher.MissionClassTeacherID = Guid.NewGuid(); teacher.MissionClassID = educationMissionClass.EducationMissionClassID; teacher.TeachType = list.TeachingMethod; teacher.UserID = list.UserID; SetNewStatus(teacher); educationMissionClass.EM_MissionClassTeacher.Add(teacher); resultTeacherList.Add(teacher); } int? ClassroomType = null; //教室类型,教学任务班表和课程进度需要 if (executableFreeSelectionCouseScheduling != null && executableFreeSelectionCouseScheduling.ClassroomID != null) { var classRoom = educationMissionClassDAL.ClassroomRepository.GetList(x => x.ClassroomID == executableFreeSelectionCouseScheduling.ClassroomID, x => x.CF_ClassroomType).FirstOrDefault(); if (classRoom != null && classRoom.CF_ClassroomType.FirstOrDefault() != null) { ClassroomType = classRoom.CF_ClassroomType.FirstOrDefault().ClassroomType; educationMissionClass.ClassroomTypeID = ClassroomType; } educationMissionClass.ClassroomID = executableFreeSelectionCouseScheduling.ClassroomID; } if (executableFreeSelectionCouseScheduling.CoursesTimeID != null) { var coursesTime = educationMissionClassDAL.CoursesTimeRepository.Entities.Where(x => x.CoursesTimeID == executableFreeSelectionCouseScheduling.CoursesTimeID).FirstOrDefault(); educationMissionClass.EM_CoursesTime = new HashSet(); educationMissionClass.EM_CoursesTime.Add(coursesTime); } //插入排课班 EM_EducationSchedulingClass educationSchedulingClass = new EM_EducationSchedulingClass(); educationSchedulingClass.EducationSchedulingClassID = Guid.NewGuid(); educationSchedulingClass.EducationMissionClassID = educationMissionClass.EducationMissionClassID; educationSchedulingClass.TaskGroupName = "1班"; SetNewStatus(educationSchedulingClass); //添加排课任务班学生 educationSchedulingClass.CF_Student = mission.Student; //选此课的学生 resultMissionClassList.Add(educationMissionClass); resultMissionClassTeachingSettingList.Add(educationMissionClassTeachingSetting); resultEducationSchedulingClassList.Add(educationSchedulingClass); //添加排课任务班学生 educationSchedulingClass.CF_Student = mission.Student; //选此课的学生 //resultMissionClassList.Add(educationMissionClass); //resultSchedulingClassList.Add(educationSchedulingClass); //根据开始和结束周,得到所有周的列表 List schedulingWeekList = new List(); schedulingWeekList.Add(mission.TeachingSetting.StartWeeklyNum); schedulingWeekList.Add(mission.TeachingSetting.EndWeeklyNum); for (int j = 1; j + schedulingWeekList.Min() < schedulingWeekList.Max(); j++) { schedulingWeekList.Add(j + schedulingWeekList.Min()); } //排课课表 foreach (var list in mission.Scheduling.Select(x => new { x.CoursesTimeID, x.ClassroomID, x.Weekday })) { ES_EducationScheduling educationScheduling = new ES_EducationScheduling(); educationScheduling.EducationSchedulingID = Guid.NewGuid(); educationScheduling.EducationSchedulingClassID = educationSchedulingClass.EducationSchedulingClassID; educationScheduling.SchoolyearID = educationMission.SchoolyearID; educationScheduling.Weekday = list.Weekday; educationScheduling.ClassroomID = list.ClassroomID; educationScheduling.CoursesTimeID = list.CoursesTimeID; SetNewStatus(educationScheduling); //educationScheduling.ES_EducationSchedulingTeacher.Add(educationScheduling); resultEducationSchedulingList.Add(educationScheduling); //排课教师表 foreach (var teacherlist in mission.Teacher.Select(x => new { x.UserID, x.TeachingMethod })) { ES_EducationSchedulingTeacher teacher = new ES_EducationSchedulingTeacher(); teacher.EducationSchedulingTeacherID = Guid.NewGuid(); teacher.EducationSchedulingID = educationScheduling.EducationSchedulingID; teacher.TeachingMethod = teacherlist.TeachingMethod; teacher.UserID = teacherlist.UserID; SetNewStatus(teacher); educationScheduling.ES_EducationSchedulingTeacher.Add(teacher); resultEducationSchedulingTeacherList.Add(teacher); } foreach (var weekList in schedulingWeekList) { ES_EducationSchedulingWeekNum week = new ES_EducationSchedulingWeekNum(); week.EducationSchedulingWeekNumID = Guid.NewGuid(); week.EducationSchedulingID = educationScheduling.EducationSchedulingID; week.WeekNum = weekList; SetNewStatus(week); educationScheduling.ES_EducationSchedulingWeekNum.Add(week); resultEducationSchedulingWeekNumList.Add(week); } } //课程进度和教室以及任务班设置表 foreach (var weekList in schedulingWeekList) { EM_CourseProcess process = new EM_CourseProcess(); process.CourseProcessID = Guid.NewGuid(); process.EducationMissionClassID = educationMissionClass.EducationMissionClassID; process.Week = weekList; process.Times = mission.TeachingSetting.WeeklyHours; process.ClassroomTypeID = ClassroomType; process.ClassroomID = educationMissionClass.ClassroomID; SetNewStatus(process); resultCourseProcessList.Add(process); //任务班设置表 EM_EducationMissionClassSettings educationMissionClassSettings = new EM_EducationMissionClassSettings(); educationMissionClassSettings.EducationMissionClassSettingsID = Guid.NewGuid(); educationMissionClassSettings.EducationMissionClassID = educationMissionClass.EducationMissionClassID; educationMissionClassSettings.WeeklyNum = weekList; SetNewStatus(educationMissionClassSettings); resultEducationMissionClassSettingsList.Add(educationMissionClassSettings); //排课教师表 foreach (var teacherlist in mission.Teacher.Select(x => new { x.UserID, x.TeachingMethod })) { EM_CourseProcessTeacher teacher = new EM_CourseProcessTeacher(); teacher.CourseProcessTeacherID = Guid.NewGuid(); teacher.CourseProcessID = process.CourseProcessID; teacher.UserID = teacherlist.UserID; teacher.TeachType = teacherlist.TeachingMethod; SetNewStatus(teacher); resultCourseProcessTeacherList.Add(teacher); } } } //UnitOfWork.Add(educationMission); EM_ExecutableFreeSelectionCouse eoc = GetExecutableFreeSelectionCouseEntity(mission.ExecutableFreeSelectionCourse.ExecutableFreeSelectionCouseID); if (eoc != null) //状态改为已开班 eoc.RecordStatus = (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Created; } UnitOfWork.BulkInsert(resultMissionList); //教学任务 UnitOfWork.BulkInsert(resultMissionClassList); //教学任务班 UnitOfWork.BulkInsert(resultMissionClassTeachingSettingList); UnitOfWork.BulkInsert(resultTeacherList); // UnitOfWork.BulkInsert(resultMissionClassList, x => x.EM_CoursesTime); // UnitOfWork.BulkInsert(resultEducationMissionClassSettingsList); //任务班设置表 UnitOfWork.BulkInsert(resultEducationSchedulingList); //排课课表 UnitOfWork.BulkInsert(resultEducationSchedulingTeacherList); //排课老师表 UnitOfWork.BulkInsert(resultEducationSchedulingWeekNumList); // UnitOfWork.BulkInsert(resultEducationSchedulingClassList); //排课班表 UnitOfWork.BulkInsert(resultEducationSchedulingClassList, (x => x.CF_Student)); //排课班与学生关联表 UnitOfWork.BulkInsert(resultCourseProcessList); //课程进度 UnitOfWork.BulkInsert(resultCourseProcessTeacherList); //课程进度任课老师表 UnitOfWork.Commit(); } catch (Exception) { throw; } } public bool EditStudent(SelectCourseResultView selectCourseResult, IList studentList) { try { var executableOptionalCourse = OptionalCourseSettingDAL.ExecutableOptionalCourseRepository.GetList(x => x.ExecutableOptionalCourseID == selectCourseResult.ID, (x => x.CF_Student) ).FirstOrDefault(); var executableFreeSelectionCouse = OptionalCourseSettingDAL.ExecutableFreeSelectionCouseRepository.GetList(x => x.ExecutableFreeSelectionCouseID == selectCourseResult.ID, (x => x.CF_Student) ).FirstOrDefault(); var ids = studentList.Select(x => x.UserID).ToList(); var list = SelectCourseResultDAL.StudentRepository.GetList(x => ids.Contains(x.UserID)); if (executableOptionalCourse != null) { if (executableOptionalCourse.RecordStatus == (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Created) throw new Exception("已生成教学任务班,不能修改学生"); executableOptionalCourse.CF_Student = new HashSet(); //UnitOfWork.Delete(executableFreeSelectionCouse, (x => x.CF_Student)); foreach (var student in list) { executableOptionalCourse.CF_Student.Add(student); } //UnitOfWork.Update(executableFreeSelectionCouse); } else if (executableFreeSelectionCouse != null) { if (executableFreeSelectionCouse.RecordStatus == (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Created) throw new Exception("已生成教学任务班,不能修改学生"); executableFreeSelectionCouse.CF_Student = new HashSet(); foreach (var student in list) { executableFreeSelectionCouse.CF_Student.Add(student); } //UnitOfWork.Update(executableFreeSelectionCouse); } UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } /// /// 更新 /// /// /// public void OptionalCourseSettingUpdate(OptionalCourseSettingView optionalCourseSettingView, IList teacherList) { try { //删除教师 UnitOfWork.Delete(x => x.ExecutableOptionalCourseID == optionalCourseSettingView.ExecutableOptionalCourseID); //添加教师 if (teacherList.Count > 0) { foreach (var teacher in teacherList) { EM_ExecutableOptionalCourseTeacher executableOptionalCourseTeacher = new EM_ExecutableOptionalCourseTeacher(); executableOptionalCourseTeacher.ExecutableOptionalCourseTeacherID = Guid.NewGuid(); executableOptionalCourseTeacher.ExecutableOptionalCourseID = optionalCourseSettingView.ExecutableOptionalCourseID; executableOptionalCourseTeacher.UserID = teacher.UserID; executableOptionalCourseTeacher.TeachingMethod = teacher.TeachingMethod; SetNewStatus(executableOptionalCourseTeacher); UnitOfWork.Add(executableOptionalCourseTeacher); } UnitOfWork.Commit(); } } catch (Exception) { throw; } } /// /// 获取教学任务授课老师 /// /// /// public List GetTeacherList(Guid? ID, string Type) { if (Type == "0") return OptionalCourseSettingDAL.GetTeacherList().Where(x => x.ID == ID).OrderBy(x => x.TeachingMethod).ToList(); else return OptionalCourseSettingDAL.GetTeacherList1().Where(x => x.ID == ID).OrderBy(x => x.TeachingMethod).ToList(); } public EM_ExecutableFreeSelectionCouse GetExecutableFreeSelectionCouseEntity(Guid? executableOptionalCourseID) { return SelectCourseResultDAL.ExecutableFreeSelectionCouseRepository.GetSingle(x => x.ExecutableFreeSelectionCouseID == executableOptionalCourseID); } /// /// 选课结果人数是否达到下限 /// /// /// public bool CheckEnouthNum(IList IDs) { var query = SelectCourseResultDAL.GetCheckEnouthNumSelectCourseResult(IDs).Where(x => x.StudentTotalNum < x.PeopleNumlower); if (query.ToList().Count > 0) return true; else return false; } /// /// 选课结果判断是否有教师、教室 /// /// /// //public bool CheckHaveTeacherOrClassroom(IList IDs) //{ // var query = SelectCourseResultDAL // if (query.ToList().Count > 0) // return true; // else // return false; //} } }