|
@@ -1,196 +0,0 @@
|
|
|
-package com.yonge.cooleshow.biz.dal.service.impl;
|
|
|
-
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
|
|
|
-import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
|
-import com.yonge.cooleshow.biz.dal.dao.*;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.*;
|
|
|
-import com.yonge.cooleshow.biz.dal.enums.CourseGroupEnum;
|
|
|
-import com.yonge.cooleshow.biz.dal.enums.CourseScheduleEnum;
|
|
|
-import com.yonge.cooleshow.biz.dal.service.CourseScheduleService;
|
|
|
-import com.yonge.cooleshow.biz.dal.service.CourseScheduleTeacherTimeService;
|
|
|
-import com.yonge.cooleshow.biz.dal.support.PageUtil;
|
|
|
-import com.yonge.cooleshow.biz.dal.support.WrapperUtil;
|
|
|
-import com.yonge.cooleshow.biz.dal.vo.*;
|
|
|
-import com.yonge.toolset.base.exception.BizException;
|
|
|
-import com.yonge.toolset.base.page.PageInfo;
|
|
|
-import com.yonge.toolset.utils.date.DateUtil;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-/**
|
|
|
- * @Author: cy
|
|
|
- * @Date: 2022/5/26
|
|
|
- */
|
|
|
-@Service("courseScheduleTeacherTimeService")
|
|
|
-public class CourseScheduleTeacherTimeServiceImpl extends ServiceImpl<CourseScheduleTeacherTimeDao, CourseScheduleTeacherTime> implements CourseScheduleTeacherTimeService {
|
|
|
- private final static Logger log = LoggerFactory.getLogger(CourseScheduleTeacherTimeServiceImpl.class);
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SysUserFeignService sysUserFeignService;
|
|
|
- @Autowired
|
|
|
- private PinaoRoomTimeDao pinaoRoomTimeDao;
|
|
|
- @Autowired
|
|
|
- private UserBindingTeacherDao userBindingTeacherDao;
|
|
|
- @Autowired
|
|
|
- private CourseScheduleService courseScheduleService;
|
|
|
- @Autowired
|
|
|
- private CourseGroupServiceImpl groupService;
|
|
|
- @Autowired
|
|
|
- private CourseGroupDao courseGroupDao;
|
|
|
- @Autowired
|
|
|
- private CourseScheduleDao courseScheduleDao;
|
|
|
-
|
|
|
- /**
|
|
|
- * @Description: 查询琴房剩余时长、冻结时长、统计学员人数
|
|
|
- * @Author: cy
|
|
|
- * @Date: 2022/5/26
|
|
|
- */
|
|
|
- @Override
|
|
|
- public PinaoRoomTimeVo selectRemainTime(Long teacherId) {
|
|
|
- return pinaoRoomTimeDao.selectRemainTime(teacherId);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @Description: 我的学员
|
|
|
- * @Author: cy
|
|
|
- * @Date: 2022/5/26
|
|
|
- */
|
|
|
- @Override
|
|
|
- public PageInfo<CourseStudentVo> myStudent(Map<String, Object> param) {
|
|
|
- Page<CourseStudentVo> pageInfo = PageUtil.getPageInfo(param);
|
|
|
- IPage<CourseStudentVo> page = userBindingTeacherDao.myStudent(pageInfo, param);
|
|
|
- return PageUtil.pageInfo(page);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @Description: 排课
|
|
|
- * @Author: cy
|
|
|
- * @Date: 2022/5/26
|
|
|
- */
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void arrangeCourse(ArrangeCourseVo arrangeCourseVo) {
|
|
|
- Integer classNum = arrangeCourseVo.getClassNum();//课时数
|
|
|
- Integer singleClssTime = arrangeCourseVo.getSingleClssTime();//单课时长
|
|
|
- List<Long> studentIds = arrangeCourseVo.getStudentIds();//学员id集合
|
|
|
- Integer consumTime = classNum * singleClssTime * studentIds.size();//消耗时长
|
|
|
- List<CourseTimeEntity> timeList = arrangeCourseVo.getTimeList();//选课时间
|
|
|
- Integer consumeTime = arrangeCourseVo.getConsumeTime();
|
|
|
- SysUser user = sysUserFeignService.queryUserInfo();
|
|
|
- Long teacherId = user.getId();
|
|
|
-
|
|
|
- //校验课时
|
|
|
- if (timeList.size() != classNum) {
|
|
|
- throw new BizException("课时数与排课数不符");
|
|
|
- }
|
|
|
-
|
|
|
- //校验消耗时长
|
|
|
- if (!consumTime.equals(consumeTime)){
|
|
|
- throw new BizException("时长计算错误");
|
|
|
- }
|
|
|
-
|
|
|
- //校验时长
|
|
|
- PinaoRoomTime pinaoRoomTime = pinaoRoomTimeDao.selectOne(Wrappers.<PinaoRoomTime>lambdaQuery().eq(PinaoRoomTime::getTeacherId, teacherId));
|
|
|
- if (pinaoRoomTime == null) {
|
|
|
- throw new BizException("未查询到老师剩余时长");
|
|
|
- }
|
|
|
- Long remainTime = pinaoRoomTime.getRemainTime();
|
|
|
- Long frozenTime = pinaoRoomTime.getFrozenTime();
|
|
|
- if (consumTime > remainTime) {
|
|
|
- throw new BizException("剩余时长不足");
|
|
|
- }
|
|
|
-
|
|
|
- //校验学员是否绑定
|
|
|
- List<UserBindingTeacher> bindingTeachers = userBindingTeacherDao.selectList(Wrappers.<UserBindingTeacher>lambdaQuery().eq(UserBindingTeacher::getTeacherId, teacherId));
|
|
|
- if (CollectionUtils.isEmpty(bindingTeachers)) {
|
|
|
- throw new BizException("无绑定学员");
|
|
|
- }
|
|
|
- List<Long> studentList = bindingTeachers.stream().map(UserBindingTeacher::getStudentId).collect(Collectors.toList());
|
|
|
- for (Long studentId : studentIds) {
|
|
|
- if (!studentList.contains(studentId)) {
|
|
|
- throw new BizException("学员id:{},未绑定", studentId);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //校验传入时间是否交集
|
|
|
- if (timeList.size() > 1) {
|
|
|
- for (int i = 0; i < timeList.size(); i++) {
|
|
|
- if (i == timeList.size() - 1) {
|
|
|
- break;
|
|
|
- }
|
|
|
- CourseTimeEntity o = timeList.get(i);
|
|
|
- List<CourseTimeEntity> newList = timeList.subList(i + 1, timeList.size());
|
|
|
- boolean checkParamTime = courseScheduleService.checkCourseTime(newList, CourseTimeEntity::getStartTime, CourseTimeEntity::getEndTime, o.getStartTime(), o.getEndTime());
|
|
|
- if (checkParamTime) {
|
|
|
- throw new BizException(DateUtil.dateToString(o.getStartTime(), "yyyy年MM月dd号 HH点mm分") + "的课程时间重复!");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //批量检查老师课时在数据库是否重复
|
|
|
- groupService.batchCheckTeacherCourseTime(teacherId, timeList, CourseTimeEntity::getStartTime, CourseTimeEntity::getEndTime);
|
|
|
-
|
|
|
- //校验购买的课程组每节课时间是否和自己的课时冲突
|
|
|
- for (Long studentId : studentIds) {
|
|
|
- groupService.batchCheckStudentCourseTime(studentId, timeList, CourseTimeEntity::getStartTime, CourseTimeEntity::getEndTime);
|
|
|
- }
|
|
|
-
|
|
|
- //添加课程组
|
|
|
- CourseGroup courseGroup = new CourseGroup();
|
|
|
- courseGroup.setType(CourseScheduleEnum.PIANO_ROOM_CLASS.getCode());
|
|
|
- courseGroup.setTeacherId(teacherId);
|
|
|
- courseGroup.setName(arrangeCourseVo.getCourseName());
|
|
|
- courseGroup.setSubjectId(arrangeCourseVo.getSubjectId());
|
|
|
- courseGroup.setSingleCourseMinutes(singleClssTime);
|
|
|
- courseGroup.setCourseNum(classNum);
|
|
|
- courseGroup.setStatus(CourseGroupEnum.NOT_SALE.getCode());
|
|
|
- courseGroup.setCreatedBy(teacherId);
|
|
|
- courseGroupDao.insert(courseGroup);
|
|
|
-
|
|
|
- for (int i = 0; i < timeList.size(); i++) {
|
|
|
- //添加课程
|
|
|
- CourseTimeEntity courseTimeEntity = timeList.get(i);
|
|
|
- CourseSchedule schedule = new CourseSchedule();
|
|
|
- schedule.setCourseGroupId(courseGroup.getId());
|
|
|
- schedule.setType(CourseScheduleEnum.PIANO_ROOM_CLASS.getCode());
|
|
|
- schedule.classNum(i + 1);
|
|
|
- schedule.setTeacherId(teacherId);
|
|
|
- schedule.setClassDate(DateUtil.trunc(courseTimeEntity.getStartTime()));
|
|
|
- schedule.setStartTime(courseTimeEntity.getStartTime());
|
|
|
- schedule.setEndTime(courseTimeEntity.getEndTime());
|
|
|
- schedule.setLock(0);
|
|
|
- schedule.setStatus(CourseScheduleEnum.NOT_START.getCode());
|
|
|
- schedule.setCreatedBy(teacherId);
|
|
|
- courseScheduleDao.insert(schedule);
|
|
|
-
|
|
|
- //添加course_schedule_teacher_time
|
|
|
- CourseScheduleTeacherTime teacherTime = new CourseScheduleTeacherTime();
|
|
|
- teacherTime.setCourseGroupId(courseGroup.getId());
|
|
|
- teacherTime.setCourseScheduleId(schedule.getId());
|
|
|
- teacherTime.setTeacherId(teacherId);
|
|
|
- teacherTime.setStudentIdList(studentIds.toString());
|
|
|
- teacherTime.setClassNum(i + 1);
|
|
|
- teacherTime.setConsumeTime(Long.valueOf(singleClssTime));
|
|
|
- baseMapper.insert(teacherTime);
|
|
|
- }
|
|
|
-
|
|
|
- //扣减pinao_room_time
|
|
|
- PinaoRoomTime roomTime = new PinaoRoomTime();
|
|
|
- roomTime.setRemainTime(remainTime - consumTime);
|
|
|
- roomTime.setFrozenTime(frozenTime + consumTime);
|
|
|
- pinaoRoomTimeDao.update(roomTime,Wrappers.<PinaoRoomTime>lambdaQuery().eq(PinaoRoomTime::getTeacherId,teacherId));
|
|
|
- }
|
|
|
-}
|