浏览代码

缓存时长校验

cy 3 年之前
父节点
当前提交
037967521a

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

@@ -73,6 +73,14 @@ public interface CourseGroupService extends IService<CourseGroup> {
     void unlockCourseToCache(Long teacherId);
 
     /**
+     * 获取老师锁定课时数据的缓存-设置过期时间
+     *
+     * @param teacherId 老师id
+     * @return 缓存
+     */
+    RMap<Long, List<CourseTimeEntity>> getExpireLiveLockTimeCache(Long teacherId);
+
+    /**
      * 获取老师锁定的直播课时数据的缓存
      *
      * @param teacherId 老师id

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

@@ -533,7 +533,7 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
      * @param teacherId 老师id
      * @return 缓存
      */
-    private RMap<Long, List<CourseTimeEntity>> getExpireLiveLockTimeCache(Long teacherId) {
+    public 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 = getLiveLockTimeCache(teacherId);

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

@@ -946,6 +946,20 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
         if (multiply.compareTo(scheduleDto.getCoursePrice()) != 0) {
             throw new BizException("价格异常。预计价格:{},实际价格:{}", multiply, scheduleDto.getCoursePrice());
         }
+
+        //获取老师锁课缓存
+        RMap<Long, List<CourseTimeEntity>> map = courseGroupService.getExpireLiveLockTimeCache(scheduleDto.getTeacherId());
+        if (map.isExists()) {
+            List<CourseTimeEntity> courseTimeCache = map.get(scheduleDto.getTeacherId());
+            //校验缓存中的时间和当前自动生成的时间有没有重复
+            dateList.forEach(item ->
+            {
+                if (!checkCourseTime(courseTimeCache, CourseTimeEntity::getStartTime, CourseTimeEntity::getEndTime, item.getStartTime(), item.getEndTime())) {
+                    throw new BizException("与缓存中时间存在中途");
+                }
+            });
+        }
+
         //批量检查老师课时在数据库是否重复
         batchCheckTeacherCourseTime(scheduleDto.getTeacherId(), dateList, CourseScheduleDate::getStartTime, CourseScheduleDate::getEndTime);
         //批量检查学生课时在数据库是否重复