deason 1 年之前
父節點
當前提交
e2428b1b95

+ 10 - 30
src/main/java/com/qmth/exam/reserve/cache/CacheConstants.java

@@ -6,44 +6,24 @@ package com.qmth.exam.reserve.cache;
 public interface CacheConstants {
 
     /**
-     * 缓存策略:禁止空值
-     */
-    String DISABLE_NULL_VALUE = "#result == null";
-
-    /**
-     * 用户登录会话缓存前缀
-     */
-    String CACHE_SESSION_PREFIX = "$SESSION:";
-
-    /**
-     * 用户登录标识_{userId}
-     */
-    String CACHE_USER_LOGIN = "U_";
-
-    /**
-     * 学生登录标识_{studentId}
-     */
-    String CACHE_STUDENT_LOGIN = "S_";
-
-    /**
-     * 当前预约任务 - 某考点某时段的“可预约总量”的缓存
-     * $cache:apply_total_{examSiteId}_{timePeriodId}
+     * 预约任务 - 某考点某时段的“可预约总量”的缓存
+     * $cache:apply_total:{examSiteId}_{timePeriodId}
      * Value:总量
      */
-    String CACHE_APPLY_TOTAL = "apply_total_%s_%s";
+    String CACHE_APPLY_TOTAL = "$cache:apply_total:%s_%s";
 
     /**
-     * 当前预约任务 - 某考点某时段的“已预约数量”的缓存
-     * $cache:apply_finish_{examSiteId}_{timePeriodId}
+     * 预约任务 - 某考点某时段的“已预约数量”的缓存
+     * $cache:apply_finish:{examSiteId}_{timePeriodId}
      * Value:已约量
      */
-    String CACHE_APPLY_FINISH = "apply_finish_%s_%s";
+    String CACHE_APPLY_FINISH = "$cache:apply_finish:%s_%s";
 
     /**
      * 某考生预约操作锁
-     * $lock:student_apply_{studentId}
+     * $lock:student_apply:{studentId}
      */
-    String LOCK_STUDENT_APPLY = "student_apply_%s";
+    String LOCK_STUDENT_APPLY = "student_apply:%s";
 
     /**
      * 系统自动为考生预约操作锁
@@ -53,8 +33,8 @@ public interface CacheConstants {
 
     /**
      * 自动排考
-     * $lock:arrange_exam_{yyyyMMdd}
+     * $lock:arrange_exam:{yyyyMMdd}
      */
-    String LOCK_ARRANGE_EXAM = "arrange_exam_%s";
+    String LOCK_ARRANGE_EXAM = "arrange_exam:%s";
 
 }

+ 0 - 32
src/main/java/com/qmth/exam/reserve/cache/LoginSessionManager.java

@@ -1,32 +0,0 @@
-package com.qmth.exam.reserve.cache;
-
-import com.qmth.exam.reserve.bean.login.LoginUser;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.Resource;
-import java.util.concurrent.TimeUnit;
-
-/**
- * 登录用户会话管理
- */
-@Component
-public class LoginSessionManager {
-
-    private final long SESSION_TIMEOUT = 60;
-
-    @Resource
-    private RedisClient redisClient;
-
-    public LoginUser getLoginSession(String sessionId) {
-        return redisClient.get(CacheConstants.CACHE_SESSION_PREFIX + sessionId, LoginUser.class, SESSION_TIMEOUT, TimeUnit.MINUTES);
-    }
-
-    public void addLoginSession(LoginUser session) {
-        redisClient.set(CacheConstants.CACHE_SESSION_PREFIX + session.getSessionId(), session, SESSION_TIMEOUT, TimeUnit.MINUTES);
-    }
-
-    public void removeLoginSession(String sessionId) {
-        redisClient.delete(CacheConstants.CACHE_SESSION_PREFIX + sessionId);
-    }
-
-}

+ 11 - 0
src/main/java/com/qmth/exam/reserve/cache/impl/ApplyTaskCacheService.java

@@ -1,8 +1,10 @@
 package com.qmth.exam.reserve.cache.impl;
 
 import com.qmth.exam.reserve.cache.CacheConstants;
