Pārlūkot izejas kodu

完成标签等级统计(v4.0)

JensionDzero 1 gadu atpakaļ
vecāks
revīzija
ac3076b7af

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

@@ -4,6 +4,7 @@ import com.benyun.core.constant.RedisContant;
 import com.benyun.core.entity.Brand;
 import com.benyun.core.entity.bo.WdCount;
 import com.benyun.core.entity.vo.ChannelAnalyseAceeptVo;
+import com.benyun.core.entity.vo.ChannelMapAceeptVo;
 import com.benyun.core.service.ChannelAnalyseService;
 import com.github.pagehelper.PageInfo;
 import com.ruoyi.common.core.domain.R;
@@ -47,4 +48,16 @@ public class ChannelAnalyseController {
         PageInfo<Brand> brandPageInfo = channelAnalyseService.brandList(channelAnalyseAceeptVo);
         return R.ok(brandPageInfo);
     }
+
+    @RequestMapping("/tagAnalyse")
+    public R tagAnalyse(ChannelMapAceeptVo channelMapAceeptVo){
+        HashMap<String, Object> hashMap = channelAnalyseService.tagAnalyse(channelMapAceeptVo);
+        return R.ok(hashMap);
+    }
+
+//    @RequestMapping("/businessAnalyse")
+//    public R businessAnalyse(ChannelMapAceeptVo channelMapAceeptVo){
+//        channelAnalyseService.businessAnalyse(channelMapAceeptVo);
+//        return R.ok();
+//    }
 }

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

