Browse Source

精准营销-plus-改良算法(v2.0)

JensionDzero 1 year ago
parent
commit
c153eb8cab
30 changed files with 1173 additions and 786 deletions
  1. 2 2
      benyun-core/Dockerfile
  2. 4 0
      benyun-core/pom.xml
  3. 27 27
      benyun-core/src/main/java/com/benyun/core/config/QuartzConfig.java
  4. 10 0
      benyun-core/src/main/java/com/benyun/core/constant/RedisContant.java
  5. 3 3
      benyun-core/src/main/java/com/benyun/core/controller/ChannelAnalyseController.java
  6. 4 4
      benyun-core/src/main/java/com/benyun/core/controller/ChannelMapController.java
  7. 4 4
      benyun-core/src/main/java/com/benyun/core/controller/TopologicalStoreWdController.java
  8. 5 0
      benyun-core/src/main/java/com/benyun/core/dao/HouseWdDao.java
  9. 0 1
      benyun-core/src/main/java/com/benyun/core/entity/TopologicalHouseWdStatisticsData.java
  10. 1 1
      benyun-core/src/main/java/com/benyun/core/entity/bo/BuildWdCategoryCount.java
  11. 1 1
      benyun-core/src/main/java/com/benyun/core/entity/bo/WdCountBody.java
  12. 28 16
      benyun-core/src/main/java/com/benyun/core/entity/bo/WdTopologicalInfoBo.java
  13. 28 6
      benyun-core/src/main/java/com/benyun/core/entity/vo/ChannelMapAceeptVo.java
  14. 9 10
      benyun-core/src/main/java/com/benyun/core/entity/vo/TopologicalWdAceeptVo.java
  15. 64 8
      benyun-core/src/main/java/com/benyun/core/init/BenyunCoreInit.java
  16. 4 19
      benyun-core/src/main/java/com/benyun/core/job/AnalyseJob.java
  17. 2 2
      benyun-core/src/main/java/com/benyun/core/service/ChannelAnalyseService.java
  18. 3 2
      benyun-core/src/main/java/com/benyun/core/service/ChannelMapService.java
  19. 71 197
      benyun-core/src/main/java/com/benyun/core/service/impl/ChannelAnalyseServiceImpl.java
  20. 243 202
      benyun-core/src/main/java/com/benyun/core/service/impl/ChannelMapServiceImpl.java
  21. 87 50
      benyun-core/src/main/java/com/benyun/core/service/impl/TopologicalBuildWdSereviceImpl.java
  22. 41 16
      benyun-core/src/main/java/com/benyun/core/service/impl/TopologicalCommonServiceImpl.java
  23. 51 25
      benyun-core/src/main/java/com/benyun/core/service/impl/TopologicalEnterpriseWdServiceImpl.java
  24. 91 40
      benyun-core/src/main/java/com/benyun/core/service/impl/TopologicalHouseServiceWdImpl.java
  25. 131 71
      benyun-core/src/main/java/com/benyun/core/service/impl/TopologicalStoreWdServiceImpl.java
  26. 148 0
      benyun-core/src/main/java/com/benyun/core/utils/WdRedisStoreage.java
  27. 26 12
      benyun-core/src/main/resources/application-prod.yaml
  28. 16 0
      benyun-core/src/main/resources/mapper/HouseWdDao.xml
  29. 14 12
      benyun-core/src/test/java/com/benyun/core/BenyunCoreApplicationTests.java
  30. 55 55
      benyun-core/src/test/java/com/benyun/core/service/ChannelMapServiceImplTest.java

+ 2 - 2
benyun-core/Dockerfile

@@ -11,11 +11,11 @@ WORKDIR /data/bailian-biz
 #ENV SERVER_PORT=9210
 #
 
-ADD ./target/benyun-core-4.8.0.jar ./ds.jar
+ADD ./target/benyun-core-4.8.0.jar ./app.jar
 
 ENTRYPOINT ["java", \
             "-Djava.security.egd=file:/dev/./urandom", \
 #            "-Dserver.port=${SERVER_PORT}", \
 #            "-Dskywalking.agent.service_name=saas-auth", \
 #            "-javaagent:/ruoyi/skywalking/agent/skywalking-agent.jar", \
-            "-jar", "ds.jar"]
+            "-jar", "app.jar"]

+ 4 - 0
benyun-core/pom.xml

@@ -72,6 +72,10 @@
             <scope>test</scope>
         </dependency>
 
+        <dependency>
+            <groupId>redis.clients</groupId>
+            <artifactId>jedis</artifactId>
+        </dependency>
 
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 27 - 27
benyun-core/src/main/java/com/benyun/core/config/QuartzConfig.java

@@ -11,34 +11,34 @@ import org.springframework.context.annotation.Configuration;
 * 定时器:分析网点数据
 * */
 @Slf4j
-@Configuration
+//@Configuration
 public class QuartzConfig {
     // 创建一个封装Job对象的类型JobDetall,并放入Spring容器中
-//    @Bean
-//    public JobDetail clearImgJobDetail(){
-//        log.info("分析网点数据的 JobDetall");
-//
-//        return JobBuilder.newJob(AnalyseJob.class) //newJob方法就是在绑定要运行的Job接口实现。
-//            .withIdentity("abcJobDetail") //给当前JobDetail对象取名字
-//            .storeDurably() //及时没有触发器绑定当前JobDetail对象,也不会被删除
-//            .build();
-//    }
-//
-//    //触发器声明,设置job的运行时机,并放入Spring容器中
-//    @Bean
-//    public Trigger clearImgTrigger(){
-//        log.info("创建分析网点数据的 Trigger");
-//
-//
-//        //定义Cron表达式
-//        CronScheduleBuilder cron  = CronScheduleBuilder.cronSchedule("0 38 9 3 9 ? ");
-//
-//        return TriggerBuilder
-//            .newTrigger()
-//            .forJob(clearImgJobDetail()) //绑定要运行的JobDetail对象,这是得到的是Spring容器里的JobDetail
-//            .withIdentity("abcTrigger") //给当前Trigger对象起名字,名字任意
-//            .withSchedule(cron) //绑定cron表达式
-//            .build();
-//    }
+    @Bean
+    public JobDetail clearImgJobDetail(){
+        log.info("分析网点数据的 JobDetall");
+
+        return JobBuilder.newJob(AnalyseJob.class) //newJob方法就是在绑定要运行的Job接口实现。
+            .withIdentity("abcJobDetail") //给当前JobDetail对象取名字
+            .storeDurably() //及时没有触发器绑定当前JobDetail对象,也不会被删除
+            .build();
+    }
+
+    //触发器声明,设置job的运行时机,并放入Spring容器中
+    @Bean
+    public Trigger clearImgTrigger(){
+        log.info("创建分析网点数据的 Trigger");
+
+
+        //定义Cron表达式
+        CronScheduleBuilder cron  = CronScheduleBuilder.cronSchedule("0 30 3 13 9 ? ");
+
+        return TriggerBuilder
+            .newTrigger()
+            .forJob(clearImgJobDetail()) //绑定要运行的JobDetail对象,这是得到的是Spring容器里的JobDetail
+            .withIdentity("abcTrigger") //给当前Trigger对象起名字,名字任意
+            .withSchedule(cron) //绑定cron表达式
+            .build();
+    }
 
 }

+ 10 - 0
benyun-core/src/main/java/com/benyun/core/constant/RedisContant.java

@@ -43,4 +43,14 @@ public class RedisContant {
 
     public static String CHANNEL_ANALYSE_BRANDLIST = "channel_analyse_brandList";
     public static int CHANNEL_ANALYSE_BRANDLIST_TIME = 60*8;
+
+    public static String CHANNEL_MAP_TAG_STOREAGE = "channel_map_tag_storeage";
+
+    public static int CHANNEL_MAP_TAG_STOREAGE_TIME = 60*8;
+    public static String WD_TAG = "wd_tag";
+    public static int WD_TAG_TIME = 60*8;
+
+    public static String WD_POINT = "wd_point";  //保存网点的经纬度坐标
+    public static int WD_POINT_TIME = 60*8;
+
 }

+ 3 - 3
benyun-core/src/main/java/com/benyun/core/controller/ChannelAnalyseController.java

