소스 검색

定时处理品牌名称多样化问题

JensionDzero 1 년 전
부모
커밋
9fb5fa4a44

+ 2 - 1
benyun-core/src/main/java/com/ruoyi/benyun/config/QuartzConfig.java

@@ -85,7 +85,8 @@ public class QuartzConfig {
     @Bean
     public Trigger BrandStatsiticsTrigger() {
         //定义Cron表达式
-        CronScheduleBuilder cron = CronScheduleBuilder.cronSchedule("0 0 18 13 11 ? ");
+        CronScheduleBuilder cron = CronScheduleBuilder.cronSchedule("0 0 22 1/14 * ? *");
+        //CronScheduleBuilder cron = CronScheduleBuilder.cronSchedule("0 30 11 16 11 ? ");
         cron.inTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
 
         return TriggerBuilder

+ 1 - 1
benyun-core/src/main/java/com/ruoyi/benyun/mapper/BrandCityDao.java

@@ -11,7 +11,7 @@ import java.util.List;
 @Mapper
 public interface BrandCityDao extends BaseMapper<BrandCity> {
     List<BrandCity> searchByBrandId(String brandId);
-    List<BrandCity> searchByBrandIdOrderByCity(String brandId,String month);
+    List<BrandCity> searchByBrandIdOrderByCity(@Param("cities") String brandId,@Param("cities") String month);
     void insertAll(@Param("cities") List<BrandCity> cities);
     List<String> selectIns();
     Integer selectCountByBrandId(String brandId);

+ 2 - 1
benyun-core/src/main/java/com/ruoyi/benyun/mapper/BrandStatisticsMapper.java

@@ -1,12 +1,13 @@
 package com.ruoyi.benyun.mapper;
 
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ruoyi.benyun.entity.BrandStatistics;
 import org.apache.ibatis.annotations.Mapper;
 
 import java.util.List;
 
 @Mapper
-public interface BrandStatisticsMapper {
+public interface BrandStatisticsMapper extends BaseMapper<BrandStatistics> {
     BrandStatistics searchByBrandId(String brandId);
     List<BrandStatistics> searchList();
 }

+ 1 - 1
benyun-core/src/main/java/com/ruoyi/benyun/service/impl/ChannelAnalyseServiceImpl.java

@@ -65,7 +65,7 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
 
         //1.获取所有符合条件的网点信息
         QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
-        queryWrapper.select("addr_code","count(wd_id) as audit");
+        queryWrapper.select("addr_code","count(*) as audit");
         assembleQueryWrapper(queryWrapper,channelMapAceeptVo);
         queryWrapper.groupBy("addr_code");
         List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);

+ 18 - 2
benyun-core/src/test/java/com/ruoyi/benyun/BenyunCoreApplicationTests.java

@@ -5,8 +5,10 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.ruoyi.benyun.constant.RedisContant;
 import com.ruoyi.benyun.constant.RedisInitContant;
 import com.ruoyi.benyun.entity.Brand;
+import com.ruoyi.benyun.entity.BrandStatistics;
 import com.ruoyi.benyun.entity.StoreWd;
 import com.ruoyi.benyun.mapper.BrandMapper;
+import com.ruoyi.benyun.mapper.BrandStatisticsMapper;
 import com.ruoyi.benyun.mapper.StoreWdDao;
 import com.ruoyi.benyun.mapper.WdInfoDao;
 import com.ruoyi.benyun.service.WriteService;
@@ -50,14 +52,28 @@ class BenyunCoreApplicationTests {
     @Autowired
     BrandMapper brandMapper;
 
+    @Autowired
+    BrandStatisticsMapper brandStatisticsMapper;
+
     @Autowired
     StoreWdDao storeWdDao;
 
     @Test
     void contextLoads() {
+        QueryWrapper<BrandStatistics> queryWrapper3 = new QueryWrapper<>();
+        queryWrapper3.select("brand_name");
+        queryWrapper3.ge("total",30);
+        queryWrapper3.orderByDesc("total");
+        List<BrandStatistics> brandStatistics = brandStatisticsMapper.selectList(queryWrapper3);
+        List<String> collect1 = brandStatistics.stream().map(item -> {
+            return item.getBrandName();
+        }).collect(Collectors.toList());
+
         ArrayList<String> moreBrandName = new ArrayList<>();
         ArrayList<String> existBrandName = new ArrayList<>();
-        for (String brandName : brandNames) {
+        int i = 1;
+        for (String brandName : collect1) {
+            System.out.println((i++) + "/"+collect1.size());
             //1.找到主品牌
             QueryWrapper<Brand> queryWrapper = new QueryWrapper<>();
             queryWrapper.select("brand_id","brand_name");
@@ -98,7 +114,7 @@ class BenyunCoreApplicationTests {
                 queryWrapper2.in("brand_id",collect);
                 brandMapper.delete(queryWrapper2);
             }catch (Exception exception){
-                exception.printStackTrace();
+                System.out.println("多个: "+brandName);
                 moreBrandName.add(brandName);
             }
         }

+ 13 - 0
ruoyi-demo/src/main/java/com/ruoyi/demo/constant/RedisContant.java

@@ -90,4 +90,17 @@ public class RedisContant {
 
     public int CITY_TIER_MAP_time = 60*8;
 
+    public static String COMMON_LEVEL = "commonLevel";
+
+    public static int COMMON_LEVEL_TIME = 60*8;
+
+
+    public static String COMMON_ADDR_CODE_MAP = "commonAddrCodeMap";
+
+    public static int COMMON_ADDR_CODE_MAP_TIME = 60*8;
+
+    public static String COMMON_TAG= "commonTag";
+
+    public static int COMMON_TAG_TIME = 60*8;
+
 }

+ 4 - 4
ruoyi-demo/src/main/java/com/ruoyi/demo/controller/ChannelAnalyseController.java

@@ -117,10 +117,10 @@ public class ChannelAnalyseController {
         String md5 = channelMapAceeptVo.getHash();
 
         //2.查看redis中是否存在有缓存
-//        HashMap<String,Integer> wdCount = (HashMap<String,Integer>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE).get(md5);
-//        if (wdCount != null) {
-//            return R.ok(wdCount);
-//        }
+        HashMap<String,Integer> wdCount = (HashMap<String,Integer>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE).get(md5);
+        if (wdCount != null) {
+            return R.ok(wdCount);
+        }
         HashMap<String,Integer> hashMap = channelAnalyseService.businessStatusAnalyse(channelMapAceeptVo);
 
         //4.保存到redis中

+ 7 - 7
ruoyi-demo/src/main/java/com/ruoyi/demo/controller/ChannelMapController.java

@@ -67,13 +67,13 @@ public class ChannelMapController {
     public R list(@Validated(value={ChannelListGroup.class}) ChannelMapAceeptVo channel){
 
         String md5 = channel.getHash();
-//        HashMap pageInfo = (HashMap) redisTemplate.boundHashOps(RedisContant.CHANNEL_MAP_LIST).get(md5);
-//        if(pageInfo != null){
-//            List<WdTopologicalInfoBo> data = (List<WdTopologicalInfoBo>) pageInfo.get("data");
-//            attention(data);
-//            pageInfo.put("data",data);
-//            return R.ok(pageInfo);
-//        }
+        HashMap pageInfo = (HashMap) redisTemplate.boundHashOps(RedisContant.CHANNEL_MAP_LIST).get(md5);
+        if(pageInfo != null){
+            List<WdTopologicalInfoBo> data = (List<WdTopologicalInfoBo>) pageInfo.get("data");
+            attention(data);
+            pageInfo.put("data",data);
+            return R.ok(pageInfo);
+        }
 
         HashMap hashMap = channelMapService.list(channel);
         if(hashMap == null)

+ 37 - 0
ruoyi-demo/src/main/java/com/ruoyi/demo/controller/CommonController.java

@@ -2,32 +2,69 @@ package com.ruoyi.demo.controller;
 
 
 import com.ruoyi.common.core.domain.R;
+import com.ruoyi.demo.constant.RedisContant;
+import com.ruoyi.demo.entity.AddrCategory;
+import com.ruoyi.demo.entity.bo.WdCount;
 import com.ruoyi.demo.entity.vo.AddrCategoryBody;
 import com.ruoyi.demo.entity.vo.TypeByBody;
 import com.ruoyi.demo.service.CommonService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 @RestController
 @RequestMapping("/common")
 public class CommonController {
     @Autowired
     CommonService commonService;
+
+    @Autowired
+    RedisTemplate redisTemplate;
     //获取网点标签
     @GetMapping("/tag")
     public R tag(){
+        List<TypeByBody>  wdCount = (List<TypeByBody>) redisTemplate.boundValueOps(RedisContant.COMMON_TAG).get();
+        if (wdCount != null) {
+            return R.ok(wdCount);
+        }
+
         List<TypeByBody> tag = commonService.tag();
+        //4.保存到redis中
+        redisTemplate.boundValueOps(RedisContant.COMMON_TAG).set(tag);
+        redisTemplate.expire(RedisContant.COMMON_TAG,RedisContant.COMMON_TAG_TIME, TimeUnit.MINUTES); //30分钟
         return R.ok(tag);
     }
 
     //获取网点标签
     @GetMapping("/addrCodeMap")
     public R addrCodeMap(){
+        List<AddrCategoryBody>  wdCount = (List<AddrCategoryBody>) redisTemplate.boundValueOps(RedisContant.COMMON_ADDR_CODE_MAP).get();
+        if (wdCount != null) {
+            return R.ok(wdCount);
+        }
+
         List<AddrCategoryBody> addrCategoryBodies = commonService.addrCodeMap();
+        redisTemplate.boundValueOps(RedisContant.COMMON_ADDR_CODE_MAP).set(wdCount);
+        redisTemplate.expire(RedisContant.COMMON_ADDR_CODE_MAP,RedisContant.COMMON_ADDR_CODE_MAP_TIME, TimeUnit.MINUTES); //30分钟
         return R.ok(addrCategoryBodies);
     }
+
+    @GetMapping("/addrCodeLevel")
+    public R addrCodeLevel(String code,String level){
+        //2.查看redis中是否存在有缓存
+        List<AddrCategory>  wdCount = (List<AddrCategory> ) redisTemplate.boundHashOps(RedisContant.COMMON_LEVEL).get(code+level);
+        if (wdCount != null) {
+            return R.ok(wdCount);
+        }
+
+        List<AddrCategory> addrCategories = commonService.addrCodeLevel(code,level);
+        redisTemplate.boundHashOps(RedisContant.COMMON_LEVEL).put(code+level,addrCategories);
+        redisTemplate.expire(RedisContant.COMMON_LEVEL,RedisContant.COMMON_LEVEL_TIME, TimeUnit.MINUTES); //30分钟
+        return R.ok(addrCategories);
+    }
 }

+ 2 - 0
ruoyi-demo/src/main/java/com/ruoyi/demo/service/CommonService.java

@@ -2,6 +2,7 @@ package com.ruoyi.demo.service;
 
 
 
+import com.ruoyi.demo.entity.AddrCategory;
 import com.ruoyi.demo.entity.vo.AddrCategoryBody;
 import com.ruoyi.demo.entity.vo.TypeByBody;
 
@@ -11,4 +12,5 @@ public interface CommonService {
     List<AddrCategoryBody> addrCodeMap();
     List<TypeByBody> tag();
 
+    List<AddrCategory> addrCodeLevel(String code, String level);
 }

+ 27 - 0
ruoyi-demo/src/main/java/com/ruoyi/demo/service/impl/CommonServiceImpl.java

@@ -1,6 +1,7 @@
 package com.ruoyi.demo.service.impl;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.ruoyi.demo.entity.AddrCategory;
 import com.ruoyi.demo.entity.TypeBy;
 import com.ruoyi.demo.entity.vo.AddrCategoryBody;
@@ -48,6 +49,32 @@ public class CommonServiceImpl implements CommonService {
         return typeByBodies;
     }
 
+    @Override
+    public List<AddrCategory> addrCodeLevel(String code,String level) {
+        if ("province".equals(level)){
+            QueryWrapper<AddrCategory> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("city","");
+            return addrCategoryDao.selectList(queryWrapper);
+        }else if("city".equals(level)){
+            QueryWrapper<AddrCategory> queryWrapper = new QueryWrapper<>();
+            queryWrapper.likeRight("addr_code",code.substring(0,2));
+            queryWrapper.and(categoryQueryWrapper -> {
+                categoryQueryWrapper.eq("district", "").and(addrCategoryQueryWrapper -> {
+                    addrCategoryQueryWrapper.ne("city", "");
+                });
+            });
+            return addrCategoryDao.selectList(queryWrapper);
+        }else if("zone".equals(level)){
+            QueryWrapper<AddrCategory> queryWrapper = new QueryWrapper<>();
+            queryWrapper.likeRight("addr_code",code.substring(0,4));
+            queryWrapper.and(categoryQueryWrapper -> {
+                categoryQueryWrapper.ne("district", "");
+            });
+            return addrCategoryDao.selectList(queryWrapper);
+        }
+        return null;
+    }
+
     public List<TypeByBody> findChild(List<TypeBy> typeBIES, String typeCodeBy, int randType){
         String substring = typeCodeBy.substring(0, randType);
         if(randType == 2){