/// <summary>
        /// 获取常规课多个时间段上课信息
        /// <para>作    者:zhiwei.Tang</para>
        /// <para>创建时间:2019-03-07</para>
        /// </summary>
        /// <param name="regularAttends">常规课次信息</param>
        /// <param name="res">out 常规课多个上课信息</param>
        private static void GetMultiAttendRegular(
            List <ViewStudentScanCodeAttend> regularAttends,
            List <ScanCodeClassInfo> res)
        {
            var classIdList  = regularAttends.Select(x => x.ClassId).Distinct().ToList();  //班级ID列表
            var courseIdList = regularAttends.Select(x => x.CourseId).Distinct().ToList(); //课程ID列表

            //获取课程信息列表
            var courseList = CourseService.GetByCourseId(courseIdList);

            foreach (var classId in classIdList)
            {
                var regularAttend = regularAttends.FirstOrDefault(x => x.ClassId == classId);
                var courseInfo    = courseList.FirstOrDefault(x => x.CourseId == regularAttend?.CourseId);

                //上课时间
                var classTimeList = regularAttends
                                    .OrderBy(x => x.ClassBeginTime)
                                    .Select(x => x.ClassBeginTime + '-' + x.ClassEndTime)
                                    .ToList();

                ScanCodeClassInfo scanCode = new ScanCodeClassInfo
                {
                    ClassId   = classId,
                    ClassName = courseInfo?.ClassCnName ?? string.Empty,
                    ClassTime = string.Join(" ", classTimeList)
                };

                res.Add(scanCode);
            }
        }
        /// <summary>
        /// 正常考勤补签
        /// <para>作    者:zhiwei.Tang</para>
        /// <para>创建时间:2019-03-12</para>
        /// </summary>
        /// <param name="lessonStudent">学生考勤</param>
        /// <exception cref="BussinessException">
        /// 异常ID:48 异常描述:未找到考勤信息
        /// 异常ID:49 异常描述:补签老师与上课老师不一致
        /// 异常ID:50 异常描述:当前状态不可补签
        /// </exception>
        private void UpdateStuAttend(ViewTimLessonStudent lessonStudent)
        {
            if (lessonStudent == null)
            {
                //未找到考勤信息
                throw new BussinessException(ModelType.Timetable, 48);
            }

            //校验是否绑定家校互联
            this.VerifyStudentBindWeiXin(lessonStudent.StudentId);

            if (!this._teacherId.Equals(lessonStudent.TeacherId, StringComparison.Ordinal))
            {
                //补签老师与上课老师不一致
                throw new BussinessException(ModelType.Timetable, 49);
            }
            if (lessonStudent.AttendStatus == (int)AttendStatus.Normal)
            {
                //当前状态不可补签
                throw new BussinessException(ModelType.Timetable, 50);
            }
            if (lessonStudent.AdjustType != (int)AdjustType.DEFAULT)
            {
                //当前状态不可补签
                throw new BussinessException(ModelType.Timetable, 50);
            }

            //如果是180分钟的课次会有两条课次信息 这里获取下面批量更新
            var lessonList = _viewLessonStudentRepository.Value
                             .GetLessonList(lessonStudent.SchoolId, lessonStudent.ClassId,
                                            lessonStudent.ClassDate, lessonStudent.StudentId);

            var stuLessonIdList = lessonList.Select(x => x.LessonStudentId);

            string replenishCode = Guid.NewGuid().ToString().Replace("-", "");

            //更新插班补课考勤课次
            _lessonStudentRepository.Value.UpdateStuAttend(stuLessonIdList,
                                                           AdjustType.SUPPLEMENTNOTCONFIRMED, AttendStatus.NotClockIn,
                                                           DateTime.Now, replenishCode);

            //微信通知

            //班级名称
            string className = CourseService.GetByCourseId(lessonStudent.CourseId)?.ClassCnName ?? string.Empty;

            //上课时间段
            var    classTimeList = lessonList.Select(x => x.ClassBeginTime + "-" + x.ClassEndTime);
            string classTime     = $"{lessonStudent.ClassDate.ToString("yyyy.MM.dd")} {string.Join("、", classTimeList)}";

            //教室
            var    roomService = new ClassRoomService(lessonStudent.ClassRoomId);
            string classRoom   = roomService.ClassRoomInfo?.RoomNo ?? string.Empty;

            //推送
            this.PushWeChatNotice(lessonStudent.StudentId, className, classRoom, classTime, replenishCode);
        }
        /// <summary>
        /// 获取已安排补课或调课的详情
        /// <para>作    者:zhiwei.Tang</para>
        /// <para>创建时间:2019-03-12</para>
        /// </summary>
        /// <param name="studentId">学生Id</param>
        /// <param name="lessonId">课次ID</param>
        /// <returns>调课详情/补课详情</returns>
        public StudentReplenishLessonsResponse GetStudentReplenishLessons(long studentId, long lessonId)
        {
            var studentAttendance = _viewCompleteStudentAttendanceRepository.Value.GetLesson(lessonId);

            if (studentAttendance == null)
            {
                //未找到该学生的补课信息
                throw new BussinessException(ModelType.Timetable, 47);
            }

            if (studentAttendance.StudentId != studentId)
            {
                //未找到该学生的补课信息
                throw new BussinessException(ModelType.Timetable, 47);
            }

            //获取一个班级学生的课次信息
            var stuDayAttendances = _viewCompleteStudentAttendanceRepository.Value.GetStudetnDayLessonList(
                studentAttendance.SchoolId, studentAttendance.ClassId, studentAttendance.ClassDate,
                studentId, LessonType.RegularCourse);

            var lessonIds  = stuDayAttendances.Select(x => x.LessonId).ToList();
            var stuLessons = _viewTimReplenishLessonStudentRepository.Value.GetLessonListByParentLessonId(lessonIds);

            if (stuLessons == null || !stuLessons.Any())
            {
                //未找到该学生的补课信息
                throw new BussinessException(ModelType.Timetable, 47);
            }

            var stuLesson = stuLessons.OrderBy(x => x.ClassBeginTime).FirstOrDefault();

            string classTime = string.Join(" ", stuLessons.Select(x => x.ClassBeginTime + "-" + x.ClassEndTime));

            var classInfo = new DefaultClassService(stuLesson.ClassId).TblDatClass;

            StudentReplenishLessonsResponse res = new StudentReplenishLessonsResponse
            {
                ClassId     = stuLesson.ClassId,
                ClassName   = CourseService.GetByCourseId(stuLesson.CourseId)?.ClassCnName,
                ClassRoom   = new ClassRoomService(stuLesson.ClassRoomId).ClassRoomInfo?.RoomNo,
                ClassTime   = classTime,
                ClassDate   = stuLesson.ClassDate.ToString("yyyy.MM.dd"),
                ClassNo     = new DefaultClassService(stuLesson.ClassId).TblDatClass?.ClassNo,
                TeacherName = TeachService.GetTeacher(stuLesson.TeacherId)?.TeacherName,
                Week        = WeekDayConvert.DayOfWeekToString(stuLesson.ClassDate.DayOfWeek)
            };

            return(res);
        }
        /// <summary>
        /// 微信通知
        /// <para>作    者:zhiwei.Tang</para>
        /// <para>创建时间:2019-03-15</para>
        /// </summary>
        private void PushWeChatNoticeStart(List <ViewStudentScanCodeAttend> stuAttends, DateTime attendTime)
        {
            List <long> cIds = stuAttends.Select(x => x.ClassId).Distinct().ToList();

            foreach (var item in cIds)
            {
                var    temp          = stuAttends.Where(x => x.ClassId == item).ToList();
                var    model         = temp.FirstOrDefault();
                var    classTimeList = temp.Select(x => x.ClassBeginTime + "-" + x.ClassEndTime);
                string classTime     = $"{model.ClassDate:yyyy.MM.dd} {string.Join("、", classTimeList)}"; //上课时间段
                var    classService  = new DefaultClassService(item);
                var    classInfo     = classService.TblDatClass;
                var    classRoom     = new ClassRoomService(classInfo.ClassRoomId).ClassRoomInfo.RoomNo; //教室门牌号

                var className = CourseService.GetByCourseId(classInfo.CourseId)?.ClassCnName;            //班级名称

                PushWeChatNotice(className, classTime, classRoom, attendTime);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取的排课详情
        /// <para>作    者:zhiwei.Tang</para>
        /// <para>创建时间:2018-11-06</para>
        /// </summary>
        /// <param name="enrollOrderItemId">报名课程订单Id</param>
        /// <returns>学生报名一个课程的排课详细信息</returns>
        public MakeLessonDetailResponse GetMakeLessonDetail(long enrollOrderItemId)
        {
            MakeLessonDetailResponse res = new MakeLessonDetailResponse
            {
                CourseInfos = new List <CourseInformation>()
            };

            TblOdrEnrollOrderItem enrollOrderItem = _enrollOrderItemRepository.Load(enrollOrderItemId);
            TblOdrEnrollOrder     enrollOrder     = _enrollOrderRepository.Load(enrollOrderItem.EnrollOrderId);

            TblDatCourse course = CourseService.GetByCourseId(enrollOrderItem.CourseId);

            res.RegisterInfo = new RegisterInformation()
            {
                ClassTimes    = enrollOrderItem.ClassTimes,
                ClassTimesUse = enrollOrderItem.ClassTimesUse,
                CourseName    = string.Empty,
                LevelName     = CourseLevelService.GetById(enrollOrderItem.CourseLevelId)?.LevelCnName ?? string.Empty,
                Year          = enrollOrderItem.Year,
                CourseType    = CourseType.Elective,
                TermTypeId    = enrollOrderItem.TermTypeId,
                TermTypeName  = TermTypeService.GetTermTypeName(enrollOrderItem.TermTypeId),
                EnrollDate    = enrollOrder.CreateTime
            };

            if (course != null)
            {
                res.RegisterInfo.CourseName = course.ShortName;
                res.RegisterInfo.CourseType = CourseType.Compulsory;
            }

            List <TblTimMakeLesson> makeLessons =
                _makeLessonRepository.GetUnconfirmedMakeLessonList(enrollOrderItem.EnrollOrderItemId);

            if (makeLessons.Any())
            {
                List <long> classIds = makeLessons.Select(x => x.ClassId).ToList();

                List <TblDatClass> classes = DefaultClassService.GetClassByClassIdAsync(classIds).Result;

                List <ViewRoomCourse> classRooms = ClassRoomService.GetClassRoomBySchoolId(enrollOrder.SchoolId);

                //老师
                var teacherList = TeachService.GetTeachers();

                foreach (var makeLesson in makeLessons)
                {
                    var classInfo        = classes.FirstOrDefault(x => x.ClassId == makeLesson.ClassId);
                    var classSchoolTimes = new DefaultClassService(classInfo.ClassId).ClassSchoolTimes;
                    //老师信息
                    var teacher = teacherList.FirstOrDefault(x => x.TeacherId == classInfo.TeacherId);

                    CourseInformation courseInformation = new CourseInformation
                    {
                        ClassId        = classInfo.ClassId,
                        Year           = enrollOrderItem.Year,
                        ClassNo        = classInfo.ClassNo,
                        ClassTimesUse  = makeLesson.ClassTimes,
                        CourseName     = course?.ShortName ?? string.Empty,
                        FirstClassTime = makeLesson.FirstClassTime,
                        RoomNo         = classRooms.FirstOrDefault(x => x.ClassRoomId == classInfo.ClassRoomId)?.RoomNo ?? string.Empty,
                        LevelName      = CourseLevelService.GetById(classInfo.CourseLeveId)?.LevelCnName ?? string.Empty,
                        TeacherName    = teacher?.TeacherName ?? string.Empty,
                        TermName       = TermService.GetTermByTermId(classInfo.TermId)?.TermName ?? string.Empty,
                        Week           = classSchoolTimes.Select(x => x.WeekDay)
                                         .Distinct()
                                         .OrderBy(x => x)
                                         .Select(x => WeekDayConvert.IntToString(x))
                                         .ToList(),
                        PeriodTime = new List <string>()
                    };

                    foreach (var item in classSchoolTimes)
                    {
                        string time = item.BeginTime + "-" + item.EndTime;
                        if (courseInformation.PeriodTime.Any(x => x == time))
                        {
                            continue;
                        }
                        courseInformation.PeriodTime.Add(time);
                    }

                    res.CourseInfos.Add(courseInformation);
                }
            }

            return(res);
        }
        /// <summary>
        /// 微信通知
        /// <para>作    者:zhiwei.Tang</para>
        /// <para>创建时间:2019-03-15</para>
        /// </summary>
        private void PushWeChatNotice()
        {
            var stuInfo  = StudentService.GetStudentInfo(_request.StudentId);
            var inLesson = this._inLessonList.FirstOrDefault();

            string pushClassTime = this._outLessonList
                                   .Select(x => DateTime.Parse(x.ClassDate.ToString("yyyy-MM-dd") + " " + x.ClassBeginTime))
                                   .Min().ToString("yyyy.MM.dd HH:mm");

            //first={0}家长,您好!因{1}于{2}请假,为了保证孩子的学习效果,我们特别为孩子安排了补课,具体时间如下:
            string title =
                string.Format(
                    ClientConfigManager.HssConfig.WeChatTemplateTitle.MakeupNotice,
                    stuInfo.StudentName, stuInfo.StudentName, pushClassTime);

            //keyword1=上课时间
            var    classTimeList = this._inLessonList.Select(x => x.ClassBeginTime + "-" + x.ClassEndTime);
            string classTime     = $"{inLesson.ClassDate.ToString("yyyy.MM.dd")} {string.Join("、", classTimeList)}";

            //keyword2=班级名称
            string className = CourseService.GetByCourseId(inLesson.CourseId)?.ClassCnName ?? string.Empty;

            //keyword3=教室
            string classRoom = new ClassRoomService(inLesson.ClassRoomId)?.ClassRoomInfo?.RoomNo ?? string.Empty;

            //keyword4=老师名称
            string teacherName = TeachService.GetTeacher(inLesson.TeacherId)?.TeacherName ?? string.Empty;

            //remark=校区名称
            string schoolName = OrgService.GetSchoolBySchoolId(_schoolId)?.SchoolName ?? string.Empty;

            WxNotifyProducerService wxNotifyProducerService = WxNotifyProducerService.Instance;
            WxNotifyInDto           wxNotify = new WxNotifyInDto
            {
                Data = new List <WxNotifyItemInDto> {
                    new WxNotifyItemInDto {
                        DataKey = "first", Value = title
                    },
                    new WxNotifyItemInDto {
                        DataKey = "keyword1", Value = classTime
                    },
                    new WxNotifyItemInDto {
                        DataKey = "keyword2", Value = className
                    },
                    new WxNotifyItemInDto {
                        DataKey = "keyword3", Value = classRoom
                    },
                    new WxNotifyItemInDto {
                        DataKey = "keyword4", Value = teacherName
                    },
                    new WxNotifyItemInDto {
                        DataKey = "remark", Value = schoolName
                    }
                },
                ToUser     = StudentService.GetWxOpenId(stuInfo),
                TemplateId = WeChatTemplateConstants.MakeupNotice,
                Url        = string.Empty
            };

            wxNotifyProducerService.Publish(wxNotify);
        }