Explorar o código

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

caoliqin hai 1 semana
pai
achega
d96620260a

+ 2 - 15
fs-admin/src/main/java/com/fs/stats/SalesWatchStatisController.java

@@ -1,17 +1,10 @@
 package com.fs.stats;
 
 import com.fs.common.core.domain.R;
-import com.fs.common.core.page.TableDataInfo;
-import com.fs.company.mapper.CompanyMapper;
-import com.fs.company.service.ICompanyService;
-import com.fs.company.vo.CompanyDataVO;
 import com.fs.sop.service.IQwSopService;
 import com.fs.sop.vo.QwSopTask;
-import com.fs.statis.domain.FsStatisPeriodWatch;
 import com.fs.statis.domain.FsStatisSalerWatch;
 import com.fs.statis.dto.StatsWatchLogPageListDTO;
-import com.fs.statis.service.FsStatisEveryDayWatchService;
-import com.fs.statis.service.FsStatisPeriodWatchService;
 import com.fs.statis.service.FsStatisSalerWatchService;
 import lombok.AllArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -30,12 +23,6 @@ public class SalesWatchStatisController {
     @Autowired
     private FsStatisSalerWatchService fsStatisSalerWatchService;
 
-    @Autowired
-    private FsStatisPeriodWatchService fsStatisPeriodWatchService;
-
-    @Autowired
-    private FsStatisEveryDayWatchService fsStatisEveryDayWatchService;
-
     @Autowired
     private IQwSopService qwSopService;
 
@@ -57,7 +44,7 @@ public class SalesWatchStatisController {
      */
     @PostMapping("/period/pageList")
     public R periodQueryList(@RequestBody StatsWatchLogPageListDTO param){
-        List<FsStatisPeriodWatch> list = fsStatisPeriodWatchService.queryList(param);
+        List<FsStatisSalerWatch> list = fsStatisSalerWatchService.queryPeriodList(param);
         return R.ok().put("data", list);
     }
 
@@ -68,7 +55,7 @@ public class SalesWatchStatisController {
      */
     @PostMapping("/everyDay/pageList")
     public R everyDayQueryList(@RequestBody StatsWatchLogPageListDTO param){
-        List<FsStatisSalerWatch> list = fsStatisEveryDayWatchService.queryList(param);
+        List<FsStatisSalerWatch> list = fsStatisSalerWatchService.queryTodayList(param);
         return R.ok().put("data", list);
     }
 

+ 16 - 0
fs-admin/src/main/java/com/fs/task/FsCourseTask.java

@@ -3,6 +3,7 @@ package com.fs.task;
 import com.fs.course.service.IFsCourseWatchLogService;
 import com.fs.qw.service.IHyWorkTaskService;
 import com.fs.qw.service.IQwWorkTaskService;
+import com.fs.statis.service.FsStatisSalerWatchService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -17,6 +18,8 @@ public class FsCourseTask {
     private IFsCourseWatchLogService fsCourseWatchLogService;
     @Autowired
     private IHyWorkTaskService hyWorkTaskService;
+    @Autowired
+    private FsStatisSalerWatchService fsStatisSalerWatchService;
     /**
      * 添加会员观看日志
      * @throws Exception
@@ -45,4 +48,17 @@ public class FsCourseTask {
         hyWorkTaskService.hyWorkTask();
     }
 
+    /**
+     * 看课统计
+     */
+    public void watchCourseStatis(){
+        fsStatisSalerWatchService.writeData();
+    }
+
+    /**
+     * 看课统计-统计当天的-每15分钟统计一次
+     */
+    public void watchCourseStatisToday(){
+        fsStatisSalerWatchService.writeDataToday();
+    }
 }

+ 3 - 0
fs-service-system/src/main/java/com/fs/company/mapper/CompanyUserMapper.java

@@ -276,4 +276,7 @@ public interface CompanyUserMapper
 
     Long queryCompanyUserWatchCountCompleted(@Param("companyUserId") Long companyUserId,
                                              @Param("previousDay") LocalDate previousDay);
+
+    Long queryCompanyUserInterruptCount(@Param("companyUserId") Long companyUserId,
+                                        @Param("previousDay") LocalDate previousDay);
 }

+ 2 - 0
fs-service-system/src/main/java/com/fs/sop/mapper/QwSopLogsMapper.java

@@ -294,4 +294,6 @@ public interface QwSopLogsMapper extends BaseMapper<QwSopLogs> {
                                         @Param("periodId") String periodId,
                                         @Param("previousDay") LocalDate previousDay);
 
+    @DataSource(DataSourceType.SOP)
+    String queryPeriodNameById(@Param("periodId") String periodId);
 }

+ 8 - 0
fs-service-system/src/main/java/com/fs/statis/domain/FsStatisSalerWatch.java

@@ -57,6 +57,10 @@ public class FsStatisSalerWatch {
      * 完课人数
      */
     private Long completedNum;
+    /**
+     * 看课中断数
+     */
+    private Long interruptNum;
 
     /**
      * 报名率
@@ -113,6 +117,10 @@ public class FsStatisSalerWatch {
      */
     private String periodId;
 
+    /**
+     * 营期名称
+     */
+    private String periodName;
     /**
      * 数据日期
      */

+ 5 - 0
fs-service-system/src/main/java/com/fs/statis/mapper/FsStatisSalerWatchMapper.java

@@ -83,4 +83,9 @@ public interface FsStatisSalerWatchMapper {
     List<FsStatisSalerWatch> queryList(StatsWatchLogPageListDTO param);
 
     void batchSave(@Param("list") List<FsStatisSalerWatch> writeData);
+
+
+    List<FsStatisSalerWatch> queryPeriodList(StatsWatchLogPageListDTO param);
+    List<FsStatisSalerWatch> queryTodayList(StatsWatchLogPageListDTO param);
+
 }

+ 0 - 47
fs-service-system/src/main/java/com/fs/statis/service/FsStatisEveryDayWatchService.java

@@ -1,47 +0,0 @@
-package com.fs.statis.service;
-
-import com.fs.statis.domain.FsStatisEveryDayWatch;
-import com.fs.statis.domain.FsStatisSalerWatch;
-import com.fs.statis.dto.StatsWatchLogPageListDTO;
-
-import java.util.List;
-
-/**
- * 每日统计数据服务接口
- */
-public interface FsStatisEveryDayWatchService {
-
-    /**
-     * 根据主键ID查询每日统计数据
-     *
-     * @param id 主键ID
-     * @return 每日统计数据对象,如果不存在则返回null
-     */
-    FsStatisEveryDayWatch findById(Integer id);
-
-    /**
-     * 新增每日统计数据
-     *
-     * @param fsStatisEveryDayWatch 待插入的每日统计数据对象
-     * @return 影响的行数,通常是1表示成功
-     */
-    int create(FsStatisEveryDayWatch fsStatisEveryDayWatch);
-
-    /**
-     * 更新每日统计数据
-     *
-     * @param fsStatisEveryDayWatch 待更新的每日统计数据对象 (必须包含ID)
-     * @return 影响的行数,通常是1表示成功,0表示未找到对应记录
-     */
-    int update(FsStatisEveryDayWatch fsStatisEveryDayWatch);
-
-    /**
-     * 查询所有每日统计数据
-     *
-     * @return 每日统计数据列表
-     */
-    List<FsStatisEveryDayWatch> findAll();
-
-    List<FsStatisSalerWatch> queryList(StatsWatchLogPageListDTO param);
-
-}

+ 0 - 58
fs-service-system/src/main/java/com/fs/statis/service/FsStatisPeriodWatchService.java

@@ -1,58 +0,0 @@
-package com.fs.statis.service; // 假设Service接口放在此包下
-
-import com.fs.statis.domain.FsStatisPeriodWatch;
-import com.fs.statis.dto.StatsWatchLogPageListDTO;
-
-import java.util.List;
-
-/**
- * 训练营周期统计数据服务接口
- * 对应表 fs_statis_period_watch
- */
-public interface FsStatisPeriodWatchService {
-
-    /**
-     * 根据主键ID查询训练营周期统计数据
-     *
-     * @param id 主键ID
-     * @return 训练营周期统计数据对象,如果不存在则返回null
-     */
-    FsStatisPeriodWatch findById(Integer id);
-
-    /**
-     * 新增训练营周期统计数据
-     *
-     * @param fsStatisPeriodWatch 待插入的训练营周期统计数据对象
-     * @return 影响的行数,通常是1表示成功
-     */
-    int create(FsStatisPeriodWatch fsStatisPeriodWatch);
-
-    /**
-     * 根据主键更新训练营周期统计数据
-     * (只会更新实体中非null的字段)
-     *
-     * @param fsStatisPeriodWatch 待更新的训练营周期统计数据对象 (必须包含ID)
-     * @return 影响的行数,通常是1表示成功,0表示未找到对应记录或未更新任何字段
-     */
-    int updateById(FsStatisPeriodWatch fsStatisPeriodWatch);
-
-    /**
-     * 根据主键ID删除训练营周期统计数据
-     *
-     * @param id 主键ID
-     * @return 影响的行数
-     */
-    int deleteById(Integer id);
-
-    /**
-     * 查询所有训练营周期统计数据
-     *
-     * @return 训练营周期统计数据列表
-     */
-    List<FsStatisPeriodWatch> findAll();
-
-    List<FsStatisPeriodWatch> queryList(StatsWatchLogPageListDTO param);
-
-    void writeData();
-
-}

+ 7 - 0
fs-service-system/src/main/java/com/fs/statis/service/FsStatisSalerWatchService.java

@@ -50,10 +50,17 @@ public interface FsStatisSalerWatchService {
     boolean deleteById(Integer id);
 
     List<FsStatisSalerWatch> queryList(StatsWatchLogPageListDTO param);
+    List<FsStatisSalerWatch> queryPeriodList(StatsWatchLogPageListDTO param);
+    List<FsStatisSalerWatch> queryTodayList(StatsWatchLogPageListDTO param);
 
 
     /**
      * 写入数据 写入前一天的数据
      */
     void writeData();
+
+    /**
+     * 计算每天的数据
+     */
+    void writeDataToday();
 }

+ 0 - 71
fs-service-system/src/main/java/com/fs/statis/service/impl/FsStatisEveryDayWatchServiceImpl.java

@@ -1,71 +0,0 @@
-package com.fs.statis.service.impl;
-
-import com.fs.statis.domain.FsStatisEveryDayWatch;
-import com.fs.statis.domain.FsStatisSalerWatch;
-import com.fs.statis.dto.StatsWatchLogPageListDTO;
-import com.fs.statis.mapper.FsStatisEveryDayWatchMapper;
-import com.fs.statis.service.FsStatisEveryDayWatchService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional; // 引入事务注解
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * 每日统计数据服务实现类
- */
-@Service
-public class FsStatisEveryDayWatchServiceImpl implements FsStatisEveryDayWatchService {
-
-    private final FsStatisEveryDayWatchMapper fsStatisEveryDayWatchMapper;
-
-    /**
-     * 通过构造函数注入Mapper
-     * @param fsStatisEveryDayWatchMapper 每日统计数据Mapper
-     */
-    @Autowired
-    public FsStatisEveryDayWatchServiceImpl(FsStatisEveryDayWatchMapper fsStatisEveryDayWatchMapper) {
-        this.fsStatisEveryDayWatchMapper = fsStatisEveryDayWatchMapper;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public FsStatisEveryDayWatch findById(Integer id) {
-        return fsStatisEveryDayWatchMapper.findById(id);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    @Transactional
-    public int create(FsStatisEveryDayWatch fsStatisEveryDayWatch) {
-        return fsStatisEveryDayWatchMapper.insert(fsStatisEveryDayWatch);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    @Transactional
-    public int update(FsStatisEveryDayWatch fsStatisEveryDayWatch) {
-        return fsStatisEveryDayWatchMapper.update(fsStatisEveryDayWatch);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public List<FsStatisEveryDayWatch> findAll() {
-        return fsStatisEveryDayWatchMapper.findAll();
-    }
-
-    @Override
-    public List<FsStatisSalerWatch> queryList(StatsWatchLogPageListDTO param) {
-        return fsStatisEveryDayWatchMapper.queryList(param);
-    }
-
-}

+ 0 - 114
fs-service-system/src/main/java/com/fs/statis/service/impl/FsStatisPeriodWatchServiceImpl.java

@@ -1,114 +0,0 @@
-package com.fs.statis.service.impl; // 假设Service实现类放在此包下
-
-import com.fs.company.domain.CompanyUser;
-import com.fs.qw.mapper.QwUserMapper;
-import com.fs.sop.domain.SopUserLogs;
-import com.fs.statis.domain.FsStatisPeriodWatch;
-import com.fs.statis.domain.FsStatisSalerWatch;
-import com.fs.statis.dto.StatsWatchLogPageListDTO;
-import com.fs.statis.mapper.FsStatisPeriodWatchMapper;
-import com.fs.statis.service.FsStatisPeriodWatchService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.time.LocalDate;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * 训练营周期统计数据服务实现类
- */
-@Service
-public class FsStatisPeriodWatchServiceImpl implements FsStatisPeriodWatchService {
-
-    private final FsStatisPeriodWatchMapper fsStatisPeriodWatchMapper;
-
-    private final QwUserMapper qwUserMapper;
-
-    /**
-     * 通过构造函数注入Mapper
-     * @param fsStatisPeriodWatchMapper 训练营周期统计数据Mapper
-     */
-    @Autowired
-    public FsStatisPeriodWatchServiceImpl(FsStatisPeriodWatchMapper fsStatisPeriodWatchMapper, QwUserMapper qwUserMapper) {
-        this.fsStatisPeriodWatchMapper = fsStatisPeriodWatchMapper;
-        this.qwUserMapper = qwUserMapper;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public FsStatisPeriodWatch findById(Integer id) {
-        return fsStatisPeriodWatchMapper.selectById(id);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    @Transactional // 标记此方法需要事务管理
-    public int create(FsStatisPeriodWatch fsStatisPeriodWatch) {
-        // 在这里可以添加业务逻辑,例如参数校验等
-        return fsStatisPeriodWatchMapper.insert(fsStatisPeriodWatch);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    @Transactional // 标记此方法需要事务管理
-    public int updateById(FsStatisPeriodWatch fsStatisPeriodWatch) {
-        // 在这里可以添加业务逻辑,例如检查记录是否存在,或在更新前进行特定校验
-        // 注意:Mapper中的updateById是动态SQL,只更新非null字段
-        return fsStatisPeriodWatchMapper.updateById(fsStatisPeriodWatch);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    @Transactional // 标记此方法需要事务管理
-    public int deleteById(Integer id) {
-        // 在这里可以添加业务逻辑,例如检查关联数据等
-        return fsStatisPeriodWatchMapper.deleteById(id);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public List<FsStatisPeriodWatch> findAll() {
-        return fsStatisPeriodWatchMapper.selectAll();
-    }
-
-    @Override
-    public List<FsStatisPeriodWatch> queryList(StatsWatchLogPageListDTO param) {
-        return fsStatisPeriodWatchMapper.queryList(param);
-    }
-
-    @Override
-    public void writeData() {
-//        LocalDate previousDay = LocalDate.now().minusDays(1);
-//
-//        // 获取每个sop任务
-//        List<SopUserLogs> list = fsStatisPeriodWatchMapper.selectRecords(previousDay);
-//        for (SopUserLogs logs : list) {
-//            // 根据sop任务营期id 获取当前任务的企微id列表
-//            String qwUserId = logs.getQwUserId();
-//            // 转换企微id列表为对应的销售
-//            Long companyUserId = qwUserMapper.selectCompanyIdByQwUserId(qwUserId);
-//            FsStatisPeriodWatch fsStatisPeriodWatch = new FsStatisPeriodWatch();
-//            fsStatisPeriodWatch.setPeriodId(logs.getId());
-//            fsStatisPeriodWatch.setDataDate(previousDay);
-//
-//            // 获取当前的训练营人数
-//
-//
-//            // for 获取
-//        }
-
-    }
-}

+ 136 - 1
fs-service-system/src/main/java/com/fs/statis/service/impl/FsStatisSalerWatchServiceImpl.java

@@ -25,6 +25,7 @@ import org.springframework.stereotype.Service;
 
 import java.time.LocalDate;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
@@ -142,6 +143,71 @@ public class FsStatisSalerWatchServiceImpl implements FsStatisSalerWatchService
                     item.setCompanyUserName(companyUserName);
                 }
             }
+
+            if(item.getPeriodId() != null) {
+                String periodName = qwSopLogsMapper.queryPeriodNameById(item.getPeriodId());
+                if(StringUtils.isNotEmpty(periodName)) {
+                    item.setPeriodName(periodName);
+                }
+            }
+
+
+        }
+        return fsStatisSalerWatches;
+    }
+
+    @Override
+    public List<FsStatisSalerWatch> queryPeriodList(StatsWatchLogPageListDTO param) {
+        List<FsStatisSalerWatch> fsStatisSalerWatches = fsStatisSalerWatchMapper.queryPeriodList(param);
+        for (FsStatisSalerWatch item : fsStatisSalerWatches) {
+            if(item.getDeptId() != null) {
+                CompanyDept companyDept = companyDeptMapper.selectCompanyDeptById(item.getDeptId());
+                if(ObjectUtils.isNotNull(companyDept)) {
+                    item.setDeptName(companyDept.getDeptName());
+                }
+            }
+            if(item.getCompanyUserId() != null) {
+                String companyUserName = companyUserCacheService.selectCompanyUserNameUserById(item.getCompanyUserId());
+                if(StringUtils.isNotEmpty(companyUserName)){
+                    item.setCompanyUserName(companyUserName);
+                }
+            }
+
+            if(item.getPeriodId() != null) {
+                String periodName = qwSopLogsMapper.queryPeriodNameById(item.getPeriodId());
+                if(StringUtils.isNotEmpty(periodName)) {
+                    item.setPeriodName(periodName);
+                }
+            }
+
+        }
+        return fsStatisSalerWatches;
+    }
+
+    @Override
+    public List<FsStatisSalerWatch> queryTodayList(StatsWatchLogPageListDTO param) {
+        List<FsStatisSalerWatch> fsStatisSalerWatches = fsStatisSalerWatchMapper.queryTodayList(param);
+        for (FsStatisSalerWatch item : fsStatisSalerWatches) {
+            if(item.getDeptId() != null) {
+                CompanyDept companyDept = companyDeptMapper.selectCompanyDeptById(item.getDeptId());
+                if(ObjectUtils.isNotNull(companyDept)) {
+                    item.setDeptName(companyDept.getDeptName());
+                }
+            }
+            if(item.getCompanyUserId() != null) {
+                String companyUserName = companyUserCacheService.selectCompanyUserNameUserById(item.getCompanyUserId());
+                if(StringUtils.isNotEmpty(companyUserName)){
+                    item.setCompanyUserName(companyUserName);
+                }
+            }
+
+            if(item.getPeriodId() != null) {
+                String periodName = qwSopLogsMapper.queryPeriodNameById(item.getPeriodId());
+                if(StringUtils.isNotEmpty(periodName)) {
+                    item.setPeriodName(periodName);
+                }
+            }
+
         }
         return fsStatisSalerWatches;
     }
@@ -182,7 +248,8 @@ public class FsStatisSalerWatchServiceImpl implements FsStatisSalerWatchService
                 // 再去course_watch_log找对应的销售观看记录作为已报名数
                 Long registerCount = companyUserMapper.queryCompanyUserWatchCount(companyUser.getUserId(),previousDay);
                 Long completedCount = companyUserMapper.queryCompanyUserWatchCountCompleted(companyUser.getUserId(),previousDay);
-
+                // 当前销售当天的看课中断数量
+                Long interruptCount = companyUserMapper.queryCompanyUserInterruptCount(companyUser.getUserId(),previousDay);
 
                 FsStatisSalerWatch fsStatisSalerWatch = new FsStatisSalerWatch();
                 fsStatisSalerWatch.setDeptId(companyUser.getDeptId());
@@ -191,6 +258,7 @@ public class FsStatisSalerWatchServiceImpl implements FsStatisSalerWatchService
                 fsStatisSalerWatch.setNotRegisteredNum(Math.max(0, periodCount - registerCount));
                 fsStatisSalerWatch.setRegisteredNum(registerCount);
                 fsStatisSalerWatch.setCompletedNum(completedCount);
+                fsStatisSalerWatch.setInterruptNum(interruptCount);
 
                 // 修复比率计算
                 float regRate = (periodCount > 0) ? (float) registerCount / periodCount : 0.0f;
@@ -210,4 +278,71 @@ public class FsStatisSalerWatchServiceImpl implements FsStatisSalerWatchService
             fsStatisSalerWatchMapper.batchSave(writeData);
         }
     }
+
+    @Override
+    public void writeDataToday() {
+        // 统计销售看课情况
+        // 获取前一天的时间
+        List<CompanyUser> companyUserList = this.companyUserMapper.selectAllCompanyUserList();
+
+        List<FsStatisSalerWatch> writeData = new ArrayList<>();
+
+        LocalDate nowDay = LocalDate.now();
+        for (CompanyUser companyUser : companyUserList) {
+
+            if(companyUser.getCompanyId() == null) {
+                log.info("销售{} 对应公司id {} 为空!",companyUser.getUserId(),companyUser.getCompanyId());
+                continue;
+            }
+            // 找到销售关联的 企微账号
+            List<String> qwUserIdList = qwUserMapper.findQwUserIdListByCompanyUserId(companyUser.getUserId());
+            if(CollectionUtils.isEmpty(qwUserIdList)){
+                log.info("当前销售 {} 没有关联企微账号!",companyUser.getUserId());
+                continue;
+            }
+
+            // 确定当前销售对应的sop任务的执行记录
+            List<String> periodList = sopUserLogsMapper.selectSopUserLogsByQwUserIds(qwUserIdList);
+
+            if(CollectionUtils.isEmpty(periodList)){
+                log.info("当前销售 {} 没有相关的SOP营期!", companyUser.getUserId());
+                continue;
+            }
+
+            for (String periodId : periodList) {
+                // 去sop记录表找对应的SOP发送记录,记录数作为营期人数
+                Long periodCount = qwSopLogsMapper.selectQwSopLogsCountByQwUserId(qwUserIdList,periodId,nowDay);
+                // 再去course_watch_log找对应的销售观看记录作为已报名数
+                Long registerCount = companyUserMapper.queryCompanyUserWatchCount(companyUser.getUserId(),nowDay);
+                Long completedCount = companyUserMapper.queryCompanyUserWatchCountCompleted(companyUser.getUserId(),nowDay);
+                // 当前销售当天的看课中断数量
+                Long interruptCount = companyUserMapper.queryCompanyUserInterruptCount(companyUser.getUserId(),nowDay);
+
+                FsStatisSalerWatch fsStatisSalerWatch = new FsStatisSalerWatch();
+                fsStatisSalerWatch.setDeptId(companyUser.getDeptId());
+                fsStatisSalerWatch.setCompanyUserId(companyUser.getUserId());
+                fsStatisSalerWatch.setTrainCampNum(periodCount);
+                fsStatisSalerWatch.setNotRegisteredNum(Math.max(0, periodCount - registerCount));
+                fsStatisSalerWatch.setRegisteredNum(registerCount);
+                fsStatisSalerWatch.setCompletedNum(completedCount);
+                fsStatisSalerWatch.setInterruptNum(interruptCount);
+
+                // 修复比率计算
+                float regRate = (periodCount > 0) ? (float) registerCount / periodCount : 0.0f;
+                float finishedRate = (registerCount > 0) ? (float) completedCount / registerCount : 0.0f;
+
+                fsStatisSalerWatch.setRegRate(regRate);
+                fsStatisSalerWatch.setFinishedRate(finishedRate);
+                fsStatisSalerWatch.setDataDate(nowDay);
+
+                fsStatisSalerWatch.setPeriodId(periodId);
+
+                writeData.add(fsStatisSalerWatch);
+            }
+        }
+
+        if(CollectionUtils.isNotEmpty(writeData)){
+            fsStatisSalerWatchMapper.batchSave(writeData);
+        }
+    }
 }

+ 12 - 0
fs-service-system/src/main/resources/mapper/company/CompanyUserMapper.xml

@@ -525,6 +525,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             </if>
         </where>
     </select>
+    <select id="queryCompanyUserInterruptCount" resultType="java.lang.Long">
+        select count(1) from fs_course_watch_log
+        <where>
+            AND log_type = 4
+            <if test="companyUserId != null">
+                AND company_user_id = #{companyUserId}
+            </if>
+            <if test="previousDay != null">
+                and camp_period_time = ${previousDay}
+            </if>
+        </where>
+    </select>
 
     <update id="setIsRegisterMember" parameterType="Long">
         update company_user

+ 3 - 0
fs-service-system/src/main/resources/mapper/sop/QwSopLogsMapper.xml

@@ -569,6 +569,9 @@
         </where>
 
     </select>
+    <select id="queryPeriodNameById" resultType="java.lang.String">
+        select concat(qw_user_id,'-',start_time) from sop_user_logs where id=#{periodId}
+    </select>
 
 
     <!-- 批量更新 QwSopLogs -->

+ 133 - 20
fs-service-system/src/main/resources/mapper/statis/FsStatisSalerWatchMapper.xml

@@ -31,28 +31,36 @@
     </sql>
 
     <select id="queryList" resultType="com.fs.statis.domain.FsStatisSalerWatch">
-        select
-                company_user_id,
-                ANY_VALUE(dept_id) as dept_id,
-               sum(train_camp_num) as train_camp_num,
-               sum(not_registered_num) as not_registered_num,
-               sum(registered_num) as registered_num,
-               sum(reg_rate) as reg_rate,
-               sum(finished_rate) as finished_rate,
-               sum(offline_total) as offline_total,
-               sum(offline_not_part) as offline_not_part,
-               sum(offline_not_watched) as offline_not_watched,
-               sum(online_total) as online_total,
-               sum(online_online_rate) as online_online_rate,
-               sum(online_playback_comple_rate) as online_playback_comple_rate,
-               sum(online_incomplete_playback) as online_incomplete_playback,
-               sum(online_complete_playback) as online_complete_playback
-               from fs_statis_saler_watch
+        SELECT
+        company_user_id,
+        ANY_VALUE(dept_id) as dept_id,
+        SUM(train_camp_num) as train_camp_num,
+        SUM(not_registered_num) as not_registered_num,
+        SUM(registered_num) as registered_num,
+        SUM(offline_total) as offline_total,
+        SUM(offline_not_part) as offline_not_part,
+        SUM(offline_not_watched) as offline_not_watched,
+        SUM(online_total) as online_total,
+        SUM(online_incomplete_playback) as online_incomplete_playback,
+        SUM(online_complete_playback) as online_complete_playback,
+        CASE WHEN SUM(train_camp_num) > 0
+        THEN ROUND(SUM(registered_num) * 1.0 / SUM(train_camp_num), 4)
+        ELSE 0 END as reg_rate,
+        CASE WHEN SUM(registered_num) > 0
+        THEN ROUND((SUM(registered_num) - SUM(not_registered_num)) * 1.0 / SUM(registered_num), 4)
+        ELSE 0 END as finished_rate,
+        CASE WHEN SUM(online_total) > 0
+        THEN ROUND(SUM(online_complete_playback) * 1.0 / SUM(online_total), 4)
+        ELSE 0 END as online_online_rate,
+        CASE WHEN SUM(online_total) > 0
+        THEN ROUND(SUM(online_complete_playback) * 1.0 / SUM(online_total), 4)
+        ELSE 0 END as online_playback_comple_rate
+        FROM fs_statis_saler_watch
         <where>
             <if test="userIds != null and userIds.size() > 0">
                 AND company_user_id IN
-                 <foreach collection="userIds" open="(" close=")" separator="," item="item">
-                     ${item}
+                <foreach collection="userIds" open="(" close=")" separator="," item="item">
+                    ${item}
                 </foreach>
             </if>
             <if test="periodList != null and periodList.size() > 0">
@@ -65,8 +73,99 @@
                 AND data_date BETWEEN #{startDate} AND #{endDate}
             </if>
         </where>
-        group by company_user_id,data_date
+        GROUP BY company_user_id
     </select>
+    <select id="queryPeriodList" resultType="com.fs.statis.domain.FsStatisSalerWatch">
+        SELECT
+        period_id,
+        ANY_VALUE(dept_id) as dept_id,
+        SUM(train_camp_num) as train_camp_num,
+        SUM(not_registered_num) as not_registered_num,
+        SUM(registered_num) as registered_num,
+        SUM(offline_total) as offline_total,
+        SUM(offline_not_part) as offline_not_part,
+        SUM(offline_not_watched) as offline_not_watched,
+        SUM(online_total) as online_total,
+        SUM(online_incomplete_playback) as online_incomplete_playback,
+        SUM(online_complete_playback) as online_complete_playback,
+        CASE WHEN SUM(train_camp_num) > 0
+        THEN ROUND(SUM(registered_num) * 1.0 / SUM(train_camp_num), 4)
+        ELSE 0 END as reg_rate,
+        CASE WHEN SUM(registered_num) > 0
+        THEN ROUND((SUM(registered_num) - SUM(not_registered_num)) * 1.0 / SUM(registered_num), 4)
+        ELSE 0 END as finished_rate,
+        CASE WHEN SUM(online_total) > 0
+        THEN ROUND(SUM(online_complete_playback) * 1.0 / SUM(online_total), 4)
+        ELSE 0 END as online_online_rate,
+        CASE WHEN SUM(online_total) > 0
+        THEN ROUND(SUM(online_complete_playback) * 1.0 / SUM(online_total), 4)
+        ELSE 0 END as online_playback_comple_rate
+        FROM fs_statis_saler_watch
+        <where>
+            <if test="userIds != null and userIds.size() > 0">
+                AND company_user_id IN
+                <foreach collection="userIds" open="(" close=")" separator="," item="item">
+                    ${item}
+                </foreach>
+            </if>
+            <if test="periodList != null and periodList.size() > 0">
+                AND period_id IN
+                <foreach collection="periodList" open="(" close=")" separator="," item="item">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="startDate != null and endDate != null">
+                AND data_date BETWEEN #{startDate} AND #{endDate}
+            </if>
+        </where>
+        GROUP BY period_id
+    </select>
+    <select id="queryTodayList" resultType="com.fs.statis.domain.FsStatisSalerWatch">
+        SELECT
+        data_date,
+        ANY_VALUE(dept_id) as dept_id,
+        SUM(train_camp_num) as train_camp_num,
+        SUM(not_registered_num) as not_registered_num,
+        SUM(registered_num) as registered_num,
+        SUM(offline_total) as offline_total,
+        SUM(offline_not_part) as offline_not_part,
+        SUM(offline_not_watched) as offline_not_watched,
+        SUM(online_total) as online_total,
+        SUM(online_incomplete_playback) as online_incomplete_playback,
+        SUM(online_complete_playback) as online_complete_playback,
+        CASE WHEN SUM(train_camp_num) > 0
+        THEN ROUND(SUM(registered_num) * 1.0 / SUM(train_camp_num), 4)
+        ELSE 0 END as reg_rate,
+        CASE WHEN SUM(registered_num) > 0
+        THEN ROUND((SUM(registered_num) - SUM(not_registered_num)) * 1.0 / SUM(registered_num), 4)
+        ELSE 0 END as finished_rate,
+        CASE WHEN SUM(online_total) > 0
+        THEN ROUND(SUM(online_complete_playback) * 1.0 / SUM(online_total), 4)
+        ELSE 0 END as online_online_rate,
+        CASE WHEN SUM(online_total) > 0
+        THEN ROUND(SUM(online_complete_playback) * 1.0 / SUM(online_total), 4)
+        ELSE 0 END as online_playback_comple_rate
+        FROM fs_statis_saler_watch
+        <where>
+            <if test="userIds != null and userIds.size() > 0">
+                AND company_user_id IN
+                <foreach collection="userIds" open="(" close=")" separator="," item="item">
+                    ${item}
+                </foreach>
+            </if>
+            <if test="periodList != null and periodList.size() > 0">
+                AND period_id IN
+                <foreach collection="periodList" open="(" close=")" separator="," item="item">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="startDate != null and endDate != null">
+                AND data_date BETWEEN #{startDate} AND #{endDate}
+            </if>
+        </where>
+        GROUP BY data_date
+    </select>
+
 
     <insert id="batchSave">
         INSERT INTO fs_statis_saler_watch (
@@ -98,6 +197,20 @@
                 #{item.dataDate,jdbcType=VARCHAR}
             )
         </foreach>
+        ON DUPLICATE KEY UPDATE
+        train_camp_num = VALUES(train_camp_num),
+        not_registered_num = VALUES(not_registered_num),
+        registered_num = VALUES(registered_num),
+        reg_rate = VALUES(reg_rate),
+        finished_rate = VALUES(finished_rate),
+        offline_total = VALUES(offline_total),
+        offline_not_part = VALUES(offline_not_part),
+        offline_not_watched = VALUES(offline_not_watched),
+        online_total = VALUES(online_total),
+        online_online_rate = VALUES(online_online_rate),
+        online_playback_comple_rate = VALUES(online_playback_comple_rate),
+        online_incomplete_playback = VALUES(online_incomplete_playback),
+        online_complete_playback = VALUES(online_complete_playback)
     </insert>
 
 </mapper>