Example #1
0
        /// <summary>
        /// 根据学期获取停课日
        /// <para>作    者:zhiwei.Tang</para>
        /// <para>创建时间:2018-11-08</para>
        /// </summary>
        /// <param name="term">学期信息</param>
        /// <returns>停课时间段数据列表</returns>
        internal static List <SchoolHolidayResponse> GetSchoolHoliday(TblDatTerm term)
        {
            SchoolHolidayService beginSchoolHoliday = new SchoolHolidayService(term.SchoolId, term.BeginDate.Year);
            SchoolHolidayService endSchoolHoliday   = new SchoolHolidayService(term.SchoolId, term.EndDate.Year);

            List <SchoolHolidayResponse> beginSchoolHolidayResponses = beginSchoolHoliday.GetWeekDayHolidayList().Result;
            List <SchoolHolidayResponse> endSchoolHolidayResponses   = endSchoolHoliday.GetWeekDayHolidayList().Result;

            List <SchoolHolidayResponse> schoolHoliday = beginSchoolHolidayResponses.Union(endSchoolHolidayResponses).ToList();

            return(schoolHoliday);
        }
Example #2
0
        /// <summary>
        /// 获取插班补上本学期已上课程数
        /// <para>作    者:zhiwei.Tang</para>
        /// <para>创建时间:2018-11-07</para>
        /// </summary>
        /// <param name="firstTime">首次上课时间</param>
        /// <returns>插班补上本学期已上课程数</returns>
        /// <exception cref="BussinessException">
        /// 异常ID:1 异常描述:学期信息为空
        /// </exception>
        public int GetTransferLessonByFirstTime(DateTime?firstTime)
        {
            int transferLesson = 0;

            //1.获取学期信息
            var termInfo = TermService.GetTermByTermId(TblDatClass.TermId);

            if (termInfo == null)
            {
                throw new BussinessException(ModelType.Default, 1);
            }

            if (!firstTime.HasValue)
            {
                firstTime = termInfo.BeginDate;
            }

            //时间不在学期的开始、结束范围类则没有插班补课
            if (firstTime < termInfo.BeginDate || firstTime > termInfo.EndDate)
            {
                return(transferLesson);
            }

            //2.获取停课日
            List <SchoolHolidayResponse> schoolHoliday = TermService.GetSchoolHoliday(termInfo);

            while (termInfo.BeginDate < firstTime)
            {
                //今天
                DateTime today = termInfo.BeginDate;

                termInfo.BeginDate = termInfo.BeginDate.AddDays(1);

                bool isClosed = SchoolHolidayService.TodayIsSuspendClasses(schoolHoliday, today);
                if (isClosed)
                {
                    continue;
                }

                int weekDay = WeekDayConvert.DayOfWeekToInt(today);

                var todayClassTimes = ClassSchoolTimes
                                      .Where(x => x.WeekDay == weekDay)
                                      .OrderBy(x => x.BeginTime)
                                      .ToList();
                if (todayClassTimes.Count == 0)
                {
                    continue;
                }

                var firstClassTime = todayClassTimes.FirstOrDefault();

                if (todayClassTimes.Count == 1)
                {
                    switch ((TimeType)firstClassTime.Duration)
                    {
                    case TimeType.Sixty when termInfo.Classes60 <= transferLesson:
                        return(transferLesson);

                    case TimeType.Ninety when termInfo.Classes60 <= transferLesson:
                        return(transferLesson);
                    }
                }
                else
                {
                    if (termInfo.Classes180 <= transferLesson)
                    {
                        return(transferLesson);
                    }
                }

                transferLesson += todayClassTimes.Count;
            }

            return(transferLesson);
        }
