JensionDzero 1 жил өмнө
parent
commit
976bfcb026

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

@@ -34,6 +34,10 @@ public class RedisContant {
     public static String CHANNEL_ANALYSE_CITYTIER = "channel_analyse_cityiter";
     public static int CHANNEL_ANALYSE_CITYTIER_TIME = 60*8;
 
+    public static String CHANNEL_ANALYSE_TAG_ANLYSE = "channel_analyse_tag_anlyse";
+
+    public static int CHANNEL_ANALYSE_TAG_ANLYSE_TIME = 60*8;
+
     public static String TOPOLOGICAL_COMMON_MAP = "topological_common_map";
     public static int TOPOLOGICAL_COMMON_MAP_TIME = 60*8;
 }

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

@@ -5,6 +5,7 @@ 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.entity.vo.TagAnalyse;
 import com.benyun.core.service.ChannelAnalyseService;
 import com.github.pagehelper.PageInfo;
 import com.ruoyi.common.core.domain.R;
@@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.concurrent.TimeUnit;
 
 @RestController
@@ -51,8 +53,29 @@ public class ChannelAnalyseController {
 
     @RequestMapping("/tagAnalyse")
     public R tagAnalyse(ChannelMapAceeptVo channelMapAceeptVo){
+        int page = channelMapAceeptVo.getPageNum();
+        channelMapAceeptVo.setPageNum(0);
+        String md5 = channelMapAceeptVo.getHash();
+
+        //2.查看redis中是否存在有缓存
+        HashMap<String, Object> result = new HashMap<>();
+        HashMap<String,Object> wdCount = (HashMap<String,Object>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_TAG_ANLYSE).get(md5);
+        if (wdCount != null) {
+            result.put("data",(List<TagAnalyse>) wdCount.get(page + ""));
+            result.put("pages",(int)wdCount.get("pages"));
+            result.put("total",(int)wdCount.get("total"));
+            return R.ok(result);
+        }
         HashMap<String, Object> hashMap = channelAnalyseService.tagAnalyse(channelMapAceeptVo);
-        return R.ok(hashMap);
+
+        //4.保存到redis中
+        redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_TAG_ANLYSE).put(md5,hashMap);
+        redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_TAG_ANLYSE,RedisContant.CHANNEL_ANALYSE_TAG_ANLYSE_TIME, TimeUnit.MINUTES); //30分钟
+
+        result.put("data",(List<TagAnalyse>) hashMap.get(page + ""));
+        result.put("pages",(int)hashMap.get("pages"));
+        result.put("total",(int)hashMap.get("total"));
+        return R.ok(result);
     }
 
 //    @RequestMapping("/businessAnalyse")

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

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

+ 5 - 5
benyun-core/src/main/java/com/benyun/core/controller/TopologicalBuildWdController.java

