Browse Source

新增数据项

wangyunpeng 1 month ago
parent
commit
913caf0090

+ 65 - 189
api-module/src/main/java/com/tzld/piaoquan/api/job/ContentPlatformDatastatJob.java

@@ -1,7 +1,6 @@
 package com.tzld.piaoquan.api.job;
 
 import com.aliyun.odps.data.Record;
-import com.tzld.piaoquan.api.common.enums.contentplatform.ContentPlatformGzhPlanTypeEnum;
 import com.tzld.piaoquan.api.component.AigcApiService;
 import com.tzld.piaoquan.api.dao.mapper.contentplatform.*;
 import com.tzld.piaoquan.api.dao.mapper.contentplatform.ext.ContentPlatformDataStatMapperExt;
@@ -45,9 +44,6 @@ public class ContentPlatformDatastatJob {
     @Autowired
     private ContentPlatformQwPlanMapper qwPlanMapper;
 
-    @Autowired
-    private ContentPlatformQwPlanVideoMapper qwPlanVideoMapper;
-
     @Autowired
     private ContentPlatformDataStatMapperExt dataStatMapperExt;
 
@@ -70,39 +66,29 @@ public class ContentPlatformDatastatJob {
         }
         Long now = System.currentTimeMillis();
         // 公众号自动回复数据统计
-        String sql = String.format("SELECT 合作方, 公众号id, 访问人数, 首层访问人数, dt " +
-                "FROM loghubods.gzh_autoreply_behavior_uv_total WHERE dt=%s;", dt);
+        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 " +
+                "WHERE   first_level.dt = %s and first_level.type = '公众号即时回复' and first_level.tag = '投放渠道内分客户分账号去重';", dt);
         List<Record> dataList = OdpsUtil.getOdpsData(sql);
         // 所有公众号
         List<ContentPlatformGzhAccount> accountList = getAllGzhAccount();
         Map<String, ContentPlatformGzhAccount> accountMap = accountList.stream()
                 .collect(Collectors.toMap(ContentPlatformGzhAccount::getGhId, account -> account));
-        List<Long> accountIds = accountList.stream().map(ContentPlatformGzhAccount::getId).collect(Collectors.toList());
         List<String> ghIds = accountList.stream().map(ContentPlatformGzhAccount::getGhId).collect(Collectors.toList());
         List<String> accountExternalIds = accountList.stream().map(ContentPlatformGzhAccount::getExternalId).collect(Collectors.toList());
         String dateStr = dt.substring(0, 4) + "-" + dt.substring(4, 6) + "-" + dt.substring(6, 8);
         List<WxAccountDatastatVO> wxAccountDatastatVOList = aigcApiService.getWxAccountDatastat(dateStr, accountExternalIds);
         Map<String, WxAccountDatastatVO> wxAccountDatastatMap = wxAccountDatastatVOList.stream()
                 .collect(Collectors.toMap(WxAccountDatastatVO::getAccountId, wxAccountDatastatVO -> wxAccountDatastatVO));
