|  | @@ -95,11 +95,13 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private HolidaysFestivalsDao holidaysFestivalsDao;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  | -    private PinaoRoomTimeDao pinaoRoomTimeDao;
 | 
	
		
			
				|  |  | +    private PianoRoomTimeDao pianoRoomTimeDao;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private UserBindingTeacherDao userBindingTeacherDao;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private CourseScheduleStudentDao courseScheduleStudentDao;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private CourseScheduleRecordDao recordDao;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public CourseScheduleDao getDao() {
 | 
	
	
		
			
				|  | @@ -1489,25 +1491,45 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public void scheduleTask() {
 | 
	
		
			
				|  |  | -        //更新课程开始状态(开课时间 ≤ NOW ≤ 结束时间)
 | 
	
		
			
				|  |  | +        //课程开始(开课时间 ≤ NOW ≤ 结束时间)
 | 
	
		
			
				|  |  |          List<CourseSchedule> courseStart = baseMapper.selectList(Wrappers.<CourseSchedule>lambdaQuery()
 | 
	
		
			
				|  |  |                  .eq(CourseSchedule::getLock, 0)
 | 
	
		
			
				|  |  | -                .eq(CourseSchedule::getType, CourseScheduleEnum.NOT_START)
 | 
	
		
			
				|  |  | +                .eq(CourseSchedule::getStatus, CourseScheduleEnum.NOT_START)
 | 
	
		
			
				|  |  |                  .le(CourseSchedule::getStartTime, new Date())
 | 
	
		
			
				|  |  |                  .ge(CourseSchedule::getEndTime, new Date()));
 | 
	
		
			
				|  |  |          if (CollectionUtils.isNotEmpty(courseStart)) {
 | 
	
		
			
				|  |  | +            //课程状态更新为ING
 | 
	
		
			
				|  |  |              baseMapper.updateStartTime(courseStart);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        //更新课程结束状态(NOW ≥ 结束时间)
 | 
	
		
			
				|  |  | -        List<String> typeList = Arrays.asList(CourseScheduleEnum.ING.getCode(), CourseScheduleEnum.NOT_START.getCode());
 | 
	
		
			
				|  |  | -        List<CourseSchedule> courseEnd = baseMapper.selectList(Wrappers.<CourseSchedule>lambdaQuery()
 | 
	
		
			
				|  |  | -                .in(CourseSchedule::getType, typeList)
 | 
	
		
			
				|  |  | -                .eq(CourseSchedule::getLock, 0)
 | 
	
		
			
				|  |  | -                .le(CourseSchedule::getEndTime, new Date()));
 | 
	
		
			
				|  |  | -        if (CollectionUtils.isNotEmpty(courseEnd)) {
 | 
	
		
			
				|  |  | -            baseMapper.updateEndTime(courseEnd);
 | 
	
		
			
				|  |  | -            //TODO 根据老师&学生id 更新绑定学员结课时间
 | 
	
		
			
				|  |  | +        //课程结束(NOW ≥ 结束时间)
 | 
	
		
			
				|  |  | +        List<CourseScheduleStudentVo> userList = courseScheduleStudentDao.selectUser();
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isNotEmpty(userList)) {
 | 
	
		
			
				|  |  | +            //更新学生最近结课时间
 | 
	
		
			
				|  |  | +            pianoRoomTimeDao.updateEndTime(userList);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            List<CourseScheduleRecord> recordList = recordDao.sumCourseTime();
 | 
	
		
			
				|  |  | +            if (CollectionUtils.isNotEmpty(recordList)) {
 | 
	
		
			
				|  |  | +                //记录消耗课时
 | 
	
		
			
				|  |  | +                recordDao.insertBatch(recordList);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                //释放冻结课时
 | 
	
		
			
				|  |  | +                List<PianoRoomTime> roomTimeList = new ArrayList<>();
 | 
	
		
			
				|  |  | +                Map<Long, List<CourseScheduleRecord>> collect = recordList.stream().collect(Collectors.groupingBy(CourseScheduleRecord::getTeacherId, Collectors.toList()));
 | 
	
		
			
				|  |  | +                collect.forEach((key, list) -> {
 | 
	
		
			
				|  |  | +                    PianoRoomTime pianoRoomTime = pianoRoomTimeDao.selectOne(Wrappers.<PianoRoomTime>lambdaQuery().eq(PianoRoomTime::getTeacherId, key));
 | 
	
		
			
				|  |  | +                    Long frozenTime = pianoRoomTime.getFrozenTime();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    PianoRoomTime roomTime = new PianoRoomTime();
 | 
	
		
			
				|  |  | +                    roomTime.setTeacherId(key);
 | 
	
		
			
				|  |  | +                    roomTime.setFrozenTime(frozenTime - Long.valueOf(list.stream().mapToInt(CourseScheduleRecord::getConsumTime).sum()));
 | 
	
		
			
				|  |  | +                    roomTimeList.add(roomTime);
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +                pianoRoomTimeDao.updateBatch(roomTimeList);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            //课程状态更新为COMPLETE
 | 
	
		
			
				|  |  | +            baseMapper.updateEndTime(userList);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -1533,8 +1555,8 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
 | 
	
		
			
				|  |  |       * @Author: cy
 | 
	
		
			
				|  |  |       * @Date: 2022/5/27
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    public PinaoRoomTimeVo selectRemainTime(Long teacherId) {
 | 
	
		
			
				|  |  | -        return pinaoRoomTimeDao.selectRemainTime(teacherId);
 | 
	
		
			
				|  |  | +    public PianoRoomTimeVo selectRemainTime(Long teacherId) {
 | 
	
		
			
				|  |  | +        return pianoRoomTimeDao.selectRemainTime(teacherId);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
	
		
			
				|  | @@ -1589,12 +1611,12 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          //校验时长
 | 
	
		
			
				|  |  | -        PinaoRoomTime pinaoRoomTime = pinaoRoomTimeDao.selectOne(Wrappers.<PinaoRoomTime>lambdaQuery().eq(PinaoRoomTime::getTeacherId, teacherId));
 | 
	
		
			
				|  |  | -        if (pinaoRoomTime == null) {
 | 
	
		
			
				|  |  | +        PianoRoomTime pianoRoomTime = pianoRoomTimeDao.selectOne(Wrappers.<PianoRoomTime>lambdaQuery().eq(PianoRoomTime::getTeacherId, teacherId));
 | 
	
		
			
				|  |  | +        if (pianoRoomTime == null) {
 | 
	
		
			
				|  |  |              throw new BizException("未查询到老师剩余时长");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        Long remainTime = pinaoRoomTime.getRemainTime();
 | 
	
		
			
				|  |  | -        Long frozenTime = pinaoRoomTime.getFrozenTime();
 | 
	
		
			
				|  |  | +        Long remainTime = pianoRoomTime.getRemainTime();
 | 
	
		
			
				|  |  | +        Long frozenTime = pianoRoomTime.getFrozenTime();
 | 
	
		
			
				|  |  |          if (consumTime > remainTime) {
 | 
	
		
			
				|  |  |              throw new BizException("剩余时长不足");
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -1674,10 +1696,19 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
 | 
	
		
			
				|  |  |              courseScheduleStudentDao.insertBatch(list);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        //扣减pinao_room_time
 | 
	
		
			
				|  |  | -        PinaoRoomTime roomTime = new PinaoRoomTime();
 | 
	
		
			
				|  |  | +        //扣减piano_room_time
 | 
	
		
			
				|  |  | +        PianoRoomTime roomTime = new PianoRoomTime();
 | 
	
		
			
				|  |  |          roomTime.setRemainTime(remainTime - consumTime);
 | 
	
		
			
				|  |  |          roomTime.setFrozenTime(frozenTime + consumTime);
 | 
	
		
			
				|  |  | -        pinaoRoomTimeDao.update(roomTime, Wrappers.<PinaoRoomTime>lambdaQuery().eq(PinaoRoomTime::getTeacherId, teacherId));
 | 
	
		
			
				|  |  | +        pianoRoomTimeDao.update(roomTime, Wrappers.<PianoRoomTime>lambdaQuery().eq(PianoRoomTime::getTeacherId, teacherId));
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 根据月份查询消耗记录
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public Map<String, Object> selectConsumeTime(String month, Long teacherId) {
 | 
	
		
			
				|  |  | +        Map<String, Object> map = new HashMap();
 | 
	
		
			
				|  |  | +        map.put("consumeTime", recordDao.countTimeByTeacherId(teacherId, month));
 | 
	
		
			
				|  |  | +        return map;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 |