Explorar o código

人均消费直方图

JensionDzero hai 1 ano
pai
achega
729e1f58f9

+ 10 - 12
benyun-core/src/main/java/com/ruoyi/benyun/utils/WdRedisStoreage.java

@@ -15,10 +15,7 @@ import org.springframework.data.redis.connection.RedisGeoCommands;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
@@ -196,20 +193,21 @@ public class WdRedisStoreage {
         QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
         queryWrapper.ge("collect_time",time);
 
-        HashMap<String,Integer> hashMap = new HashMap<>();
-        hashMap.put("total",1);
-        CompletableFuture<Void> future = null;
+        Hashtable<String,Integer> hashtable = new Hashtable<>();
+        hashtable.put("total",0);
+        List<CompletableFuture<Void>> completableFutureList = new ArrayList<>();
         List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
         for (WdInfo wdInfo : wdInfos) {
             //开启线程
-            future = CompletableFuture.runAsync(()->{
+            completableFutureList.add(CompletableFuture.runAsync(()->{
                 redisTemplate.boundGeoOps(wdInfo.getAddrCode().substring(0,4)).add(new Point(wdInfo.getLng().doubleValue(),wdInfo.getLat().doubleValue()),wdInfo.getWdId());
-                 System.out.println("进度:"+wdInfos.size()+"/"+hashMap.get("total"));
-                 hashMap.put("total",hashMap.get("total")+1);
-            },executorService);
+                wdTagAnalyse(wdInfo);
+                System.out.println("进度:"+wdInfos.size()+"/"+hashtable.get("total"));
+                hashtable.put("total",hashtable.get("total")+1);
+            },executorService));
         }
         try {
-            future.get();
+            CompletableFuture.allOf(completableFutureList.toArray(new CompletableFuture[0])).get();
         } catch (InterruptedException e) {
             throw new RuntimeException(e);
         } catch (ExecutionException e) {

+ 1 - 1
ruoyi-admin/src/main/resources/application-prod.yml

@@ -124,7 +124,7 @@ spring:
     lettuce:
       pool:
         min-idle: 0
-        max-active: 8
+        max-active: 12
         max-wait: -1
         max-idle: 8
         enabled: true

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

@@ -46,6 +46,10 @@ public class RedisContant {
 
     public static int CHANNEL_ANALYSE_AROUND_BUILD_ANALYSE_TIME = 60*8;
 
+    public static String CHANNEL_ANALYSE_PER_CAPITA_COSUMP_ANALYSE= "channel_analyse_pre_capita_cosump_analyse";
+
+    public static int CHANNEL_ANALYSE_PER_CAPITA_COSUMP_ANALYSE_TIME = 60*8;
+
     public static String TOPOLOGICAL_COMMON_MAP = "topological_common_map";
     public static int TOPOLOGICAL_COMMON_MAP_TIME = 60*8;
 

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

@@ -5,6 +5,7 @@ import com.github.pagehelper.PageInfo;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.demo.constant.RedisContant;
 import com.ruoyi.demo.entity.Brand;
+import com.ruoyi.demo.entity.bo.Histogram;
 import com.ruoyi.demo.entity.bo.StoreWdCategoryCount;
 import com.ruoyi.demo.entity.vo.ChannelAnalyseAceeptVo;
 import com.ruoyi.demo.entity.vo.ChannelMapAceeptVo;
@@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.List;
@@ -133,15 +135,33 @@ public class ChannelAnalyseController {
         String md5 = channelMapAceeptVo.getHash();
 
         //2.查看redis中是否存在有缓存
-//        HashMap<String,Integer> wdCount = (HashMap<String,Integer>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_AROUND_BUILD_ANALYSE).get(md5);
+        ArrayList<Histogram> wdCount = (ArrayList<Histogram>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_AROUND_BUILD_ANALYSE).get(md5);
+        if (wdCount != null) {
+            return R.ok(wdCount);
+        }
+        ArrayList<Histogram> hashtable = channelAnalyseService.aroundBuildAnalyse(channelMapAceeptVo);
+
+        //4.保存到redis中
+        redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_AROUND_BUILD_ANALYSE).put(md5,hashtable);
+        redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_AROUND_BUILD_ANALYSE,RedisContant.CHANNEL_ANALYSE_AROUND_BUILD_ANALYSE_TIME, TimeUnit.MINUTES); //30分钟
+
+        return R.ok(hashtable);
+    }
+
+    @GetMapping("/perCapitaConsumpAnalyse")
+    public R perCapitaConsumpAnalyse(ChannelMapAceeptVo channelMapAceeptVo){
+        String md5 = channelMapAceeptVo.getHash();
+
+        //2.查看redis中是否存在有缓存
+//        ArrayList<Histogram> wdCount = (ArrayList<Histogram>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_PER_CAPITA_COSUMP_ANALYSE).get(md5);
 //        if (wdCount != null) {
 //            return R.ok(wdCount);
 //        }
-        Hashtable<String, Integer> hashtable = channelAnalyseService.aroundBuildAnalyse(channelMapAceeptVo);
+        ArrayList<Histogram> hashtable = channelAnalyseService.perCapitaConsumpAnalyse(channelMapAceeptVo);
 
         //4.保存到redis中
         redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE).put(md5,hashtable);
-        redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE,RedisContant.CHANNEL_ANALYSE_AROUND_BUILD_ANALYSE_TIME, TimeUnit.MINUTES); //30分钟
+        redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_PER_CAPITA_COSUMP_ANALYSE,RedisContant.CHANNEL_ANALYSE_PER_CAPITA_COSUMP_ANALYSE_TIME, TimeUnit.MINUTES); //30分钟
 
         return R.ok(hashtable);
     }

