using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using Bowin.Common.Linq.Entity; using Bowin.Common.Linq; using EMIS.DataLogic.RetakeManage; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.RetakeManage; using EMIS.Utility; using EMIS.CommonLogic.SystemServices; using EMIS.ViewModel.EducationManage; using EMIS.DataLogic.EducationManage; using EMIS.CommonLogic.EducationSchedule; using EMIS.DataLogic.SystemSetting; using EMIS.CommonLogic.RetakeManage.General; using EMIS.CommonLogic.StudentManage.StudentStatistics; namespace EMIS.CommonLogic.RetakeManage.General { public class RetakePlanResultServices : BaseServices, IRetakePlanResultServices { public RetakePlanResultDAL RetakePlanResultDAL { get; set; } public EducationMissionClassDAL educationMissionClassDAL { get; set; } public RetakePlanTaskDAL RetakePlanTaskDAL { get; set; } public IInSchoolSettingServices InSchoolSettingServices { get; set; } public IRetakePlanStudentApplyServices IRetakePlanStudentApplyServices { get; set; } /// /// 查询重修班级信息View(统计已报人数) /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetRetakePlanResultTaskView(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID, Guid? departmentID, Guid? coursematerialID, int? retakeTypeID, int? statusID, int pageIndex, int pageSize) { //重修计划 Expression> expRetakePlan = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); //排除重修任务状态为未开放状态的信息 expRetakePlan = expRetakePlan.And(x => x.RecordStatus != (int)ER_RetakePlanStatus.NotOpened); if (schoolyearID.HasValue) { //重修学年学期 expRetakePlan = expRetakePlan.And(x => x.SchoolyearID == schoolyearID); } if (coursematerialID.HasValue) { //课程信息 expRetakePlan = expRetakePlan.And(x => x.CoursematerialID == coursematerialID); } if (retakeTypeID.HasValue) { //重修类型 expRetakePlan = expRetakePlan.And(x => x.RetakeTypeID == retakeTypeID); } if (statusID.HasValue) { //重修任务状态 expRetakePlan = expRetakePlan.And(x => x.RecordStatus == statusID); } //查询对应的重修班级信息View var query = RetakePlanResultDAL.GetRetakePlanResultTaskView(expRetakePlan); if (collegeID.HasValue) { //开课院系所 query = query.Where(x => x.CourseCollegeID == collegeID); } if (departmentID.HasValue) { //开课教研室 query = query.Where(x => x.DepartmentID == departmentID); } //查询条件() if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SchoolyearCode.Length) .ThenBy(x => x.SchoolyearCode).ThenBy(x => x.DepartmentCode.Length) .ThenBy(x => x.DepartmentCode).ThenBy(x => x.RetakeTypeID) .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode) .ThenBy(x => x.CourseTypeID).ThenBy(x => x.ClassName) .ToGridResultSet(pageIndex, pageSize); //查询对应的重修计划IDList var retakePlanIDList = query.Select(x => x.RetakePlanID).ToList(); //查询对应的课程表信息 var schedulingList = RetakePlanTaskDAL.GetSchedulingView(x => retakePlanIDList.Contains(x.RetakePlanID.Value)).ToList(); //查询合并显示的课程表信息 var weekdayTimesList = IRetakePlanStudentApplyServices.GetWeekdayTimesSegmentName(schedulingList); result.rows.ForEach(x => { var list = weekdayTimesList.Where(w => w.ID == x.RetakePlanID); x.WeekdayTimesSegmentName = string.Join(";", list.OrderBy(w => w.Weekday).Select(w => w.WeekdayTimesSegmentName)); x.ClassroomName = schedulingList.Where(w => w.ID == x.RetakePlanID).Select(w => w.ClassroomName).FirstOrDefault(); }); //查询合并显示的任课老师信息 var teacherList = RetakePlanResultDAL.GetRetakePlanTeacherView(x => retakePlanIDList.Contains(x.RetakePlanID)); result.rows.ForEach(x => x.TeacherName = string.Join(",", teacherList.Where(w => w.RetakePlanID == x.RetakePlanID).Select(w => w.TeacherName))); return result; } /// /// 查询重修班级信息List(统计已报人数) /// /// /// /// /// /// /// /// public List GetRetakePlanResultTaskViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID, Guid? departmentID, Guid? coursematerialID, int? retakeTypeID, int? statusID) { //重修计划 Expression> expRetakePlan = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); //排除重修任务状态为未开放状态的信息 expRetakePlan = expRetakePlan.And(x => x.RecordStatus != (int)ER_RetakePlanStatus.NotOpened); if (schoolyearID.HasValue) { //重修学年学期 expRetakePlan = expRetakePlan.And(x => x.SchoolyearID == schoolyearID); } if (coursematerialID.HasValue) { //课程信息 expRetakePlan = expRetakePlan.And(x => x.CoursematerialID == coursematerialID); } if (retakeTypeID.HasValue) { //重修类型 expRetakePlan = expRetakePlan.And(x => x.RetakeTypeID == retakeTypeID); } if (statusID.HasValue) { //重修任务状态 expRetakePlan = expRetakePlan.And(x => x.RecordStatus == statusID); } //查询对应的重修班级信息View var query = RetakePlanResultDAL.GetRetakePlanResultTaskView(expRetakePlan); if (collegeID.HasValue) { //开课院系所 query = query.Where(x => x.CourseCollegeID == collegeID); } if (departmentID.HasValue) { //开课教研室 query = query.Where(x => x.DepartmentID == departmentID); } //查询条件() if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SchoolyearCode.Length) .ThenBy(x => x.SchoolyearCode).ThenBy(x => x.DepartmentCode.Length) .ThenBy(x => x.DepartmentCode).ThenBy(x => x.RetakeTypeID) .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode) .ThenBy(x => x.CourseTypeID).ThenBy(x => x.ClassName) .ToList(); //查询对应的重修计划IDList var retakePlanIDList = query.Select(x => x.RetakePlanID).ToList(); //查询对应的课程表信息 var schedulingList = RetakePlanTaskDAL.GetSchedulingView(x => retakePlanIDList.Contains(x.RetakePlanID.Value)).ToList(); //查询合并显示的课程表信息 var weekdayTimesList = IRetakePlanStudentApplyServices.GetWeekdayTimesSegmentName(schedulingList); result.ForEach(x => { var list = weekdayTimesList.Where(w => w.ID == x.RetakePlanID); x.WeekdayTimesSegmentName = string.Join(";", list.OrderBy(w => w.Weekday).Select(w => w.WeekdayTimesSegmentName)); x.ClassroomName = schedulingList.Where(w => w.ID == x.RetakePlanID).Select(w => w.ClassroomName).FirstOrDefault(); }); //查询合并显示的任课老师信息 var teacherList = RetakePlanResultDAL.GetRetakePlanTeacherView(x => retakePlanIDList.Contains(x.RetakePlanID)); result.ForEach(x => x.TeacherName = string.Join(",", teacherList.Where(w => w.RetakePlanID == x.RetakePlanID).Select(w => w.TeacherName))); return result; } /// /// 查询对应的重修班级报名名单信息 /// /// /// /// /// public IGridResultSet GetRetakePlanResultTaskStudentView(Guid? retakePlanID, int pageIndex, int pageSize) { var query = RetakePlanResultDAL.GetRetakePlanResultView(x => x.RetakePlanID == retakePlanID) .OrderBy(x => x.LoginID); return query.ToGridResultSet(pageIndex, pageSize); } /// /// 查询对应的重修班级报名名单信息List /// /// /// /// public List GetRetakePlanResultTaskStudentViewList(ConfiguretView configuretView, Guid? retakePlanID) { var query = RetakePlanResultDAL.GetRetakePlanResultView(x => x.RetakePlanID == retakePlanID) .OrderBy(x => x.LoginID); return query.ToList(); } /// /// 查询对应的重修班级未报名名单列表(未报名名单) /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetStudentView(ConfiguretView configuretView, Guid? retakePlanID, int? gradeYearID, int? standardID, Guid? classmajorID, int? inSchoolStatus, int pageIndex, int pageSize) { //查询对应的重修计划信息 var retakePlanView = RetakePlanResultDAL.RetakePlanRepository.Entities .Where(x => x.RetakePlanID == retakePlanID).SingleOrDefault(); if (retakePlanView == null) { throw new Exception("数据有误,请核查。"); } //查询对应的重修班级未报名名单 var query = RetakePlanResultDAL.GetRetakePlanResultTaskStudentView(x => x.RetakePlanID == retakePlanID); if (gradeYearID.HasValue) { query = query.Where(x => x.Gradeyear == gradeYearID); } if (standardID.HasValue) { query = query.Where(x => x.StandardID == standardID); } if (classmajorID.HasValue) { query = query.Where(x => x.ClassmajorID == classmajorID); } if (inSchoolStatus != null && inSchoolStatus > -1) { //在校状态 var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true); if (inSchoolStatus == 1) { //表示在校 query = query.Where(x => inschoolStatusList.Contains(x.InSchoolStatusID)); } if (inSchoolStatus == 0) { //不在校 query = query.Where(x => !inschoolStatusList.Contains(x.InSchoolStatusID)); } } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.LoginID.Length) .ThenBy(x => x.LoginID) .ToGridResultSet(pageIndex, pageSize); } /// /// 重修班级报名名单报名(从计划人数中选择) /// 由于存在多个相对应的重修计划,需要判断报名情况 /// /// /// /// public string AddStudent(Guid? retakePlanID, string UserIDs) { try { int success = 0; //成功 int fail = 0; //失败 string tipMessage = null; //提示消息 List userIDslist = UserIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)) .Select(x => (Guid?)new Guid(x)).ToList(); //查询对应的学生信息View var studentViewList = RetakePlanResultDAL.StudentRepository .GetList(x => userIDslist.Contains(x.UserID)).ToList(); //查询对应的重修计划信息View var retakePlanView = RetakePlanResultDAL.RetakePlanRepository .GetList(x => x.RetakePlanID == retakePlanID, (x => x.ER_RetakePlanSetting), (x => x.CF_Student)).FirstOrDefault(); if (retakePlanView == null) { throw new Exception("数据有误,请核查"); } if (retakePlanView.RecordStatus == (int)EMIS.ViewModel.ER_RetakePlanStatus.Generated) { throw new Exception("不能对已开班状态的信息进行报名。"); } //对人数上限进行判断 if (retakePlanView.PeopleNumlimit != null && retakePlanView.PeopleNumlimit != 0 && (retakePlanView.CF_Student.Count() + userIDslist.Count()) > retakePlanView.PeopleNumlimit.Value) { throw new Exception("报名人数已达上限。"); } //重修计划 Expression> expRetakePlan = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (retakePlanView.CoursematerialID.HasValue) { //课程信息 expRetakePlan = expRetakePlan.And(x => x.CoursematerialID == retakePlanView.CoursematerialID); } if (retakePlanView.RetakeTypeID.HasValue) { //重修类型 expRetakePlan = expRetakePlan.And(x => x.RetakeTypeID == retakePlanView.RetakeTypeID); } if (retakePlanView.SchoolyearID.HasValue) { //重修学年学期 expRetakePlan = expRetakePlan.And(x => x.SchoolyearID == retakePlanView.SchoolyearID); } if (retakePlanView.CourseTypeID.HasValue) { //课程类型 expRetakePlan = expRetakePlan.And(x => x.CourseTypeID == retakePlanView.CourseTypeID); } if (retakePlanView.Credit.HasValue) { //课程学分 expRetakePlan = expRetakePlan.And(x => x.Credit == retakePlanView.Credit); } //查询对应的重修计划信息View var newRetakePlanViewList = RetakePlanResultDAL.GetRetakePlanResultTaskView(expRetakePlan); var newRetakePlanIDList = newRetakePlanViewList.Where(x => x.DepartmentID == retakePlanView.ER_RetakePlanSetting.DepartmentID).Select(x => x.RetakePlanID).ToList(); //查询对应的重修报名信息List var retakePlanStudentApplyList = RetakePlanResultDAL.RetakePlanStudentRepository .GetList(x => newRetakePlanIDList.Contains(x.RetakePlanID), (x => x.ER_RetakePlan), (x => x.ER_RetakePlan.CF_Student)) .Where(x => x.ER_RetakePlan.CF_Student.Any(w => w.UserID == x.UserID)) .ToList(); //if (retakePlanStudentApplyList.Count() > 0) //{ // throw new Exception("存在对应的已报名重修计划名单。"); //} //判断重修计划的报名情况 foreach (var studentView in studentViewList) { //查询对应的学生重修报名信息 var retakePlanStudentApply = retakePlanStudentApplyList .Where(x => x.UserID == studentView.UserID).ToList(); if (retakePlanStudentApply.Count() <= 0) { //表示可报名 //目前缺少排课冲突的判断(暂时不考虑) //重修报名 retakePlanView.CF_Student.Add(studentView); success++; } else { //表示已存在报名名单 fail++; } } UnitOfWork.Commit(); if (success > 0 && fail <= 0) { tipMessage = success + "个"; } else { tipMessage = success + "个," + fail + "个失败,原因:已存在相应的报名信息,请检查"; } return tipMessage; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除(重修报名名单删除,取消报名) /// /// /// public void DeleteStudent(Guid? retakePlanID, string UserIDs) { try { List userIDslist = UserIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)) .Select(x => (Guid?)new Guid(x)).ToList(); //查询对应的重修计划信息 var retakePlanView = RetakePlanResultDAL.RetakePlanRepository .GetList(x => x.RetakePlanID == retakePlanID, x => x.CF_Student).FirstOrDefault(); if (retakePlanView == null) { throw new Exception("数据有误,请核查。"); } if (retakePlanView.RecordStatus == (int)EMIS.ViewModel.ER_RetakePlanStatus.Generated) { throw new Exception("不能对已开班状态的信息取消报名。"); } //重修报名表 retakePlanView.CF_Student.RemoveWhere(x => userIDslist.Contains(x.UserID)); UnitOfWork.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 开班(重修计划) /// /// /// public string RetakePlanResultGenerate(string RetakePlanIDs) { try { int success = 0; //成功 int fail = 0; //失败 string tipMessage = null; //提示消息 List RetakePlanIDslist = RetakePlanIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)) .Select(x => (Guid?)new Guid(x)).ToList(); //查询对应的重修计划信息 var retakePlanList = RetakePlanResultDAL.RetakePlanRepository .GetList(x => RetakePlanIDslist.Contains(x.RetakePlanID), x => x.CF_Student, x => x.EM_Coursematerial, x => x.EM_Coursematerial.EM_ClassGrouping.EM_ClassGroupingSettings, x => x.ER_RetakePlanSetting, x => x.ER_RetakePlanSetting.ER_RetakePlanTeachingModeType, x => x.ER_RetakePlanSetting.ER_RetakePlanTeachingPlace, x => x.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting, x => x.ER_RetakePlanStudent, x => x.ER_RetakePlanTeacher, x => x.ER_RetakePlanSettingScheduling ).ToList(); var noSchedulingList = retakePlanList.Where(x => x.ER_RetakePlanSettingScheduling.Count() == 0).FirstOrDefault(); if (noSchedulingList != null) { throw new Exception(noSchedulingList.ClassName + ",缺少排课信息,不能开班"); } var noClassRoomList = retakePlanList.Where(x => x.ER_RetakePlanSettingScheduling.Any(w => w.ClassroomID == null)).FirstOrDefault(); if (noClassRoomList != null) { throw new Exception(noClassRoomList.ClassName + ",未设置上课教室,不能开班"); } var DepartmentIDsList = retakePlanList.Select(x => x.ER_RetakePlanSetting.DepartmentID).Distinct().ToList(); var CollegeDepartmentList = RetakePlanResultDAL.DepartmentRepository.GetList(x => DepartmentIDsList.Contains(x.DepartmentID)); var RetakeGenerateList = retakePlanList.Where(x => x.RecordStatus == (int)EMIS.ViewModel.ER_RetakePlanStatus.Generated).ToList(); if (RetakeGenerateList.Count > 0) { throw new Exception("已开班状态的重修计划不能进行开班,请核查。"); } string coursematerialName = ""; var courseNames = retakePlanList.Where(x => x.EM_Coursematerial != null && x.EM_Coursematerial.EM_ClassGrouping == null).Select(x => x.EM_Coursematerial.CourseName).Distinct().ToArray(); coursematerialName = string.Join(",", courseNames); if (courseNames.Length > 0) { throw new Exception("以下重修所对应的课程并未设置上课类型,无法确定任务班的分班方式,请到课程资料菜单完成设置后再次进行提交:\r\n" + coursematerialName); } List message = new List(); //var PassRetakeList = RetakeList; List RemoveList = new List(); //验证必填项 #region for (int i = 0; i < retakePlanList.Count; i++) //foreach (var Retake in PassRetakeList) { var Retake = retakePlanList[i]; if (Retake.ER_RetakePlanSetting.DepartmentID == null) { message.Add("教研室、"); //message += ; //RemoveList.Add(Retake);//PassRetakeList.Remove(Retake); RemoveList.Add(Retake); } if (Retake.ER_RetakePlanSetting.CourseCategoryID == null) { message.Add("课程属性、"); //message += ; //RemoveList.Add(Retake);//PassRetakeList.Remove(Retake); RemoveList.Add(Retake); } if (Retake.ER_RetakePlanSetting.CourseQualityID == null) { message.Add("课程性质、"); //message += ; RemoveList.Add(Retake);//RemoveList.Add(Retake);//PassRetakeList.Remove(Retake); } if (Retake.CourseTypeID == null) { message.Add("课程类型、"); //message += ; RemoveList.Add(Retake);//PassRetakeList.Remove(Retake); } if (Retake.ER_RetakePlanSetting.ExaminationModeID == null) { message.Add("考试方式、"); //message += ; RemoveList.Add(Retake);//PassRetakeList.Remove(Retake); } if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting != null) { if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting.TheoryCourse == null) { message.Add("理论学时、"); //message += ; RemoveList.Add(Retake);//PassRetakeList.Remove(Retake); } if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting.Trialhours == null) { message.Add("实验学时、"); //message += ; RemoveList.Add(Retake);//PassRetakeList.Remove(Retake); } if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting.WeeklyNum == null) { message.Add("每周次数、"); //message += ; RemoveList.Add(Retake);//PassRetakeList.Remove(Retake); } if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting.TheoryWeeklyNum == null) { message.Add("理论周数、"); //message += ; RemoveList.Add(Retake);//PassRetakeList.Remove(Retake); } if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting.TrialWeeklyNum == null) { message.Add("实验周数、"); //message += "实验周数、"; RemoveList.Add(Retake);//PassRetakeList.Remove(Retake); } if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting.StartWeeklyNum == null) { message.Add("开始周次、"); //message += ; RemoveList.Add(Retake);//PassRetakeList.Remove(Retake); } if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting.EndWeeklyNum == null) { message.Add("结束周次、"); //message += ; RemoveList.Add(Retake);//PassRetakeList.Remove(Retake); } if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting.WeeklyHours == null) { message.Add("周学时、"); //message += ; RemoveList.Add(Retake);//PassRetakeList.Remove(Retake); } } else { message.Add("教学设置、"); //message += ; RemoveList.Add(Retake);//PassRetakeList.Remove(Retake); } if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingModeType.Count == 0 || !Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingModeType.Any(w => w.TeachingModeID != null)) { message.Add("授课方式、"); //message += ; RemoveList.Add(Retake);//PassRetakeList.Remove(Retake); } //if (Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingPlace.Count == 0 || !Retake.ER_RetakePlanSetting.ER_RetakePlanTeachingPlace.Any(w => w.TeachingPlace != null)) //{ // message += "授课地点、"; // RemoveList.Add(Retake);//PassRetakeList.Remove(Retake); //} if (Retake.CF_Student.Count == 0) { message.Add("报名学生、"); //message += ; RemoveList.Add(Retake);//PassRetakeList.Remove(Retake); } if (Retake.EM_Coursematerial != null && Retake.EM_Coursematerial.EM_ClassGrouping == null) { RemoveList.Add(Retake);//PassRetakeList.Remove(Retake); } } RemoveList = RemoveList.Distinct().ToList(); retakePlanList.RemoveAll(x => RemoveList.Contains(x)); //message = message.Length > 0 ? message.Remove(message.Length - 1) : message; string result = ""; message.Distinct().ToList().ForEach(x => result += x); result = result.Length > 0 ? result.Remove(result.Length - 1) : result; #endregion ////判断是否有设置授课方式 //var noTeachingModeTypeList = RetakeList.Where(x => x.ER_RetakePlanSetting.ER_RetakePlanTeachingModeType.Count == 0) // .Concat(RetakeList.Where(x => !x.ER_RetakePlanSetting.ER_RetakePlanTeachingModeType.Any(w => w.TeachingModeID != null))).ToList(); //if (noTeachingModeTypeList.Count > 0) //{ // throw new Exception("没有设置授课方式的计划不能提交,请核查。"); //} 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 query = ( from efsc in ( //先找出上课类型没有设置的授课方式,然后单独成一个班 (from efsc in retakePlanList where efsc.ER_RetakePlanSetting.ER_RetakePlanTeachingModeType .Any(x => !efsc.EM_Coursematerial .EM_ClassGrouping .EM_ClassGroupingSettings.Select(w => w.TeachingModeID).Contains(x.TeachingModeID)) select new { RetakePlan = efsc, TeachingMode = efsc.ER_RetakePlanSetting.ER_RetakePlanTeachingModeType .FirstOrDefault(x => !efsc.EM_Coursematerial .EM_ClassGrouping .EM_ClassGroupingSettings.Select(w => w.TeachingModeID).Contains(x.TeachingModeID)) .TeachingModeID }) //接下来对除理论班之外的其他分班设置进行匹配,如果该专业课程有这个授课方式的话,就单独再分一个班 .Concat( from efsc in retakePlanList from tmt in efsc.ER_RetakePlanSetting.ER_RetakePlanTeachingModeType from cgs in efsc.EM_Coursematerial.EM_ClassGrouping.EM_ClassGroupingSettings where tmt.TeachingModeID == cgs.TeachingModeID select new { RetakePlan = efsc, TeachingMode = cgs.TeachingModeID })) join co in RetakePlanResultDAL.DepartmentRepository.Entities on efsc.RetakePlan.ER_RetakePlanSetting.DepartmentID equals co.DepartmentID join dtm in DictionaryHelper.GetDictionaryValue(ViewModel.DictionaryItem.CF_TeachingMode) on efsc.TeachingMode equals dtm.Value group dtm by new { RetakePlan = efsc.RetakePlan, CollegeID = co.CollegeID } into g select new { collegeID = g.Key.CollegeID, RetakePlan = g.Key.RetakePlan, TeachingSetting = g.Key.RetakePlan.ER_RetakePlanSetting.ER_RetakePlanTeachingSetting, TeachingMode = g.Select(x => x).ToList(), Teacher = g.Key.RetakePlan.ER_RetakePlanTeacher, Scheduling = g.Key.RetakePlan.ER_RetakePlanSettingScheduling, Student = g.Key.RetakePlan.CF_Student, //选此课的学生 RetakePlanStudent = g.Key.RetakePlan.ER_RetakePlanStudent } ); 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.RetakePlan.ClassName; educationMission.DepartmentID = mission.RetakePlan.ER_RetakePlanSetting.DepartmentID; educationMission.SchoolyearID = mission.RetakePlan.SchoolyearID; educationMission.CollegeID = mission.collegeID;//CollegeDepartmentList.FirstOrDefault(x => x.DepartmentID == mission.RetakePlan.ER_RetakePlanSetting.DepartmentID.Value).CollegeID; SetNewStatus(educationMission); //educationMission.CF_Classmajor.Add(mission.Classmajor); resultMissionList.Add(educationMission); foreach (var tm in mission.TeachingMode) { var Scheduling = mission.RetakePlan.ER_RetakePlanSettingScheduling.FirstOrDefault(); EM_EducationMissionClass educationMissionClass = new EM_EducationMissionClass(); educationMissionClass.EducationMissionClassID = Guid.NewGuid(); educationMissionClass.OrderNo = 0; educationMissionClass.EducationMissionID = educationMission.EducationMissionID; educationMissionClass.Name = mission.RetakePlan.ClassName; //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 = (int)CF_CourseSelectType.Required; educationMissionClass.CoursematerialID = mission.RetakePlan.CoursematerialID; educationMissionClass.CourseStructureID = mission.RetakePlan.ER_RetakePlanSetting.CourseStructureID; educationMissionClass.CourseCategoryID = mission.RetakePlan.ER_RetakePlanSetting.CourseCategoryID; educationMissionClass.CourseTypeID = mission.RetakePlan.CourseTypeID; educationMissionClass.CourseQualityID = mission.RetakePlan.ER_RetakePlanSetting.CourseQualityID; educationMissionClass.ExaminationModeID = mission.RetakePlan.ER_RetakePlanSetting.ExaminationModeID; educationMissionClass.TeachinglanguageID = mission.RetakePlan.ER_RetakePlanSetting.TeachinglanguageID; //重修默认为必修 educationMissionClass.HandleModeID = (int)EMIS.ViewModel.CF_HandleMode.RequiredCourse; educationMissionClass.IsNeedMaterial = mission.RetakePlan.ER_RetakePlanSetting.IsNeedMaterial; //成绩类型,默认为百分制 educationMissionClass.ResultTypeID = (int)EMIS.ViewModel.CF_ResultType.Percentage; SetNewStatus(educationMissionClass); educationMissionClass.RecordStatus = (int)EMIS.ViewModel.EM_EducationMissionClassStatus.Scheduled; //插入教学设置 EM_EducationMissionClassTeachingSetting educationMissionClassTeachingSetting = new EM_EducationMissionClassTeachingSetting(); educationMissionClassTeachingSetting.EducationMissionClassID = educationMissionClass.EducationMissionClassID; educationMissionClassTeachingSetting.Credit = mission.RetakePlan.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.TeachType })) { EM_MissionClassTeacher teacher = new EM_MissionClassTeacher(); teacher.MissionClassTeacherID = Guid.NewGuid(); teacher.MissionClassID = educationMissionClass.EducationMissionClassID; teacher.TeachType = list.TeachType; teacher.UserID = list.UserID; SetNewStatus(teacher); educationMissionClass.EM_MissionClassTeacher.Add(teacher); resultTeacherList.Add(teacher); } int? ClassroomType = null; //教室类型,教学任务班表和课程进度需要 if (Scheduling != null && Scheduling.ClassroomID != null) { var classRoom = educationMissionClassDAL.ClassroomRepository.GetList(x => x.ClassroomID == Scheduling.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 = Scheduling.ClassroomID; } if (Scheduling.CoursesTimeID != null) { var coursesTime = educationMissionClassDAL.CoursesTimeRepository.Entities.Where(x => x.CoursesTimeID == Scheduling.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); #region//插入排课相关信息 //添加排课任务班学生 educationSchedulingClass.CF_Student = mission.Student; //选此课的学生 //根据开始和结束周,得到所有周的列表 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.TeachType })) { ES_EducationSchedulingTeacher teacher = new ES_EducationSchedulingTeacher(); teacher.EducationSchedulingTeacherID = Guid.NewGuid(); teacher.EducationSchedulingID = educationScheduling.EducationSchedulingID; teacher.TeachingMethod = teacherlist.TeachType; 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.TeachType })) { EM_CourseProcessTeacher teacher = new EM_CourseProcessTeacher(); teacher.CourseProcessTeacherID = Guid.NewGuid(); teacher.CourseProcessID = process.CourseProcessID; teacher.UserID = teacherlist.UserID; teacher.TeachType = teacherlist.TeachType; SetNewStatus(teacher); resultCourseProcessTeacherList.Add(teacher); } } #endregion mission.RetakePlanStudent.ToList().ForEach(x => x.EducationMissionID = educationMission.EducationMissionID); } //UnitOfWork.Add(educationMission); } 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); //课程进度任课老师表 retakePlanList.ForEach(x => x.RecordStatus = (int)EMIS.ViewModel.ER_RetakePlanStatus.Generated); UnitOfWork.Commit(); if (RemoveList.Count == 0) { return "开班成功。"; } else { return string.Format("成功开班{0}条,失败{1}条,原因:缺少{2}", retakePlanList.Count, RemoveList.Count, result + "。"); } } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 检测重修报名人数是否超过人数下限和人数上限范围 /// /// /// public bool IsOverRange(string retakePlanIDs) { List list = retakePlanIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)) .Select(x => (Guid?)new Guid(x)).ToList(); var IsExistsList = this.RetakePlanTaskDAL.RetakePlanRepository .GetList(x => list.Contains(x.RetakePlanID), (x => x.CF_Student)).ToList(); if (IsExistsList != null && IsExistsList.Count() > 0) { foreach (var IsExists in IsExistsList) { if (IsExists.PeopleNumlower != null && IsExists.PeopleNumlower != 0) { //人数下限 if (IsExists.CF_Student.Count() < IsExists.PeopleNumlower.Value) { return true; } } else if (IsExists.PeopleNumlimit != null && IsExists.PeopleNumlimit != 0) { //人数上限 if (IsExists.CF_Student.Count() > IsExists.PeopleNumlimit.Value) { return true; } } } } return false; } /// /// 查询重修计划报名名单信息View /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetRetakePlanResultStudentView(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID, int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem, Guid? classmajorID, Guid? coursematerialID, int? inSchoolStatus, int? retakePlanStatusID, int? generalPurposeID, int pageIndex, int pageSize) { //重修计划 Expression> expRetakePlan = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); ////排除重修任务状态为未开放状态的信息 //expRetakePlan = expRetakePlan.And(x => x.RecordStatus != (int)ER_RetakePlanStatus.NotOpened); if (coursematerialID.HasValue) { //课程信息 expRetakePlan = expRetakePlan.And(x => x.CoursematerialID == coursematerialID); } if (schoolyearID.HasValue) { //重修学年学期 expRetakePlan = expRetakePlan.And(x => x.SchoolyearID == schoolyearID); } if (retakePlanStatusID.HasValue) { //重修任务状态 expRetakePlan = expRetakePlan.And(x => x.RecordStatus == retakePlanStatusID); } //学生信息 Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (classmajorID.HasValue) { //班级信息 expStudent = expStudent.And(x => x.ClassmajorID == classmajorID); } if (inSchoolStatus != null && inSchoolStatus > -1) { //在校状态 var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true); if (inSchoolStatus == 1) { //表示在校 expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID)); } if (inSchoolStatus == 0) { //不在校 expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID)); } } var query = RetakePlanResultDAL.GetRetakePlanResultStudentView(expRetakePlan, expStudent); if (collegeID.HasValue) { //院系所 query = query.Where(x => x.CollegeID == collegeID); } if (yearID.HasValue) { //年级 query = query.Where(x => x.Gradeyear == yearID); } if (standardID.HasValue) { //专业名称 query = query.Where(x => x.StandardID == standardID); } if (educationID.HasValue) { //培养层次 query = query.Where(x => x.EducationID == educationID); } if (learningformID.HasValue) { //学习形式 query = query.Where(x => x.LearningformID == learningformID); } if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1") { //学制 var LearnSystems = Convert.ToDecimal(learnSystem); query = query.Where(x => x.LearnSystem == LearnSystems); } if (generalPurposeID.HasValue) { //报名状态 if (generalPurposeID.Value == (int)CF_GeneralPurpose.IsYes) { query = query.Where(x => x.ApplyStatus == true); } if (generalPurposeID.Value == (int)CF_GeneralPurpose.IsNo) { query = query.Where(x => x.ApplyStatus == false); } } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SchoolyearCode) .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode) .ThenBy(x => x.CourseTypeID).ThenBy(x => x.CourseCredit) .ThenBy(x => x.DepartmentCode.Length).ThenBy(x => x.DepartmentCode) .ThenBy(x => x.LoginID.Length).ThenBy(x => x.LoginID) .ToGridResultSet(pageIndex, pageSize); } /// /// 查询重修计划报名名单信息List /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public List GetRetakePlanResultStudentViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID, int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem, Guid? classmajorID, Guid? coursematerialID, int? inSchoolStatus, int? retakePlanStatusID, int? generalPurposeID) { //重修计划 Expression> expRetakePlan = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); ////排除重修任务状态为未开放状态的信息 //expRetakePlan = expRetakePlan.And(x => x.RecordStatus != (int)ER_RetakePlanStatus.NotOpened); if (coursematerialID.HasValue) { //课程信息 expRetakePlan = expRetakePlan.And(x => x.CoursematerialID == coursematerialID); } if (schoolyearID.HasValue) { //重修学年学期 expRetakePlan = expRetakePlan.And(x => x.SchoolyearID == schoolyearID); } if (retakePlanStatusID.HasValue) { //重修任务状态 expRetakePlan = expRetakePlan.And(x => x.RecordStatus == retakePlanStatusID); } //学生信息 Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (classmajorID.HasValue) { //班级信息 expStudent = expStudent.And(x => x.ClassmajorID == classmajorID); } if (inSchoolStatus != null && inSchoolStatus > -1) { //在校状态 var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true); if (inSchoolStatus == 1) { //表示在校 expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID)); } if (inSchoolStatus == 0) { //不在校 expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID)); } } var query = RetakePlanResultDAL.GetRetakePlanResultStudentView(expRetakePlan, expStudent); if (collegeID.HasValue) { //院系所 query = query.Where(x => x.CollegeID == collegeID); } if (yearID.HasValue) { //年级 query = query.Where(x => x.Gradeyear == yearID); } if (standardID.HasValue) { //专业名称 query = query.Where(x => x.StandardID == standardID); } if (educationID.HasValue) { //培养层次 query = query.Where(x => x.EducationID == educationID); } if (learningformID.HasValue) { //学习形式 query = query.Where(x => x.LearningformID == learningformID); } if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1") { //学制 var LearnSystems = Convert.ToDecimal(learnSystem); query = query.Where(x => x.LearnSystem == LearnSystems); } if (generalPurposeID.HasValue) { //报名状态 if (generalPurposeID.Value == (int)CF_GeneralPurpose.IsYes) { query = query.Where(x => x.ApplyStatus == true); } if (generalPurposeID.Value == (int)CF_GeneralPurpose.IsNo) { query = query.Where(x => x.ApplyStatus == false); } } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SchoolyearCode) .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode) .ThenBy(x => x.CourseTypeID).ThenBy(x => x.CourseCredit) .ThenBy(x => x.DepartmentCode.Length).ThenBy(x => x.DepartmentCode) .ThenBy(x => x.LoginID.Length).ThenBy(x => x.LoginID) .ToList(); } /// /// 取消报名(删除) /// /// /// public void RetakePlanResultDelete(string RetakePlanStudentIDs) { try { List retakePlanStudentIDsList = RetakePlanStudentIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)) .Select(x => (Guid?)new Guid(x)).ToList(); //查询对应的重修报名信息List(已报名) var retakePlanStudentApplyViewList = RetakePlanResultDAL.RetakePlanStudentRepository .GetList(x => retakePlanStudentIDsList.Contains(x.RetakePlanStudentID), (x => x.ER_RetakePlan), (x => x.ER_RetakePlan.CF_Student)) .Where(x => x.ER_RetakePlan.CF_Student.Any(w => w.UserID == x.UserID)) .ToList(); if (retakePlanStudentApplyViewList.Count() > 0) { //查询对应的重修计划信息 var retakePlanViewList = retakePlanStudentApplyViewList .Select(x => x.ER_RetakePlan).Distinct().ToList(); //重修报名表 foreach (var retakePlan in retakePlanViewList) { //查询存在报名名单的重修计划名单对应的userIDList var userIDList = retakePlanStudentApplyViewList .Where(x => x.RetakePlanID == retakePlan.RetakePlanID) .Select(x => x.UserID).ToList(); //取消报名(删除) retakePlan.CF_Student.RemoveWhere(x => userIDList.Contains(x.UserID)); } } UnitOfWork.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } } }