/// <summary>
        /// 过滤学期课程表未排课的上课时间段
        /// <para>作    者:zhiwei.Tang</para>
        /// <para>创建时间:2018-11-06</para>
        /// </summary>
        /// <param name="termCourse">90分钟或60分钟课程表</param>
        /// <returns>课程表明细数据</returns>
        private TermCourseTimetableResponse TermCourseTimetableResponseFilter(TermCourseTimetableResponse termCourse)
        {
            List <TblDatSchoolTime> scheduledTimes = GetScheduledTimes(termCourse.ClassRooms, _termId); //获取已排课的时间段

            termCourse.SchoolTimes = GetSchoolTimeResponse(termCourse.SchoolTimes, scheduledTimes);     //渲染上课时间段

            termCourse.ClassRooms = GetClassRoomResponse(termCourse, scheduledTimes);                   //渲染上课时间段对应的班级

            return(termCourse);
        }
        /// <summary>
        /// 渲染上课时间段对应的班级
        /// <para>作    者:zhiwei.Tang</para>
        /// <para>创建时间:2018-11-06</para>
        /// </summary>
        /// <param name="termCourse">学期课程信息</param>
        /// <param name="scheduledTimes">已排课列表</param>
        /// <returns>课程表教室列表</returns>
        private static List <TimetableClassRoomResponse> GetClassRoomResponse(TermCourseTimetableResponse termCourse, List <TblDatSchoolTime> scheduledTimes)
        {
            List <TimetableClassRoomResponse> classRooms = new List <TimetableClassRoomResponse>();

            foreach (var classRoom in termCourse.ClassRooms)
            {
                TimetableClassRoomResponse newClassRoom = new TimetableClassRoomResponse
                {
                    ClassRoomId = classRoom.ClassRoomId,
                    RoomNo      = classRoom.RoomNo,
                    Classes     = new List <TimetableClassResponse>()
                };

                foreach (var scheduledTime in scheduledTimes)
                {
                    newClassRoom.Classes.Add(classRoom.Classes.FirstOrDefault(x => x.SchoolTimeId == scheduledTime.SchoolTimeId));
                }

                classRooms.Add(newClassRoom);
            }

            return(classRooms);
        }
Esempio n. 3
0
        /// <summary>
        /// 获取不同时间段的课表信息
        /// <para>作    者:zhiwei.Tang</para>
        /// <para>创建时间:2018-09-21</para>
        /// </summary>
        /// <param name="duration">60分钟或90分钟</param>
        /// <returns>课表信息</returns>
        private TermCourseTimetableResponse GetTermCourseTimetable(TimeType duration)
        {
            TermCourseTimetableResponse res = new TermCourseTimetableResponse();

            var schTimeRes = this.GetTimetableSchoolTimeResponse(duration);

            res.SchoolTimes = schTimeRes.TimetableSchoolTimeResponses;        //上课时间表
            res.ClassRooms  = new List <TimetableClassRoomResponse>();        //教室信息

            //审核中所有班级
            var classes = _tblAutClassRepository.Value.GetByAuditId(base.TblAutAudit.AuditId).Result;

            //校区
            var schoolId = TermService.GetTermByTermId(_termId)?.SchoolId;

            //班级上课时间表
            var classTimes = new TblAutClassTimeRepository()
                             .GetBySchoolTimeId(schTimeRes.TblDatSchoolTimes.Select(x => x.SchoolTimeId), base.TblAutAudit.AuditId)
                             .Result;

            //获取老师用户信息
            var teachers = TeachService.GetTeachers();

            //所有的课程
            var courses = CourseService.GetAllAsync().Result;

            //课程等级
            var courseLv = CourseLevelService.GetCourseLevelList().Result;

            //获取校区教室
            var durationClassId = classTimes.Select(x => x.ClassId).ToList();
            SchoolClassRoomService    schoolClassRoomService = new SchoolClassRoomService(schoolId);
            List <RoomCourseResponse> roomCourseResponses    = schoolClassRoomService.RoomCourseList;

            List <long> classRoomIds = classes.Where(x => durationClassId.Contains(x.ClassId)).Select(x => x.ClassRoomId).ToList();

            classRoomIds.AddRange(roomCourseResponses.Where(x => !x.IsDisabled).Select(x => x.ClassRoomId));

            List <TblDatClassRoom> classRooms = schoolClassRoomService
                                                .ClassRoomList
                                                .Where(x => classRoomIds.Contains(x.ClassRoomId))
                                                .OrderBy(o => o.RoomNo, new NaturalStringComparer())
                                                .ToList();

            //渲染教室
            foreach (var classRoom in classRooms)
            {
                TimetableClassRoomResponse ttcrr = new TimetableClassRoomResponse
                {
                    ClassRoomId = classRoom.ClassRoomId,
                    RoomNo      = classRoom.RoomNo,
                    Classes     = new List <TimetableClassResponse>()
                };

                int lessonIndex = 0;

                int weekDay = -1;

                //教室对应的上课时间段的班级
                foreach (var schoolTime in schTimeRes.TblDatSchoolTimes)
                {
                    if (weekDay != schoolTime.WeekDay)
                    {
                        weekDay     = schoolTime.WeekDay;
                        lessonIndex = 0;
                    }

                    lessonIndex++;

                    TimetableClassResponse ttcr = new TimetableClassResponse
                    {
                        SchoolTimeId    = schoolTime.SchoolTimeId,
                        ClassId         = 0,
                        CourseId        = 0,
                        CourseName      = string.Empty,
                        CourseLeveId    = 0,
                        CourseLevelName = string.Empty,
                        TeacherId       = string.Empty,
                        TeacherName     = string.Empty,
                        WeekDay         = schoolTime.WeekDay,
                        LessonIndex     = lessonIndex
                    };

                    var classIds = (from a in classTimes
                                    join b in classes on a.ClassId equals b.ClassId
                                    where a.SchoolTimeId == schoolTime.SchoolTimeId && b.ClassRoomId == classRoom.ClassRoomId
                                    select a.ClassId).ToList();

                    if (classIds.Any())
                    {
                        var classInfo = classes.FirstOrDefault(x => x.ClassId == classIds.First());
                        ttcr.ClassId         = classInfo.ClassId;
                        ttcr.CourseId        = classInfo.CourseId;
                        ttcr.CourseName      = courses.FirstOrDefault(x => x.CourseId == classInfo.CourseId)?.ShortName;
                        ttcr.CourseLeveId    = classInfo.CourseLeveId;
                        ttcr.CourseLevelName = courseLv.FirstOrDefault(x => x.CourseLevelId == classInfo.CourseLeveId)?.LevelCnName;
                        ttcr.TeacherId       = classInfo.TeacherId;
                        ttcr.TeacherName     = teachers.FirstOrDefault(x => x.TeacherId == classInfo.TeacherId)?.TeacherName;
                    }

                    ttcrr.Classes.Add(ttcr);
                }

                res.ClassRooms.Add(ttcrr);
            }

            return(res);
        }