@@ -29,13 +29,13 @@ public class TopologicalBuildWdController {
     RedisTemplate redisTemplate;
 
     @RequestMapping("/buildingLevel")
-    public R buildingLevel(@Validated(value = {TopologicalWdGroup.class}) TopologicalWdAceeptVo topologicalWdAceeptVo){
+    public R buildingLevel(@Validated(value = {TopologicalWdListGroup.class}) TopologicalWdAceeptVo topologicalWdAceeptVo){
         String md5 = topologicalWdAceeptVo.getHash();
         //2.查看redis中是否存在有缓存
-//        List<BuildWdCategoryCount> wdCount = (List<BuildWdCategoryCount>) redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_BUILD_WD_CATEGORY).get(md5);
-//        if (wdCount != null) {
-//            return R.ok(wdCount);
-//        }
+        List<BuildWdCategoryCount> wdCount = (List<BuildWdCategoryCount>) redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_BUILD_WD_CATEGORY).get(md5);
+        if (wdCount != null) {
+            return R.ok(wdCount);
+        }
 
         List<BuildWdCategoryCount> list = topologicalBuildWdSerevice.buildingLevel(topologicalWdAceeptVo);
 

+ 1 - 0
benyun-core/src/main/java/com/benyun/core/controller/TopologicalCommonController.java

@@ -53,4 +53,5 @@ public class TopologicalCommonController {
 
         return R.ok(map);
     }
+
 }

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

@@ -29,6 +29,8 @@ public class ChannelMapAceeptVo {
 
     String orderby = ""; //排序字段,(list接口)
 
+    int size = 15; //tag分析时候用
+
     /*
     * 分页字段(list、point接口)
     * */

+ 5 - 2
benyun-core/src/main/java/com/benyun/core/entity/vo/TagAnalyse.java

@@ -2,10 +2,13 @@ package com.benyun.core.entity.vo;
 
 import lombok.Data;
 
+import java.io.Serializable;
+
 @Data
-public class TagAnalyse {
+public class TagAnalyse implements Serializable {
     String name ;
     Integer count;
-
     double radio;
+
+
 }

+ 164 - 63
benyun-core/src/main/java/com/benyun/core/service/impl/ChannelAnalyseServiceImpl.java

@@ -26,7 +26,7 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
 
     @Autowired
     @Qualifier("cityTierMap")
-    HashMap<String,String> cityTierMap;
+    HashMap<String, String> cityTierMap;
 
     @Autowired
     BrandMapper brandMapper;
@@ -36,25 +36,25 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
 
     @Autowired
     @Qualifier("typeByMap")
-    private HashMap<String,String> typeByMap;
+    private HashMap<String, String> typeByMap;
 
     @Override
     public HashMap cityTier(ChannelAnalyseAceeptVo channelAnalyseAceeptVo) {
-        HashMap<String,Long> result = new HashMap<>();
-        result.put("一线",0L);
-        result.put("新一线",0L);
-        result.put("二线",0L);
-        result.put("三线",0L);
-        result.put("四线",0L);
-        result.put("五线",0L);
-        result.put("其他",0L);
+        HashMap<String, Long> result = new HashMap<>();
+        result.put("一线", 0L);
+        result.put("新一线", 0L);
+        result.put("二线", 0L);
+        result.put("三线", 0L);
+        result.put("四线", 0L);
+        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("")){
+        if (channelAnalyseAceeptVo.getSearchText() != null && !channelAnalyseAceeptVo.getSearchText().equals("")) {
             queryWrapper.and(wdInfoQueryWrapper -> {
-                wdInfoQueryWrapper.like("wd_name",channelAnalyseAceeptVo.getSearchText());
+                wdInfoQueryWrapper.like("wd_name", channelAnalyseAceeptVo.getSearchText());
             });
         }
 
@@ -62,15 +62,14 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
         System.out.println(wdInfos.size());
         for (WdInfo wdInfo : wdInfos) {
             String addrCode = wdInfo.getAddrCode();
-            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);
+            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);
         }
 
 
@@ -79,17 +78,115 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
 
     @Override
     public PageInfo<Brand> brandList(ChannelAnalyseAceeptVo channelAnalyseAceeptVo) {
-        PageHelper.startPage(channelAnalyseAceeptVo.getPageNum(),channelAnalyseAceeptVo.getPageSize());
-        String text = null;
-        if(channelAnalyseAceeptVo.getSearchText() != null)
+        PageHelper.startPage(channelAnalyseAceeptVo.getPageNum(), channelAnalyseAceeptVo.getPageSize());
+        String text = "";
+        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 HashMap<String,Object> tagAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
+    public HashMap<String, Object> tagAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
         //1.根据不同级别得到地区码
         List<String> addrCodeList = new ArrayList<>();
         if ("province".equals(channelMapAceeptVo.getRankType())) {
@@ -116,8 +213,8 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
 
 
         //2.根据地区前缀找到所有的网点
-        QueryWrapper<WdTopologicalInfo> queryWrapper = new QueryWrapper<>();
-        queryWrapper.in("center_wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
+        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.in("wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
             for (String s : addrCodeList) {
                 originWdInfoQueryWrapper.likeRight("addr_code", s).or();
             }
@@ -125,53 +222,46 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
 
         if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText().trim().equals("")) {
             queryWrapper.and(originWdInfoQueryWrapper -> {
-                originWdInfoQueryWrapper.like("center_wd_name", channelMapAceeptVo.getSearchText());
+                originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText());
             });
         }
 
-        queryWrapper.and(wdTopologicalInfoQueryWrapper -> {
-            wdTopologicalInfoQueryWrapper.eq("radius",1000); //1km内算附近
-        });
-        List<WdTopologicalInfo> originWdInfos = wdTopologicalInfoDao.selectList(queryWrapper);
+//        queryWrapper.and(wdTopologicalInfoQueryWrapper -> {
+//            wdTopologicalInfoQueryWrapper.eq("radius", 1000); //1km内算附近
+//        });
+        List<WdInfo> wdInfos = wdInfoDao.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++;
-                    }
+        Integer total = 0;
+        HashMap<String, Integer> hashMap = new HashMap<>();
+        for (WdInfo wdInfo : wdInfos) {
+            String tag = wdInfo.getTypeNameBy();
+            if (tag != null && !tag.equals("")) {
+                Integer integer = hashMap.get(tag);
+                if (integer == null) {
+                    hashMap.put(tag, 1);
+                } else {
+                    hashMap.put(tag, integer + 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);
+            String[] split = s.split(":");
+            if (split.length == 3)
+                tagAnalyse.setName(split[2]);
+            else if (split.length == 2)
+                tagAnalyse.setName(split[1]);
+            else if (split.length == 1)
+                tagAnalyse.setName(split[0]);
+            else
+                tagAnalyse.setName("");
             tagAnalyse.setCount(hashMap.get(s));
-            tagAnalyse.setRadio((double)tagAnalyse.getCount()/total);
+            tagAnalyse.setRadio((double) tagAnalyse.getCount() / total);
             list.add(tagAnalyse);
         }
 
@@ -182,8 +272,17 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
             }
         });
 
-        result.put("total",total);
-        result.put("data",list);
+        int i = 1;
+        int start = 0,end = 6;
+        while(start<list.size()){
+            if(end>=list.size())
+                end = list.size();
+            result.put(""+i++,new ArrayList(list.subList(start,end)));
+            start=end;
+            end+=6;
+        }
+        result.put("pages",i);
+        result.put("total",list.size());
         return result;
     }
 
@@ -228,5 +327,7 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
                 originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText());
             });
         }
+
+
     }
 }