Explorar el Código

渠道分析、点位营销优化

JensionDzero hace 1 año
padre
commit
707175335c
Se han modificado 21 ficheros con 232 adiciones y 124 borrados
  1. 31 23
      benyun-core/src/main/java/com/ruoyi/benyun/config/QuartzConfig.java
  2. 1 1
      benyun-core/src/main/java/com/ruoyi/benyun/init/BenyunCoreInit.java
  3. 4 1
      benyun-core/src/main/java/com/ruoyi/benyun/job/AnalyseJob.java
  4. 3 2
      benyun-core/src/main/java/com/ruoyi/benyun/job/WriteRedisJob.java
  5. 4 3
      benyun-core/src/main/java/com/ruoyi/benyun/service/impl/AttentionPoolServiceImpl.java
  6. 2 1
      benyun-core/src/main/java/com/ruoyi/benyun/service/impl/BusinessOpportunitiesServiceImpl.java
  7. 0 1
      benyun-core/src/main/java/com/ruoyi/benyun/service/impl/ChannelMapServiceImpl.java
  8. 3 2
      benyun-core/src/main/java/com/ruoyi/benyun/service/impl/WdInfoServiceImpl.java
  9. 30 23
      benyun-core/src/main/java/com/ruoyi/benyun/utils/WdRedisStoreage.java
  10. 9 1
      benyun-core/src/test/java/com/ruoyi/benyun/BenyunCoreApplicationTests.java
  11. 1 1
      ruoyi-admin/Dockerfile
  12. 3 2
      ruoyi-admin/src/main/resources/application-prod.yml
  13. 1 0
      ruoyi-demo/src/main/java/com/ruoyi/demo/config/RedisConfiguration.java
  14. 1 1
      ruoyi-demo/src/main/java/com/ruoyi/demo/constant/RedisContant.java
  15. 8 8
      ruoyi-demo/src/main/java/com/ruoyi/demo/controller/ChannelAnalyseController.java
  16. 12 0
      ruoyi-demo/src/main/java/com/ruoyi/demo/entity/bo/Histogram.java
  17. 3 2
      ruoyi-demo/src/main/java/com/ruoyi/demo/init/BenyunCoreInit.java
  18. 4 0
      ruoyi-demo/src/main/java/com/ruoyi/demo/mapper/StoreWdDao.java
  19. 99 52
      ruoyi-demo/src/main/java/com/ruoyi/demo/service/impl/ChannelAnalyseServiceImpl.java
  20. 5 0
      ruoyi-demo/src/main/java/com/ruoyi/demo/utils/WdRedisStoreage.java
  21. 8 0
      ruoyi-demo/src/main/resources/mapper/demo/StoreWdDaoMapper.xml

+ 31 - 23
benyun-core/src/main/java/com/ruoyi/benyun/config/QuartzConfig.java

@@ -2,20 +2,24 @@ package com.ruoyi.benyun.config;
 
 
 import com.ruoyi.benyun.job.AnalyseJob;
+import com.ruoyi.benyun.job.WriteRedisJob;
 import lombok.extern.slf4j.Slf4j;
 import org.quartz.*;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
