Jelajahi Sumber

公众号自动回复 裂变率改质量分

wangyunpeng 1 Minggu lalu
induk
melakukan
a905531864

+ 122 - 72
api-module/src/main/java/com/tzld/piaoquan/api/job/contentplatform/ContentPlatformDatastatJob.java

@@ -73,12 +73,12 @@ public class ContentPlatformDatastatJob {
         Long now = System.currentTimeMillis();
         // 公众号自动回复数据统计
         String sql = String.format(
-                "SELECT first_level.channel_shortname, first_level.subchannel, first_level.first_uv, fission.split_uv " +
-                "FROM loghubods.out_channel_mid_first_total first_level " +
-                "left join loghubods.out_channel_mid_split_total fission " +
-                "on first_level.channel_shortname = fission.channel_shortname and first_level.subchannel = fission.subchannel " +
-                "and first_level.dt = fission.dt and first_level.type = fission.type and first_level.tag = fission.tag " +
-                "WHERE first_level.dt = %s and first_level.type = '公众号即时回复' and first_level.tag = '分投放渠道客户分账号去重';", dt);
+                "SELECT first_level.channel_shortname, first_level.subchannel, first_level.first_uv, fission.split_uv, fission.裂变arpu " +
+                        "FROM loghubods.out_channel_mid_first_total first_level " +
+                        "left join loghubods.out_channel_mid_split_total fission " +
+                        "on first_level.channel_shortname = fission.channel_shortname and first_level.subchannel = fission.subchannel " +
+                        "and first_level.dt = fission.dt and first_level.type = fission.type and first_level.tag = fission.tag " +
+                        "WHERE first_level.dt = %s and first_level.type = '公众号即时回复' and first_level.tag = '分投放渠道客户分账号去重';", dt);
         List<Record> dataList = OdpsUtil.getOdpsData(sql);
         // 所有公众号
         List<ContentPlatformGzhAccount> accountList = getAllGzhAccount();
