Jelajahi Sumber

首页统计

xdd 3 hari lalu
induk
melakukan
20894a3599

+ 2 - 0
fs-admin/src/main/java/com/fs/FSAdminApplication.java

@@ -8,6 +8,7 @@ import org.springframework.cache.annotation.EnableCaching;
 import org.springframework.context.annotation.Bean;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 import org.springframework.web.multipart.commons.CommonsMultipartResolver;
 
@@ -23,6 +24,7 @@ import java.util.Date;
 @EnableTransactionManagement
 @EnableAsync
 @EnableCaching
+@EnableScheduling
 public class FSAdminApplication
 {
     public static void main(String[] args)

+ 34 - 7
fs-admin/src/main/java/com/fs/api/controller/IndexStatisticsController.java

@@ -1,5 +1,7 @@
 package com.fs.api.controller;
 
+import com.fs.common.core.redis.RedisCache;
+import com.fs.statis.StatisticsRedisConstant;
 import com.fs.statis.cache.IStatisticsCacheService;
 import com.fs.statis.dto.*;
 import com.fs.statis.service.IStatisticsService;
@@ -10,6 +12,8 @@ import com.fs.common.core.domain.R;
 
 import java.util.List;
 
+import static com.fs.statis.StatisticsRedisConstant.DATA_OVERVIEW_DEALER_CHARTS;
+
 /**
  * 首页-统计
  */
@@ -20,12 +24,30 @@ public class IndexStatisticsController {
     private IStatisticsCacheService statisticsService;
     @Autowired
     private IStatisticsService statisticsService1;
+    @Autowired
+    private RedisCache redisCache;
     /**
      * 分析概览
      */
     @PostMapping("/analysisPreview")
     public R analysisPreview(@RequestBody AnalysisPreviewQueryDTO param){
-        AnalysisPreviewDTO analysisPreviewDTO = statisticsService1.analysisPreview(param);
+        AnalysisPreviewDTO analysisPreviewDTO = null;
+        Integer type = param.getType();
+        if(type == null) {
+            type = 0;
+        }
+
+        if(0 == type){
+            analysisPreviewDTO = redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_ANALYSISPREVIEW_TODAY);
+        } else if(1 == type){
+            analysisPreviewDTO = redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_ANALYSISPREVIEW_YESTODAY);
+        } else if(2 == type) {
+            analysisPreviewDTO = redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_ANALYSISPREVIEW_THIS_WEEEK);
+        } else if(3 == type) {
+            analysisPreviewDTO = redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_ANALYSISPREVIEW_THIS_MONTH);
+        } else if(4 == type) {
+            analysisPreviewDTO = redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_ANALYSISPREVIEW_BEFORE_MONTH);
+        }
         return R.ok().put("data",analysisPreviewDTO);
     }
 
@@ -34,7 +56,8 @@ public class IndexStatisticsController {
      */
     @GetMapping("/rechargeComsumption")
     public R rechargeComsumption(){
-        ConsumptionBalanceDataDTO consumptionBalanceDataDTO = statisticsService.rechargeConsumption();
+        ConsumptionBalanceDataDTO consumptionBalanceDataDTO = redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_BALANCE);
+
         return R.ok().put("data", consumptionBalanceDataDTO);
     }
 
@@ -43,8 +66,9 @@ public class IndexStatisticsController {
      */
     @PostMapping("/watchEndPlayTrend")
     public R watchEndPlayTrend(@RequestBody AnalysisPreviewQueryDTO param){
-        List<WatchEndPlayTrendDTO> watchEndPlayTrendDTOS = statisticsService.watchEndPlayTrend(param);
-        return R.ok().put("data", watchEndPlayTrendDTOS);
+        String key = String.format("%s::%d", DATA_OVERVIEW_DEALER_CHARTS, param.getType());
+        List<DeaMemberTopTenDTO> deaMemberTopTenDTOS = redisCache.getCacheObject(key);
+        return R.ok().put("data", deaMemberTopTenDTOS);
     }
 
     /**
@@ -88,7 +112,8 @@ public class IndexStatisticsController {
      */
     @GetMapping("/dealerAggregated")
     public R dealerAggregated(){
-        DealerAggregatedDTO dealerAggregatedDTO = statisticsService.dealerAggregated();
+        DealerAggregatedDTO dealerAggregatedDTO = redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_AGGREGATED);
+
         return R.ok().put("data",dealerAggregatedDTO);
     }
 
@@ -97,7 +122,8 @@ public class IndexStatisticsController {
      */
     @GetMapping("/smsBalance")
     public R smsBalance(){
-        Long smsBalance = statisticsService1.smsBalance();
+        Long smsBalance = redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_SMS_BALANCE);
+
         return R.ok().put("data", smsBalance);
     }
 
