소스 검색

推送列表统计 调整

qinxuyang 5 시간 전
부모
커밋
a338964a3e

+ 4 - 0
alien-entity/src/main/java/shop/alien/entity/store/CommonPushTaskUser.java

@@ -37,6 +37,10 @@ public class CommonPushTaskUser implements Serializable {
     @TableField("device_id")
     private String deviceId;
 
+    @ApiModelProperty("手机设备类型")
+    @TableField("phone_type")
+    private String phoneType;
+
     @ApiModelProperty("关联类型:1-接收用户 2-协办人 3-权限查看人")
     @TableField("rel_type")
     private Integer relType;

+ 2 - 2
alien-entity/src/main/java/shop/alien/entity/store/vo/CommonPushFunnelVo.java

@@ -18,8 +18,8 @@ public class CommonPushFunnelVo implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
-    @ApiModelProperty("推送任务ID,为空表示汇总")
-    private Long pushTaskId;
+    @ApiModelProperty("手机设备类型筛选条件,为空表示全部")
+    private String phoneType;
 
     @ApiModelProperty("漏斗各步骤")
     private List<CommonPushFunnelStepVo> steps;

+ 1 - 1
alien-entity/src/main/java/shop/alien/entity/store/vo/CommonPushReportVo.java

@@ -23,7 +23,7 @@ public class CommonPushReportVo implements Serializable {
     @ApiModelProperty("报表类型:1-日报 2-周报 3-月报")
     private Integer reportType;
 
-    @ApiModelProperty("报表日期")
+    @ApiModelProperty("报表日期(按当前日期及报表类型自动计算)")
     @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
     private Date reportDate;
 

+ 2 - 2
alien-entity/src/main/java/shop/alien/entity/store/vo/CommonPushStatisticsSummaryVo.java

@@ -18,10 +18,10 @@ public class CommonPushStatisticsSummaryVo implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
-    @ApiModelProperty("推送量(status=0或1)")
+    @ApiModelProperty("推送量(status=2或3)")
     private Long pushVolume;
 
-    @ApiModelProperty("送达数(status=1)")
+    @ApiModelProperty("送达数(status=3)")
     private Long deliveredCount;
 
     @ApiModelProperty("点击数(user_add=1)")

+ 2 - 2
alien-entity/src/main/java/shop/alien/entity/store/vo/CommonPushTaskStatisticsItemVo.java

@@ -41,10 +41,10 @@ public class CommonPushTaskStatisticsItemVo implements Serializable {
     @ApiModelProperty("目标用户数")
     private Integer estimatedCount;
 
-    @ApiModelProperty("实际发送数(status=0或1)")
+    @ApiModelProperty("实际发送数(status=2或3)")
     private Long sentCount;
 
-    @ApiModelProperty("送达数(status=1)")
+    @ApiModelProperty("送达数(status=3)")
     private Long deliveredCount;
 
     @ApiModelProperty("点击数(user_add=1)")

+ 39 - 25
alien-entity/src/main/java/shop/alien/mapper/CommonPushTaskMapper.java

@@ -15,26 +15,51 @@ import java.util.List;
 @Mapper
 public interface CommonPushTaskMapper extends BaseMapper<CommonPushTask> {
 
-    String TASK_STATS_SELECT = "SELECT t.id, t.task_no AS taskNo, t.title, t.push_type AS pushType, t.status, " +
+    @Select("<script>" +
+            "SELECT " +
+            "IFNULL(SUM(CASE WHEN u.status IN (2, 3) THEN 1 ELSE 0 END), 0) AS sentCount, " +
+            "IFNULL(SUM(CASE WHEN u.status = 3 THEN 1 ELSE 0 END), 0) AS deliveredCount, " +
+            "IFNULL(SUM(CASE WHEN u.user_add = 1 THEN 1 ELSE 0 END), 0) AS clickCount " +
+            "FROM common_push_task t " +
+            "LEFT JOIN common_push_task_user u ON u.push_task_id = t.id AND u.delete_flag = 0 " +
+            "WHERE t.delete_flag = 0 " +
+            "<if test='taskNo != null and taskNo != \"\"'>AND t.task_no = #{taskNo} </if>" +
+            "<if test='keyword != null and keyword != \"\"'>AND (t.title LIKE CONCAT('%', #{keyword}, '%') OR t.task_no LIKE CONCAT('%', #{keyword}, '%')) </if>" +
+            "<if test='status != null and status != \"\"'>AND t.status = #{status} </if>" +
+            "<if test='pushType != null'>AND t.push_type = #{pushType} </if>" +
+            "<if test='channel != null and channel != \"\"'>AND t.channels LIKE CONCAT('%', #{channel}, '%') </if>" +
+            "<if test='startTime != null'>AND t.created_time &gt;= #{startTime} </if>" +
+            "<if test='endTime != null'>AND t.created_time &lt; #{endTime} </if>" +
+            "<if test='startTime != null'>AND u.created_time &gt;= #{startTime} </if>" +
+            "<if test='endTime != null'>AND u.created_time &lt; #{endTime} </if>" +
+            "</script>")
+    CommonPushTaskStatsDto selectStatisticsSummary(@Param("taskNo") String taskNo,
+                                                   @Param("keyword") String keyword,
+                                                   @Param("status") String status,
+                                                   @Param("pushType") Integer pushType,
+                                                   @Param("channel") String channel,
+                                                   @Param("startTime") Date startTime,
+                                                   @Param("endTime") Date endTime);
+
+    @Select("<script>" +
+            "SELECT t.id, t.task_no AS taskNo, t.title, t.push_type AS pushType, t.status, " +
             "t.channels, t.estimated_count AS estimatedCount, t.created_time AS createdTime, " +
             "IFNULL(SUM(CASE WHEN u.status IN (2, 3) THEN 1 ELSE 0 END), 0) AS sentCount, " +
             "IFNULL(SUM(CASE WHEN u.status = 3 THEN 1 ELSE 0 END), 0) AS deliveredCount, " +
             "IFNULL(SUM(CASE WHEN u.show_info = 1 THEN 1 ELSE 0 END), 0) AS showCount, " +
-            "IFNULL(SUM(CASE WHEN u.user_add = 1 THEN 1 ELSE 0 END), 0) AS clickCount ";
-
-    String TASK_STATS_FROM = "FROM common_push_task t " +
-            "LEFT JOIN common_push_task_user u ON u.push_task_id = t.id AND u.delete_flag = 0 ";
-
-    String TASK_STATS_WHERE = "WHERE t.delete_flag = 0 " +
+            "IFNULL(SUM(CASE WHEN u.user_add = 1 THEN 1 ELSE 0 END), 0) AS clickCount " +
+            "FROM common_push_task t " +
+            "LEFT JOIN common_push_task_user u ON u.push_task_id = t.id AND u.delete_flag = 0 " +
+            "WHERE t.delete_flag = 0 " +
             "<if test='taskNo != null and taskNo != \"\"'>AND t.task_no = #{taskNo} </if>" +
             "<if test='keyword != null and keyword != \"\"'>AND (t.title LIKE CONCAT('%', #{keyword}, '%') OR t.task_no LIKE CONCAT('%', #{keyword}, '%')) </if>" +
             "<if test='status != null and status != \"\"'>AND t.status = #{status} </if>" +
             "<if test='pushType != null'>AND t.push_type = #{pushType} </if>" +
             "<if test='channel != null and channel != \"\"'>AND t.channels LIKE CONCAT('%', #{channel}, '%') </if>" +
             "<if test='startTime != null'>AND t.created_time &gt;= #{startTime} </if>" +
-            "<if test='endTime != null'>AND t.created_time &lt; #{endTime} </if>";
-
-    @Select("<script>" + TASK_STATS_SELECT + TASK_STATS_FROM + TASK_STATS_WHERE +
+            "<if test='endTime != null'>AND t.created_time &lt; #{endTime} </if>" +
+            "<if test='startTime != null'>AND u.created_time &gt;= #{startTime} </if>" +
+            "<if test='endTime != null'>AND u.created_time &lt; #{endTime} </if>" +
             "GROUP BY t.id, t.task_no, t.title, t.push_type, t.status, t.channels, t.estimated_count, t.created_time " +
             "ORDER BY t.created_time DESC" +
             "</script>")
@@ -47,17 +72,6 @@ public interface CommonPushTaskMapper extends BaseMapper<CommonPushTask> {
                                                        @Param("startTime") Date startTime,
                                                        @Param("endTime") Date endTime);
 
-    @Select("<script>" + TASK_STATS_SELECT + TASK_STATS_FROM + TASK_STATS_WHERE +
-            "GROUP BY t.id, t.task_no, t.title, t.push_type, t.status, t.channels, t.estimated_count, t.created_time " +
-            "</script>")
-    List<CommonPushTaskStatsDto> selectStatisticsList(@Param("taskNo") String taskNo,
-                                                      @Param("keyword") String keyword,
-                                                      @Param("status") String status,
-                                                      @Param("pushType") Integer pushType,
-                                                      @Param("channel") String channel,
-                                                      @Param("startTime") Date startTime,
-                                                      @Param("endTime") Date endTime);
-
     @Select("<script>" +
             "SELECT " +
             "IFNULL(SUM(CASE WHEN u.status IN (2, 3) THEN 1 ELSE 0 END), 0) AS sentCount, " +
@@ -66,13 +80,13 @@ public interface CommonPushTaskMapper extends BaseMapper<CommonPushTask> {
             "IFNULL(SUM(CASE WHEN u.user_add = 1 THEN 1 ELSE 0 END), 0) AS clickCount " +
             "FROM common_push_task_user u " +
             "WHERE u.delete_flag = 0 " +
-            "<if test='pushTaskId != null'>AND u.push_task_id = #{pushTaskId} </if>" +
             "<if test='startTime != null'>AND u.created_time &gt;= #{startTime} </if>" +
             "<if test='endTime != null'>AND u.created_time &lt; #{endTime} </if>" +
+            "<if test='phoneType != null and phoneType != \"\"'>AND u.phone_type = #{phoneType} </if>" +
             "</script>")
-    CommonPushTaskStatsDto selectUserStats(@Param("pushTaskId") Long pushTaskId,
-                                           @Param("startTime") Date startTime,
-                                           @Param("endTime") Date endTime);
+    CommonPushTaskStatsDto selectUserStats(@Param("startTime") Date startTime,
+                                           @Param("endTime") Date endTime,
+                                           @Param("phoneType") String phoneType);
 
     @Select("<script>" +
             "SELECT t.id, t.title, " +

+ 6 - 9
alien-store/src/main/java/shop/alien/store/controller/CommonPushTaskController.java

@@ -113,28 +113,25 @@ public class CommonPushTaskController {
     @ApiOperation("推送漏斗统计")
     @ApiOperationSupport(order = 7)
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "pushTaskId", value = "推送任务ID,为空则统计全部", dataType = "Long", paramType = "query"),
+            @ApiImplicitParam(name = "phoneType", value = "手机设备类型,筛选 common_push_task_user.phone_type,为空则统计全部", dataType = "String", paramType = "query"),
             @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "Date", paramType = "query"),
             @ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "Date", paramType = "query")
     })
     @GetMapping("/funnel")
     public R<CommonPushFunnelVo> funnel(
-            @RequestParam(required = false) Long pushTaskId,
+            @RequestParam(required = false) String phoneType,
             @RequestParam(required = false) Date startTime,
             @RequestParam(required = false) Date endTime) {
-        return commonPushTaskService.funnel(pushTaskId, startTime, endTime);
+        return commonPushTaskService.funnel(phoneType, startTime, endTime);
     }
 
     @ApiOperation("报表中心(日报/周报/月报)")
     @ApiOperationSupport(order = 8)
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "reportType", value = "报表类型:1-日报 2-周报 3-月报", dataType = "Integer", paramType = "query"),
-            @ApiImplicitParam(name = "reportDate", value = "报表日期,日报传当天,周报传周内任意一天,月报传月内任意一天", dataType = "Date", paramType = "query")
+            @ApiImplicitParam(name = "reportType", value = "报表类型:1-日报 2-周报 3-月报", dataType = "Integer", paramType = "query")
     })
     @GetMapping("/report")
