Explorar o código

优化陪练课日历

hgw %!s(int64=3) %!d(string=hai) anos
pai
achega
36b39600b6

+ 9 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/CourseGroupService.java

@@ -9,6 +9,7 @@ import com.yonge.cooleshow.biz.dal.entity.CourseTimeEntity;
 import com.yonge.cooleshow.biz.dal.vo.CourseGroupVo;
 import com.yonge.cooleshow.biz.dal.vo.LiveCourseInfoVo;
 import com.yonge.cooleshow.common.page.PageInfo;
+import org.redisson.api.RMap;
 
 import java.util.List;
 import java.util.Map;
@@ -53,5 +54,13 @@ public interface CourseGroupService extends IService<CourseGroup> {
      */
     void unlockCourseToCache(Long teacherId);
 
+    /**
+     * 获取老师锁定的直播课时数据的缓存
+     *
+     * @param teacherId 老师id
+     * @return 缓存 key teacherId value List<CourseTimeEntity>
+     */
+    RMap<Long, List<CourseTimeEntity>> getLiveLockTimeCache(Long teacherId);
+
 }
 

+ 13 - 7
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/CourseGroupServiceImpl.java

@@ -139,7 +139,7 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
         //批量检查老师课时在数据库是否重复
         batchCheckTeacherCourseTime(dto.getTeacherId(), dto.getCoursePlanList(), CoursePlanDto::getStartTime, CoursePlanDto::getEndTime);
         //获取锁定课时缓存,没有问题就刷新缓存
