|  | @@ -98,8 +98,6 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
 | 
											
												
													
														|  |      private PianoRoomTimeDao pianoRoomTimeDao;
 |  |      private PianoRoomTimeDao pianoRoomTimeDao;
 | 
											
												
													
														|  |      @Autowired
 |  |      @Autowired
 | 
											
												
													
														|  |      private UserBindingTeacherDao userBindingTeacherDao;
 |  |      private UserBindingTeacherDao userBindingTeacherDao;
 | 
											
												
													
														|  | -    //    @Autowired
 |  | 
 | 
											
												
													
														|  | -//    private CourseScheduleStudentDao courseScheduleStudentDao;
 |  | 
 | 
											
												
													
														|  |      @Autowired
 |  |      @Autowired
 | 
											
												
													
														|  |      private CourseScheduleRecordDao recordDao;
 |  |      private CourseScheduleRecordDao recordDao;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -884,7 +882,7 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
 | 
											
												
													
														|  |          timeList.forEach(o -> {
 |  |          timeList.forEach(o -> {
 | 
											
												
													
														|  |              boolean checkDataTime = this.checkStudentCourseTime(studentId, startTimeFun.apply(o), endTimeFun.apply(o));
 |  |              boolean checkDataTime = this.checkStudentCourseTime(studentId, startTimeFun.apply(o), endTimeFun.apply(o));
 | 
											
												
													
														|  |              if (checkDataTime) {
 |  |              if (checkDataTime) {
 | 
											
												
													
														|  | -                throw new BizException("预计安排在" + DateUtil.dateToString(startTimeFun.apply(o), "yyyy年MM月dd号 HH点mm分") + "的课程时间存在冲突!");
 |  | 
 | 
											
												
													
														|  | 
 |  | +                throw new BizException("学生id:" + studentId + ",预计安排在" + DateUtil.dateToString(startTimeFun.apply(o), "yyyy年MM月dd号 HH点mm分") + "的课程时间存在冲突!");
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |          });
 |  |          });
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
										
											
												
													
														|  | @@ -1120,7 +1118,7 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
 | 
											
												
													
														|  |          CourseTimeEntity timeEntity = new CourseTimeEntity();
 |  |          CourseTimeEntity timeEntity = new CourseTimeEntity();
 | 
											
												
													
														|  |          timeEntity.setStartTime(startTime);
 |  |          timeEntity.setStartTime(startTime);
 | 
											
												
													
														|  |          timeEntity.setEndTime(endTime);
 |  |          timeEntity.setEndTime(endTime);
 | 
											
												
													
														|  | -        List<CourseTimeEntity> timeList=Arrays.asList(timeEntity);
 |  | 
 | 
											
												
													
														|  | 
 |  | +        List<CourseTimeEntity> timeList = Arrays.asList(timeEntity);
 | 
											
												
													
														|  |          //校验老师课程是否冲突
 |  |          //校验老师课程是否冲突
 | 
											
												
													
														|  |          this.batchCheckTeacherCourseTime(teacherId, timeList, CourseTimeEntity::getStartTime, CourseTimeEntity::getEndTime);
 |  |          this.batchCheckTeacherCourseTime(teacherId, timeList, CourseTimeEntity::getStartTime, CourseTimeEntity::getEndTime);
 | 
											
												
													
														|  |          //校验学生课程是否冲突
 |  |          //校验学生课程是否冲突
 | 
											
										
											
												
													
														|  | @@ -1513,11 +1511,11 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
 | 
											
												
													
														|  |                  Map<Long, List<CourseScheduleRecord>> collect = recordList.stream().collect(Collectors.groupingBy(CourseScheduleRecord::getTeacherId, Collectors.toList()));
 |  |                  Map<Long, List<CourseScheduleRecord>> collect = recordList.stream().collect(Collectors.groupingBy(CourseScheduleRecord::getTeacherId, Collectors.toList()));
 | 
											
												
													
														|  |                  collect.forEach((key, list) -> {
 |  |                  collect.forEach((key, list) -> {
 | 
											
												
													
														|  |                      PianoRoomTime pianoRoomTime = pianoRoomTimeDao.selectOne(Wrappers.<PianoRoomTime>lambdaQuery().eq(PianoRoomTime::getTeacherId, key));
 |  |                      PianoRoomTime pianoRoomTime = pianoRoomTimeDao.selectOne(Wrappers.<PianoRoomTime>lambdaQuery().eq(PianoRoomTime::getTeacherId, key));
 | 
											
												
													
														|  | -                    Long frozenTime = pianoRoomTime.getFrozenTime();
 |  | 
 | 
											
												
													
														|  | 
 |  | +                    Integer frozenTime = pianoRoomTime.getFrozenTime();
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |                      PianoRoomTime roomTime = new PianoRoomTime();
 |  |                      PianoRoomTime roomTime = new PianoRoomTime();
 | 
											
												
													
														|  |                      roomTime.setTeacherId(key);
 |  |                      roomTime.setTeacherId(key);
 | 
											
												
													
														|  | -                    roomTime.setFrozenTime(frozenTime - Long.valueOf(list.stream().mapToInt(CourseScheduleRecord::getConsumTime).sum()));
 |  | 
 | 
											
												
													
														|  | 
 |  | +                    roomTime.setFrozenTime(frozenTime - list.stream().mapToInt(CourseScheduleRecord::getConsumTime).sum());
 | 
											
												
													
														|  |                      roomTimeList.add(roomTime);
 |  |                      roomTimeList.add(roomTime);
 | 
											
												
													
														|  |                  });
 |  |                  });
 | 
											
												
													
														|  |                  pianoRoomTimeDao.updateBatch(roomTimeList);
 |  |                  pianoRoomTimeDao.updateBatch(roomTimeList);
 | 
											
										
											
												
													
														|  | @@ -1633,8 +1631,8 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
 | 
											
												
													
														|  |          if (pianoRoomTime == null) {
 |  |          if (pianoRoomTime == null) {
 | 
											
												
													
														|  |              throw new BizException("未查询到老师剩余时长");
 |  |              throw new BizException("未查询到老师剩余时长");
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | -        Long remainTime = pianoRoomTime.getRemainTime();
 |  | 
 | 
											
												
													
														|  | -        Long frozenTime = pianoRoomTime.getFrozenTime();
 |  | 
 | 
											
												
													
														|  | 
 |  | +        Integer remainTime = pianoRoomTime.getRemainTime();
 | 
											
												
													
														|  | 
 |  | +        Integer frozenTime = pianoRoomTime.getFrozenTime();
 | 
											
												
													
														|  |          if (consumTime > remainTime) {
 |  |          if (consumTime > remainTime) {
 | 
											
												
													
														|  |              throw new BizException("剩余时长不足");
 |  |              throw new BizException("剩余时长不足");
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
										
											
												
													
														|  | @@ -1703,7 +1701,7 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
 | 
											
												
													
														|  |              schedule.setSingleCourseTime(singleClssTime);
 |  |              schedule.setSingleCourseTime(singleClssTime);
 | 
											
												
													
														|  |              baseMapper.insert(schedule);
 |  |              baseMapper.insert(schedule);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -            //添加course_schedule_student
 |  | 
 | 
											
												
													
														|  | 
 |  | +            //添加payment
 | 
											
												
													
														|  |              for (Long studentId : studentIds) {
 |  |              for (Long studentId : studentIds) {
 | 
											
												
													
														|  |                  CourseScheduleStudentPayment payment = new CourseScheduleStudentPayment();
 |  |                  CourseScheduleStudentPayment payment = new CourseScheduleStudentPayment();
 | 
											
												
													
														|  |                  payment.setCourseGroupId(courseGroup.getId());
 |  |                  payment.setCourseGroupId(courseGroup.getId());
 | 
											
										
											
												
													
														|  | @@ -1711,6 +1709,8 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
 | 
											
												
													
														|  |                  payment.setUserId(studentId);
 |  |                  payment.setUserId(studentId);
 | 
											
												
													
														|  |                  payment.setCourseType(CourseScheduleEnum.PIANO_ROOM_CLASS.getCode());
 |  |                  payment.setCourseType(CourseScheduleEnum.PIANO_ROOM_CLASS.getCode());
 | 
											
												
													
														|  |                  courseScheduleStudentPaymentService.save(payment);
 |  |                  courseScheduleStudentPaymentService.save(payment);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                pianoSend(teacherId, studentId);
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -1742,4 +1742,235 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
 | 
											
												
													
														|  |          param.put("type", CourseScheduleEnum.PIANO_ROOM_CLASS.getCode());
 |  |          param.put("type", CourseScheduleEnum.PIANO_ROOM_CLASS.getCode());
 | 
											
												
													
														|  |          return PageUtil.pageInfo(recordDao.selectConsumeTimeList(PageUtil.getPageInfo(param), param));
 |  |          return PageUtil.pageInfo(recordDao.selectConsumeTimeList(PageUtil.getPageInfo(param), param));
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    /**
 | 
											
												
													
														|  | 
 |  | +     * @Description: 排课推送
 | 
											
												
													
														|  | 
 |  | +     * @Author: cy
 | 
											
												
													
														|  | 
 |  | +     * @Date: 2022/5/31
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  | 
 |  | +    public void pianoSend(Long teacherId, Long studentId) {
 | 
											
												
													
														|  | 
 |  | +        try {
 | 
											
												
													
														|  | 
 |  | +            //查询老师&学生信息
 | 
											
												
													
														|  | 
 |  | +            SysUser teacher = sysUserFeignService.queryUserById(teacherId);
 | 
											
												
													
														|  | 
 |  | +            SysUser student = sysUserFeignService.queryUserById(studentId);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            //消息接收者(Key:用户编号 value:消息接收对象)
 | 
											
												
													
														|  | 
 |  | +            Map<Long, String> studentReceivers = new HashMap<>();
 | 
											
												
													
														|  | 
 |  | +            studentReceivers.put(studentId, student.getPhone());
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            String pianoUrl = sysMessageService.selectConfigUrl(MessageTypeEnum.ARRANGE_PIANO_ROOM_CLASS.getCode());
 | 
											
												
													
														|  | 
 |  | +            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.ARRANGE_PIANO_ROOM_CLASS,
 | 
											
												
													
														|  | 
 |  | +                    studentReceivers, null, 0, pianoUrl, ClientEnum.STUDENT.getCode(),
 | 
											
												
													
														|  | 
 |  | +                    teacher.getUsername());
 | 
											
												
													
														|  | 
 |  | +            log.info("老师:{},学员:{},排课推送成功", teacherId, studentId);
 | 
											
												
													
														|  | 
 |  | +        } catch (Exception e) {
 | 
											
												
													
														|  | 
 |  | +            log.error("老师:{},学员:{},排课推送失败,{}", teacherId, studentId, e);
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    /**
 | 
											
												
													
														|  | 
 |  | +     * @Description: 删除课程
 | 
											
												
													
														|  | 
 |  | +     * @Author: cy
 | 
											
												
													
														|  | 
 |  | +     * @Date: 2022/5/31
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  | 
 |  | +    @Transactional(rollbackFor = Exception.class)
 | 
											
												
													
														|  | 
 |  | +    public void deleteCourse(Map<String, Object> param) {
 | 
											
												
													
														|  | 
 |  | +        Long courseId = WrapperUtil.toLong(param, "courseId", "课程id不能为空!");
 | 
											
												
													
														|  | 
 |  | +        Long teacherId = WrapperUtil.toLong(param, "teacherId", "老师id不能为空!");
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        //校验课程是否存在
 | 
											
												
													
														|  | 
 |  | +        CourseSchedule schedule = baseMapper.selectOne(Wrappers.<CourseSchedule>lambdaQuery()
 | 
											
												
													
														|  | 
 |  | +                .eq(CourseSchedule::getId, courseId)
 | 
											
												
													
														|  | 
 |  | +                .eq(CourseSchedule::getTeacherId, teacherId)
 | 
											
												
													
														|  | 
 |  | +                .eq(CourseSchedule::getType, CourseScheduleEnum.PIANO_ROOM_CLASS.getCode()));
 | 
											
												
													
														|  | 
 |  | +        if (schedule == null) {
 | 
											
												
													
														|  | 
 |  | +            throw new BizException("课程不存在");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        //课程是否未开始
 | 
											
												
													
														|  | 
 |  | +        if (!schedule.getStatus().equals(CourseScheduleEnum.NOT_START.getCode())) {
 | 
											
												
													
														|  | 
 |  | +            throw new BizException("只能删除未开始的课程");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        //计算课时
 | 
											
												
													
														|  | 
 |  | +        List<CourseScheduleStudentPayment> studentPaymentList = paymentDao.selectList(Wrappers.<CourseScheduleStudentPayment>lambdaQuery().eq(CourseScheduleStudentPayment::getCourseId, courseId));
 | 
											
												
													
														|  | 
 |  | +        int time = studentPaymentList.size() * schedule.getSingleCourseTime();
 | 
											
												
													
														|  | 
 |  | +        PianoRoomTime pianoRoomTime = pianoRoomTimeDao.selectOne(Wrappers.<PianoRoomTime>lambdaQuery().eq(PianoRoomTime::getTeacherId, teacherId));
 | 
											
												
													
														|  | 
 |  | +        if (pianoRoomTime == null) {
 | 
											
												
													
														|  | 
 |  | +            throw new BizException("未查到剩余时长");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        if (pianoRoomTime.getFrozenTime() - time < 0) {
 | 
											
												
													
														|  | 
 |  | +            throw new BizException("冻结时长计算错误");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        pianoRoomTimeDao.update(null, Wrappers.<PianoRoomTime>lambdaUpdate()
 | 
											
												
													
														|  | 
 |  | +                .eq(PianoRoomTime::getTeacherId, teacherId)
 | 
											
												
													
														|  | 
 |  | +                .set(PianoRoomTime::getRemainTime, pianoRoomTime.getRemainTime() + time)
 | 
											
												
													
														|  | 
 |  | +                .set(PianoRoomTime::getFrozenTime, pianoRoomTime.getFrozenTime() - time));
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        //删除课程
 | 
											
												
													
														|  | 
 |  | +        baseMapper.deleteById(courseId);
 | 
											
												
													
														|  | 
 |  | +        //删除payment
 | 
											
												
													
														|  | 
 |  | +        paymentDao.delete(Wrappers.<CourseScheduleStudentPayment>lambdaQuery().eq(CourseScheduleStudentPayment::getCourseId, courseId));
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        //更新组课程数
 | 
											
												
													
														|  | 
 |  | +        Long groupId = schedule.getCourseGroupId();
 | 
											
												
													
														|  | 
 |  | +        Integer count = baseMapper.selectCount(Wrappers.<CourseSchedule>lambdaQuery().eq(CourseSchedule::getCourseGroupId, groupId));
 | 
											
												
													
														|  | 
 |  | +        if (count == 0) {
 | 
											
												
													
														|  | 
 |  | +            courseGroupService.getDao().deleteById(groupId);
 | 
											
												
													
														|  | 
 |  | +        } else {
 | 
											
												
													
														|  | 
 |  | +            courseGroupService.update(null, Wrappers.<CourseGroup>lambdaUpdate()
 | 
											
												
													
														|  | 
 |  | +                    .eq(CourseGroup::getId, groupId)
 | 
											
												
													
														|  | 
 |  | +                    .set(CourseGroup::getCourseNum, count));
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    /**
 | 
											
												
													
														|  | 
 |  | +     * @Description: 调整上课时间
 | 
											
												
													
														|  | 
 |  | +     * @Author: cy
 | 
											
												
													
														|  | 
 |  | +     * @Date: 2022/5/31
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  | 
 |  | +    @Transactional(rollbackFor = Exception.class)
 | 
											
												
													
														|  | 
 |  | +    public void updateCourseTime(Map<String, Object> param) {
 | 
											
												
													
														|  | 
 |  | +        Long courseId = WrapperUtil.toLong(param, "courseId", "课程id不能为空!");
 | 
											
												
													
														|  | 
 |  | +        Long teacherId = WrapperUtil.toLong(param, "teacherId", "老师id不能为空!");
 | 
											
												
													
														|  | 
 |  | +        String startTimeStr = WrapperUtil.toStr(param, "startTime", "开始时间不能为空!");
 | 
											
												
													
														|  | 
 |  | +        String endTimeStr = WrapperUtil.toStr(param, "endTime", "结束时间不能为空!");
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        Date startTime = DateUtil.strToDate(startTimeStr);
 | 
											
												
													
														|  | 
 |  | +        Date endTime = DateUtil.strToDate(endTimeStr);
 | 
											
												
													
														|  | 
 |  | +        CourseTimeEntity courseTime = new CourseTimeEntity();
 | 
											
												
													
														|  | 
 |  | +        courseTime.setStartTime(startTime);
 | 
											
												
													
														|  | 
 |  | +        courseTime.setEndTime(endTime);
 | 
											
												
													
														|  | 
 |  | +        List<CourseTimeEntity> timeList = Arrays.asList(courseTime);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        CourseSchedule courseSchedule = baseMapper.selectOne(Wrappers.<CourseSchedule>lambdaQuery()
 | 
											
												
													
														|  | 
 |  | +                .eq(CourseSchedule::getId, courseId)
 | 
											
												
													
														|  | 
 |  | +                .eq(CourseSchedule::getTeacherId, teacherId)
 | 
											
												
													
														|  | 
 |  | +                .eq(CourseSchedule::getStatus, CourseScheduleEnum.NOT_START.getCode())
 | 
											
												
													
														|  | 
 |  | +                .eq(CourseSchedule::getType, CourseScheduleEnum.PIANO_ROOM_CLASS.getCode()));
 | 
											
												
													
														|  | 
 |  | +        if (courseSchedule == null) {
 | 
											
												
													
														|  | 
 |  | +            throw new BizException("无法修改课程");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        //校验上下课时间
 | 
											
												
													
														|  | 
 |  | +        Integer singleCourseTime = courseSchedule.getSingleCourseTime();
 | 
											
												
													
														|  | 
 |  | +        if (!DateUtil.offsetMinute(startTime, singleCourseTime).equals(endTime)) {
 | 
											
												
													
														|  | 
 |  | +            throw new BizException("课程结束时间计算错误");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        //批量检查老师课时在数据库是否重复
 | 
											
												
													
														|  | 
 |  | +        this.batchCheckTeacherCourseTime(teacherId, timeList, CourseTimeEntity::getStartTime, CourseTimeEntity::getEndTime);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        //校验购买的课程组每节课时间是否和自己的课时冲突
 | 
											
												
													
														|  | 
 |  | +        List<CourseScheduleStudentPayment> studentPayments = paymentDao.selectList(Wrappers.<CourseScheduleStudentPayment>lambdaQuery()
 | 
											
												
													
														|  | 
 |  | +                .eq(CourseScheduleStudentPayment::getCourseId, courseId)
 | 
											
												
													
														|  | 
 |  | +                .eq(CourseScheduleStudentPayment::getCourseType, CourseScheduleEnum.PIANO_ROOM_CLASS.getCode()));
 | 
											
												
													
														|  | 
 |  | +        if (CollectionUtils.isNotEmpty(studentPayments)) {
 | 
											
												
													
														|  | 
 |  | +            for (CourseScheduleStudentPayment payment : studentPayments) {
 | 
											
												
													
														|  | 
 |  | +                this.batchCheckStudentCourseTime(payment.getUserId(), timeList, CourseTimeEntity::getStartTime, CourseTimeEntity::getEndTime);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        //更新时间
 | 
											
												
													
														|  | 
 |  | +        baseMapper.update(null, Wrappers.<CourseSchedule>lambdaUpdate()
 | 
											
												
													
														|  | 
 |  | +                .eq(CourseSchedule::getId, courseId)
 | 
											
												
													
														|  | 
 |  | +                .set(CourseSchedule::getClassDate, DateUtil.trunc(startTime))
 | 
											
												
													
														|  | 
 |  | +                .set(CourseSchedule::getStartTime, startTime)
 | 
											
												
													
														|  | 
 |  | +                .set(CourseSchedule::getEndTime, endTime));
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    /**
 | 
											
												
													
														|  | 
 |  | +     * @Description: 调整学员
 | 
											
												
													
														|  | 
 |  | +     * @Author: cy
 | 
											
												
													
														|  | 
 |  | +     * @Date: 2022/5/31
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  | 
 |  | +    @Transactional(rollbackFor = Exception.class)
 | 
											
												
													
														|  | 
 |  | +    public void updateCourseStudent(Map<String, Object> param) {
 | 
											
												
													
														|  | 
 |  | +        Long courseId = WrapperUtil.toLong(param, "courseId", "课程id不能为空!");
 | 
											
												
													
														|  | 
 |  | +        Long teacherId = WrapperUtil.toLong(param, "teacherId", "老师id不能为空!");
 | 
											
												
													
														|  | 
 |  | +        List<Integer> studentIdsList = (List<Integer>) param.get("studentIds");
 | 
											
												
													
														|  | 
 |  | +        List<Long> studentIds = JSONArray.parseArray(studentIdsList.toString(), Long.class);
 | 
											
												
													
														|  | 
 |  | +        if (CollectionUtils.isEmpty(studentIds)) {
 | 
											
												
													
														|  | 
 |  | +            throw new BizException("学生id不能为空");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        List<UserBindingTeacher> bindingTeachers = userBindingTeacherDao.selectList(Wrappers.<UserBindingTeacher>lambdaQuery().eq(UserBindingTeacher::getTeacherId, teacherId));
 | 
											
												
													
														|  | 
 |  | +        if (CollectionUtils.isEmpty(bindingTeachers)) {
 | 
											
												
													
														|  | 
 |  | +            throw new BizException("未绑定学员");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        List<Long> students = bindingTeachers.stream().map(UserBindingTeacher::getStudentId).collect(Collectors.toList());
 | 
											
												
													
														|  | 
 |  | +        if (!students.containsAll(studentIds)) {
 | 
											
												
													
														|  | 
 |  | +            throw new BizException("存在未绑定学员");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        CourseSchedule courseSchedule = baseMapper.selectOne(Wrappers.<CourseSchedule>lambdaQuery()
 | 
											
												
													
														|  | 
 |  | +                .eq(CourseSchedule::getId, courseId)
 | 
											
												
													
														|  | 
 |  | +                .eq(CourseSchedule::getTeacherId, teacherId)
 | 
											
												
													
														|  | 
 |  | +                .eq(CourseSchedule::getStatus, CourseScheduleEnum.NOT_START.getCode())
 | 
											
												
													
														|  | 
 |  | +                .eq(CourseSchedule::getType, CourseScheduleEnum.PIANO_ROOM_CLASS.getCode()));
 | 
											
												
													
														|  | 
 |  | +        if (courseSchedule == null) {
 | 
											
												
													
														|  | 
 |  | +            throw new BizException("无法修改课程");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        Integer singleCourseTime = courseSchedule.getSingleCourseTime();
 | 
											
												
													
														|  | 
 |  | +        Long groupId = courseSchedule.getCourseGroupId();
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        List<CourseScheduleStudentPayment> paymentList = paymentDao.selectList(Wrappers.<CourseScheduleStudentPayment>lambdaQuery()
 | 
											
												
													
														|  | 
 |  | +                .eq(CourseScheduleStudentPayment::getCourseId, courseId)
 | 
											
												
													
														|  | 
 |  | +                .eq(CourseScheduleStudentPayment::getCourseType, CourseScheduleEnum.PIANO_ROOM_CLASS.getCode()));
 | 
											
												
													
														|  | 
 |  | +        if (CollectionUtils.isEmpty(paymentList)) {
 | 
											
												
													
														|  | 
 |  | +            throw new BizException("未查到排课学员");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        PianoRoomTime pianoRoomTime = pianoRoomTimeDao.selectOne(Wrappers.<PianoRoomTime>lambdaQuery().eq(PianoRoomTime::getTeacherId, teacherId));
 | 
											
												
													
														|  | 
 |  | +        if (pianoRoomTime == null) {
 | 
											
												
													
														|  | 
 |  | +            throw new BizException("未查到剩余时长");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        Integer frozenTime = pianoRoomTime.getFrozenTime();
 | 
											
												
													
														|  | 
 |  | +        Integer remainTime = pianoRoomTime.getRemainTime();
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        int i = studentIds.size() - paymentList.size();//新人数-原人数
 | 
											
												
													
														|  | 
 |  | +        if (i > 0) {//加人,扣时长
 | 
											
												
													
														|  | 
 |  | +            int courseTime = singleCourseTime * i;
 | 
											
												
													
														|  | 
 |  | +            if (remainTime - courseTime < 0) {
 | 
											
												
													
														|  | 
 |  | +                throw new BizException("剩余时长不足");
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            pianoRoomTimeDao.update(null, Wrappers.<PianoRoomTime>lambdaUpdate()
 | 
											
												
													
														|  | 
 |  | +                    .eq(PianoRoomTime::getTeacherId, teacherId)
 | 
											
												
													
														|  | 
 |  | +                    .set(PianoRoomTime::getRemainTime, remainTime - courseTime)
 | 
											
												
													
														|  | 
 |  | +                    .set(PianoRoomTime::getFrozenTime, frozenTime + courseTime));
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        if (i < 0) {//减人,释放时长
 | 
											
												
													
														|  | 
 |  | +            int courseTime = singleCourseTime * (-i);
 | 
											
												
													
														|  | 
 |  | +            pianoRoomTimeDao.update(null, Wrappers.<PianoRoomTime>lambdaUpdate()
 | 
											
												
													
														|  | 
 |  | +                    .eq(PianoRoomTime::getTeacherId, teacherId)
 | 
											
												
													
														|  | 
 |  | +                    .set(PianoRoomTime::getRemainTime, remainTime + courseTime)
 | 
											
												
													
														|  | 
 |  | +                    .set(PianoRoomTime::getFrozenTime, frozenTime - courseTime));
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        //删除原学员
 | 
											
												
													
														|  | 
 |  | +        paymentDao.delete(Wrappers.<CourseScheduleStudentPayment>lambdaQuery().eq(CourseScheduleStudentPayment::getCourseId, courseId));
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        CourseTimeEntity courseTime = new CourseTimeEntity();
 | 
											
												
													
														|  | 
 |  | +        courseTime.setStartTime(courseSchedule.getStartTime());
 | 
											
												
													
														|  | 
 |  | +        courseTime.setEndTime(courseSchedule.getEndTime());
 | 
											
												
													
														|  | 
 |  | +        List<CourseTimeEntity> timeList = Arrays.asList(courseTime);
 | 
											
												
													
														|  | 
 |  | +        //批量检查老师课时在数据库是否重复
 | 
											
												
													
														|  | 
 |  | +        this.batchCheckTeacherCourseTime(teacherId, timeList, CourseTimeEntity::getStartTime, CourseTimeEntity::getEndTime);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        List<CourseScheduleStudentPayment> payments = new ArrayList<>();
 | 
											
												
													
														|  | 
 |  | +        for (Long studentId : studentIds) {
 | 
											
												
													
														|  | 
 |  | +            //校验购买的课程组每节课时间是否和自己的课时冲突
 | 
											
												
													
														|  | 
 |  | +            this.batchCheckStudentCourseTime(studentId, timeList, CourseTimeEntity::getStartTime, CourseTimeEntity::getEndTime);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            CourseScheduleStudentPayment payment = new CourseScheduleStudentPayment();
 | 
											
												
													
														|  | 
 |  | +            payment.setUserId(studentId);
 | 
											
												
													
														|  | 
 |  | +            payment.setCourseId(courseId);
 | 
											
												
													
														|  | 
 |  | +            payment.setCourseGroupId(groupId);
 | 
											
												
													
														|  | 
 |  | +            payment.setCourseType(CourseScheduleEnum.PIANO_ROOM_CLASS.getCode());
 | 
											
												
													
														|  | 
 |  | +            payments.add(payment);
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        //重新新增学员
 | 
											
												
													
														|  | 
 |  | +        paymentDao.insertBatch(payments);
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  |  }
 |  |  }
 |