Browse Source

进线客户统计

xdd 1 month ago
parent
commit
c0bf265184

+ 4 - 8
fs-admin/src/main/java/com/fs/course/controller/FsCourseWatchLogController.java

@@ -6,6 +6,7 @@ import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.enums.BusinessType;
+import com.fs.common.exception.CustomException;
 import com.fs.common.utils.ServletUtils;
 import com.fs.common.utils.poi.ExcelUtil;
 import com.fs.core.security.LoginUser;
@@ -74,7 +75,7 @@ public class FsCourseWatchLogController extends BaseController
     public TableDataInfo statisticsList(FsCourseWatchLogStatisticsListParam param)
     {
         if(param.getCompanyId() == null){
-            throw new IllegalArgumentException("必须选择公司!");
+            throw new CustomException("必须选择公司!");
         }
         if (param.getSTime()==null||param.getETime()==null){
             return getDataTable(new ArrayList<>());
@@ -117,26 +118,21 @@ public class FsCourseWatchLogController extends BaseController
     @GetMapping("/qwWatchLogAllStatisticsList")
     public TableDataInfo qwWatchLogAllStatisticsList(QwWatchLogStatisticsListParam param)
     {
-        startPage();
-        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         if (param.getSTime()==null||param.getETime()==null){
             return getDataTable(new ArrayList<>());
         }
-        List<QwWatchLogAllStatisticsListVO> list = qwWatchLogService.selectQwWatchLogAllStatisticsListVONew(param);
-        return getDataTable(list);
+        return qwWatchLogService.selectQwWatchLogAllStatisticsListVONew(param);
     }
     @GetMapping("/myQwWatchLogAllStatisticsList")
     public TableDataInfo myQwWatchLogAllStatisticsList(QwWatchLogStatisticsListParam param)
     {
-        startPage();
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
 
         param.setCompanyUserId(loginUser.getUser().getUserId());
         if (param.getSTime()==null||param.getETime()==null){
             return getDataTable(new ArrayList<>());
         }
-        List<QwWatchLogAllStatisticsListVO> list = qwWatchLogService.selectQwWatchLogAllStatisticsListVONew(param);
-        return getDataTable(list);
+        return qwWatchLogService.selectQwWatchLogAllStatisticsListVONew(param);
     }
     @GetMapping("/watchLogStatistics")
     public TableDataInfo watchLogStatistics(FsCourseOverParam param)

+ 6 - 8
fs-admin/src/main/java/com/fs/course/controller/qw/QwFsCourseWatchLogController.java

@@ -5,6 +5,7 @@ import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.enums.BusinessType;
+import com.fs.common.exception.CustomException;
 import com.fs.common.utils.ServletUtils;
 import com.fs.common.utils.poi.ExcelUtil;
 import com.fs.core.security.LoginUser;
@@ -85,25 +86,24 @@ public class QwFsCourseWatchLogController extends BaseController
     @GetMapping("/qwWatchLogStatisticsList")
     public TableDataInfo qwWatchLogStatisticsList(QwWatchLogStatisticsListParam param)
     {
-        startPage();
         if (param.getSTime()==null||param.getETime()==null){
             return getDataTable(new ArrayList<>());
         }
-        List<QwWatchLogStatisticsListVO> list = qwWatchLogService.selectQwWatchLogStatisticsListVO(param);
-        return getDataTable(list);
+        if(param.getCompanyId() == null){
+            throw new CustomException("必须选择公司!");
+        }
+        return qwWatchLogService.selectQwWatchLogStatisticsListVO(param);
     }
     @GetMapping("/myQwWatchLogStatisticsList")
     public TableDataInfo myQwWatchLogStatisticsList(QwWatchLogStatisticsListParam param)
     {
-        startPage();
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
 
         param.setCompanyUserId(loginUser.getUser().getUserId());
         if (param.getSTime()==null||param.getETime()==null){
             return getDataTable(new ArrayList<>());
         }
-        List<QwWatchLogStatisticsListVO> list = qwWatchLogService.selectQwWatchLogStatisticsListVO(param);
-        return getDataTable(list);
+        return qwWatchLogService.selectQwWatchLogStatisticsListVO(param);
     }
 
 
@@ -111,8 +111,6 @@ public class QwFsCourseWatchLogController extends BaseController
     public TableDataInfo qwWatchLogAllStatisticsList(QwWatchLogStatisticsListParam param)
     {
         startPage();
-        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
-
         if (param.getSTime()==null||param.getETime()==null){
             return getDataTable(new ArrayList<>());
         }

+ 2 - 6
fs-company/src/main/java/com/fs/course/controller/FsCourseWatchLogController.java

@@ -115,27 +115,23 @@ public class FsCourseWatchLogController extends BaseController
     @GetMapping("/qwWatchLogAllStatisticsList")
     public TableDataInfo qwWatchLogAllStatisticsList(QwWatchLogStatisticsListParam param)
     {
-        startPage();
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         param.setCompanyId( loginUser.getCompany().getCompanyId());
         if (param.getSTime()==null||param.getETime()==null){
             return getDataTable(new ArrayList<>());
         }
-        List<QwWatchLogAllStatisticsListVO> list = qwWatchLogService.selectQwWatchLogAllStatisticsListVONew(param);
-        return getDataTable(list);
+        return qwWatchLogService.selectQwWatchLogAllStatisticsListVONew(param);
     }
     @GetMapping("/myQwWatchLogAllStatisticsList")
     public TableDataInfo myQwWatchLogAllStatisticsList(QwWatchLogStatisticsListParam param)
     {
-        startPage();
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         param.setCompanyId( loginUser.getCompany().getCompanyId());
         param.setCompanyUserId(loginUser.getUser().getUserId());
         if (param.getSTime()==null||param.getETime()==null){
             return getDataTable(new ArrayList<>());
         }
-        List<QwWatchLogAllStatisticsListVO> list = qwWatchLogService.selectQwWatchLogAllStatisticsListVONew(param);
-        return getDataTable(list);
+        return qwWatchLogService.selectQwWatchLogAllStatisticsListVONew(param);
     }
     @GetMapping("/watchLogStatistics")
     public TableDataInfo watchLogStatistics(FsCourseOverParam param)

+ 2 - 6
fs-company/src/main/java/com/fs/course/controller/qw/QwFsCourseWatchLogController.java

@@ -88,27 +88,23 @@ public class QwFsCourseWatchLogController extends BaseController
     @GetMapping("/qwWatchLogStatisticsList")
     public TableDataInfo qwWatchLogStatisticsList(QwWatchLogStatisticsListParam param)
     {
-        startPage();
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         param.setCompanyId( loginUser.getCompany().getCompanyId());
         if (param.getSTime()==null||param.getETime()==null){
             return getDataTable(new ArrayList<>());
         }
-        List<QwWatchLogStatisticsListVO> list = qwWatchLogService.selectQwWatchLogStatisticsListVO(param);
-        return getDataTable(list);
+        return qwWatchLogService.selectQwWatchLogStatisticsListVO(param);
     }
     @GetMapping("/myQwWatchLogStatisticsList")
     public TableDataInfo myQwWatchLogStatisticsList(QwWatchLogStatisticsListParam param)
     {
-        startPage();
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         param.setCompanyId( loginUser.getCompany().getCompanyId());
         param.setCompanyUserId(loginUser.getUser().getUserId());
         if (param.getSTime()==null||param.getETime()==null){
             return getDataTable(new ArrayList<>());
         }
-        List<QwWatchLogStatisticsListVO> list = qwWatchLogService.selectQwWatchLogStatisticsListVO(param);
-        return getDataTable(list);
+        return qwWatchLogService.selectQwWatchLogStatisticsListVO(param);
     }
 
 

+ 6 - 2
fs-service-system/src/main/java/com/fs/qw/mapper/QwWatchLogMapper.java

@@ -95,6 +95,7 @@ public interface QwWatchLogMapper extends BaseMapper<QwWatchLog>{
             "    qec.qw_user_id, DATE(qec.create_time) \n" +
             "ORDER BY\n" +
             "    DATE(qec.create_time) "+
+            "limit ${(pageNum-1)*pageSize},${pageSize}"+
             "</script>"})
     List<QwWatchLogStatisticsListVO> selectQwExtCountByDayAnd(QwWatchLogStatisticsListParam param);
     @Select("select \n" +
@@ -197,8 +198,7 @@ public interface QwWatchLogMapper extends BaseMapper<QwWatchLog>{
     QwWatchLogAllStatisticsListVO selectQwWatchLogAllStatisticsListVO(@Param("id")Long id,@Param("createTime") Date createTime);
 
 
-    List<QwWatchLogAllStatisticsListVO> selectQwWatchLogAllStatisticsListVONew(@Param("companyUserId")Long companyUserId,
-                                                                               @Param("companyId")Long companyId,
+    List<QwWatchLogAllStatisticsListVO> selectQwWatchLogAllStatisticsListVONew(@Param("companyUserIds") List<Long> userIds,
                                                                                @Param("sDate") Date sDate, @Param("eDate") Date eDate,
                                                                                @Param("project") Long project,
                                                                                @Param("courseId") Long courseId,
@@ -227,4 +227,8 @@ public interface QwWatchLogMapper extends BaseMapper<QwWatchLog>{
             "    DATE(qec.create_time) "+
             "</script>"})
     List<QwWatchLogAllStatisticsListVO> selectQwExtCountByDayAndLine(QwWatchLogStatisticsListParam param);
+
+    Long selectQwExtCountByDayAndCount(QwWatchLogStatisticsListParam param);
+
+    Long selectQwWatchLogAllStatisticsListVONewCount(List<Long> userIds, Date sTime, Date eTime, Long project, Long courseId, Long videoId);
 }

+ 2 - 2
fs-service-system/src/main/java/com/fs/qw/service/IQwWatchLogService.java

@@ -64,12 +64,12 @@ public interface IQwWatchLogService extends IService<QwWatchLog>{
      */
     int deleteQwWatchLogById(Long id);
 
-    List<QwWatchLogStatisticsListVO> selectQwWatchLogStatisticsListVO(QwWatchLogStatisticsListParam param);
+    TableDataInfo selectQwWatchLogStatisticsListVO(QwWatchLogStatisticsListParam param);
     TableDataInfo selectQwWatchLogStatisticsListVONew(QwWatchLogStatisticsListParam param);
     Long selectQwWatchLogStatisticsListVONewCount(QwWatchLogStatisticsListParam param);
 
     List<QwWatchLogAllStatisticsListVO> selectQwWatchLogAllStatisticsListVO(QwWatchLogStatisticsListParam param);
-    List<QwWatchLogAllStatisticsListVO> selectQwWatchLogAllStatisticsListVONew(QwWatchLogStatisticsListParam param);
+    TableDataInfo selectQwWatchLogAllStatisticsListVONew(QwWatchLogStatisticsListParam param);
 
 
 

+ 59 - 32
fs-service-system/src/main/java/com/fs/qw/service/impl/QwWatchLogServiceImpl.java

@@ -7,6 +7,7 @@ import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.DictUtils;
 import com.fs.company.cache.ICompanyCacheService;
+import com.fs.company.cache.ICompanyUserCacheService;
 import com.fs.company.domain.Company;
 import com.fs.company.domain.CompanyUser;
 import com.fs.company.mapper.CompanyUserMapper;
@@ -53,6 +54,9 @@ public class QwWatchLogServiceImpl extends ServiceImpl<QwWatchLogMapper, QwWatch
 
     @Autowired
     private ICompanyCacheService companyCacheService;
+
+    @Autowired
+    private ICompanyUserCacheService companyUserCacheService;
     /**
      * 查询企微看课
      *
@@ -127,13 +131,18 @@ public class QwWatchLogServiceImpl extends ServiceImpl<QwWatchLogMapper, QwWatch
     }
 
     @Override
-    public List<QwWatchLogStatisticsListVO> selectQwWatchLogStatisticsListVO(QwWatchLogStatisticsListParam param) {
+    public TableDataInfo selectQwWatchLogStatisticsListVO(QwWatchLogStatisticsListParam param) {
+        TableDataInfo rspData = new TableDataInfo();
+        rspData.setCode(HttpStatus.SUCCESS);
+        rspData.setMsg("查询成功");
+        rspData.setRows(new ArrayList<>());
+        rspData.setTotal(0L);
 
         Date sTime = param.getSTime();
         Date eTime = param.getETime();
         List<Date> datesBetween = getDatesBetween(sTime, eTime);
         if (datesBetween.size() > 7) {
-            return new ArrayList<>();
+            return rspData;
         }
         if (param.getCompanyUserId()!=null){
             param.setIds(companyUserMapper.selectQwUserIdsByCompany(param.getCompanyUserId()));
@@ -149,10 +158,12 @@ public class QwWatchLogServiceImpl extends ServiceImpl<QwWatchLogMapper, QwWatch
             vo.setFirstOver(stat.getFirstOver());
         }
 
-        return vos;
+        Long total = qwWatchLogMapper.selectQwExtCountByDayAndCount(param);
+        rspData.setRows(vos);
+        rspData.setTotal(total);
+        return rspData;
     }
 
-
     @Override
     public TableDataInfo selectQwWatchLogStatisticsListVONew(QwWatchLogStatisticsListParam param) {
         // 获取当前公司下的所有销售
@@ -243,45 +254,61 @@ public class QwWatchLogServiceImpl extends ServiceImpl<QwWatchLogMapper, QwWatch
     }
 
     @Override
-    public List<QwWatchLogAllStatisticsListVO> selectQwWatchLogAllStatisticsListVONew(QwWatchLogStatisticsListParam param) {
+    public TableDataInfo selectQwWatchLogAllStatisticsListVONew(QwWatchLogStatisticsListParam param) {
         // 获取当前公司下的所有销售
         List<CompanyUser> companyUsers = companyUserMapper.selectCompanyUserByCompanyId(param.getCompanyId());
 
         List<QwWatchLogAllStatisticsListVO> list = new ArrayList<>();
 
-        for (CompanyUser companyUser : companyUsers) {
-            List<QwWatchLogAllStatisticsListVO> vos = qwWatchLogMapper
-                    .selectQwWatchLogAllStatisticsListVONew(companyUser.getUserId(),companyUser.getCompanyId(), param.getSTime(), param.getETime(),
-                            param.getProject(),param.getCourseId(),param.getVideoId()
-                            );
-            for (QwWatchLogAllStatisticsListVO item : vos) {
-                if(ObjectUtils.isNotNull(item.getProject())){
-                    String sysCourseProject = DictUtils.getDictLabel("sys_course_project", String.valueOf(item.getProject()));
-                    if(StringUtils.isNotBlank(sysCourseProject)){
-                        item.setProjectName(sysCourseProject);
-                    }
+        List<Long> userIds = companyUsers.stream().filter(e -> e.getUserId() != null)
+                .map(e -> e.getUserId())
+                .collect(Collectors.toList());
+
+        List<QwWatchLogAllStatisticsListVO> vos = qwWatchLogMapper
+                .selectQwWatchLogAllStatisticsListVONew(userIds, param.getSTime(), param.getETime(),
+                        param.getProject(),param.getCourseId(),param.getVideoId()
+                        );
+        for (QwWatchLogAllStatisticsListVO item : vos) {
+            if(ObjectUtils.isNotNull(item.getProject())){
+                String sysCourseProject = DictUtils.getDictLabel("sys_course_project", String.valueOf(item.getProject()));
+                if(StringUtils.isNotBlank(sysCourseProject)){
+                    item.setProjectName(sysCourseProject);
                 }
-                // 课程名
-                if(ObjectUtils.isNotNull(item.getCourseId())) {
-                    FsUserCourse course = fsUserCourseCacheService.selectFsUserCourseByCourseId(item.getCourseId());
-                    if(ObjectUtils.isNotNull(course)){
-                        item.setCourseName(course.getCourseName());
-                    }
+            }
+            // 课程名
+            if(ObjectUtils.isNotNull(item.getCourseId())) {
+                FsUserCourse course = fsUserCourseCacheService.selectFsUserCourseByCourseId(item.getCourseId());
+                if(ObjectUtils.isNotNull(course)){
+                    item.setCourseName(course.getCourseName());
                 }
-                // 小节名
-                if(ObjectUtils.isNotNull(item.getVideoId())) {
-                    FsUserCourseVideo fsUserCourseVideo = fsUserCourseVideoCacheService.selectFsUserCourseVideoByVideoId(item.getVideoId());
-                    if(ObjectUtils.isNotNull(fsUserCourseVideo)){
-                        item.setVideoName(fsUserCourseVideo.getTitle());
-                    }
+            }
+            // 小节名
+            if(ObjectUtils.isNotNull(item.getVideoId())) {
+                FsUserCourseVideo fsUserCourseVideo = fsUserCourseVideoCacheService.selectFsUserCourseVideoByVideoId(item.getVideoId());
+                if(ObjectUtils.isNotNull(fsUserCourseVideo)){
+                    item.setVideoName(fsUserCourseVideo.getTitle());
                 }
-                item.setQwUserName(companyUser.getUserName());
-                item.setCreateTime(companyUser.getCreateTime());
-                list.add(item);
             }
+            // 销售名称
+            CompanyUser companyUser = companyUserCacheService.selectCompanyUserById(item.getCompanyUserId());
 
+            item.setQwUserName(companyUser.getUserName());
+            item.setCreateTime(companyUser.getCreateTime());
+            list.add(item);
         }
-        return list;
+
+        Long total = qwWatchLogMapper
+                .selectQwWatchLogAllStatisticsListVONewCount(userIds, param.getSTime(), param.getETime(),
+                        param.getProject(),param.getCourseId(),param.getVideoId()
+                );
+
+        TableDataInfo rspData = new TableDataInfo();
+        rspData.setCode(HttpStatus.SUCCESS);
+        rspData.setMsg("查询成功");
+        rspData.setRows(list);
+        rspData.setTotal(total);
+
+        return rspData;
     }
 
     @Override

+ 5 - 0
fs-service-system/src/main/java/com/fs/qw/vo/QwWatchLogAllStatisticsListVO.java

@@ -95,4 +95,9 @@ public class QwWatchLogAllStatisticsListVO {
      */
     private Long videoId;
     private String videoName;
+
+    private Long companyId;
+
+    private Long companyUserId;
+
 }

+ 54 - 4
fs-service-system/src/main/resources/mapper/qw/QwWatchLogMapper.xml

@@ -66,6 +66,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="selectQwWatchLogAllStatisticsListVONew"
             resultType="com.fs.qw.vo.QwWatchLogAllStatisticsListVO">
             select
+            any_value(company_id),
+            any_value(company_user_id),
             COUNT(CASE WHEN day = 0 and status in (1,2) THEN 1 END) AS firstOnline,
             COUNT(CASE WHEN day = 0 and status=2 THEN 1 END) AS firstOver,
             COUNT(CASE WHEN day = 1 and status in (1,2) THEN 1 END) AS d1Online,
@@ -132,11 +134,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
              from qw_watch_log
             <where>
                  <if test="companyUserId">
-                     and company_user_id=#{companyUserId}
+                     and company_user_id in
+                     <foreach collection="companyUserIds" item="item" open="(" close=")" separator=",">
+                         ${item}
+                     </foreach>
                  </if>
-                <if test="companyId">
-                    and company_id = #{companyId}
-                </if>
                 <if test="project != null">
                     and project = #{project}
                 </if>
@@ -175,6 +177,54 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         GROUP BY project, course_id, video_id
         ) AS count_temp_table
     </select>
+    <select id="selectQwExtCountByDayAndCount" resultType="java.lang.Long">
+        SELECT COUNT(*) AS total_count
+        FROM (
+        SELECT 1
+        FROM
+        qw_external_contact qec
+        JOIN
+        qw_user qu ON qec.qw_user_id = qu.id
+        WHERE
+        DATE(qec.create_time) &gt;= DATE(#{sTime})
+        AND DATE(qec.create_time) &lt;= DATE(#{eTime})
+        AND qec.company_id = #{companyId}
+        <if test='nickName != null and nickName != ""'>
+            AND qu.qw_user_name LIKE CONCAT(#{nickName}, '%')
+        </if>
+        <if test='ids != null and ids != ""'>
+            AND qec.qw_user_id IN
+            <foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY
+        qec.qw_user_id, DATE(qec.create_time)
+        ) AS grouped_data
+    </select>
+    <select id="selectQwWatchLogAllStatisticsListVONewCount" resultType="java.lang.Long">
+        select
+        count(1)
+        from qw_watch_log
+        <where>
+            <if test="companyUserId">
+                and company_user_id in
+                <foreach collection="companyUserIds" item="item" open="(" close=")" separator=",">
+                    ${item}
+                </foreach>
+            </if>
+            <if test="project != null">
+                and project = #{project}
+            </if>
+            <if test="courseId != null">
+                and course_id = #{courseId}
+            </if>
+            <if test="videoId != null">
+                and video_id =#{videoId}
+            </if>
+            and DATE(line_time) between #{sDate} AND #{eDate} group by project,course_id,video_id
+        </where>
+    </select>
 
     <insert id="insertQwWatchLog" parameterType="QwWatchLog" useGeneratedKeys="true" keyProperty="id">
         insert into qw_watch_log