-    public R<CommonPushReportVo> report(
-            @RequestParam(required = false) Integer reportType,
-            @RequestParam(required = false) Date reportDate) {
-        return commonPushTaskService.report(reportType, reportDate);
+    public R<CommonPushReportVo> report(@RequestParam(required = false) Integer reportType) {
+        return commonPushTaskService.report(reportType);
     }
 }

+ 2 - 2
alien-store/src/main/java/shop/alien/store/service/CommonPushTaskService.java

@@ -26,7 +26,7 @@ public interface CommonPushTaskService extends IService<CommonPushTask> {
                                                      String status, Integer pushType, String channel,
                                                      Date startTime, Date endTime);
 
-    R<CommonPushFunnelVo> funnel(Long pushTaskId, Date startTime, Date endTime);
+    R<CommonPushFunnelVo> funnel(String phoneType, Date startTime, Date endTime);
 
-    R<CommonPushReportVo> report(Integer reportType, Date reportDate);
+    R<CommonPushReportVo> report(Integer reportType);
 }

+ 11 - 32
alien-store/src/main/java/shop/alien/store/service/impl/CommonPushTaskServiceImpl.java

@@ -91,50 +91,43 @@ public class CommonPushTaskServiceImpl extends ServiceImpl<CommonPushTaskMapper,
         Page<CommonPushTaskStatsDto> page = new Page<>(pageNum, pageSize);
         IPage<CommonPushTaskStatsDto> statsPage = baseMapper.selectStatisticsPage(page, taskNo, keyword, status, pushType, channel, startTime, endTime);
 