Example #3
0
        /// <summary>
        /// 获取排课课次信息列表
        /// <para>作    者:zhiwei.Tang</para>
        /// <para>创建时间:2019-02-19</para>
        /// </summary>
        /// <returns>课次信息列表</returns>
        public List <LessonCreatorInfo> GetLessonCreatorInfo()
        {
            List <LessonCreatorInfo> res = new List <LessonCreatorInfo>();

            //校验排课信息是否为空
            ValidateObject(_makeLesson);

            if (_makeLesson.IsConfirm)
            {
                throw new BussinessException(ModelType.SignUp, 9);
            }

            //1.获取学期信息
            var termInfo = TermService.GetTermByTermId(_classService.TblDatClass.TermId);

            ValidateObject(termInfo);

            //订单明细
            TblOdrEnrollOrderItem orderItem =
                _enrollOrderItemRepository.Load(_makeLesson.EnrollOrderItemId);
            //订单
            TblOdrEnrollOrder order =
                _enrollOrderRepository.Load(orderItem.EnrollOrderId);

            //2.获取停课日
            List <SchoolHolidayResponse> schoolHoliday = TermService.GetSchoolHoliday(termInfo);

            //上课时间
            DateTime classDate = _makeLesson.FirstClassTime;

            //首次上课日期大于学期结束日期则没有课次
            if (classDate > termInfo.EndDate)
            {
                return(res);
            }

            //首次上课日期未到学期开始时间取学期设置开始日期
            if (classDate < termInfo.BeginDate)
            {
                classDate = termInfo.BeginDate;
            }

            bool     isStandard180 = this.IsStandard180(_classService.ClassSchoolTimes);                 //180分钟
            TimeType duration      = (TimeType)_classService.ClassSchoolTimes.FirstOrDefault().Duration; //时长

            int standard180     = termInfo.Classes180;                                                   //设置180分钟标准
            int makeLessonTotal = _makeLesson.ClassTimes;                                                //设置排课总数

            if (isStandard180)
            {
                //180分钟设置的标准是否是奇数
                bool class180IsOddNumber = Convert.ToBoolean(termInfo.Classes180 % 2);
                standard180 = class180IsOddNumber ? termInfo.Classes180 - 1 : termInfo.Classes180;

                //排课是否是奇数
                bool makeIsOddNumber = Convert.ToBoolean(_makeLesson.ClassTimes % 2);
                //报名课次数量 考虑180分钟排2个课次的完整性
                makeLessonTotal = makeIsOddNumber ? _makeLesson.ClassTimes - 1 : _makeLesson.ClassTimes;
            }

            //上课日期大于学期结束日期停止排课
            while (classDate <= termInfo.EndDate)
            {
                //当天是否停课
                bool isClosed = SchoolHolidayService.TodayIsSuspendClasses(schoolHoliday, classDate);

                if (isClosed)
                {
                    classDate = classDate.AddDays(1);
                    continue;
                }

                int week = WeekDayConvert.DayOfWeekToInt(classDate);

                List <TblDatSchoolTime> classTimes = _classService.ClassSchoolTimes
                                                     .Where(x => x.WeekDay == week)
                                                     .OrderBy(x => x.BeginTime)
                                                     .ToList();

                //处理上课时间发生变化
                var changeTimes = _viewChangeClassTimeDates
                                  .Where(x => x.OldClassDate == classDate)
                                  .OrderBy(x => x.NewClassBeginTime)
                                  .ToList();

                if (!classTimes.Any() && !changeTimes.Any())
                {
                    classDate = classDate.AddDays(1);
                    continue;
                }

                //180分钟课程
                if (duration == TimeType.Ninety && isStandard180 == true)
                {
                    if (!changeTimes.Any())
                    {
                        var ct1 = classTimes[0];
                        var ct2 = classTimes[1];

                        res.Add(this.GetCreatorInfo(classDate, ct1.BeginTime, ct1.EndTime, termInfo.SchoolId, order.StudentId, termInfo.TermId));
                        res.Add(this.GetCreatorInfo(classDate, ct2.BeginTime, ct2.EndTime, termInfo.SchoolId, order.StudentId, termInfo.TermId));
                    }
                    else
                    {
                        var ct1 = changeTimes[0];
                        var ct2 = changeTimes[1];

                        res.Add(this.GetCreatorInfo(ct1.NewClassDate, ct1.NewClassBeginTime, ct1.NewClassEndTime, termInfo.SchoolId, order.StudentId, termInfo.TermId));
                        res.Add(this.GetCreatorInfo(ct2.NewClassDate, ct2.NewClassBeginTime, ct2.NewClassEndTime, termInfo.SchoolId, order.StudentId, termInfo.TermId));
                    }

                    _lessonCount += 2;
                }
                else
                {
                    if (!changeTimes.Any())
                    {
                        var ct1 = classTimes[0];
                        res.Add(this.GetCreatorInfo(classDate, ct1.BeginTime, ct1.EndTime, termInfo.SchoolId, order.StudentId, termInfo.TermId));
                    }
                    else
                    {
                        var ct1 = changeTimes[0];
                        res.Add(this.GetCreatorInfo(ct1.NewClassDate, ct1.NewClassBeginTime, ct1.NewClassEndTime, termInfo.SchoolId, order.StudentId, termInfo.TermId));
                    }

                    _lessonCount += 1;
                }

                //上课时间大于学期结束时间停止排课或者预计排课课次等于实际排课课次停止排课
                if (this._lessonCount == makeLessonTotal)
                {
                    return(res);
                }
                //执行60分钟标准
                else if (duration == TimeType.Sixty && this._lessonCount == termInfo.Classes60)
                {
                    return(res);
                }
                //执行90分钟标准
                else if (duration == TimeType.Ninety && isStandard180 == false && this._lessonCount == termInfo.Classes90)
                {
                    return(res);
                }
                //执行180分钟标准
                else if (duration == TimeType.Ninety && isStandard180 == true && this._lessonCount == standard180)
                {
                    return(res);
                }

                classDate = classDate.AddDays(1);
            }

            return(res);
        }
