Bläddra i källkod

新增营业状态、商圈分析

JensionDzero 1 år sedan
förälder
incheckning
32e9e60bf7

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

@@ -38,6 +38,14 @@ public class RedisContant {
 
     public static int CHANNEL_ANALYSE_TAG_ANLYSE_TIME = 60*8;
 
+    public static String CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE= "channel_analyse_business_status_analyse";
+
+    public static int CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE_TIME = 60*8;
+
+    public static String CHANNEL_ANALYSE_AROUND_BUILD_ANALYSE= "channel_analyse_around_build_analyse";
+
+    public static int CHANNEL_ANALYSE_AROUND_BUILD_ANALYSE_TIME = 60*8;
+
     public static String TOPOLOGICAL_COMMON_MAP = "topological_common_map";
     public static int TOPOLOGICAL_COMMON_MAP_TIME = 60*8;
 

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

@@ -12,10 +12,12 @@ import com.ruoyi.demo.entity.vo.TagAnalyse;
 import com.ruoyi.demo.service.ChannelAnalyseService;
 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.HashMap;
+import java.util.Hashtable;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
@@ -28,7 +30,7 @@ public class ChannelAnalyseController {
     @Autowired
     RedisTemplate redisTemplate;
 
-    @RequestMapping("/cityTier")
+    @GetMapping("/cityTier")
     public R cityTier(ChannelMapAceeptVo channelMapAceeptVo){
         String md5 = channelMapAceeptVo.getHash();
 
@@ -46,7 +48,7 @@ public class ChannelAnalyseController {
         return R.ok(hashMap);
     }
 
-    @RequestMapping("/brandList")
+    @GetMapping("/brandList")
     public R brandList(ChannelAnalyseAceeptVo channelAnalyseAceeptVo){
         String md5 = channelAnalyseAceeptVo.getHash();
 
@@ -64,7 +66,7 @@ public class ChannelAnalyseController {
         return R.ok(brandPageInfo);
     }
 
-    @RequestMapping("/category")
+    @GetMapping("/category")
     public R category(ChannelMapAceeptVo channelMapAceeptVo){
         String md5 = channelMapAceeptVo.getHash();
 
@@ -81,7 +83,7 @@ public class ChannelAnalyseController {
         return R.ok(category);
     }
 
-    @RequestMapping("/tagAnalyse")
+    @GetMapping("/tagAnalyse")
     public R tagAnalyse(ChannelMapAceeptVo channelMapAceeptVo){
         Integer page = channelMapAceeptVo.getPageNum() == null ? 1:channelMapAceeptVo.getPageNum();
         channelMapAceeptVo.setPageNum(0);
@@ -108,6 +110,42 @@ public class ChannelAnalyseController {
         return R.ok(result);
     }
 
+    @GetMapping("/businessStatusAnalyse")
+    public R businessStatusAnalyse(ChannelMapAceeptVo channelMapAceeptVo){
+        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> hashMap = channelAnalyseService.businessStatusAnalyse(channelMapAceeptVo);
+
+        //4.保存到redis中
+        redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE).put(md5,hashMap);
+        redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE,RedisContant.CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE_TIME, TimeUnit.MINUTES); //30分钟
+
+        return R.ok(hashMap);
+    }
+
+    @GetMapping("/aroundBuildAnalyse")
+    public R aroundBuildAnalyse(ChannelMapAceeptVo channelMapAceeptVo){
+        String md5 = channelMapAceeptVo.getHash();
+
+        //2.查看redis中是否存在有缓存
+//        HashMap<String,Integer> wdCount = (HashMap<String,Integer>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_AROUND_BUILD_ANALYSE).get(md5);
+//        if (wdCount != null) {
+//            return R.ok(wdCount);
+//        }
+        Hashtable<String, Integer> hashtable = channelAnalyseService.aroundBuildAnalyse(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分钟
+
+        return R.ok(hashtable);
+    }
+
 //    @RequestMapping("/businessAnalyse")
 //    public R businessAnalyse(ChannelMapAceeptVo channelMapAceeptVo){
 //        channelAnalyseService.businessAnalyse(channelMapAceeptVo);

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

@@ -8,6 +8,7 @@ import com.ruoyi.demo.entity.vo.ChannelMapAceeptVo;
 
 
 import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.List;
 
 public interface ChannelAnalyseService {
@@ -19,5 +20,9 @@ public interface ChannelAnalyseService {
 
     List<StoreWdCategoryCount> category(ChannelMapAceeptVo channelMapAceeptVo);
 
+    HashMap<String,Integer> businessStatusAnalyse(ChannelMapAceeptVo channelMapAceeptVo);
+
+    Hashtable<String, Integer> aroundBuildAnalyse(ChannelMapAceeptVo channelMapAceeptVo);
+
 //    void businessAnalyse(ChannelMapAceeptVo channelMapAceeptVo);
 }

+ 76 - 1
ruoyi-demo/src/main/java/com/ruoyi/demo/service/impl/ChannelAnalyseServiceImpl.java

@@ -21,7 +21,14 @@ import com.ruoyi.demo.utils.InitMapUtil;
 import com.ruoyi.demo.utils.WdRedisStoreage;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.data.geo.Circle;
+import org.springframework.data.geo.Distance;
+import org.springframework.data.geo.GeoResults;
+import org.springframework.data.geo.Point;
+import org.springframework.data.redis.connection.RedisGeoCommands;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
 
 import java.math.BigDecimal;
 import java.util.*;
@@ -48,10 +55,12 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
     @Autowired
     private WdRedisStoreage wdRedisStoreage;
 
-
     @Autowired
     private StoreWdDao storeWdDao;
 
+    @Autowired
+    private RedisTemplate redisTemplate;
+
     @Autowired
     @Qualifier("executor")
     ExecutorService executor;
@@ -257,9 +266,75 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
             storeWdCategoryCounts.add(hashMap.get(s));
         }
 
+
         return storeWdCategoryCounts;
     }
 
+    @Override
+    public HashMap<String,Integer> businessStatusAnalyse(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(wdInfo -> {
+            return wdInfo.getWdId();
+        }).collect(Collectors.toList());
+        QueryWrapper<StoreWd> queryWrapper1 = new QueryWrapper<>();
+        queryWrapper1.select("business_status","count(*) as comment_count")
+            .in("wd_id",collect)
+            .groupBy("business_status");
+        List<StoreWd> storeWds = storeWdDao.selectList(queryWrapper1);
+        HashMap<String,Integer> hashMap = new HashMap<>();
+        int total = 0;
+        for (StoreWd storeWd : storeWds) {
+            total+=storeWd.getCommentCount();
+            hashMap.put(storeWd.getBusinessStatus(),storeWd.getCommentCount());
+        }
+        hashMap.put("total",total);
+        return hashMap;
+    }
+
+    @Override
+    public Hashtable<String, Integer> aroundBuildAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
+        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("wd_id","wd_type_code","lat","lng");
+        assembleQueryWrapper(queryWrapper,channelMapAceeptVo);
+        queryWrapper.and(queryWrapper1 -> {
+            queryWrapper1.eq("wd_type_code","3");
+        });
+        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<>();
+        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);
+            }));
+        }
+        CompletableFuture.allOf(list.toArray(new CompletableFuture[0]));
+
+        return hashtable;
+    }
+
     public void assembleQueryWrapper(QueryWrapper<WdInfo> queryWrapper,ChannelMapAceeptVo channelMapAceeptVo){
         //1.根据不同级别得到需要查询的 地区码
         List<String> addrCodeList = new ArrayList<>();