ソースを参照

解决城市等级Bug

JensionDzero 1 年間 前
コミット
3bb4e6366b

+ 7 - 4
benyun-core/src/main/java/com/ruoyi/benyun/init/BenyunCoreInit.java

@@ -55,14 +55,17 @@ public class BenyunCoreInit {
      */
     @PostConstruct
     public void initCityTierMap(){
-        if(redisTemplate.hasKey(RedisInitContant.INIT_CITY_TIER_MAP))
-            return;
+//        if(redisTemplate.hasKey(RedisInitContant.INIT_CITY_TIER_MAP))
+//            return;
         System.out.println("正在加载CityTierMap");
         QueryWrapper<AddrCategory> queryWrapper = new QueryWrapper<>();
-        queryWrapper.isNotNull("city_tier");
+        queryWrapper.eq("type","zone");
+        queryWrapper.and(addrCategoryQueryWrapper -> {
+            addrCategoryQueryWrapper.isNotNull("city_tier");
+        });
         for (AddrCategory addrCategory : addrCategoryDao.selectList(queryWrapper)) {
             if (addrCategory.getCityTier() != null && !addrCategory.getCityTier().equals("")) {
-                redisTemplate.boundHashOps(RedisInitContant.INIT_CITY_TIER_MAP).put(addrCategory.getAddrCode().substring(0, 4), addrCategory.getCityTier());
+                redisTemplate.boundHashOps(RedisInitContant.INIT_CITY_TIER_MAP).put(addrCategory.getAddrCode(), addrCategory.getCityTier());
             }
         }
         initCityTierListMap();

+ 30 - 0
ruoyi-admin/src/test/java/com/ruoyi/test/StatTest.java

@@ -1,15 +1,25 @@
 package com.ruoyi.test;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.ruoyi.demo.entity.AddrCategory;
+import com.ruoyi.demo.mapper.AddrCategoryDao;
 import com.ruoyi.demo.utils.statistics.BrandCityTierStat;
+import org.checkerframework.checker.units.qual.A;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 
+import java.util.List;
+import java.util.stream.Collectors;
+
 @SpringBootTest
 public class StatTest {
     @Autowired
     BrandCityTierStat brandCityTierStat;
 
+    @Autowired
+    AddrCategoryDao addrCategoryDao;
     @Test
     public void test(){
         brandCityTierStat.start();
@@ -19,4 +29,24 @@ public class StatTest {
     public void continueTest(){
         brandCityTierStat.continueInsert();
     }
+
+    @Test
+    public void cityTier(){
+        QueryWrapper<AddrCategory> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("type","city");
+        queryWrapper.and(categoryQueryWrapper -> {
+            categoryQueryWrapper.isNotNull("city_tier");
+        });
+        List<AddrCategory> addrCategories = addrCategoryDao.selectList(queryWrapper);
+
+        for (AddrCategory addrCategory : addrCategories) {
+            UpdateWrapper<AddrCategory> queryWrapper1 = new UpdateWrapper<>();
+            queryWrapper1.eq("type","zone");
+            queryWrapper1.and(addrCategoryUpdateWrapper -> {
+                addrCategoryUpdateWrapper.likeRight("addr_code",addrCategory.getAddrCode().substring(0,4));
+            });
+            queryWrapper1.set("city_tier",addrCategory.getCityTier());
+            addrCategoryDao.update(null,queryWrapper1);
+        }
+    }
 }

+ 6 - 5
ruoyi-demo/src/main/java/com/ruoyi/demo/init/BenyunCoreInit.java

@@ -48,11 +48,14 @@ public class BenyunCoreInit {
      */
     @PostConstruct
     public void initCityTierMap(){
-        if(redisTemplate.hasKey(RedisInitContant.INIT_CITY_TIER_MAP))
-            return;
+//        if(redisTemplate.hasKey(RedisInitContant.INIT_CITY_TIER_MAP))
+//            return;
         System.out.println("正在加载CityTierMap");
         QueryWrapper<AddrCategory> queryWrapper = new QueryWrapper<>();
-        queryWrapper.isNotNull("city_tier");
+        queryWrapper.eq("type","zone");
+        queryWrapper.and(categoryQueryWrapper -> {
+            categoryQueryWrapper.isNotNull("city_tier");
+        });
         for (AddrCategory addrCategory : addrCategoryDao.selectList(queryWrapper)) {
             if (addrCategory.getCityTier() != null && !addrCategory.getCityTier().equals("")) {
                 redisTemplate.boundHashOps(RedisInitContant.INIT_CITY_TIER_MAP).put(addrCategory.getAddrCode(), addrCategory.getCityTier());
@@ -67,8 +70,6 @@ public class BenyunCoreInit {
      * 一线城市的addrCode(redis)
      */
     public void initCityTierListMap(){
-        if(redisTemplate.hasKey(RedisInitContant.INIT_CITY_TIER_LIST_MAP))
-            return;
         System.out.println("正在加载CityTierListMap");
         List<String> one = new ArrayList<>();
         List<String> two = new ArrayList<>();