Example #4
0
        /// <summary>
        /// 根据首次上课时间获取排课最大课次
        /// <para>作    者:zhiwei.Tang</para>
        /// <para>创建时间:2018-11-05</para>
        /// </summary>
        /// <param name="firstTime">首次上课时间</param>
        /// <returns>获取排课最大课次</returns>
        /// <exception cref="BussinessException">
        /// 异常ID:1 异常描述:学期信息为空
        /// </exception>
        public int GetMaximumLessonByFirstTime(DateTime firstTime)
        {
            int maximumLesson = 0;

            //1.获取学期信息
            var termInfo = TermService.GetTermByTermId(TblDatClass.TermId);

            if (termInfo == null)
            {
                throw new BussinessException(ModelType.Default, 1);
            }

            //获取停课日
            List <SchoolHolidayResponse> schoolHoliday = TermService.GetSchoolHoliday(termInfo);

            //首次上课时间大于学期结束时间则没有课次
            if (firstTime > termInfo.EndDate)
            {
                return(maximumLesson);
            }

            //首次上课时间小于学期开始时间则以学期开始时间为准
            if (firstTime < termInfo.BeginDate)
            {
                firstTime = termInfo.BeginDate;
            }

            bool     isStandard180 = this.IsStandard180(ClassSchoolTimes);                 //180分钟
            TimeType duration      = (TimeType)ClassSchoolTimes.FirstOrDefault().Duration; //时长

            while (firstTime <= termInfo.EndDate)
            {
                //判断停课日
                bool isClosed = SchoolHolidayService.TodayIsSuspendClasses(schoolHoliday, firstTime);
                if (isClosed)
                {
                    firstTime = firstTime.AddDays(1);
                    continue;
                }

                //执行60分钟标准
                if (duration == TimeType.Sixty && maximumLesson == termInfo.Classes60)
                {
                    return(maximumLesson);
                }
                //执行90分钟标准
                else if (duration == TimeType.Ninety && !isStandard180 && maximumLesson == termInfo.Classes90)
                {
                    return(maximumLesson);
                }
                //执行180分钟标准
                else if (duration == TimeType.Ninety && isStandard180 && maximumLesson >= termInfo.Classes180)
                {
                    //180分钟标准由90分钟标准构成
                    //180分钟标准设置可能会是奇数
                    //最大课次排课超过标准,则按标准执行
                    if (maximumLesson > termInfo.Classes180)
                    {
                        return(termInfo.Classes180);
                    }
                    break;
                }

                int weekDay = WeekDayConvert.DayOfWeekToInt(firstTime);

                int lessonCount = ClassSchoolTimes.Count(x => x.WeekDay == weekDay);

                maximumLesson += lessonCount;

                firstTime = firstTime.AddDays(1);
            }

            return(maximumLesson);
        }
        /// <summary>
        /// 描述:获取可转入的课次信息
        /// <para>作    者:瞿琦</para>
        /// <para>创建时间:2018-11-7</para>
        /// </summary>
        /// <exception cref="AMS.Core.BussinessException">
        /// 异常Id:1,异常描述:未找到数据
        /// 异常Id:71,异常描述:转入班级时间段和课次信息调整时间段不一致
        /// </exception>
        /// <returns>可转入课次信息列表</returns>
        public List <LessonCreatorInfo> GetLessonCreatorInfo()
        {
            var result = new List <LessonCreatorInfo>();
            //获取转入班级信息
            var classService = new DefaultClassService(base._entity.InClassId);
            var firstTime    = base._entity.InDate;
            //1.获取学期信息
            var termInfo = TermService.GetTermByTermId(classService.TblDatClass.TermId);

            if (termInfo == null)
            {
                throw new BussinessException(ModelType.Default, 1);
            }
            //2.获取停课日
            var schoolHoliday = TermService.GetSchoolHoliday(termInfo);

            //首次上课时间大于学期结束时间则没有课次
            if (firstTime > termInfo.EndDate)
            {
                return(result);
            }
            //首次上课时间小于学期开始时间,则首次上课时间等于学期开始时间
            if (firstTime < termInfo.BeginDate)
            {
                firstTime = termInfo.BeginDate;
            }

            while (firstTime <= termInfo.EndDate)
            {
                //上课时间大于学期结束时间或者预计排课课次等于实际排课课次,则停止排课
                if (firstTime > termInfo.EndDate || _entity.ClassTimes == _actualLesson)
                {
                    break;
                }

                var isClosed = SchoolHolidayService.TodayIsSuspendClasses(schoolHoliday, firstTime);
                //当前时间是否是停课日,如果是则加1
                if (isClosed)
                {
                    firstTime = firstTime.AddDays(1);
                    continue;
                }
                //星期转换
                var week = WeekDayConvert.DayOfWeekToInt(firstTime);
                //获取与当前时间匹配的班级上课时间
                var schoolTimes = classService.ClassSchoolTimes.Where(x => x.WeekDay == week).OrderBy(x => x.BeginTime).ToList();

                //获取班级是否有课程信息调整(上课日期和上课时间段 修改)
                var classDateChangeList = _viewChangeClassTimeDates.Where(x => x.OldClassDate == firstTime).OrderBy(x => x.NewClassBeginTime).ToList();
                if (classDateChangeList.Count > 0 && classDateChangeList.Count != schoolTimes.Count)  //如果班级设置的上课时间段和课程调整的时间段不一致则抛出异常
                {
                    throw new BussinessException(ModelType.Timetable, 71);
                }
                var lessonCount = 0;
                foreach (var time in schoolTimes)
                {
                    var lesson = new LessonCreatorInfo
                    {
                        BusinessId        = base._entity.ChangeClassId,
                        BusinessType      = base.BusinessType,
                        ClassId           = base._entity.InClassId,
                        ClassDate         = firstTime,
                        ClassBeginTime    = time.BeginTime,
                        ClassEndTime      = time.EndTime,
                        ClassRoomId       = classService.TblDatClass.ClassRoomId,
                        CourseId          = classService.TblDatClass.CourseId,
                        CourseLevelId     = classService.TblDatClass.CourseLeveId,
                        EnrollOrderItemId = _enrollOrderItemId,
                        SchoolId          = termInfo.SchoolId,
                        StudentId         = base._entity.StudentId,
                        TeacherId         = classService.TblDatClass.TeacherId,
                        TermId            = termInfo.TermId
                    };
                    //获取是否有老师调课
                    var teacherLessonChangeInfo = _viewClassTeacherDates.FirstOrDefault(x => x.ClassId == lesson.ClassId && x.ClassDate == lesson.ClassDate);
                    if (teacherLessonChangeInfo != null && teacherLessonChangeInfo.TeacherId.Trim() != lesson.TeacherId.Trim())
                    {
                        lesson.TeacherId = teacherLessonChangeInfo.TeacherId;
                    }
                    //获取班级是否有修改上课日期和上课时间段,并赋值
                    if (classDateChangeList.Any())
                    {
                        lesson.ClassDate      = classDateChangeList[lessonCount].NewClassDate;
                        lesson.ClassBeginTime = classDateChangeList[lessonCount].NewClassBeginTime;
                        lesson.ClassEndTime   = classDateChangeList[lessonCount].NewClassEndTime;
                    }
                    result.Add(lesson);
                    lessonCount++;
                    //实际排课课次+1
                    _actualLesson++;
                }
                firstTime = firstTime.AddDays(1);
            }
            return(result);
        }