@@ -28,8 +28,8 @@ public class ChannelAnalyseController {
     RedisTemplate redisTemplate;
 
     @RequestMapping("/cityTier")
-    public R cityTier(ChannelAnalyseAceeptVo channelAnalyseAceeptVo){
-        String md5 = channelAnalyseAceeptVo.getHash();
+    public R cityTier(ChannelMapAceeptVo channelMapAceeptVo){
+        String md5 = channelMapAceeptVo.getHash();
 
         //2.查看redis中是否存在有缓存
         HashMap wdCount = (HashMap) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_CITYTIER).get(md5);
@@ -37,7 +37,7 @@ public class ChannelAnalyseController {
             return R.ok(wdCount);
         }
 
-        HashMap hashMap = channelAnalyseService.cityTier(channelAnalyseAceeptVo);
+        HashMap hashMap = channelAnalyseService.cityTier(channelMapAceeptVo);
 
         //4.保存到redis中
         redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_CITYTIER).put(md5,hashMap);

+ 4 - 4
benyun-core/src/main/java/com/benyun/core/controller/ChannelMapController.java

@@ -50,7 +50,7 @@ public class ChannelMapController {
         }
 
         //3.redis中没有,直接请求
-        WdCount area = channelMapService.area(Arrays.asList(channel.getChannel()), channel.getRankType(), channel.getSearchText(), channel.getAddrCode());
+        WdCount area = channelMapService.area(channel);
         if(area == null)
             return R.fail("请求参数错误");
 
@@ -73,7 +73,7 @@ public class ChannelMapController {
             return R.ok(pageInfo);
         }
 
-        HashMap hashMap = channelMapService.list(channel.getChannel(), channel.getRankType(), channel.getSearchText(), channel.getOrderby(), channel.getAddrCode(), channel.getPageNum(), channel.getPageSize());
+        HashMap hashMap = channelMapService.list(channel);
         if(hashMap == null)
             return R.fail("请求参数错误");
 
@@ -107,7 +107,7 @@ public class ChannelMapController {
     //Todo 标记网点关注
     public void attention(List<WdTopologicalInfoBo> wdTopologicalInfoBos){
         List<String> collect = wdTopologicalInfoBos.stream().map(wdTopologicalInfoBo -> {
-            return wdTopologicalInfoBo.getCenterWdId();
+            return wdTopologicalInfoBo.getWdId();
         }).collect(Collectors.toList());
 
         //标志是否关注
@@ -121,7 +121,7 @@ public class ChannelMapController {
             }).collect(Collectors.toList());
 
             for (WdTopologicalInfoBo wdTopologicalInfoBo : wdTopologicalInfoBos) {
-                boolean contains = collect1.contains(wdTopologicalInfoBo.getCenterWdId());
+                boolean contains = collect1.contains(wdTopologicalInfoBo.getWdId());
                 if (contains)
                     wdTopologicalInfoBo.setAttention(1);
                 else

+ 4 - 4
benyun-core/src/main/java/com/benyun/core/controller/TopologicalStoreWdController.java

@@ -34,10 +34,10 @@ public class TopologicalStoreWdController {
     public R category(@Validated(value = {TopologicalWdGroup.class}) TopologicalWdAceeptVo topologicalWdAceeptVo){
         String md5 = topologicalWdAceeptVo.getHash();
         //2.查看redis中是否存在有缓存
-//        List<StoreWdCategoryCount>wdCount = (List<StoreWdCategoryCount>) redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_STORE_WD_CATEGORY).get(md5);
-//        if (wdCount != null) {
-//            return R.ok(wdCount);
-//        }
+        List<StoreWdCategoryCount>wdCount = (List<StoreWdCategoryCount>) redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_STORE_WD_CATEGORY).get(md5);
+        if (wdCount != null) {
+            return R.ok(wdCount);
+        }
 
         List<StoreWdCategoryCount> category = topologicalStoreWdService.category(topologicalWdAceeptVo);
 

+ 5 - 0
benyun-core/src/main/java/com/benyun/core/dao/HouseWdDao.java

@@ -2,8 +2,13 @@ package com.benyun.core.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.benyun.core.entity.HouseWd;
+import com.benyun.core.entity.TopologicalHouseWdStatisticsData;
+import com.benyun.core.entity.WdInfo;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
+
 @Mapper
 public interface HouseWdDao extends BaseMapper<HouseWd> {
+    List<TopologicalHouseWdStatisticsData> selectAndStatistics(List<String> list);
 }

+ 0 - 1
benyun-core/src/main/java/com/benyun/core/entity/TopologicalHouseWdStatisticsData.java

@@ -7,7 +7,6 @@ import lombok.Data;
 import java.time.LocalDateTime;
 
 @Data
-@TableName("bl_topological_house_wd_statistics_data")
 public class TopologicalHouseWdStatisticsData {
 
     @TableField("center_wd_id")

+ 1 - 1
benyun-core/src/main/java/com/benyun/core/entity/bo/BuildWdCategoryCount.java

@@ -4,7 +4,7 @@ import lombok.Data;
 
 @Data
 public class BuildWdCategoryCount {
-    public String name;
+    private String name;
     private int count;
     private double radio;
 }

+ 1 - 1
benyun-core/src/main/java/com/benyun/core/entity/bo/WdCountBody.java

@@ -11,6 +11,6 @@ public class WdCountBody implements Serializable {
     private BigDecimal lat;
     private BigDecimal lng;
     private String addrCode;
-    private Long count;
+    private int count;
     private float radio;
 }

+ 28 - 16
benyun-core/src/main/java/com/benyun/core/entity/bo/WdTopologicalInfoBo.java

@@ -2,6 +2,7 @@ package com.benyun.core.entity.bo;
 
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.benyun.core.entity.WdInfo;
 import com.benyun.core.entity.WdTopologicalInfo;
 import lombok.Data;
 
@@ -13,9 +14,9 @@ import java.util.List;
 @Data
 @TableName("bl_wd_topological_info")
 public class WdTopologicalInfoBo {
-    private String centerWdId;
-    private String centerWdName;
-    private String centerWdTypeCode;
+    private String wdId;
+    private String wdName;
+    private String wdTypeCode;
 
     private String typeCodeBy;
 
@@ -33,21 +34,32 @@ public class WdTopologicalInfoBo {
     @TableField("analyse_time")
     private LocalDateTime analyseTime;
 
-    public WdTopologicalInfoBo(WdTopologicalInfo wdTopologicalInfo) {
-        this.centerWdId = wdTopologicalInfo.getCenterWdId();
-        this.centerWdName = wdTopologicalInfo.getCenterWdName();
-        this.centerWdTypeCode = wdTopologicalInfo.getCenterWdTypeCode();
-        this.typeCodeBy = wdTopologicalInfo.getTypeCodeBy();
-        this.radius = wdTopologicalInfo.getRadius();
-        this.addrCode = wdTopologicalInfo.getAddrCode();
-        this.addrCodeInfo = wdTopologicalInfo.getAddrCodeInfo();
-        this.addrInfo = wdTopologicalInfo.getAddrInfo();
-        this.lat = wdTopologicalInfo.getLat();
-        this.lng = wdTopologicalInfo.getLng();
-        this.geoHash = wdTopologicalInfo.getGeoHash();
-        this.analyseTime = wdTopologicalInfo.getAnalyseTime();
+    public WdTopologicalInfoBo(WdInfo wdInfo) {
+        this.wdId = wdInfo.getWdId();
+        this.wdName = wdInfo.getWdName();
+        this.wdTypeCode = wdInfo.getWdTypeCode();
+        this.typeCodeBy = wdInfo.getTypeCodeBy();
+        this.addrCode = wdInfo.getAddrCode();
+        this.addrInfo = wdInfo.getAddrInfo();
+        this.lat = wdInfo.getLat();
+        this.lng = wdInfo.getLng();
+        this.geoHash = wdInfo.getGeoHash();
+        this.radius = 1000;
     }
 
     public WdTopologicalInfoBo() {
     }
+
+    public WdTopologicalInfoBo(WdTopologicalInfo wdInfo) {
+        this.wdId = wdInfo.getCenterWdId();
+        this.wdName = wdInfo.getCenterWdName();
+        this.wdTypeCode = wdInfo.getCenterWdTypeCode();
+        this.typeCodeBy = wdInfo.getTypeCodeBy();
+        this.addrCode = wdInfo.getAddrCode();
+        this.addrInfo = wdInfo.getAddrInfo();
+        this.lat = wdInfo.getLat();
+        this.lng = wdInfo.getLng();
+        this.geoHash = wdInfo.getGeoHash();
+        this.radius = 1000;
+    }
 }

+ 28 - 6
benyun-core/src/main/java/com/benyun/core/entity/vo/ChannelMapAceeptVo.java

@@ -13,19 +13,29 @@ import javax.validation.constraints.NotEmpty;
 @Data
 public class ChannelMapAceeptVo {
 
-    String[] channel;  //网点类型,渠道(0:基础设施网点、1:门店网点、2:小区网点、3:楼宇网点、4:交通设施网点、5:公司网点)
+    /*
+    * 搜索字段
+    * */
+    String searchText;  //网点关键字
+    String brandName; //品牌名称
+
+    /*
+    * 分类字段
+    * */
+    String[] channel;  //渠道分类(0:基础设施网点、1:门店网点、2:小区网点、3:楼宇网点、4:交通设施网点、5:公司网点)
+
     @NotBlank(groups = { ChannelAreaGroup.class, ChannelListGroup.class},message = "rankType不能为空")
     String rankType; //搜索等级(province:搜索省、city:搜素市、zone:搜素区)
 
-    String searchText; //搜索关键字
-
     /*
     * 地区编码code
     * 当 rankType = province,city 需要提交省区码编码
     * 当 rankType = zone 需要提交市区码编码
     * */
     @NotEmpty(groups = {ChannelPointGroup.class},message = "地区码为空")
-    String[] addrCode;
+    String[] addrCode; //地区Code
+
+    String[] cityTier; //["一线","新一线"、"二线"、"三线"、"四线"、"五线"]
 
     String orderby = ""; //排序字段,(list接口)
 
@@ -55,6 +65,11 @@ public class ChannelMapAceeptVo {
     public String getHash(){
         StringBuilder stringBuilder = new StringBuilder();
 
+        //搜索文本
+        stringBuilder.append(this.searchText);
+        //搜索品牌
+        stringBuilder.append(this.brandName);
+
         //搜索渠道
         for (String s : getChannel()) {
             stringBuilder.append(s);
@@ -63,14 +78,21 @@ public class ChannelMapAceeptVo {
         //搜索等级
         stringBuilder.append(this.rankType);
 
-        //搜索文本
-        stringBuilder.append(this.searchText);
 
         //搜索地区
         for (String s : getAddrCode()) {
             stringBuilder.append(s);
         }
 
+        //城市等级
+        if(this.cityTier != null && this.cityTier.length > 0){
+            for (String s : this.cityTier) {
+                stringBuilder.append(s);
+            }
+        }
+
+        stringBuilder.append(orderby);
+        stringBuilder.append(size);
         stringBuilder.append(pageNum);
         stringBuilder.append(pageSize);
 

+ 9 - 10
benyun-core/src/main/java/com/benyun/core/entity/vo/TopologicalWdAceeptVo.java

@@ -12,20 +12,21 @@ import javax.validation.constraints.NotNull;
 @Data
 public class TopologicalWdAceeptVo {
 
+    //中心网点Id
     @NotBlank(groups = {TopologicalWdGroup.class,TopologicalWdListGroup.class},message = "请选择中心点")
     String centerWdId;
+
+    //半径范围
     @NotNull(groups = {TopologicalWdGroup.class,TopologicalWdListGroup.class},message = "半径范围未正确选择")
     int radius;
-    int size = 10;
 
-    @NotBlank(groups = {TopologicalWdListGroup.class},message = "geoHash不能为空")
-    String geoHash;
+    //地区Code
+    String addrCode;
 
-    @NotNull(groups = {TopologicalWdListGroup.class},message = "lat不能为空")
-    double lat;
-    @NotNull(groups = {TopologicalWdListGroup.class},message = "lng不能为空")
-    double lng;
+    //限制条数
+    int size = 10;
 
+    //网点分类
     String[] channel;
 
 
@@ -34,9 +35,7 @@ public class TopologicalWdAceeptVo {
         stringBuilder.append(centerWdId);
         stringBuilder.append(radius);
         stringBuilder.append(size);
-        stringBuilder.append(geoHash);
-        stringBuilder.append(lat);
-        stringBuilder.append(lng);
+
         for (String s : getChannel()) {
             stringBuilder.append(s);
         }

+ 64 - 8
benyun-core/src/main/java/com/benyun/core/init/BenyunCoreInit.java

@@ -1,5 +1,6 @@
 package com.benyun.core.init;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.benyun.core.dao.AddrCategoryDao;
 import com.benyun.core.dao.TypeByDao;
 import com.benyun.core.entity.AddrCategory;
@@ -11,7 +12,11 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 @Configuration
 public class BenyunCoreInit {
@@ -24,22 +29,72 @@ public class BenyunCoreInit {
     @Autowired
     TypeByDao byDao;
 
+    @Bean("executor")
+    public ExecutorService getExecutor(){
+        return Executors.newFixedThreadPool(2);
+    }
+
+    /**
+     * HashMap<地区Code,城市等级>
+     * */
     @Bean("cityTierMap")
-    public HashMap getCityTierMap(){
+    public HashMap<String, String> getCityTierMap(){
         HashMap<String, String> hashMap = new HashMap<>();
-        for (AddrCategory addrCategory : addrCategoryDao.selectList(null)) {
+
+        QueryWrapper<AddrCategory> queryWrapper = new QueryWrapper<>();
+        queryWrapper.isNotNull("city_tier");
+        for (AddrCategory addrCategory : addrCategoryDao.selectList(queryWrapper)) {
             if(addrCategory.getCityTier() != null && !addrCategory.getCityTier().equals("")){
-                if(addrCategory.getDistrict()!=null && !addrCategory.getDistrict().equals("")){
-                    hashMap.put(addrCategory.getAddrCode(), addrCategory.getCityTier());
-                }else if(addrCategory.getCity()!=null && !addrCategory.getCity().equals("")){
-                    hashMap.put(addrCategory.getAddrCode().substring(0,4), addrCategory.getCityTier());
-                }else
-                    hashMap.put(addrCategory.getAddrCode().substring(0,2), addrCategory.getCityTier());
+                hashMap.put(addrCategory.getAddrCode().substring(0,4), addrCategory.getCityTier());
             }
         }
         return hashMap;
     }
 
+    /**
+     * 一线城市的addrCode
+     * */
+    @Bean("cityTierListMap")
+    public HashMap<String,List<String>> getCityTierListMap(){
+        List<String> one = new ArrayList<>();
+        List<String> two = new ArrayList<>();
+        List<String> three = new ArrayList<>();
+        List<String> four = new ArrayList<>();
+        List<String> five = new ArrayList<>();
+
+        HashMap<String, String> cityTierMap = getCityTierMap();
+        for (String s : cityTierMap.keySet()) {
+            String s1 = cityTierMap.get(s);
+            switch (s1){
+                case "一线":
+                    one.add(s);
+                    break;
+                case "二线":
+                    two.add(s);
+                    break;
+                case "三线":
+                    three.add(s);
+                    break;
+                case "四线":
+                    four.add(s);
+                    break;
+                case "五线":
+                    five.add(s);
+                    break;
+            }
+        }
+        HashMap<String,List<String>> util = new HashMap<>();
+        util.put("一线",one);
+        util.put("二线",two);
+        util.put("三线",three);
+        util.put("四线",four);
+        util.put("五线",five);
+        return util;
+    }
+
+
+
+
     @Bean("ManageType")
     public HashMap getManageType(){
         HashMap<String,ManageType> hashMap = new HashMap<>();
@@ -50,6 +105,7 @@ public class BenyunCoreInit {
         return hashMap;
     }
 
+
     @Bean("addrCodeMap")
     public HashMap getAddrCodeMap(){
         HashMap<String,String> hashMap = new HashMap<>();

+ 4 - 19
benyun-core/src/main/java/com/benyun/core/job/AnalyseJob.java

@@ -4,11 +4,13 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.benyun.core.dao.WdInfoDao;
 import com.benyun.core.entity.WdInfo;
 import com.benyun.core.service.AnalyseWdService;
+import com.benyun.core.utils.WdRedisStoreage;
 import lombok.extern.slf4j.Slf4j;
 import org.quartz.Job;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Component;
 
 import java.time.LocalDateTime;
@@ -25,30 +27,13 @@ import java.util.concurrent.Executors;
 public class AnalyseJob implements Job {
 
     @Autowired
-    AnalyseWdService analyseWdService;
-
-    public static ExecutorService executor = Executors.newFixedThreadPool(10);
+    WdRedisStoreage wdRedisStoreage;
 
     @Autowired
     WdInfoDao wdInfoDao;
 
     @Override
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
-        ZoneId zone = ZoneId.of("Asia/Shanghai");
-        LocalDateTime now = LocalDateTime.now(zone);  //分析时间
-
-        System.out.println("start:");
-
-        //测试需要
-        QueryWrapper<WdInfo> queryWrapper1 = new QueryWrapper<>();
-        queryWrapper1.in("wd_type_code", Arrays.asList("1","2","3"));
-
-        List<WdInfo> wdInfos1 = wdInfoDao.selectList(queryWrapper1);
-        int index = 1;
-        System.out.println(wdInfos1.size());
-        //1.遍历所有网点
-        for (WdInfo wdInfo : wdInfos1) {
-            analyseWdService.analyse(wdInfo,now,wdInfos1.size(),index++);
-        }
+        wdRedisStoreage.writeWdGeoRedis();
     }
 }

+ 2 - 2
benyun-core/src/main/java/com/benyun/core/service/ChannelAnalyseService.java

@@ -11,11 +11,11 @@ import java.util.HashMap;
 import java.util.List;
 
 public interface ChannelAnalyseService {
-    public HashMap cityTier(ChannelAnalyseAceeptVo channelAnalyseAceeptVo);
+    public HashMap cityTier(ChannelMapAceeptVo channelMapAceeptVo);
 
     PageInfo<Brand> brandList(ChannelAnalyseAceeptVo channelAnalyseAceeptVo);
 
     HashMap<String,Object> tagAnalyse(ChannelMapAceeptVo channelMapAceeptVo);
 
-    void businessAnalyse(ChannelMapAceeptVo channelMapAceeptVo);
+//    void businessAnalyse(ChannelMapAceeptVo channelMapAceeptVo);
 }

+ 3 - 2
benyun-core/src/main/java/com/benyun/core/service/ChannelMapService.java

@@ -3,14 +3,15 @@ package com.benyun.core.service;
 import com.benyun.core.entity.WdTopologicalInfo;
 import com.benyun.core.entity.bo.WdCount;
 import com.benyun.core.entity.WdInfo;
+import com.benyun.core.entity.vo.ChannelMapAceeptVo;
 import com.github.pagehelper.PageInfo;
 
 import java.util.HashMap;
 import java.util.List;
 
 public interface ChannelMapService {
-    public WdCount area(List<String> channel, String rankType, String searchText, String[] addrCode);
-    public HashMap list(String[] channel, String rankType, String searchText, String orderby, String[] addrCode, int pageNum, int pageSize);
+    public WdCount area(ChannelMapAceeptVo channel);
+    public HashMap list(ChannelMapAceeptVo channel);
 
     public PageInfo<WdInfo> point(String[] channel, String searchText, String[] addrCode, int pageNum, int pageSize);
 }

+ 71 - 197
benyun-core/src/main/java/com/benyun/core/service/impl/ChannelAnalyseServiceImpl.java

@@ -9,6 +9,7 @@ import com.benyun.core.entity.vo.ChannelAnalyseAceeptVo;
 import com.benyun.core.entity.vo.ChannelMapAceeptVo;
 import com.benyun.core.entity.vo.TagAnalyse;
 import com.benyun.core.service.ChannelAnalyseService;
+import com.benyun.core.utils.WdRedisStoreage;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -39,8 +40,16 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
     @Qualifier("typeByMap")
     private HashMap<String, String> typeByMap;
 
+    @Autowired
+    private WdRedisStoreage wdRedisStoreage;
+
+    @Autowired
+    @Qualifier("cityTierListMap")
+    HashMap<String,List<String>> cityTierListMap;
+
     @Override
-    public HashMap cityTier(ChannelAnalyseAceeptVo channelAnalyseAceeptVo) {
+    public HashMap cityTier(ChannelMapAceeptVo channelMapAceeptVo) {
+        //1.统计结果
         HashMap<String, Long> result = new HashMap<>();
         result.put("一线", 0L);
         result.put("新一线", 0L);
@@ -50,24 +59,13 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
         result.put("五线", 0L);
         result.put("其他", 0L);
 
-        //1.获取所有符合条件的网点信息
-        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
-        queryWrapper.in("wd_type_code", channelAnalyseAceeptVo.getChannel());
-        if (channelAnalyseAceeptVo.getSearchText() != null && !channelAnalyseAceeptVo.getSearchText().equals("")) {
-            queryWrapper.and(wdInfoQueryWrapper -> {
-                wdInfoQueryWrapper.like("wd_name", channelAnalyseAceeptVo.getSearchText());
-            });
-        }
 
-        List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
+        //1.获取所有符合条件的网点信息
+        List<WdInfo> wdInfos = getQueryWd(channelMapAceeptVo);
         for (WdInfo wdInfo : wdInfos) {
-            String addrCode = wdInfo.getAddrCode();
+            String addrCode = wdInfo.getAddrCode().substring(0,4);
             if (cityTierMap.containsKey(addrCode)) {
                 result.put(cityTierMap.get(addrCode), result.get(cityTierMap.get(addrCode)) + 1);
-            } else if (cityTierMap.containsKey(addrCode.substring(0, 4))) {
-                result.put(cityTierMap.get(addrCode.substring(0, 4)), result.get(cityTierMap.get(addrCode.substring(0, 4))) + 1);
-            } else if (cityTierMap.containsKey(addrCode.substring(0, 2))) {
-                result.put(cityTierMap.get(addrCode.substring(0, 2)), result.get(cityTierMap.get(addrCode.substring(0, 2))) + 1);
             } else
                 result.put("其他", result.get("其他") + 1);
         }
@@ -78,190 +76,37 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
 
     @Override
     public PageInfo<Brand> brandList(ChannelAnalyseAceeptVo channelAnalyseAceeptVo) {
-        PageHelper.startPage(channelAnalyseAceeptVo.getPageNum(), channelAnalyseAceeptVo.getPageSize());
         String text = "";
         if (channelAnalyseAceeptVo.getSearchText() != null)
             text = channelAnalyseAceeptVo.getSearchText();
+        PageHelper.startPage(channelAnalyseAceeptVo.getPageNum(), channelAnalyseAceeptVo.getPageSize());
         List<Brand> brands = brandMapper.searchList(text);
         PageInfo<Brand> pageInfo = new PageInfo<>(brands);
         return pageInfo;
     }
 
-    //    @Override
-//    public HashMap<String,Object> tagAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
-//        //1.根据不同级别得到地区码
-//        List<String> addrCodeList = new ArrayList<>();
-//        if ("province".equals(channelMapAceeptVo.getRankType())) {
-//            //省码
-//            for (String s : channelMapAceeptVo.getAddrCode()) {
-//                String substring = s.substring(0, 2);
-//                addrCodeList.add(substring);
-//            }
-//        } else if ("city".equals(channelMapAceeptVo.getRankType())) {
-//            //省的所有市
-//            for (String s : channelMapAceeptVo.getAddrCode()) {
-//                String substring = s.substring(0, 4);
-//                addrCodeList.add(substring);
-//            }
-//        } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
-//            //区
-//            for (String s : channelMapAceeptVo.getAddrCode()) {
-//                String substring = s.substring(0, 6);
-//                addrCodeList.add(substring);
-//            }
-//        } else {
-//            return null;
-//        }
-//
-//
-//        //2.根据地区前缀找到所有的网点
-//        QueryWrapper<WdTopologicalInfo> queryWrapper = new QueryWrapper<>();
-//        queryWrapper.in("center_wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
-//            for (String s : addrCodeList) {
-//                originWdInfoQueryWrapper.likeRight("addr_code", s).or();
-//            }
-//        });
-//
-//        if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText().trim().equals("")) {
-//            queryWrapper.and(originWdInfoQueryWrapper -> {
-//                originWdInfoQueryWrapper.like("center_wd_name", channelMapAceeptVo.getSearchText());
-//            });
-//        }
-//
-//        queryWrapper.and(wdTopologicalInfoQueryWrapper -> {
-//            wdTopologicalInfoQueryWrapper.eq("radius",1000); //1km内算附近
-//        });
-//        List<WdTopologicalInfo> originWdInfos = wdTopologicalInfoDao.selectList(queryWrapper);
-//
-//        //统计
-//        Integer total = 0 ;
-//        HashMap<String,Integer> hashMap = new HashMap<>();
-//        for (WdTopologicalInfo originWdInfo : originWdInfos) {
-//            String tag = originWdInfo.getTag();
-//            for (String s : tag.split(";")) {
-//                String[] split = s.split(":");
-//                if (split != null && split.length == 2) {
-//                    if(typeByMap.get(split[0]) == null)
-//                        continue;
-//                    String[] split1 = typeByMap.get(split[0]).split(":");
-//                    String t = "";
-//                    if (split1.length == 3)
-//                        t = split1[2];
-//                    else if (split1.length == 2)
-//                        t = split1[1];
-//                    else if (split1.length == 1)
-//                        t = split1[0];
-//
-//                    if(!t.equals("")) {
-//                        Integer integer = hashMap.get(t);
-//                        if(integer == null)
-//                            hashMap.put(t,1);
-//                        else {
-//                            hashMap.put(t,hashMap.get(t)+1);
-//                        }
-//                        total++;
-//                    }
-//                }
-//            }
-//        }
-//        HashMap<String, Object> result = new HashMap<>();
-//        List<TagAnalyse> list = new ArrayList<>();
-//        for (String s : hashMap.keySet()) {
-//            TagAnalyse tagAnalyse = new TagAnalyse();
-//            tagAnalyse.setName(s);
-//            tagAnalyse.setCount(hashMap.get(s));
-//            tagAnalyse.setRadio((double)tagAnalyse.getCount()/total);
-//            list.add(tagAnalyse);
-//        }
-//
-//        Collections.sort(list, new Comparator<TagAnalyse>() {
-//            @Override
-//            public int compare(TagAnalyse o1, TagAnalyse o2) {
-//                return o2.getCount() - o1.getCount();
-//            }
-//        });
-//
-//        result.put("total",total);
-//        result.put("data",list);
-//        return result;
-//    }
 
+    //TODO 待测试(redis版本)
     @Override
     public HashMap<String, Object> tagAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
-        //1.根据不同级别得到地区码
-        List<String> addrCodeList = new ArrayList<>();
-        if ("province".equals(channelMapAceeptVo.getRankType())) {
-            //省码
-            for (String s : channelMapAceeptVo.getAddrCode()) {
-                String substring = s.substring(0, 2);
-                addrCodeList.add(substring);
-            }
-        } else if ("city".equals(channelMapAceeptVo.getRankType())) {
-            //省的所有市
-            for (String s : channelMapAceeptVo.getAddrCode()) {
-                String substring = s.substring(0, 4);
-                addrCodeList.add(substring);
-            }
-        } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
-            //区
-            for (String s : channelMapAceeptVo.getAddrCode()) {
-                String substring = s.substring(0, 6);
-                addrCodeList.add(substring);
-            }
-        } else {
-            return null;
-        }
-
+        //1.根据条件的到位网点信息
+        List<WdInfo> queryWd = getQueryWd(channelMapAceeptVo);
 
-        //2.根据地区前缀找到所有的网点
-        QueryWrapper<WdTopologicalInfo> queryWrapper = new QueryWrapper<>();
-        queryWrapper.in("center_wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
-            for (String s : addrCodeList) {
-                originWdInfoQueryWrapper.likeRight("addr_code", s).or();
-            }
-        });
-
-        if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText().trim().equals("")) {
-            queryWrapper.and(originWdInfoQueryWrapper -> {
-                originWdInfoQueryWrapper.like("center_wd_name", channelMapAceeptVo.getSearchText());
-            });
-        }
-
-        queryWrapper.and(wdTopologicalInfoQueryWrapper -> {
-            wdTopologicalInfoQueryWrapper.eq("radius",1000); //1km内算附近
-        });
-        List<WdTopologicalInfo> originWdInfos = wdTopologicalInfoDao.selectList(queryWrapper);
-
-        //统计
-        Integer total = originWdInfos.size() ;
+        //2.获取网点周边标签,并进行统计
+        Integer total = queryWd.size() ;
         HashMap<String,Integer> hashMap = new HashMap<>();
-        for (WdTopologicalInfo originWdInfo : originWdInfos) {
-            String tag = originWdInfo.getTag();
-            for (String s : tag.split(";")) {
-                String[] split = s.split(":");
-                if (split != null && split.length == 2) {
-                    if(typeByMap.get(split[0]) == null)
-                        continue;
-                    String[] split1 = typeByMap.get(split[0]).split(":");
-                    String t = "";
-                    if (split1.length == 3)
-                        t = split1[2];
-                    else if (split1.length == 2)
-                        t = split1[1];
-                    else if (split1.length == 1)
-                        t = split1[0];
-
-                    if(!t.equals("")) {
-                        Integer integer = hashMap.get(t);
-                        if(integer == null)
-                            hashMap.put(t,1);
-                        else {
-                            hashMap.put(t,hashMap.get(t)+1);
-                        }
-                    }
-                }
+        for (WdInfo wdInfo : queryWd) {
+            List<String> wdTag = wdRedisStoreage.getWdTag(wdInfo);
+            for (String s : wdTag) {
+                Integer integer = hashMap.get(s);
+                if (integer == null)
+                    hashMap.put(s,1);
+                else
+                    hashMap.put(s,integer+1);
             }
         }
+
+        //3.封装统计值
         HashMap<String, Object> result = new HashMap<>();
         List<TagAnalyse> list = new ArrayList<>();
         for (String s : hashMap.keySet()) {
@@ -274,6 +119,7 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
             list.add(tagAnalyse);
         }
 
+        //4.对结果集进行排序
         Collections.sort(list, new Comparator<TagAnalyse>() {
             @Override
             public int compare(TagAnalyse o1, TagAnalyse o2) {
@@ -282,6 +128,7 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
         });
 
 
+        //5.分页返回结果集
         int i = 1;
         int start = 0,end = 6;
         while(start<list.size()){
@@ -296,9 +143,12 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
         return result;
     }
 
-    @Override
-    public void businessAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
-        //1.根据不同级别得到地区码
+
+    /**
+     * 根据条件获取网点
+     * */
+    public List<WdInfo> getQueryWd(ChannelMapAceeptVo channelMapAceeptVo){
+        //1.根据不同级别得到需要查询的 地区码
         List<String> addrCodeList = new ArrayList<>();
         if ("province".equals(channelMapAceeptVo.getRankType())) {
             //省码
@@ -309,33 +159,57 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
         } else if ("city".equals(channelMapAceeptVo.getRankType())) {
             //省的所有市
             for (String s : channelMapAceeptVo.getAddrCode()) {
-                String substring = s.substring(0, 4);
+                String substring = s.substring(0, 2);
                 addrCodeList.add(substring);
             }
         } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
-            //区
+            //市的所有区
+            for (String s : channelMapAceeptVo.getAddrCode()) {
+                String substring = s.substring(0, 4);
+                addrCodeList.add(substring);
+            }
+        } else if ("district".equals(channelMapAceeptVo.getRankType())){
+            //区的所有街道
             for (String s : channelMapAceeptVo.getAddrCode()) {
                 String substring = s.substring(0, 6);
                 addrCodeList.add(substring);
             }
-        } else {
-            //return null;
-        }
+        }else
+            return new ArrayList<>();
 
 
-        //2.根据地区前缀找到所有的网点
-        QueryWrapper<WdTopologicalInfo> queryWrapper = new QueryWrapper<>();
-        queryWrapper.select("wd_id");
+        //2.组装条件构造器找到网点信息网点
+        //2.1 渠道、地区分类
+        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
         queryWrapper.in("wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
             for (String s : addrCodeList) {
                 originWdInfoQueryWrapper.likeRight("addr_code", s).or();
             }
         });
 
-        if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText().trim().equals("")) {
+        //搜索字段
+        if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText() .trim().equals("")) {
             queryWrapper.and(originWdInfoQueryWrapper -> {
-                originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText());
+                originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
+            });
+        }
+
+        //城市等级分类
+        if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
+            List<String> tierCode = new ArrayList<>();
+            for (String s : channelMapAceeptVo.getCityTier()) {
+                List<String> list = cityTierListMap.get(s);
+                if (list != null){
+                    tierCode.addAll(list);
+                }
+            }
+            queryWrapper.and(wdInfoQueryWrapper -> {
+                wdInfoQueryWrapper.in("addr_code",tierCode);
             });
         }
+
+
+        List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
+        return wdInfos;
     }
 }

+ 243 - 202
benyun-core/src/main/java/com/benyun/core/service/impl/ChannelMapServiceImpl.java

@@ -1,6 +1,7 @@
 package com.benyun.core.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.benyun.core.constant.RedisContant;
 import com.benyun.core.dao.AddrCategoryDao;
 import com.benyun.core.dao.AttentionPoolDao;
 import com.benyun.core.dao.WdInfoDao;
@@ -12,19 +13,23 @@ import com.benyun.core.entity.bo.WdCount;
 import com.benyun.core.entity.bo.WdCountBody;
 import com.benyun.core.entity.WdInfo;
 import com.benyun.core.entity.bo.WdTopologicalInfoBo;
+import com.benyun.core.entity.vo.ChannelMapAceeptVo;
+import com.benyun.core.entity.vo.WdInfoVo;
 import com.benyun.core.service.ChannelMapService;
+import com.benyun.core.utils.WdRedisStoreage;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.ruoyi.common.core.domain.R;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.data.geo.*;
+import org.springframework.data.redis.connection.RedisGeoCommands;
+import org.springframework.data.redis.core.BoundGeoOperations;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
@@ -53,23 +58,35 @@ public class ChannelMapServiceImpl implements ChannelMapService {
     @Autowired
     WdInfoDao wdInfoDao;
 
+    @Autowired
+    @Qualifier("cityTierListMap")
+    HashMap<String,List<String>> cityTierListMap;
+
+    @Autowired
+    RedisTemplate redisTemplate;
+
+    @Autowired
+    WdRedisStoreage wdRedisStoreage;
+
     @Override
-    public WdCount area(List<String> channel, String rankType, String searchText, String[] addrCode) {
+    public WdCount area(ChannelMapAceeptVo channelMapAceeptVo) {
+        //1.根据不同级别得到 需要封装的 地区码
         List<String> addrCodeList = new ArrayList<>();
-
-        //1.根据不同级别得到地区码
-        if ("province".equals(rankType)) {
+        if ("province".equals(channelMapAceeptVo.getRankType())) {
             //省码
-            Collections.addAll(addrCodeList, addrCode);
-        } else if ("city".equals(rankType)) {
+            for (String s : channelMapAceeptVo.getAddrCode()) {
+                String substring = s.substring(0, 2);
+                addrCodeList.add(substring);
+            }
+        } else if ("city".equals(channelMapAceeptVo.getRankType())) {
             //省的所有市
-            for (String s : addrCode) {
+            for (String s : channelMapAceeptVo.getAddrCode()) {
                 String substring = s.substring(0, 2);
                 addrCodeList.add(substring);
             }
-        } else if ("zone".equals(rankType)) {
+        } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
             //市的所有区
-            for (String s : addrCode) {
+            for (String s : channelMapAceeptVo.getAddrCode()) {
                 String substring = s.substring(0, 4);
                 addrCodeList.add(substring);
             }
@@ -77,15 +94,16 @@ public class ChannelMapServiceImpl implements ChannelMapService {
             return null;
         }
 
-        //2.找到相关地区信息
+
+        //2.找到所有需要封装的 地区信息
         QueryWrapper<AddrCategory> queryWrapper = new QueryWrapper<>();
-        if ("province".equals(rankType)) {
+        if ("province".equals(channelMapAceeptVo.getRankType())) {
             queryWrapper.eq("city", "");
-        } else if ("city".equals(rankType)) {
+        } else if ("city".equals(channelMapAceeptVo.getRankType())) {
             queryWrapper.eq("district", "").and(addrCategoryQueryWrapper -> {
                 addrCategoryQueryWrapper.ne("city", "");
             });
-        } else if ("zone".equals(rankType)) {
+        } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
             queryWrapper.ne("district", "");
         }
         queryWrapper.and(addrCategoryQueryWrapper -> {
@@ -95,15 +113,12 @@ public class ChannelMapServiceImpl implements ChannelMapService {
                 }
             });
         });
-
-        //TODO 前置分类删选还没做
-
-
         List<AddrCategory> addrCategories = addrCategoryDao.selectList(queryWrapper);
 
 
         //3.组装地区信息
         List<WdCountBody> result = new ArrayList<>();
+        HashMap<String,Integer> statistics = new HashMap<>(); //统计信息
         for (AddrCategory addrCategory : addrCategories) {
             WdCountBody wdCountBody = new WdCountBody();
 
@@ -111,43 +126,82 @@ public class ChannelMapServiceImpl implements ChannelMapService {
             wdCountBody.setLat(addrCategory.getLatGd());
             wdCountBody.setLng(addrCategory.getLngGd());
             wdCountBody.setAddrCode(addrCategory.getAddrCode());
-            if ("province".equals(rankType)) {
+            if ("province".equals(channelMapAceeptVo.getRankType())) {
                 wdCountBody.setName(addrCategory.getProvince());
-            } else if ("city".equals(rankType)) {
+                statistics.put(addrCategory.getAddrCode().substring(0,2),0);
+            } else if ("city".equals(channelMapAceeptVo.getRankType())) {
                 wdCountBody.setName(addrCategory.getCity());
-            } else if ("zone".equals(rankType)) {
+                statistics.put(addrCategory.getAddrCode().substring(0,4),0);
+            } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
                 wdCountBody.setName(addrCategory.getDistrict());
+                statistics.put(addrCategory.getAddrCode().substring(0,6),0);
             }
             result.add(wdCountBody);
         }
 
-        //4.统计地区网点信息
-        Long total = 0L;
-        for (WdCountBody wdCountBody : result) {
-            QueryWrapper<WdInfo> queryWrapper1 = new QueryWrapper<>();
-            String code = wdCountBody.getAddrCode();
 
-            //根据地区前缀,使用模糊查询
-            if ("province".equals(rankType))
-                code = code.substring(0, 2);
-            else if ("city".equals(rankType))
-                code = code.substring(0, 4);
+        //4.组装条件构造器找到网点信息网点
+        //2.1 渠道、地区分类
+        QueryWrapper<WdInfo> queryWrapper2 = new QueryWrapper<>();
+        queryWrapper2.in("wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
+            for (String s : addrCodeList) {
+                originWdInfoQueryWrapper.likeRight("addr_code", s).or();
+            }
+        });
 
-            queryWrapper1.likeRight("addr_code", code).and(originWdInfoQueryWrapper -> {
-                originWdInfoQueryWrapper.in("wd_type_code", channel);
+        //搜索字段
+        if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText() .trim().equals("")) {
+            queryWrapper2.and(originWdInfoQueryWrapper -> {
+                originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
             });
-            if (searchText != null && !searchText.trim().equals("")) {
-                queryWrapper1.and(originWdInfoQueryWrapper -> {
-                    originWdInfoQueryWrapper.like("wd_name", searchText);
-                });
+        }
+
+        //城市等级分类
+        if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
+            List<String> tierCode = new ArrayList<>();
+            for (String s : channelMapAceeptVo.getCityTier()) {
+                List<String> list = cityTierListMap.get(s);
+                if (list != null){
+                    tierCode.addAll(list);
+                }
             }
-            Long aLong = originWdInfoDao.selectCount(queryWrapper1);
-            wdCountBody.setCount(aLong);
-            total += aLong;
+            queryWrapper2.and(wdInfoQueryWrapper -> {
+                wdInfoQueryWrapper.in("addr_code",tierCode);
+            });
         }
 
+        //5.统计
+        int total = 0;
+        List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper2);
+        for (WdInfo wdInfo : wdInfos) {
+            if("province".equals(channelMapAceeptVo.getRankType())){
+                statistics.put(wdInfo.getAddrCode().substring(0,2),statistics.get(wdInfo.getAddrCode().substring(0,2))+1);
+            } else if ("city".equals(channelMapAceeptVo.getRankType())) {
+                statistics.put(wdInfo.getAddrCode().substring(0,4),statistics.get(wdInfo.getAddrCode().substring(0,4))+1);
+            } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
+                statistics.put(wdInfo.getAddrCode().substring(0,6),statistics.get(wdInfo.getAddrCode().substring(0,6))+1);
+            }
+            total++;
+        }
+
+
         //5.计算radio
         for (WdCountBody wdCountBody : result) {
+            String code =  null;
+            if("province".equals(channelMapAceeptVo.getRankType())){
+                code = wdCountBody.getAddrCode().substring(0,2);
+            }else if("city".equals(channelMapAceeptVo.getRankType())){
+                code = wdCountBody.getAddrCode().substring(0,4);
+            }else if("zone".equals(channelMapAceeptVo.getRankType())){
+                code = wdCountBody.getAddrCode().substring(0,4);
+            }
+
+            if(statistics.get(code) != null){
+                wdCountBody.setCount(statistics.get(code));
+            }else {
+                wdCountBody.setCount(0);
+            }
+
             if (total != 0){
                 BigDecimal bigDecimal = new BigDecimal((float) wdCountBody.getCount() / total);
                 float v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
@@ -162,205 +216,192 @@ public class ChannelMapServiceImpl implements ChannelMapService {
         return wdCount;
     }
 
-    //TODO 需要优化
-//    @Override
-//    public HashMap list(String[] channel, String rankType, String searchText, String orderby, String[] addrCode, int pageNum, int pageSize) {
-//        //1.根据不同级别得到地区码
-//        List<String> addrCodeList = new ArrayList<>();
-//        if ("province".equals(rankType)) {
-//            //省码
-//            for (String s : addrCode) {
-//                String substring = s.substring(0, 2);
-//                addrCodeList.add(substring);
-//            }
-//        } else if ("city".equals(rankType)) {
-//            //省的所有市
-//            for (String s : addrCode) {
-//                String substring = s.substring(0, 4);
-//                addrCodeList.add(substring);
-//            }
-//        } else if ("zone".equals(rankType)) {
-//            //区
-//            for (String s : addrCode) {
-//                String substring = s.substring(0, 6);
-//                addrCodeList.add(substring);
-//            }
-//        } else {
-//            return null;
-//        }
-//
-//
-//        //2.根据地区前缀找到所有的网点
-//        QueryWrapper<WdTopologicalInfo> queryWrapper = new QueryWrapper<>();
-//        queryWrapper.in("center_wd_type_code", channel).and(originWdInfoQueryWrapper -> {
-//            for (String s : addrCodeList) {
-//                originWdInfoQueryWrapper.likeRight("addr_code", s).or();
-//            }
-//        });
-//
-//        if (searchText != null && !searchText.trim().equals("")) {
-//            queryWrapper.and(originWdInfoQueryWrapper -> {
-//                originWdInfoQueryWrapper.like("center_wd_name", searchText);
-//            });
-//        }
-//
-//        queryWrapper.and(wdTopologicalInfoQueryWrapper -> {
-//            wdTopologicalInfoQueryWrapper.eq("radius",1000); //1km内算附近
-//        });
-//
-//        if (orderby != null && !orderby.trim().equals("")) {
-//            queryWrapper.orderByDesc(orderby);
-//        }
-//
-//        //获取数据
-//        PageHelper.startPage(pageNum, pageSize);
-//        List<WdTopologicalInfo> originWdInfos = wdTopologicalInfoDao.selectList(queryWrapper);
-//        PageInfo<WdTopologicalInfo> PageInfo = new PageInfo<>(originWdInfos);
-//
-//
-//        //组装
-//        List<WdTopologicalInfoBo> collect = PageInfo.getList().stream().map(wdTopologicalInfo -> {
-//            wdTopologicalInfo.setAddrCodeInfo(addrCodeMap.get(wdTopologicalInfo.getAddrCode()));
-//
-//            List<String> list = new ArrayList<>();
-//            String tag = wdTopologicalInfo.getTag();
-//            for (String s : tag.split(";")) {
-//                String[] split = s.split(":");
-//                if (split != null && split.length == 2) {
-//                    if(typeByMap.get(split[0]) == null)
-//                        continue;
-//                    String[] split1 = typeByMap.get(split[0]).split(":");
-//                    String t = "";
-//                    if (split1.length == 3)
-//                        t = split1[2];
-//                    else if (split1.length == 2)
-//                        t = split1[1];
-//                    else if (split1.length == 1)
-//                        t = split1[0];
-//                    list.add(t);
-//                }
-//            }
-//
-//            WdTopologicalInfoBo wdTopologicalInfoBo = new WdTopologicalInfoBo(wdTopologicalInfo);
-//            wdTopologicalInfoBo.setTag(list);
-//            return wdTopologicalInfoBo;
-//        }).collect(Collectors.toList());
-//
-//
-//        PageInfo.setList(null);
-//        HashMap result = new HashMap();
-//        result.put("data",collect);
-//        result.put("page",PageInfo);
-//
-//        return result;
-//    }
 
+    //TODO 待测试(redis版本)
     @Override
-    public HashMap list(String[] channel, String rankType, String searchText, String orderby, String[] addrCode, int pageNum, int pageSize) {
-        //1.根据不同级别得到地区码
+    public HashMap list(ChannelMapAceeptVo channelMapAceeptVo) {
+        //1.根据条件获取网点
+        PageInfo<WdInfo> PageInfo = getQueryPageWd(channelMapAceeptVo);
+
+        //2.获取标签并组装
+        List<WdTopologicalInfoBo> result = new ArrayList<>();   //返回的封装网点数据集
+        for (WdInfo wdInfo : PageInfo.getList()) {
+            WdTopologicalInfoBo wdTopologicalInfoBo = new WdTopologicalInfoBo(wdInfo);
+            wdTopologicalInfoBo.setAddrCodeInfo(addrCodeMap.get(wdInfo.getAddrCode()));
+            List<String> tags = wdRedisStoreage.getWdTag(wdInfo);
+            wdTopologicalInfoBo.setTag(tags);
+            result.add(wdTopologicalInfoBo);
+        }
+
+        //返回结果集
+        PageInfo.setList(null);
+        HashMap data = new HashMap();
+        data.put("data",result);
+        data.put("page",PageInfo);
+
+        return data;
+    }
+
+    @Override
+    public PageInfo<WdInfo> point(String[] channel, String searchText, String[] addrCode, int pageNum, int pageSize) {
+        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.in("wd_type_code", channel);
+        for (String s : addrCode) {
+            queryWrapper.and(originWdInfoQueryWrapper -> {
+                originWdInfoQueryWrapper.eq("addr_code",s);
+            });
+        }
+        if (searchText != null && !searchText.trim().equals("")) {
+            queryWrapper.and(originWdInfoQueryWrapper -> {
+                originWdInfoQueryWrapper.like("wd_name", searchText);
+            });
+        }
+        PageHelper.startPage(pageNum, pageSize);
+        List<WdInfo> originWdInfos = originWdInfoDao.selectList(queryWrapper);
+        PageInfo<WdInfo> PageInfo = new PageInfo<>(originWdInfos);
+        return PageInfo;
+    }
+
+    /**
+     * 根据条件获取网点(分页)
+     * */
+    public PageInfo<WdInfo> getQueryPageWd(ChannelMapAceeptVo channelMapAceeptVo){
+        //1.根据不同级别得到需要查询的 地区码
         List<String> addrCodeList = new ArrayList<>();
-        if ("province".equals(rankType)) {
+        if ("province".equals(channelMapAceeptVo.getRankType())) {
             //省码
-            for (String s : addrCode) {
+            for (String s : channelMapAceeptVo.getAddrCode()) {
                 String substring = s.substring(0, 2);
                 addrCodeList.add(substring);
             }
-        } else if ("city".equals(rankType)) {
+        } else if ("city".equals(channelMapAceeptVo.getRankType())) {
             //省的所有市
-            for (String s : addrCode) {
+            for (String s : channelMapAceeptVo.getAddrCode()) {
+                String substring = s.substring(0, 2);
+                addrCodeList.add(substring);
+            }
+        } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
+            //市的所有区
+            for (String s : channelMapAceeptVo.getAddrCode()) {
                 String substring = s.substring(0, 4);
                 addrCodeList.add(substring);
             }
-        } else if ("zone".equals(rankType)) {
-            //区
-            for (String s : addrCode) {
+        } else if ("district".equals(channelMapAceeptVo.getRankType())){
+            //区的所有街道
+            for (String s : channelMapAceeptVo.getAddrCode()) {
                 String substring = s.substring(0, 6);
                 addrCodeList.add(substring);
             }
-        } else {
+        }else
             return null;
-        }
 
 
-        //2.根据地区前缀找到所有的网点
+        //2.组装条件构造器找到网点信息网点
+        //2.1 渠道、地区分类
         QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
-        queryWrapper.in("wd_type_code", channel).and(originWdInfoQueryWrapper -> {
+        queryWrapper.in("wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
             for (String s : addrCodeList) {
                 originWdInfoQueryWrapper.likeRight("addr_code", s).or();
             }
         });
 
-        if (searchText != null && !searchText.trim().equals("")) {
+        //搜索字段
+        if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText() .trim().equals("")) {
             queryWrapper.and(originWdInfoQueryWrapper -> {
-                originWdInfoQueryWrapper.like("wd_name", searchText);
+                originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
             });
         }
 
-        if (orderby != null && !orderby.trim().equals("")) {
-            queryWrapper.orderByDesc(orderby);
+        //城市等级分类
+        if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
+            List<String> tierCode = new ArrayList<>();
+            for (String s : channelMapAceeptVo.getCityTier()) {
+                List<String> list = cityTierListMap.get(s);
+                if (list != null){
+                    tierCode.addAll(list);
+                }
+            }
+            queryWrapper.and(wdInfoQueryWrapper -> {
+                wdInfoQueryWrapper.in("addr_code",tierCode);
+            });
         }
 
-        //获取数据
-        PageHelper.startPage(pageNum, pageSize);
+        //排序字段查询
+        if (channelMapAceeptVo.getOrderby() != null && !channelMapAceeptVo.getOrderby().trim().equals("")) {
+            PageHelper.orderBy(channelMapAceeptVo.getOrderby());
+        }
+        PageHelper.startPage(channelMapAceeptVo.getPageNum(), channelMapAceeptVo.getPageSize());
         List<WdInfo> originWdInfos = wdInfoDao.selectList(queryWrapper);
         PageInfo<WdInfo> PageInfo = new PageInfo<>(originWdInfos);
+        return PageInfo;
+    }
 
-
-        //组装
-        List<WdTopologicalInfoBo> collect = PageInfo.getList().stream().map(wdInfo -> {
-
-            List<String> list = new ArrayList<>();
-            String tag = wdInfo.getTypeNameBy();
-            if(tag != null){
-                String[] split = tag.split(":");
-                for (String s : split) {
-                    list.add(s);
-                }
+    /**
+     * 根据条件获取网点
+     * */
+    public List<WdInfo> getQueryWd(ChannelMapAceeptVo channelMapAceeptVo){
+        //1.根据不同级别得到需要查询的 地区码
+        List<String> addrCodeList = new ArrayList<>();
+        if ("province".equals(channelMapAceeptVo.getRankType())) {
+            //省码
+            for (String s : channelMapAceeptVo.getAddrCode()) {
+                String substring = s.substring(0, 2);
+                addrCodeList.add(substring);
             }
+        } else if ("city".equals(channelMapAceeptVo.getRankType())) {
+            //省的所有市
+            for (String s : channelMapAceeptVo.getAddrCode()) {
+                String substring = s.substring(0, 2);
+                addrCodeList.add(substring);
+            }
+        } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
+            //市的所有区
+            for (String s : channelMapAceeptVo.getAddrCode()) {
+                String substring = s.substring(0, 4);
+                addrCodeList.add(substring);
+            }
+        } else if ("district".equals(channelMapAceeptVo.getRankType())){
+            //区的所有街道
+            for (String s : channelMapAceeptVo.getAddrCode()) {
+                String substring = s.substring(0, 6);
+                addrCodeList.add(substring);
+            }
+        }else
+            return null;
 
 
-            WdTopologicalInfoBo wdTopologicalInfoBo = new WdTopologicalInfoBo();
-            wdTopologicalInfoBo.setCenterWdId(wdInfo.getWdId());
-            wdTopologicalInfoBo.setCenterWdName(wdInfo.getWdName());
-            wdTopologicalInfoBo.setCenterWdTypeCode(wdInfo.getWdTypeCode());
-            wdTopologicalInfoBo.setAddrCode(wdInfo.getAddrCode());
-            wdTopologicalInfoBo.setAddrCodeInfo(addrCodeMap.get(wdInfo.getAddrCode()));
-            wdTopologicalInfoBo.setAddrInfo(wdInfo.getAddrInfo());
-            wdTopologicalInfoBo.setGeoHash(wdInfo.getGeoHash());
-            wdTopologicalInfoBo.setLat(wdInfo.getLat());
-            wdTopologicalInfoBo.setLng(wdInfo.getLng());
-
-            wdTopologicalInfoBo.setTag(list);
-            return wdTopologicalInfoBo;
-        }).collect(Collectors.toList());
-
-
-        PageInfo.setList(null);
-        HashMap result = new HashMap();
-        result.put("data",collect);
-        result.put("page",PageInfo);
-
-        return result;
-    }
-
-
-    @Override
-    public PageInfo<WdInfo> point(String[] channel, String searchText, String[] addrCode, int pageNum, int pageSize) {
+        //2.组装条件构造器找到网点信息网点
+        //2.1 渠道、地区分类
         QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
-        queryWrapper.in("wd_type_code", channel);
-        for (String s : addrCode) {
+        queryWrapper.in("wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
+            for (String s : addrCodeList) {
+                originWdInfoQueryWrapper.likeRight("addr_code", s).or();
+            }
+        });
+
+        //搜索字段
+        if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText() .trim().equals("")) {
             queryWrapper.and(originWdInfoQueryWrapper -> {
-                originWdInfoQueryWrapper.eq("addr_code",s);
+                originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
             });
         }
-        if (searchText != null && !searchText.trim().equals("")) {
-            queryWrapper.and(originWdInfoQueryWrapper -> {
-                originWdInfoQueryWrapper.like("wd_name", searchText);
+
+        //城市等级分类
+        if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
+            List<String> tierCode = new ArrayList<>();
+            for (String s : channelMapAceeptVo.getCityTier()) {
+                List<String> list = cityTierListMap.get(s);
+                if (list != null){
+                    tierCode.addAll(list);
+                }
+            }
+            queryWrapper.and(wdInfoQueryWrapper -> {
+                wdInfoQueryWrapper.in("addr_code",tierCode);
             });
         }
-        PageHelper.startPage(pageNum, pageSize);
-        List<WdInfo> originWdInfos = originWdInfoDao.selectList(queryWrapper);
-        PageInfo<WdInfo> PageInfo = new PageInfo<>(originWdInfos);
-        return PageInfo;
+
+
+        List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
+        return wdInfos;
     }
 }

+ 87 - 50
benyun-core/src/main/java/com/benyun/core/service/impl/TopologicalBuildWdSereviceImpl.java

@@ -1,6 +1,7 @@
 package com.benyun.core.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.benyun.core.dao.BuildWdDao;
 import com.benyun.core.dao.TopologicalBuildWdDao;
 import com.benyun.core.dao.TopologicalBuildWdStatisticsCategoryDao;
 import com.benyun.core.dao.WdInfoDao;
@@ -17,6 +18,12 @@ import org.gavaghan.geodesy.Ellipsoid;
 import org.gavaghan.geodesy.GlobalCoordinates;
 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.transaction.annotation.Transactional;
 
@@ -42,76 +49,106 @@ public class TopologicalBuildWdSereviceImpl implements TopologicalBuildWdSerevic
     @Qualifier("addrCodeMap")
     HashMap<String,String> addrCodeMap;
 
+    @Autowired
+    RedisTemplate redisTemplate;
+
+    @Autowired
+    BuildWdDao buildWdDao;
+
     @Override
     public List<BuildWdCategoryCount> buildingLevel(TopologicalWdAceeptVo topologicalWdAceeptVo) {
-        QueryWrapper<TopologicalBuildWdStatisticsCategory> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("center_wd_id",topologicalWdAceeptVo.getCenterWdId());
-        queryWrapper.and(wrapper -> {
-            wrapper.eq("radius",topologicalWdAceeptVo.getRadius());
+        //1.根据中心网点Id找到网点详细信息
+        QueryWrapper<WdInfo> queryWrapper1 = new QueryWrapper<>();
+        queryWrapper1.eq("wd_id",topologicalWdAceeptVo.getCenterWdId());
+        WdInfo wdInfo1 = wdInfoDao.selectOne(queryWrapper1);
+
+        //2.根据中心网点找到周边网点Id
+        // 以经纬度为中心,获取半径不超过最大距离的所有元素
+        Point point = new Point(wdInfo1.getLng().doubleValue(),wdInfo1.getLat().doubleValue());
+        //半径范围
+        Distance distance = new Distance(topologicalWdAceeptVo.getRadius(), RedisGeoCommands.DistanceUnit.METERS);
+        //圆
+        Circle circle = new Circle(point, distance);
+        GeoResults<RedisGeoCommands.GeoLocation<Object>> radius = redisTemplate.boundGeoOps(wdInfo1.getAddrCode().substring(0, 4)).radius(circle);
+        //周边网点Id
+        List<String> aroundWdId = new ArrayList<>();
+        radius.getContent().stream().forEach(item -> {
+            //记录网点坐标及距离
+            aroundWdId.add((String) item.getContent().getName());
         });
 
-        List<BuildWdCategoryCount> list = new ArrayList<>();
-        TopologicalBuildWdStatisticsCategory topologicalBuildWdStatisticsCategory = topologicalBuildWdStatisticsCategoryDao.selectOne(queryWrapper);
-        String propertyTypeStatistics = topologicalBuildWdStatisticsCategory.getPropertyTypeStatistics();
-        if (propertyTypeStatistics == null)
-            return list;
 
-        int total = 0;
-        for (String s : propertyTypeStatistics.split(";")) {
+        //4.分页查找网点信息
+        QueryWrapper<BuildWd> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("property_type","count(*) as people_count")
+            .in("wd_id",aroundWdId)
+            .groupBy("property_type");
+
+        List<BuildWdCategoryCount> list = new ArrayList<>();
+        List<BuildWd> buildWds = buildWdDao.selectList(queryWrapper);
+        for (BuildWd buildWd : buildWds) {
             BuildWdCategoryCount buildWdCategoryCount = new BuildWdCategoryCount();
-            String[] split = s.split(":");
-            if (split.length !=2)
-                continue;
-            buildWdCategoryCount.setName(split[0]);
-            buildWdCategoryCount.setCount(Integer.parseInt(split[1]));
-            total+=buildWdCategoryCount.getCount();
+            buildWdCategoryCount.setName(buildWd.getPropertyType());
+            buildWdCategoryCount.setCount(buildWd.getPeopleCount());
             list.add(buildWdCategoryCount);
         }
-        for (BuildWdCategoryCount buildWdCategoryCount : list) {
-            BigDecimal bigDecimal = new BigDecimal((double) buildWdCategoryCount.getCount() / total);
-            double v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
-            buildWdCategoryCount.setRadio(v);
-        }
+
         return list;
     }
 
     @Override
     public List<TopologicalBuildingWd> list(TopologicalWdAceeptVo topologicalWdAceeptVo) {
 
-        //return pageInfo;
-        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
-
-        //条件构造
-        queryWrapper.eq("wd_type_code","3");
-        queryWrapper.and(wdInfoQueryWrapper -> {
-            wdInfoQueryWrapper.likeRight("geo_hash",topologicalWdAceeptVo.getGeoHash().substring(0,5));
+        //1.根据中心网点Id找到网点详细信息
+        QueryWrapper<WdInfo> queryWrapper1 = new QueryWrapper<>();
+        queryWrapper1.eq("wd_id",topologicalWdAceeptVo.getCenterWdId());
+        WdInfo wdInfo1 = wdInfoDao.selectOne(queryWrapper1);
+        if(wdInfo1 == null)
+            return new ArrayList<>();
+
+        //2.根据中心网点找到周边网点Id
+        // 以经纬度为中心,获取半径不超过最大距离的所有元素
+        Point point = new Point(wdInfo1.getLng().doubleValue(),wdInfo1.getLat().doubleValue());
+        //半径范围
+        Distance distance = new Distance(topologicalWdAceeptVo.getRadius(), RedisGeoCommands.DistanceUnit.METERS);
+        //圆
+        Circle circle = new Circle(point, distance);
+        RedisGeoCommands.GeoRadiusCommandArgs geoRadiusCommandArgs = RedisGeoCommands.GeoRadiusCommandArgs.newGeoRadiusArgs();
+        geoRadiusCommandArgs.includeDistance();
+        GeoResults<RedisGeoCommands.GeoLocation<Object>> radius = redisTemplate.boundGeoOps(wdInfo1.getAddrCode().substring(0, 4)).radius(circle,geoRadiusCommandArgs);
+        //周边网点Id
+        List<String> aroundWdId = new ArrayList<>();
+        HashMap<String,Double> hashMap = new HashMap<>();
+        radius.getContent().stream().forEach(item -> {
+            //记录网点坐标及距离
+            aroundWdId.add((String) item.getContent().getName());
+            hashMap.put((String) item.getContent().getName(), item.getDistance().getValue());
         });
 
-        //查询结果
+
+        //4.分页查找网点信息
+        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("wd_type_code","3")
+            .and(wdInfoQueryWrapper -> {
+                wdInfoQueryWrapper.in("wd_id", aroundWdId);
+            });
+
+        //5.查询周边网点结果
+        PageHelper.startPage(1, topologicalWdAceeptVo.getSize());
         List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
+        PageInfo<WdInfo> pageInfo = new PageInfo<>(wdInfos);
 
+
+        //6.组装结果集
         List<TopologicalBuildingWd> list = new ArrayList<>();  //返回结果集
-        GlobalCoordinates source = new GlobalCoordinates(topologicalWdAceeptVo.getLat(), topologicalWdAceeptVo.getLng());
-        for (WdInfo wdInfo : wdInfos) {
-            if(list.size() >= topologicalWdAceeptVo.getSize())
-                break;
-
-            //1.计算距离
-            GlobalCoordinates target = new GlobalCoordinates(wdInfo.getLat().doubleValue(), wdInfo.getLng().doubleValue());
-            double meter2 = DistanceUtil.getDistanceMeter(source, target, Ellipsoid.WGS84);
-
-            if(meter2 <= topologicalWdAceeptVo.getRadius()){
-                TopologicalBuildingWd topologicalBuildingWd = new TopologicalBuildingWd(wdInfo);
-                topologicalBuildingWd.setAddrCodeInfo(addrCodeMap.get(topologicalBuildingWd.getAddrCode()));
-                BigDecimal bigDecimal = new BigDecimal(meter2);
-                topologicalBuildingWd.setDistance(bigDecimal.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
-
-                //补充公司数据
-                //....
-
-                list.add(topologicalBuildingWd);
-            }
+        for (WdInfo wdInfo : pageInfo.getList()) {
+            TopologicalBuildingWd topologicalBuildingWd = new TopologicalBuildingWd(wdInfo);
+            topologicalBuildingWd.setAddrCodeInfo(addrCodeMap.get(topologicalBuildingWd.getAddrCode()));
+            BigDecimal bigDecimal = new BigDecimal(hashMap.get(wdInfo.getWdId()));
+            topologicalBuildingWd.setDistance(bigDecimal.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
+            list.add(topologicalBuildingWd);
         }
+
         return list;
     }
 }

+ 41 - 16
benyun-core/src/main/java/com/benyun/core/service/impl/TopologicalCommonServiceImpl.java

@@ -5,6 +5,7 @@ import com.benyun.core.dao.WdInfoDao;
 import com.benyun.core.entity.TopologicalStoreWd;
 import com.benyun.core.entity.WdInfo;
 import com.benyun.core.entity.vo.TopologicalWdAceeptVo;
+import com.benyun.core.entity.vo.WdInfoVo;
 import com.benyun.core.service.TopologicalCommonService;
 import com.benyun.core.utils.DistanceUtil;
 import com.github.pagehelper.PageHelper;
@@ -12,12 +13,20 @@ import com.github.pagehelper.PageInfo;
 import org.gavaghan.geodesy.Ellipsoid;
 import org.gavaghan.geodesy.GlobalCoordinates;
 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 java.lang.reflect.Array;
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
 
 @Service
@@ -25,6 +34,13 @@ public class TopologicalCommonServiceImpl implements TopologicalCommonService {
     @Autowired
     WdInfoDao wdInfoDao;
 
+    @Autowired
+    @Qualifier("addrCodeMap")
+    HashMap<String,String> addrCodeMap;
+
+    @Autowired
+    RedisTemplate redisTemplate;
+
     @Override
     public List<WdInfo> prefixSearch(String searchText) {
         QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
@@ -73,29 +89,38 @@ public class TopologicalCommonServiceImpl implements TopologicalCommonService {
 
     @Override
     public List<WdInfo> map(TopologicalWdAceeptVo topologicalWdAceeptVo) {
-        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
+        //1.根据中心网点Id找到网点详细信息
+        QueryWrapper<WdInfo> queryWrapper1 = new QueryWrapper<>();
+        queryWrapper1.eq("wd_id",topologicalWdAceeptVo.getCenterWdId());
+        WdInfo wdInfo1 = wdInfoDao.selectOne(queryWrapper1);
 
-        //条件构造
-        queryWrapper.in("wd_type_code",topologicalWdAceeptVo.getChannel());
-        queryWrapper.and(wdInfoQueryWrapper -> {
-            wdInfoQueryWrapper.likeRight("geo_hash",topologicalWdAceeptVo.getGeoHash().substring(0,5));
+        //2.根据中心网点找到周边网点Id
+        // 以经纬度为中心,获取半径不超过最大距离的所有元素
+        Point point = new Point(wdInfo1.getLat().doubleValue(),wdInfo1.getLng().doubleValue());
+        //半径范围
+        Distance distance = new Distance(topologicalWdAceeptVo.getRadius(), RedisGeoCommands.DistanceUnit.METERS);
+        //圆
+        Circle circle = new Circle(point, distance);
+        GeoResults<RedisGeoCommands.GeoLocation<Object>> radius = redisTemplate.boundGeoOps(wdInfo1.getAddrCode().substring(0, 4)).radius(circle);
+        //周边网点Id
+        List<String> aroundWdId = new ArrayList<>();
+        radius.getContent().stream().forEach(item -> {
+            //记录网点坐标及距离
+            aroundWdId.add((String) item.getContent().getName());
         });
 
+        //条件构造
+        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("wd_id","wd_name","addr_info","addr_code","lat","lng","typeCodeBy","typeNameBy","wdTypeCode")
+                .in("wd_id",aroundWdId);
+
         //查询结果
         List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
-
-        List<WdInfo> list = new ArrayList<>();  //返回结果集
-        GlobalCoordinates source = new GlobalCoordinates(topologicalWdAceeptVo.getLat(), topologicalWdAceeptVo.getLng());
         for (WdInfo wdInfo : wdInfos) {
-            //1.计算距离
-            GlobalCoordinates target = new GlobalCoordinates(wdInfo.getLat().doubleValue(), wdInfo.getLng().doubleValue());
-            double meter2 = DistanceUtil.getDistanceMeter(source, target, Ellipsoid.WGS84);
-
-            if(meter2 <= topologicalWdAceeptVo.getRadius()){
-                list.add(wdInfo);
-            }
+            wdInfo.setAddrCode(addrCodeMap.get(wdInfo.getAddrCode()));
         }
-        return list;
+
+        return wdInfos;
     }
 
 }

+ 51 - 25
benyun-core/src/main/java/com/benyun/core/service/impl/TopologicalEnterpriseWdServiceImpl.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.benyun.core.dao.TopologicalEnterpriseWdDao;
 import com.benyun.core.dao.WdInfoDao;
 import com.benyun.core.entity.TopologicalEnterpriseWd;
+import com.benyun.core.entity.TopologicalHouseWd;
 import com.benyun.core.entity.TopologicalStoreWd;
 import com.benyun.core.entity.WdInfo;
 import com.benyun.core.entity.vo.TopologicalWdAceeptVo;
@@ -15,6 +16,12 @@ import org.gavaghan.geodesy.Ellipsoid;
 import org.gavaghan.geodesy.GlobalCoordinates;
 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 java.math.BigDecimal;
@@ -32,41 +39,60 @@ public class TopologicalEnterpriseWdServiceImpl implements TopologicalEnterprise
     @Autowired
     @Qualifier("addrCodeMap")
     HashMap<String,String> addrCodeMap;
+
+    @Autowired
+    RedisTemplate redisTemplate;
+
     @Override
     public List<TopologicalEnterpriseWd> list(TopologicalWdAceeptVo topologicalWdAceeptVo) {
-        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
+        //1.根据中心网点Id找到网点详细信息
+        QueryWrapper<WdInfo> queryWrapper1 = new QueryWrapper<>();
+        queryWrapper1.eq("wd_id",topologicalWdAceeptVo.getCenterWdId());
+        WdInfo wdInfo1 = wdInfoDao.selectOne(queryWrapper1);
 
-        //条件构造
-        queryWrapper.eq("wd_type_code","5");
-        queryWrapper.and(wdInfoQueryWrapper -> {
-            wdInfoQueryWrapper.likeRight("geo_hash",topologicalWdAceeptVo.getGeoHash().substring(0,5));
+        //2.根据中心网点找到周边网点Id
+        // 以经纬度为中心,获取半径不超过最大距离的所有元素
+        Point point = new Point(wdInfo1.getLng().doubleValue(),wdInfo1.getLat().doubleValue());
+        //半径范围
+        Distance distance = new Distance(topologicalWdAceeptVo.getRadius(), RedisGeoCommands.DistanceUnit.METERS);
+        //圆
+        Circle circle = new Circle(point, distance);
+        RedisGeoCommands.GeoRadiusCommandArgs geoRadiusCommandArgs = RedisGeoCommands.GeoRadiusCommandArgs.newGeoRadiusArgs();
+        geoRadiusCommandArgs.includeDistance();
+        GeoResults<RedisGeoCommands.GeoLocation<Object>> radius = redisTemplate.boundGeoOps(wdInfo1.getAddrCode().substring(0, 4)).radius(circle,geoRadiusCommandArgs);
+        //周边网点Id
+        List<String> aroundWdId = new ArrayList<>();
+        HashMap<String,Double> hashMap = new HashMap<>();
+        radius.getContent().stream().forEach(item -> {
+            //记录网点坐标及距离
+            aroundWdId.add((String) item.getContent().getName());
+            hashMap.put((String) item.getContent().getName(), item.getDistance().getValue());
         });
 
-        //查询结果
-        List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
 
-        List<TopologicalEnterpriseWd> list = new ArrayList<>();  //返回结果集
-        GlobalCoordinates source = new GlobalCoordinates(topologicalWdAceeptVo.getLat(), topologicalWdAceeptVo.getLng());
-        for (WdInfo wdInfo : wdInfos) {
-            if(list.size() >= topologicalWdAceeptVo.getSize())
-                break;
-
-            //1.计算距离
-            GlobalCoordinates target = new GlobalCoordinates(wdInfo.getLat().doubleValue(), wdInfo.getLng().doubleValue());
-            double meter2 = DistanceUtil.getDistanceMeter(source, target, Ellipsoid.WGS84);
+        //4.分页查找网点信息
+        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("wd_type_code","5")
+            .and(wdInfoQueryWrapper -> {
+                wdInfoQueryWrapper.in("wd_id", aroundWdId);
+            });
 
-            if(meter2 <= topologicalWdAceeptVo.getRadius()){
-                TopologicalEnterpriseWd topologicalEnterpriseWd = new TopologicalEnterpriseWd(wdInfo);
-                topologicalEnterpriseWd.setAddrCodeInfo(addrCodeMap.get(topologicalEnterpriseWd.getAddrCode()));
-                BigDecimal bigDecimal = new BigDecimal(meter2);
-                topologicalEnterpriseWd.setDistance(bigDecimal.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
+        //5.查询周边网点结果
+        PageHelper.startPage(1, topologicalWdAceeptVo.getSize());
+        List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
+        PageInfo<WdInfo> pageInfo = new PageInfo<>(wdInfos);
 
-                //补充公司数据
-                //....
 
-                list.add(topologicalEnterpriseWd);
-            }
+        //6.组装结果集
+        List<TopologicalEnterpriseWd> list = new ArrayList<>();  //返回结果集
+        for (WdInfo wdInfo : pageInfo.getList()) {
+            TopologicalEnterpriseWd topologicalEnterpriseWd = new TopologicalEnterpriseWd(wdInfo);
+            topologicalEnterpriseWd.setAddrCodeInfo(addrCodeMap.get(topologicalEnterpriseWd.getAddrCode()));
+            BigDecimal bigDecimal = new BigDecimal(hashMap.get(wdInfo.getWdId()));
+            topologicalEnterpriseWd.setDistance(bigDecimal.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
+            list.add(topologicalEnterpriseWd);
         }
+
         return list;
     }
 }

+ 91 - 40
benyun-core/src/main/java/com/benyun/core/service/impl/TopologicalHouseServiceWdImpl.java

@@ -1,13 +1,11 @@
 package com.benyun.core.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.benyun.core.dao.HouseWdDao;
 import com.benyun.core.dao.TopologicalHouseWdDao;
 import com.benyun.core.dao.TopologicalHouseWdStatisticsDataDao;
 import com.benyun.core.dao.WdInfoDao;
-import com.benyun.core.entity.TopologicalHouseWd;
-import com.benyun.core.entity.TopologicalHouseWdStatisticsData;
-import com.benyun.core.entity.TopologicalStoreWd;
-import com.benyun.core.entity.WdInfo;
+import com.benyun.core.entity.*;
 import com.benyun.core.entity.vo.TopologicalWdAceeptVo;
 import com.benyun.core.service.TopologicalHouseWdService;
 import com.benyun.core.utils.DistanceUtil;
@@ -17,6 +15,12 @@ import org.gavaghan.geodesy.Ellipsoid;
 import org.gavaghan.geodesy.GlobalCoordinates;
 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 java.math.BigDecimal;
@@ -26,64 +30,111 @@ import java.util.List;
 
 @Service
 public class TopologicalHouseServiceWdImpl implements TopologicalHouseWdService {
-    @Autowired
-    TopologicalHouseWdDao topologicalHouseWdDao;
 
-    @Autowired
-    WdInfoDao wdInfoDao;
 
     @Autowired
-    TopologicalHouseWdStatisticsDataDao topologicalHouseWdStatisticsDataDao;
+    WdInfoDao wdInfoDao;
 
     @Autowired
     @Qualifier("addrCodeMap")
     HashMap<String,String> addrCodeMap;
 
+    @Autowired
+    RedisTemplate redisTemplate;
+
+    @Autowired
+    HouseWdDao houseWdDao;
+
     @Override
     public List<TopologicalHouseWd> list(TopologicalWdAceeptVo topologicalWdAceeptVo) {
-        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
+        //1.根据中心网点Id找到网点详细信息
+        QueryWrapper<WdInfo> queryWrapper1 = new QueryWrapper<>();
+        queryWrapper1.eq("wd_id",topologicalWdAceeptVo.getCenterWdId());
+        WdInfo wdInfo1 = wdInfoDao.selectOne(queryWrapper1);
 
-        //条件构造
-        queryWrapper.eq("wd_type_code","2");
-        queryWrapper.and(wdInfoQueryWrapper -> {
-            wdInfoQueryWrapper.likeRight("geo_hash",topologicalWdAceeptVo.getGeoHash().substring(0,5));
+        //2.根据中心网点找到周边网点Id
+        // 以经纬度为中心,获取半径不超过最大距离的所有元素
+        Point point = new Point(wdInfo1.getLng().doubleValue(),wdInfo1.getLat().doubleValue());
+        //半径范围
+        Distance distance = new Distance(topologicalWdAceeptVo.getRadius(), RedisGeoCommands.DistanceUnit.METERS);
+        //圆
+        Circle circle = new Circle(point, distance);
+        RedisGeoCommands.GeoRadiusCommandArgs geoRadiusCommandArgs = RedisGeoCommands.GeoRadiusCommandArgs.newGeoRadiusArgs();
+        geoRadiusCommandArgs.includeDistance();
+        GeoResults<RedisGeoCommands.GeoLocation<Object>> radius = redisTemplate.boundGeoOps(wdInfo1.getAddrCode().substring(0, 4)).radius(circle,geoRadiusCommandArgs);
+        //周边网点Id
+        List<String> aroundWdId = new ArrayList<>();
+        HashMap<String,Double> hashMap = new HashMap<>();
+        radius.getContent().stream().forEach(item -> {
+            //记录网点坐标及距离
+            aroundWdId.add((String) item.getContent().getName());
+            hashMap.put((String) item.getContent().getName(), item.getDistance().getValue());
         });
 
-        //查询结果
+
+        //4.分页查找网点信息
+        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("wd_type_code","2")
+            .and(wdInfoQueryWrapper -> {
+                wdInfoQueryWrapper.in("wd_id", aroundWdId);
+            });
+
+        //5.查询周边网点结果
+        PageHelper.startPage(1, topologicalWdAceeptVo.getSize());
         List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
+        PageInfo<WdInfo> pageInfo = new PageInfo<>(wdInfos);
+
 
+        //6.组装结果集
         List<TopologicalHouseWd> list = new ArrayList<>();  //返回结果集
-        GlobalCoordinates source = new GlobalCoordinates(topologicalWdAceeptVo.getLat(), topologicalWdAceeptVo.getLng());
-        for (WdInfo wdInfo : wdInfos) {
-            if(list.size() >= topologicalWdAceeptVo.getSize())
-                break;
-
-            //1.计算距离
-            GlobalCoordinates target = new GlobalCoordinates(wdInfo.getLat().doubleValue(), wdInfo.getLng().doubleValue());
-            double meter2 = DistanceUtil.getDistanceMeter(source, target, Ellipsoid.WGS84);
-
-            if(meter2 <= topologicalWdAceeptVo.getRadius()){
-                TopologicalHouseWd topologicalHouseWd = new TopologicalHouseWd(wdInfo);
-                topologicalHouseWd.setAddrCodeInfo(addrCodeMap.get(topologicalHouseWd.getAddrCode()));
-                BigDecimal bigDecimal = new BigDecimal(meter2);
-                topologicalHouseWd.setDistance(bigDecimal.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
-
-                //补充门店数据
-                //....
-
-                list.add(topologicalHouseWd);
-            }
+        for (WdInfo wdInfo : pageInfo.getList()) {
+            TopologicalHouseWd topologicalHouseWd = new TopologicalHouseWd(wdInfo);
+            topologicalHouseWd.setAddrCodeInfo(addrCodeMap.get(topologicalHouseWd.getAddrCode()));
+            BigDecimal bigDecimal = new BigDecimal(hashMap.get(wdInfo.getWdId()));
+            topologicalHouseWd.setDistance(bigDecimal.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
+            list.add(topologicalHouseWd);
         }
+
         return list;
     }
 
     @Override
     public TopologicalHouseWdStatisticsData info(TopologicalWdAceeptVo topologicalWdAceeptVo) {
-        QueryWrapper<TopologicalHouseWdStatisticsData> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("center_wd_id",topologicalWdAceeptVo.getCenterWdId()).and(topologicalHouseWdStatisticsDataQueryWrapper -> {
-            topologicalHouseWdStatisticsDataQueryWrapper.eq("radius",Integer.valueOf(topologicalWdAceeptVo.getRadius()));
+        //1.根据中心网点Id找到网点详细信息
+        QueryWrapper<WdInfo> queryWrapper1 = new QueryWrapper<>();
+        queryWrapper1.eq("wd_id",topologicalWdAceeptVo.getCenterWdId());
+        WdInfo wdInfo1 = wdInfoDao.selectOne(queryWrapper1);
+
+        //2.根据中心网点找到周边网点Id
+        // 以经纬度为中心,获取半径不超过最大距离的所有元素
+        Point point = new Point(wdInfo1.getLng().doubleValue(),wdInfo1.getLat().doubleValue());
+        //半径范围
+        Distance distance = new Distance(topologicalWdAceeptVo.getRadius(), RedisGeoCommands.DistanceUnit.METERS);
+        //圆
+        Circle circle = new Circle(point, distance);
+        GeoResults<RedisGeoCommands.GeoLocation<Object>> radius = redisTemplate.boundGeoOps(wdInfo1.getAddrCode().substring(0, 4)).radius(circle);
+        //周边网点Id
+        List<String> aroundWdId = new ArrayList<>();
+        radius.getContent().stream().forEach(item -> {
+            //记录网点坐标及距离
+            aroundWdId.add((String) item.getContent().getName());
         });
-        TopologicalHouseWdStatisticsData topologicalHouseWdStatisticsData = topologicalHouseWdStatisticsDataDao.selectOne(queryWrapper);
-        return topologicalHouseWdStatisticsData;
+
+
+
+        //4.分页查找网点信息
+        TopologicalHouseWdStatisticsData result = new TopologicalHouseWdStatisticsData();
+        int total = 0;
+        List<TopologicalHouseWdStatisticsData> houseWdStatisticsData = houseWdDao.selectAndStatistics(aroundWdId);
+        for (TopologicalHouseWdStatisticsData houseWdStatisticsDatum : houseWdStatisticsData) {
+            result.setTotalPeopleCount(houseWdStatisticsDatum.getTotalPeopleCount()+result.getTotalPeopleCount());
+            result.setTotalHouseholds(houseWdStatisticsDatum.getTotalHouseholds()+result.getTotalHouseholds());
+            result.setAverageRent(houseWdStatisticsDatum.getAverageRent()+result.getAverageRent());
+            total++;
+        }
+        result.setHouseWdCount(total);
+        result.setAverageRent(result.getAverageRent()/total);
+
+        return result;
     }
 }

+ 131 - 71
benyun-core/src/main/java/com/benyun/core/service/impl/TopologicalStoreWdServiceImpl.java

@@ -1,14 +1,9 @@
 package com.benyun.core.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.benyun.core.dao.TopologicalStoreWdDao;
-import com.benyun.core.dao.TopologicalStoreWdStatisticsCategoryDao;
+import com.benyun.core.dao.*;
 import com.benyun.core.dao.WdInfoDao;
-import com.benyun.core.dao.WdInfoDao;
-import com.benyun.core.entity.ManageType;
-import com.benyun.core.entity.TopologicalStoreWd;
-import com.benyun.core.entity.TopologicalStoreWdStatisticsCategory;
-import com.benyun.core.entity.WdInfo;
+import com.benyun.core.entity.*;
 import com.benyun.core.entity.bo.StoreWdCategoryCount;
 import com.benyun.core.entity.bo.StoreWdCategoryCountBody;
 import com.benyun.core.entity.vo.TopologicalWdAceeptVo;
@@ -20,12 +15,16 @@ import org.gavaghan.geodesy.Ellipsoid;
 import org.gavaghan.geodesy.GlobalCoordinates;
 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 java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
 
 @Service
 public class TopologicalStoreWdServiceImpl implements TopologicalStoreWdService {
@@ -36,6 +35,9 @@ public class TopologicalStoreWdServiceImpl implements TopologicalStoreWdService
     @Autowired
     WdInfoDao wdInfoDao;
 
+    @Autowired
+    StoreWdDao storeWdDao;
+
     @Autowired
     @Qualifier("ManageType")
     HashMap<String, ManageType> manageType;
@@ -44,87 +46,145 @@ public class TopologicalStoreWdServiceImpl implements TopologicalStoreWdService
     @Qualifier("addrCodeMap")
     HashMap<String,String> addrCodeMap;
 
+    @Autowired
+    RedisTemplate redisTemplate;
 
-
+    //TODO 待测试
     @Override
     public List<TopologicalStoreWd> list(TopologicalWdAceeptVo topologicalWdAceeptVo) {
-        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
-
-        //条件构造
-        queryWrapper.eq("wd_type_code","1");
-        queryWrapper.and(wdInfoQueryWrapper -> {
-            wdInfoQueryWrapper.likeRight("geo_hash",topologicalWdAceeptVo.getGeoHash().substring(0,5));
+        //1.根据中心网点Id找到网点详细信息
+        QueryWrapper<WdInfo> queryWrapper1 = new QueryWrapper<>();
+        queryWrapper1.eq("wd_id",topologicalWdAceeptVo.getCenterWdId());
+        WdInfo wdInfo1 = wdInfoDao.selectOne(queryWrapper1);
+
+        //2.根据中心网点找到周边网点Id
+        // 以经纬度为中心,获取半径不超过最大距离的所有元素
+        Point point = new Point(wdInfo1.getLng().doubleValue(),wdInfo1.getLat().doubleValue());
+        //半径范围
+        Distance distance = new Distance(topologicalWdAceeptVo.getRadius(), RedisGeoCommands.DistanceUnit.METERS);
+        //圆
+        Circle circle = new Circle(point, distance);
+        RedisGeoCommands.GeoRadiusCommandArgs geoRadiusCommandArgs = RedisGeoCommands.GeoRadiusCommandArgs.newGeoRadiusArgs();
+        geoRadiusCommandArgs.includeDistance();
+        GeoResults<RedisGeoCommands.GeoLocation<Object>> radius = redisTemplate.boundGeoOps(wdInfo1.getAddrCode().substring(0, 4)).radius(circle,geoRadiusCommandArgs);
+        //周边网点Id
+        List<String> aroundWdId = new ArrayList<>();
+        HashMap<String,Double> hashMap = new HashMap<>();
+        radius.getContent().stream().forEach(item -> {
+            //记录网点坐标及距离
+            aroundWdId.add((String) item.getContent().getName());
+            hashMap.put((String) item.getContent().getName(), item.getDistance().getValue());
         });
 
-        //查询结果
-        List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
-
-        List<TopologicalStoreWd> list = new ArrayList<>();  //返回结果集
-        GlobalCoordinates source = new GlobalCoordinates(topologicalWdAceeptVo.getLat(), topologicalWdAceeptVo.getLng());
-        for (WdInfo wdInfo : wdInfos) {
-            if(list.size() >= topologicalWdAceeptVo.getSize())
-                break;
 
-            //1.计算距离
-            GlobalCoordinates target = new GlobalCoordinates(wdInfo.getLat().doubleValue(), wdInfo.getLng().doubleValue());
-            double meter2 = DistanceUtil.getDistanceMeter(source, target, Ellipsoid.WGS84);
+        //4.分页查找网点信息
+        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("wd_type_code","1")
+            .and(wdInfoQueryWrapper -> {
+                wdInfoQueryWrapper.in("wd_id", aroundWdId);
+        });
 
-            if(meter2 <= topologicalWdAceeptVo.getRadius()){
-                TopologicalStoreWd topologicalStoreWd = new TopologicalStoreWd(wdInfo);
-                topologicalStoreWd.setAddrCodeInfo(addrCodeMap.get(topologicalStoreWd.getAddrCode()));
-                BigDecimal bigDecimal = new BigDecimal(meter2);
-                topologicalStoreWd.setDistance(bigDecimal.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
+        //5.查询周边网点结果
+        PageHelper.startPage(1, topologicalWdAceeptVo.getSize());
+        List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
+        PageInfo<WdInfo> pageInfo = new PageInfo<>(wdInfos);
 
-                //补充门店数据
-                //....
 
-                list.add(topologicalStoreWd);
-            }
+        //6.组装结果集
+        List<TopologicalStoreWd> list = new ArrayList<>();  //返回结果集
+        for (WdInfo wdInfo : pageInfo.getList()) {
+            TopologicalStoreWd topologicalStoreWd = new TopologicalStoreWd(wdInfo);
+            topologicalStoreWd.setAddrCodeInfo(addrCodeMap.get(topologicalStoreWd.getAddrCode()));
+            BigDecimal bigDecimal = new BigDecimal(hashMap.get(wdInfo.getWdId()));
+            topologicalStoreWd.setDistance(bigDecimal.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
+            list.add(topologicalStoreWd);
         }
+
         return list;
     }
 
-    //TODO 未返回total
+    //TODO 待测试
     @Override
     public List<StoreWdCategoryCount> category(TopologicalWdAceeptVo topologicalWdAceeptVo) {
+        //1.根据中心网点Id找到网点详细信息
+        QueryWrapper<WdInfo> queryWrapper1 = new QueryWrapper<>();
+        queryWrapper1.eq("wd_id",topologicalWdAceeptVo.getCenterWdId());
+        WdInfo wdInfo1 = wdInfoDao.selectOne(queryWrapper1);
+
+        //2.根据中心网点找到周边网点Id
+        // 以经纬度为中心,获取半径不超过最大距离的所有元素
+        Point point = new Point(wdInfo1.getLng().doubleValue(),wdInfo1.getLat().doubleValue());
+        //半径范围
+        Distance distance = new Distance(topologicalWdAceeptVo.getRadius(), RedisGeoCommands.DistanceUnit.METERS);
+        //圆
+        Circle circle = new Circle(point, distance);
+        GeoResults<RedisGeoCommands.GeoLocation<Object>> radius = redisTemplate.boundGeoOps(wdInfo1.getAddrCode().substring(0, 4)).radius(circle);
+        //周边网点Id
+        List<String> aroundWdId = new ArrayList<>();
+        radius.getContent().stream().forEach(item -> {
+            //记录网点坐标及距离
+            aroundWdId.add((String) item.getContent().getName());
+        });
 
-        List<StoreWdCategoryCount> storeWdCategoryCounts = new ArrayList<>();
 
-        int total = 0;
-        List<TopologicalStoreWdStatisticsCategory> statisticsCategories = storeWdStatisticsCategoryDao.category(topologicalWdAceeptVo);
-        for (TopologicalStoreWdStatisticsCategory statisticsCategory : statisticsCategories) {
-            StoreWdCategoryCount storeWdCategoryCount = new StoreWdCategoryCount();
-
-            String midManageTypeCode = statisticsCategory.getMidManageTypeCode();
-            String[] split1 = midManageTypeCode.split(":");
-            storeWdCategoryCount.setManageTypeCode(split1[0]+"00");
-            ManageType manageType1 = manageType.get(storeWdCategoryCount.getManageTypeCode());
-            storeWdCategoryCount.setName(manageType1.getMidCategory());
-            storeWdCategoryCount.setCount(Integer.parseInt(split1[1]));
-            total+=storeWdCategoryCount.getCount();
-
-            //拆分
-            String subCategoryCodeStatistics = statisticsCategory.getSubCategoryCodeStatistics();
-            List<StoreWdCategoryCountBody> storeWdCategoryCountBodyList = new ArrayList<>();
-            for (String s : subCategoryCodeStatistics.split(";")) {
-                String[] split = s.split(":");
-                if (split.length !=2)
-                    continue;
-                if(split[0].equals(storeWdCategoryCount.getManageTypeCode()))
-                    break;
+        //4.分页查找网点信息
+        QueryWrapper<StoreWd> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("manage_type_code","count(*) as comment_count")
+            .in("wd_id",aroundWdId)
+            .groupBy("manage_type_code");
 
+        //5.查询周边网点结果,并统计
+        List<StoreWd> wdInfos = storeWdDao.selectList(queryWrapper);
+        HashMap<String,StoreWdCategoryCount> hashMap = new HashMap<>();
+        for (StoreWd wdInfo : wdInfos) {
+            if(wdInfo.getManageTypeCode() == null || wdInfo.getManageTypeCode().equals(""))
+                continue;
+
+            String s = wdInfo.getManageTypeCode().substring(0, 4) + "00";
+            StoreWdCategoryCount storeWdCategoryCount = hashMap.get(s);
+            if (storeWdCategoryCount == null){
+                StoreWdCategoryCountBody storeWdCategoryCountBody = new StoreWdCategoryCountBody();
+                if(manageType.get(wdInfo.getManageTypeCode()).getSubCategory() != null && manageType.get(wdInfo.getManageTypeCode()).getSubCategory().equals("")){
+                    storeWdCategoryCountBody.setName(manageType.get(wdInfo.getManageTypeCode()).getSubCategory());
+                }else if(manageType.get(wdInfo.getManageTypeCode()).getMidCategory() != null && manageType.get(wdInfo.getManageTypeCode()).getMidCategory().equals("")){
+                    storeWdCategoryCountBody.setName(manageType.get(wdInfo.getManageTypeCode()).getMidCategory());
+                }else if (manageType.get(wdInfo.getManageTypeCode()).getBigCategory() != null && manageType.get(wdInfo.getManageTypeCode()).getBigCategory().equals("")){
+                    storeWdCategoryCountBody.setName(manageType.get(wdInfo.getManageTypeCode()).getBigCategory());
+                }
+                storeWdCategoryCountBody.setManageTypeCode(wdInfo.getManageTypeCode());
+                storeWdCategoryCountBody.setCount(wdInfo.getCommentCount());
+
+                StoreWdCategoryCount storeWdCategoryCount1 = new StoreWdCategoryCount();
+                storeWdCategoryCount1.setManageTypeCode(s);
+                storeWdCategoryCount1.setName(manageType.get(s).getMidCategory());
+                storeWdCategoryCount1.setCount(wdInfo.getCommentCount());
+                ArrayList<StoreWdCategoryCountBody> list = new ArrayList<>();
+                list.add(storeWdCategoryCountBody);
+                storeWdCategoryCount1.setStoreWdCategoryCountBodyList(list);
+                hashMap.put(s,storeWdCategoryCount1);
+            }else {
                 StoreWdCategoryCountBody storeWdCategoryCountBody = new StoreWdCategoryCountBody();
-                storeWdCategoryCountBody.setManageTypeCode(split[0]);
-                ManageType manageType2 = manageType.get(storeWdCategoryCountBody.getManageTypeCode());
-                storeWdCategoryCountBody.setName(manageType2.getSubCategory());
-                storeWdCategoryCountBody.setCount(Integer.parseInt(split[1]));
-                BigDecimal bigDecimal = new BigDecimal((double) storeWdCategoryCount.getCount() / storeWdCategoryCountBody.getCount());
-                double v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
-                storeWdCategoryCountBody.setRadio(v);
-                storeWdCategoryCountBodyList.add(storeWdCategoryCountBody);
+                if(manageType.get(wdInfo.getManageTypeCode()).getSubCategory() != null && manageType.get(wdInfo.getManageTypeCode()).getSubCategory().equals("")){
+                    storeWdCategoryCountBody.setName(manageType.get(wdInfo.getManageTypeCode()).getSubCategory());
+                }else if(manageType.get(wdInfo.getManageTypeCode()).getMidCategory() != null && manageType.get(wdInfo.getManageTypeCode()).getMidCategory().equals("")){
+                    storeWdCategoryCountBody.setName(manageType.get(wdInfo.getManageTypeCode()).getMidCategory());
+                }else if (manageType.get(wdInfo.getManageTypeCode()).getBigCategory() != null && manageType.get(wdInfo.getManageTypeCode()).getBigCategory().equals("")){
+                    storeWdCategoryCountBody.setName(manageType.get(wdInfo.getManageTypeCode()).getBigCategory());
+                }
+                storeWdCategoryCountBody.setManageTypeCode(wdInfo.getManageTypeCode());
+                storeWdCategoryCountBody.setCount(wdInfo.getCommentCount());
+
+                storeWdCategoryCount.getStoreWdCategoryCountBodyList().add(storeWdCategoryCountBody);
+                storeWdCategoryCount.setCount(storeWdCategoryCountBody.getCount()+storeWdCategoryCount.getCount());
+                //hashMap.put(s,storeWdCategoryCount);
             }
-            storeWdCategoryCount.setStoreWdCategoryCountBodyList(storeWdCategoryCountBodyList);
-            storeWdCategoryCounts.add(storeWdCategoryCount);
+        }
+
+
+        //6.组装结果集
+        List<StoreWdCategoryCount> storeWdCategoryCounts = new ArrayList<>();
+        for (String s : hashMap.keySet()) {
+            storeWdCategoryCounts.add(hashMap.get(s));
         }
 
         return storeWdCategoryCounts;

+ 148 - 0
benyun-core/src/main/java/com/benyun/core/utils/WdRedisStoreage.java

@@ -0,0 +1,148 @@
+package com.benyun.core.utils;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.benyun.core.constant.RedisContant;
+import com.benyun.core.dao.WdInfoDao;
+import com.benyun.core.entity.WdInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.data.geo.Distance;
+import org.springframework.data.geo.GeoResult;
+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.Component;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.stream.Collectors;
+
+@Component
+public class WdRedisStoreage {
+    @Autowired
+    private  RedisTemplate redisTemplate;
+
+    @Autowired
+    public   WdInfoDao wdInfoDao;
+
+    @Autowired
+    @Qualifier("executor")
+    private ExecutorService executorService;
+
+
+    /***
+     * 获取中心网点的周边标签
+     * @param wdInfo 中心网点信息
+     * @return
+     */
+    public  List<String> getWdTag(WdInfo wdInfo){
+        List<String> tag = (List<String>) redisTemplate.boundHashOps(RedisContant.WD_TAG).get(wdInfo.getWdId());
+        if (tag != null)
+            return tag;
+
+        //分析该网点
+        List<String> strings = wdTagAnalyse(wdInfo);
+        return strings;
+    }
+
+    /***
+     * 分析网点周边标签,并把分析结果存入redis(默认范围:1km)
+     * @param wdInfo 中心网点信息
+     * @return
+     */
+    public  List<String> wdTagAnalyse(WdInfo wdInfo){
+        //1. 找到距离中心网点半径1km的所有网点Id
+        Distance distance = new Distance(1, RedisGeoCommands.DistanceUnit.KILOMETERS);
+        GeoResults<RedisGeoCommands.GeoLocation<Object>> radius = redisTemplate.boundGeoOps(wdInfo.getAddrCode().substring(0, 4)).radius(wdInfo.getWdId(), distance);
+        List<GeoResult<RedisGeoCommands.GeoLocation<Object>>> content = radius.getContent();
+        List<String> aroundWdId = content.stream().map(item -> {
+            String name = (String) item.getContent().getName();
+            return name;
+        }).collect(Collectors.toList());
+
+        //2. 查询周边网点标签的Set集
+        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("type_name_by")
+                .in("wd_id",aroundWdId)
+                    .groupBy("type_name_by");
+        List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
+
+        //3. 打标签
+        List<String> tag = new ArrayList<>();
+        wdInfos.stream().forEach(item -> {
+            if(item != null){
+                String typeNameBy = item.getTypeNameBy();
+                if(typeNameBy != null && !typeNameBy.equals("")){
+                    String[] split = typeNameBy.split(":");
+                    if (split.length > 0)
+                        tag.add(split[split.length-1]);
+                }
+            }
+        });
+        redisTemplate.boundHashOps(RedisContant.WD_TAG).put(wdInfo.getWdId(),tag);
+        return tag;
+    }
+
+    /**
+     * 将网点数据库 导入 redis
+     * */
+    public void writeWdGeoRedis(){
+        //将所有网点坐标导入redis
+        //writeWdGeoRedis1();
+
+        //给网点打标签并存入redis中
+        writeWdGeoRedis2();
+    }
+
+    private void writeWdGeoRedis1(){
+        //1.将网点坐标存入redis中
+        long start = System.currentTimeMillis();
+        System.out.println("开始将网点坐标存入redis");
+        for (WdInfo wdInfo : wdInfoDao.selectList(null)) {
+            //开启线程
+            CompletableFuture<Void> future = CompletableFuture.runAsync(()->{
+                redisTemplate.boundGeoOps(wdInfo.getAddrCode().substring(0,4)).add(new Point(wdInfo.getLng().doubleValue(),wdInfo.getLat().doubleValue()),wdInfo.getWdId());
+            },executorService);
+            try {
+                future.get();
+            } catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            } catch (ExecutionException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        long end = System.currentTimeMillis();
+        System.out.println("完成存入 "+(end-start)/(1000*60));
+    }
+
+    private void writeWdGeoRedis2(){
+        //2.对所有网点坐标进行分析打标签
+        long start = System.currentTimeMillis();
+        System.out.println("开始打标签");
+        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.in("wd_type_code", Arrays.asList("1","2","3","5"));
+        List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
+        for (WdInfo wdInfo : wdInfos) {
+            //开启线程
+            CompletableFuture<Void> future = CompletableFuture.runAsync(()->{
+                wdTagAnalyse(wdInfo);
+            },executorService);
+            try {
+                future.get();
+            } catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            } catch (ExecutionException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        long end = System.currentTimeMillis();
+        System.out.println("完成打标签 "+(end-start)/(1000*60));
+    }
+
+
+}

+ 26 - 12
benyun-core/src/main/resources/application-prod.yaml

@@ -144,18 +144,32 @@ spring:
             standard:
               sharding-column: center_wd_id
               precise-algorithm-class-name: com.benyun.core.utils.sharding.ConsistenceHashAlgorithm
-  redis: #redis配置
-    host: 192.168.2.64  #redis服务地址
-    database: 11
-    port: 6379       #redis连接端口
-    timeout: 5000ms  #连接超时时间
-    password: "123456"
-    pool:
-      minIdle: 1   #连接池中的最小空闲连接
-      maxIdle: 10  #连接池中的最大空闲连接
-      maxWait: 3   #连接池最大阻塞等待时间(使用负值表示没有限制)
-      maxActive: 8 #连接池最大连接数(使用赋值表示没有限制)
-
+#  redis: #redis配置
+#    host: 192.168.2.64  #redis服务地址
+#    database: 11
+#    port: 6379       #redis连接端口
+#    timeout: 5000ms  #连接超时时间
+#    password: "123456"
+#    pool:
+#      minIdle: 1   #连接池中的最小空闲连接
+#      maxIdle: 10  #连接池中的最大空闲连接
+#      maxWait: 3   #连接池最大阻塞等待时间(使用负值表示没有限制)
+#      maxActive: 8 #连接池最大连接数(使用赋值表示没有限制)
+  redis:
+    cluster:
+      # 集群节点
+      nodes: 192.168.2.99:7001,192.168.2.99:7002,192.168.2.99:7003,192.168.2.99:7004,192.168.2.99:7005,192.168.2.99:7006
+      # 最大重定向次数
+      max-redirects: 5
+    # 密码
+    password: 123456
+    lettuce:
+      pool:
+        min-idle: 0
+        max-active: 8
+        max-wait: -1
+        max-idle: 8
+        enabled: true
 #mybatis-plus配置
 mybatis-plus:
   mapper-locations: classpath:/mapper/**/*.xml  #告诉mybatis数据库映射文件mapper.xml的位置

+ 16 - 0
benyun-core/src/main/resources/mapper/HouseWdDao.xml

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.benyun.core.dao.HouseWdDao">
+    <select id="selectAndStatistics" parameterType="java.lang.String" resultType="com.benyun.core.entity.TopologicalHouseWdStatisticsData">
+        select people_count as totalPeopleCount,households as totalHouseholds,rent as averageRent from ddt_house_wd inner join ddt_wd_info on ddt_house_wd.wd_id = ddt_wd_info.wd_id
+        <where>
+            ddt_house_wd.wd_id in
+            <foreach collection="list" open="(" close=")" item="item" separator=",">
+                #{item}
+            </foreach>
+        </where>
+    </select>
+
+</mapper>
+

+ 14 - 12
benyun-core/src/test/java/com/benyun/core/BenyunCoreApplicationTests.java

@@ -1,28 +1,30 @@
 package com.benyun.core;
 
+import com.benyun.core.dao.WdInfoDao;
+import com.benyun.core.entity.WdInfo;
+import com.benyun.core.utils.WdRedisStoreage;
 import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.data.geo.Point;
+import org.springframework.data.redis.core.RedisTemplate;
 
 import java.math.BigDecimal;
+import java.util.List;
 import java.util.Random;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
 
 @SpringBootTest
 class BenyunCoreApplicationTests {
+    @Autowired
+    WdRedisStoreage wdRedisStoreage;
 
     @Test
     void contextLoads() {
-//        String str = "xx:xx:";
-//        String[] split = str.split(":");
-//        System.out.println(split.length);
-
-        Random random = new Random();
-        double v = random.nextDouble();
-        double random1 = Math.random()+4.0;
-
-        BigDecimal b = new BigDecimal(random1);
-        double f1 = b.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
-        System.out.println(f1);
-
+        wdRedisStoreage.writeWdGeoRedis();
     }
 
 }

+ 55 - 55
benyun-core/src/test/java/com/benyun/core/service/ChannelMapServiceImplTest.java

@@ -19,62 +19,62 @@ public class ChannelMapServiceImplTest {
     @Autowired
     ChannelMapService channelMapService;
 
-    @Test
-    public void areaProvinceTest() {
-        List<String> channel = Arrays.asList("1", "2", "3", "4", "5", "0");
-        String rankType = "province";
-        String searchText = "";
-        String[] addrCode = new String[]{"110000000000", "120000000000", "130000000000", "140000000000", "150000000000", "210000000000", "220000000000", "230000000000", "310000000000", "320000000000", "330000000000", "340000000000", "350000000000", "360000000000", "370000000000", "410000000000", "420000000000", "430000000000", "440000000000", "450000000000", "460000000000", "500000000000", "510000000000", "520000000000", "530000000000", "540000000000", "610000000000", "620000000000", "630000000000", "640000000000", "650000000000"};
-        WdCount area = channelMapService.area(channel, rankType, searchText, addrCode);
-        for (WdCountBody wdCountBody : area.getWdCountBodyList()) {
-            System.out.println(wdCountBody);
-        }
-        System.out.println(area.getTotal());
-    }
-
-    //市
-    @Test
-    public void areaCityest() {
-        List<String> channel = Arrays.asList("1", "2", "3", "4", "5", "0");
-        String rankType = "city";
-        String searchText = "蜜";
-        String[] addrCode =  new String[]{"450000000000"}; //省码
-        WdCount area = channelMapService.area(channel, rankType, searchText, addrCode);
-        for (WdCountBody wdCountBody : area.getWdCountBodyList()) {
-            System.out.println(wdCountBody);
-        }
-        System.out.println(area.getTotal());
-    }
+//    @Test
+//    public void areaProvinceTest() {
+//        List<String> channel = Arrays.asList("1", "2", "3", "4", "5", "0");
+//        String rankType = "province";
+//        String searchText = "";
+//        String[] addrCode = new String[]{"110000000000", "120000000000", "130000000000", "140000000000", "150000000000", "210000000000", "220000000000", "230000000000", "310000000000", "320000000000", "330000000000", "340000000000", "350000000000", "360000000000", "370000000000", "410000000000", "420000000000", "430000000000", "440000000000", "450000000000", "460000000000", "500000000000", "510000000000", "520000000000", "530000000000", "540000000000", "610000000000", "620000000000", "630000000000", "640000000000", "650000000000"};
+//        WdCount area = channelMapService.area(channel, rankType, searchText, addrCode);
+//        for (WdCountBody wdCountBody : area.getWdCountBodyList()) {
+//            System.out.println(wdCountBody);
+//        }
+//        System.out.println(area.getTotal());
+//    }
+//
+//    //市
+//    @Test
+//    public void areaCityest() {
+//        List<String> channel = Arrays.asList("1", "2", "3", "4", "5", "0");
+//        String rankType = "city";
+//        String searchText = "蜜";
+//        String[] addrCode =  new String[]{"450000000000"}; //省码
+//        WdCount area = channelMapService.area(channel, rankType, searchText, addrCode);
+//        for (WdCountBody wdCountBody : area.getWdCountBodyList()) {
+//            System.out.println(wdCountBody);
+//        }
+//        System.out.println(area.getTotal());
+//    }
+//
+//    //区
+//    @Test
+//    public void areaZoneTest() {
+//        List<String> channel = Arrays.asList("1", "2", "3", "4", "5", "0");
+//        String rankType = "zone";
+//        String searchText = "蜜";
+//        String[] addrCode = new String[]{"500000000000"}; //市码
+//        WdCount area = channelMapService.area(channel, rankType, searchText, addrCode);
+//        for (WdCountBody wdCountBody : area.getWdCountBodyList()) {
+//            System.out.println(wdCountBody);
+//        }
+//        System.out.println(area.getTotal());
+//    }
 
-    //区
-    @Test
-    public void areaZoneTest() {
-        List<String> channel = Arrays.asList("1", "2", "3", "4", "5", "0");
-        String rankType = "zone";
-        String searchText = "蜜";
-        String[] addrCode = new String[]{"500000000000"}; //市码
-        WdCount area = channelMapService.area(channel, rankType, searchText, addrCode);
-        for (WdCountBody wdCountBody : area.getWdCountBodyList()) {
-            System.out.println(wdCountBody);
-        }
-        System.out.println(area.getTotal());
-    }
-
-    @Test
-    public void listProvinceTest(){
-        String orderby = "collect_time";
-        int pageNum = 1;
-        int pageSize = 10;
-        String[] channel = new String[]{"1", "2", "3", "4", "5", "0"};
-        String[] addrCode = new String[]{"450000000000"};
-        String rankType = "province";
-        String searchText = "蜜";
-        HashMap hashMap = channelMapService.list(channel, rankType, searchText, orderby, addrCode, pageNum, pageSize);
-        List<WdTopologicalInfoBo> data = (List<WdTopologicalInfoBo>) hashMap.get("data");
-        for (WdTopologicalInfoBo originWdInfo : data) {
-            System.out.println("originWdInfo = " + originWdInfo);
-        }
-    }
+//    @Test
+//    public void listProvinceTest(){
+//        String orderby = "collect_time";
+//        int pageNum = 1;
+//        int pageSize = 10;
+//        String[] channel = new String[]{"1", "2", "3", "4", "5", "0"};
+//        String[] addrCode = new String[]{"450000000000"};
+//        String rankType = "province";
+//        String searchText = "蜜";
+//        HashMap hashMap = channelMapService.list(channel, rankType, searchText, orderby, addrCode, pageNum, pageSize);
+//        List<WdTopologicalInfoBo> data = (List<WdTopologicalInfoBo>) hashMap.get("data");
+//        for (WdTopologicalInfoBo originWdInfo : data) {
+//            System.out.println("originWdInfo = " + originWdInfo);
+//        }
+//    }
 
     @Test
     public void pointTest(){