浏览代码

更新课程状态

cy 3 年之前
父节点
当前提交
afa5126e8d

+ 35 - 5
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/CourseScheduleServiceImpl.java

@@ -51,6 +51,7 @@ import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
 import java.time.Instant;
 import java.time.Instant;
 import java.time.LocalDate;
 import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.time.temporal.ChronoUnit;
 import java.time.temporal.ChronoUnit;
 import java.time.temporal.TemporalAdjusters;
 import java.time.temporal.TemporalAdjusters;
 import java.util.*;
 import java.util.*;
@@ -59,6 +60,7 @@ import java.util.function.BiConsumer;
 import java.util.function.BiFunction;
 import java.util.function.BiFunction;
 import java.util.function.Function;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 
 import static com.yonge.cooleshow.biz.dal.support.WrapperUtil.inInterSection;
 import static com.yonge.cooleshow.biz.dal.support.WrapperUtil.inInterSection;
 
 
@@ -1610,12 +1612,40 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
      */
      */
     @Transactional(rollbackFor = Exception.class)
     @Transactional(rollbackFor = Exception.class)
     public void scheduleTask() {
     public void scheduleTask() {
-        //课程开始(开课时间 ≤ NOW ≤ 结束时间)
-        List<CourseSchedule> courseStart = baseMapper.selectList(Wrappers.<CourseSchedule>lambdaQuery()
+        //查询房间配置时间
+        LocalDateTime liveMinute = LocalDateTime.now().plusMinutes(Long.parseLong(sysConfigService.findConfigValue(SysConfigConstant.PRE_CREATE_LIVE_ROOM_MINUTE)));
+        LocalDateTime practiceMinute = LocalDateTime.now().plusMinutes(Long.parseLong(sysConfigService.findConfigValue(SysConfigConstant.PRE_CREATE_PRACTICE_ROOM_MINUTE)));
+        LocalDateTime pianoMinute = LocalDateTime.now().plusMinutes(Long.parseLong(sysConfigService.findConfigValue(SysConfigConstant.PRE_CREATE_PIANO_ROOM_MINUTE)));
+
+        //课程开始(开课时间 ≤ (NOW + 提前进入房间时间(分)) && NOW ≤ 结束时间)
+        List<CourseSchedule> liveStart = baseMapper.selectList(Wrappers.<CourseSchedule>lambdaQuery()
+                .eq(CourseSchedule::getLock, 0)
+                .eq(CourseSchedule::getStatus, CourseScheduleEnum.NOT_START)
+                .eq(CourseSchedule::getType, CourseScheduleEnum.LIVE)
+                .le(CourseSchedule::getStartTime, liveMinute)
+                .ge(CourseSchedule::getEndTime, LocalDateTime.now()));
+        List<CourseSchedule> practiceStart = baseMapper.selectList(Wrappers.<CourseSchedule>lambdaQuery()
+                .eq(CourseSchedule::getLock, 0)
+                .eq(CourseSchedule::getStatus, CourseScheduleEnum.NOT_START)
+                .eq(CourseSchedule::getType, CourseScheduleEnum.PRACTICE)
+                .le(CourseSchedule::getStartTime, practiceMinute)
+                .ge(CourseSchedule::getEndTime, LocalDateTime.now()));
+        List<CourseSchedule> pianoStart = baseMapper.selectList(Wrappers.<CourseSchedule>lambdaQuery()
                 .eq(CourseSchedule::getLock, 0)
                 .eq(CourseSchedule::getLock, 0)
                 .eq(CourseSchedule::getStatus, CourseScheduleEnum.NOT_START)
                 .eq(CourseSchedule::getStatus, CourseScheduleEnum.NOT_START)
-                .le(CourseSchedule::getStartTime, new Date())
-                .ge(CourseSchedule::getEndTime, new Date()));
+                .eq(CourseSchedule::getType, CourseScheduleEnum.PIANO_ROOM_CLASS)
+                .le(CourseSchedule::getStartTime, pianoMinute)
+                .ge(CourseSchedule::getEndTime, LocalDateTime.now()));
+        if (CollectionUtils.isEmpty(liveStart)) {
+            liveStart = new ArrayList<>();
+        }
+        if (CollectionUtils.isEmpty(practiceStart)) {
+            practiceStart = new ArrayList<>();
+        }
+        if (CollectionUtils.isEmpty(pianoStart)) {
+            pianoStart = new ArrayList<>();
+        }
+        List<CourseSchedule> courseStart = Stream.of(liveStart, practiceStart, pianoStart).flatMap(Collection::stream).collect(Collectors.toList());
         if (CollectionUtils.isNotEmpty(courseStart)) {
         if (CollectionUtils.isNotEmpty(courseStart)) {
             //课程状态更新为ING
             //课程状态更新为ING
             baseMapper.updateStartTime(courseStart);
             baseMapper.updateStartTime(courseStart);
@@ -1716,7 +1746,7 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
     @Transactional(rollbackFor = Exception.class)
     @Transactional(rollbackFor = Exception.class)
     public void teacherSalaryTask() {
     public void teacherSalaryTask() {
         //课程结算日期(天)
         //课程结算日期(天)
-        Integer settlementDay = Integer.valueOf(sysConfigService.findConfigValue(SysConfigConstant.COURSE_SALARY_SETTLEMENT_DAY));
+        Integer settlementDay = Integer.valueOf(sysConfigService.findConfigValue(SysConfigConstant.COURSE_SETTLEMENT_TIME_DAY));
         //获取n天前日期
         //获取n天前日期
         String day = DateUtil.getDayAgoOrAftString(-settlementDay);
         String day = DateUtil.getDayAgoOrAftString(-settlementDay);