@@ -107,7 +133,8 @@ public class IndexStatisticsController {
      */
     @GetMapping("/authorizationInfo")
     public R authorizationInfo(){
-        AuthorizationInfoDTO authorizationInfoDTO = statisticsService1.authorizationInfo();
+        AuthorizationInfoDTO authorizationInfoDTO = redisCache.getCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_AUTHORIZATION_INFO);
+
         return R.ok().put("data", authorizationInfoDTO);
     }
 }

+ 1 - 0
fs-common/src/main/java/com/fs/common/core/redis/RedisCache.java

@@ -128,6 +128,7 @@ public class RedisCache
         return count == null ? 0 : count;
     }
 
+
     /**
      * 获得缓存的list对象
      *

+ 64 - 0
fs-service-system/src/main/java/com/fs/statis/StatisticsRedisConstant.java

@@ -0,0 +1,64 @@
+package com.fs.statis;
+
+/**
+ * 统计redis常量
+ */
+public class StatisticsRedisConstant {
+    /**
+     * 经销商统计
+     */
+    public static final String DATA_OVERVIEW_DEALER_AGGREGATED = "statistics::data::overview::DealerAggregatedDTO";
+    /**
+     * 短信余额
+     */
+    public static final String DATA_OVERVIEW_DEALER_SMS_BALANCE = "statistics::data::overview::SMS::BALANCE";
+    /**
+     * 余额类
+     */
+    public static final String DATA_OVERVIEW_DEALER_BALANCE = "statistics::data::overview::balance";
+    /**
+     * 平台统计类信息
+     */
+    public static final String DATA_OVERVIEW_DEALER_AUTHORIZATION_INFO = "statistics::data::overview::authorizationInfo";
+
+    /**
+     * 分析概览-今日
+     */
+    public static final String DATA_OVERVIEW_DEALER_ANALYSISPREVIEW_TODAY = "statistics::data::overview::AnalysisPreviewDTO::0";
+    /**
+     * 分析概览-昨日
+     */
+    public static final String DATA_OVERVIEW_DEALER_ANALYSISPREVIEW_YESTODAY = "statistics::data::overview::AnalysisPreviewDTO::1";
+
+    /**
+     * 分析概览-本周
+     */
+    public static final String DATA_OVERVIEW_DEALER_ANALYSISPREVIEW_THIS_WEEEK = "statistics::data::overview::AnalysisPreviewDTO::2";
+
+    /**
+     * 分析概览-本月
+     */
+    public static final String DATA_OVERVIEW_DEALER_ANALYSISPREVIEW_THIS_MONTH = "statistics::data::overview::AnalysisPreviewDTO::3";
+    /**
+     * 分析概览-上月
+     */
+    public static final String DATA_OVERVIEW_DEALER_ANALYSISPREVIEW_BEFORE_MONTH = "statistics::data::overview::AnalysisPreviewDTO::4";
+
+
+    /**
+     * 会员观看、完播人数趋势图
+     */
+    public static final String DATA_OVERVIEW_DEALER_CHARTS = "statistics::data::charts::dealer::charts";
+
+
+    /**
+     * 经销商会员观看TOP10 - 按观看人数
+     */
+    public static final String CHARTS_MEMBER_TOP_TEN_WATCH = "statistics::data::charts::memeber::top10::watch::user::count";
+    /**
+     * 经销商会员观看TOP10 - 按完播人数
+     */
+    public static final String CHARTS_MEMBER_TOP_TEN_COMPLETED = "statistics::data:charts::memeber::top10::watch::completed::user::count";
+
+
+}

+ 1 - 0
fs-service-system/src/main/java/com/fs/statis/cache/IStatisticsCacheService.java