-        List<CommonPushTaskStatsDto> allStats = baseMapper.selectStatisticsList(taskNo, keyword, status, pushType, channel, startTime, endTime);
+        CommonPushTaskStatsDto summaryStats = baseMapper.selectStatisticsSummary(taskNo, keyword, status, pushType, channel, startTime, endTime);
 
         CommonPushTaskStatisticsPageVo result = new CommonPushTaskStatisticsPageVo();
-        result.setSummary(buildSummary(allStats));
+        result.setSummary(buildUserStatsSummary(summaryStats != null ? summaryStats : emptyUserStats()));
         result.setPage(statsPage.convert(this::toStatisticsItem));
         return R.data(result);
     }
 
     @Override
-    public R<CommonPushFunnelVo> funnel(Long pushTaskId, Date startTime, Date endTime) {
-        log.info("CommonPushTaskServiceImpl.funnel, pushTaskId={}, startTime={}, endTime={}", pushTaskId, startTime, endTime);
-        CommonPushTaskStatsDto stats = baseMapper.selectUserStats(pushTaskId, startTime, endTime);
+    public R<CommonPushFunnelVo> funnel(String phoneType, Date startTime, Date endTime) {
+        log.info("CommonPushTaskServiceImpl.funnel, phoneType={}, startTime={}, endTime={}", phoneType, startTime, endTime);
+        CommonPushTaskStatsDto stats = baseMapper.selectUserStats(startTime, endTime, phoneType);
         if (stats == null) {
             stats = emptyUserStats();
         }
 
         CommonPushFunnelVo funnelVo = new CommonPushFunnelVo();
-        funnelVo.setPushTaskId(pushTaskId);
+        funnelVo.setPhoneType(phoneType);
         funnelVo.setSteps(buildFunnelSteps(stats));
         return R.data(funnelVo);
     }
 
     @Override
-    public R<CommonPushReportVo> report(Integer reportType, Date reportDate) {
-        log.info("CommonPushTaskServiceImpl.report, reportType={}, reportDate={}", reportType, reportDate);
+    public R<CommonPushReportVo> report(Integer reportType) {
+        log.info("CommonPushTaskServiceImpl.report, reportType={}", reportType);
         if (reportType == null) {
             reportType = 1;
         }
-        if (reportDate == null) {
-            reportDate = truncateToDay(new Date());
-        } else {
-            reportDate = truncateToDay(reportDate);
-        }
+        Date reportDate = truncateToDay(new Date());
 
         Date[] range = resolveReportRange(reportType, reportDate);
         Date startTime = range[0];
         Date endTime = range[1];
 
-        CommonPushTaskStatsDto stats = baseMapper.selectUserStats(null, startTime, endTime);
+        CommonPushTaskStatsDto stats = baseMapper.selectUserStats(startTime, endTime, null);
         if (stats == null) {
-            stats = new CommonPushTaskStatsDto();
-            stats.setSentCount(0L);
-            stats.setDeliveredCount(0L);
-            stats.setClickCount(0L);
+            stats = emptyUserStats();
         }
 
         CommonPushReportVo reportVo = new CommonPushReportVo();
@@ -167,20 +160,6 @@ public class CommonPushTaskServiceImpl extends ServiceImpl<CommonPushTaskMapper,
         return item;
     }
 
-    private CommonPushStatisticsSummaryVo buildSummary(List<CommonPushTaskStatsDto> statsList) {
-        long sentCount = 0L;
-        long deliveredCount = 0L;
-        long clickCount = 0L;
-        if (statsList != null) {
-            for (CommonPushTaskStatsDto dto : statsList) {
-                sentCount += defaultCount(dto.getSentCount());
-                deliveredCount += defaultCount(dto.getDeliveredCount());
-                clickCount += defaultCount(dto.getClickCount());
-            }
-        }
-        return buildSummary(sentCount, deliveredCount, clickCount);
-    }
-
     private CommonPushStatisticsSummaryVo buildUserStatsSummary(CommonPushTaskStatsDto stats) {
         return buildSummary(defaultCount(stats.getSentCount()), defaultCount(stats.getDeliveredCount()), defaultCount(stats.getClickCount()));
     }