Selaa lähdekoodia

Merge branch 'master' of http://1.14.104.71:10880/root/ylrz_his_scrm_java

yzx 1 viikko sitten
vanhempi
commit
c4d4d4e4a3

+ 0 - 2
README.md

@@ -53,7 +53,6 @@ CREATE INDEX idx_search_mobile ON qw_external_contact(search_mobile);
 
 
 -- 新加统计表
-
 CREATE TABLE IF NOT EXISTS user_daily_stats (
     id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '记录ID',
     company_id BIGINT NOT NULL COMMENT '公司ID',
@@ -72,7 +71,6 @@ CREATE TABLE IF NOT EXISTS user_daily_stats (
     red_packet_amount DECIMAL(10, 2) NOT NULL DEFAULT 0.00 COMMENT '红包金额',
     create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '记录创建时间',
     update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '记录更新时间',
-    UNIQUE KEY uk_user_date (user_id, statistics_time) COMMENT '用户+日期唯一约束',
     KEY idx_company_date (company_id, statistics_time) COMMENT '公司+日期索引',
     KEY idx_dept_date (dept_id, create_time) COMMENT '部门+日期索引'
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '用户每日统计数据表';

+ 33 - 8
fs-admin/src/main/java/com/fs/api/controller/StatisticManageController.java

@@ -1,15 +1,11 @@
 package com.fs.api.controller;
 
-
 import com.fs.common.core.domain.R;
 import com.fs.company.service.IStatisticManageService;
 import com.fs.statis.param.ComprehensiveStatisticsParam;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.util.Assert;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 
@@ -26,12 +22,41 @@ public class StatisticManageController {
     @Resource
     private IStatisticManageService statisticManageService;
 
+    /**
+     * 获取统计信息
+     * @param param
+     * @return
+     */
     @PostMapping("/statisticMain")
     public R statisticMain(@RequestBody ComprehensiveStatisticsParam param) {
         Assert.notNull(param.getDimension(), "请选择统计维度");
-        statisticManageService.executeTask();
-//        return R.ok().put("data", statisticManageService.statisticMain(param));
-        return R.ok("success");
+        return R.ok().put("data", statisticManageService.statisticMain(param));
+    }
+
+    /**
+     * 获取公司下拉
+     * @return
+     */
+    @GetMapping("/getSearchCompanyInfo")
+    public R getSearchCompanyInfo(){
+        return R.ok().put("data", statisticManageService.getSearchCompanyInfo());
+    }
+
+    /**
+     * 根据公司id获取部门下拉
+     * @return
+     */
+    @GetMapping("/getSearchDeptInfo")
+    public R getSearchDeptInfo(@RequestParam("id") Long id){
+        return R.ok().put("data", statisticManageService.getSearchDeptInfo(id));
+    }
 
+    /**
+     * 根据公司id获取部门下拉
+     * @return
+     */
+    @GetMapping("/getSearchUserInfo")
+    public R getSearchUserInfo(@RequestParam("id") Long id){
+        return R.ok().put("data", statisticManageService.getSearchUserInfo(id));
     }
 }

+ 14 - 1
fs-admin/src/main/java/com/fs/company/controller/CompanyDeductController.java

@@ -14,6 +14,7 @@ import com.fs.company.domain.CompanyDeduct;
 import com.fs.company.domain.CompanyMoneyLogs;
 import com.fs.company.service.ICompanyDeductService;
 import com.fs.company.service.ICompanyMoneyLogsService;
+import com.fs.company.service.ICompanyRechargeService;
 import com.fs.company.service.ICompanyService;
 import com.fs.company.vo.CompanyDeductExportVO;
 import com.fs.company.vo.CompanyDeductVO;
@@ -45,6 +46,10 @@ public class CompanyDeductController extends BaseController
     private ICompanyService companyService;
     @Autowired
     private ICompanyMoneyLogsService moneyLogsService;
+
+    @Autowired
+    private ICompanyRechargeService companyRechargeService;
+
     /**
      * 查询扣款列表
      */
@@ -128,7 +133,15 @@ public class CompanyDeductController extends BaseController
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         if(deduct.getIsAudit()==1){
             Company company=companyService.selectCompanyByIdForUpdate(deduct.getCompanyId());
-            company.setMoney(company.getMoney().subtract(deduct.getMoney()));
+
+            // 同步redis缓存
+            R r = companyRechargeService.syncUpdateRedisCompanyRecharge(company, deduct.getMoney(), 2);
+            if(!"200".equals(r.get("code").toString())){
+                return r;
+            }
+            // 充值后,需要同步更新余额到数据库,否则余额与缓存中的不一致
+            String newMoney = r.get("newMoney").toString();
+            company.setMoney(new BigDecimal(newMoney));
             companyService.updateCompany(company);
             CompanyMoneyLogs log=new CompanyMoneyLogs();
             log.setCompanyId(deduct.getCompanyId());

+ 1 - 1
fs-admin/src/main/java/com/fs/company/controller/CompanyRechargeController.java

@@ -125,7 +125,7 @@ public class CompanyRechargeController extends BaseController
 
             // 同步redis缓存
             // 注意:在进行充值审核之前,需要先执行一下定时任务同步缓存数据到数据库,再进行后续操作,否则金额不正确
-            R r = companyRechargeService.syncUpdateRedisCompanyRecharge(company, companyRecharge.getMoney());
+            R r = companyRechargeService.syncUpdateRedisCompanyRecharge(company, companyRecharge.getMoney(), 1);
             if(!"200".equals(r.get("code").toString())){
                 return r;
             }

+ 9 - 0
fs-admin/src/main/java/com/fs/task/SgTestController.java

@@ -3,6 +3,8 @@ package com.fs.task;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+ import com.fs.company.service.IStatisticManageService;
+
 import javax.annotation.Resource;
 
 /**
@@ -17,11 +19,18 @@ public class SgTestController {
     @Resource
     private SyncTuLinStudentInfoTask syncTuLinStudentInfoTask;
 
+    @Resource
+    private IStatisticManageService iStatisticManageService;
+
 
     @RequestMapping("/execute")
     public void execute(){
         syncTuLinStudentInfoTask.execute();
     }
 
+    @RequestMapping("/statistic")
+    public void executeTask(){
+        iStatisticManageService.executeTask();
+    }
 
 }

+ 1 - 0
fs-admin/src/main/resources/logback.xml

@@ -78,6 +78,7 @@
 
     <!-- log4j2.xml -->
     <Logger name="com.fs.his.mapper" level="debug"/>
+    <Logger name="com.fs.company.mapper" level="debug"/>
     <Logger name="org.apache.ibatis" level="debug"/>
 
 

+ 73 - 3
fs-service/src/main/java/com/fs/company/mapper/StatisticManageMapper.java

@@ -16,15 +16,56 @@ import java.util.List;
  */
 public interface StatisticManageMapper {
 
-    //插入数据
+    /**
+     * 插入数据
+     * @param comprehensiveDailyStats
+     */
     Integer insert(ComprehensiveDailyStats comprehensiveDailyStats);
 
+    /**
+     * 根据id更新数据
+     * @param comprehensiveDailyStats
+     */
+    Integer updateById(ComprehensiveDailyStats comprehensiveDailyStats);
+
+    /**
+     * 根据userId和日期更新数据
+     * @param comprehensiveDailyStats
+     */
+    Integer updateByUserAndDate(ComprehensiveDailyStats comprehensiveDailyStats);
+
+    /**
+     * 根据deptId和日期查询数据
+     * @param deptId
+     * @param statisticsTime
+     */
+    ComprehensiveDailyStats selectByDeptAndDate(@Param("deptId") Long deptId, @Param("statisticsTime") Date statisticsTime);
+
+    /**
+     * 根据用户id和日期查询是否有数据
+     * @param userId
+     * @param statisticsTime
+     */
+    ComprehensiveDailyStats selectByUserAndDate(@Param("userId") Long userId, @Param("statisticsTime") Date statisticsTime);
+
+    /**
+     * 根据用户id和日期查询是否有数据
+     * @param userId
+     * @param statisticsTime
+     */
+    Integer countByUserAndDate(@Param("userId") Long userId, @Param("statisticsTime") Date statisticsTime);
+
+    /**
+     * 根据id删除数据
+     * @param id
+     */
+    Integer deleteById(@Param("id") Long id);
+
     //获取公司、部门、员工信息
     List<CompanyDeptUserInfo> getCompanyAndDeptAndDeptUserList(@Param("companyId") Long companyId);
 
     List<CompanyDeptUserInfo> getCompanyInfo();
 
-
     CompanyDeptUserInfoDTO getStatisticNum(@Param("userIds") Long userIds);
 
     /**
@@ -34,5 +75,34 @@ public interface StatisticManageMapper {
      * @param endTime
      * @param userIds
      */
-    List<ComprehensiveStatisticsDTO> getStatisticNumByPersonal(@Param("dimension")Integer dimension, @Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("userIds") Long... userIds);
+    List<ComprehensiveDailyStats> getStatisticNumByPersonal(@Param("dimension")Integer dimension, @Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("userIds") Long... userIds);
+
+    /**
+     * 按照部门统计
+     * @param startTime
+     * @param endTime
+     * @param deptIds
+     */
+    List<ComprehensiveDailyStats> getStatisticNumByDeptId(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("deptIds") Long... deptIds);
+
+    /**
+     * 按照公司统计
+     * @param startTime
+     * @param endTime
+     * @param companyIds
+     */
+    List<ComprehensiveDailyStats> getStatisticNumByCompanyId(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("companyIds") Long... companyIds);
+
+    /**
+     * 根据公司id获取部门下拉搜索信息
+     * @param id
+     */
+    List<CompanyDeptUserInfo> getSearchDeptInfo(@Param("id") Long id);
+
+    /**
+     * 根据部门id获取用户下拉信息
+     * @param id
+     */
+    List<CompanyDeptUserInfo> getSearchUserInfo(@Param("id") Long id);
+
 }

+ 2 - 1
fs-service/src/main/java/com/fs/company/service/ICompanyRechargeService.java

@@ -55,9 +55,10 @@ public interface ICompanyRechargeService
      * 同步到缓存余额
      * @param company 公司
      * @param rechargeMoney 充值金额
+     * @param type 同步类型,1-充值,2-扣款
      * @return 是否成功
      */
-    R syncUpdateRedisCompanyRecharge(Company company, BigDecimal rechargeMoney);
+    R syncUpdateRedisCompanyRecharge(Company company, BigDecimal rechargeMoney, Integer type);
 
     List<CompanyRechargeVO> selectCompanyRechargeListVO(CompanyRechargeVO companyRecharge);
     /**

+ 25 - 2
fs-service/src/main/java/com/fs/company/service/IStatisticManageService.java

@@ -1,9 +1,9 @@
 package com.fs.company.service;
 
+import com.fs.company.domain.CompanyDeptUserInfo;
 import com.fs.statis.param.ComprehensiveStatisticsParam;
 
 import java.util.List;
-import java.util.Map;
 
 /**
  * @description:
@@ -12,10 +12,33 @@ import java.util.Map;
  */
 public interface IStatisticManageService {
 
-    List<Map<String, Object>> statisticMain(ComprehensiveStatisticsParam param);
+    /**
+     * 统计主页
+     * @param param
+     * @return
+     */
+    Object statisticMain(ComprehensiveStatisticsParam param);
+
+    /**
+     * 获取搜索公司信息
+     */
+    List<CompanyDeptUserInfo> getSearchCompanyInfo();
+
+    /**
+     * 根据公司id获取部门下拉搜索信息
+     * @param id
+     */
+    List<CompanyDeptUserInfo> getSearchDeptInfo(Long id);
+
+    /**
+     * 根据部门id获取用户下拉信息
+     * @param id
+     */
+    List<CompanyDeptUserInfo> getSearchUserInfo(Long id);
 
     /**
      * 用来执行定时任务
      */
     void executeTask();
+
 }

+ 9 - 4
fs-service/src/main/java/com/fs/company/service/impl/CompanyRechargeServiceImpl.java

@@ -109,9 +109,9 @@ public class CompanyRechargeServiceImpl implements ICompanyRechargeService
     }
 
     @Override
-    public R syncUpdateRedisCompanyRecharge(Company company, BigDecimal rechargeMoney) {
+    public R syncUpdateRedisCompanyRecharge(Company company, BigDecimal rechargeMoney, Integer type) {
         if(company.getCompanyId() == null){
-            log.error("公司充值-审核-同步更新到缓存,参数错误,公司id:{}, 充值余额:{}", company.getCompanyId(), rechargeMoney);
+            log.error("公司充值/扣款-审核-同步更新到缓存,参数错误,公司id:{}, 充值/扣款余额:{},类型:{}", null, rechargeMoney, type);
             return R.error("公司id为空");
         }
 
@@ -136,13 +136,18 @@ public class CompanyRechargeServiceImpl implements ICompanyRechargeService
                     redisMoney = company.getMoney();
                 }
 
-                newMoney = redisMoney.add(rechargeMoney);
+                if(type == 1){
+                    // 充值
+                    newMoney = redisMoney.add(rechargeMoney);
+                } else {
+                    newMoney = redisMoney.subtract(rechargeMoney);
+                }
 
                 redisCache.setCacheObject(companyMoneyKey, newMoney.toString());
             }
             return R.ok().put("newMoney", newMoney);
         } catch (Exception e) {
-            log.error("公司充值-审核-同步更新到缓存,参数错误,请求异常,异常信息:{}", e.getMessage(), e);
+            log.error("公司充值/扣款-审核-同步更新到缓存,参数错误,请求异常,异常信息:{}", e.getMessage(), e);
             return R.error("审核失败,请重试");
         } finally {
             if (lockAcquired && lock.isHeldByCurrentThread()) {

+ 95 - 63
fs-service/src/main/java/com/fs/company/service/impl/StatisticManageServiceImpl.java

@@ -1,18 +1,15 @@
 package com.fs.company.service.impl;
 
-import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.date.StopWatch;
 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;
-import com.fs.company.dto.ComprehensiveStatisticsDTO;
 import com.fs.company.mapper.StatisticManageMapper;
 import com.fs.company.service.IStatisticManageService;
 import com.fs.statis.param.ComprehensiveStatisticsParam;
-import com.google.common.collect.Maps;
 import lombok.extern.slf4j.Slf4j;
-import com.google.common.collect.Lists;
+import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.util.Assert;
 
@@ -20,10 +17,6 @@ import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
 /**
  * @description:
  * @author: Guos
@@ -42,77 +35,116 @@ public class StatisticManageServiceImpl implements IStatisticManageService {
      * @return
      */
     @Override
-    public List<Map<String, Object>> statisticMain(ComprehensiveStatisticsParam param) {
-        List<Map<String, Object>> result = Lists.newArrayList();
-
-        if (param.getDimension() == DimensionEnum.PERSONAL.getValue()){
-            Assert.notNull(param.getId(), "按个人展示查询条件不能为空!");
-            List<CompanyDeptUserInfo> companyDeptdUserList = statisticManageMapper.getCompanyAndDeptAndDeptUserList(null);
-            //从所有数据中去匹配userId = param.getId的
-            Optional<CompanyDeptUserInfo> first = companyDeptdUserList.stream()
-                    .filter(e -> e.getUserId().equals(param.getId()))
-                    .findFirst();
-            if (!first.isPresent()) {
-                return result;
-            }
-            CompanyDeptUserInfo companyDeptUserInfo = first.get();
-            Map<String, Object> map = Maps.newHashMap();
-            map.put("id", companyDeptUserInfo.getUserId());
-            map.put("name", companyDeptUserInfo.getNickName());
-            List<ComprehensiveStatisticsDTO> statisticNumByPersonal =
-                    getStatisticNumByPersonal(DimensionEnum.PERSONAL.getValue(), param.getStartTime(), param.getEndTime(), param.getId());
-            map.put("list", statisticNumByPersonal);
-            result.add(map);
-            return result;
-        }
+    public Object statisticMain(ComprehensiveStatisticsParam param) {
         if(param.getDimension() == DimensionEnum.COMPANY.getValue()){
-            //按照公司统计,如果id为空就要展示全部公司,如果不为空就展示id查询的公司
-            if(ObjectUtil.isEmpty(param.getId())){
-                //得到所有公司信息
-                List<CompanyDeptUserInfo> companyInfo = statisticManageMapper.getCompanyInfo();
-                for (CompanyDeptUserInfo companyDeptUserInfo : companyInfo){
-                    getStatisticNumByPersonal(DimensionEnum.COMPANY.getValue(), param.getStartTime(), param.getEndTime(),
-                            companyDeptUserInfo.getCompanyId());
-                }
-            }
+            Assert.notNull(param.getId(), "按公司展示查询条件不能为空!");
+            return getStatisticNumByCompanyId(param.getStartTime(), param.getEndTime(), param.getId());
         }
         if(param.getDimension() == DimensionEnum.DEPARTMENT.getValue()){
-            Assert.notNull(param.getId(), "按部门展示公司不能为空!");
-            List<CompanyDeptUserInfo> companyDeptdUserList = statisticManageMapper.getCompanyAndDeptAndDeptUserList(param.getId());
-            //按照部门分组
-            Map<Long, List<CompanyDeptUserInfo>> deptInfos = companyDeptdUserList.stream()
-                    .collect(Collectors.groupingBy(CompanyDeptUserInfo::getDeptId));
-            deptInfos.forEach((deptId, companyDeptUserInfos) -> {
-                Long[] userIds = companyDeptUserInfos.stream().map(CompanyDeptUserInfo::getUserId).toArray(Long[]::new);
-                getStatisticNumByPersonal(DimensionEnum.PERSONAL.getValue(), param.getStartTime(), param.getEndTime(),userIds);
-            });
+            Assert.notNull(param.getId(), "按部门展示查询条件不能为空!");
+            return getStatisticNumByDeptId(param.getStartTime(), param.getEndTime(), param.getId());
+        }
+        if (param.getDimension() == DimensionEnum.PERSONAL.getValue()){
+            Assert.notNull(param.getId(), "按个人展示查询条件不能为空!");
+            return getStatisticNumByPersonal(DimensionEnum.PERSONAL.getValue(), param.getStartTime(), param.getEndTime(), param.getId());
         }
         return null;
     }
 
+    /**
+     * 获取搜索公司信息
+     */
     @Override
-    public void executeTask() {
-        List<CompanyDeptUserInfo> companyDeptdUserList = statisticManageMapper.getCompanyAndDeptAndDeptUserList(null);
-        companyDeptdUserList.forEach(companyDeptUserInfo -> {
-            CompanyDeptUserInfoDTO statisticNum =  new CompanyDeptUserInfoDTO();
-            if(null != companyDeptUserInfo.getUserId()){
-                statisticNum = statisticManageMapper.getStatisticNum(companyDeptUserInfo.getUserId());
-            }
-            ComprehensiveDailyStats comprehensiveDailyStats = component(companyDeptUserInfo, statisticNum);
-            statisticManageMapper.insert(comprehensiveDailyStats);
-        });
+    public List<CompanyDeptUserInfo> getSearchCompanyInfo(){
+        return statisticManageMapper.getCompanyInfo();
+    }
+
+    /**
+     * 根据公司id获取部门下拉搜索信息
+     * @param id
+     */
+    @Override
+    public List<CompanyDeptUserInfo> getSearchDeptInfo(Long id){
+        return statisticManageMapper.getSearchDeptInfo(id);
+    }
+
+    /**
+     * 根据部门id获取用户下拉信息
+     * @param id
+     */
+    @Override
+    public List<CompanyDeptUserInfo> getSearchUserInfo(Long id){
+        return statisticManageMapper.getSearchUserInfo(id);
     }
 
     /**
-     * 获取统计数据
+     * 获取个人统计数据
      * @param dimension 维度
      * @param startTime 开始时间
      * @param endTime 结束时间
      * @param userIds 用户id
      * @return
      */
-    public List<ComprehensiveStatisticsDTO> getStatisticNumByPersonal(Integer dimension, Date startTime, Date endTime, Long... userIds) {
-       return statisticManageMapper.getStatisticNumByPersonal(dimension, startTime, endTime, userIds);
+    public List<ComprehensiveDailyStats> getStatisticNumByPersonal(Integer dimension, Date startTime, Date endTime, Long... userIds) {
+        return statisticManageMapper.getStatisticNumByPersonal(dimension, startTime, endTime, userIds);
+    }
+
+    /**
+     * 获取部门统计数据
+     * @param startTime 开始时间
+     * @param endTime 结束时间
+     * @param deptId 用户id
+     * @return
+     */
+    public List<ComprehensiveDailyStats> getStatisticNumByDeptId(Date startTime, Date endTime, Long... deptId) {
+        return statisticManageMapper.getStatisticNumByDeptId(startTime, endTime, deptId);
+    }
+
+    /**
+     * 获取部门统计数据
+     * @param startTime 开始时间
+     * @param endTime 结束时间
+     * @param deptId 用户id
+     * @return
+     */
+    public List<ComprehensiveDailyStats> getStatisticNumByCompanyId(Date startTime, Date endTime, Long... deptId) {
+        return statisticManageMapper.getStatisticNumByCompanyId(startTime, endTime, deptId);
+    }
+
+    /**
+     * 执行定时任务
+     * 还需要考虑在统计部门数据时,部门下面没有用户,某个时候这个部门下面又加入新的用户了,这个时候就会出现数据偏差
+     */
+    @Override
+    public void executeTask() {
+        StopWatch stopWatch = new StopWatch();
+        stopWatch.start("gs-执行数据统计任务");
+        List<CompanyDeptUserInfo> companyDeptdUserList = statisticManageMapper.getCompanyAndDeptAndDeptUserList(null);
+        log.info("统计人数列表:{}", companyDeptdUserList.size());
+        companyDeptdUserList.forEach(companyDeptUserInfo -> {
+            CompanyDeptUserInfoDTO statisticNum =  new CompanyDeptUserInfoDTO();
+            boolean empty = null == companyDeptUserInfo.getUserId(); //用户id为空返回true
+            if(!empty){
+                statisticNum = statisticManageMapper.getStatisticNum(companyDeptUserInfo.getUserId());
+            }
+            ComprehensiveDailyStats comprehensiveDailyStats = component(companyDeptUserInfo, statisticNum);
+            ComprehensiveDailyStats selectResult = null;
+            if(!empty){
+                //用户id不为空,我们就用用户id去查询这个日期是否有数据
+                selectResult = statisticManageMapper.selectByUserAndDate(comprehensiveDailyStats.getUserId(), comprehensiveDailyStats.getStatisticsTime());
+            }else{
+                //如果用户id为空,说明部门下面没有人(没人情况下,部门id只会在当天的日期中存在一条),先按照部门去查询后删除(或者直接按照id更新就可以了)
+                selectResult = statisticManageMapper.selectByDeptAndDate(companyDeptUserInfo.getDeptId(), comprehensiveDailyStats.getStatisticsTime());
+            }
+            if(!ObjectUtils.isEmpty(selectResult)){
+                comprehensiveDailyStats.setId(selectResult.getId());
+                statisticManageMapper.updateById(comprehensiveDailyStats);
+            }else{
+                statisticManageMapper.insert(comprehensiveDailyStats);
+            }
+        });
+        stopWatch.stop();
+        log.info("gs-执行数据统计任务完成,耗时:{}", stopWatch.getTotalTimeSeconds());
     }
 
     private ComprehensiveDailyStats component(CompanyDeptUserInfo source, CompanyDeptUserInfoDTO statisticNum){

+ 7 - 0
fs-service/src/main/resources/application-config-dev-jnlzjk.yml

@@ -90,5 +90,12 @@ ipad:
 wx_miniapp_temp:
   pay_order_temp_id:
   inquiry_temp_id:
+qw:
+  enableAutoTag: 1
+tag:
+  thread:
+    num: 5
+  rate:
+    limit: 30
 
 

+ 5 - 3
fs-service/src/main/resources/application-config-druid-hst.yml

@@ -88,12 +88,14 @@ headerImg:
   imgUrl:
 ipad:
   ipadUrl: http://ipad.schstyl.cn
-  aiApi:
-  voiceApi:
-  commonApi:
+  aiApi: http://49.232.181.28:3000/api
+  voiceApi: http://123.207.48.104:8009
+  commonApi: http://123.207.48.104:7771
 wx_miniapp_temp:
   pay_order_temp_id:
   inquiry_temp_id:
 
 # 0 代表关闭 1代表开启(润天老商户号的扣款限制)
 enableRedPackAccount: 1
+
+

+ 0 - 7
fs-service/src/main/resources/application-config-druid-jnlzjk.yml

@@ -98,12 +98,5 @@ ipad:
 wx_miniapp_temp:
   pay_order_temp_id:
   inquiry_temp_id:
-qw:
-  enableAutoTag: 1
-tag:
-  thread:
-    num: 5
-  rate:
-    limit: 30
 
 

+ 7 - 1
fs-service/src/main/resources/application-druid-jnlzjk.yml

@@ -155,5 +155,11 @@ im:
     type: NONE
 #是否为新商户,新商户不走mpOpenId
 isNewWxMerchant: false
-
+qw:
+    enableAutoTag: 1
+tag:
+    thread:
+        num: 5
+    rate:
+        limit: 30
 

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

@@ -40,7 +40,7 @@
                 qw_external_contact AS qec
             WHERE
                 date_format( qec.create_time, '%y%m%d' ) = date_format(now(), '%y%m%d' )
-              AND qec.company_user_id = 327
+              AND qec.company_user_id = #{userIds}
         ),
         t2 AS (
                  SELECT
@@ -50,181 +50,14 @@
                  WHERE
                      date_format( qec.create_time, '%y%m%d' ) = date_format(now(), '%y%m%d' )
                    AND qec.fs_user_id IS NOT NULL
-                   AND qec.company_user_id = 327
+                   AND qec.company_user_id = #{userIds}
              ),
-             t3 AS ( SELECT count(*) AS completeNum FROM fs_course_watch_log AS fcwl WHERE date_format(fcwl.create_time, '%y%m%d' ) = date_format( now(), '%y%m%d') and fcwl.log_type = 2 AND fcwl.company_user_id = 327 ),
-             t4 AS ( SELECT count(*) AS answerNum FROM fs_course_answer_logs AS fcal WHERE date_format(fcal.create_time, '%y%m%d' ) = date_format( now(), '%y%m%d')  and fcal.company_user_id = 327 ),
-             t5 AS ( SELECT count(*) AS redPacketNum FROM fs_course_red_packet_log AS fcrpl WHERE date_format(fcrpl.create_time, '%y%m%d' ) = date_format( now(), '%y%m%d' )  and  fcrpl.company_user_id = 327 )
+             t3 AS ( SELECT count(*) AS completeNum FROM fs_course_watch_log AS fcwl WHERE date_format(fcwl.create_time, '%y%m%d' ) = date_format( now(), '%y%m%d') and fcwl.log_type = 2 AND fcwl.company_user_id = #{userIds} ),
+             t4 AS ( SELECT count(*) AS answerNum FROM fs_course_answer_logs AS fcal WHERE date_format(fcal.create_time, '%y%m%d' ) = date_format( now(), '%y%m%d')  and fcal.company_user_id = #{userIds} ),
+             t5 AS ( SELECT count(*) AS redPacketNum FROM fs_course_red_packet_log AS fcrpl WHERE date_format(fcrpl.create_time, '%y%m%d' ) = date_format( now(), '%y%m%d' )  and  fcrpl.company_user_id = #{userIds} )
         SELECT * FROM t1,t2,t3,t4,t5
     </select>
 
-    <select id="getStatisticNumByPersonal" resultType="com.fs.company.dto.ComprehensiveStatisticsDTO">
-        WITH RECURSIVE date_range AS (
-            SELECT #{startTime} AS dt
-            UNION ALL
-            SELECT DATE_ADD(dt, INTERVAL 1 DAY)
-            FROM date_range
-            WHERE dt &lt; #{endTime}
-        ),
-        t1 AS (
-            SELECT
-            COUNT(qec.id) AS t1_count,
-            d.dt AS create_time
-            FROM date_range d
-            LEFT JOIN qw_external_contact qec
-            ON DATE(qec.create_time) = d.dt
-        <if test="userIds != null">
-            <if test="dimension == 1">
-                <choose>
-                    <when test="userIds.length > 1 ">
-                        AND qec.company_user_id IN (
-                        <foreach collection="userIds" item="i" separator=",">
-                            #{i}
-                        </foreach>
-                        )
-                    </when>
-                    <otherwise>
-                        AND qec.company_user_id = #{userIds[0]}
-                    </otherwise>
-                </choose>
-            </if>
-            <if test="dimension == 2">
-                AND qec.company_id = #{userIds[0]}
-            </if>
-        </if>
-            GROUP BY d.dt
-        ),
-        t2 AS (
-            SELECT
-            COUNT(qec.id) AS t2_count,
-            d.dt AS create_time
-            FROM date_range d
-            LEFT JOIN qw_external_contact qec
-            ON DATE(qec.create_time) = d.dt
-        <if test="userIds != null">
-            <if test="dimension == 1">
-                <choose>
-                    <when test="userIds.length > 1 ">
-                        AND qec.company_user_id IN (
-                        <foreach collection="userIds" item="i" separator=",">
-                            #{i}
-                        </foreach>
-                        )
-                    </when>
-                    <otherwise>
-                        AND qec.company_user_id = #{userIds[0]}
-                    </otherwise>
-                </choose>
-            </if>
-            <if test="dimension == 2">
-                AND qec.company_id = #{userIds[0]}
-            </if>
-        </if>
-            AND qec.fs_user_id IS NOT NULL
-            GROUP BY d.dt
-        ),
-        t4 AS (
-            SELECT
-            d.dt AS create_time,
-            COUNT(fcwl.qw_external_contact_id) AS completeNum
-            FROM
-            date_range d
-            LEFT JOIN fs_course_watch_log AS fcwl
-            ON DATE(fcwl.create_time) = d.dt
-            AND fcwl.log_type = 2
-        <if test="userIds != null">
-            <if test="dimension == 1">
-                <choose>
-                    <when test="userIds.length > 1 ">
-                        AND fcwl.company_user_id IN (
-                        <foreach collection="userIds" item="i" separator=",">
-                            #{i}
-                        </foreach>
-                        )
-                    </when>
-                    <otherwise>
-                        AND fcwl.company_user_id = #{userIds[0]}
-                    </otherwise>
-                </choose>
-            </if>
-            <if test="dimension == 2">
-                AND fcwl.company_id = #{userIds[0]}
-            </if>
-        </if>
-            GROUP BY d.dt
-        ),
-        t5 AS (
-            SELECT
-            d.dt AS create_time,
-            COUNT(fcal.log_id) AS answerNum
-            FROM
-            date_range d
-            LEFT JOIN fs_course_answer_logs AS fcal
-            ON DATE(fcal.create_time) = d.dt
-        <if test="userIds != null">
-            <if test="dimension == 1">
-                <choose>
-                    <when test="userIds.length > 1 ">
-                        AND fcal.company_user_id IN (
-                        <foreach collection="userIds" item="i" separator=",">
-                            #{i}
-                        </foreach>
-                        )
-                    </when>
-                    <otherwise>
-                        AND fcal.company_user_id = #{userIds[0]}
-                    </otherwise>
-                </choose>
-            </if>
-            <if test="dimension == 2">
-                AND fcal.company_id = #{userIds[0]}
-            </if>
-        </if>
-            GROUP BY d.dt
-        ),
-        t6 AS (
-            SELECT
-            d.dt AS create_time,
-            COUNT(fcrpl.log_id) AS redPacketNum
-            FROM
-            date_range d
-            LEFT JOIN fs_course_red_packet_log AS fcrpl
-            ON DATE(fcrpl.create_time) = d.dt
-        <if test="userIds != null">
-            <if test="dimension == 1">
-                <choose>
-                    <when test="userIds.length > 1 ">
-                        AND fcrpl.company_user_id IN (
-                        <foreach collection="userIds" item="i" separator=",">
-                            #{i}
-                        </foreach>
-                        )
-                    </when>
-                    <otherwise>
-                        AND fcrpl.company_user_id = #{userIds[0]}
-                    </otherwise>
-                </choose>
-            </if>
-            <if test="dimension == 2">
-                AND fcrpl.company_id = #{userIds[0]}
-            </if>
-        </if>
-            GROUP BY d.dt
-        )
-        SELECT
-            t1.create_time as dateStr,
-            t1.t1_count as lineNum,
-            t2.t2_count as activeNum,
-            t4.completeNum,
-            t5.answerNum,
-            t6.redPacketNum
-        FROM t1
-        INNER JOIN t2 ON t1.create_time = t2.create_time
-        INNER JOIN t4 ON t1.create_time = t4.create_time
-        INNER JOIN t5 ON t1.create_time = t5.create_time
-        INNER JOIN t6 ON t1.create_time = t6.create_time
-        ORDER BY t1.create_time
-    </select>
 
     <select id="getCompanyInfo" resultType="com.fs.company.domain.CompanyDeptUserInfo">
         SELECT
@@ -244,6 +77,33 @@
         red_packet_num, red_packet_amount, create_time, update_time
     </sql>
 
+    <select id="getStatisticNumByPersonal" resultType="com.fs.company.domain.ComprehensiveDailyStats">
+        select <include refid="Base_Column_List"/> from user_daily_stats as uds
+        <where>
+            uds.user_id = #{userIds[0]}
+            and statistics_time >=date_format(#{startTime},'%y%m%d')
+            and statistics_time &lt;= date_format(#{endTime},'%y%m%d')
+        </where>
+    </select>
+
+    <select id="getStatisticNumByDeptId" resultType="com.fs.company.domain.ComprehensiveDailyStats">
+        select <include refid="Base_Column_List"/> from user_daily_stats as uds
+        <where>
+            uds.dept_id = #{deptIds[0]}
+            and statistics_time >=date_format(#{startTime},'%y%m%d')
+            and statistics_time &lt;= date_format(#{endTime},'%y%m%d')
+        </where>
+    </select>
+
+    <select id="getStatisticNumByCompanyId" resultType="com.fs.company.domain.ComprehensiveDailyStats">
+        select <include refid="Base_Column_List"/> from user_daily_stats as uds
+        <where>
+            uds.company_id = #{companyIds[0]}
+            and statistics_time >=date_format(#{startTime},'%y%m%d')
+            and statistics_time &lt;= date_format(#{endTime},'%y%m%d')
+        </where>
+    </select>
+
     <!-- 1. 插入数据(全字段插入) -->
     <insert id="insert" parameterType="com.fs.company.domain.ComprehensiveDailyStats">
         INSERT INTO user_daily_stats (
@@ -259,7 +119,7 @@
         )
     </insert>
 
-    <!-- 2. 插入或更新(根据唯一索引uk_user_date,存在则更新,不存在则插入) -->
+    <!-- 2. 插入或更新(根据唯一索引uk_user_date,存在则更新,不存在则插入) 已经删除了索引,有时候用户id是空的 -->
     <insert id="insertOrUpdate" parameterType="com.fs.company.domain.ComprehensiveDailyStats">
         INSERT INTO user_daily_stats (
             company_id, company_name, dept_id, dept_name,
@@ -320,7 +180,7 @@
             red_packet_num = #{redPacketNum},
             red_packet_amount = #{redPacketAmount},
             update_time = NOW()
-        WHERE user_id = #{userId} AND statistics_time = #{statisticsTime}
+        WHERE user_id = #{userId} AND statistics_time = date_format(#{statisticsTime},'%y%m%d')
     </update>
 
     <!-- 5. 根据ID查询 -->
@@ -332,16 +192,22 @@
     <select id="selectByUserAndDate" resultType="com.fs.company.domain.ComprehensiveDailyStats">
         SELECT <include refid="Base_Column_List"/>
         FROM user_daily_stats
-        WHERE user_id = #{userId} AND statistics_time = #{statisticsTime}
+        WHERE user_id = #{userId} AND statistics_time =date_format(#{statisticsTime},'%y%m%d')
     </select>
 
-    <!-- 7. 根据公司ID和日期范围查询 -->
-    <select id="selectByCompanyAndDateRange" resultType="com.fs.company.domain.ComprehensiveDailyStats">
+    <!-- 6. 根据用户ID和统计日期查询 -->
+    <select id="countByUserAndDate" resultType="java.lang.Integer">
+        SELECT count(id)
+        FROM user_daily_stats
+        WHERE user_id = #{userId} AND statistics_time = date_format(#{statisticsTime},'%y%m%d')
+    </select>
+
+    <!-- 8. 根据部门ID和日期查询 -->
+    <select id="selectByDeptAndDate" resultType="com.fs.company.domain.ComprehensiveDailyStats">
         SELECT <include refid="Base_Column_List"/>
         FROM user_daily_stats
-        WHERE company_id = #{companyId}
-        AND statistics_time BETWEEN #{startTime} AND #{endTime}
-        ORDER BY statistics_time ASC
+        WHERE dept_id = #{deptId}
+        AND statistics_time = date_format(#{statisticsTime},'%y%m%d')
     </select>
 
     <!-- 8. 根据部门ID和日期范围查询 -->
@@ -353,6 +219,15 @@
         ORDER BY statistics_time ASC
     </select>
 
+    <!-- 7. 根据公司ID和日期范围查询 -->
+    <select id="selectByCompanyAndDateRange" resultType="com.fs.company.domain.ComprehensiveDailyStats">
+        SELECT <include refid="Base_Column_List"/>
+        FROM user_daily_stats
+        WHERE company_id = #{companyId}
+        AND statistics_time BETWEEN #{startTime} AND #{endTime}
+        ORDER BY statistics_time ASC
+    </select>
+
     <!-- 9. 删除数据(根据ID) -->
     <delete id="deleteById" parameterType="java.lang.Long">
         DELETE FROM user_daily_stats WHERE id = #{id}
@@ -360,7 +235,7 @@
 
     <!-- 10. 删除数据(根据用户ID和统计日期) -->
     <delete id="deleteByUserAndDate">
-        DELETE FROM user_daily_stats WHERE user_id = #{userId} AND statistics_time = #{statisticsTime}
+        DELETE FROM user_daily_stats WHERE user_id = #{userId} AND statistics_time = date_format(#{statisticsTime},'%y%m%d')
     </delete>
 
 </mapper>

+ 3 - 2
fs-service/src/main/resources/mapper/course/FsCourseLinkMapper.xml

@@ -135,7 +135,7 @@
         link, real_link, create_time, update_time,
         company_id, company_user_id, qw_user_id, video_id,
         corp_id, course_id, qw_external_id, link_type,
-        is_room
+        is_room,chat_id
         )
         VALUES
         <foreach collection="courseLinks" item="item" separator=",">
@@ -152,7 +152,8 @@
             #{item.courseId,jdbcType=BIGINT},
             #{item.qwExternalId,jdbcType=BIGINT},
             #{item.linkType,jdbcType=BIGINT},
-            #{item.isRoom,jdbcType=VARCHAR}
+            #{item.isRoom,jdbcType=VARCHAR},
+            #{item.chatId,jdbcType=VARCHAR}
             )
         </foreach>
     </insert>