@@ -27,6 +27,7 @@ public interface IStatisticsCacheService {
      * @return 会员观看、完播人数趋势图
      */
     List<WatchEndPlayTrendDTO> watchEndPlayTrend(AnalysisPreviewQueryDTO param);
+    void setWatchEndPlayTrend(Integer type,List<WatchEndPlayTrendDTO> data);
 
     /**
      * 经销商会员观看TOP10

+ 6 - 1
fs-service-system/src/main/java/com/fs/statis/cache/impl/StatisticsCacheServiceImpl.java

@@ -34,7 +34,6 @@ public class StatisticsCacheServiceImpl implements IStatisticsCacheService {
 
     private static final Cache<Integer, List<WatchEndPlayTrendDTO>> WATCH_END_PLAY_TREND = Caffeine.newBuilder()
             .maximumSize(1000)
-            .expireAfterWrite(10, TimeUnit.MINUTES)
             .build();
 
     private static final Cache<Integer, List<DeaMemberTopTenDTO>> DEA_MEMBER_TOP_TEN = Caffeine.newBuilder()
@@ -70,6 +69,12 @@ public class StatisticsCacheServiceImpl implements IStatisticsCacheService {
         });
     }
 
+    @Override
+    public void setWatchEndPlayTrend(Integer type,List<WatchEndPlayTrendDTO> data) {
+        WATCH_END_PLAY_TREND.put(type,data);
+    }
+
+
     @Override
     public List<DeaMemberTopTenDTO> deaMemberTopTen(AnalysisPreviewQueryDTO param) {
         return DEA_MEMBER_TOP_TEN.get(param.getType(),e->{

+ 4 - 3
fs-service-system/src/main/java/com/fs/statis/dto/ConsumptionBalanceDataDTO.java

@@ -3,6 +3,7 @@ package com.fs.statis.dto;
 import lombok.Data;
 
 import java.io.Serializable;
+import java.math.BigDecimal;
 
 /**
  * 消费余额
@@ -13,16 +14,16 @@ public class ConsumptionBalanceDataDTO implements Serializable {
      * 当前账户余额。
      * 数值表示,单位可能是分或其他约定单位。
      */
-    private Long balance;
+    private BigDecimal balance;
     /**
      * 今日消费金额。
      * 当天的总消费数额。
      */
-    private Integer todayComsumption;
+    private BigDecimal todayComsumption;
     /**
      * 昨日消费金额。
      * 昨天的总消费数额。
      */
-    private Integer yesterdayComsumption;
+    private BigDecimal yesterdayComsumption;
 
 }

+ 27 - 0
fs-service-system/src/main/java/com/fs/statis/service/IStatisticsService.java

