From e685b58fd40cf28a20844643d70cc5f5b46ca037 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期五, 10 四月 2026 11:08:17 +0800
Subject: [PATCH] Merge branch 'master' of http://139.186.142.91:10010/r/productDev/gtzxinglijicun

---
 server/services/src/main/java/com/doumee/config/jwt/JwtTokenUtil.java |   32 ++++++++++++++++++++++++++++----
 1 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/server/services/src/main/java/com/doumee/config/jwt/JwtTokenUtil.java b/server/services/src/main/java/com/doumee/config/jwt/JwtTokenUtil.java
index 8e361d5..54bdf66 100644
--- a/server/services/src/main/java/com/doumee/config/jwt/JwtTokenUtil.java
+++ b/server/services/src/main/java/com/doumee/config/jwt/JwtTokenUtil.java
@@ -18,10 +18,7 @@
 
 import javax.annotation.Resource;
 import java.io.IOException;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 
 @Component
@@ -40,6 +37,8 @@
     @Resource
     private JwtProperties jwtProperties;
 
+    //redis杩囨湡鏃堕棿
+    private static final Integer redisExpire = 365;
     /**
      * 鐢熸垚token浠ょ墝
      *
@@ -67,6 +66,31 @@
     }
 
 
+
+    /**
+     * 鐢熸垚token淇℃伅锛堝悓涓�鐢ㄦ埛浠呬繚鐣欎竴涓湁鏁坱oken锛�
+     * @param userId
+     * @param userType 鐢ㄦ埛绫诲瀷 0=浼氬憳锛�1=鍙告満锛�2=搴楅摵
+     * @param userInfo
+     * @param redisTemplate
+     * @return
+     */
+    public static String generateTokenForRedis(Integer userId, Integer userType, String userInfo, RedisTemplate<String,Object> redisTemplate) {
+        // 鍒犻櫎璇ョ敤鎴蜂箣鍓嶇櫥褰曠殑token
+        String userTokenMappingKey = Constants.REDIS_TOKEN_KEY + "user_" + userType + "_" + userId;
+        String oldToken = (String) redisTemplate.opsForValue().get(userTokenMappingKey);
+        if (StringUtils.isNotBlank(oldToken)) {
+            redisTemplate.delete(Constants.REDIS_TOKEN_KEY + oldToken);
+        }
+        // 鐢熸垚鏂皌oken
+        String tokenKey = userType +""+ UUID.randomUUID() + "_" + userId;
+        redisTemplate.opsForValue().set(Constants.REDIS_TOKEN_KEY + tokenKey, userInfo, redisExpire, TimeUnit.DAYS);
+        // 璁板綍鐢ㄦ埛涓巘oken鐨勬槧灏勫叧绯�
+        redisTemplate.opsForValue().set(userTokenMappingKey, tokenKey, redisExpire, TimeUnit.DAYS);
+        return tokenKey;
+    }
+
+
     /**
      * 鍒锋柊浠ょ墝
      *

--
Gitblit v1.9.3