Browse Source

fix 预发布

zoujiajian 3 years ago
parent
commit
f2caa08928

+ 15 - 0
netflix-service/src/main/java/com/cyksj/redis/RedisService.java

@@ -3,9 +3,11 @@ package com.cyksj.redis;
 import com.cyksj.common.util.StringUtil;
 import lombok.AllArgsConstructor;
 import lombok.Getter;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.PostConstruct;
 import javax.annotation.Resource;
 import java.util.Arrays;
 import java.util.List;
@@ -26,6 +28,16 @@ public class RedisService {
     @Resource
     private RedisTemplate<String, Object> redisTemplate;
 
+    public static String env = "dev";
+
+    @Value("${spring.profiles.active}")
+    private String active;
+
+    @PostConstruct
+    public void init(){
+        env = active + ":";
+    }
+
     /**
      * 指定缓存失效时间
      *
@@ -641,6 +653,9 @@ public class RedisService {
 
         private long timeout;
 
+        public String getEnvName() {
+            return this.name + env;
+        }
 
         public String getNameFormat(Object ... str) {
             return String.format(this.getName(), str);

+ 4 - 4
netflix-web/src/main/java/com/cyksj/web/controller/goods/GoodsDonController.java

@@ -157,7 +157,7 @@ public class GoodsDonController {
     @GetMapping("/get/list")
     public Result<List<GoodsFrontListView>> getGoodsList() {
         List<Long> filter_goodsIds = getFilterGoodsIds();
-        String pcCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "PC";
+        String pcCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "PC";
         if (CollUtil.isNotEmpty(filter_goodsIds)) {
             pcCacheKey += ":hz-ip";
         }
@@ -207,7 +207,7 @@ public class GoodsDonController {
     @GetMapping("/get/homePage")
     public Result<List<GoodsHomePageView>> getGoodsHomePage() {
         List<Long> filter_goodsIds = getFilterGoodsIds();
-        String h5CacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "H5";
+        String h5CacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "H5";
         if (CollUtil.isNotEmpty(filter_goodsIds)) {
             h5CacheKey += ":hz-ip";
         }
@@ -242,7 +242,7 @@ public class GoodsDonController {
      */
     @GetMapping("/get/register")
     public Result<List<RegisterGoodsDonView>> getRegisterGoodsDon() {
-        String registerCacheKey = RedisService.key.REGISTER_HOME_PAGE_CACHE.getName();
+        String registerCacheKey = RedisService.key.REGISTER_HOME_PAGE_CACHE.getEnvName();
         Object value = redisService.get(registerCacheKey);
         if (value != null) {
             try {
@@ -296,7 +296,7 @@ public class GoodsDonController {
      */
     @GetMapping("/get/recommend/{id}")
     public Result<List<GoodsRecommendViews>> getRecommendGoodsByGid(@PathVariable Long id) throws Exception {
-        String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "recommend:" + id;
+        String key = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "recommend:" + id;
         Object value = redisService.get(key);
         if (value != null) {
             List<GoodsRecommendViews> goodsRecommendViews = Jsons.parseList(value.toString(), GoodsRecommendViews.class);

+ 1 - 1
netflix-web/src/main/resources/application-pre.yml

@@ -22,7 +22,7 @@ spring:
     default-encoding: utf-8
   datasource:
     type: com.zaxxer.hikari.HikariDataSource
-    url: jdbc:mysql://172.17.0.17:3306/yhlxj?useAffectedRows=true
+    url: jdbc:mysql://sh-cdb-4tdnmrqa.sql.tencentcdb.com:63893/yhlxj_pre?useAffectedRows=true
     username: yhlxj
     password: yhlxj123
     platform: mysql