@@ -8,6 +8,33 @@ import java.util.List;
  * 统计接口
  */
 public interface IStatisticsService {
+
+    /**
+     * 数据概览定时任务
+     */
+    void dataOverviewTask();
+
+    /**
+     * 分析概览定时任务
+     */
+    void analysisPreviewTask(Integer type);
+
+
+    /**
+     * 会员观看、完播人数趋势图
+     */
+    void watchEndPlayTrendTask(Integer type);
+
+    /**
+     * 课程观看TOP10
+     */
+    void watchCourseTopTenTask();
+
+    /**
+     * 答题红包金额TOP10
+     */
+    void rewardMoneyTopTenTask();
+
     /**
      * 分析概览 - 经销商统计
      */

+ 162 - 1
fs-service-system/src/main/java/com/fs/statis/service/impl/StatisticsServiceImpl.java

@@ -1,6 +1,9 @@
 package com.fs.statis.service.impl;
 
+import com.fs.common.core.redis.RedisCache;
 import com.fs.company.cache.ICompanyCacheService;
+import com.fs.statis.StatisticsRedisConstant;
+import com.fs.statis.cache.IStatisticsCacheService;
 import com.fs.statis.dto.*;
 import com.fs.statis.mapper.ConsumptionBalanceMapper;
 import com.fs.statis.service.IStatisticsService;
@@ -9,13 +12,20 @@ import com.fs.store.service.cache.IFsUserCourseCacheService;
 import com.hc.openapi.tool.util.ObjectUtils;
 import com.hc.openapi.tool.util.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.Collections;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.TemporalAdjusters;
 import java.util.List;
 
+import static com.fs.statis.StatisticsRedisConstant.DATA_OVERVIEW_DEALER_CHARTS;
+
 @Service
 public class StatisticsServiceImpl implements IStatisticsService {
     @Autowired
@@ -27,6 +37,157 @@ public class StatisticsServiceImpl implements IStatisticsService {
     @Autowired
     private ICompanyCacheService companyCacheService;
 
+    @Autowired
+    private RedisCache redisCache;
+
+
+    @Override
+    @Scheduled(cron = "0 * * * * *")
+    public void dataOverviewTask() {
+        DealerAggregatedDTO dealerAggregatedDTO = this.dealerAggregated();
+        ConsumptionBalanceDataDTO consumptionBalanceDataDTO = this.rechargeConsumption();
+        AuthorizationInfoDTO authorizationInfoDTO = authorizationInfo();
+        Long smsBalance = this.smsBalance();
+
+        redisCache.setCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_AGGREGATED, dealerAggregatedDTO);
+        redisCache.setCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_BALANCE, consumptionBalanceDataDTO);
+        redisCache.setCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_AUTHORIZATION_INFO, authorizationInfoDTO);
+        redisCache.setCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_SMS_BALANCE, smsBalance);
+    }
+
+
+    @Scheduled(cron = "0 * * * * *")
+    public void analysisPreviewTask0(){
+        analysisPreviewTask(0);
+    }
+
+    @Scheduled(cron = "0 * * * * *")
+    public void analysisPreviewTask1(){
+        analysisPreviewTask(0);
+        analysisPreviewTask(1);
+        analysisPreviewTask(2);
+        analysisPreviewTask(3);
+        analysisPreviewTask(4);
+    }
+
+
+    @Override
+    public void analysisPreviewTask(Integer type) {
+        // 根据type计算出时间范围
+        String startDate = "";
+        String endDate = "";
+
+        LocalDate now = LocalDate.now();
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+
+
+        if(0 == type){
+            startDate = now.format(formatter);
+            endDate = now.format(formatter);
+        } else if(1 == type){
+            LocalDate yesterday = now.minusDays(1);
+            startDate = yesterday.format(formatter);
+            endDate = yesterday.format(formatter);
+        } else if(2 == type) {
+            LocalDate startOfWeek = now.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
+            startDate = startOfWeek.format(formatter);
+            endDate = now.format(formatter);
+        } else if(3 == type) {
+            LocalDate startOfMonth = now.withDayOfMonth(1);
+            startDate = startOfMonth.format(formatter);
+            endDate = now.format(formatter);
+        } else if(4 == type) {
+            LocalDate firstDayOfPreviousMonth = now.minusMonths(1).withDayOfMonth(1);
+            LocalDate lastDayOfPreviousMonth = now.withDayOfMonth(1).minusDays(1);
+            startDate = firstDayOfPreviousMonth.format(formatter);
+            endDate = lastDayOfPreviousMonth.format(formatter);
+        }
+
+        AnalysisPreviewQueryDTO param = new AnalysisPreviewQueryDTO();
+        param.setStartTime(startDate);
+        param.setEndTime(endDate);
+        param.setType(type);
+
+        AnalysisPreviewDTO analysisPreviewDTO = this.analysisPreview(param);
+
+        if(0 == type){
+            redisCache.setCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_ANALYSISPREVIEW_TODAY, analysisPreviewDTO);
+        } else if(1 == type){
+            redisCache.setCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_ANALYSISPREVIEW_YESTODAY, analysisPreviewDTO);
+        } else if(2 == type) {
+            redisCache.setCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_ANALYSISPREVIEW_THIS_WEEEK, analysisPreviewDTO);
+        } else if(3 == type) {
+            redisCache.setCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_ANALYSISPREVIEW_THIS_MONTH, analysisPreviewDTO);
+        } else if(4 == type) {
+            redisCache.setCacheObject(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_ANALYSISPREVIEW_BEFORE_MONTH, analysisPreviewDTO);
+        }
+
+    }
+
+    @Scheduled(cron = "0 * * * * *")
+    public void watchEndPlayTrendTask0(){
+        this.watchEndPlayTrendTask(0);
+        this.watchEndPlayTrendTask(1);
+        this.watchEndPlayTrendTask(2);
+        this.watchEndPlayTrendTask(3);
+        this.watchEndPlayTrendTask(4);
+    }
+
+
+    @Override
+    public void watchEndPlayTrendTask(Integer type) {
+        // 根据type计算出时间范围
+        String startDate = "";
+        String endDate = "";
+
+        LocalDateTime now = LocalDateTime.now();
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
+
+        if(0 == type){
+            startDate = now.format(formatter);
+            endDate = now.format(formatter);
+        } else if(1 == type){
+            LocalDateTime yesterday = now.minusDays(1);
+            startDate = yesterday.format(formatter);
+            endDate = yesterday.format(formatter);
+        } else if(2 == type) {
+            LocalDateTime startOfWeek = now.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
+            startDate = startOfWeek.format(formatter);
+            endDate = now.format(formatter);
+        } else if(3 == type) {
+            LocalDateTime startOfMonth = now.withDayOfMonth(1);
+            startDate = startOfMonth.format(formatter);
+            endDate = now.format(formatter);
+        } else if(4 == type) {
+            LocalDateTime firstDayOfPreviousMonth = now.minusMonths(1).withDayOfMonth(1);
+            LocalDateTime lastDayOfPreviousMonth = now.withDayOfMonth(1).minusDays(1);
+            startDate = firstDayOfPreviousMonth.format(formatter);
+            endDate = lastDayOfPreviousMonth.format(formatter);
+        }
+
+        AnalysisPreviewQueryDTO param = new AnalysisPreviewQueryDTO();
+        param.setStartTime(startDate);
+        param.setEndTime(endDate);
+        param.setType(type);
+
+        List<WatchEndPlayTrendDTO> watchEndPlayTrendDTOS = this.watchEndPlayTrend(param);
+
+        redisCache.setCacheObject(String.format("%s::%d",DATA_OVERVIEW_DEALER_CHARTS,type),watchEndPlayTrendDTOS);
+
+    }
+
+    @Override
+    public void watchCourseTopTenTask() {
+
+    }
+
+    @Override
+    public void rewardMoneyTopTenTask() {
+
+    }
+
+
     @Override
     public DealerAggregatedDTO dealerAggregated() {
         return consumptionBalanceMapper.dealerAggregated();