+import com.qmth.exam.reserve.cache.RedisClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 @Component
@@ -10,10 +12,19 @@ public class ApplyTaskCacheService implements CacheConstants {
 
     private static final Logger log = LoggerFactory.getLogger(ApplyTaskCacheService.class);
 
+    @Autowired
+    private RedisClient redisClient;
+
     /**
      * 获取某考点某时段的“可预约总量”
      */
     public int getApplyTotalCount(Long examSiteId, Long timePeriodId) {
+        String cacheKey = String.format(CACHE_APPLY_TOTAL, examSiteId, timePeriodId);
+        Integer value = redisClient.get(cacheKey, Integer.class);
+        if (value != null) {
+            return value;
+        }
+        // todo
         return 1;
     }
 

+ 51 - 0
src/main/java/com/qmth/exam/reserve/cache/impl/LoginSessionManager.java

@@ -0,0 +1,51 @@
+package com.qmth.exam.reserve.cache.impl;
+
+import com.qmth.exam.reserve.bean.login.LoginUser;
+import com.qmth.exam.reserve.cache.RedisClient;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * 登录用户会话管理
+ */
+@Component
+public class LoginSessionManager {
+
+    /**
+     * 用户登录会话缓存过期时间(分钟)
+     */
+    public static final long SESSION_TIMEOUT = 60;
+
+    /**
+     * 用户登录会话缓存前缀
+     */
+    public static final String CACHE_SESSION_PREFIX = "$SESSION:";
+
+    /**
+     * 用户登录标识_{userId}
+     */
+    public static final String USER_LOGIN = "U_";
+
+    /**
+     * 学生登录标识_{studentId}
+     */
+    public static final String STUDENT_LOGIN = "S_";
+
+    @Resource
+    private RedisClient redisClient;
+
+    public LoginUser getLoginSession(String sessionId) {
+        return redisClient.get(CACHE_SESSION_PREFIX + sessionId, LoginUser.class, SESSION_TIMEOUT, TimeUnit.MINUTES);
+    }
+
+    public void addLoginSession(LoginUser session) {
+        redisClient.set(CACHE_SESSION_PREFIX + session.getSessionId(), session, SESSION_TIMEOUT, TimeUnit.MINUTES);
+    }
+
+    public void removeLoginSession(String sessionId) {
+        redisClient.delete(CACHE_SESSION_PREFIX + sessionId);
+    }
+
+}

+ 4 - 5
src/main/java/com/qmth/exam/reserve/service/impl/AuthServiceImpl.java

@@ -9,8 +9,7 @@ import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
 import com.qmth.exam.reserve.bean.login.LoginReq;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.login.WechatLoginReq;
-import com.qmth.exam.reserve.cache.CacheConstants;
-import com.qmth.exam.reserve.cache.LoginSessionManager;
+import com.qmth.exam.reserve.cache.impl.LoginSessionManager;
 import com.qmth.exam.reserve.entity.ApplyTaskEntity;
 import com.qmth.exam.reserve.entity.StudentEntity;
 import com.qmth.exam.reserve.entity.UserEntity;
@@ -73,7 +72,7 @@ public class AuthServiceImpl implements AuthorizationService<LoginUser>, AuthSer
         loginUser.setOrgId(user.getOrgId());
         loginUser.setCategoryId(user.getCategoryId());
 
-        loginUser.setSessionId(CacheConstants.CACHE_USER_LOGIN + user.getId());
+        loginUser.setSessionId(LoginSessionManager.USER_LOGIN + user.getId());
         loginUser.setToken(FastUUID.get());
         loginSessionManager.addLoginSession(loginUser);
 
@@ -117,7 +116,7 @@ public class AuthServiceImpl implements AuthorizationService<LoginUser>, AuthSer
         loginUser.setApplyTaskId(student.getApplyTaskId());
         loginUser.setOpenId(student.getOpenId());
 
-        loginUser.setSessionId(CacheConstants.CACHE_STUDENT_LOGIN + student.getId());
+        loginUser.setSessionId(LoginSessionManager.STUDENT_LOGIN + student.getId());
         loginUser.setToken(FastUUID.get());
         loginSessionManager.addLoginSession(loginUser);
 
@@ -152,7 +151,7 @@ public class AuthServiceImpl implements AuthorizationService<LoginUser>, AuthSer
         loginUser.setApplyTaskId(student.getApplyTaskId());
         loginUser.setOpenId(student.getOpenId());
 
-        loginUser.setSessionId(CacheConstants.CACHE_STUDENT_LOGIN + student.getId());
+        loginUser.setSessionId(LoginSessionManager.STUDENT_LOGIN + student.getId());
         loginUser.setToken(FastUUID.get());
         loginSessionManager.addLoginSession(loginUser);