Pārlūkot izejas kodu

Merge branch 'master' of http://47.107.53.207:3000/traineeCoder001/Bailian-Al

# Conflicts:
#	benyun-core/src/main/java/com/benyun/core/service/impl/ChannelAnalyseServiceImpl.java
JensionDzero 1 gadu atpakaļ
vecāks
revīzija
bb52257d46

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

@@ -40,4 +40,7 @@ public class RedisContant {
 
     public static String TOPOLOGICAL_COMMON_MAP = "topological_common_map";
     public static int TOPOLOGICAL_COMMON_MAP_TIME = 60*8;
+
+    public static String CHANNEL_ANALYSE_BRANDLIST = "channel_analyse_brandList";
+    public static int CHANNEL_ANALYSE_BRANDLIST_TIME = 60*8;
 }

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

@@ -47,7 +47,19 @@ public class ChannelAnalyseController {
 
     @RequestMapping("/brandList")
     public R brandList(ChannelAnalyseAceeptVo channelAnalyseAceeptVo){
+        String md5 = channelAnalyseAceeptVo.getHash();
+
+        //2.查看redis中是否存在有缓存
+        PageInfo<Brand> wdCount = (PageInfo<Brand>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_BRANDLIST).get(md5);
+        if (wdCount != null) {
+            return R.ok(wdCount);
+        }
+
         PageInfo<Brand> brandPageInfo = channelAnalyseService.brandList(channelAnalyseAceeptVo);
+
+        //4.保存到redis中
+        redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_BRANDLIST).put(md5,brandPageInfo);
+        redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_BRANDLIST,RedisContant.CHANNEL_ANALYSE_BRANDLIST_TIME, TimeUnit.MINUTES); //30分钟
         return R.ok(brandPageInfo);
     }
 

+ 21 - 22
benyun-core/src/main/java/com/benyun/core/service/impl/ChannelAnalyseServiceImpl.java

@@ -27,7 +27,7 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
 
     @Autowired
     @Qualifier("cityTierMap")
-    HashMap<String,String> cityTierMap;
+    HashMap<String, String> cityTierMap;
 
     @Autowired
     BrandMapper brandMapper;
@@ -37,25 +37,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());
             });
         }
 
@@ -63,15 +63,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);
         }
 
 
@@ -89,7 +88,7 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
         return pageInfo;
     }
 
-//    @Override
+    //    @Override
 //    public HashMap<String,Object> tagAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
 //        //1.根据不同级别得到地区码
 //        List<String> addrCodeList = new ArrayList<>();

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

@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -148,8 +149,11 @@ public class ChannelMapServiceImpl implements ChannelMapService {
 
         //5.计算radio
         for (WdCountBody wdCountBody : result) {
-            if (total != 0)
-                wdCountBody.setRadio((float) wdCountBody.getCount() / total);
+            if (total != 0){
+                BigDecimal bigDecimal = new BigDecimal((float) wdCountBody.getCount() / total);
+                float v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
+                wdCountBody.setRadio(v);
+            }
             else
                 wdCountBody.setRadio(0.0f);
         }