Ver Fonte

优化标签分类

JensionDzero há 1 ano atrás
pai
commit
35624b0aa2

+ 3 - 1
benyun-core/src/main/java/com/ruoyi/benyun/init/BenyunCoreInit.java

@@ -41,7 +41,9 @@ public class BenyunCoreInit {
 
     @Bean("executor")
     public ExecutorService getExecutor() {
-        return Executors.newFixedThreadPool(10);
+        return new ThreadPoolExecutor(0, 8,
+            60L, TimeUnit.SECONDS,
+            new SynchronousQueue<Runnable>());
     }
 
 

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

@@ -83,7 +83,7 @@ public class ChannelAnalyseController {
 
     @RequestMapping("/tagAnalyse")
     public R tagAnalyse(ChannelMapAceeptVo channelMapAceeptVo){
-        int page = channelMapAceeptVo.getPageNum();
+        Integer page = channelMapAceeptVo.getPageNum() == null ? 1:channelMapAceeptVo.getPageNum();
         channelMapAceeptVo.setPageNum(0);
         String md5 = channelMapAceeptVo.getHash();
 

+ 2 - 2
ruoyi-demo/src/main/java/com/ruoyi/demo/entity/vo/ChannelMapAceeptVo.java

@@ -46,8 +46,8 @@ public class ChannelMapAceeptVo implements Serializable {
     /*
     * 分页字段(list、point接口)
     * */
-    int pageNum = 1;
-    int pageSize = 10;
+    Integer pageNum = 1;
+    Integer pageSize = 10;
 
 
     public String[] getChannel() {

+ 38 - 15
ruoyi-demo/src/main/java/com/ruoyi/demo/service/impl/ChannelAnalyseServiceImpl.java

@@ -20,10 +20,14 @@ import com.ruoyi.demo.service.ChannelAnalyseService;
 import com.ruoyi.demo.utils.InitMapUtil;
 import com.ruoyi.demo.utils.WdRedisStoreage;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
 import java.util.stream.Collectors;
 
 @Service
@@ -48,6 +52,10 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
     @Autowired
     private StoreWdDao storeWdDao;
 
+    @Autowired
+    @Qualifier("executor")
+    ExecutorService executor;
+
 
     @Override
     public HashMap cityTier(ChannelMapAceeptVo channelMapAceeptVo) {
@@ -103,29 +111,44 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
         List<WdInfo> queryWd = wdInfoDao.selectList(queryWrapper);
 
         //2.获取网点周边标签,并进行统计
-        int total = 0;
-        HashMap<String,Integer> hashMap = new HashMap<>();
+        Hashtable<String, Integer> hashtable = new Hashtable<>();
+        hashtable.put("total",0);
+        CompletableFuture<Void> future = null;
         for (WdInfo wdInfo : queryWd) {
-            List<String> wdTag = wdRedisStoreage.getWdTag(wdInfo);
-            if (wdTag == null)
-                continue;
-            total++;
-            for (String s : wdTag) {
-                Integer integer = hashMap.get(s);
-                if (integer == null)
-                    hashMap.put(s,1);
-                else
-                    hashMap.put(s,integer+1);
-            }
+            future = CompletableFuture.runAsync(()->{
+                List<String> wdTag = wdRedisStoreage.getWdTag(wdInfo);
+                if (wdTag != null){
+                    for (String s : wdTag) {
+                        s += "边";
+                        Integer integer = hashtable.get(s);
+                        if (integer == null)
+                            hashtable.put(s,1);
+                        else
+                            hashtable.put(s,integer+1);
+                        hashtable.put("total",hashtable.get("total")+1);
+                    }
+                }
+            },executor);
+        }
+        try {
+            future.get();
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        } catch (ExecutionException e) {
+            throw new RuntimeException(e);
         }
 
         //3.封装统计值
         HashMap<String, Object> result = new HashMap<>();
         List<TagAnalyse> list = new ArrayList<>();
-        for (String s : hashMap.keySet()) {
+        Integer total = hashtable.get("total");
+        for (String s : hashtable.keySet()) {
+            if (s.equals("total"))
+                continue;
+
             TagAnalyse tagAnalyse = new TagAnalyse();
             tagAnalyse.setName(s);
-            tagAnalyse.setCount(hashMap.get(s));
+            tagAnalyse.setCount(hashtable.get(s));
             BigDecimal bigDecimal = new BigDecimal((double) tagAnalyse.getCount() / total);
             double v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
             tagAnalyse.setRadio(v);

+ 6 - 0
ruoyi-demo/src/main/java/com/ruoyi/demo/utils/InitMapUtil.java

@@ -4,16 +4,22 @@ package com.ruoyi.demo.utils;
 import com.ruoyi.demo.constant.RedisInitContant;
 import com.ruoyi.demo.entity.ManageType;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 
 import java.util.List;
+import java.util.concurrent.*;
 
 @Component
 public class InitMapUtil {
     @Autowired
     RedisTemplate redisTemplate;
 
+    @Bean("executor")
+    public ExecutorService getExecutor() {
+        return new ThreadPoolExecutor(0,10,10,TimeUnit.SECONDS,new LinkedBlockingDeque<>(1000000),Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());
+    }
 
     public String getInitCityTierMap(String addrCode){
         return (String) redisTemplate.boundHashOps(RedisInitContant.INIT_CITY_TIER_MAP).get(addrCode.substring(0,4));