Ejemplo n.º 1
0
        /// <summary>
        /// 作者:Primo
        /// 日期:2014.07.29
        /// 描述:新增Product
        /// </summary>
        /// <param name="branchId"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool AddProduct(int branchId, List<Model.Acs.Product> model)
        {
            try
            {
                var edb = new Model.Acs.EmeAcsEntities();
                var deleteModelList = (from a in edb.Product
                                       where a.BranchId == branchId
                                       select a);

                //先把旧的移除
                foreach (var item in deleteModelList)
                {
                    edb.Entry(item).State = EntityState.Deleted;
                }
                //重新添加新的Product
                foreach (var item in model)
                {
                    edb.Entry(item).State = EntityState.Added;
                }
                //保存操作
                edb.Configuration.ValidateOnSaveEnabled = false;
                edb.SaveChanges();
                edb.Configuration.ValidateOnSaveEnabled = true;
                return true;
            }
            catch (Exception e)
            {
                // 异常日志消息队列
                Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs
                {
                    ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                    Message = string.Format("BranchBLL-AddProduct:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink),
                    IsTreat = false,
                    CreateTime = DateTime.Now
                });
                return false;
            }
        }
Ejemplo n.º 2
0
        /// <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;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 作者:Primo
        /// 日期:2014.07.30
        /// 描述:删除教室 物理删除
        /// </summary>
        /// <param name="branchId"></param>
        /// <param name="beginDate"></param>
        /// <param name="endDate"></param>
        /// <param name="updateBy"></param>
        /// <returns></returns>
        public static bool DeleteClassroomByBranchId(int branchId, DateTime beginDate, DateTime endDate, int updateBy)
        {
            try
            {
                var edb = new Model.Acs.EmeAcsEntities();
                var model = (from a in edb.Classroom
                             where a.BranchId == branchId
                             && a.WorkDate >= beginDate
                             && a.WorkDate <= endDate
                             && a.Status == ConvertEnum.StatusTypeForActive
                             select a);

                //数据集为0的时候,跳出
                if (model.Count() <= 0)
                {
                    return true;
                }
                else
                {
                    foreach (var item in model)
                    {
                        edb.Entry(item).State = EntityState.Deleted;
                    }
                    edb.SaveChanges();
                    return true;
                }
            }
            catch (Exception e)
            {
                // 异常日志消息队列
                Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs
                {
                    ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                    Message = string.Format("BranchBLL-DeleteClassroomByBranchId:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink),
                    IsTreat = false,
                    CreateTime = DateTime.Now
                });
                return false;
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 作者:Primo
 /// 日期:2014.10.27
 /// 描述:创建Weight
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool CreateWeightByBranchId(Model.Acs.Weight model)
 {
     try
     {
         var edb = new Model.Acs.EmeAcsEntities();
         edb.Entry(model).State = EntityState.Added;
         edb.Configuration.ValidateOnSaveEnabled = false;
         edb.SaveChanges();
         edb.Configuration.ValidateOnSaveEnabled = true;
         return true;
     }
     catch (Exception e)
     {
         // 异常日志消息队列
         Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs
         {
             ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
             Message = string.Format("BranchBLL-CreateWeightByBranchId:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink),
             IsTreat = false,
             CreateTime = DateTime.Now
         });
         return false;
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 作者:Primo
        /// 日期:2014.10.30
        /// 描述:删除那些课程是指定只能外教上的,或者指定中教上的
        /// </summary>
        /// <param name="branchId"></param>
        /// <param name="productLevelID"></param>
        /// <param name="productLevelCourseTypeID"></param>
        /// <returns></returns>
        public static bool DeleteTeacherProductLevelCourseTypeCourseConfig(int branchId, int productLevelID, int productLevelCourseTypeID)
        {
            try
            {
                var edb = new Model.Acs.EmeAcsEntities();
                var model = (from a in edb.TeacherProductLevelCourseTypeCourseConfig
                             where a.BranchId == branchId
                             && a.ProductLevelID == productLevelID
                             && a.ProductLevelCourseTypeID == productLevelCourseTypeID
                             && a.Status == ConvertEnum.StatusTypeForActive
                             select a);

                //没有内容,直接返回跳出
                if (model.Count() <= 0)
                {
                    return true;
                }
                else
                {
                    //循环删除
                    foreach (var item in model)
                    {
                        edb.Entry(item).State = EntityState.Deleted;
                    }
                    edb.SaveChanges();
                    return true;
                }
            }
            catch (Exception e)
            {
                // 异常日志消息队列
                Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs
                {
                    ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                    Message = string.Format("BranchBLL-DeleteTeacherProductLevelCourseTypeCourseConfig:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink),
                    IsTreat = false,
                    CreateTime = DateTime.Now
                });
                return false;
            }
        }
Ejemplo n.º 6
0
        /// <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;//继续执行下一个学生
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 作者:Primo
        /// 日期:2014.09.05
        /// 描述:删除ArrangeCourseLogs
        /// </summary>
        /// <param name="branchId"></param>
        /// <param name="beginDate"></param>
        /// <param name="endDate"></param>
        /// <param name="updateBy"></param>
        /// <returns></returns>
        public static bool DeleteArrangeCourseLogs(int branchId, DateTime beginDate, DateTime endDate, int updateBy)
        {
            try
            {
                var edb = new Model.Acs.EmeAcsEntities();

                var model = (from a in edb.ArrangeCourseLogs
                             where a.BranchId == branchId
                             && a.BeginDate == beginDate
                             && a.EndDate == endDate
                             select a);

                if (model.Count() <= 0)
                {
                    return true;
                }
                else
                {
                    foreach (var item in model)
                    {
                        edb.Entry(item).State = EntityState.Deleted;
                    }
                    return edb.SaveChanges() > 0;
                }
            }
            catch (Exception e)
            {
                // 异常日志消息队列
                Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs
                {
                    ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                    Message = string.Format("StudyBLL-DeleteArrangeCourseLogs:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink),
                    IsTreat = false,
                    CreateTime = DateTime.Now
                });
                return false;
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 作者:Primo
 /// 日期:2014.08.04
 /// 描述:更新ArrangeCourseLogs
 /// </summary>
 /// <param name="branchId"></param>
 /// <param name="step"></param>
 /// <param name="beginDate"></param>
 /// <param name="endDate"></param>
 /// <returns></returns>
 public static bool UpdateArrangeCourseLogs(int branchId, int step, DateTime beginDate, DateTime endDate, int updateBy)
 {
     try
     {
         var edb = new Model.Acs.EmeAcsEntities();
         var model = edb.ArrangeCourseLogs.SingleOrDefault(p => p.BranchId == branchId && p.BeginDate == beginDate && p.EndDate == endDate);
         model.Step = step;
         model.UpdateBy = updateBy;
         model.UpdateTime = DateTime.Now;
         edb.Entry(model).State = EntityState.Modified;
         var result = edb.SaveChanges() > 0;
         return result;
     }
     catch (Exception e)
     {
         // 异常日志消息队列
         Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs
         {
             ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
             Message = string.Format("StudyBLL-UpdateArrangeCourseLogs:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink),
             IsTreat = false,
             CreateTime = DateTime.Now
         });
         return false;
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// 作者:Primo
        /// 日期:2014.07.29
        /// 描述:根据中心区域ID创建产品,重新在Eme库整理后返回
        /// </summary>
        /// <param name="branchId"></param>
        /// <param name="createBy"></param>
        /// <returns></returns>
        public static bool CreateProductByBranchId(int branchId, int createBy)
        {
            try
            {
                var edb = new Model.Acs.EmeAcsEntities();
                var modelProduct = Eme.ProductBLL.GetProductBranchListByBranchId(branchId);
                foreach (var item in modelProduct)
                {
                    foreach (var itemProductLevel in item.Product.ProductLevel.Where(p =>
                        p.Status == ConvertEnum.StatusTypeForActive))
                    {
                        foreach (var itemProductLevelCourseType in itemProductLevel.ProductLevelCourseType.Where(p =>
                            p.Status == ConvertEnum.StatusTypeForActive))
                        {
                            var product = new Model.Acs.Product
                            {
                                BranchId = branchId,
                                BranchName = item.Branch.CName,
                                ProductId = item.ProductId,
                                ProductName = item.Product.SCode,
                                ProductLevelId = itemProductLevel.Id,
                                ProductLevelName = itemProductLevel.EName,
                                ProductLevelCourseTypeId = itemProductLevelCourseType.Id,
                                Status = ConvertEnum.StatusTypeForActive,
                                CreateBy = createBy,
                                CreateTime = DateTime.Now
                            };

                            //获取所属中心的课节
                            foreach (var itemProductLevelCourseTypeCourses in itemProductLevelCourseType.ProductLevelCourseTypeCourse.Where(p =>
                                p.Status == ConvertEnum.StatusTypeForActive
                                && (p.BranchId == branchId || p.BranchId == item.Product.BranchId)))
                            {
                                product.ProductLevelCourseTypeCourses = string.Format("{0},{1}", product.ProductLevelCourseTypeCourses, itemProductLevelCourseTypeCourses.Id);
                            }

                            //为空的不做录入
                            if (product.ProductLevelCourseTypeCourses == null)
                            {
                                continue;
                            }
                            else
                            {
                                edb.Entry(product).State = EntityState.Added;
                            }
                        }
                    }
                }
                edb.Configuration.ValidateOnSaveEnabled = false;
                edb.SaveChanges();
                edb.Configuration.ValidateOnSaveEnabled = true;
                return true;
            }
            catch (Exception e)
            {
                // 异常日志消息队列
                Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs
                {
                    ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                    Message = string.Format("BranchBLL-CreateProductByBranchId:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink),
                    IsTreat = false,
                    CreateTime = DateTime.Now
                });
                return false;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 作者:Primo
        /// 日期:2014.08.07
        /// 描述:创建CoursePlanResult
        /// </summary>
        /// <param name="branchId"></param>
        /// <param name="beginDate"></param>
        /// <param name="endDate"></param>
        /// <param name="createBy"></param>
        /// <returns></returns>
        public static List<Model.Acs.CoursePlanResult> CreateCoursePlanResultByBranchId(int branchId, DateTime beginDate, DateTime endDate, int createBy)
        {
            try
            {
                var coursePlanResultList = new List<Model.Acs.CoursePlanResult>();
                var edbAcs = new Model.Acs.EmeAcsEntities();

                //获取CoursePlan
                var coursePlanModel = (from a in edbAcs.CoursePlan
                                       where a.BeginDate >= beginDate && a.EndDate <= endDate
                                       group a by new { a.BranchId, a.BranchName, a.ProductId, a.ProductName, a.ProductLevelId, a.ProductLevelName }
                                           into p
                                           select new
                                           {
                                               ID = p.Key,
                                               Students = p.Sum(a => a.Students)
                                           }).ToList();

                //学生总数
                var studentsAll = coursePlanModel.Sum(p => p.Students);

                //循环录入
                foreach (var coursePlanResult in coursePlanModel.Select(itemCoursePlan => new Model.Acs.CoursePlanResult
                {
                    BranchId = itemCoursePlan.ID.BranchId,
                    BranchName = itemCoursePlan.ID.BranchName,
                    ProductId = itemCoursePlan.ID.ProductId,
                    ProductName = itemCoursePlan.ID.ProductName,
                    ProductLevelId = itemCoursePlan.ID.ProductLevelId,
                    ProductLevelName = itemCoursePlan.ID.ProductLevelName,
                    BeginDate = beginDate,
                    EndDate = endDate,
                    Ratio = (Convert.ToDouble(itemCoursePlan.Students) / Convert.ToDouble(studentsAll)),
                    Theory = 0,
                    Actual = 0,
                    Final = 0,
                    Status = ConvertEnum.StatusTypeForActive,
                    CreateBy = createBy,
                    CreateTime = DateTime.Now
                }))
                {
                    edbAcs.Entry(coursePlanResult).State = EntityState.Added;
                    coursePlanResultList.Add(coursePlanResult);
                }
                edbAcs.Configuration.ValidateOnSaveEnabled = false;
                edbAcs.SaveChanges();
                edbAcs.Configuration.ValidateOnSaveEnabled = true;

                return coursePlanResultList;
            }
            catch (Exception e)
            {
                // 异常日志消息队列
                Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs
                {
                    ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                    Message = string.Format("BranchBLL-CreateCoursePlanResultByBranchId:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink),
                    IsTreat = false,
                    CreateTime = DateTime.Now
                });
                return null;
            }
        }
Ejemplo n.º 11
0
        /// <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;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 作者:Primo
        /// 日期:2014.10.27
        /// 描述:跟新Weight
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool UpdateWeightByBranchId(Model.Acs.Weight model)
        {
            try
            {
                var edb = new Model.Acs.EmeAcsEntities();
                var objModel = GetWeightByBranchId(model.BranchId.Value);
                objModel.BranchId = model.BranchId.Value;
                objModel.Progress = model.Progress.Value;
                objModel.StartDays = model.StartDays.Value;
                objModel.EndDays = model.EndDays.Value;
                objModel.SurplusHours = model.SurplusHours.Value;
                objModel.DemandTimes = model.DemandTimes.Value;

                edb.Entry(objModel).State = EntityState.Modified;
                edb.Configuration.ValidateOnSaveEnabled = false;
                edb.SaveChanges();
                edb.Configuration.ValidateOnSaveEnabled = true;
                return true;
            }
            catch (Exception e)
            {
                // 异常日志消息队列
                Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs
                {
                    ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                    Message = string.Format("BranchBLL-CreateWeightByBranchId:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink),
                    IsTreat = false,
                    CreateTime = DateTime.Now
                });
                return false;
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 作者:Primo
        /// 日期:2015.01.04
        /// 描述:修改教师的占用时间 
        /// </summary>
        /// <param name="branchId"></param>
        /// <param name="teacherId"></param>
        /// <param name="workDate"></param>
        /// <param name="atdate"></param>
        /// <param name="updateType">101:去掉AvailableTime,新增OccupyTime    102:去掉OccupyTime,新增AvailableTime</param>
        /// <returns></returns>
        public static bool UpdateTeacherByBranchId(int branchId, int teacherId, DateTime workDate, string atdate, int updateType)
        {
            try
            {
                var edb = new Model.Acs.EmeAcsEntities();
                var model = (from a in edb.Teacher
                             where a.BranchId == branchId
                             && a.WorkDate == workDate
                             && a.Id == teacherId
                             && a.Status == ConvertEnum.StatusTypeForActive
                             select a).FirstOrDefault();

                if (model == null)
                {
                    return true;
                }
                else
                {
                    if (updateType == 101)
                    {
                        model.AvailableTime = model.AvailableTime.Replace("," + atdate, "");
                        model.OccupyTime = model.OccupyTime + "," + atdate;
                    }
                    else if (updateType == 102)
                    {
                        model.OccupyTime = model.OccupyTime.Replace("," + atdate, "");
                        model.AvailableTime = model.AvailableTime + "," + atdate;
                    }
                    edb.Entry(model).State = EntityState.Modified;
                    return edb.SaveChanges() > 0;
                }
            }
            catch (Exception e)
            {
                // 异常日志消息队列
                Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs
                {
                    ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                    Message = string.Format("BranchBLL-UpdateTeacherByBranchId:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink),
                    IsTreat = false,
                    CreateTime = DateTime.Now
                });
                return false;
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 作者:Primo
        /// 日期:2015.01.09
        /// 描述:存在可用的Plan,则修改学员
        /// </summary>
        /// <param name="planNum"></param>
        /// <param name="branchId"></param>
        /// <param name="beginDate"></param>
        /// <param name="endDate"></param>
        /// <param name="createBy"></param>
        /// <returns></returns>
        public static bool UpateStudentByPlanNum(int planNum, int branchId, DateTime beginDate, DateTime endDate, int createBy)
        {
            try
            {
                var edbAcs = new Model.Acs.EmeAcsEntities();
                var result = false;
                //获取还存在匹配次数的学生
                var model = edbAcs.Student.Where(a => a.BranchId == branchId
                    && a.WorkDate >= beginDate
                    && a.WorkDate <= endDate
                    && a.PlanNum < planNum
                    && a.CurrTaskNum < Common.Global.MaxNum);

                //获取还存在匹配次数,但是已经达到最大匹配课数的学生
                var modelObj = edbAcs.Student.Where(a => a.BranchId == branchId
                    && a.WorkDate >= beginDate
                    && a.WorkDate <= endDate
                    && a.PlanNum < planNum
                    && a.CurrTaskNum >= Common.Global.MaxNum);

                //判断是否含有元素
                if (model.Any())
                {
                    //把元素里面都改成有效状态
                    foreach (var item in model)
                    {
                        item.Status = ConvertEnum.StatusTypeForActive;
                        edbAcs.Entry(item).State = EntityState.Modified;
                    }
                }

                if (modelObj.Any())
                {
                    //把元素里面都改成无效状态
                    foreach (var item in modelObj)
                    {
                        item.PlanNum = planNum;
                        item.Status = ConvertEnum.OperateTypeForDelete;
                        edbAcs.Entry(item).State = EntityState.Modified;
                    }
                }

                edbAcs.Configuration.ValidateOnSaveEnabled = false;
                result = edbAcs.SaveChanges() > 0;
                edbAcs.Configuration.ValidateOnSaveEnabled = true;

                return result;
            }
            catch (Exception e)
            {
                // 异常日志消息队列
                Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs
                {
                    ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                    Message = string.Format("BranchBLL-UpateStudentByPlanNum:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink),
                    IsTreat = false,
                    CreateTime = DateTime.Now
                });
                return false;
            }
        }
Ejemplo n.º 15
0
        /// <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 InsertArrangeCourse(int branchId, DateTime beginDate, DateTime endDate, int createBy, out Dictionary<string, string> outList)
        {
            //初始化操作状态
            var result = false;
            outList = new Dictionary<string, string>();
            var edbAcs = new Model.Acs.EmeAcsEntities();

            //ArrangeCourseId 返回参数
            var outArrangeCourseId = 0;

            //获取一条预备创建的ArrangeCourse
            var modelArrangeCourse = edbAcs.ArrangeCourse.OrderBy(p => p.BeginTime).FirstOrDefault(a => a.BranchId == branchId && a.BeginTime >= beginDate && a.BeginTime < endDate && a.Status == ConvertEnum.StatusTypeForActive);
            if (modelArrangeCourse == null)
                return false;

            try
            {
                //排课 只安排线下
                var num = 0;
                if (branchId == 12)
                {
                    num = Eme.StudyBLL.CreateArrangeCourse(branchId, modelArrangeCourse.ProductLevelCourseTypeCourseId, modelArrangeCourse.TeacherId, null,
                            modelArrangeCourse.BeginTime, true, createBy, out outArrangeCourseId);
                }
                else
                {
                    num = Eme.StudyBLL.CreateArrangeCourse(branchId, modelArrangeCourse.ProductLevelCourseTypeCourseId, modelArrangeCourse.TeacherId, modelArrangeCourse.ClassroomId,
                                modelArrangeCourse.BeginTime, false, createBy, out outArrangeCourseId);
                }

                //判断是否拍成功
                if (outArrangeCourseId > 0)
                {
                    #region //放课  2014.08.20 Primo 暂时把放课取消

                    //using (var edb = new Model.Eme.EmeEntities())
                    //{
                    //    var openArrangeCourse = (from a in edb.ArrangeCourse
                    //                             where a.Id == outArrangeCourseId
                    //                             select a).FirstOrDefault();
                    //    openArrangeCourse.OpenTime = DateTime.Now;
                    //    edb.Entry(openArrangeCourse).State = EntityState.Modified;
                    //    edb.SaveChanges();
                    //}

                    #endregion

                    //成功排了一节课,修改状态
                    var modelProductLevelCourseTypeCourse = Eme.ProductBLL.GetProductLevelCourseTypeCourseById(modelArrangeCourse.ProductLevelCourseTypeCourseId);

                    #region 暂时不安排学员进去

                    //var studentList = modelArrangeCourse.StudentIds.Trim(',').Split(',');
                    //foreach (var itemStudent in studentList)
                    //{
                    //    var tip = Eme.StudyBLL.CreateBookRecord(Convert.ToInt32(itemStudent), modelProductLevelCourseTypeCourse.ProductLevelCourseType.ProductLevelId, outArrangeCourseId, createBy);
                    //    var msg = "";
                    //    switch (tip)
                    //    {
                    //        case 100:
                    //            msg = "课程预订成功!";
                    //            result = true;//需要刷新
                    //            break;
                    //        case 101:
                    //            msg = "已达最大订课人数限制!";
                    //            break;
                    //        case 102:
                    //            msg = "已预订了该排课!";
                    //            break;
                    //        case 103:
                    //            msg = "所订课程已结课(或待结课)";
                    //            break;
                    //        case 104:
                    //            msg = "学员在该时间段已经预定其他课程!";
                    //            break;
                    //        case 105:
                    //            msg = "排课信息已失效!";
                    //            break;
                    //        case 106:
                    //            msg = "订课信息提交失败!";
                    //            break;
                    //        case 107:
                    //            msg = "系统异常,请联系管理员!";
                    //            break;
                    //        default:
                    //            msg = "系统异常,请联系管理员!";
                    //            break;
                    //    }
                    //    modelArrangeCourse.Remark = string.Format("{0},学员{1}:{2}", modelArrangeCourse.Remark, itemStudent, msg);
                    //}

                    #endregion

                    //更改状态
                    modelArrangeCourse.Remark = string.Format("课程ID:{0},{1}", outArrangeCourseId, modelArrangeCourse.Remark);
                    modelArrangeCourse.ArrangeCourseId = outArrangeCourseId;
                }
                else
                {
                    //不成功
                    modelArrangeCourse.Remark = string.Format("课程ID:{0},排课时出现错误!错误码:{1}", outArrangeCourseId, num);
                }

                #region

                outList.Add("ProductLevelName", modelArrangeCourse.ProductLevelName);//级别名称
                outList.Add("StudentNames", modelArrangeCourse.StudentNames);//学员名称
                outList.Add("ClassroomName", modelArrangeCourse.ClassroomName);//教室名称
                outList.Add("ClassroomTypeName", modelArrangeCourse.ClassroomTypeName);//教室类型
                outList.Add("TeacherName", modelArrangeCourse.TeacherName);//教师名称
                outList.Add("TeacherTypeName", modelArrangeCourse.TeacherTypeName);//教师类型
                outList.Add("BeginDate", modelArrangeCourse.BeginTime.ToString("yyyy/MM/dd HH:mm"));//上课时间
                outList.Add("ProductLevelCourseTypeCourseName", modelArrangeCourse.ProductLevelCourseTypeCourseName);//课程名称
                outList.Add("ArrangeCourseId", outArrangeCourseId > 0 ? outArrangeCourseId.ToString() : "");//课程Id

                #endregion

                //更新记录
                modelArrangeCourse.Status = ConvertEnum.StatusTypeForDelete;
                modelArrangeCourse.IsSuccessful = true;
                modelArrangeCourse.UpdateBy = createBy;
                modelArrangeCourse.UpdateTime = DateTime.Now;
                edbAcs.Entry(modelArrangeCourse).State = EntityState.Modified;
                edbAcs.Configuration.ValidateOnSaveEnabled = false;
                result = edbAcs.SaveChanges() > 0;
                edbAcs.Configuration.ValidateOnSaveEnabled = true;

                return result;
            }
            catch (Exception e)
            {
                modelArrangeCourse.Status = ConvertEnum.StatusTypeForDelete;
                modelArrangeCourse.IsSuccessful = true;
                modelArrangeCourse.Remark = string.Format("课程ID:{0},排课时出现错误!错误码:{1}", outArrangeCourseId, e.ToString());
                edbAcs.Entry(modelArrangeCourse).State = EntityState.Modified;
                edbAcs.Configuration.ValidateOnSaveEnabled = false;
                result = edbAcs.SaveChanges() > 0;
                edbAcs.Configuration.ValidateOnSaveEnabled = true;
                return result;
            }
        }
Ejemplo n.º 16
0
        /// <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;
            }
        }
Ejemplo n.º 17
0
 /// <summary>
 /// 作者:Primo
 /// 日期:2014.08.04
 /// 描述:创建ArrangeCourseLogs
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool CreateArrangeCourseLogs(Model.Acs.ArrangeCourseLogs model)
 {
     try
     {
         var edb = new Model.Acs.EmeAcsEntities();
         edb.Entry(model).State = EntityState.Added;
         var result = edb.SaveChanges() > 0;
         return result;
     }
     catch (Exception e)
     {
         // 异常日志消息队列
         Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs
         {
             ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
             Message = string.Format("StudyBLL-CreateArrangeCourseLogs:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink),
             IsTreat = false,
             CreateTime = DateTime.Now
         });
         return false;
     }
 }
Ejemplo n.º 18
0
        /// <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;
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 作者:Primo
        /// 日期:2014.12.26
        /// 描述:调整课程时用的根据ID删除ArrangeCourse
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool DeleteArrangeCourseById(int id)
        {
            var edbAcs = new Model.Acs.EmeAcsEntities();
            try
            {
                var arrangeCourseObj = edbAcs.ArrangeCourse.FirstOrDefault(p => p.Id == id);
                var workDate = Convert.ToDateTime(arrangeCourseObj.BeginTime.ToString("yyyy-MM-dd"));
                var teacherObj = edbAcs.Teacher.FirstOrDefault(p => p.BranchId == arrangeCourseObj.BranchId && p.TeacherId == arrangeCourseObj.TeacherId && p.WorkDate == workDate);
                var classroomObj = edbAcs.Classroom.FirstOrDefault(p => p.BranchId == arrangeCourseObj.BranchId && p.ClassroomId == arrangeCourseObj.ClassroomId && p.WorkDate == workDate);

                #region 处理教师和教室返还数据

                teacherObj.CurrTaskNum = teacherObj.CurrTaskNum - 1;//返还任务
                for (var i = 0; i < arrangeCourseObj.ClassTime.Value; i++)//返回时间
                {
                    var strDate = arrangeCourseObj.BeginTime.AddHours(i).ToString("yyyyMMddHHmm");
                    teacherObj.AvailableTime = teacherObj.AvailableTime + "," + strDate;
                    if (arrangeCourseObj.BranchId != 12)
                    {
                        classroomObj.UnavailableTime = classroomObj.UnavailableTime.Replace("," + strDate, "");//处理教室的时间数据返还
                    }
                }
                edbAcs.Entry(teacherObj).State = EntityState.Modified;
                if (arrangeCourseObj.BranchId != 12)
                {
                    edbAcs.Entry(classroomObj).State = EntityState.Modified;
                }

                #endregion

                edbAcs.Entry(arrangeCourseObj).State = EntityState.Deleted;

                return edbAcs.SaveChanges() > 0;

            }
            catch (Exception e)
            {
                // 异常日志消息队列
                Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs
                {
                    ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                    Message = string.Format("StudyBLL-DeleteArrangeCourseById:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink),
                    IsTreat = false,
                    CreateTime = DateTime.Now
                });
                return false;
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 作者:Primo
        /// 日期:2014.07.29
        /// 描述:根据中心区域ID获取教室,重新在Eme库整理后返回
        /// </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.Classroom> CreateClassroomByBranchId(int branchId, DateTime beginDate, DateTime endDate, int createBy, out bool result)
        {
            //教室数据集
            var classroomList = new List<Model.Acs.Classroom>();
            try
            {
                //用于计算时间相隔的天数
                var dateNum = endDate - beginDate;
                //获取中心的所有教室
                var modelClassroom = Eme.BranchBLL.GetClassroomList(branchId);
                //初始化
                result = false;

                var edb = new Model.Acs.EmeAcsEntities();

                for (var i = 0; i <= dateNum.Days; i++)
                {
                    foreach (var item in modelClassroom)
                    {
                        var classroom = new Model.Acs.Classroom
                        {
                            BranchId = branchId,
                            BranchName = item.Branch.CName,
                            ClassroomId = item.Id,
                            ClassroomName = item.ClassroomName,
                            ClassroomTypeId = item.ClassroomTypeId,
                            ClassroomTypeName = item.ClassroomType.CName,
                            ClassroomTypeForProductCourseType = "",
                            MaxBookNum = item.MaxBookNum,
                            WorkDate = beginDate.AddDays(i),
                            CreateBy = createBy,
                            CreateTime = DateTime.Now,
                            UnavailableTime = "",
                            Status = ConvertEnum.StatusTypeForActive
                        };

                        //教室不可用时间 1
                        if (item.Status == ConvertEnum.StatusTypeForInactive)
                        {
                            if (item.RenewTime.HasValue)
                                if (beginDate.AddDays(i) <= item.RenewTime.Value)
                                {
                                    var dateRenewTime = item.RenewTime.Value - beginDate.AddDays(i);
                                    var strRenewTime = new StringBuilder();
                                    for (var renewTimeNum = 0; renewTimeNum <= dateRenewTime.Hours; renewTimeNum++)
                                    {
                                        strRenewTime.AppendFormat(",{0}", beginDate.AddDays(i).AddHours(renewTimeNum).ToString("yyyyMMddHHmm"));
                                    }
                                    classroom.UnavailableTime = strRenewTime.ToString();
                                }
                        }

                        //教室不可用时间 2
                        var modelExistClassroomForArrangeCourse = Eme.StudyBLL.GetExistClassroomForArrangeCourse(classroom.ClassroomId, beginDate.AddDays(i), beginDate.AddDays(i + 1));
                        foreach (var itemExistClassroomForArrangeCourse in modelExistClassroomForArrangeCourse)
                        {
                            classroom.UnavailableTime = string.Format("{0},{1}", classroom.UnavailableTime, itemExistClassroomForArrangeCourse.BeginTime.ToString("yyyyMMddHHmm"));
                        }
                        classroom.UnavailableTime = string.Format("{0},", classroom.UnavailableTime);

                        //教室不可用时间3
                        var modelArrangeCourse = edb.ArrangeCourse.Where(p => p.BeginTime >= beginDate && p.BeginTime < endDate && p.BranchId == branchId && p.ClassroomId == item.Id);
                        foreach (var itemArrangeCourse in modelArrangeCourse)
                        {
                            for (var iac = 0; iac < itemArrangeCourse.ClassTime.Value; iac++)
                            {
                                classroom.UnavailableTime = string.Format("{0},{1}", classroom.UnavailableTime, itemArrangeCourse.BeginTime.AddHours(iac).ToString("yyyyMMddHHmm"));
                            }
                        }

                        //教室可上的课程
                        foreach (var itemClassroomTypeConfig in item.ClassroomType.ClassroomTypeConfig.Where(p =>
                            p.Status == ConvertEnum.StatusTypeForActive && p.BranchId == branchId))
                        {
                            classroom.ClassroomTypeForProductCourseType = string.Format("{0},{1}",
                                classroom.ClassroomTypeForProductCourseType, itemClassroomTypeConfig.ProductCourseTypeId);
                        }
                        //如果课程都是空的,则跳转
                        if (classroom.ClassroomTypeForProductCourseType.Trim(',').Length <= 0)
                        {
                            continue;
                        }
                        else
                        {
                            classroom.ClassroomTypeForProductCourseType = string.Format("{0},", classroom.ClassroomTypeForProductCourseType);
                        }

                        edb.Entry(classroom).State = EntityState.Added;
                        classroomList.Add(classroom);

                        edb.Configuration.ValidateOnSaveEnabled = false;
                        edb.SaveChanges();
                        edb.Configuration.ValidateOnSaveEnabled = true;
                        result = true;
                    }
                }
                return classroomList;
            }
            catch (Exception e)
            {
                // 异常日志消息队列
                Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs
                {
                    ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                    Message = string.Format("BranchBLL-DeleteClassroomByBranchId:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink),
                    IsTreat = false,
                    CreateTime = DateTime.Now
                });
                result = false;
                return classroomList;
            }
        }
Ejemplo n.º 21
0
        /// <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;
            }
        }
Ejemplo n.º 22
0
 /// <summary>
 /// 作者:Primo
 /// 日期:2014.10.30
 /// 描述:创建那些课程是指定只能外教上的,或者指定中教上的
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool CreateTeacherProductLevelCourseTypeCourseConfig(List<Model.Acs.TeacherProductLevelCourseTypeCourseConfig> model)
 {
     try
     {
         var edb = new Model.Acs.EmeAcsEntities();
         foreach (var item in model)
         {
             edb.Entry(item).State = EntityState.Added;
         }
         edb.Configuration.ValidateOnSaveEnabled = false;
         edb.SaveChanges();
         edb.Configuration.ValidateOnSaveEnabled = true;
         return true;
     }
     catch (Exception e)
     {
         // 异常日志消息队列
         Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs
         {
             ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
             Message = string.Format("BranchBLL-CreateTeacherProductLevelCourseTypeCourseConfig:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink),
             IsTreat = false,
             CreateTime = DateTime.Now
         });
         return false;
     }
 }
Ejemplo n.º 23
0
        /// <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;
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 作者:Primo
        /// 日期:2014.08.04
        /// 描述:删除学员 物理删除
        /// </summary>
        /// <param name="branchId"></param>
        /// <param name="beginDate"></param>
        /// <param name="endDate"></param>
        /// <param name="updateBy"></param>
        /// <returns></returns>
        public static bool DeleteStudentByBranchId(int branchId, DateTime beginDate, DateTime endDate, int updateBy)
        {
            var edb = new Model.Acs.EmeAcsEntities();
            try
            {
                var model = (from a in edb.Student
                             where a.BranchId == branchId
                             && a.WorkDate >= beginDate
                             && a.WorkDate <= endDate
                             select a);

                if (model.Count() <= 0)
                {
                    return true;
                }
                else
                {
                    foreach (var item in model)
                    {
                        edb.Entry(item).State = EntityState.Deleted;
                    }
                    edb.SaveChanges();
                    return true;
                }
            }
            catch (Exception e)
            {
                return false;
            }
        }