@@ -114,17 +114,19 @@ public class ChannelMapController {
         QueryWrapper<AttentionPool> queryWrapper1 = new QueryWrapper<>();
         queryWrapper1.select("wd_id");
         queryWrapper1.in("wd_id",collect);
-        List<AttentionPool> attentionPools = attentionPoolDao.selectList(queryWrapper1);
-        List<String> collect1 = attentionPools.stream().map(attentionPool -> {
-            return attentionPool.getWdId();
-        }).collect(Collectors.toList());
-
-        for (WdTopologicalInfoBo wdTopologicalInfoBo : wdTopologicalInfoBos) {
-            boolean contains = collect1.contains(wdTopologicalInfoBo.getCenterWdId());
-            if (contains)
-                wdTopologicalInfoBo.setAttention(1);
-            else
-                wdTopologicalInfoBo.setAttention(0);
+        if(collect.size() > 0){
+            List<AttentionPool> attentionPools = attentionPoolDao.selectList(queryWrapper1);
+            List<String> collect1 = attentionPools.stream().map(attentionPool -> {
+                return attentionPool.getWdId();
+            }).collect(Collectors.toList());
+
+            for (WdTopologicalInfoBo wdTopologicalInfoBo : wdTopologicalInfoBos) {
+                boolean contains = collect1.contains(wdTopologicalInfoBo.getCenterWdId());
+                if (contains)
+                    wdTopologicalInfoBo.setAttention(1);
+                else
+                    wdTopologicalInfoBo.setAttention(0);
+            }
         }
     }
 

+ 4 - 2
benyun-core/src/main/java/com/benyun/core/entity/Brand.java

@@ -31,7 +31,7 @@ public class Brand {
     private Float perCapitaConsumption;
     @TableField("comment_count")
     private Long commentCount;
-    @TableField("socre")
+    @TableField("score")
     private Float score;
     @TableField("menu_info")
     private String menuInfo;
@@ -41,13 +41,15 @@ public class Brand {
     private String contact;
     @TableField("telephone")
     private String telephone;
-    @TableField("create_data")
+    @TableField("create_date")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @JsonSerialize(using = LocalDateTimeSerializer.class)
     @JsonDeserialize(using = LocalDateTimeDeserializer.class)
     private LocalDateTime createDate;
     @TableField("audit")
     private Long audit;
+    @TableField("collect_user_id")
+    private String collectUserId;
     @TableField("collect_person")
     private String collectPerson;
     @TableField("collect_time")

+ 2 - 0
benyun-core/src/main/java/com/benyun/core/entity/EnterpriseWd.java

@@ -12,4 +12,6 @@ public class EnterpriseWd {
     private String wdId;
     @TableField("enterprise_usci")
     private String enterpriseUsci;
+
+
 }

+ 11 - 0
benyun-core/src/main/java/com/benyun/core/entity/vo/TagAnalyse.java

@@ -0,0 +1,11 @@
+package com.benyun.core.entity.vo;
+
+import lombok.Data;
+
+@Data
+public class TagAnalyse {
+    String name ;
+    Integer count;
+
+    double radio;
+}

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

@@ -3,6 +3,7 @@ package com.benyun.core.service;
 import com.benyun.core.entity.Brand;
 import com.benyun.core.entity.CityTierBody;
 import com.benyun.core.entity.vo.ChannelAnalyseAceeptVo;
+import com.benyun.core.entity.vo.ChannelMapAceeptVo;
 import com.github.pagehelper.PageInfo;
 import com.ruoyi.common.core.domain.R;
 
@@ -14,4 +15,7 @@ public interface ChannelAnalyseService {
 
     PageInfo<Brand> brandList(ChannelAnalyseAceeptVo channelAnalyseAceeptVo);
 
+    HashMap<String,Object> tagAnalyse(ChannelMapAceeptVo channelMapAceeptVo);
+
+    void businessAnalyse(ChannelMapAceeptVo channelMapAceeptVo);
 }

+ 159 - 7
benyun-core/src/main/java/com/benyun/core/service/impl/ChannelAnalyseServiceImpl.java

@@ -3,20 +3,20 @@ package com.benyun.core.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.benyun.core.dao.BrandMapper;
 import com.benyun.core.dao.WdInfoDao;
-import com.benyun.core.entity.Brand;
-import com.benyun.core.entity.CityTierBody;
-import com.benyun.core.entity.TopologicalStoreWd;
-import com.benyun.core.entity.WdInfo;
+import com.benyun.core.dao.WdTopologicalInfoDao;
+import com.benyun.core.entity.*;
 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.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.origin.Origin;
 import org.springframework.stereotype.Service;
 
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
 
 @Service
 public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
@@ -31,6 +31,13 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
     @Autowired
     BrandMapper brandMapper;
 
+    @Autowired
+    WdTopologicalInfoDao wdTopologicalInfoDao;
+
+    @Autowired
+    @Qualifier("typeByMap")
+    private HashMap<String,String> typeByMap;
+
     @Override
     public HashMap cityTier(ChannelAnalyseAceeptVo channelAnalyseAceeptVo) {
         HashMap<String,Long> result = new HashMap<>();
@@ -73,8 +80,153 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
     @Override
     public PageInfo<Brand> brandList(ChannelAnalyseAceeptVo channelAnalyseAceeptVo) {
         PageHelper.startPage(channelAnalyseAceeptVo.getPageNum(),channelAnalyseAceeptVo.getPageSize());
-        List<Brand> brands = brandMapper.searchList(channelAnalyseAceeptVo.getSearchText());
+        String text = null;
+        if(channelAnalyseAceeptVo.getSearchText() != null)
+            text = channelAnalyseAceeptVo.getSearchText();
+        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;
+    }
+
+    @Override
+    public void businessAnalyse(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.select("wd_id");
+        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.like("wd_name", channelMapAceeptVo.getSearchText());
+            });
+        }
+    }
 }

+ 2 - 0
benyun-core/src/main/java/com/benyun/core/service/impl/ChannelMapServiceImpl.java

@@ -224,6 +224,8 @@ public class ChannelMapServiceImpl implements ChannelMapService {
             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)

+ 1 - 1
benyun-core/src/main/resources/application.yaml

@@ -10,7 +10,7 @@ server:
 # 数据源配置
 spring:
   profiles:
-    active: prod
+    active: dev
   application:
     name: bailian-ai #当前服务的名称
 

+ 15 - 3
benyun-core/src/test/java/com/benyun/core/BenyunCoreApplicationTests.java

@@ -3,14 +3,26 @@ package com.benyun.core;
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.SpringBootTest;
 
+import java.math.BigDecimal;
+import java.util.Random;
+
 @SpringBootTest
 class BenyunCoreApplicationTests {
 
     @Test
     void contextLoads() {
-        String str = "xx:xx:";
-        String[] split = str.split(":");
-        System.out.println(split.length);
+//        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);
+
     }
 
 }