|
@@ -41,14 +41,13 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.time.LocalTime;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.function.Consumer;
|
|
|
import java.util.function.Function;
|
|
|
+import java.util.function.Predicate;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -113,6 +112,7 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
|
|
|
result.setSalesStartDate(group.getSalesStartDate());
|
|
|
result.setSalesEndDate(group.getSalesEndDate());
|
|
|
result.setMixStudentNum(group.getMixStudentNum());
|
|
|
+ result.setImGroupId(group.getImGroupId());
|
|
|
Optional.ofNullable(group.getTeacherId()).map(this::getSysUser)
|
|
|
.ifPresent(sysUser -> result.setTeacherName(sysUser.getRealName()));
|
|
|
Optional.ofNullable(group.getSubjectId()).map(subjectService::get)
|
|
@@ -121,7 +121,16 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
|
|
|
result.setPlanList(coursePlanService.queryCoursePlanByGroupId(groupId));
|
|
|
//课程组学员信息
|
|
|
result.setStudentList(courseScheduleStudentPaymentService.queryStudentInfoByGroupId(groupId));
|
|
|
-
|
|
|
+ //查询是否购买过该课程组
|
|
|
+ Long id = getSysUser().getId();
|
|
|
+ List<CourseScheduleStudentPayment> paymentList = courseScheduleStudentPaymentService.list(Wrappers.<CourseScheduleStudentPayment>lambdaQuery()
|
|
|
+ .eq(CourseScheduleStudentPayment::getUserId, id)
|
|
|
+ .eq(CourseScheduleStudentPayment::getCourseGroupId, groupId)
|
|
|
+ );
|
|
|
+ result.setExistBuy(0);
|
|
|
+ if (CollectionUtils.isNotEmpty(paymentList)) {
|
|
|
+ result.setExistBuy(1);
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -141,6 +150,27 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
|
|
|
Page<CourseGroupVo> pageInfo = PageUtil.getPageInfo(param);
|
|
|
pageInfo.setAsc("b.created_time_");
|
|
|
IPage<CourseGroupVo> page = baseMapper.queryTeacherCourseGroup(pageInfo, param);
|
|
|
+ //学生端查询报名中的课程组需要标明该学生是否已经购买过该课程组
|
|
|
+ String os = WrapperUtil.toStr(param, "os");
|
|
|
+ if ("student".equals(os) && CollectionUtils.isNotEmpty(page.getRecords())) {
|
|
|
+ //获取当前课程组Id
|
|
|
+ List<CourseGroupVo> records = page.getRecords();
|
|
|
+ List<Long> groupId = records.stream().map(CourseGroupVo::getCourseGroupId).collect(Collectors.toList());
|
|
|
+ //根据学生id 及 课程组id集合查询购买记录
|
|
|
+ List<CourseScheduleStudentPayment> paymentList = courseScheduleStudentPaymentService.list(Wrappers.<CourseScheduleStudentPayment>lambdaQuery()
|
|
|
+ .eq(CourseScheduleStudentPayment::getUserId, getSysUser().getId())
|
|
|
+ .in(CourseScheduleStudentPayment::getCourseGroupId, groupId)
|
|
|
+ );
|
|
|
+ if (CollectionUtils.isNotEmpty(paymentList)) {
|
|
|
+ Map<Long, List<CourseScheduleStudentPayment>> payMap = WrapperUtil.groupList(paymentList, CourseScheduleStudentPayment::getCourseGroupId);
|
|
|
+ records.forEach(o -> {
|
|
|
+ o.setExistBuy(0);
|
|
|
+ if (payMap.containsKey(o.getCourseGroupId())) {
|
|
|
+ o.setExistBuy(1);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
return PageUtil.pageInfo(page);
|
|
|
}
|
|
|
|
|
@@ -219,11 +249,44 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 取消课程组-下架课程组
|
|
|
+ *
|
|
|
+ * @param groupId 课程组
|
|
|
+ */
|
|
|
+ public void cancelCourseGroup(Long groupId) {
|
|
|
+ //获取课程组
|
|
|
+ CourseGroup group = this.getOne(Wrappers.<CourseGroup>lambdaQuery().
|
|
|
+ eq(CourseGroup::getId, groupId));
|
|
|
+ Predicate<CourseGroupEnum> courseStateFunc = e -> group.getStatus().equalsIgnoreCase(e.getCode());
|
|
|
+ if (courseStateFunc.test(CourseGroupEnum.ING)) {
|
|
|
+ throw new BizException("课程组进行中,无法下架/取消课程组!");
|
|
|
+ } else if (courseStateFunc.test(CourseGroupEnum.APPLY)) {
|
|
|
+ //已上架没人买的课程可以下架
|
|
|
+ if (group.getPreStudentNum() > 0) {
|
|
|
+ throw new BizException("课程组已有学生购买,无法下架/取消课程组!");
|
|
|
+ }
|
|
|
+ } else if (courseStateFunc.test(CourseGroupEnum.COMPLETE)) {
|
|
|
+ throw new BizException("课程组已完结!");
|
|
|
+ } else if (courseStateFunc.test(CourseGroupEnum.DISSOLVE) || courseStateFunc.test(CourseGroupEnum.CANCEL)) {
|
|
|
+ throw new BizException("课程组已下架!");
|
|
|
+ }
|
|
|
+ //只剩下未开售状态和上架没人购买,可以直接修改
|
|
|
+ group.setStatus(CourseGroupEnum.CANCEL.getCode());
|
|
|
+ this.updateById(group);
|
|
|
+ //修改课程表
|
|
|
+ courseScheduleService.lambdaUpdate()
|
|
|
+ .eq(CourseSchedule::getCourseGroupId, groupId)
|
|
|
+ .set(CourseSchedule::getStatus, CourseScheduleEnum.CANCEL.getCode())
|
|
|
+ .update();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 创建课时写到缓存锁定时间
|
|
|
*/
|
|
|
+ @Override
|
|
|
public List<CourseTimeEntity> lockCourseToCache(CheckCourseTimeDto dto) {
|
|
|
- //获取课程类型
|
|
|
- CourseScheduleEnum courseType = CourseScheduleEnum.existCourseType(dto.getCourseType(), "课程类型不正确!");
|
|
|
+ // true:陪练课PRACTICE false:LIVE直播课
|
|
|
+ boolean courseTypeFlag = CourseScheduleEnum.existCourseType(dto.getCourseType(), "课程类型不正确!").equals(CourseScheduleEnum.PRACTICE);
|
|
|
//先自校验传入时间是否交集
|
|
|
List<CourseTimeEntity> timeList = dto.getTimeList();
|
|
|
if (timeList.size() > 1) {
|
|
@@ -241,21 +304,21 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
|
|
|
}
|
|
|
//批量检查老师课时在数据库是否重复
|
|
|
batchCheckTeacherCourseTime(dto.getTeacherId(), timeList, CourseTimeEntity::getStartTime, CourseTimeEntity::getEndTime);
|
|
|
- //获取老师锁课缓存并添加课时数据
|
|
|
- RMap<Long, List<CourseTimeEntity>> map = getExpireLiveLockTimeCache(dto.getTeacherId());
|
|
|
- map.fastPut(dto.getTeacherId(), timeList);
|
|
|
|
|
|
//需要自动补全课时
|
|
|
if (dto.getLoop() == 1) {
|
|
|
//自动排课,获取排课后所有的课程时间
|
|
|
- List<CourseTimeEntity> allCourseTime = autoPlanningLiveCourseTime(dto.getTeacherId(), dto.getCourseNum(), timeList, courseType);
|
|
|
- allCourseTime.sort(Comparator.comparing(CourseTimeEntity::getStartTime));
|
|
|
- //替换掉原有的课时
|
|
|
- dto.setTimeList(allCourseTime);
|
|
|
- //将自动排课后的课时写入缓存覆盖原有的
|
|
|
- map.fastPut(dto.getTeacherId(), dto.getTimeList());
|
|
|
+ timeList = autoPlanningLiveCourseTime(dto.getTeacherId(), dto.getCourseNum(), timeList, courseTypeFlag);
|
|
|
+ timeList.sort(Comparator.comparing(CourseTimeEntity::getStartTime));
|
|
|
+ }
|
|
|
+ //获取老师锁课缓存
|
|
|
+ RMap<Long, List<CourseTimeEntity>> map = getExpireLiveLockTimeCache(dto.getTeacherId());
|
|
|
+ //陪练课无需锁定时间
|
|
|
+ if (!courseTypeFlag) {
|
|
|
+ //直播课添加课时数据
|
|
|
+ map.fastPut(dto.getTeacherId(), timeList);
|
|
|
}
|
|
|
- return dto.getTimeList();
|
|
|
+ return timeList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -299,14 +362,12 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
|
|
|
* @param teacherId 老师id
|
|
|
* @param totalCourseNum 总课程数量
|
|
|
* @param paramTimeList 当前课程的时间段
|
|
|
- * @param courseType PRACTICE陪练课 LIVE直播课
|
|
|
+ * @param courseTypeFlag true:陪练课PRACTICE false:LIVE直播课
|
|
|
* @return 自动排课后的全部课时
|
|
|
*/
|
|
|
- private List<CourseTimeEntity> autoPlanningLiveCourseTime(Long teacherId, int totalCourseNum, List<CourseTimeEntity> paramTimeList, CourseScheduleEnum courseType) {
|
|
|
+ private List<CourseTimeEntity> autoPlanningLiveCourseTime(Long teacherId, int totalCourseNum, List<CourseTimeEntity> paramTimeList, boolean courseTypeFlag) {
|
|
|
//是否跳过节假日
|
|
|
boolean skipHoliday = false;
|
|
|
- //true 陪练课
|
|
|
- boolean courseTypeFlag = courseType.equals(CourseScheduleEnum.PRACTICE);
|
|
|
if (courseTypeFlag) {
|
|
|
//查询老师陪练课设置
|
|
|
TeacherFreeTime teacherTime = teacherFreeTimeService.getOne(Wrappers.<TeacherFreeTime>lambdaQuery()
|