+import java.time.ZoneId;
+import java.util.TimeZone;
+
 /*
-* 定时器:分析网点数据
-* */
+ * 定时器:分析网点数据
+ * */
 @Slf4j
 @Configuration
 public class QuartzConfig {
     // 创建一个封装Job对象的类型JobDetall,并放入Spring容器中
     @Bean
-    public JobDetail AnalyseJobDetail(){
+    public JobDetail AnalyseJobDetail() {
         log.info("AnalyseJobDetail");
 
         return JobBuilder.newJob(AnalyseJob.class) //newJob方法就是在绑定要运行的Job接口实现。
@@ -24,21 +28,12 @@ public class QuartzConfig {
             .build();
     }
 
-    @Bean
-    public JobDetail WriteRedisJobDetail(){
-        log.info("WriteRedisJobDetail");
-
-        return JobBuilder.newJob(AnalyseJob.class) //newJob方法就是在绑定要运行的Job接口实现。
-            .withIdentity("writeRedisJobDetail") //给当前JobDetail对象取名字
-            .storeDurably() //及时没有触发器绑定当前JobDetail对象,也不会被删除
-            .build();
-    }
-
     //触发器声明,设置job的运行时机,并放入Spring容器中
     @Bean
-    public Trigger AnalyseTrigger(){
+    public Trigger AnalyseTrigger() {
         //定义Cron表达式
-        CronScheduleBuilder cron  = CronScheduleBuilder.cronSchedule("0 0 13 6 10 ? ");
+        CronScheduleBuilder cron = CronScheduleBuilder.cronSchedule("0 0 0 18 10 ? ");
+        cron.inTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
 
         return TriggerBuilder
             .newTrigger()
@@ -49,16 +44,29 @@ public class QuartzConfig {
     }
 
     @Bean
-    public Trigger WriteRedisTrigger(){
-        //定义Cron表达式
-        CronScheduleBuilder cron  = CronScheduleBuilder.cronSchedule("0 0 13 * * ? *");
+    public JobDetail WriteRedisJobDetail() {
+        log.info("WriteRedisJobDetail");
 
-        return TriggerBuilder
-            .newTrigger()
-            .forJob(WriteRedisJobDetail()) //绑定要运行的JobDetail对象,这是得到的是Spring容器里的JobDetail
-            .withIdentity("writeRedisTrigger") //给当前Trigger对象起名字,名字任意
-            .withSchedule(cron) //绑定cron表达式
+        return JobBuilder.newJob(WriteRedisJob.class) //newJob方法就是在绑定要运行的Job接口实现。
+            .withIdentity("writeRedisJobDetail") //给当前JobDetail对象取名字
+            .storeDurably() //及时没有触发器绑定当前JobDetail对象,也不会被删除
             .build();
     }
 
+
+
+//    @Bean
+//    public Trigger WriteRedisTrigger(){
+//        //定义Cron表达式
+//        CronScheduleBuilder cron  = CronScheduleBuilder.cronSchedule("0 0 0 18 10 ? ");
+//        cron.inTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
+//
+//        return TriggerBuilder
+//            .newTrigger()
+//            .forJob(WriteRedisJobDetail()) //绑定要运行的JobDetail对象,这是得到的是Spring容器里的JobDetail
+//            .withIdentity("writeRedisTrigger") //给当前Trigger对象起名字,名字任意
+//            .withSchedule(cron) //绑定cron表达式
+//            .build();
+//    }
+
 }

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

@@ -43,7 +43,7 @@ public class BenyunCoreInit {
     public ExecutorService getExecutor() {
         return new ThreadPoolExecutor(0, 8,
             60L, TimeUnit.SECONDS,
-            new SynchronousQueue<Runnable>());
+            new LinkedBlockingQueue<Runnable>());
     }
 
 

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

@@ -21,6 +21,9 @@ public class AnalyseJob implements Job {
 
     @Override
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
-        wdRedisStoreage.writeWdGeoRedis1("2023-09-25");
+        System.out.println("大统计.....");
+        wdRedisStoreage.writeWdGeoRedis2(new String[]{"1"});
+        wdRedisStoreage.writeWdGeoRedis2(new String[]{"2","3","5"});
+        System.out.println("大统计.....结束");
     }
 }

+ 3 - 2
benyun-core/src/main/java/com/ruoyi/benyun/job/WriteRedisJob.java

@@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.time.LocalDateTime;
+import java.time.ZoneId;
 
 @Slf4j
 @Component
@@ -24,9 +25,9 @@ public class WriteRedisJob implements Job {
 
     @Override
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
-        LocalDateTime now = LocalDateTime.now();
+        LocalDateTime now = LocalDateTime.now(ZoneId.of("Asia/Shanghai"));
         LocalDateTime localDateTime = now.plusDays(-1);
-        log.info("开始载入redis:"+localDateTime.toString());
+        log.info("开始载入redis:" + localDateTime.toString());
         wdRedisStoreage.writeWdGeoRedis1(localDateTime.toString());
     }
 }

+ 4 - 3
benyun-core/src/main/java/com/ruoyi/benyun/service/impl/AttentionPoolServiceImpl.java

@@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.time.LocalDateTime;
+import java.time.ZoneId;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
@@ -81,7 +82,7 @@ public class AttentionPoolServiceImpl implements AttentionPoolService {
         clue.setTelephone(turnVo.getTelephone());
         clue.setFollowUpCount(0);
         clue.setUserId(userId);
-        clue.setCreateTime(LocalDateTime.now());
+        clue.setCreateTime(LocalDateTime.now(ZoneId.of("Asia/Shanghai")));
         return businessOpportunitiesDao.insert(clue);
     }
 
@@ -107,7 +108,7 @@ public class AttentionPoolServiceImpl implements AttentionPoolService {
         pool.setWdName("");
         pool.setWdAddrInfo("");
         pool.setUserId(userId);
-        pool.setAttentionTime(LocalDateTime.now());
+        pool.setAttentionTime(LocalDateTime.now(ZoneId.of("Asia/Shanghai")));
         return attentionPoolDao.insert(pool);
     }
 
@@ -164,7 +165,7 @@ public class AttentionPoolServiceImpl implements AttentionPoolService {
             pool.setBrandName("");
         }
         pool.setUserId(userId);
-        pool.setAttentionTime(LocalDateTime.now());
+        pool.setAttentionTime(LocalDateTime.now(ZoneId.of("Asia/Shanghai")));
         return attentionPoolDao.insert(pool);
     }
 

+ 2 - 1
benyun-core/src/main/java/com/ruoyi/benyun/service/impl/BusinessOpportunitiesServiceImpl.java

@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
+import java.time.ZoneId;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
@@ -83,7 +84,7 @@ public class BusinessOpportunitiesServiceImpl implements BusinessOpportunitiesSe
         record.setFollowPerson(addVo.getPerson());
         record.setFollowWay(addVo.getWay());
         record.setUserId(userId);
-        record.setFollowTime(LocalDateTime.now());
+        record.setFollowTime(LocalDateTime.now(ZoneId.of("Asia/Shanghai")));
         if (followUpDao.insert(record) == 1){
             return businessOpportunitiesDao.updateFollowUpCountByClueIdAndUserId(clue.getClueId(), clue.getFollowUpCount() + 1, userId);
         }

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

@@ -219,7 +219,6 @@ public class ChannelMapServiceImpl implements ChannelMapService {
     }
 
 
-    //TODO 待测试(redis版本)
     @Override
     public HashMap list(ChannelMapAceeptVo channelMapAceeptVo) {
         //1.根据条件获取网点

+ 3 - 2
benyun-core/src/main/java/com/ruoyi/benyun/service/impl/WdInfoServiceImpl.java

@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
+import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.List;
@@ -31,7 +32,7 @@ public class WdInfoServiceImpl implements WdInfoService {
         List<String> addrs = new ArrayList<>();
         List<String> times = new ArrayList<>();
         for (int i = 0; i < 12; i++){
-            times.add(LocalDateTime.now().plusMonths(-i).format(DateTimeFormatter.ofPattern("yyyy-MM")));
+            times.add(LocalDateTime.now(ZoneId.of("Asia/Shanghai")).plusMonths(-i).format(DateTimeFormatter.ofPattern("yyyy-MM")));
         }
         if (addrCodes != null){
             for (String s : addrCodes){
@@ -55,7 +56,7 @@ public class WdInfoServiceImpl implements WdInfoService {
         List<WdOpcloseVo> vos = new ArrayList<>();
         if (addrCodes != null){
             for (String s : addrCodes){
-                WdOpclose opclose = wdOpcloseDao.selectListByAddrCodeAndWdTypeCodes(categoryUtil.whatis(s), wdTypeCodes, LocalDateTime.now().plusMonths(-1));
+                WdOpclose opclose = wdOpcloseDao.selectListByAddrCodeAndWdTypeCodes(categoryUtil.whatis(s), wdTypeCodes, LocalDateTime.now(ZoneId.of("Asia/Shanghai")).plusMonths(-1));
                 if (opclose != null){
                     WdOpcloseVo vo = new WdOpcloseVo(s,opclose);
                     vo.setAddrName(categoryUtil.addrMap.get(s));

+ 30 - 23
benyun-core/src/main/java/com/ruoyi/benyun/utils/WdRedisStoreage.java

@@ -34,6 +34,8 @@ public class WdRedisStoreage {
     private ExecutorService executorService;
 
 
+
+
     @Autowired
     WriteService writeService;
 
@@ -50,6 +52,11 @@ public class WdRedisStoreage {
         return tag;
     }
 
+    public  List<List<String>> getWdTagList(List<String> key){
+        List<List<String>>  list = redisTemplate.opsForValue().multiGet(key);
+        return list;
+    }
+
     /***
      * 分析网点周边标签,并把分析结果存入redis(默认范围:1km)
      * @param wdInfo 中心网点信息
@@ -71,6 +78,9 @@ public class WdRedisStoreage {
                 .in("wd_id",aroundWdId)
                     .groupBy("type_name_by");
         List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
+        //释放内存
+        aroundWdId = null;
+        aroundWdId = null;
 
         //3. 打标签
         List<String> tag = new ArrayList<>();
@@ -85,6 +95,7 @@ public class WdRedisStoreage {
             }
         });
         redisTemplate.boundValueOps(RedisContant.WD_TAG+"_"+wdInfo.getWdId()).set(tag);
+
         return tag;
     }
 
@@ -191,6 +202,7 @@ public class WdRedisStoreage {
         long start = System.currentTimeMillis();
         System.out.println("开始将网点坐标存入redis");
         QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("wd_id","addr_code","lng","lat");
         queryWrapper.ge("collect_time",time);
 
         Hashtable<String,Integer> hashtable = new Hashtable<>();
@@ -206,44 +218,39 @@ public class WdRedisStoreage {
                 hashtable.put("total",hashtable.get("total")+1);
             },executorService));
         }
-        try {
-            CompletableFuture.allOf(completableFutureList.toArray(new CompletableFuture[0])).get();
-        } catch (InterruptedException e) {
-            throw new RuntimeException(e);
-        } catch (ExecutionException e) {
-            throw new RuntimeException(e);
-        }
+        CompletableFuture.allOf(completableFutureList.toArray(new CompletableFuture[0])).join();
         long end = System.currentTimeMillis();
         System.out.println("完成存入 "+(end-start)/(1000*60));
+
     }
 
-    private void writeWdGeoRedis2(){
-        //2.对所有网点坐标进行分析打标签
+    public void writeWdGeoRedis2(String[] wdTypeCodes){
+        //对所有网点坐标进行分析打标签
         long start = System.currentTimeMillis();
         System.out.println("开始打标签");
+
+        //开始
         QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
-        queryWrapper.in("wd_type_code", Arrays.asList("1"));
+        queryWrapper.select("wd_id","addr_code");
+        queryWrapper.in("wd_type_code", wdTypeCodes);
         List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
-        CompletableFuture<Void> future = null;
-        HashMap<String,Integer> hashMap = new HashMap<>();
-        hashMap.put("total",1);
+
+        ArrayList<CompletableFuture<Void>> list = new ArrayList<>();
+        Hashtable<String,Integer> hashtable = new Hashtable<>();
+        hashtable.put("total",1);
         for (WdInfo wdInfo : wdInfos) {
             //开启线程
-            future = CompletableFuture.runAsync(()->{
+            CompletableFuture<Void> future = CompletableFuture.runAsync(()->{
                 wdTagAnalyse(wdInfo);
-                System.out.println("进度:"+wdInfos.size()+"/"+hashMap.get("total"));
-                hashMap.put("total",hashMap.get("total")+1);
+                System.out.println("进度:"+wdInfos.size()+"/"+hashtable.get("total"));
+                hashtable.put("total",hashtable.get("total")+1);
             },executorService);
+            list.add(future);
         }
-        try {
-            future.get();
-        } catch (InterruptedException e) {
-            throw new RuntimeException(e);
-        } catch (ExecutionException e) {
-            throw new RuntimeException(e);
-        }
+        CompletableFuture.allOf(list.toArray(new CompletableFuture[list.size()])).join();
         long end = System.currentTimeMillis();
         System.out.println("完成打标签 "+(end-start)/(1000*60));
+
     }
 
 

+ 9 - 1
benyun-core/src/test/java/com/ruoyi/benyun/BenyunCoreApplicationTests.java

@@ -1,5 +1,6 @@
 package com.ruoyi.benyun;
 
+import com.ruoyi.benyun.constant.RedisContant;
 import com.ruoyi.benyun.mapper.WdInfoDao;
 import com.ruoyi.benyun.service.WriteService;
 import com.ruoyi.benyun.utils.WdRedisStoreage;
@@ -8,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 
 import java.time.LocalDateTime;
+import java.util.ArrayList;
 import java.util.List;
 
 @SpringBootTest
@@ -23,7 +25,13 @@ class BenyunCoreApplicationTests {
 
     @Test
     void contextLoads() {
-        //wdRedisStoreage.writeWdGeoRedis();
+        ArrayList<String> list = new ArrayList<>();
+        list.add(RedisContant.WD_TAG+"_"+"00003743d4b047aab0e8ab9481225fbf");
+        list.add(RedisContant.WD_TAG+"_"+"000040593b0e4c7f82b798d30604f350");
+        list.add(RedisContant.WD_TAG+"_"+"0000f8d2a49043cf8e4525241faf5fb9");
+        List<List<String>> wdTagList = wdRedisStoreage.getWdTagList(list);
+        System.out.println(wdTagList);
+
         //List<String> wdTag = wdRedisStoreage.getWdTag(null);
     }
 

+ 1 - 1
ruoyi-admin/Dockerfile

@@ -20,4 +20,4 @@ ENTRYPOINT ["java", \
             # 应用名称 如果想区分集群节点监控 改成不同的名称即可
 #            "-Dskywalking.agent.service_name=ruoyi-server", \
 #            "-javaagent:/ruoyi/skywalking/agent/skywalking-agent.jar", \
-            "-jar", "ruoyi-admin-plus.jar"]
+            "-Xmx10240m","-jar", "ruoyi-admin-plus.jar"]

+ 3 - 2
ruoyi-admin/src/main/resources/application-prod.yml

@@ -128,8 +128,9 @@ spring:
         max-wait: -1
         max-idle: 8
         enabled: true
+    timeout: 600000
 
-#redisson:
+#  #redisson:
 #  # redis key前缀
 #  keyPrefix:
 #  # 线程池数量
@@ -149,7 +150,7 @@ spring:
 #    # 连接空闲超时,单位:毫秒
 #    idleConnectionTimeout: 10000
 #    # 命令等待超时,单位:毫秒
-#    timeout: 3000
+#    timeout: 6000
 #    # 发布和订阅连接池大小
 #    subscriptionConnectionPoolSize: 50
 

+ 1 - 0
ruoyi-demo/src/main/java/com/ruoyi/demo/config/RedisConfiguration.java

@@ -43,6 +43,7 @@ public class RedisConfiguration {
         redisTemplate.setHashValueSerializer(valueSerializer());
 
         redisTemplate.setConnectionFactory(redisConnectionFactory);
+
         return redisTemplate;
     }
 

+ 1 - 1
ruoyi-demo/src/main/java/com/ruoyi/demo/constant/RedisContant.java

@@ -48,7 +48,7 @@ public class RedisContant {
 
     public static String CHANNEL_ANALYSE_TAG_ANLYSE = "channel_analyse_tag_anlyse";
 
-    public static int CHANNEL_ANALYSE_TAG_ANLYSE_TIME = 60*8;
+    public static int CHANNEL_ANALYSE_TAG_ANLYSE_TIME = 60*20;
 
     public static String CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE= "channel_analyse_business_status_analyse";
 

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

@@ -73,10 +73,10 @@ public class ChannelAnalyseController {
         String md5 = channelMapAceeptVo.getHash();
 
         //2.查看redis中是否存在有缓存
-        List<StoreWdCategoryCount> wdCount = (List<StoreWdCategoryCount>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_CATEGORY).get(md5);
-        if (wdCount != null) {
-            return R.ok(wdCount);
-        }
+//        List<StoreWdCategoryCount> wdCount = (List<StoreWdCategoryCount>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_CATEGORY).get(md5);
+//        if (wdCount != null) {
+//            return R.ok(wdCount);
+//        }
 
 
         List<StoreWdCategoryCount> category = channelAnalyseService.category(channelMapAceeptVo);
@@ -117,10 +117,10 @@ public class ChannelAnalyseController {
         String md5 = channelMapAceeptVo.getHash();
 
         //2.查看redis中是否存在有缓存
-        HashMap<String,Integer> wdCount = (HashMap<String,Integer>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE).get(md5);
-        if (wdCount != null) {
-            return R.ok(wdCount);
-        }
+//        HashMap<String,Integer> wdCount = (HashMap<String,Integer>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE).get(md5);
+//        if (wdCount != null) {
+//            return R.ok(wdCount);
+//        }
         HashMap<String,Integer> hashMap = channelAnalyseService.businessStatusAnalyse(channelMapAceeptVo);
 
         //4.保存到redis中

+ 12 - 0
ruoyi-demo/src/main/java/com/ruoyi/demo/entity/bo/Histogram.java

@@ -1,9 +1,21 @@
 package com.ruoyi.demo.entity.bo;
 
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
 @Data
 public class Histogram {
     private String name;
     private int count;
+
+    public Histogram(String name, int count) {
+        this.name = name;
+        this.count = count;
+    }
+
+    public Histogram() {
+
+    }
+
+
 }

+ 3 - 2
ruoyi-demo/src/main/java/com/ruoyi/demo/init/BenyunCoreInit.java

@@ -37,9 +37,10 @@ public class BenyunCoreInit {
 
     @Bean("executor")
     public ExecutorService getExecutor() {
-        return new ThreadPoolExecutor(0,10,10, TimeUnit.SECONDS,new LinkedBlockingDeque<>(1000000), Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());
+        return new ThreadPoolExecutor(0, 8,
+            60L, TimeUnit.SECONDS,
+            new LinkedBlockingQueue<Runnable>());
     }
-
     /**
      * HashMap<地区Code,城市等级>(redis版本)
      */

+ 4 - 0
ruoyi-demo/src/main/java/com/ruoyi/demo/mapper/StoreWdDao.java

@@ -15,4 +15,8 @@ public interface StoreWdDao extends BaseMapper<StoreWd> {
     List<StoreWd> perCapitaConsumpAnalyse(@Param(Constants.WRAPPER) QueryWrapper<WdInfo> queryWrapper);
 
     List<StoreWd> operateTimeAnalyse(@Param(Constants.WRAPPER) QueryWrapper<WdInfo> queryWrapper);
+
+    List<StoreWd> category(@Param(Constants.WRAPPER) QueryWrapper<WdInfo> queryWrapper);
+
+    List<StoreWd> businessStatusAnalyse(@Param(Constants.WRAPPER) QueryWrapper<WdInfo> queryWrapper);
 }

+ 99 - 52
ruoyi-demo/src/main/java/com/ruoyi/demo/service/impl/ChannelAnalyseServiceImpl.java

@@ -3,6 +3,7 @@ package com.ruoyi.demo.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.ruoyi.demo.constant.RedisContant;
 import com.ruoyi.demo.entity.Brand;
 import com.ruoyi.demo.entity.ManageType;
 import com.ruoyi.demo.entity.StoreWd;
@@ -116,37 +117,71 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
         QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
         queryWrapper.select("wd_id");
         assembleQueryWrapper(queryWrapper,channelMapAceeptVo);
+        queryWrapper.and(queryWrapper2 ->{
+            queryWrapper2.eq("deleted",0);
+        });
         List<WdInfo> queryWd = wdInfoDao.selectList(queryWrapper);
 
-        //2.获取网点周边标签,并进行统计
+        //2.获取周边标签
+        List<String> collect = queryWd.stream().map(item -> {
+            return RedisContant.WD_TAG + "_" + item.getWdId();
+        }).collect(Collectors.toList());
+
+        //切割获取redis数据
+        int split = 60000;
+        int splitCount = collect.size()/split;
+        int p1 = 0,p2 = split;
+        ArrayList<CompletableFuture<List<List<String>>>> splitList = new ArrayList<>();
+        for (int i=1;i<=splitCount;i++){
+            if (p2 > collect.size())
+                p2 = collect.size();
+            List<String> list2 = collect.subList(p1, p2);
+            CompletableFuture<List<List<String>>> future = CompletableFuture.supplyAsync(()->{
+                return wdRedisStoreage.getWdTagList(list2);
+            },executor);
+            splitList.add(future);
+            p1 = p2;
+            p2+=split;
+        }
+
+        //3.统计
         Hashtable<String, Integer> hashtable = new Hashtable<>();
         hashtable.put("total",0);
-        CompletableFuture<Void> future = null;
-        for (WdInfo wdInfo : queryWd) {
-            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);
+        ArrayList<CompletableFuture<Void>> list1 = new ArrayList<>();
+        for (CompletableFuture<List<List<String>>> listCompletableFuture : splitList) {
+            try {
+                List<List<String>> lists = listCompletableFuture.get();
+                for (List<String> list : lists) {
+                    if (list != null && !list.isEmpty()){
+                        CompletableFuture<Void> future = CompletableFuture.runAsync(()->{
+                            for (String s : list) {
+                                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);
+                        list1.add(future);
                     }
                 }
-            },executor);
-        }
-        try {
-            future.get();
-        } catch (InterruptedException e) {
-            throw new RuntimeException(e);
-        } catch (ExecutionException e) {
-            throw new RuntimeException(e);
+                CompletableFuture.allOf(list1.toArray(new CompletableFuture[list1.size()])).join();
+                lists = null;
+            } catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            } catch (ExecutionException e) {
+                throw new RuntimeException(e);
+            }
+
         }
 
-        //3.封装统计值
+        collect = null;
+        queryWd = null;
+
+
+        //4.封装统计值
         HashMap<String, Object> result = new HashMap<>();
         List<TagAnalyse> list = new ArrayList<>();
         Integer total = hashtable.get("total");
@@ -163,7 +198,7 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
             list.add(tagAnalyse);
         }
 
-        //4.对结果集进行排序
+        //5.对结果集进行排序
         Collections.sort(list, new Comparator<TagAnalyse>() {
             @Override
             public int compare(TagAnalyse o1, TagAnalyse o2) {
@@ -194,24 +229,18 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
         QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
         queryWrapper.select("wd_id");
         assembleQueryWrapper(queryWrapper,channelMapAceeptVo);
+        queryWrapper.and(queryWrapper2 ->{
+            queryWrapper2.eq("deleted",0);
+        });
 
         //门店
         queryWrapper.and(queryWrapper1 -> {
             queryWrapper1.eq("wd_type_code","1");
         });
-        List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
 
 
-        List<String> collect = wdInfos.stream().map(wdInfo -> {
-            return wdInfo.getWdId();
-        }).collect(Collectors.toList());
-        QueryWrapper<StoreWd> queryWrapper1 = new QueryWrapper<>();
-        queryWrapper1.select("manage_type_code","count(*) as comment_count")
-            .in("wd_id",collect)
-            .groupBy("manage_type_code");
-
         //5.查询周边网点结果,并统计
-        List<StoreWd> storeWds = storeWdDao.selectList(queryWrapper1);
+        List<StoreWd> storeWds = storeWdDao.category(queryWrapper);
         HashMap<String,StoreWdCategoryCount> hashMap = new HashMap<>();
         for (StoreWd wdInfo : storeWds) {
             if(wdInfo.getManageTypeCode() == null || wdInfo.getManageTypeCode().equals(""))
@@ -270,31 +299,37 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
     }
 
     @Override
-    public HashMap<String,Integer> businessStatusAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
+    public HashMap businessStatusAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
         QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
         queryWrapper.select("wd_id");
         assembleQueryWrapper(queryWrapper,channelMapAceeptVo);
         queryWrapper.and(queryWrapper1 -> {
             queryWrapper1.eq("wd_type_code","1");
         });
-        List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
+        queryWrapper.and(queryWrapper2 ->{
+            queryWrapper2.eq("deleted",0);
+        });
 
-        List<String> collect = wdInfos.stream().map(wdInfo -> {
-            return wdInfo.getWdId();
-        }).collect(Collectors.toList());
-        QueryWrapper<StoreWd> queryWrapper1 = new QueryWrapper<>();
-        queryWrapper1.select("business_status","count(*) as comment_count")
-            .in("wd_id",collect)
-            .groupBy("business_status");
-        List<StoreWd> storeWds = storeWdDao.selectList(queryWrapper1);
+        List<StoreWd> storeWds = storeWdDao.businessStatusAnalyse(queryWrapper);
         HashMap<String,Integer> hashMap = new HashMap<>();
         int total = 0;
         for (StoreWd storeWd : storeWds) {
             total+=storeWd.getCommentCount();
             hashMap.put(storeWd.getBusinessStatus(),storeWd.getCommentCount());
         }
-        hashMap.put("total",total);
-        return hashMap;
+
+        ArrayList<Histogram> list = new ArrayList<>();
+        for (String s : hashMap.keySet()) {
+            Histogram histogram = new Histogram();
+            histogram.setName(s);
+            histogram.setCount(hashMap.get(s));
+            list.add(histogram);
+        }
+
+        HashMap<String, Object> result = new HashMap<>();
+        result.put("total",total);
+        result.put("data",list);
+        return result;
     }
 
     @Override
@@ -343,6 +378,10 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
         queryWrapper.and(queryWrapper1 -> {
             queryWrapper1.eq("wd_type_code","1");
         });
+        queryWrapper.and(queryWrapper2 ->{
+            queryWrapper2.eq("deleted",0);
+        });
+
         List<StoreWd> storeWds = storeWdDao.perCapitaConsumpAnalyse(queryWrapper);
         HashMap<String, Integer> hashMap = new HashMap<>();
         hashMap.put("0~20",0);
@@ -367,12 +406,16 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
         }
 
         ArrayList<Histogram> list = new ArrayList<>();
-        for (String s : hashMap.keySet()) {
-            Histogram histogram = new Histogram();
-            histogram.setName(s);
-            histogram.setCount(hashMap.get(s));
-            list.add(histogram);
-        }
+        Histogram histogram1 = new Histogram("0~20",hashMap.get("0~20"));
+        Histogram histogram2 = new Histogram("20~50",hashMap.get("20~50"));
+        Histogram histogram3 = new Histogram("50~100",hashMap.get("50~100"));
+        Histogram histogram4 = new Histogram("100~200",hashMap.get("100~200"));
+        Histogram histogram5 = new Histogram("200以上",hashMap.get("200以上"));
+        list.add(histogram1);
+        list.add(histogram2);
+        list.add(histogram3);
+        list.add(histogram4);
+        list.add(histogram5);
         return list;
     }
 
@@ -384,6 +427,10 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
         queryWrapper.and(queryWrapper1 -> {
             queryWrapper1.eq("wd_type_code","1");
         });
+        queryWrapper.and(queryWrapper2 ->{
+            queryWrapper2.eq("deleted",0);
+        });
+
         List<StoreWd> storeWds = storeWdDao.operateTimeAnalyse(queryWrapper);
 
         HashMap<Integer,Integer> hashMap = new HashMap<>();

+ 5 - 0
ruoyi-demo/src/main/java/com/ruoyi/demo/utils/WdRedisStoreage.java

@@ -49,6 +49,11 @@ public class WdRedisStoreage {
         return tag;
     }
 
+    public  List<List<String>> getWdTagList(List<String> key){
+        List<List<String>>  list = redisTemplate.opsForValue().multiGet(key);
+        return list;
+    }
+
 //    /***
 //     * 分析网点周边标签,并把分析结果存入redis(默认范围:1km)
 //     * @param wdInfo 中心网点信息

+ 8 - 0
ruoyi-demo/src/main/resources/mapper/demo/StoreWdDaoMapper.xml

@@ -8,4 +8,12 @@
     <select id="operateTimeAnalyse" resultType="com.ruoyi.demo.entity.StoreWd">
         select opentime,closetime from ddt_store_wd where opentime != '' and closetime != '' and wd_id in (select ${ew.sqlSelect} from ddt_wd_info ${ew.customSqlSegment})
     </select>
+
+    <select id="category" resultType="com.ruoyi.demo.entity.StoreWd">
+        select manage_type_code,count(*) as comment_count from ddt_store_wd where opentime != '' and closetime != '' and wd_id in (select ${ew.sqlSelect} from ddt_wd_info ${ew.customSqlSegment}) group by manage_type_code
+    </select>
+
+    <select id="businessStatusAnalyse" resultType="com.ruoyi.demo.entity.StoreWd">
+        select business_status,count(*) as comment_count from ddt_store_wd where opentime != '' and closetime != '' and wd_id in (select ${ew.sqlSelect} from ddt_wd_info ${ew.customSqlSegment}) group by business_status
+    </select>
 </mapper>