Ver Fonte

fix cache

he2802 há 2 anos atrás
pai
commit
49db1e329a

+ 3 - 2
zhongzheng-common/src/main/java/com/zhongzheng/common/core/redis/RedisCache.java

@@ -5,6 +5,7 @@ import java.util.concurrent.TimeUnit;
 
 import cn.hutool.core.lang.Validator;
 import com.zhongzheng.common.utils.ServletUtils;
+import com.zhongzheng.common.utils.ToolsUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -60,7 +61,7 @@ public class RedisCache
     {
         String unionKey = key;
         if(Validator.isNotEmpty(ServletUtils.getRequest())){
-            String tenantId = ServletUtils.getRequest().getHeader("TenantId");
+            String tenantId = ToolsUtils.getTenantId();
             if(Validator.isNotEmpty(tenantId)){
                 unionKey = tenantId + key;
             }
@@ -111,7 +112,7 @@ public class RedisCache
         ValueOperations<String, T> operation = redisTemplate.opsForValue();
         String unionKey = key;
         if(Validator.isNotEmpty(ServletUtils.getRequest())){
-            String tenantId = ServletUtils.getRequest().getHeader("TenantId");
+            String tenantId = ToolsUtils.getTenantId();
             if(Validator.isNotEmpty(tenantId)){
                 unionKey = tenantId + key;
             }

+ 10 - 0
zhongzheng-common/src/main/java/com/zhongzheng/common/utils/ToolsUtils.java

@@ -1,11 +1,13 @@
 package com.zhongzheng.common.utils;
 
 import cn.hutool.core.lang.Validator;
+import cn.hutool.core.util.StrUtil;
 import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
 import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
 import com.aliyun.teaopenapi.models.Config;
 import com.zhongzheng.common.core.domain.AjaxResult;
 import io.micrometer.core.lang.NonNull;
+import net.sf.jsqlparser.expression.LongValue;
 
 import java.io.*;
 import java.nio.charset.StandardCharsets;
@@ -338,4 +340,12 @@ public class ToolsUtils {
         }
     }
 
+    public static String getTenantId() {
+        String TenantId = ServletUtils.getRequest().getHeader("TenantId");
+        if(!StrUtil.isNotBlank(TenantId)||TenantId==null){
+            TenantId = ServletUtils.getResponse().getHeader("TenantId");
+        }
+        return TenantId;
+    }
+
 }