@@ -93,16 +93,29 @@ public class ContentPlatformDatastatJob {
                 .collect(Collectors.toMap(WxAccountDatastatVO::getAccountId, wxAccountDatastatVO -> wxAccountDatastatVO));
         if (CollectionUtils.isNotEmpty(dataList)) {
             List<ContentPlatformGzhDataStat> saveList = new ArrayList<>();
+            BigDecimal sumScore = BigDecimal.ZERO;
             for (Record record : dataList) {
-                ContentPlatformGzhDataStat item = new ContentPlatformGzhDataStat();
+                String channel = (String) record.get(0);
                 String ghId = (String) record.get(1);
-                int firstLevelCount = Integer.parseInt((String) record.get(2));
+                Integer firstLevelCount = parseInteger(record.get(2));
                 Integer fissionCount = parseInteger(record.get(3));
-                item.setDateStr(dt);
+                Double fissionArpu = parseDouble(record.get(4));
+                if (fissionArpu > 0.3) {
+                    fissionArpu = 0.3;
+                }
+                if ("SUM".equals(channel)) {
+                    BigDecimal fissionRate = BigDecimal.valueOf(fissionCount.doubleValue() * 10 / firstLevelCount)
+                            .setScale(2, RoundingMode.HALF_UP);
+                    fissionArpu = BigDecimal.valueOf(fissionArpu).setScale(2, RoundingMode.HALF_UP).doubleValue();
+                    sumScore = fissionRate.add(new BigDecimal(fissionArpu));
+                    continue;
+                }
                 if (!ghIds.contains(ghId)) {
                     continue;
                 }
                 ContentPlatformGzhAccount gzhAccount = accountMap.get(ghId);
+                ContentPlatformGzhDataStat item = new ContentPlatformGzhDataStat();
+                item.setDateStr(dt);
                 item.setAccountId(gzhAccount.getId());
                 item.setFirstLevelCount(firstLevelCount);
                 WxAccountDatastatVO wxAccountDatastatVO = wxAccountDatastatMap.get(gzhAccount.getExternalId());
@@ -111,13 +124,25 @@ public class ContentPlatformDatastatJob {
                 }
 
                 if (fissionCount > 0 && firstLevelCount > 0) {
-                    BigDecimal num = BigDecimal.valueOf(fissionCount.doubleValue() * 10 / firstLevelCount);
-                    BigDecimal rounded = num.setScale(2, RoundingMode.HALF_UP);
-                    item.setScore(rounded.doubleValue());
+                    BigDecimal fissionRate = BigDecimal.valueOf(fissionCount.doubleValue() * 10 / firstLevelCount)
+                            .setScale(2, RoundingMode.HALF_UP);
+                    fissionArpu = BigDecimal.valueOf(fissionArpu).setScale(2, RoundingMode.HALF_UP).doubleValue();
+                    BigDecimal totalScore = fissionRate.add(new BigDecimal(fissionArpu));
+                    item.setScore(totalScore.doubleValue());
                 }
                 item.setCreateTimestamp(now);
                 saveList.add(item);
             }
+            for (ContentPlatformGzhDataStat item : saveList) {
+                if (item.getFirstLevelCount() < 10) {
+                    item.setScore(0.0);
+                    continue;
+                }
+                if (Objects.nonNull(item.getScore())) {
+                    BigDecimal score = BigDecimal.valueOf(item.getScore());
+                    item.setScore(score.divide(sumScore, 2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(10)).doubleValue());
+                }
+            }
             if (CollectionUtils.isNotEmpty(saveList)) {
                 dataStatMapperExt.deleteGzhDatastat(dt);
                 dataStatMapperExt.batchInsertGzhDatastat(saveList);
@@ -186,15 +211,15 @@ public class ContentPlatformDatastatJob {
         Long now = System.currentTimeMillis();
         // 公众号自动回复数据统计
         String sql = String.format(
-                "SELECT first_level.channel_shortname, first_level.first_uv, fission.split_uv, price.arpu " +
-                "FROM loghubods.out_channel_mid_first_total first_level " +
-                "left join loghubods.out_channel_mid_split_total fission " +
-                "on first_level.channel_shortname = fission.channel_shortname and first_level.dt = fission.dt " +
-                "and first_level.type = fission.type and first_level.tag = fission.tag " +
-                "left join loghubods.wecom_cooperation_dynamic_unit_price price " +
-                "on first_level.channel_shortname = price.channel_shortname and first_level.dt = price.dt " +
-                "and first_level.type = price.type and first_level.tag = price.tag " +
-                "WHERE first_level.dt = %s and first_level.type = '公众号即时回复' and first_level.tag = '投放渠道内去重' ;", dt);
+                "SELECT first_level.channel_shortname, first_level.first_uv, fission.split_uv, fission.裂变arpu, price.arpu " +
+                        "FROM loghubods.out_channel_mid_first_total first_level " +
+                        "left join loghubods.out_channel_mid_split_total fission " +
+                        "on first_level.channel_shortname = fission.channel_shortname and first_level.dt = fission.dt " +
+                        "and first_level.type = fission.type and first_level.tag = fission.tag " +
+                        "left join loghubods.wecom_cooperation_dynamic_unit_price price " +
+                        "on first_level.channel_shortname = price.channel_shortname and first_level.dt = price.dt " +
+                        "and first_level.type = price.type and first_level.tag = price.tag " +
+                        "WHERE first_level.dt = %s and first_level.type = '公众号即时回复' and first_level.tag = '投放渠道内去重' ;", dt);
         List<Record> dataList = OdpsUtil.getOdpsData(sql);
         // 所有公众号
         List<ContentPlatformAccount> accountList = getAllAccount();
@@ -210,16 +235,24 @@ public class ContentPlatformDatastatJob {
         Map<String, WxAccountDatastatVO> wxAccountDatastatMap = wxAccountDatastatVOList.stream()
                 .collect(Collectors.toMap(WxAccountDatastatVO::getAccountId, wxAccountDatastatVO -> wxAccountDatastatVO));
         if (CollectionUtils.isNotEmpty(dataList)) {
+            BigDecimal sumScore = BigDecimal.ZERO;
             List<ContentPlatformGzhDataStatTotal> saveList = new ArrayList<>();
             for (Record record : dataList) {
-                ContentPlatformGzhDataStatTotal item = new ContentPlatformGzhDataStatTotal();
                 String channel = record.getString(0);
-                int firstLevelCount = Integer.parseInt((String) record.get(1));
+                Integer firstLevelCount = parseInteger(record.get(1));
                 Integer fissionCount = parseInteger(record.get(2));
-                Double arpu = parseDouble(record.get(3));
-                item.setDateStr(dt);
-                item.setChannel(channel);
-                item.setFirstLevelCount(firstLevelCount);
+                Double fissionArpu = parseDouble(record.get(3));
+                if (fissionArpu > 0.3) {
+                    fissionArpu = 0.3;
+                }
+                Double arpu = parseDouble(record.get(4));
+                if ("SUM".equals(channel)) {
+                    BigDecimal fissionRate = BigDecimal.valueOf(fissionCount.doubleValue() * 10 / firstLevelCount)
+                            .setScale(2, RoundingMode.HALF_UP);
+                    fissionArpu = BigDecimal.valueOf(fissionArpu).setScale(2, RoundingMode.HALF_UP).doubleValue();
+                    sumScore = fissionRate.add(new BigDecimal(fissionArpu));
+                    continue;
+                }
                 ContentPlatformAccount account = accountMap.get(channel);
                 if (Objects.isNull(account)) {
                     continue;
@@ -234,12 +267,19 @@ public class ContentPlatformDatastatJob {
                         }
                     }
                 }
+                ContentPlatformGzhDataStatTotal item = new ContentPlatformGzhDataStatTotal();
+                item.setDateStr(dt);
+                item.setChannel(channel);
+                item.setFirstLevelCount(firstLevelCount);
                 item.setFansIncreaseCount(fansIncreaseCount);
 
                 if (fissionCount > 0 && firstLevelCount > 0) {
-                    BigDecimal fissionRate = BigDecimal.valueOf(fissionCount.doubleValue() / firstLevelCount);
-                    BigDecimal rounded = fissionRate.multiply(new BigDecimal(10)).setScale(2, RoundingMode.HALF_UP);
-                    item.setScore(rounded.doubleValue());
+                    BigDecimal fissionRate = BigDecimal.valueOf(fissionCount.doubleValue() * 10 / firstLevelCount)
+                            .setScale(2, RoundingMode.HALF_UP);
+                    fissionArpu = BigDecimal.valueOf(fissionArpu).setScale(2, RoundingMode.HALF_UP).doubleValue();
+                    BigDecimal totalScore = fissionRate.add(new BigDecimal(fissionArpu));
+                    item.setScore(totalScore.doubleValue());
+
                     BigDecimal unitPrice = getUnitPrice(account.getPrice(), fissionRate, arpu, BussinessTypeEnum.GZH_AUTO_REPLY);
                     if (Objects.nonNull(unitPrice)) {
                         item.setUnitPrice(unitPrice.doubleValue());
@@ -254,6 +294,16 @@ public class ContentPlatformDatastatJob {
                 item.setCreateTimestamp(now);
                 saveList.add(item);
             }
+            for (ContentPlatformGzhDataStatTotal item : saveList) {
+                if (item.getFirstLevelCount() < 25) {
+                    item.setScore(0.0);
+                    continue;
+                }
+                if (Objects.nonNull(item.getScore())) {
+                    BigDecimal score = BigDecimal.valueOf(item.getScore());
+                    item.setScore(score.divide(sumScore, 2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(10)).doubleValue());
+                }
+            }
             if (CollectionUtils.isNotEmpty(saveList)) {
                 dataStatMapperExt.deleteGzhDatastatTotal(dt);
                 dataStatMapperExt.batchInsertGzhDatastatTotal(saveList);
@@ -272,11 +322,11 @@ public class ContentPlatformDatastatJob {
         // 公众号自动回复数据统计
         String sql = String.format(
                 "SELECT first_level.subchannel, first_level.first_uv, fission.split_uv " +
-                "FROM loghubods.out_channel_mid_first_total first_level " +
-                "left join loghubods.out_channel_mid_split_total fission " +
-                "on first_level.subchannel = fission.subchannel and first_level.dt = fission.dt " +
-                "and first_level.type = fission.type and first_level.tag = fission.tag " +
-                "WHERE first_level.dt = %s and first_level.type = '服务号代运营' and first_level.tag = '分投放渠道客户分账号去重' ;", dt);
+                        "FROM loghubods.out_channel_mid_first_total first_level " +
+                        "left join loghubods.out_channel_mid_split_total fission " +
+                        "on first_level.subchannel = fission.subchannel and first_level.dt = fission.dt " +
+                        "and first_level.type = fission.type and first_level.tag = fission.tag " +
+                        "WHERE first_level.dt = %s and first_level.type = '服务号代运营' and first_level.tag = '分投放渠道客户分账号去重' ;", dt);
         List<Record> dataList = OdpsUtil.getOdpsData(sql);
         // 所有公众号
         List<ContentPlatformGzhAccount> accountList = getAllGzhAccount();
@@ -334,14 +384,14 @@ public class ContentPlatformDatastatJob {
         // 公众号自动回复数据统计
         String sql = String.format(
                 "SELECT first_level.channel_shortname, first_level.first_uv, fission.split_uv, price.arpu " +
-                "FROM loghubods.out_channel_mid_first_total first_level " +
-                "left join loghubods.out_channel_mid_split_total fission " +
-                "on first_level.channel_shortname = fission.channel_shortname and first_level.dt = fission.dt " +
-                "and first_level.type = fission.type and first_level.tag = fission.tag " +
-                "left join loghubods.wecom_cooperation_dynamic_unit_price price " +
-                "on first_level.channel_shortname = price.channel_shortname and first_level.dt = price.dt " +
-                "and first_level.type = price.type and first_level.tag = price.tag " +
-                "WHERE first_level.dt = %s and first_level.type = '服务号代运营' and first_level.tag = '投放渠道内去重' ;", dt);
+                        "FROM loghubods.out_channel_mid_first_total first_level " +
+                        "left join loghubods.out_channel_mid_split_total fission " +
+                        "on first_level.channel_shortname = fission.channel_shortname and first_level.dt = fission.dt " +
+                        "and first_level.type = fission.type and first_level.tag = fission.tag " +
+                        "left join loghubods.wecom_cooperation_dynamic_unit_price price " +
+                        "on first_level.channel_shortname = price.channel_shortname and first_level.dt = price.dt " +
+                        "and first_level.type = price.type and first_level.tag = price.tag " +
+                        "WHERE first_level.dt = %s and first_level.type = '服务号代运营' and first_level.tag = '投放渠道内去重' ;", dt);
         List<Record> dataList = OdpsUtil.getOdpsData(sql);
         // 所有公众号
         List<ContentPlatformAccount> accountList = getAllAccount();
@@ -419,11 +469,11 @@ public class ContentPlatformDatastatJob {
         // 公众号自动回复数据统计
         String sql = String.format(
                 "SELECT first_level.subchannel, first_level.first_uv, fission.split_uv " +
-                "FROM loghubods.out_channel_mid_first_total first_level " +
-                "left join loghubods.out_channel_mid_split_total fission " +
-                "on first_level.subchannel = fission.subchannel and first_level.dt = fission.dt " +
-                "and first_level.type = fission.type and first_level.tag = fission.tag " +
-                "WHERE first_level.dt = %s and first_level.type = '公众号推送' and first_level.tag = '分投放渠道客户分账号去重' ;", dt);
+                        "FROM loghubods.out_channel_mid_first_total first_level " +
+                        "left join loghubods.out_channel_mid_split_total fission " +
+                        "on first_level.subchannel = fission.subchannel and first_level.dt = fission.dt " +
+                        "and first_level.type = fission.type and first_level.tag = fission.tag " +
+                        "WHERE first_level.dt = %s and first_level.type = '公众号推送' and first_level.tag = '分投放渠道客户分账号去重' ;", dt);
         List<Record> dataList = OdpsUtil.getOdpsData(sql);
         // 所有公众号
         List<ContentPlatformGzhAccount> accountList = getAllGzhAccount();
@@ -481,14 +531,14 @@ public class ContentPlatformDatastatJob {
         // 公众号自动回复数据统计
         String sql = String.format(
                 "SELECT first_level.channel_shortname, first_level.first_uv, fission.split_uv, price.arpu " +
-                "FROM loghubods.out_channel_mid_first_total first_level " +
-                "left join loghubods.out_channel_mid_split_total fission " +
-                "on first_level.channel_shortname = fission.channel_shortname and first_level.dt = fission.dt " +
-                "and first_level.type = fission.type and first_level.tag = fission.tag " +
-                "left join loghubods.wecom_cooperation_dynamic_unit_price price " +
-                "on first_level.channel_shortname = price.channel_shortname and first_level.dt = price.dt " +
-                "and first_level.type = price.type and first_level.tag = price.tag " +
-                "WHERE first_level.dt = %s and first_level.type = '公众号推送' and first_level.tag = '投放渠道内去重' ;", dt);
+                        "FROM loghubods.out_channel_mid_first_total first_level " +
+                        "left join loghubods.out_channel_mid_split_total fission " +
+                        "on first_level.channel_shortname = fission.channel_shortname and first_level.dt = fission.dt " +
+                        "and first_level.type = fission.type and first_level.tag = fission.tag " +
+                        "left join loghubods.wecom_cooperation_dynamic_unit_price price " +
+                        "on first_level.channel_shortname = price.channel_shortname and first_level.dt = price.dt " +
+                        "and first_level.type = price.type and first_level.tag = price.tag " +
+                        "WHERE first_level.dt = %s and first_level.type = '公众号推送' and first_level.tag = '投放渠道内去重' ;", dt);
         List<Record> dataList = OdpsUtil.getOdpsData(sql);
         // 所有公众号
         List<ContentPlatformAccount> accountList = getAllAccount();
@@ -718,14 +768,14 @@ public class ContentPlatformDatastatJob {
         Map<String, ContentPlatformQwDataStatTotal> saveMap = new HashMap<>();
         String outSql = String.format(
                 "SELECT first_level.channel_shortname, first_level.first_uv, fission.split_uv, price.arpu " +
-                "FROM loghubods.out_channel_mid_first_total first_level " +
-                "left join loghubods.out_channel_mid_split_total fission " +
-                "on first_level.channel_shortname = fission.channel_shortname and first_level.dt = fission.dt " +
-                "and first_level.type = fission.type and first_level.tag = fission.tag " +
-                "left join loghubods.wecom_cooperation_dynamic_unit_price price " +
-                "on first_level.channel_shortname = price.channel_shortname and first_level.dt = price.dt " +
-                "and first_level.type = price.type and first_level.tag = price.tag " +
-                "WHERE first_level.dt = %s and first_level.type = '企微外部' and first_level.tag = '投放渠道内去重' ;", dt);
+                        "FROM loghubods.out_channel_mid_first_total first_level " +
+                        "left join loghubods.out_channel_mid_split_total fission " +
+                        "on first_level.channel_shortname = fission.channel_shortname and first_level.dt = fission.dt " +
+                        "and first_level.type = fission.type and first_level.tag = fission.tag " +
+                        "left join loghubods.wecom_cooperation_dynamic_unit_price price " +
+                        "on first_level.channel_shortname = price.channel_shortname and first_level.dt = price.dt " +
+                        "and first_level.type = price.type and first_level.tag = price.tag " +
+                        "WHERE first_level.dt = %s and first_level.type = '企微外部' and first_level.tag = '投放渠道内去重' ;", dt);
         List<Record> outDataList = OdpsUtil.getOdpsData(outSql);
         List<ContentPlatformAccount> accountList = getAllAccount();
         Map<String, ContentPlatformAccount> accountMap = accountList.stream()
@@ -870,14 +920,14 @@ public class ContentPlatformDatastatJob {
         List<ContentPlatformQwDataStatSubChannel> saveList = new ArrayList<>();
         String outSql = String.format(
                 "SELECT first_level.channel_shortname, first_level.subchannel, first_level.first_uv, fission.split_uv, price.arpu " +
-                "FROM loghubods.out_channel_mid_first_total first_level " +
-                "left join loghubods.out_channel_mid_split_total fission " +
-                "on first_level.channel_shortname = fission.channel_shortname and first_level.subchannel = fission.subchannel " +
-                "and first_level.dt = fission.dt and first_level.type = fission.type and first_level.tag = fission.tag " +
-                "left join loghubods.wecom_cooperation_dynamic_unit_price price " +
-                "on first_level.channel_shortname = price.channel_shortname and first_level.subchannel = price.subchannel " +
-                "and first_level.dt = price.dt and first_level.type = price.type and first_level.tag = price.tag " +
-                "WHERE first_level.dt = %s and first_level.type = '企微外部' and first_level.tag = '分投放渠道客户分账号去重' ;", dt);
+                        "FROM loghubods.out_channel_mid_first_total first_level " +
+                        "left join loghubods.out_channel_mid_split_total fission " +
+                        "on first_level.channel_shortname = fission.channel_shortname and first_level.subchannel = fission.subchannel " +
+                        "and first_level.dt = fission.dt and first_level.type = fission.type and first_level.tag = fission.tag " +
+                        "left join loghubods.wecom_cooperation_dynamic_unit_price price " +
+                        "on first_level.channel_shortname = price.channel_shortname and first_level.subchannel = price.subchannel " +
+                        "and first_level.dt = price.dt and first_level.type = price.type and first_level.tag = price.tag " +
+                        "WHERE first_level.dt = %s and first_level.type = '企微外部' and first_level.tag = '分投放渠道客户分账号去重' ;", dt);
         List<Record> outDataList = OdpsUtil.getOdpsData(outSql);
         List<ContentPlatformAccount> accountList = getAllAccount();
         Map<String, ContentPlatformAccount> accountMap = accountList.stream()

+ 1 - 1
api-module/src/main/java/com/tzld/piaoquan/api/model/vo/contentplatform/GzhAccountVideoDatastatItemExportVO.java

@@ -31,6 +31,6 @@ public class GzhAccountVideoDatastatItemExportVO {
     @ExcelProperty("小程序访问人数")
     private Integer firstLevel;
 
-    @ExcelProperty("本渠道裂变率")
+    @ExcelProperty("本渠道质量分")
     private Double score;
 }

+ 1 - 1
api-module/src/main/java/com/tzld/piaoquan/api/model/vo/contentplatform/GzhDatastatItemExportVO.java

@@ -34,6 +34,6 @@ public class GzhDatastatItemExportVO {
     @ExcelProperty("打开率")
     private Double openRate;
 
-    @ExcelProperty("本渠道裂变率")
+    @ExcelProperty("本渠道质量分")
     private Double score;
 }

+ 1 - 1
api-module/src/main/java/com/tzld/piaoquan/api/model/vo/contentplatform/GzhDatastatItemVO.java

@@ -30,7 +30,7 @@ public class GzhDatastatItemVO {
     @ApiModelProperty(value = "打开率")
     private Double openRate;
 
-    @ApiModelProperty(value = "分")
+    @ApiModelProperty(value = "本渠道质量分")
     private Double score;
 
     @ApiModelProperty(value = "预估单价")

+ 1 - 1
api-module/src/main/java/com/tzld/piaoquan/api/model/vo/contentplatform/GzhTotalDatastatItemExportVO.java

@@ -28,7 +28,7 @@ public class GzhTotalDatastatItemExportVO {
     @ExcelProperty("打开率")
     private Double openRate;
 
-    @ExcelProperty("本渠道裂变率")
+    @ExcelProperty("本渠道质量分")
     private Double score;
 
     @ExcelProperty(value = "预估单价")

+ 2 - 9
api-module/src/main/java/com/tzld/piaoquan/api/service/contentplatform/impl/ContentPlatformNoticeServiceImpl.java

@@ -39,15 +39,8 @@ public class ContentPlatformNoticeServiceImpl implements ContentPlatformNoticeSe
         for (ContentPlatformIllegalMsg item : list) {
             NoticeItemVO vo = new NoticeItemVO();
             vo.setId(item.getId());
-            String videoTitle = item.getTitle();
-            if (videoTitle.length() >= 20) {
-                videoTitle = videoTitle.substring(0, 19) + "...";
-            }
-            String title = "视频“" + videoTitle + "”被封禁,请及时替换";
-            vo.setTitle(title);
-            String msg = "您在" + item.getBusinessType() + "栏目中使用的视频“" +
-                    videoTitle + "”(视频ID:" + item.getVideoId() + ")被微信封禁,请及时替换为其他视频。";
-            vo.setMsg(msg);
+            vo.setTitle(item.getIllegalTitle());
+            vo.setMsg(item.getIllegalContent());
             vo.setStatus(item.getStatus());
             vo.setCreateTimestamp(item.getCreateTimestamp());
             records.add(vo);