-        List<ContentPlatformGzhPlan> gzhPlanList = planService.getGzhPlanListByCooperateAccountIds(accountIds,
-                ContentPlatformGzhPlanTypeEnum.AUTO_REPLY.getVal());
-        List<Long> planIds = gzhPlanList.stream().map(ContentPlatformGzhPlan::getId).collect(Collectors.toList());
-        Map<Long, List<Long>> gzhPlanMap = gzhPlanList.stream()
-                .collect(Collectors.groupingBy(ContentPlatformGzhPlan::getAccountId,
-                        Collectors.mapping(ContentPlatformGzhPlan::getId, Collectors.toList())));
-        List<ContentPlatformGzhPlanVideo> gzhPlanVideoList = planService.getGzhPlanVideoList(planIds);
-        Map<Long, List<ContentPlatformGzhPlanVideo>> gzhPlanVideoMap = gzhPlanVideoList.stream()
-                .collect(Collectors.groupingBy(ContentPlatformGzhPlanVideo::getPlanId));
-        List<Long> videoIds = gzhPlanVideoList.stream().map(ContentPlatformGzhPlanVideo::getVideoId).collect(Collectors.toList());
-        List<ContentPlatformVideoAgg> contentPlatformVideoList = planService.getVideoContentAggListByVideoIds(videoIds);
-        Map<Long, ContentPlatformVideoAgg> videoMap = contentPlatformVideoList.stream()
-                .collect(Collectors.toMap(ContentPlatformVideoAgg::getVideoId, video -> video, (a, b) -> a));
         if (CollectionUtils.isNotEmpty(dataList)) {
             List<ContentPlatformGzhDataStat> saveList = new ArrayList<>();
             for (Record record : dataList) {
                 ContentPlatformGzhDataStat item = new ContentPlatformGzhDataStat();
                 String ghId = (String) record.get(1);
-                Integer firstLevelCount = Integer.valueOf((String) record.get(3));
+                Integer firstLevelCount = Integer.valueOf((String) record.get(2));
+                Integer fissionCount = parseInteger(record.get(3));
                 item.setDateStr(dt);
                 if (!ghIds.contains(ghId)) {
                     continue;
@@ -114,26 +100,9 @@ public class ContentPlatformDatastatJob {
                 if (Objects.nonNull(wxAccountDatastatVO)) {
                     item.setFansIncreaseCount(wxAccountDatastatVO.getFansIncreaseCount());
                 }
-                List<Long> planIdList = gzhPlanMap.get(gzhAccount.getId());
-                if (CollectionUtils.isEmpty(planIdList)) {
-                    continue;
-                }
-                Double score = 0.0;
-                int size = 0;
-                for (Long planId : planIdList) {
-                    List<ContentPlatformGzhPlanVideo> videoList = gzhPlanVideoMap.get(planId);
-                    if (CollectionUtils.isNotEmpty(videoList)) {
-                        List<Long> itemVideoIds = videoList.stream().map(ContentPlatformGzhPlanVideo::getVideoId).collect(Collectors.toList());
-                        for (Long videoId : itemVideoIds) {
-                            if (Objects.nonNull(videoMap.get(videoId))) {
-                                score += videoMap.get(videoId).getScore();
-                            }
-                        }
-                        size += videoList.size();
-                    }
-                }
-                if (size > 0) {
-                    BigDecimal num = BigDecimal.valueOf(score / size);
+
+                if (Objects.nonNull(fissionCount) && fissionCount > 0 && firstLevelCount > 0) {
+                    BigDecimal num = BigDecimal.valueOf(fissionCount / firstLevelCount);
                     BigDecimal rounded = num.setScale(2, RoundingMode.HALF_UP);
                     item.setScore(rounded.doubleValue());
                 }
@@ -155,8 +124,11 @@ public class ContentPlatformDatastatJob {
         }
         Long now = System.currentTimeMillis();
         // 公众号自动回复数据统计
-        String sql = String.format("SELECT channel_shortname, first_uv, dt " +
-                "FROM loghubods.out_channel_mid_first_total WHERE tag = '投放渠道内去重' and type = '公众号即时回复' and dt=%s;", dt);
+        String sql = String.format("SELECT  first_level.channel_shortname, 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 " +
+                "WHERE   first_level.dt = %s and first_level.type = '公众号即时回复' and first_level.tag = '投放渠道内去重' ;", dt);
         List<Record> dataList = OdpsUtil.getOdpsData(sql);
         // 所有公众号
         List<ContentPlatformAccount> accountList = getAllAccount();
@@ -165,31 +137,18 @@ public class ContentPlatformDatastatJob {
         List<ContentPlatformGzhAccount> gzhAccountList = getAllGzhAccount();
         Map<Long, List<ContentPlatformGzhAccount>> gzhAccountMap = gzhAccountList.stream()
                 .collect(Collectors.groupingBy(ContentPlatformGzhAccount::getCreateAccountId));
-        List<Long> accountIds = gzhAccountList.stream().map(ContentPlatformGzhAccount::getId).collect(Collectors.toList());
         List<String> accountExternalIds = gzhAccountList.stream().map(ContentPlatformGzhAccount::getExternalId).collect(Collectors.toList());
         String dateStr = dt.substring(0, 4) + "-" + dt.substring(4, 6) + "-" + dt.substring(6, 8);
         List<WxAccountDatastatVO> wxAccountDatastatVOList = aigcApiService.getWxAccountDatastat(dateStr, accountExternalIds);
         Map<String, WxAccountDatastatVO> wxAccountDatastatMap = wxAccountDatastatVOList.stream()
                 .collect(Collectors.toMap(WxAccountDatastatVO::getAccountId, wxAccountDatastatVO -> wxAccountDatastatVO));
-        List<ContentPlatformGzhPlan> gzhPlanList = planService.getGzhPlanListByCooperateAccountIds(accountIds,
-                ContentPlatformGzhPlanTypeEnum.AUTO_REPLY.getVal());
-        List<Long> planIds = gzhPlanList.stream().map(ContentPlatformGzhPlan::getId).collect(Collectors.toList());
-        Map<Long, List<Long>> gzhPlanMap = gzhPlanList.stream()
-                .collect(Collectors.groupingBy(ContentPlatformGzhPlan::getAccountId,
-                        Collectors.mapping(ContentPlatformGzhPlan::getId, Collectors.toList())));
-        List<ContentPlatformGzhPlanVideo> gzhPlanVideoList = planService.getGzhPlanVideoList(planIds);
-        Map<Long, List<ContentPlatformGzhPlanVideo>> gzhPlanVideoMap = gzhPlanVideoList.stream()
-                .collect(Collectors.groupingBy(ContentPlatformGzhPlanVideo::getPlanId));
-        List<Long> videoIds = gzhPlanVideoList.stream().map(ContentPlatformGzhPlanVideo::getVideoId).collect(Collectors.toList());
-        List<ContentPlatformVideoAgg> contentPlatformVideoList = planService.getVideoContentAggListByVideoIds(videoIds);
-        Map<Long, ContentPlatformVideoAgg> videoMap = contentPlatformVideoList.stream()
-                .collect(Collectors.toMap(ContentPlatformVideoAgg::getVideoId, video -> video, (a, b) -> a));
         if (CollectionUtils.isNotEmpty(dataList)) {
             List<ContentPlatformGzhDataStatTotal> saveList = new ArrayList<>();
             for (Record record : dataList) {
                 ContentPlatformGzhDataStatTotal item = new ContentPlatformGzhDataStatTotal();
                 String channel = record.getString(0);
                 Integer firstLevelCount = Integer.valueOf((String) record.get(1));
+                Integer fissionCount = parseInteger(record.get(2));
                 item.setDateStr(dt);
                 item.setChannel(channel);
                 item.setFirstLevelCount(firstLevelCount);
@@ -199,33 +158,16 @@ public class ContentPlatformDatastatJob {
                 }
                 List<ContentPlatformGzhAccount> gzhAccounts = gzhAccountMap.get(account.getId());
                 int fansIncreaseCount = 0;
-                Double score = 0.0;
-                int size = 0;
                 for (ContentPlatformGzhAccount gzhAccount : gzhAccounts) {
                     WxAccountDatastatVO wxAccountDatastatVO = wxAccountDatastatMap.get(gzhAccount.getExternalId());
                     if (Objects.nonNull(wxAccountDatastatVO)) {
                         fansIncreaseCount += wxAccountDatastatVO.getFansIncreaseCount();
                     }
-                    List<Long> planIdList = gzhPlanMap.get(gzhAccount.getId());
-                    if (CollectionUtils.isEmpty(planIdList)) {
-                        continue;
-                    }
-                    for (Long planId : planIdList) {
-                        List<ContentPlatformGzhPlanVideo> videoList = gzhPlanVideoMap.get(planId);
-                        if (CollectionUtils.isNotEmpty(videoList)) {
-                            List<Long> itemVideoIds = videoList.stream().map(ContentPlatformGzhPlanVideo::getVideoId).collect(Collectors.toList());
-                            for (Long videoId : itemVideoIds) {
-                                if (Objects.nonNull(videoMap.get(videoId))) {
-                                    score += videoMap.get(videoId).getScore();
-                                }
-                            }
-                            size += videoList.size();
-                        }
-                    }
                 }
                 item.setFansIncreaseCount(fansIncreaseCount);
-                if (size > 0) {
-                    BigDecimal num = BigDecimal.valueOf(score / size);
+
+                if (Objects.nonNull(fissionCount) && fissionCount > 0 && firstLevelCount > 0) {
+                    BigDecimal num = BigDecimal.valueOf(fissionCount / firstLevelCount);
                     BigDecimal rounded = num.setScale(2, RoundingMode.HALF_UP);
                     item.setScore(rounded.doubleValue());
                 }
@@ -252,39 +194,29 @@ public class ContentPlatformDatastatJob {
         }
         Long now = System.currentTimeMillis();
         // 公众号自动回复数据统计
-        String sql = String.format("SELECT ghid, 首层访问人数, dt " +
-                "FROM loghubods.fwhhzdyy_data_per_ghid WHERE dt=%s;", dt);
+        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.channel_shortname = fission.channel_shortname and first_level.subchannel = fission.subchannel and first_level.dt = fission.dt " +
+                "WHERE   first_level.dt = %s and first_level.type = '服务号代运营' and first_level.tag = '投放渠道内分客户分账号去重' ;", dt);
         List<Record> dataList = OdpsUtil.getOdpsData(sql);
         // 所有公众号
         List<ContentPlatformGzhAccount> accountList = getAllGzhAccount();
         Map<String, ContentPlatformGzhAccount> accountMap = accountList.stream()
                 .collect(Collectors.toMap(ContentPlatformGzhAccount::getGhId, account -> account));
-        List<Long> accountIds = accountList.stream().map(ContentPlatformGzhAccount::getId).collect(Collectors.toList());
         List<String> ghIds = accountList.stream().map(ContentPlatformGzhAccount::getGhId).collect(Collectors.toList());
         List<String> accountExternalIds = accountList.stream().map(ContentPlatformGzhAccount::getExternalId).collect(Collectors.toList());
         String dateStr = dt.substring(0, 4) + "-" + dt.substring(4, 6) + "-" + dt.substring(6, 8);
         List<WxAccountDatastatVO> wxAccountDatastatVOList = aigcApiService.getWxAccountDatastat(dateStr, accountExternalIds);
         Map<String, WxAccountDatastatVO> wxAccountDatastatMap = wxAccountDatastatVOList.stream()
                 .collect(Collectors.toMap(WxAccountDatastatVO::getAccountId, wxAccountDatastatVO -> wxAccountDatastatVO));
-        List<ContentPlatformGzhPlan> gzhPlanList = planService.getGzhPlanListByCooperateAccountIds(accountIds,
-                ContentPlatformGzhPlanTypeEnum.FWH_PUSH.getVal());
-        List<Long> planIds = gzhPlanList.stream().map(ContentPlatformGzhPlan::getId).collect(Collectors.toList());
-        Map<Long, List<Long>> gzhPlanMap = gzhPlanList.stream()
-                .collect(Collectors.groupingBy(ContentPlatformGzhPlan::getAccountId,
-                        Collectors.mapping(ContentPlatformGzhPlan::getId, Collectors.toList())));
-        List<ContentPlatformGzhPlanVideo> gzhPlanVideoList = planService.getGzhPlanVideoList(planIds);
-        Map<Long, List<ContentPlatformGzhPlanVideo>> gzhPlanVideoMap = gzhPlanVideoList.stream()
-                .collect(Collectors.groupingBy(ContentPlatformGzhPlanVideo::getPlanId));
-        List<Long> videoIds = gzhPlanVideoList.stream().map(ContentPlatformGzhPlanVideo::getVideoId).collect(Collectors.toList());
-        List<ContentPlatformVideoAgg> contentPlatformVideoList = planService.getVideoContentAggListByVideoIds(videoIds);
-        Map<Long, ContentPlatformVideoAgg> videoMap = contentPlatformVideoList.stream()
-                .collect(Collectors.toMap(ContentPlatformVideoAgg::getVideoId, video -> video, (a, b) -> a));
         if (CollectionUtils.isNotEmpty(dataList)) {
             List<ContentPlatformFwhDataStat> saveList = new ArrayList<>();
             for (Record record : dataList) {
                 ContentPlatformFwhDataStat item = new ContentPlatformFwhDataStat();
                 String ghId = (String) record.get(0);
                 Integer firstLevelCount = Integer.valueOf((String) record.get(1));
+                Integer fissionCount = parseInteger(record.get(2));
                 item.setDateStr(dt);
                 if (!ghIds.contains(ghId)) {
                     continue;
@@ -296,26 +228,9 @@ public class ContentPlatformDatastatJob {
                 if (Objects.nonNull(wxAccountDatastatVO)) {
                     item.setFansIncreaseCount(wxAccountDatastatVO.getFansIncreaseCount());
                 }
-                List<Long> planIdList = gzhPlanMap.get(gzhAccount.getId());
-                if (CollectionUtils.isEmpty(planIdList)) {
-                    continue;
-                }
-                Double score = 0.0;
-                int size = 0;
-                for (Long planId : planIdList) {
-                    List<ContentPlatformGzhPlanVideo> videoList = gzhPlanVideoMap.get(planId);
-                    if (CollectionUtils.isNotEmpty(videoList)) {
-                        List<Long> itemVideoIds = videoList.stream().map(ContentPlatformGzhPlanVideo::getVideoId).collect(Collectors.toList());
-                        for (Long videoId : itemVideoIds) {
-                            if (Objects.nonNull(videoMap.get(videoId))) {
-                                score += videoMap.get(videoId).getScore();
-                            }
-                        }
-                        size += videoList.size();
-                    }
-                }
-                if (size > 0) {
-                    BigDecimal num = BigDecimal.valueOf(score / size);
+
+                if (Objects.nonNull(fissionCount) && fissionCount > 0 && firstLevelCount > 0) {
+                    BigDecimal num = BigDecimal.valueOf(fissionCount / firstLevelCount);
                     BigDecimal rounded = num.setScale(2, RoundingMode.HALF_UP);
                     item.setScore(rounded.doubleValue());
                 }
@@ -337,8 +252,11 @@ public class ContentPlatformDatastatJob {
         }
         Long now = System.currentTimeMillis();
         // 公众号自动回复数据统计
-        String sql = String.format("SELECT channel_shortname, first_uv, dt " +
-                "FROM loghubods.out_channel_mid_first_total WHERE tag = '投放渠道内去重' and type = '服务号代运营' and dt=%s;", dt);
+        String sql = String.format("SELECT  first_level.channel_shortname, 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 " +
+                "WHERE   first_level.dt = %s and first_level.type = '服务号代运营' and first_level.tag = '投放渠道内去重' ;", dt);
         List<Record> dataList = OdpsUtil.getOdpsData(sql);
         // 所有公众号
         List<ContentPlatformAccount> accountList = getAllAccount();
@@ -347,31 +265,18 @@ public class ContentPlatformDatastatJob {
         List<ContentPlatformGzhAccount> gzhAccountList = getAllGzhAccount();
         Map<Long, List<ContentPlatformGzhAccount>> gzhAccountMap = gzhAccountList.stream()
                 .collect(Collectors.groupingBy(ContentPlatformGzhAccount::getCreateAccountId));
-        List<Long> accountIds = gzhAccountList.stream().map(ContentPlatformGzhAccount::getId).collect(Collectors.toList());
         List<String> accountExternalIds = gzhAccountList.stream().map(ContentPlatformGzhAccount::getExternalId).collect(Collectors.toList());
         String dateStr = dt.substring(0, 4) + "-" + dt.substring(4, 6) + "-" + dt.substring(6, 8);
         List<WxAccountDatastatVO> wxAccountDatastatVOList = aigcApiService.getWxAccountDatastat(dateStr, accountExternalIds);
         Map<String, WxAccountDatastatVO> wxAccountDatastatMap = wxAccountDatastatVOList.stream()
                 .collect(Collectors.toMap(WxAccountDatastatVO::getAccountId, wxAccountDatastatVO -> wxAccountDatastatVO));
-        List<ContentPlatformGzhPlan> gzhPlanList = planService.getGzhPlanListByCooperateAccountIds(accountIds,
-                ContentPlatformGzhPlanTypeEnum.FWH_PUSH.getVal());
-        List<Long> planIds = gzhPlanList.stream().map(ContentPlatformGzhPlan::getId).collect(Collectors.toList());
-        Map<Long, List<Long>> gzhPlanMap = gzhPlanList.stream()
-                .collect(Collectors.groupingBy(ContentPlatformGzhPlan::getAccountId,
-                        Collectors.mapping(ContentPlatformGzhPlan::getId, Collectors.toList())));
-        List<ContentPlatformGzhPlanVideo> gzhPlanVideoList = planService.getGzhPlanVideoList(planIds);
-        Map<Long, List<ContentPlatformGzhPlanVideo>> gzhPlanVideoMap = gzhPlanVideoList.stream()
-                .collect(Collectors.groupingBy(ContentPlatformGzhPlanVideo::getPlanId));
-        List<Long> videoIds = gzhPlanVideoList.stream().map(ContentPlatformGzhPlanVideo::getVideoId).collect(Collectors.toList());
-        List<ContentPlatformVideoAgg> contentPlatformVideoList = planService.getVideoContentAggListByVideoIds(videoIds);
-        Map<Long, ContentPlatformVideoAgg> videoMap = contentPlatformVideoList.stream()
-                .collect(Collectors.toMap(ContentPlatformVideoAgg::getVideoId, video -> video, (a, b) -> a));
         if (CollectionUtils.isNotEmpty(dataList)) {
             List<ContentPlatformFwhDataStatTotal> saveList = new ArrayList<>();
             for (Record record : dataList) {
                 ContentPlatformFwhDataStatTotal item = new ContentPlatformFwhDataStatTotal();
                 String channel = record.getString(0);
                 Integer firstLevelCount = Integer.valueOf((String) record.get(1));
+                Integer fissionCount = parseInteger(record.get(2));
                 item.setDateStr(dt);
                 item.setChannel(channel);
                 item.setFirstLevelCount(firstLevelCount);
@@ -381,33 +286,16 @@ public class ContentPlatformDatastatJob {
                 }
                 List<ContentPlatformGzhAccount> gzhAccounts = gzhAccountMap.get(account.getId());
                 int fansIncreaseCount = 0;
-                Double score = 0.0;
-                int size = 0;
                 for (ContentPlatformGzhAccount gzhAccount : gzhAccounts) {
                     WxAccountDatastatVO wxAccountDatastatVO = wxAccountDatastatMap.get(gzhAccount.getExternalId());
                     if (Objects.nonNull(wxAccountDatastatVO)) {
                         fansIncreaseCount += wxAccountDatastatVO.getFansIncreaseCount();
                     }
-                    List<Long> planIdList = gzhPlanMap.get(gzhAccount.getId());
-                    if (CollectionUtils.isEmpty(planIdList)) {
-                        continue;
-                    }
-                    for (Long planId : planIdList) {
-                        List<ContentPlatformGzhPlanVideo> videoList = gzhPlanVideoMap.get(planId);
-                        if (CollectionUtils.isNotEmpty(videoList)) {
-                            List<Long> itemVideoIds = videoList.stream().map(ContentPlatformGzhPlanVideo::getVideoId).collect(Collectors.toList());
-                            for (Long videoId : itemVideoIds) {
-                                if (Objects.nonNull(videoMap.get(videoId))) {
-                                    score += videoMap.get(videoId).getScore();
-                                }
-                            }
-                            size += videoList.size();
-                        }
-                    }
                 }
                 item.setFansIncreaseCount(fansIncreaseCount);
-                if (size > 0) {
-                    BigDecimal num = BigDecimal.valueOf(score / size);
+
+                if (Objects.nonNull(fissionCount) && fissionCount > 0 && firstLevelCount > 0) {
+                    BigDecimal num = BigDecimal.valueOf(fissionCount / firstLevelCount);
                     BigDecimal rounded = num.setScale(2, RoundingMode.HALF_UP);
                     item.setScore(rounded.doubleValue());
                 }
@@ -558,14 +446,18 @@ public class ContentPlatformDatastatJob {
         }
         dataStatMapperExt.deleteQwDatastatTotal(dt);
         Map<String, ContentPlatformQwDataStatTotal> saveMap = new HashMap<>();
-        String outSql = String.format("SELECT channel_shortname, first_uv, dt " +
-                "FROM loghubods.out_channel_mid_first_total WHERE tag = '投放渠道内去重' and type = '企微外部' and dt=%s;", dt);
+        String outSql = String.format("SELECT first_level.channel_shortname, 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 " +
+                "WHERE   first_level.dt = %s and first_level.type = '企微外部' and first_level.tag = '投放渠道内去重' ;", dt);
         List<Record> outDataList = OdpsUtil.getOdpsData(outSql);
         Long now = System.currentTimeMillis();
         if (CollectionUtils.isNotEmpty(outDataList)) {
             for (Record record : outDataList) {
                 String channel = (String) record.get(0);
                 int firstLevelCount = Integer.parseInt((String) record.get(1));
+                Integer fissionCount = parseInteger(record.get(2));
                 if (firstLevelCount == 0) {
                     continue;
                 }
@@ -575,6 +467,12 @@ public class ContentPlatformDatastatJob {
                 if (item.getFirstLevelCount() == null) {
                     item.setFirstLevelCount(0);
                 }
+
+                if (Objects.nonNull(fissionCount) && fissionCount > 0 && firstLevelCount > 0) {
+                    BigDecimal num = BigDecimal.valueOf(fissionCount / firstLevelCount);
+                    BigDecimal rounded = num.setScale(2, RoundingMode.HALF_UP);
+                    item.setScore(rounded.doubleValue());
+                }
                 item.setFirstLevelCount(item.getFirstLevelCount() + firstLevelCount);
                 item.setCreateTimestamp(now);
                 saveMap.put(channel, item);
@@ -671,8 +569,11 @@ public class ContentPlatformDatastatJob {
             dt = param;
         }
         List<ContentPlatformQwDataStatSubChannel> saveList = new ArrayList<>();
-        String outSql = String.format("SELECT channel, subchannel, first_uv " +
-                "FROM loghubods.qw_out_channel_mid_first_total WHERE dt=%s;", dt);
+        String outSql = 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 " +
+                "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()
@@ -680,20 +581,6 @@ public class ContentPlatformDatastatJob {
         List<ContentPlatformQwPlan> qwPlanList = getSubChannelQwPlanList();
         Map<Long, List<ContentPlatformQwPlan>> qwPlanMap = qwPlanList.stream().collect(
                 Collectors.groupingBy(ContentPlatformQwPlan::getCreateAccountId));
-        List<Long> qwPlanIds = qwPlanList.stream().map(ContentPlatformQwPlan::getId).collect(Collectors.toList());
-        List<ContentPlatformQwPlanVideo> qwPlanVideoList = new ArrayList<>();
-        if (CollectionUtils.isNotEmpty(qwPlanIds)) {
-            qwPlanVideoList = getSubChannelQwPlanVideoList(qwPlanIds);
-        }
-        Map<Long, List<ContentPlatformQwPlanVideo>> qwPlanVideoMap = qwPlanVideoList.stream()
-               .collect(Collectors.groupingBy(ContentPlatformQwPlanVideo::getPlanId));
-        List<Long> videoIdList = qwPlanVideoList.stream().map(ContentPlatformQwPlanVideo::getVideoId).collect(Collectors.toList());
-        List<ContentPlatformVideo> videoList = new ArrayList<>();
-        if (CollectionUtils.isNotEmpty(videoIdList)) {
-            videoList = planService.getVideoContentListByVideoIds(videoIdList);
-        }
-        Map<Long, Double> videoScoreMap = videoList.stream()
-                .collect(Collectors.toMap(ContentPlatformVideo::getVideoId, ContentPlatformVideo::getScore, (a, b) -> a));
         Long now = System.currentTimeMillis();
         if (CollectionUtils.isNotEmpty(outDataList)) {
             List<Record> noSubChannelRecordList = new ArrayList<>();
@@ -701,6 +588,7 @@ public class ContentPlatformDatastatJob {
                 String channel = (String) record.get(0);
                 String subChannel = (String) record.get(1);
                 int firstLevelCount = Integer.parseInt((String) record.get(2));
+                Integer fissionCount = parseInteger(record.get(3));
                 if (firstLevelCount == 0) {
                     continue;
                 }
@@ -721,23 +609,9 @@ public class ContentPlatformDatastatJob {
                 if (item.getFirstLevelCount() == null) {
                     item.setFirstLevelCount(0);
                 }
-                Double score = 0.0;
-                int size = 0;
-                for (ContentPlatformQwPlan qwPlan : qwPlans) {
-                    List<ContentPlatformQwPlanVideo> planVideoList = qwPlanVideoMap.get(qwPlan.getId());
-                    if (CollectionUtils.isEmpty(planVideoList)) {
-                        continue;
-                    }
-                    List<Long> videoIds = planVideoList.stream().map(ContentPlatformQwPlanVideo::getVideoId).collect(Collectors.toList());
-                    size += videoIds.size();
-                    for (Long videoId : videoIds) {
-                        if (Objects.nonNull(videoScoreMap.get(videoId))) {
-                            score += videoScoreMap.get(videoId);
-                        }
-                    }
-                }
-                if (size > 0) {
-                    BigDecimal num = BigDecimal.valueOf(score / size);
+
+                if (Objects.nonNull(fissionCount) && fissionCount > 0 && firstLevelCount > 0) {
+                    BigDecimal num = BigDecimal.valueOf(fissionCount / firstLevelCount);
                     BigDecimal rounded = num.setScale(2, RoundingMode.HALF_UP);
                     item.setScore(rounded.doubleValue());
                 }
@@ -776,11 +650,13 @@ public class ContentPlatformDatastatJob {
         example.createCriteria().andSubChannelIsNotNull();
         return qwPlanMapper.selectByExample(example);
     }
-
-    private List<ContentPlatformQwPlanVideo> getSubChannelQwPlanVideoList(List<Long> qwPlanIds) {
-        ContentPlatformQwPlanVideoExample example = new ContentPlatformQwPlanVideoExample();
-        example.createCriteria().andPlanIdIn(qwPlanIds);
-        return qwPlanVideoMapper.selectByExample(example);
+    
+    private Integer parseInteger(Object value) {
+        try {
+            return Integer.parseInt((String) value);
+        } catch (NumberFormatException e) {
+            return null;
+        }
     }
 
 }

+ 2 - 2
api-module/src/main/java/com/tzld/piaoquan/api/model/param/contentplatform/VideoContentListParam.java

@@ -14,8 +14,8 @@ public class VideoContentListParam extends PageParam {
     private String category;
 
     @ApiModelProperty(value = "排序 0-自动回复、1-服务号推送、2-企微-社群、3-企微-自动回复")
-    private Integer type;
+    private Integer type = 999;
 
     @ApiModelProperty(value = "排序 0-平台推荐 1-行业裂变率 2-本渠道裂变率")
-    private Integer sort;
+    private Integer sort = 0;
 }