+ 1 - 1
ruoyi-demo/src/main/java/com/ruoyi/demo/entity/StoreWd.java

@@ -18,7 +18,7 @@ public class StoreWd implements Serializable {
     @TableField("brand_name")
     private String brandName;
     @TableField("per_capita_consumption")
-    private String perCapitaConsumption;
+    private Double perCapitaConsumption;
     @TableField("manage_type_code")
     private String manageTypeCode;
     @TableField("industry_code")

+ 9 - 0
ruoyi-demo/src/main/java/com/ruoyi/demo/entity/bo/Histogram.java

@@ -0,0 +1,9 @@
+package com.ruoyi.demo.entity.bo;
+
+import lombok.Data;
+
+@Data
+public class Histogram {
+    private String name;
+    private int count;
+}

+ 7 - 0
ruoyi-demo/src/main/java/com/ruoyi/demo/init/BenyunCoreInit.java

@@ -10,6 +10,7 @@ import com.ruoyi.demo.mapper.AddrCategoryDao;
 import com.ruoyi.demo.mapper.TypeByDao;
 import com.ruoyi.demo.service.ManageTypeService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.data.redis.core.BoundHashOperations;
 import org.springframework.data.redis.core.RedisTemplate;
@@ -18,6 +19,7 @@ import javax.annotation.PostConstruct;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
+import java.util.concurrent.*;
 
 @Configuration
 public class BenyunCoreInit {
@@ -33,6 +35,11 @@ public class BenyunCoreInit {
     @Autowired
     RedisTemplate redisTemplate;
 
+    @Bean("executor")
+    public ExecutorService getExecutor() {
+        return new ThreadPoolExecutor(0,10,10, TimeUnit.SECONDS,new LinkedBlockingDeque<>(1000000), Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());
+    }
+
     /**
      * HashMap<地区Code,城市等级>(redis版本)
      */

+ 5 - 1
ruoyi-demo/src/main/java/com/ruoyi/demo/service/ChannelAnalyseService.java

@@ -2,11 +2,13 @@ package com.ruoyi.demo.service;
 
 import com.github.pagehelper.PageInfo;
 import com.ruoyi.demo.entity.Brand;
+import com.ruoyi.demo.entity.bo.Histogram;
 import com.ruoyi.demo.entity.bo.StoreWdCategoryCount;
 import com.ruoyi.demo.entity.vo.ChannelAnalyseAceeptVo;
 import com.ruoyi.demo.entity.vo.ChannelMapAceeptVo;
 
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.List;
@@ -22,7 +24,9 @@ public interface ChannelAnalyseService {
 
     HashMap<String,Integer> businessStatusAnalyse(ChannelMapAceeptVo channelMapAceeptVo);
 
-    Hashtable<String, Integer> aroundBuildAnalyse(ChannelMapAceeptVo channelMapAceeptVo);
+    ArrayList<Histogram> aroundBuildAnalyse(ChannelMapAceeptVo channelMapAceeptVo);
+
+    ArrayList<Histogram> perCapitaConsumpAnalyse(ChannelMapAceeptVo channelMapAceeptVo);
 
 //    void businessAnalyse(ChannelMapAceeptVo channelMapAceeptVo);
 }

+ 83 - 27
ruoyi-demo/src/main/java/com/ruoyi/demo/service/impl/ChannelAnalyseServiceImpl.java

@@ -7,6 +7,7 @@ import com.ruoyi.demo.entity.Brand;
 import com.ruoyi.demo.entity.ManageType;
 import com.ruoyi.demo.entity.StoreWd;
 import com.ruoyi.demo.entity.WdInfo;
+import com.ruoyi.demo.entity.bo.Histogram;
 import com.ruoyi.demo.entity.bo.StoreWdCategoryCount;
 import com.ruoyi.demo.entity.bo.StoreWdCategoryCountBody;
 import com.ruoyi.demo.entity.vo.ChannelAnalyseAceeptVo;
@@ -58,8 +59,6 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
     @Autowired
     private StoreWdDao storeWdDao;
 
-    @Autowired
-    private RedisTemplate redisTemplate;
 
     @Autowired
     @Qualifier("executor")
@@ -299,40 +298,95 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
     }
 
     @Override
-    public Hashtable<String, Integer> aroundBuildAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
+    public ArrayList<Histogram> aroundBuildAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
         QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
-        queryWrapper.select("wd_id","wd_type_code","lat","lng");
+        queryWrapper.select("type_code_by","count(*) as audit");
         assembleQueryWrapper(queryWrapper,channelMapAceeptVo);
         queryWrapper.and(queryWrapper1 -> {
             queryWrapper1.eq("wd_type_code","3");
         });
+        queryWrapper.groupBy("type_code_by");
         List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
-
-        Hashtable<String,Integer> hashtable = new Hashtable<>();
-        hashtable.put("0~100",0);
-        hashtable.put("100~500",0);
-        hashtable.put("500~1000",0);
-        hashtable.put("1000以上",0);
-        ArrayList<CompletableFuture<Void>> list = new ArrayList<>();
+        int total = 0;
+        HashMap<String,Integer> hashMap = new HashMap<>();
         for (WdInfo wdInfo : wdInfos) {
-            list.add(CompletableFuture.runAsync(() -> {
-                //半径范围
-                Distance distance = new Distance(1000, RedisGeoCommands.DistanceUnit.METERS);
-                GeoResults radius = redisTemplate.boundGeoOps(wdInfo.getAddrCode().substring(0, 4)).radius(wdInfo.getWdId(), distance);
-                int size = radius.getContent().size();
-                if (size <= 100)
-                    hashtable.put("0~100", hashtable.get("0~100") + 1);
-                else if (size > 100 && size <= 500)
-                    hashtable.put("100~500", hashtable.get("100~500") + 1);
-                else if (size > 500 && size <= 1000)
-                    hashtable.put("500~1000", hashtable.get("500~1000") + 1);
-                else
-                    hashtable.put("1000以上", hashtable.get("1000以上") + 1);
-            }));
+            if(wdInfo.getTypeCodeBy() == null)
+                continue;
+            String typeCodeBy = wdInfo.getTypeCodeBy().substring(0,2);
+            Integer integer = hashMap.get(typeCodeBy);
+            if (integer == null){
+                hashMap.put(typeCodeBy,wdInfo.getAudit());
+            }else {
+                hashMap.put(typeCodeBy,hashMap.get(typeCodeBy)+wdInfo.getAudit());
+            }
+            total+=wdInfo.getAudit();
+        }
+        ArrayList<Histogram> list = new ArrayList<>();
+        for (String s : hashMap.keySet()) {
+            Integer integer = hashMap.get(s);
+            String initTypeByMap = initMapUtil.getInitTypeByMap(s + "0000").replace(":","");
+            Histogram histogram = new Histogram();
+            histogram.setName(initTypeByMap);
+            histogram.setCount(integer);
+            list.add(histogram);
+        }
+
+        return list;
+    }
+
+    @Override
+    public ArrayList<Histogram> perCapitaConsumpAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
+        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("wd_id");
+        assembleQueryWrapper(queryWrapper,channelMapAceeptVo);
+        queryWrapper.and(queryWrapper1 -> {
+            queryWrapper1.eq("wd_type_code","1");
+        });
+        List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
+
+        List<String> collect = wdInfos.stream().map(item -> {
+            return item.getWdId();
+        }).collect(Collectors.toList());
+
+        HashMap<String, Integer> hashMap = new HashMap<>();
+        hashMap.put("0~20",0);
+        hashMap.put("20~50",0);
+        hashMap.put("50~100",0);
+        hashMap.put("100~200",0);
+        hashMap.put("200以上",0);
+        if (!collect.isEmpty()){
+            QueryWrapper<StoreWd> queryWrapper1 = new QueryWrapper<>();
+            queryWrapper1.select("per_capita_consumption");
+            //queryWrapper1.in("wd_id",collect);
+            for (String s : collect) {
+                queryWrapper1.eq("wd_id",s).or();
+            }
+            List<StoreWd> storeWds = storeWdDao.selectList(queryWrapper1);
+            for (StoreWd storeWd : storeWds) {
+                if (storeWd.getPerCapitaConsumption() != null){
+                    if (storeWd.getPerCapitaConsumption() >= 0 && storeWd.getPerCapitaConsumption()<20){
+                        hashMap.put("0~20",hashMap.get("0~20")+1);
+                    }else if(storeWd.getPerCapitaConsumption() >= 20 && storeWd.getPerCapitaConsumption()<50){
+                        hashMap.put("20~50",hashMap.get("20~50")+1);
+                    }else if(storeWd.getPerCapitaConsumption() >= 50 && storeWd.getPerCapitaConsumption()< 100){
+                        hashMap.put("50~100",hashMap.get("50~1000")+1);
+                    }else if(storeWd.getPerCapitaConsumption() >= 100 && storeWd.getPerCapitaConsumption()< 200){
+                        hashMap.put("100~200",hashMap.get("100~200")+1);
+                    }else {
+                        hashMap.put("200以上",hashMap.get("200以上")+1);
+                    }
+                }
+            }
         }
-        CompletableFuture.allOf(list.toArray(new CompletableFuture[0]));
 
-        return hashtable;
+        ArrayList<Histogram> list = new ArrayList<>();
+        for (String s : hashMap.keySet()) {
+            Histogram histogram = new Histogram();
+            histogram.setName(s);
+            histogram.setCount(hashMap.get(s));
+            list.add(histogram);
+        }
+        return list;
     }
 
     public void assembleQueryWrapper(QueryWrapper<WdInfo> queryWrapper,ChannelMapAceeptVo channelMapAceeptVo){
@@ -406,4 +460,6 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
 
     }
 
+
+
 }

+ 0 - 4
ruoyi-demo/src/main/java/com/ruoyi/demo/utils/InitMapUtil.java

@@ -16,10 +16,6 @@ public class InitMapUtil {
     @Autowired
     RedisTemplate redisTemplate;
 
-    @Bean("executor")
-    public ExecutorService getExecutor() {
-        return new ThreadPoolExecutor(0,10,10,TimeUnit.SECONDS,new LinkedBlockingDeque<>(1000000),Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());
-    }
 
     public String getInitCityTierMap(String addrCode){
         return (String) redisTemplate.boundHashOps(RedisInitContant.INIT_CITY_TIER_MAP).get(addrCode.substring(0,4));