Pārlūkot izejas kodu

修改统计接口,编写定时任务。

Guos 1 nedēļu atpakaļ
vecāks
revīzija
679c91048c

+ 4 - 1
fs-admin/src/main/java/com/fs/api/controller/StatisticManageController.java

@@ -29,6 +29,9 @@ public class StatisticManageController {
     @PostMapping("/statisticMain")
     public R statisticMain(@RequestBody ComprehensiveStatisticsParam param) {
         Assert.notNull(param.getDimension(), "请选择统计维度");
-        return R.ok().put("data", statisticManageService.statisticMain(param));
+        statisticManageService.executeTask();
+//        return R.ok().put("data", statisticManageService.statisticMain(param));
+        return R.ok("success");
+
     }
 }

+ 35 - 20
fs-service/src/main/java/com/fs/company/service/impl/StatisticManageServiceImpl.java

@@ -2,6 +2,7 @@ package com.fs.company.service.impl;
 
 import cn.hutool.core.util.ObjectUtil;
 import com.fs.common.enums.DimensionEnum;
+import com.fs.common.utils.bean.BeanUtils;
 import com.fs.company.domain.CompanyDeptUserInfo;
 import com.fs.company.domain.ComprehensiveDailyStats;
 import com.fs.company.dto.CompanyDeptUserInfoDTO;
@@ -11,13 +12,12 @@ import com.fs.company.service.IStatisticManageService;
 import com.fs.statis.param.ComprehensiveStatisticsParam;
 import com.google.common.collect.Maps;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.CollectionUtils;
 import com.google.common.collect.Lists;
-import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.util.Assert;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -94,27 +94,12 @@ public class StatisticManageServiceImpl implements IStatisticManageService {
     public void executeTask() {
         List<CompanyDeptUserInfo> companyDeptdUserList = statisticManageMapper.getCompanyAndDeptAndDeptUserList(null);
         companyDeptdUserList.forEach(companyDeptUserInfo -> {
-            ComprehensiveDailyStats comprehensiveDailyStats = new ComprehensiveDailyStats();
-            comprehensiveDailyStats.setCompanyId(companyDeptUserInfo.getCompanyId());
-            comprehensiveDailyStats.setCompanyName(companyDeptUserInfo.getCompanyName());
-            comprehensiveDailyStats.setDeptId(companyDeptUserInfo.getDeptId());
-            comprehensiveDailyStats.setDeptName(companyDeptUserInfo.getDeptName());
-            comprehensiveDailyStats.setStatisticsTime(new Date());
-            comprehensiveDailyStats.setCreateTime(new Date());
-            comprehensiveDailyStats.setUpdateTime(new Date());
+            CompanyDeptUserInfoDTO statisticNum =  new CompanyDeptUserInfoDTO();
             if(null != companyDeptUserInfo.getUserId()){
-                comprehensiveDailyStats.setUserId(companyDeptUserInfo.getUserId());
-                comprehensiveDailyStats.setUserName(companyDeptUserInfo.getUserName());
-                comprehensiveDailyStats.setNickName(companyDeptUserInfo.getNickName());
-                CompanyDeptUserInfoDTO statisticNum = statisticManageMapper.getStatisticNum(companyDeptUserInfo.getUserId());
-                comprehensiveDailyStats.setAnswerNum(statisticNum.getAnswerNum());
-                comprehensiveDailyStats.setCompleteNum(statisticNum.getCompleteNum());
-                comprehensiveDailyStats.setLineNum(statisticNum.getLineNum());
-                comprehensiveDailyStats.setActiveNum(statisticNum.getActiveNum());
-                comprehensiveDailyStats.setRedPacketNum(statisticNum.getRedPacketNum());
+                statisticNum = statisticManageMapper.getStatisticNum(companyDeptUserInfo.getUserId());
             }
+            ComprehensiveDailyStats comprehensiveDailyStats = component(companyDeptUserInfo, statisticNum);
             statisticManageMapper.insert(comprehensiveDailyStats);
-
         });
     }
 
@@ -130,6 +115,36 @@ public class StatisticManageServiceImpl implements IStatisticManageService {
        return statisticManageMapper.getStatisticNumByPersonal(dimension, startTime, endTime, userIds);
     }
 
+    private ComprehensiveDailyStats component(CompanyDeptUserInfo source, CompanyDeptUserInfoDTO statisticNum){
+        ComprehensiveDailyStats target = new ComprehensiveDailyStats();
+        target.setCompanyId(source.getCompanyId());
+        target.setCompanyName(source.getCompanyName());
+        target.setDeptId(source.getDeptId());
+        target.setDeptName(source.getDeptName());
+        target.setStatisticsTime(new Date());
+        target.setCreateTime(new Date());
+        target.setUpdateTime(new Date());
+        if(null != source.getUserId()){
+            target.setUserId(source.getUserId());
+            target.setUserName(source.getUserName());
+            target.setNickName(source.getNickName());
+            target.setAnswerNum(statisticNum.getAnswerNum());
+            target.setCompleteNum(statisticNum.getCompleteNum());
+            target.setLineNum(statisticNum.getLineNum());
+            target.setActiveNum(statisticNum.getActiveNum());
+            target.setRedPacketNum(statisticNum.getRedPacketNum());
+            target.setRedPacketAmount(new BigDecimal(0.00));
+        }else{
+            target.setAnswerNum(0);
+            target.setCompleteNum(0);
+            target.setLineNum(0);
+            target.setActiveNum(0);
+            target.setRedPacketNum(0);
+            target.setRedPacketAmount(new BigDecimal(0.00));
+        }
+      return target;
+    }
+
 
 }
 

+ 1 - 1
fs-service/src/main/resources/mapper/company/StatisticManageMapper.xml

@@ -44,7 +44,7 @@
         ),
         t2 AS (
                  SELECT
-                     count( qec.fs_user_id ) AS actvieNUm
+                     count( qec.fs_user_id ) AS activeNum
                  FROM
                      qw_external_contact AS qec
                  WHERE