-        RMap<Long, List<CourseTimeEntity>> cacheTime = getExpireLockTimeCache(dto.getTeacherId());
+        RMap<Long, List<CourseTimeEntity>> cacheTime = getExpireLiveLockTimeCache(dto.getTeacherId());
         List<CourseTimeEntity> timeEntities = new ArrayList<>();
         dto.getCoursePlanList().forEach(o -> {
             CourseTimeEntity time = new CourseTimeEntity();
@@ -222,7 +222,7 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
         //批量检查老师课时在数据库是否重复
         batchCheckTeacherCourseTime(dto.getTeacherId(), timeList, CourseTimeEntity::getStartTime, CourseTimeEntity::getEndTime);
         //获取老师锁课缓存并添加课时数据
-        RMap<Long, List<CourseTimeEntity>> map = getExpireLockTimeCache(dto.getTeacherId());
+        RMap<Long, List<CourseTimeEntity>> map = getExpireLiveLockTimeCache(dto.getTeacherId());
         map.fastPut(dto.getTeacherId(), timeList);
 
         //需要自动补全课时
@@ -349,24 +349,30 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
     @Override
     public void unlockCourseToCache(Long teacherId) {
         Optional.ofNullable(teacherId)
-                .ifPresent(id -> getLockTimeCache(id).delete());
+                .ifPresent(id -> getLiveLockTimeCache(id).delete());
     }
 
     /**
-     * 获取老师锁定课时数据的缓存
+     * 获取老师锁定课时数据的缓存-设置过期时间
      *
      * @param teacherId 老师id
      * @return 缓存
      */
-    private RMap<Long, List<CourseTimeEntity>> getExpireLockTimeCache(Long teacherId) {
+    private RMap<Long, List<CourseTimeEntity>> getExpireLiveLockTimeCache(Long teacherId) {
         String lockMinuteStr = sysConfigService.findConfigValue(SysConfigConstant.CREATE_LIVE_TIME_LOCK_MINUTE);
         long lockMinute = StringUtils.isBlank(lockMinuteStr) ? 15L : Long.parseLong(lockMinuteStr);
-        RMap<Long, List<CourseTimeEntity>> cache = getLockTimeCache(teacherId);
+        RMap<Long, List<CourseTimeEntity>> cache = getLiveLockTimeCache(teacherId);
         cache.expire(lockMinute, TimeUnit.MINUTES);
         return cache;
     }
 
-    private RMap<Long, List<CourseTimeEntity>> getLockTimeCache(Long teacherId) {
+    /**
+     * 获取老师锁定的直播课时数据的缓存
+     *
+     * @param teacherId 老师id
+     * @return 缓存 key teacherId value List<CourseTimeEntity>
+     */
+    public RMap<Long, List<CourseTimeEntity>> getLiveLockTimeCache(Long teacherId) {
         String key = String.join(":", LiveRoomConstant.COOLESHOW, CourseConstant.LOCK_COURSE_TIME_INFO, teacherId.toString());
         return redissonClient.getMap(key);
     }

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

@@ -11,10 +11,7 @@ import com.yonge.cooleshow.biz.dal.dao.CourseScheduleDao;
 import com.yonge.cooleshow.biz.dal.dto.search.MyCourseSearch;
 import com.yonge.cooleshow.biz.dal.entity.*;
 import com.yonge.cooleshow.biz.dal.enums.CourseScheduleEnum;
-import com.yonge.cooleshow.biz.dal.service.CourseScheduleService;
-import com.yonge.cooleshow.biz.dal.service.HolidaysFestivalsService;
-import com.yonge.cooleshow.biz.dal.service.SysConfigService;
-import com.yonge.cooleshow.biz.dal.service.TeacherFreeTimeService;
+import com.yonge.cooleshow.biz.dal.service.*;
 import com.yonge.cooleshow.biz.dal.support.PageUtil;
 import com.yonge.cooleshow.biz.dal.support.WrapperUtil;
 import com.yonge.cooleshow.biz.dal.vo.MyCourseVo;
@@ -25,6 +22,7 @@ import com.yonge.cooleshow.common.page.PageInfo;
 import com.yonge.toolset.utils.date.DateUtil;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.redisson.api.RMap;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -59,6 +57,8 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
     private SysConfigService sysConfigService;
     @Autowired
     private TeacherFreeTimeService teacherFreeTimeService;
+    @Autowired
+    private CourseGroupService courseGroupService;
 
     @Override
     public CourseScheduleDao getDao() {
@@ -519,7 +519,7 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
     }
 
     /**
-     * 查询老师及当前学生的课时
+     * 查询老师及当前学生的课时和目前直播课排课锁定在缓存的的课时
      *
      * @param teacherId 老师id
      * @param studentId 学员id
@@ -544,11 +544,35 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
         if (CollectionUtils.isNotEmpty(studentCourse)) {
             courseList.addAll(studentCourse);
         }
+        //查询当前老师直播课当前排课锁定的课时缓存-因为在学生购买老师课程时候老师可能正在排直播课,并且也将时间已经预排好了,所以需要查询缓存中的课时
+        RMap<Long, List<CourseTimeEntity>> lockTimeCache = courseGroupService.getLiveLockTimeCache(teacherId);
+        if (lockTimeCache.isExists()) {
+            List<CourseSchedule> lockCourseList = new ArrayList<>();
+            List<CourseTimeEntity> timeEntities = lockTimeCache.get(teacherId);
+            if (CollectionUtils.isNotEmpty(timeEntities)) {
+                timeEntities.forEach(courseTimeEntity -> {
+                    CourseSchedule lockCourse = new CourseSchedule();
+                    String ymd = DateUtil.dateToString(courseTimeEntity.getStartTime());
+                    lockCourse.setClassDate(DateUtil.toDate(ymd));
+                    lockCourse.setStartTime(courseTimeEntity.getStartTime());
+                    lockCourse.setEndTime(courseTimeEntity.getEndTime());
+                    lockCourseList.add(lockCourse);
+                });
+            }
+            if (CollectionUtils.isNotEmpty(lockCourseList)) {
+                courseList.addAll(lockCourseList);
+            }
+        }
         return getCourseListMap(courseList);
     }
 
+    /**
+     * 将课时数据结构化
+     *
+     * @param courseList 课程列表
+     * @return key:课程日期-年月日  value:课程
+     */
     private Map<String, List<CourseTimeEntity>> getCourseListMap(List<CourseSchedule> courseList) {
-        //key:课程日期-年月日  value:课程
         Map<String, List<CourseTimeEntity>> nowCourse = new HashMap<>();
         if (CollectionUtils.isNotEmpty(courseList)) {
             WrapperUtil.groupList(courseList, CourseSchedule::getClassDate)
@@ -566,8 +590,12 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
         return nowCourse;
     }
 
+    /**
+     * 获取当前登录人信息
+     */
     private SysUser getSysUser() {
-        return Optional.ofNullable(sysUserFeignService.queryUserInfo()).orElseThrow(() -> new BizException("用户不存在"));
+        return Optional.ofNullable(sysUserFeignService.queryUserInfo())
+                .orElseThrow(() -> new BizException("用户不存在"));
     }
 
     /**