/// <summary> /// 作者:Primo /// 日期:2014.08.12 /// 描述:匹配至 ArrangeCourse /// </summary> /// <param name="branchId"></param> /// <param name="beginDate"></param> /// <param name="endDate"></param> /// <param name="createBy"></param> /// <returns></returns> public static bool DisposeArrangeCourse1(int branchId, DateTime beginDate, DateTime endDate, int createBy, out Dictionary<string, string> outList) { //初始化状态 var result = false; var removeUnfinishedCourses = ""; //匹配成功后需要移除的课程 //课程名称 var ProductLevelCourseTypeCourseName = ""; outList = new Dictionary<string, string>(); var edbAcs = new Model.Acs.EmeAcsEntities(); try { var countPercent = Common.Global.CountPercent.ToString().Split(',');//匹配次数,必须要有一个float值 var planNum = 0; //获取第一个学员 var tempStudent = edbAcs.Student.OrderBy(p => p.WorkDate) .ThenByDescending(p => p.IsFirst) .ThenBy(p => p.ArrangeCourseOrder) .FirstOrDefault(p => p.BranchId == branchId && p.WorkDate >= beginDate && p.WorkDate <= endDate && p.CurrTaskNum <= Common.Global.MaxNum && p.Status == ConvertEnum.StatusTypeForActive); //表示已经循环所有学员了 if (tempStudent == null) { return BranchBLL.UpateStudentByPlanNum(countPercent.Count(), branchId, beginDate, endDate, createBy); } //未上过的课程 var unfinishedCoursesList = tempStudent.UnfinishedCourses.Trim(',').Split(','); //循环未上过的课 foreach (var itemUnfinishedCourses in unfinishedCoursesList) { if (result)//result 为 true ,说明已经找到了适合的 break; if (tempStudent.CurrTaskNum >= Common.Global.MaxNum)//最多匹配三节课给他 { tempStudent.Status = ConvertEnum.StatusTypeForDelete; tempStudent.Remark = "达到最大匹配课时数!"; edbAcs.Entry(tempStudent).State = EntityState.Modified; edbAcs.Configuration.ValidateOnSaveEnabled = false; result = edbAcs.SaveChanges() > 0; edbAcs.Configuration.ValidateOnSaveEnabled = true; break; } if (itemUnfinishedCourses.Trim() == "")//没有可匹配的课程 { tempStudent.Remark = "没有可匹配的课程!"; break; } //未上过的课程转数字类型 var itemUnfinishedCoursesToInt = Convert.ToInt32(itemUnfinishedCourses); //学员可上课时间 var availableTimeList = tempStudent.AvailableTime.Trim(',').Split(','); //循环上课时间去找适合的教室 foreach (var itemAvailableTime in availableTimeList) { //教室 var modelClassroom = new Model.Acs.Classroom(); //教师 var modelTeacher = new Model.Acs.Teacher(); #region 学员 //未上过的课 var strUnfinishedCourses = string.Format(",{0},", itemUnfinishedCourses); //可上课的时间 var strAvailableTime = string.Format(",{0},", itemAvailableTime); //获取类似条件的学生 var studentList = (from a in edbAcs.Student where a.WorkDate == tempStudent.WorkDate && a.UnfinishedCourses.Contains(strUnfinishedCourses) && a.AvailableTime.Contains(strAvailableTime) && a.StudentId != tempStudent.StudentId && a.BranchId == branchId && a.CurrTaskNum < Common.Global.MaxNum //最多只能匹配课节数 select a).ToList(); //符合条件的学员个数 var studentListCount = (studentList.Count() + 1); //如果没有类似的学员,则直接跳过,执行下一次循环 if (studentListCount == 1) continue; #endregion //上课时间拼接 var dtDate = Convert.ToDateTime(string.Format("{0}/{1}/{2} {3}:{4}", itemAvailableTime.Substring(0, 4), itemAvailableTime.Substring(4, 2), itemAvailableTime.Substring(6, 2), itemAvailableTime.Substring(8, 2), itemAvailableTime.Substring(10, 2))); var dtEndDate = dtDate;// 课程结束时间 var edb = new Model.Eme.EmeEntities(); //查询 ProductLevelCourseTypeCourse var modelProductLevelCourseTypeCourse = edb.ProductLevelCourseTypeCourse.SingleOrDefault(p => p.Id == itemUnfinishedCoursesToInt); var plctc = edb.ProductLevelCourseTypeCourse.Single(p => p.Id == itemUnfinishedCoursesToInt); dtEndDate = dtDate.AddMinutes(plctc.Course.ClassTime); ProductLevelCourseTypeCourseName = plctc.Course.EName; if (plctc.Course.EName.Contains("LMW"))//不排LMW课程 continue; #region 教室 //获取符合条件的第一个教室 var strProductCourseTypeId = string.Format(",{0},", modelProductLevelCourseTypeCourse.ProductLevelCourseType.ProductCourseTypeId.ToString()); #region 教室注释 //匹配较大的教室 if (edbAcs.Classroom.Any(a => a.WorkDate == tempStudent.WorkDate && a.ClassroomTypeForProductCourseType.Contains(strProductCourseTypeId) && a.MaxBookNum > 1 && a.MaxBookNum >= studentListCount && a.BranchId == branchId && !a.UnavailableTime.Contains(itemAvailableTime))) { //获取教室 modelClassroom = edbAcs.Classroom.OrderBy(p => p.MaxBookNum) .ThenByDescending(p => p.ClassroomTypeForProductCourseType) .FirstOrDefault(a => a.WorkDate == tempStudent.WorkDate && a.ClassroomTypeForProductCourseType.Contains(strProductCourseTypeId) && a.MaxBookNum > 1 && a.MaxBookNum >= studentListCount && a.BranchId == branchId && !a.UnavailableTime.Contains(itemAvailableTime)); } else if (edbAcs.Classroom.Any(a => a.WorkDate == tempStudent.WorkDate && a.ClassroomTypeForProductCourseType.Contains(strProductCourseTypeId) && a.MaxBookNum > 1 && a.MaxBookNum <= studentListCount && a.BranchId == branchId && !a.UnavailableTime.Contains(itemAvailableTime)))//匹配较小的教室 { //获取教室 modelClassroom = edbAcs.Classroom.OrderByDescending(p => p.MaxBookNum) .ThenByDescending(p => p.ClassroomTypeForProductCourseType) .FirstOrDefault(a => a.WorkDate == tempStudent.WorkDate && a.ClassroomTypeForProductCourseType.Contains(strProductCourseTypeId) && a.MaxBookNum > 1 && a.BranchId == branchId && a.MaxBookNum <= studentListCount && !a.UnavailableTime.Contains(itemAvailableTime)); } else { tempStudent.Remark = "没有符合条件的教室!"; continue;//没有符合条件的教室,跳出,执行下一次循环 } #endregion // 验证教室是否同一时间段被占用 if (Eme.StudyBLL.IsExistClassroomForArrangeCourse(modelClassroom.Id, dtDate, dtEndDate)) { tempStudent.Remark = "没有符合条件的教室!"; continue; } #endregion #region 教师 //获取符合条件的第一个获取教师 var strTeachRange = string.Format(",{0}{1}", tempStudent.ProductLevelId, ','); //最后上课时间 var endAvailableTime = dtEndDate.AddHours(-1).ToString("yyyyMMddHHmm"); var selectTeacher = edbAcs.Teacher.Where(a => a.WorkDate == tempStudent.WorkDate && a.TeachRange.Contains(strTeachRange) && a.AvailableTime.Contains(itemAvailableTime) && a.AvailableTime.Contains(endAvailableTime) && a.AvailableTime != "" && a.BranchId == branchId && a.AvailableTime != null && a.MaxTaskNum > a.CurrTaskNum); //判断是否有教师 if (selectTeacher.Count() > 0) { //判断是否存在特殊配置要求该课节只能是外教或者中教上 if (edbAcs.TeacherProductLevelCourseTypeCourseConfig.Any(a => a.BranchId == branchId && a.ProductLevelCourseTypeCourseID == plctc.Id && a.Status == ConvertEnum.StatusTypeForActive)) { //获取特殊配置 var tplctcc = edbAcs.TeacherProductLevelCourseTypeCourseConfig.SingleOrDefault(p => p.BranchId == branchId && p.ProductLevelCourseTypeCourseID == plctc.Id && p.Status == ConvertEnum.StatusTypeForActive); //判断老师的类别跟特殊配置要求的列表是否是一致 if (!selectTeacher.Any(a => a.TeacherTypeId == tplctcc.TeacherType)) { //不符合,跳出 tempStudent.Remark = "没有符合条件的教师!"; continue; } else { //获取教师 modelTeacher = selectTeacher.OrderByDescending(p => p.IsFullTime) .OrderBy(p => p.CurrTaskNum) .FirstOrDefault(a => a.TeacherTypeId == tplctcc.TeacherType); } } else { //获取教师 modelTeacher = selectTeacher.OrderByDescending(p => p.IsFullTime) .OrderBy(p => p.CurrTaskNum).FirstOrDefault(); } } else { tempStudent.Remark = "没有符合条件的教师!"; continue;//没有符合条件的教师,跳出,执行下一次循环 } //验证教师是否已存在相同时间段日程 if (Eme.UserBLL.GetExistUserScheduleByTeacherId(modelTeacher.Id, dtDate, dtEndDate).Count() > 0) { tempStudent.Remark = "没有符合条件的教师!"; continue; } #endregion #region 进行匹配 学生,教师,教室 var theCount = studentListCount * 1.0f / modelClassroom.MaxBookNum; if (tempStudent.PlanNum.HasValue) planNum = tempStudent.PlanNum.Value; if (theCount >= float.Parse(countPercent[planNum]))//50% 或者是 25% 以上的学员符合的话,都排 { //创建 ArrangeCourse var modelArrangeCourse = new Model.Acs.ArrangeCourse() { BranchId = branchId, TeacherId = modelTeacher.TeacherId.Value, ArrangeCourseId = 0, ClassroomId = modelClassroom.ClassroomId, ProductLevelCourseTypeCourseId = Convert.ToInt32(itemUnfinishedCourses),//当前未上过的课程 BeginTime = dtDate, IsSuccessful = false, Status = ConvertEnum.StatusTypeForActive, IsSystem = true, CreateBy = createBy, ClassTime = (plctc.Course.ClassTime / 60), CreateTime = DateTime.Now }; #region 返回值拼接 outList.Add("StudentNames", tempStudent.StudentName);//学员名称 outList.Add("ProductLevelName", tempStudent.ProductLevelName);//级别名称 outList.Add("ClassroomName", modelClassroom.ClassroomName);//教室名称 outList.Add("ClassroomTypeName", modelClassroom.ClassroomTypeName);//教室类型 outList.Add("TeacherName", modelTeacher.TeacherName);//教师名称 outList.Add("TeacherTypeName", modelTeacher.TeacherTypeName);//教师类型 outList.Add("BeginDate", dtDate.ToString("yyyy/MM/dd HH:mm"));//上课时间 outList.Add("ProductLevelCourseTypeCourseName", ProductLevelCourseTypeCourseName);//课程名称 modelArrangeCourse.ProductLevelId = tempStudent.ProductLevelId;//学员级别 modelArrangeCourse.ProductLevelName = tempStudent.ProductLevelName;//级别名称 modelArrangeCourse.ClassroomName = modelClassroom.ClassroomName;//教室名称 modelArrangeCourse.ClassroomTypeId = modelClassroom.ClassroomTypeId; modelArrangeCourse.ClassroomTypeName = modelClassroom.ClassroomTypeName;//教室类型 modelArrangeCourse.TeacherName = modelTeacher.TeacherName;//教师名称 modelArrangeCourse.TeacherTypeId = modelTeacher.TeacherTypeId; modelArrangeCourse.TeacherTypeName = modelTeacher.TeacherTypeName;//教师类型 modelArrangeCourse.ProductLevelCourseTypeCourseName = ProductLevelCourseTypeCourseName;//课程名称 #endregion modelArrangeCourse.StudentIds = string.Format(",{0}", tempStudent.StudentId);//在原学员ID基础上拼接学员ID modelArrangeCourse.StudentNames = string.Format(",{0}", tempStudent.StudentName);//在原学员名称基础上拼接学员名称 //学员ID拼接 for (var num = 0; num < (modelClassroom.MaxBookNum - 1); num++) { if (num < (studentListCount - 1)) { modelArrangeCourse.StudentIds = string.Format("{0},{1}", modelArrangeCourse.StudentIds, studentList[num].StudentId); outList["StudentNames"] = string.Format("{0},{1}", outList["StudentNames"], studentList[num].StudentName); //学员名称返回值拼接 //学员名称 modelArrangeCourse.StudentNames = outList["StudentNames"]; } } //写入匹配好的ArrangeCourse edbAcs.Entry(modelArrangeCourse).State = EntityState.Added; edbAcs.Configuration.ValidateOnSaveEnabled = false; result = edbAcs.SaveChanges() > 0; edbAcs.Configuration.ValidateOnSaveEnabled = true; if (result) { //需要移除的课程 removeUnfinishedCourses = itemUnfinishedCourses; //把匹配的学生至为无效 for (var num = 0; num < (modelClassroom.MaxBookNum - 1); num++) { if (num < (studentListCount - 1)) { studentList[num].Status = ConvertEnum.StatusTypeForDelete; studentList[num].UnfinishedCourses = studentList[num].UnfinishedCourses.Replace("," + itemUnfinishedCourses + ",", ","); studentList[num].Remark = "匹配到合适的课程:" + itemUnfinishedCourses; studentList[num].UpdateBy = createBy; studentList[num].UpdateTime = DateTime.Now; studentList[num].CurrTaskNum = studentList[num].CurrTaskNum + 1;//增加课量 edbAcs.Entry(studentList[num]).State = EntityState.Modified; edbAcs.SaveChanges(); //移除上过的课程 var removeStudentId = studentList[num].StudentId; var removeStudentList = edbAcs.Student.Where(p => p.StudentId == removeStudentId && p.WorkDate >= beginDate && p.WorkDate <= endDate).ToList(); foreach (var itemRemoveStudent in removeStudentList) { itemRemoveStudent.UnfinishedCourses = itemRemoveStudent.UnfinishedCourses.Replace("," + itemUnfinishedCourses + ",", ","); itemRemoveStudent.UpdateBy = createBy; itemRemoveStudent.UpdateTime = DateTime.Now; itemRemoveStudent.CurrTaskNum = studentList[num].CurrTaskNum;//增加课量 edbAcs.Entry(itemRemoveStudent).State = EntityState.Modified; edbAcs.SaveChanges(); } } } #region 给教室加上不可用时间 TimeSpan dtTimeSpan = dtEndDate - dtDate; for (var dtNum = 0; dtNum < dtTimeSpan.Hours; dtNum++) { modelClassroom.UnavailableTime = string.Format("{0},{1}", modelClassroom.UnavailableTime, dtDate.AddHours(dtNum).ToString("yyyyMMddHHmm")); } modelClassroom.UpdateBy = createBy; modelClassroom.UpdateTime = DateTime.Now; edbAcs.Entry(modelClassroom).State = EntityState.Modified; edbAcs.SaveChanges(); #endregion #region 给老师加上任务量,还有把相应的可用时间移除 modelTeacher.CurrTaskNum = modelTeacher.CurrTaskNum + 1; for (var dtNum = 0; dtNum < dtTimeSpan.Hours; dtNum++) { modelTeacher.AvailableTime = modelTeacher.AvailableTime.Replace("," + dtDate.AddHours(dtNum).ToString("yyyyMMddHHmm"), ""); } modelTeacher.UpdateBy = createBy; modelTeacher.UpdateTime = DateTime.Now; edbAcs.Entry(modelTeacher).State = EntityState.Modified; edbAcs.SaveChanges(); #endregion break; } } else { tempStudent.Remark = "没有相同需求的学生!"; continue; } #endregion } } //把安排后的课程移除 if (removeUnfinishedCourses != "") { tempStudent.UnfinishedCourses = tempStudent.UnfinishedCourses.Replace("," + removeUnfinishedCourses, ""); tempStudent.CurrTaskNum = tempStudent.CurrTaskNum + 1;//增加课量 tempStudent.Remark = "匹配到合适的课程:" + removeUnfinishedCourses; } else { //绝对优先,一定要匹配课程 if (tempStudent.IsFirst) { return IsFirstDisposeArrangeCourse(branchId, beginDate, endDate, tempStudent, createBy, out outList); } } tempStudent.Status = ConvertEnum.StatusTypeForDelete; if (tempStudent.PlanNum.HasValue) { tempStudent.PlanNum = tempStudent.PlanNum + 1; } else { tempStudent.PlanNum = planNum + 1; } tempStudent.UpdateBy = createBy; tempStudent.UpdateTime = DateTime.Now; edbAcs.Entry(tempStudent).State = EntityState.Modified; result = edbAcs.SaveChanges() > 0; try { //移除上过的课程 if (removeUnfinishedCourses != "") { //移除上过的课程 var studentRemoveList = edbAcs.Student.Where(p => p.StudentId == tempStudent.StudentId && p.WorkDate >= beginDate && p.WorkDate <= endDate).ToList(); foreach (var itemStudentRemove in studentRemoveList) { itemStudentRemove.UnfinishedCourses = itemStudentRemove.UnfinishedCourses.Replace("," + removeUnfinishedCourses + ",", ","); itemStudentRemove.CurrTaskNum = tempStudent.CurrTaskNum;//增加课量 itemStudentRemove.UpdateBy = createBy; itemStudentRemove.UpdateTime = DateTime.Now; edbAcs.Entry(itemStudentRemove).State = EntityState.Modified; edbAcs.Configuration.ValidateOnSaveEnabled = false; edbAcs.SaveChanges(); edbAcs.Configuration.ValidateOnSaveEnabled = true; } } } catch { } return result; } catch (Exception e) { // 异常日志消息队列 Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs { ExceptionType = CommonHelper.To<int>(ExceptionType.Function), Message = string.Format("StudyBLL-DisposeArrangeCourse:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink), IsTreat = false, CreateTime = DateTime.Now }); return false; } }
/// <summary> /// 作者:Primo /// 日期:2014.12.26 /// 描述:调整课程时用的新增一个课程 /// </summary> /// <param name="branchId"></param> /// <param name="teacherId"></param> /// <param name="classroomId"></param> /// <param name="beginDate"></param> /// <param name="endDate"></param> /// <param name="produceLevelId"></param> /// <param name="produceLevelCourseTypeCourseId"></param> /// <param name="createBy"></param> /// <returns></returns> public static bool AddArrangeCourse(int branchId, int teacherId, int classroomId, DateTime beginDate, DateTime endDate, int produceLevelId, int productLevelCourseTypeId, int produceLevelCourseTypeCourseId, bool isOccupy, int createBy, out Model.Acs.ArrangeCourse outAC) { outAC = new ArrangeCourse();//初始化返回 try { var result = false; var edbAcs = new Model.Acs.EmeAcsEntities();//Acs库连接 //获取教师 var teacherObj = edbAcs.Teacher.FirstOrDefault(p => p.Id == teacherId);//获取教师 var classroomObj = edbAcs.Classroom.FirstOrDefault(p => p.Id == classroomId);//获取教室 var edbEme = new Model.Eme.EmeEntities();//Eme库连接 var productLevelObj = edbEme.ProductLevel.FirstOrDefault(p => p.Id == produceLevelId);//获取级别 var productLevelCourseTypeObj = edbEme.ProductLevelCourseType.FirstOrDefault(p => p.Id == productLevelCourseTypeId);//获取类型 var productLevelCourseTypeCourseObj = edbEme.ProductLevelCourseTypeCourse.FirstOrDefault(p => p.Id == produceLevelCourseTypeCourseId);//获取课程 #region 处理教师 TimeSpan dtTimeSpan = endDate - beginDate; for (var dtNum = 0; dtNum < dtTimeSpan.Hours; dtNum++) { teacherObj.AvailableTime = teacherObj.AvailableTime.Replace("," + beginDate.AddHours(dtNum).ToString("yyyyMMddHHmm"), ""); } teacherObj.CurrTaskNum = teacherObj.CurrTaskNum + 1; teacherObj.UpdateBy = createBy; teacherObj.UpdateTime = DateTime.Now; edbAcs.Entry(teacherObj).State = EntityState.Modified; #endregion #region 处理教室 if (classroomId != 0) { for (var dtNum = 0; dtNum < dtTimeSpan.Hours; dtNum++) { classroomObj.UnavailableTime = classroomObj.UnavailableTime + "," + beginDate.AddHours(dtNum).ToString("yyyyMMddHHmm"); } classroomObj.UpdateBy = createBy; classroomObj.UpdateTime = DateTime.Now; edbAcs.Entry(classroomObj).State = EntityState.Modified; } #endregion #region 生成排课 var modelArrangeCourse = new Model.Acs.ArrangeCourse() { BranchId = branchId, TeacherId = teacherObj.TeacherId.Value, ClassroomId = (classroomObj == null || classroomObj.ClassroomId <= 0) ? -1 : classroomObj.ClassroomId, ProductLevelCourseTypeCourseId = produceLevelCourseTypeCourseId,//当前未上过的课程 BeginTime = beginDate, IsSuccessful = false, IsSystem = false, Status = ConvertEnum.StatusTypeForActive, CreateBy = createBy, ClassTime = (productLevelCourseTypeCourseObj.Course.ClassTime / 60), CreateTime = DateTime.Now }; modelArrangeCourse.ProductLevelId = productLevelObj.Id;//学员级别 modelArrangeCourse.ProductLevelName = productLevelObj.EName;//级别名称 if (modelArrangeCourse.ClassroomId > 0) { modelArrangeCourse.ClassroomName = classroomObj.ClassroomName;//教室名称 modelArrangeCourse.ClassroomTypeId = classroomObj.ClassroomTypeId; modelArrangeCourse.ClassroomTypeName = classroomObj.ClassroomTypeName;//教室类型 } else { modelArrangeCourse.ClassroomName = "网课教室";//教室名称 } modelArrangeCourse.TeacherName = teacherObj.TeacherName;//教师名称 modelArrangeCourse.TeacherTypeId = teacherObj.TeacherTypeId; modelArrangeCourse.TeacherTypeName = teacherObj.TeacherTypeName;//教师类型 modelArrangeCourse.ProductLevelCourseTypeId = productLevelCourseTypeObj.Id;//类型ID modelArrangeCourse.ProductLevelCourseTypeName = "";//类型名称 modelArrangeCourse.ProductLevelCourseTypeCourseName = productLevelCourseTypeCourseObj.Course.EName;//课程名称 modelArrangeCourse.IsSystem = false; #endregion //写入匹配好的ArrangeCourse edbAcs.Entry(modelArrangeCourse).State = EntityState.Added; edbAcs.Configuration.ValidateOnSaveEnabled = false; result = edbAcs.SaveChanges() > 0; edbAcs.Configuration.ValidateOnSaveEnabled = true; outAC = modelArrangeCourse; return result; } catch (Exception e) { // 异常日志消息队列 Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs { ExceptionType = CommonHelper.To<int>(ExceptionType.Function), Message = string.Format("StudyBLL-AddArrangeCourse:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink), IsTreat = false, CreateTime = DateTime.Now }); return false; } }
/// <summary> /// 作者:Primo /// 日期:2015.01.20 /// 描述:匹配至 ArrangeCourse /// </summary> /// <param name="branchId"></param> /// <param name="beginDate"></param> /// <param name="endDate"></param> /// <param name="createBy"></param> /// <returns></returns> public static bool DisposeArrangeCourse(int branchId, DateTime beginDate, DateTime endDate, int createBy, out Dictionary<string, string> outList) { var result = false;//初始化状态 var removeUnfinishedCourses = "";//匹配成功后需要移除的课程 var removeAvailableTime = "";//匹配成功后需要移除的时间 var ProductLevelCourseTypeCourseName = "";//课程名称 outList = new Dictionary<string, string>(); var edbAcs = new Model.Acs.EmeAcsEntities(); var countPercent = Common.Global.CountPercent.ToString().Split(','); //匹配次数,必须要有一个float值 var maxPlanNum = countPercent.Count();//最大的匹配次数 var planNum = 0;//记录当前的匹配次数 //获取第一个符合条件的学员,主要循环的学员 var tempStudent = edbAcs.Student.OrderBy(p => p.WorkDate) .ThenByDescending(p => p.IsFirst) .ThenBy(p => p.ArrangeCourseOrder) .FirstOrDefault(p => p.BranchId == branchId //所属中心 && p.WorkDate >= beginDate //在匹配的范围内 && p.WorkDate <= endDate //在匹配的范围内 && p.CurrTaskNum < Common.Global.MaxNum //小于最大匹配数 && p.Status == ConvertEnum.StatusTypeForActive); //是有效的数据 try { if (tempStudent == null)//表示已经循环所有学员了 { return BranchBLL.UpateStudentByPlanNum(maxPlanNum, branchId, beginDate, endDate, createBy); } //学生可用时间数组 var availableTimeList = tempStudent.AvailableTime.Trim(',').Split(',').ToList(); #region 循环学生的可用时间 //循环学生可用时间 foreach (var itemAvailableTime in availableTimeList) { if (result)//result 为 true ,说明已经找到了适合的 break; if (itemAvailableTime == string.Empty)//如果时间是空的,则跳过继续执行下一个 continue; outList = new Dictionary<string, string>();//声明一个字符词典,用来输出学生 //获取同一类的学生 var studentLikeList = (from a in edbAcs.Student where a.BranchId == tempStudent.BranchId && a.StudentId != tempStudent.StudentId && a.ProductLevelId == tempStudent.ProductLevelId && a.WorkDate == tempStudent.WorkDate && a.CurrTaskNum < Common.Global.MaxNum && a.Status == ConvertEnum.StatusTypeForActive && a.AvailableTime.Contains(itemAvailableTime) == true select a).OrderByDescending(p => p.IsFirst).ThenBy(p => p.ArrangeCourseOrder); var unfinishedCoursesList = new List<string>(); var unfinishedCoursesList2 = new List<string>(); var unfinishedCoursesStr = tempStudent.UnfinishedCourses.Trim(','); //把这些学生所有的未上过的课程都合并起来 foreach (var studentLike in studentLikeList) { unfinishedCoursesStr = unfinishedCoursesStr.Trim(',') + "," + studentLike.UnfinishedCourses.Trim(','); } //把这些学生所有的未上过的课程合并之后,转换成数组 unfinishedCoursesList = unfinishedCoursesStr.Trim(',').Split(',').ToList(); unfinishedCoursesList2 = tempStudent.UnfinishedCourses.Trim(',').Split(',').ToList(); //把数组中的重复元素合并,且统计 var modelUnfinishedCourses = (from a in unfinishedCoursesList group a by a into g select new { g.Key, NumCount = g.Count() }).OrderByDescending(a => a.NumCount).ToList(); var modelUnfinishedCourses2 = (from a in unfinishedCoursesList2 group a by a into g select new { g.Key, NumCount = g.Count() }).OrderByDescending(a => a.NumCount).ToList(); modelUnfinishedCourses = (from a in modelUnfinishedCourses2 join b in modelUnfinishedCourses on a.Key equals b.Key select new { a.Key, b.NumCount }).OrderBy(a => a.NumCount).ToList(); //教室 var modelClassroom = new Model.Acs.Classroom(); //教师 var modelTeacher = new Model.Acs.Teacher(); //上课时间拼接 var dtDate = Convert.ToDateTime(string.Format("{0}/{1}/{2} {3}:{4}" , itemAvailableTime.Substring(0, 4) , itemAvailableTime.Substring(4, 2) , itemAvailableTime.Substring(6, 2) , itemAvailableTime.Substring(8, 2) , itemAvailableTime.Substring(10, 2))); // 课程结束时间 var dtEndDate = dtDate; var edb = new Model.Eme.EmeEntities(); //Int类型的未上过课程ID var unfinishedCoursesToInt = 0; //String类型的未上过课程ID var unfinishedCoursesToString = ""; //循环未上过的课程 foreach (var itemUnfinishedCourses in modelUnfinishedCourses) { //如果为空,则跳出执行下一个 if (itemUnfinishedCourses.Key == "") continue; unfinishedCoursesToInt = Convert.ToInt32(itemUnfinishedCourses.Key); unfinishedCoursesToString = string.Format(",{0},", itemUnfinishedCourses.Key); //获取课节 var plctc = edb.ProductLevelCourseTypeCourse.SingleOrDefault(p => p.Id == unfinishedCoursesToInt); dtEndDate = dtDate.AddMinutes(plctc.Course.ClassTime); ProductLevelCourseTypeCourseName = plctc.Course.EName; //不排LMW课程 if (plctc.Course.EName.Contains("LMW")) { tempStudent.Remark = "不排LMW课程!"; continue; } #region 教师 //获取符合条件的第一个获取教师 var strTeachRange = string.Format(",{0}{1}", tempStudent.ProductLevelId, ','); //最后上课时间 var endAvailableTime = dtEndDate.AddHours(-1).ToString("yyyyMMddHHmm"); var selectTeacher = edbAcs.Teacher.Where(a => a.WorkDate == tempStudent.WorkDate && a.TeachRange.Contains(strTeachRange) && a.AvailableTime.Contains(itemAvailableTime) && a.AvailableTime.Contains(endAvailableTime) && a.AvailableTime != "" && a.BranchId == branchId && a.AvailableTime != null && a.MaxTaskNum > a.CurrTaskNum); //判断是否有教师 if (selectTeacher.Count() > 0) { //判断是否存在特殊配置要求该课节只能是外教或者中教上 if (edbAcs.TeacherProductLevelCourseTypeCourseConfig.Any(a => a.BranchId == branchId && a.ProductLevelCourseTypeCourseID == plctc.Id && a.Status == ConvertEnum.StatusTypeForActive)) { //获取特殊配置 var tplctcc = edbAcs.TeacherProductLevelCourseTypeCourseConfig.SingleOrDefault(p => p.BranchId == branchId && p.ProductLevelCourseTypeCourseID == plctc.Id && p.Status == ConvertEnum.StatusTypeForActive); //判断老师的类别跟特殊配置要求的列表是否是一致 if (!selectTeacher.Any(a => a.TeacherTypeId == tplctcc.TeacherType)) { //不符合,跳出 tempStudent.Remark = "没有符合条件的教师!"; continue; } else { //获取教师 modelTeacher = selectTeacher.OrderByDescending(p => p.IsFullTime) .OrderBy(p => p.CurrTaskNum) .FirstOrDefault(a => a.TeacherTypeId == tplctcc.TeacherType); } } else { //获取教师 modelTeacher = selectTeacher.OrderByDescending(p => p.IsFullTime) .OrderBy(p => p.CurrTaskNum).FirstOrDefault(); } } else { tempStudent.Remark = "没有符合条件的教师!"; continue;//没有符合条件的教师,跳出,执行下一次循环 } //验证教师是否已存在相同时间段日程 if (modelTeacher != null) { if (Eme.UserBLL.GetExistUserScheduleByTeacherId(modelTeacher.Id, dtDate, dtEndDate).Count() > 0) { tempStudent.Remark = "没有符合条件的教师!"; continue; } } else { tempStudent.Remark = "没有符合条件的教师!"; continue; } #endregion #region 教室 //获取符合条件的第一个教室 var strProductCourseTypeId = string.Format(",{0},", plctc.ProductLevelCourseType.ProductCourseTypeId.ToString()); //匹配较大的教室 if (edbAcs.Classroom.Any(a => a.WorkDate == tempStudent.WorkDate && a.ClassroomTypeForProductCourseType.Contains(strProductCourseTypeId) && a.MaxBookNum > 1 && a.MaxBookNum >= itemUnfinishedCourses.NumCount && a.BranchId == branchId && !a.UnavailableTime.Contains(itemAvailableTime))) { //获取教室 modelClassroom = edbAcs.Classroom.OrderBy(p => p.MaxBookNum) .ThenByDescending(p => p.ClassroomTypeForProductCourseType) .FirstOrDefault(a => a.WorkDate == tempStudent.WorkDate && a.ClassroomTypeForProductCourseType.Contains(strProductCourseTypeId) && a.MaxBookNum > 1 && a.MaxBookNum >= itemUnfinishedCourses.NumCount && a.BranchId == branchId && !a.UnavailableTime.Contains(itemAvailableTime)); } else if (edbAcs.Classroom.Any(a => a.WorkDate == tempStudent.WorkDate && a.ClassroomTypeForProductCourseType.Contains(strProductCourseTypeId) && a.MaxBookNum > 1 && a.MaxBookNum <= itemUnfinishedCourses.NumCount && a.BranchId == branchId && !a.UnavailableTime.Contains(itemAvailableTime)))//匹配较小的教室 { //获取教室 modelClassroom = edbAcs.Classroom.OrderByDescending(p => p.MaxBookNum) .ThenByDescending(p => p.ClassroomTypeForProductCourseType) .FirstOrDefault(a => a.WorkDate == tempStudent.WorkDate && a.ClassroomTypeForProductCourseType.Contains(strProductCourseTypeId) && a.MaxBookNum > 1 && a.BranchId == branchId && a.MaxBookNum <= itemUnfinishedCourses.NumCount && !a.UnavailableTime.Contains(itemAvailableTime)); } else { tempStudent.Remark = "没有符合条件的教室!"; continue;//没有符合条件的教室,跳出,执行下一次循环 } // 验证教室是否同一时间段被占用 if (Eme.StudyBLL.IsExistClassroomForArrangeCourse(modelClassroom.Id, dtDate, dtEndDate)) { tempStudent.Remark = "没有符合条件的教室!"; continue; } #endregion var theCount = itemUnfinishedCourses.NumCount * 1.0f / modelClassroom.MaxBookNum; if (tempStudent.PlanNum.HasValue) planNum = tempStudent.PlanNum.Value; //50% 或者是 25% 以上的学员符合的话,都排 if (theCount < float.Parse(countPercent[planNum])) { tempStudent.Remark = "没有相同需求的学生!"; continue; } #region 进行匹配 学生,教师,教室 //50% 或者是 25% 以上的学员符合的话,都排 if (theCount >= float.Parse(countPercent[planNum])) { //创建 ArrangeCourse var modelArrangeCourse = new Model.Acs.ArrangeCourse() { BranchId = branchId, TeacherId = modelTeacher.TeacherId.Value, ArrangeCourseId = 0, ClassroomId = modelClassroom.ClassroomId, ProductLevelCourseTypeCourseId = unfinishedCoursesToInt,//当前未上过的课程 BeginTime = dtDate, IsSuccessful = false, Status = ConvertEnum.StatusTypeForActive, IsSystem = true, CreateBy = createBy, ClassTime = (plctc.Course.ClassTime / 60), CreateTime = DateTime.Now }; #region 返回值拼接 outList.Add("StudentNames", tempStudent.StudentName);//学员名称 outList.Add("ProductLevelName", tempStudent.ProductLevelName);//级别名称 outList.Add("ClassroomName", modelClassroom.ClassroomName);//教室名称 outList.Add("ClassroomTypeName", modelClassroom.ClassroomTypeName);//教室类型 outList.Add("TeacherName", modelTeacher.TeacherName);//教师名称 outList.Add("TeacherTypeName", modelTeacher.TeacherTypeName);//教师类型 outList.Add("BeginDate", dtDate.ToString("yyyy/MM/dd HH:mm"));//上课时间 outList.Add("ProductLevelCourseTypeCourseName", ProductLevelCourseTypeCourseName);//课程名称 modelArrangeCourse.ProductLevelId = tempStudent.ProductLevelId;//学员级别 modelArrangeCourse.ProductLevelName = tempStudent.ProductLevelName;//级别名称 modelArrangeCourse.ClassroomName = modelClassroom.ClassroomName;//教室名称 modelArrangeCourse.ClassroomTypeId = modelClassroom.ClassroomTypeId; modelArrangeCourse.ClassroomTypeName = modelClassroom.ClassroomTypeName;//教室类型 modelArrangeCourse.TeacherName = modelTeacher.TeacherName;//教师名称 modelArrangeCourse.TeacherTypeId = modelTeacher.TeacherTypeId; modelArrangeCourse.TeacherTypeName = modelTeacher.TeacherTypeName;//教师类型 modelArrangeCourse.ProductLevelCourseTypeCourseName = ProductLevelCourseTypeCourseName;//课程名称 modelArrangeCourse.ProductLevelCourseTypeId = plctc.ProductLevelCourseTypeId;//类型ID modelArrangeCourse.ProductLevelCourseTypeName = "";//类型名称 #endregion modelArrangeCourse.StudentIds = string.Format(",{0}", tempStudent.StudentId);//在原学员ID基础上拼接学员ID modelArrangeCourse.StudentNames = string.Format(",{0}", tempStudent.StudentName);//在原学员名称基础上拼接学员名称 /////获取时间和未上课程都符合的学生 var studentList = studentLikeList.Where(a => a.AvailableTime.Contains(itemAvailableTime) && a.UnfinishedCourses.Contains(unfinishedCoursesToString)) .OrderBy(p => p.WorkDate).ThenByDescending(p => p.IsFirst).ThenBy(p => p.ArrangeCourseOrder).ToList(); //学员ID拼接 for (var num = 0; num < (modelClassroom.MaxBookNum - 1); num++) { if (num < (itemUnfinishedCourses.NumCount - 1)) { modelArrangeCourse.StudentIds = string.Format("{0},{1}", modelArrangeCourse.StudentIds, studentList[num].StudentId); outList["StudentNames"] = string.Format("{0},{1}", outList["StudentNames"], studentList[num].StudentName); //学员名称返回值拼接 //学员名称 modelArrangeCourse.StudentNames = outList["StudentNames"]; } } //写入匹配好的ArrangeCourse edbAcs.Entry(modelArrangeCourse).State = EntityState.Added; edbAcs.Configuration.ValidateOnSaveEnabled = false; result = edbAcs.SaveChanges() > 0; edbAcs.Configuration.ValidateOnSaveEnabled = true; if (result) //需要移除的课程 { removeUnfinishedCourses = unfinishedCoursesToString; removeAvailableTime = itemAvailableTime; //把匹配的学生至为无效 for (var num = 0; num < (modelClassroom.MaxBookNum - 1); num++) { if (num < (itemUnfinishedCourses.NumCount - 1)) { studentList[num].Status = ConvertEnum.StatusTypeForDelete; studentList[num].UnfinishedCourses = studentList[num].UnfinishedCourses.Replace(unfinishedCoursesToString, ","); studentList[num].AvailableTime = studentList[num].AvailableTime.Replace("," + itemAvailableTime, ","); studentList[num].Remark = "匹配到合适的课程:" + unfinishedCoursesToString; studentList[num].UpdateBy = createBy; studentList[num].UpdateTime = DateTime.Now; if (studentList[num].PlanNum.HasValue) studentList[num].PlanNum = studentList[num].PlanNum + 1; else studentList[num].PlanNum = 1; studentList[num].CurrTaskNum = studentList[num].CurrTaskNum + 1;//增加课量 edbAcs.Entry(studentList[num]).State = EntityState.Modified; edbAcs.SaveChanges(); //移除上过的课程 var removeStudentId = studentList[num].StudentId; var removeStudentList = edbAcs.Student.Where(p => p.StudentId == removeStudentId && p.WorkDate >= beginDate && p.WorkDate <= endDate).ToList(); foreach (var itemRemoveStudent in removeStudentList) { itemRemoveStudent.UnfinishedCourses = itemRemoveStudent.UnfinishedCourses.Replace(unfinishedCoursesToString, ","); itemRemoveStudent.AvailableTime = itemRemoveStudent.AvailableTime.Replace("," + itemAvailableTime, ","); itemRemoveStudent.UpdateBy = createBy; itemRemoveStudent.UpdateTime = DateTime.Now; itemRemoveStudent.CurrTaskNum = studentList[num].CurrTaskNum;//增加课量 edbAcs.Entry(itemRemoveStudent).State = EntityState.Modified; } edbAcs.SaveChanges(); } } #region 给教室加上不可用时间 TimeSpan dtTimeSpan = dtEndDate - dtDate; for (var dtNum = 0; dtNum < dtTimeSpan.Hours; dtNum++) { modelClassroom.UnavailableTime = string.Format("{0},{1}", modelClassroom.UnavailableTime, dtDate.AddHours(dtNum).ToString("yyyyMMddHHmm")); } modelClassroom.UpdateBy = createBy; modelClassroom.UpdateTime = DateTime.Now; edbAcs.Entry(modelClassroom).State = EntityState.Modified; edbAcs.SaveChanges(); #endregion #region 给老师加上任务量,还有把相应的可用时间移除 modelTeacher.CurrTaskNum = modelTeacher.CurrTaskNum + 1; for (var dtNum = 0; dtNum < dtTimeSpan.Hours; dtNum++) { modelTeacher.AvailableTime = modelTeacher.AvailableTime.Replace("," + dtDate.AddHours(dtNum).ToString("yyyyMMddHHmm"), ""); } modelTeacher.UpdateBy = createBy; modelTeacher.UpdateTime = DateTime.Now; edbAcs.Entry(modelTeacher).State = EntityState.Modified; edbAcs.SaveChanges(); #endregion break; } } else { tempStudent.Remark = "没有相同需求的学生!"; continue; } #endregion } } #endregion //需要把安排后的课程移除 if (removeUnfinishedCourses != "") { tempStudent.UnfinishedCourses = tempStudent.UnfinishedCourses.Replace(removeUnfinishedCourses, ","); tempStudent.AvailableTime = tempStudent.AvailableTime.Replace("," + removeAvailableTime, ","); tempStudent.CurrTaskNum = tempStudent.CurrTaskNum + 1;//增加课量 tempStudent.Remark = "匹配到合适的课程:" + removeUnfinishedCourses; } else { //绝对优先,一定要匹配课程 if (tempStudent.IsFirst) { return IsFirstDisposeArrangeCourse(branchId, beginDate, endDate, tempStudent, createBy, out outList); } } tempStudent.Status = ConvertEnum.StatusTypeForDelete; if (tempStudent.PlanNum.HasValue) { tempStudent.PlanNum = tempStudent.PlanNum.Value + 1; } else { tempStudent.PlanNum = 1; } tempStudent.UpdateBy = createBy; tempStudent.UpdateTime = DateTime.Now; edbAcs.Entry(tempStudent).State = EntityState.Modified; result = edbAcs.SaveChanges() > 0; try { //移除上过的课程 if (removeUnfinishedCourses != "") { //移除上过的课程 var studentRemoveList = edbAcs.Student.Where(p => p.StudentId == tempStudent.StudentId && p.WorkDate >= beginDate && p.WorkDate <= endDate).ToList(); foreach (var itemStudentRemove in studentRemoveList) { itemStudentRemove.UnfinishedCourses = itemStudentRemove.UnfinishedCourses.Replace(removeUnfinishedCourses, ","); itemStudentRemove.AvailableTime = itemStudentRemove.AvailableTime.Replace("," + removeAvailableTime, ","); itemStudentRemove.CurrTaskNum = tempStudent.CurrTaskNum;//增加课量 itemStudentRemove.UpdateBy = createBy; itemStudentRemove.UpdateTime = DateTime.Now; edbAcs.Entry(itemStudentRemove).State = EntityState.Modified; edbAcs.Configuration.ValidateOnSaveEnabled = false; edbAcs.SaveChanges(); edbAcs.Configuration.ValidateOnSaveEnabled = true; } } } catch (Exception ex) { var edbAcsCopy = new Model.Acs.EmeAcsEntities(); tempStudent = edbAcsCopy.Student.First(p => p.Id == tempStudent.Id); if (tempStudent.PlanNum.HasValue) { tempStudent.PlanNum = tempStudent.PlanNum.Value + 1; } else { tempStudent.PlanNum = 1; } tempStudent.Status = ConvertEnum.StatusTypeForDelete; tempStudent.Remark = ex.ToString(); edbAcsCopy.Entry(tempStudent).State = EntityState.Modified; edbAcsCopy.Configuration.ValidateOnSaveEnabled = false; edbAcsCopy.SaveChanges(); edbAcsCopy.Configuration.ValidateOnSaveEnabled = true; return true;//继续执行下一个学生 } return result; } catch (Exception e) { var edbAcsCopy = new Model.Acs.EmeAcsEntities(); tempStudent = edbAcsCopy.Student.First(p => p.Id == tempStudent.Id); if (tempStudent.PlanNum.HasValue) { tempStudent.PlanNum = tempStudent.PlanNum.Value + 1; } else { tempStudent.PlanNum = 1; } tempStudent.Status = ConvertEnum.StatusTypeForDelete; tempStudent.Remark = e.ToString(); edbAcsCopy.Entry(tempStudent).State = EntityState.Modified; edbAcsCopy.Configuration.ValidateOnSaveEnabled = false; edbAcsCopy.SaveChanges(); edbAcsCopy.Configuration.ValidateOnSaveEnabled = true; //// 异常日志消息队列 //Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs //{ // ExceptionType = CommonHelper.To<int>(ExceptionType.Function), // Message = string.Format("StudyBLL-DisposeArrangeCourse:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink), // IsTreat = false, // CreateTime = DateTime.Now //}); return true;//继续执行下一个学生 } }
/// <summary> /// beta /// 2015.08.20 /// 智能网课匹配课程 /// </summary> /// <param name="branchId"></param> /// <param name="beginDate"></param> /// <param name="endDate"></param> /// <param name="createBy"></param> /// <param name="outList"></param> /// <returns></returns> public static bool DisposeOnlineArrangeCourse(int branchId, DateTime beginDate, DateTime endDate, int createBy, int OnlineMaxNumOneDay, int OneDayTeacherMaxBookNum, out Dictionary<string, string> outList) { var result = false;//初始化状态 var ProductLevelCourseTypeCourseName = "";//课程名称 outList = new Dictionary<string, string>(); var teacherTaksList = new List<Model.Acs.ArrangeCourse>(); teacherTaksList.AddRange(StudyBLL.GetArrangeCourse(branchId, beginDate, endDate)); var arrangecourseInfo = StudyBLL.GetEMEArrangeCourse(branchId, beginDate, endDate); var edbAcs = new Model.Acs.EmeAcsEntities(); var MaxBookNum = OnlineMaxNumOneDay; var oneDayTeacherMaxBookNum = OneDayTeacherMaxBookNum; var edb = new Model.Eme.EmeEntities(); try { //教师 var modelTeacher = new Model.Acs.Teacher(); var teacherList = edbAcs.Teacher.Where( p => p.BranchId == branchId && p.WorkDate >= beginDate && p.WorkDate <= endDate && p.IsFullTime == false && p.AvailableTime != null && p.AvailableTime != "" && p.Status == ConvertEnum.StatusTypeForActive); //循环教师、时间、课节 foreach (var tlist in teacherList) { modelTeacher = teacherList.FirstOrDefault(a => a.TeacherId == tlist.TeacherId); var itemAvailableTime = tlist.AvailableTime.Trim(',').Split(',').ToList(); var productlevelList = tlist.TeachRange.Trim(',').Split(',').ToList(); if (itemAvailableTime == null || itemAvailableTime.Count <= 0 || productlevelList == null || productlevelList.Count <= 0 || itemAvailableTime[0] =="" || productlevelList[0] == "") { continue; } var teacherMaxTaskNum = edb.Teacher.FirstOrDefault(p => p.Status == 101 && p.Id == tlist.TeacherId); if (teacherMaxTaskNum.MaxTaskNum <= 0) { continue; } foreach (var teacherTimes in itemAvailableTime) { //随机获取课程级别 Random rnd = new Random(); int index = rnd.Next(0, productlevelList.Count); var plid = Int32.Parse(productlevelList[index]); Random rtime = new Random(); int itime = rtime.Next(0, itemAvailableTime.Count); var dtTime = itemAvailableTime[itime]; //上课时间拼接 var dtDate = Convert.ToDateTime(string.Format("{0}/{1}/{2} {3}:{4}" , dtTime.Substring(0, 4) , dtTime.Substring(4, 2) , dtTime.Substring(6, 2) , dtTime.Substring(8, 2) , dtTime.Substring(10, 2))); // 课程结束时间 var dtEndDate = dtDate; //获取课节 var pc = edb.TeachCourseRange.Where(p => p.ProductLevelId == plid && p.TeacherId == tlist.TeacherId && p.Status == 101); if (pc == null || pc.Count() <= 0) { break; } //随机获取 Random rndPltc = new Random(); var rndPltcIndex = rndPltc.Next(0, pc.Count()); var rndPltcValue = pc.Select(p => p.ProductLevelCourseTypeCourseId).ToList()[rndPltcIndex]; var plctc = edb.ProductLevelCourseTypeCourse.FirstOrDefault(p => p.Id == rndPltcValue); dtEndDate = dtDate.AddMinutes(plctc.Course.ClassTime); ProductLevelCourseTypeCourseName = plctc.Course.EName; //不排LMW课程 if (plctc.Course.EName.Contains("LMW")) { continue; } //不排重复时间段的老师课程 if (teacherTaksList.Any(p => p.BranchId == branchId && p.TeacherId == tlist.TeacherId && dtDate == p.BeginTime && p.Status == 101)) { break; } if (edbAcs.ArrangeCourse.Any(p => p.BranchId == branchId && p.TeacherId == tlist.TeacherId && dtDate == p.BeginTime && p.Status == 101)) { break; } var emeCount = 0; var emeOneDaybook = 0; var emeOneDaybookForTeacher = 0; var endtimes = dtDate.Date.AddDays(1); var begintimes = dtDate.Date; //判断正式线上这个时间段的老师课量 if (arrangecourseInfo != null) { emeCount = arrangecourseInfo.Where(p => p.BranchId == branchId && p.TeachRecord.Any(t => t.TeacherId == tlist.TeacherId && t.Status == ConvertEnum.StatusTypeForActive) && p.Status == 101 && p.BeginTime >= beginDate && p.BeginTime <= endDate).Count(); emeOneDaybook = arrangecourseInfo.Where(p => p.Status == 101 && p.BeginTime > begintimes && p.BeginTime < endtimes).ToList().Count(); emeOneDaybookForTeacher = arrangecourseInfo.Where(p => p.Status == 101 && p.BeginTime > begintimes && p.BeginTime < endtimes && p.TeachRecord.Any(t => t.TeacherId == tlist.TeacherId && t.Status == ConvertEnum.StatusTypeForActive)).ToList().Count(); } //达到最大任务量的不再安排课程 var acsCount = teacherTaksList.Where(p => p.BranchId == branchId && p.TeacherId == tlist.TeacherId && p.Status == 101 && p.BeginTime >= beginDate && p.BeginTime <= endDate).Count() + 1; if (teacherMaxTaskNum != null && teacherMaxTaskNum.MaxTaskNum != null && (acsCount + emeCount) >= teacherMaxTaskNum.MaxTaskNum) { break; } //当天教师总排课数量不能超过设置里面的平均总课时数值 var oneDaybook = teacherTaksList.Where(p => p.Status == 101 && p.BeginTime > begintimes && p.BeginTime < endtimes).ToList().Count(); if ((oneDaybook + emeOneDaybook) >= MaxBookNum) { break; } //当天每个教师当前上课量不超过配置的数值 var oneDaybookForTeacher = teacherTaksList.Where(p => p.Status == 101 && p.BeginTime > begintimes && p.BeginTime < endtimes && p.TeacherId == tlist.TeacherId).ToList().Count(); if ((oneDaybookForTeacher + emeOneDaybookForTeacher) >= oneDayTeacherMaxBookNum) { break; } #region 进行教师、课程的匹配 //创建 ArrangeCourse var modelArrangeCourse = new Model.Acs.ArrangeCourse() { BranchId = branchId, TeacherId = tlist.TeacherId.Value, ArrangeCourseId = 0, ProductLevelId = plid, ProductLevelName = plctc.ProductLevelCourseType.ProductLevel.EName, ProductLevelCourseTypeCourseId = plctc.Id, BeginTime = dtDate, IsSuccessful = false, Status = ConvertEnum.StatusTypeForActive, IsSystem = true, CreateBy = createBy, ClassTime = (plctc.Course.ClassTime / 60), CreateTime = DateTime.Now }; #region 返回值拼接 //outList2.Add(tlist.TeacherId.ToString() +","+ dtDate.ToString()); //outList.Add("StudentNames", "");//学员名称 //outList.Add("ProductLevelName", plctc.ProductLevelCourseType.ProductLevel.EName);//级别名称 //outList.Add("ClassroomName", "网络教室");//教室名称 //outList.Add("ClassroomTypeName", "网络课");//教室类型 //outList.Add("TeacherName", tlist.TeacherName);//教师名称 //outList.Add("TeacherTypeName", tlist.TeacherTypeName);//教师类型 //outList.Add("BeginDate", dtDate.ToString("yyyy/MM/dd HH:mm"));//上课时间 //outList.Add("ProductLevelCourseTypeCourseName", ProductLevelCourseTypeCourseName);//课程名称 modelArrangeCourse.ClassroomName = "网络教室";//教室名称 modelArrangeCourse.ClassroomTypeId = 0; modelArrangeCourse.ClassroomTypeName = "网络课";//教室类型 modelArrangeCourse.TeacherName = tlist.TeacherName;//教师名称 modelArrangeCourse.TeacherTypeId = tlist.TeacherTypeId; modelArrangeCourse.TeacherTypeName = tlist.TeacherTypeName;//教师类型 modelArrangeCourse.ProductLevelCourseTypeCourseName = ProductLevelCourseTypeCourseName;//课程名称 modelArrangeCourse.ProductLevelCourseTypeId = plctc.ProductLevelCourseTypeId;//类型ID modelArrangeCourse.ProductLevelCourseTypeName = "";//类型名称 #endregion teacherTaksList.Add(modelArrangeCourse); //写入匹配好的ArrangeCourse edbAcs.Configuration.ValidateOnSaveEnabled = false; edbAcs.Configuration.ValidateOnSaveEnabled = true; #region 给老师加上任务量,还有把相应的可用时间移除 modelTeacher.CurrTaskNum = modelTeacher.CurrTaskNum + 1; TimeSpan dtTimeSpan = dtEndDate - dtDate; for (var dtNum = 0; dtNum < dtTimeSpan.Hours; dtNum++) { modelTeacher.AvailableTime = modelTeacher.AvailableTime.Replace("," + dtDate.AddHours(dtNum).ToString("yyyyMMddHHmm"), ""); } modelTeacher.UpdateBy = createBy; modelTeacher.UpdateTime = DateTime.Now; edbAcs.Entry(modelTeacher).State = EntityState.Modified; #endregion break; } } //需要写入库的 var items = teacherTaksList.Where(p => p.Id <= 0); foreach (var item in items) { edbAcs.Entry(item).State = EntityState.Added; } result = edbAcs.SaveChanges() > 0; #endregion } catch (Exception e) { return false; } return result; }
/// <summary> /// 作者:beta /// 日期:2015.09.13 /// 描述:获取ArrangeCourse /// </summary> /// <param name="branchId"></param> /// <param name="beginDate"></param> /// <param name="endDate"></param> /// <param name="isSuccessful"></param> /// <returns></returns> public static List<Model.Eme.ArrangeCourse> GetEMEArrangeCourse(int branchId, DateTime beginDate, DateTime endDate) { var edb = new Model.Eme.EmeEntities(); var model = (from a in edb.ArrangeCourse where a.BranchId == branchId && a.BeginTime > beginDate && a.BeginTime < endDate select a).OrderBy(p => p.BeginTime).ToList(); return model; }
/// <summary> /// 作者:Primo /// 日期:2014.08.04 /// 描述:创建教师 /// </summary> /// <param name="branchId"></param> /// <param name="beginDate"></param> /// <param name="endDate"></param> /// <param name="createBy"></param> /// <param name="result"></param> /// <returns></returns> public static List<Model.Acs.Teacher> CreateTeacherByBranchId(int branchId, DateTime beginDate, DateTime endDate, int createBy, out bool result) { //初始化 result = false; try { var teacherList = new List<Model.Acs.Teacher>(); //连接实体 var edb = new Model.Eme.EmeEntities(); //连接实体 var edbAcs = new Model.Acs.EmeAcsEntities(); var dateNum = endDate - beginDate; for (var i = 0; i <= dateNum.Days; i++) { //在职的全职老师,且SA除外 var modelTeacherIsFullTime = (from a in edb.Teacher where a.TeacherType != ConvertEnum.TeacherTypeForSA && a.Status == ConvertEnum.StatusTypeForActive && a.User.UserInfo.Any(b => b.JobStatusType == ConvertEnum.JobStatusTypeForAtWork && b.Status == ConvertEnum.StatusTypeForActive) && a.User.UserBranch.Any(b => b.BranchId == branchId && b.IsMain == true && b.Status == ConvertEnum.StatusTypeForActive) select a).OrderByDescending(p => p.IsFullTime).ToList(); foreach (var itemTeacher in modelTeacherIsFullTime) { var teacher = new Model.Acs.Teacher { BranchId = branchId, //中心编号 TeacherId = itemTeacher.Id,//教师编号 ProductId = "",//产品ID List TeacherTypeId = itemTeacher.TeacherType,//教师类型编号 TeacherTypeName = BaseEnum.EmeEnum<TeacherType>.GetCnameByValue(itemTeacher.TeacherType), //老师类型名称 IsFullTime = itemTeacher.IsFullTime, //老师类型(全职、兼职) WorkDate = beginDate.AddDays(i), //工作日期 CurrTaskNum = 0, //当前任务量(工作日) Status = ConvertEnum.StatusTypeForActive, CreateBy = createBy, CreateTime = DateTime.Now }; //中心名称 foreach (var itemBranch in itemTeacher.User.UserBranch.Where(p => p.BranchId == branchId && p.IsMain)) { teacher.BranchName = itemBranch.Branch.CName; } //老师名称 foreach (var itemUserInfo in itemTeacher.User.UserInfo) { teacher.TeacherName = string.Format("{0} {1}", itemUserInfo.EName, itemUserInfo.CName == itemUserInfo.EName ? "" : itemUserInfo.CName).Trim().Split(' ')[0]; } //授课范围(ProductLevelId) 格式:1,5,12, var sbProductLevel = new StringBuilder(); //没有授课范围的,跳出执行下一个教师 if (itemTeacher.TeachRange.Count <= 0) continue; var TeachRangeList = itemTeacher.TeachRange; if (branchId == 12) { TeachRangeList = itemTeacher.TeachRange.Where(p => p.Status == ConvertEnum.StatusTypeForActive && p.ProductLevel.ProductLevelCourseType.Any(l => l.SelectivityType == 102 && l.Status == 101 && l.ProductLevelId == p.ProductLevelId)).ToList(); } else { TeachRangeList = itemTeacher.TeachRange.Where(p => p.Status == ConvertEnum.StatusTypeForActive).ToList(); } foreach (var itemTeachRange in TeachRangeList) { if (!teacher.ProductId.Contains("," + itemTeachRange.ProductLevel.ProductId.ToString() + ",")) { teacher.ProductId = teacher.ProductId + "," + itemTeachRange.ProductLevel.ProductId.ToString() + ","; } sbProductLevel.AppendFormat(",{0}", itemTeachRange.ProductLevelId); } teacher.TeachRange = sbProductLevel.ToString() + ","; teacher.ProductId = teacher.ProductId.Replace(",,", ","); //教师可用时间 格式:201407241000,201407241300, var sbAvailableTime = new StringBuilder(); //获取教师日程 var modelExistUserSchedule = Eme.UserBLL.GetExistUserScheduleByTeacherId(itemTeacher.Id, teacher.WorkDate, teacher.WorkDate.AddDays(1)); if (itemTeacher.IsFullTime)//全职教师 { var teacherUserWorkTime = itemTeacher.User.UserWorkTime.Where(p => p.WorkDate == teacher.WorkDate && p.Status == ConvertEnum.StatusTypeForActive).ToList(); //没有可用时间的,跳出执行下一个教师 if (!teacherUserWorkTime.Any()) continue; //循环可用时间 foreach (var itemWordDate in teacherUserWorkTime) { var workTimeId = itemWordDate.WorkTimeId; //最大任务量(工作日) teacher.MaxTaskNum = itemWordDate.WorkTime.TaskNum; var workTimeDetail = edb.WorkTimeDetail.Where(p => p.WorkTimeId == workTimeId && p.Status == ConvertEnum.StatusTypeForActive).OrderBy(p => p.BeginHour); foreach (var itemWorkTimeDetail in workTimeDetail) { for (var beginHour = itemWorkTimeDetail.BeginHour; beginHour < itemWorkTimeDetail.EndHour; beginHour++) { var anyBeginTime = Convert.ToDateTime(string.Format("{0} {1}:{2}:00", teacher.WorkDate.ToString("yyyy-MM-dd"), beginHour.ToString().PadLeft(2, '0'), itemWorkTimeDetail.BeginMinute.ToString().PadLeft(2, '0'))); //12点是休息移除 if (beginHour == 12) continue; //去除日程时间 if (modelExistUserSchedule.Any(p => p.BeginTime == anyBeginTime)) continue; sbAvailableTime.AppendFormat(",{0}{1}{2}", teacher.WorkDate.ToString("yyyyMMdd"), beginHour.ToString().PadLeft(2, '0'), itemWorkTimeDetail.BeginMinute.ToString().PadLeft(2, '0')); } teacher.AvailableTime = sbAvailableTime.ToString(); } } } else //兼职教师 { var wordDate = beginDate.AddDays(i); var wordDateAddDays = beginDate.AddDays(i + 1); var teachRequirement = itemTeacher.TeachRequirement.Where(p => p.TeachStartTime >= wordDate && p.TeachStartTime <= wordDateAddDays).ToList(); //没有可用需求的,跳出执行下一个教师 if (!teachRequirement.Any()) continue; foreach (var itemWordDate in teachRequirement) { //去除日程时间 if (modelExistUserSchedule.Any(p => p.BeginTime == itemWordDate.TeachStartTime)) continue; sbAvailableTime.AppendFormat(",{0}", itemWordDate.TeachStartTime.ToString("yyyyMMddHHmm")); } teacher.AvailableTime = sbAvailableTime.ToString(); } //移除已经排课被占用的时间 var modelArrangeCourse = edbAcs.ArrangeCourse.Where(p => p.BeginTime >= beginDate && p.BeginTime < endDate && p.BranchId == branchId && p.TeacherId == itemTeacher.Id); foreach (var itemArrangeCourse in modelArrangeCourse) { for (var iac = 0; iac < itemArrangeCourse.ClassTime.Value; iac++) { teacher.AvailableTime = teacher.AvailableTime.Replace("," + itemArrangeCourse.BeginTime.AddHours(iac).ToString("yyyyMMddHHmm"), ""); } } edbAcs.Entry(teacher).State = EntityState.Added; teacherList.Add(teacher); } } //录入 edbAcs.Configuration.ValidateOnSaveEnabled = false; result = edbAcs.SaveChanges() > 0; edbAcs.Configuration.ValidateOnSaveEnabled = true; return teacherList; } catch (Exception e) { // 异常日志消息队列 Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs { ExceptionType = CommonHelper.To<int>(ExceptionType.Function), Message = string.Format("BranchBLL-CreateTeacherByBranchId:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink), IsTreat = false, CreateTime = DateTime.Now }); return null; } }
/// <summary> /// 作者:Primo /// 日期:2014.08.04 /// 描述:创建学员 /// </summary> /// <param name="branchId"></param> /// <param name="beginDate"></param> /// <param name="endDate"></param> /// <param name="createBy"></param> /// <returns></returns> public static List<Model.Acs.Student> CreateStudentByBranchId(int branchId, DateTime beginDate, DateTime endDate, int createBy) { try { var studentList = new List<Model.Acs.Student>(); var edbAcs = new Model.Acs.EmeAcsEntities(); var edb = new Model.Eme.EmeEntities(); var unfinishedCoursesList = new List<string>(); var unfinishedCoursesListCopy = new List<string>(); var dateNum = endDate - beginDate; for (var i = 0; i <= dateNum.Days; i++) { var wordDate = beginDate.AddDays(i); var wordDateAddDays = beginDate.AddDays(i + 1); //获取一天的学员 var modelStudent = (from a in edb.Student join c in edb.UserBranch on a.UserId equals c.UserId join b in edb.BookRequirement on a.Id equals b.StudentId where a.Status == ConvertEnum.StatusTypeForActive && b.Status == ConvertEnum.StatusTypeForActive && b.BookStartTime >= wordDate && b.BookStartTime <= wordDateAddDays && b.IsSuccessful == false && c.IsMain && c.BranchId == branchId && a.Status == ConvertEnum.StatusTypeForActive select a).Distinct().ToList(); //循环学员 foreach (var itemStudent in modelStudent) { //循环学员名下的合同 foreach (var itemContract in itemStudent.Contract.Where(p => p.Status == ConvertEnum.StatusTypeForActive)) { //循环合同下面的明细 不是Vip的学员合同,在执行的合同 foreach (var item in itemContract.ContractDetail.Where(p => p.ContractStatusType == ConvertEnum.ContractStatusTypeForExcute && p.Status == ConvertEnum.StatusTypeForActive && p.ContractStatusType == ConvertEnum.ContractStatusTypeForExcute && p.IsVip == false)) { //产品级别编号(当前执行) var student = new Model.Acs.Student(); //循环合同的对应的当前课程级别 foreach (var itemContractLevel in item.ContractLevel.Where(p => p.Status == ConvertEnum.StatusTypeForActive && p.IsCurrent)) { student = new Model.Acs.Student(); if (itemContractLevel.IsCurrent) { student.ProductLevelId = itemContractLevel.ProductLevelId; //产品级别名称(当前执行) student.ProductLevelName = itemContractLevel.ProductLevel.EName; //剩余课时数(当前合同产品) student.SurplusHours = itemContractLevel.MajorTotal - itemContractLevel.MajorOnline - itemContractLevel.MajorOffline; //中心编号 student.BranchId = branchId; //中心名称 foreach (var itemBranch in itemContract.Student.User.UserBranch.Where(p => p.IsMain && p.BranchId == branchId)) { student.BranchName = itemBranch.Branch.CName; } //学员编号 student.StudentId = item.Contract.StudentId; //学员名称(英文名+中文名) foreach (var itemUserInfo in itemContract.Student.User.UserInfo) { if (itemUserInfo.EName != null && itemUserInfo.CName != null) student.StudentName = string.Format("{0} {1}", itemUserInfo.EName.Trim(), itemUserInfo.CName.Trim(' ').Trim()); else if (itemUserInfo.EName != null) student.StudentName = string.Format("{0}", itemUserInfo.EName.Trim()); else if (itemUserInfo.CName != null) student.StudentName = string.Format("{0}", itemUserInfo.CName.Trim(' ').Trim()); } //进度(当前合同产品) #region 进度计算 var detail = itemContractLevel.ContractDetail; var total = detail.MajorTotal; total = total <= 0 ? 1 : total; // 总课时 var online = detail.ContractLevel.Where(p => p.IsCurrent && p.Status == ConvertEnum.StatusTypeForActive).Sum(p => p.MajorOnline); // 已上线上课时 var offline = detail.ContractLevel.Where(p => p.IsCurrent && p.Status == ConvertEnum.StatusTypeForActive).Sum(p => p.MajorOffline); // 已上线下课时 var remain = total - (online + offline); remain = remain > total ? total : remain; // 剩余课时 var progress = (CommonHelper.To<double>(online + offline) / CommonHelper.To<double>(total)); student.Progress = progress; //需要计算 #endregion //是否绝对优先 student.IsFirst = itemContract.Student.IsFirst; student.ArrangeCourseOrder = 0; //需要计算 var dateContractDetail = beginDate.AddDays(i) - item.BeginDate; //距合同开始天数(当前合同产品) student.StartDays = dateContractDetail.Days; dateContractDetail = item.EndDate - beginDate.AddDays(i); //距合同结束天数(当前合同产品) student.EndDays = dateContractDetail.Days; //需求提交次数(上周) var bookStartTime = beginDate.AddDays(-7); student.DemandTimes = itemStudent.BookRequirement.Count(p => p.BookStartTime >= bookStartTime && p.BookEndTime <= beginDate && p.Status == ConvertEnum.StatusTypeForActive && p.StudentId == item.Contract.StudentId); //需求成功授理次数(上周) student.SatisfyTimes = itemStudent.BookRequirement.Count(p => p.BookStartTime >= bookStartTime && p.BookEndTime <= beginDate && p.Status == ConvertEnum.StatusTypeForActive && p.StudentId == item.Contract.StudentId && p.IsSuccessful); //已结课程编号 (ProductLevelCourseTypeCourseId)(不可重复预订的)格式:12,23,52, var bookRecordList = (from a in edb.BookRecord where a.StudentId == itemStudent.Id && a.Status == ConvertEnum.StatusTypeForActive && a.IsUnBook == false && a.ArrangeCourse.ProductLevelCourseTypeCourse.ProductLevelCourseType.ProductLevelId == itemContractLevel.ProductLevelId && (a.PassStatusType == ConvertEnum.PassStatusTypeForNoScoring || a.PassStatusType == ConvertEnum.PassStatusTypeForPass || a.PassStatusType == ConvertEnum.PassStatusTypeForAutoPass || a.PassStatusType == ConvertEnum.PassStatusTypeForProxy) select a).ToList(); var strSb = new StringBuilder(); foreach (var itemBookRecord in bookRecordList) { strSb.AppendFormat(",{0}", itemBookRecord.ArrangeCourse.ProductLevelCourseTypeCourseId); } student.CompleteCourses = string.Format("{0}{1}", strSb.ToString(), ","); //未上结课程编号 (ProductLevelCourseTypeCourseId)(不可重复预订的)格式:12,23,52, strSb = new StringBuilder(); unfinishedCoursesList = new List<string>();//装未上过的课程的ID foreach (var itemProductLevelCourseType in itemContractLevel.ProductLevel.ProductLevelCourseType.Where(p => p.SelectivityType == ConvertEnum.SelectivityTypeForRequired && p.Status == ConvertEnum.StatusTypeForActive && p.ProductCourseType.Status == ConvertEnum.StatusTypeForActive)) { unfinishedCoursesListCopy = new List<string>();//装未上过的课程的ID foreach (var itemProductLevelCourseTypeCourse in itemProductLevelCourseType.ProductLevelCourseTypeCourse.Where(p => p.ProductLevelCourseType.Status == ConvertEnum.StatusTypeForActive && p.Status == ConvertEnum.StatusTypeForActive).OrderBy(p => p.OrderNum)) { if (itemProductLevelCourseTypeCourse.Course.EName.Contains("LMW"))//不排LMW课程 { continue; } //如果在已上课的列表中,则continue if (student.CompleteCourses.Contains(string.Format(",{0},", itemProductLevelCourseTypeCourse.Id))) { continue; } else { unfinishedCoursesListCopy.Add(itemProductLevelCourseTypeCourse.Id.ToString()); } } if (unfinishedCoursesListCopy.Count() >= 6) { unfinishedCoursesListCopy = unfinishedCoursesListCopy.Take(6).ToList(); unfinishedCoursesList = unfinishedCoursesList.Union(unfinishedCoursesListCopy).ToList(); } else if (unfinishedCoursesListCopy.Count() > 0) { unfinishedCoursesList = unfinishedCoursesList.Union(unfinishedCoursesListCopy).ToList(); } } //打乱 未上结课程编号 顺序 unfinishedCoursesList = RamdonList(unfinishedCoursesList); var strRamdonList = ""; foreach (var itemStrList in unfinishedCoursesList) { strRamdonList = strRamdonList + "," + itemStrList; } student.UnfinishedCourses = string.Format("{0}{1}", strRamdonList, ","); //可排课时间(学员需求时间)格式:201407241000,201407291000,201407301500, var bookRequirementList = itemStudent.BookRequirement.Where(p => p.BookStartTime >= wordDate && p.BookEndTime <= wordDateAddDays && p.Status == ConvertEnum.StatusTypeForActive && p.StudentId == item.Contract.StudentId && !p.IsSuccessful); foreach (var itemBookRequirement in bookRequirementList) { student.AvailableTime = student.AvailableTime + "," + itemBookRequirement.BookStartTime.ToString("yyyyMMddHHmm"); } //工作日期 student.WorkDate = wordDate; //当前任务量(即已排课量) student.CurrTaskNum = 0; student.PlanNum = 0; //状态(系统枚举) student.Status = ConvertEnum.StatusTypeForActive; student.CreateBy = createBy; student.CreateTime = DateTime.Now; //录入 try { edbAcs.Entry(student).State = EntityState.Added; edbAcs.Configuration.ValidateOnSaveEnabled = false; edbAcs.SaveChanges(); edbAcs.Configuration.ValidateOnSaveEnabled = true; } catch (Exception e) { // 异常日志消息队列 Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs { ExceptionType = CommonHelper.To<int>(ExceptionType.Function), Message = string.Format("BranchBLL-CreateStudentByBranchId:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink), IsTreat = false, CreateTime = DateTime.Now }); } } } studentList.Add(student); } } } } //复制一份Student集合 var studentListCopy = new List<Model.Acs.Student>(studentList.ToArray()); //更新录入 try { //循环计算权重 foreach (var item in studentList) { //绝对优先不做计算 if (item.IsFirst) { continue; } else { //计算权重 var modelWeight = GetWeightByBranchId(branchId); var arrangeCourseOrder = studentListCopy.OrderByDescending(p => p.Progress).ToList().IndexOf(item) / Utility.CommonHelper.To<float>(modelWeight.Progress.Value); arrangeCourseOrder = arrangeCourseOrder + studentListCopy.OrderBy(p => p.StartDays).ToList().IndexOf(item) / Utility.CommonHelper.To<float>(modelWeight.StartDays.Value); arrangeCourseOrder = arrangeCourseOrder + studentListCopy.OrderBy(p => p.EndDays).ToList().IndexOf(item) / Utility.CommonHelper.To<float>(modelWeight.EndDays.Value); arrangeCourseOrder = arrangeCourseOrder + studentListCopy.OrderBy(p => p.SurplusHours).ToList().IndexOf(item) / Utility.CommonHelper.To<float>(modelWeight.SurplusHours.Value); arrangeCourseOrder = arrangeCourseOrder + studentListCopy.OrderByDescending(p => p.SatisfyTimes / (p.DemandTimes == 0 ? 1 : p.DemandTimes)).ToList().IndexOf(item) / Utility.CommonHelper.To<float>(modelWeight.DemandTimes.Value); var modelUpdate = edbAcs.Student.SingleOrDefault(p => p.Id == item.Id); if (modelUpdate != null) { modelUpdate.ArrangeCourseOrder = arrangeCourseOrder; edbAcs.Entry(modelUpdate).State = EntityState.Modified; } } } edbAcs.Configuration.ValidateOnSaveEnabled = false; edbAcs.SaveChanges(); edbAcs.Configuration.ValidateOnSaveEnabled = true; } catch (Exception e) { // 异常日志消息队列 Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs { ExceptionType = CommonHelper.To<int>(ExceptionType.Function), Message = string.Format("BranchBLL-CreateStudentByBranchId:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink), IsTreat = false, CreateTime = DateTime.Now }); return null; } return studentList; } catch (Exception e) { // 异常日志消息队列 Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs { ExceptionType = CommonHelper.To<int>(ExceptionType.Function), Message = string.Format("BranchBLL-CreateStudentByBranchId:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink), IsTreat = false, CreateTime = DateTime.Now }); return null; } }
/// <summary> /// 作者:Primo /// 日期:2014.08.04 /// 描述:创建教师 /// </summary> /// <param name="branchId"></param> /// <param name="beginDate"></param> /// <param name="endDate"></param> /// <param name="createBy"></param> /// <returns></returns> public static List<Model.Acs.CoursePlan> CreateCoursePlanByBranchId(int branchId, DateTime beginDate, DateTime endDate, int createBy) { var coursePlanList = new List<Model.Acs.CoursePlan>(); try { var edb = new Model.Eme.EmeEntities(); //更新录入 var edbAcs = new Model.Acs.EmeAcsEntities(); //获取中心下有效合同的等级 var modelProduceLevel = (from a in edb.ProductLevel join b in edb.ProductBranch on a.ProductId equals b.ProductId where a.Status == ConvertEnum.StatusTypeForActive && b.Status == ConvertEnum.StatusTypeForActive && b.BranchId == branchId select a).Distinct().ToList(); //循环级别 foreach (var itemProductLevel in modelProduceLevel) { //获取当前等级 的 合同类型 var modelContractType = (from a in edb.ContractType where a.Status == ConvertEnum.StatusTypeForActive && a.ContractDetail.Any(b => b.Status == ConvertEnum.StatusTypeForActive && b.ContractStatusType == ConvertEnum.ContractStatusTypeForExcute && b.ContractLevel.Any(c => c.IsCurrent && c.ProductLevelId == itemProductLevel.Id)) select a); foreach (var itemContractType in modelContractType) { var coursePlan = new Model.Acs.CoursePlan { BranchId = branchId }; //中心编号 //中心名称 foreach (var itemProductBranch in itemProductLevel.Product.ProductBranch.Where(p => p.BranchId == branchId)) { coursePlan.BranchName = itemProductBranch.Branch.CName; } //产品编号 coursePlan.ProductId = itemProductLevel.ProductId; //产品名称 coursePlan.ProductName = itemProductLevel.Product.EName; //产品级别编号 coursePlan.ProductLevelId = itemProductLevel.Id; //产品编号名称 coursePlan.ProductLevelName = itemProductLevel.EName; //合同类型编号 coursePlan.ContractTypeId = itemContractType.Id; //合同类型名称 coursePlan.ContractTypeName = itemContractType.CName; //执行学员人数 coursePlan.Students = edb.Student.Count(a => a.User.UserBranch.Any(e => e.BranchId == branchId && e.IsMain) && a.Contract.Any(b => b.ContractDetail.Any(c => c.ContractStatusType == ConvertEnum.ContractStatusTypeForExcute && c.ContractLevel.Any(d => d.ProductLevelId == itemProductLevel.Id && d.IsCurrent) && c.ContractType.Id == itemContractType.Id))); //开始处理时间 coursePlan.BeginDate = beginDate; //截止处理时间 coursePlan.EndDate = endDate; //状态(系统枚举) coursePlan.Status = ConvertEnum.StatusTypeForActive; //创建人 coursePlan.CreateBy = createBy; //创建时间 coursePlan.CreateTime = DateTime.Now; coursePlanList.Add(coursePlan); edbAcs.Entry(coursePlan).State = EntityState.Added; } } edbAcs.Configuration.ValidateOnSaveEnabled = false; edbAcs.SaveChanges(); edbAcs.Configuration.ValidateOnSaveEnabled = true; } catch (Exception e) { // 异常日志消息队列 Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs { ExceptionType = CommonHelper.To<int>(ExceptionType.Function), Message = string.Format("BranchBLL-CreateCoursePlanByBranchId:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink), IsTreat = false, CreateTime = DateTime.Now }); return null; } return coursePlanList; }
/// <summary> /// 获取产品 和 级别 /// </summary> /// <param name="id"></param> /// <param name="pList"></param> /// <returns></returns> public static List<Model.Eme.Product> GetProductAndProductLevels(int id, out Dictionary<int, List<Model.Eme.ProductLevel>> pList) { var Db = new EmeAcsEntities();//Acs库连接 var productlist = new List<Model.Eme.Product>(); var productLevelList = new List<Model.Eme.ProductLevel>(); pList = new Dictionary<int, List<Model.Eme.ProductLevel>>(); var teacherObj = GetTeacherById(id); var pId = teacherObj.ProductId.Trim(',').Split(','); foreach (var item in pId)//循环获取产品 { var edb = new Model.Eme.EmeEntities();//Eme库连接 var intItem = Convert.ToInt32(item); var productObj = edb.Product.FirstOrDefault(p => p.Id == intItem && p.Status == ConvertEnum.StatusTypeForActive);//获取产品 if (productObj == null) continue; productlist.Add(productObj); var productLevelsObj = edb.ProductLevel.Where(p => p.ProductId == productObj.Id && p.Status == ConvertEnum.StatusTypeForActive).ToList();//获取级别 productLevelList = new List<Model.Eme.ProductLevel>(); foreach (var itemLevel in productLevelsObj)//循环筛选级别 { if (teacherObj.TeachRange.Contains("," + itemLevel.Id + ",")) { productLevelList.Add(itemLevel); if (pList.ContainsKey(productObj.Id))//判断是否存在这个Key值 { pList[productObj.Id] = productLevelList;//替换 } else { pList.Add(productObj.Id, productLevelList);//添加 } } } } return productlist; }
/// <summary> /// 调整课程时,获取教室 /// </summary> /// <param name="branchId"></param> /// <param name="productLevelCourseTypeId"></param> /// <param name="workDate"></param> /// <param name="workTime"></param> /// <returns></returns> public static List<Model.Acs.Classroom> GetClassroom(int branchId, int productLevelCourseTypeId, DateTime workDate, string workTime) { var edbAcs = new EmeAcsEntities();//Acs 库 var edbEme = new Model.Eme.EmeEntities();//Eme 库 var modelProductLevelCourseTypeObj = edbEme.ProductLevelCourseType.FirstOrDefault(a => a.Id == productLevelCourseTypeId); var strProductCourseTypeId = string.Format(",{0},", modelProductLevelCourseTypeObj.ProductCourseTypeId); var model = (from a in edbAcs.Classroom where a.BranchId == branchId && a.WorkDate == workDate && a.UnavailableTime.Contains(workTime) == false && a.ClassroomTypeForProductCourseType.Contains(strProductCourseTypeId) == true && a.Status == ConvertEnum.StatusTypeForActive select a); return model.ToList(); }