Explorar el Código

推送列表 推送漏斗 报表中心接口查询子表替换 逻辑修改

qinxuyang hace 16 horas
padre
commit
54ab97dc14

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

@@ -41,13 +41,13 @@ public class CommonPushTaskStatisticsItemVo implements Serializable {
     @ApiModelProperty("目标用户数")
     @ApiModelProperty("目标用户数")
     private Integer estimatedCount;
     private Integer estimatedCount;
 
 
-    @ApiModelProperty("实际发送数(status=2或3)")
+    @ApiModelProperty("实际发送数(common_push_task_num.real_send 汇总)")
     private Long sentCount;
     private Long sentCount;
 
 
-    @ApiModelProperty("送达数(status=3)")
+    @ApiModelProperty("送达数(common_push_task_num.real_delivered 汇总)")
     private Long deliveredCount;
     private Long deliveredCount;
 
 
-    @ApiModelProperty("点击数(user_add=1)")
+    @ApiModelProperty("点击数(common_push_task_num.click_sum 汇总)")
     private Long clickCount;
     private Long clickCount;
 
 
     @ApiModelProperty("推送率(实际发送数/目标用户数,%)")
     @ApiModelProperty("推送率(实际发送数/目标用户数,%)")

+ 34 - 28
alien-entity/src/main/java/shop/alien/mapper/CommonPushTaskMapper.java

@@ -15,13 +15,19 @@ import java.util.List;
 @Mapper
 @Mapper
 public interface CommonPushTaskMapper extends BaseMapper<CommonPushTask> {
 public interface CommonPushTaskMapper extends BaseMapper<CommonPushTask> {
 
 
+    String NUM_SUM_REAL_SEND = "IFNULL(SUM(CAST(IFNULL(n.real_send, 0) AS UNSIGNED)), 0)";
+    String NUM_SUM_REAL_DELIVERED = "IFNULL(SUM(CAST(IFNULL(n.real_delivered, 0) AS UNSIGNED)), 0)";
+    String NUM_SUM_CLICK = "IFNULL(SUM(CAST(IFNULL(n.click_sum, 0) AS UNSIGNED)), 0)";
+    String NUM_SUM_SHOW = "IFNULL(SUM(CAST(IFNULL(n.show_sum, 0) AS UNSIGNED)), 0)";
+    String NUM_JOIN = "LEFT JOIN common_push_task_num n ON n.push_task_id = t.id AND n.delete_flag = 0 ";
+
     @Select("<script>" +
     @Select("<script>" +
             "SELECT " +
             "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 " +
+            NUM_SUM_REAL_SEND + " AS sentCount, " +
+            NUM_SUM_REAL_DELIVERED + " AS deliveredCount, " +
+            NUM_SUM_CLICK + " AS clickCount " +
             "FROM common_push_task t " +
             "FROM common_push_task t " +
-            "LEFT JOIN common_push_task_user u ON u.push_task_id = t.id AND u.delete_flag = 0 " +
+            NUM_JOIN +
             "WHERE t.delete_flag = 0 " +
             "WHERE t.delete_flag = 0 " +
             "<if test='taskNo != null and taskNo != \"\"'>AND t.task_no = #{taskNo} </if>" +
             "<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='keyword != null and keyword != \"\"'>AND (t.title LIKE CONCAT('%', #{keyword}, '%') OR t.task_no LIKE CONCAT('%', #{keyword}, '%')) </if>" +
@@ -30,8 +36,8 @@ public interface CommonPushTaskMapper extends BaseMapper<CommonPushTask> {
             "<if test='channel != null and channel != \"\"'>AND t.channels LIKE CONCAT('%', #{channel}, '%') </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='startTime != null'>AND t.created_time &gt;= #{startTime} </if>" +
             "<if test='endTime != null'>AND t.created_time &lt; #{endTime} </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>" +
+            "<if test='startTime != null'>AND n.created_time &gt;= #{startTime} </if>" +
+            "<if test='endTime != null'>AND n.created_time &lt; #{endTime} </if>" +
             "</script>")
             "</script>")
     CommonPushTaskStatsDto selectStatisticsSummary(@Param("taskNo") String taskNo,
     CommonPushTaskStatsDto selectStatisticsSummary(@Param("taskNo") String taskNo,
                                                    @Param("keyword") String keyword,
                                                    @Param("keyword") String keyword,
@@ -44,12 +50,12 @@ public interface CommonPushTaskMapper extends BaseMapper<CommonPushTask> {
     @Select("<script>" +
     @Select("<script>" +
             "SELECT t.id, t.task_no AS taskNo, t.title, t.push_type AS pushType, t.status, " +
             "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, " +
             "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 " +
+            NUM_SUM_REAL_SEND + " AS sentCount, " +
+            NUM_SUM_REAL_DELIVERED + " AS deliveredCount, " +
+            NUM_SUM_SHOW + " AS showCount, " +
+            NUM_SUM_CLICK + " AS clickCount " +
             "FROM common_push_task t " +
             "FROM common_push_task t " +
-            "LEFT JOIN common_push_task_user u ON u.push_task_id = t.id AND u.delete_flag = 0 " +
+            NUM_JOIN +
             "WHERE t.delete_flag = 0 " +
             "WHERE t.delete_flag = 0 " +
             "<if test='taskNo != null and taskNo != \"\"'>AND t.task_no = #{taskNo} </if>" +
             "<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='keyword != null and keyword != \"\"'>AND (t.title LIKE CONCAT('%', #{keyword}, '%') OR t.task_no LIKE CONCAT('%', #{keyword}, '%')) </if>" +
@@ -58,8 +64,8 @@ public interface CommonPushTaskMapper extends BaseMapper<CommonPushTask> {
             "<if test='channel != null and channel != \"\"'>AND t.channels LIKE CONCAT('%', #{channel}, '%') </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='startTime != null'>AND t.created_time &gt;= #{startTime} </if>" +
             "<if test='endTime != null'>AND t.created_time &lt; #{endTime} </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>" +
+            "<if test='startTime != null'>AND n.created_time &gt;= #{startTime} </if>" +
+            "<if test='endTime != null'>AND n.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 " +
             "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" +
             "ORDER BY t.created_time DESC" +
             "</script>")
             "</script>")
@@ -74,15 +80,15 @@ public interface CommonPushTaskMapper extends BaseMapper<CommonPushTask> {
 
 
     @Select("<script>" +
     @Select("<script>" +
             "SELECT " +
             "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.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 " +
-            "FROM common_push_task_user u " +
-            "WHERE u.delete_flag = 0 " +
-            "<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>" +
+            NUM_SUM_REAL_SEND + " AS sentCount, " +
+            NUM_SUM_REAL_DELIVERED + " AS deliveredCount, " +
+            NUM_SUM_SHOW + " AS showCount, " +
+            NUM_SUM_CLICK + " AS clickCount " +
+            "FROM common_push_task_num n " +
+            "WHERE n.delete_flag = 0 " +
+            "<if test='startTime != null'>AND n.created_time &gt;= #{startTime} </if>" +
+            "<if test='endTime != null'>AND n.created_time &lt; #{endTime} </if>" +
+            "<if test='phoneType != null and phoneType != \"\"'>AND n.phone_type = #{phoneType} </if>" +
             "</script>")
             "</script>")
     CommonPushTaskStatsDto selectUserStats(@Param("startTime") Date startTime,
     CommonPushTaskStatsDto selectUserStats(@Param("startTime") Date startTime,
                                            @Param("endTime") Date endTime,
                                            @Param("endTime") Date endTime,
@@ -90,14 +96,14 @@ public interface CommonPushTaskMapper extends BaseMapper<CommonPushTask> {
 
 
     @Select("<script>" +
     @Select("<script>" +
             "SELECT t.id, t.title, " +
             "SELECT t.id, t.title, " +
-            "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 " +
+            NUM_SUM_REAL_SEND + " AS sentCount, " +
+            NUM_SUM_REAL_DELIVERED + " AS deliveredCount, " +
+            NUM_SUM_CLICK + " AS clickCount " +
             "FROM common_push_task t " +
             "FROM common_push_task t " +
-            "INNER JOIN common_push_task_user u ON u.push_task_id = t.id AND u.delete_flag = 0 " +
+            "INNER JOIN common_push_task_num n ON n.push_task_id = t.id AND n.delete_flag = 0 " +
             "WHERE t.delete_flag = 0 " +
             "WHERE t.delete_flag = 0 " +
-            "<if test='startTime != null'>AND u.created_time &gt;= #{startTime} </if>" +
-            "<if test='endTime != null'>AND u.created_time &lt; #{endTime} </if>" +
+            "<if test='startTime != null'>AND n.created_time &gt;= #{startTime} </if>" +
+            "<if test='endTime != null'>AND n.created_time &lt; #{endTime} </if>" +
             "GROUP BY t.id, t.title " +
             "GROUP BY t.id, t.title " +
             "HAVING deliveredCount &gt; 0 " +
             "HAVING deliveredCount &gt; 0 " +
             "ORDER BY (clickCount / deliveredCount) DESC " +
             "ORDER BY (clickCount / deliveredCount) DESC " +

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

@@ -107,8 +107,8 @@ public class CommonPushTaskController {
             @ApiImplicitParam(name = "status", value = "任务状态:0-草稿 1-待审核 2-已发送 3-已送达 4-失败 5-审核通过 6-驳回", dataType = "Integer", paramType = "query"),
             @ApiImplicitParam(name = "status", value = "任务状态:0-草稿 1-待审核 2-已发送 3-已送达 4-失败 5-审核通过 6-驳回", dataType = "Integer", paramType = "query"),
             @ApiImplicitParam(name = "pushType", value = "推送类型:1-交易类 2-系统类 3-运营类 4-社交类", dataType = "Integer", paramType = "query"),
             @ApiImplicitParam(name = "pushType", value = "推送类型:1-交易类 2-系统类 3-运营类 4-社交类", dataType = "Integer", paramType = "query"),
             @ApiImplicitParam(name = "channel", value = "推送渠道,如 notification/inapp", dataType = "String", paramType = "query"),
             @ApiImplicitParam(name = "channel", value = "推送渠道,如 notification/inapp", dataType = "String", paramType = "query"),
-            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "Date", paramType = "query"),
-            @ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "Date", paramType = "query")
+            @ApiImplicitParam(name = "startTime", value = "开始时间(传日期包含当天 00:00:00 起)", dataType = "Date", paramType = "query"),
+            @ApiImplicitParam(name = "endTime", value = "结束时间(传日期包含当天 23:59:59 止)", dataType = "Date", paramType = "query")
     })
     })
     @GetMapping("/statisticsList")
     @GetMapping("/statisticsList")
     public R<CommonPushTaskStatisticsPageVo> statisticsList(
     public R<CommonPushTaskStatisticsPageVo> statisticsList(
@@ -127,7 +127,7 @@ public class CommonPushTaskController {
     @ApiOperation("推送漏斗统计")
     @ApiOperation("推送漏斗统计")
     @ApiOperationSupport(order = 7)
     @ApiOperationSupport(order = 7)
     @ApiImplicitParams({
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "phoneType", value = "手机设备类型,筛选 common_push_task_user.phone_type,为空则统计全部", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "phoneType", value = "机型:1-OPPO 2-VIVO 3-华为 4-苹果 5-荣耀 6-小米 7-三星,筛选 common_push_task_num.phone_type,为空则统计全部", dataType = "String", paramType = "query"),
             @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "Date", paramType = "query"),
             @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "Date", paramType = "query"),
             @ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "Date", paramType = "query")
             @ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "Date", paramType = "query")
     })
     })
@@ -146,7 +146,7 @@ public class CommonPushTaskController {
         return commonPushTaskService.sendTest(dto);
         return commonPushTaskService.sendTest(dto);
     }
     }
 
 
-    @ApiOperation("报表中心(日报/周报/月报)")
+    @ApiOperation(value = "报表中心(日报/周报/月报)", notes = "概览与 TOP 榜单均基于 common_push_task_num 汇总")
     @ApiOperationSupport(order = 8)
     @ApiOperationSupport(order = 8)
     @ApiImplicitParams({
     @ApiImplicitParams({
             @ApiImplicitParam(name = "reportType", value = "报表类型:1-日报 2-周报 3-月报", dataType = "Integer", paramType = "query")
             @ApiImplicitParam(name = "reportType", value = "报表类型:1-日报 2-周报 3-月报", dataType = "Integer", paramType = "query")

+ 23 - 2
alien-store/src/main/java/shop/alien/store/service/impl/CommonPushTaskServiceImpl.java

@@ -379,10 +379,12 @@ public class CommonPushTaskServiceImpl extends ServiceImpl<CommonPushTaskMapper,
                                                             Date startTime, Date endTime) {
                                                             Date startTime, Date endTime) {
         log.info("CommonPushTaskServiceImpl.statisticsList, pageNum={}, pageSize={}, taskNo={}, keyword={}, status={}, pushType={}, channel={}, startTime={}, endTime={}",
         log.info("CommonPushTaskServiceImpl.statisticsList, pageNum={}, pageSize={}, taskNo={}, keyword={}, status={}, pushType={}, channel={}, startTime={}, endTime={}",
                 pageNum, pageSize, taskNo, keyword, status, pushType, channel, startTime, endTime);
                 pageNum, pageSize, taskNo, keyword, status, pushType, channel, startTime, endTime);
+        Date queryStartTime = normalizeQueryStartTime(startTime);
+        Date queryEndTime = normalizeQueryEndTime(endTime);
         Page<CommonPushTaskStatsDto> page = new Page<>(pageNum, pageSize);
         Page<CommonPushTaskStatsDto> page = new Page<>(pageNum, pageSize);
-        IPage<CommonPushTaskStatsDto> statsPage = baseMapper.selectStatisticsPage(page, taskNo, keyword, status, pushType, channel, startTime, endTime);
+        IPage<CommonPushTaskStatsDto> statsPage = baseMapper.selectStatisticsPage(page, taskNo, keyword, status, pushType, channel, queryStartTime, queryEndTime);
 
 
-        CommonPushTaskStatsDto summaryStats = baseMapper.selectStatisticsSummary(taskNo, keyword, status, pushType, channel, startTime, endTime);
+        CommonPushTaskStatsDto summaryStats = baseMapper.selectStatisticsSummary(taskNo, keyword, status, pushType, channel, queryStartTime, queryEndTime);
 
 
         CommonPushTaskStatisticsPageVo result = new CommonPushTaskStatisticsPageVo();
         CommonPushTaskStatisticsPageVo result = new CommonPushTaskStatisticsPageVo();
         result.setSummary(buildUserStatsSummary(summaryStats != null ? summaryStats : emptyUserStats()));
         result.setSummary(buildUserStatsSummary(summaryStats != null ? summaryStats : emptyUserStats()));
@@ -588,6 +590,25 @@ public class CommonPushTaskServiceImpl extends ServiceImpl<CommonPushTaskMapper,
         return calendar.getTime();
         return calendar.getTime();
     }
     }
 
 
+    /** 查询开始时间归一化到当天 00:00:00 */
+    private Date normalizeQueryStartTime(Date startTime) {
+        return startTime == null ? null : truncateToDay(startTime);
+    }
+
+    /** 查询结束时间归一化到当天 23:59:59.999,传日期时可包含当天全天数据 */
+    private Date normalizeQueryEndTime(Date endTime) {
+        if (endTime == null) {
+            return null;
+        }
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(endTime);
+        calendar.set(Calendar.HOUR_OF_DAY, 23);
+        calendar.set(Calendar.MINUTE, 59);
+        calendar.set(Calendar.SECOND, 59);
+        calendar.set(Calendar.MILLISECOND, 999);
+        return calendar.getTime();
+    }
+
     private long defaultCount(Long count) {
     private long defaultCount(Long count) {
         return count == null ? 0L : count;
         return count == null ? 0L : count;
     }
     }