|
@@ -45,6 +45,9 @@ public class ContentPlatformDatastatJob {
|
|
|
@Autowired
|
|
|
private ContentPlatformQwPlanMapper qwPlanMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ContentPlatformQwPlanVideoMapper qwPlanVideoMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ContentPlatformDataStatMapperExt dataStatMapperExt;
|
|
|
|
|
@@ -85,15 +88,15 @@ public class ContentPlatformDatastatJob {
|
|
|
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())));
|
|
|
+ .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));
|
|
|
+ .collect(Collectors.groupingBy(ContentPlatformGzhPlanVideo::getPlanId));
|
|
|
List<Long> videoIds = gzhPlanVideoList.stream().map(ContentPlatformGzhPlanVideo::getVideoId).collect(Collectors.toList());
|
|
|
List<ContentPlatformVideo> contentPlatformVideoList = planService.getVideoContentListByVideoIds(videoIds);
|
|
|
Map<Long, ContentPlatformVideo> videoMap = contentPlatformVideoList.stream()
|
|
|
- .collect(Collectors.toMap(ContentPlatformVideo::getVideoId, video -> video, (a, b) -> a));
|
|
|
+ .collect(Collectors.toMap(ContentPlatformVideo::getVideoId, video -> video, (a, b) -> a));
|
|
|
if (CollectionUtils.isNotEmpty(dataList)) {
|
|
|
List<ContentPlatformGzhDataStat> saveList = new ArrayList<>();
|
|
|
for (Record record : dataList) {
|
|
@@ -158,7 +161,7 @@ public class ContentPlatformDatastatJob {
|
|
|
// 所有公众号
|
|
|
List<ContentPlatformAccount> accountList = getAllAccount();
|
|
|
Map<String, ContentPlatformAccount> accountMap = accountList.stream()
|
|
|
- .collect(Collectors.toMap(ContentPlatformAccount::getChannel, account -> account));
|
|
|
+ .collect(Collectors.toMap(ContentPlatformAccount::getChannel, account -> account));
|
|
|
List<ContentPlatformGzhAccount> gzhAccountList = getAllGzhAccount();
|
|
|
Map<Long, List<ContentPlatformGzhAccount>> gzhAccountMap = gzhAccountList.stream()
|
|
|
.collect(Collectors.groupingBy(ContentPlatformGzhAccount::getCreateAccountId));
|
|
@@ -172,15 +175,15 @@ public class ContentPlatformDatastatJob {
|
|
|
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())));
|
|
|
+ .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));
|
|
|
+ .collect(Collectors.groupingBy(ContentPlatformGzhPlanVideo::getPlanId));
|
|
|
List<Long> videoIds = gzhPlanVideoList.stream().map(ContentPlatformGzhPlanVideo::getVideoId).collect(Collectors.toList());
|
|
|
List<ContentPlatformVideo> contentPlatformVideoList = planService.getVideoContentListByVideoIds(videoIds);
|
|
|
Map<Long, ContentPlatformVideo> videoMap = contentPlatformVideoList.stream()
|
|
|
- .collect(Collectors.toMap(ContentPlatformVideo::getVideoId, video -> video, (a, b) -> a));
|
|
|
+ .collect(Collectors.toMap(ContentPlatformVideo::getVideoId, video -> video, (a, b) -> a));
|
|
|
if (CollectionUtils.isNotEmpty(dataList)) {
|
|
|
List<ContentPlatformGzhDataStatTotal> saveList = new ArrayList<>();
|
|
|
for (Record record : dataList) {
|
|
@@ -267,15 +270,15 @@ public class ContentPlatformDatastatJob {
|
|
|
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())));
|
|
|
+ .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));
|
|
|
+ .collect(Collectors.groupingBy(ContentPlatformGzhPlanVideo::getPlanId));
|
|
|
List<Long> videoIds = gzhPlanVideoList.stream().map(ContentPlatformGzhPlanVideo::getVideoId).collect(Collectors.toList());
|
|
|
List<ContentPlatformVideo> contentPlatformVideoList = planService.getVideoContentListByVideoIds(videoIds);
|
|
|
Map<Long, ContentPlatformVideo> videoMap = contentPlatformVideoList.stream()
|
|
|
- .collect(Collectors.toMap(ContentPlatformVideo::getVideoId, video -> video, (a, b) -> a));
|
|
|
+ .collect(Collectors.toMap(ContentPlatformVideo::getVideoId, video -> video, (a, b) -> a));
|
|
|
if (CollectionUtils.isNotEmpty(dataList)) {
|
|
|
List<ContentPlatformFwhDataStat> saveList = new ArrayList<>();
|
|
|
for (Record record : dataList) {
|
|
@@ -462,15 +465,15 @@ public class ContentPlatformDatastatJob {
|
|
|
List<ContentPlatformQwDataStat> existList = getQwDatastatCount(dt);
|
|
|
List<String> existRootSourceIds = existList.stream().map(ContentPlatformQwDataStat::getRootSourceId).collect(Collectors.toList());
|
|
|
Map<String, Long> rootSourceIdMap = qwPlanList.stream()
|
|
|
- .collect(Collectors.toMap(ContentPlatformQwPlan::getRootSourceId, ContentPlatformQwPlan::getId));
|
|
|
+ .collect(Collectors.toMap(ContentPlatformQwPlan::getRootSourceId, ContentPlatformQwPlan::getId));
|
|
|
List<Long> planIds = qwPlanList.stream().map(ContentPlatformQwPlan::getId).collect(Collectors.toList());
|
|
|
List<ContentPlatformQwPlanVideo> planVideoList = planService.getQwPlanVideoList(planIds);
|
|
|
Map<Long, Long> planVideoMap = planVideoList.stream()
|
|
|
- .collect(Collectors.toMap(ContentPlatformQwPlanVideo::getPlanId, ContentPlatformQwPlanVideo::getVideoId));
|
|
|
+ .collect(Collectors.toMap(ContentPlatformQwPlanVideo::getPlanId, ContentPlatformQwPlanVideo::getVideoId));
|
|
|
List<Long> videoIds = planVideoList.stream().map(ContentPlatformQwPlanVideo::getVideoId).collect(Collectors.toList());
|
|
|
List<ContentPlatformVideo> videoList = planService.getVideoContentListByVideoIds(videoIds);
|
|
|
Map<Long, Double> videoScoreMap = videoList.stream()
|
|
|
- .collect(Collectors.toMap(ContentPlatformVideo::getVideoId, ContentPlatformVideo::getScore, (a, b) -> a));
|
|
|
+ .collect(Collectors.toMap(ContentPlatformVideo::getVideoId, ContentPlatformVideo::getScore, (a, b) -> a));
|
|
|
List<ContentPlatformQwDataStat> saveList = new ArrayList<>();
|
|
|
List<String> rootSourceIds = qwPlanList.stream().map(ContentPlatformQwPlan::getRootSourceId).collect(Collectors.toList());
|
|
|
String outSql = String.format("SELECT * FROM loghubods.qw_out_touliu_behavior_detail WHERE dt=%s;", dt);
|
|
@@ -700,15 +703,26 @@ public class ContentPlatformDatastatJob {
|
|
|
if (StringUtils.hasText(param)) {
|
|
|
dt = param;
|
|
|
}
|
|
|
- dataStatMapperExt.deleteQwDatastatReplyTotal(dt);
|
|
|
- Map<String, ContentPlatformQwDataStatSubChannel> saveMap = new HashMap<>();
|
|
|
+ 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);
|
|
|
List<Record> outDataList = OdpsUtil.getOdpsData(outSql);
|
|
|
List<ContentPlatformAccount> accountList = getAllAccount();
|
|
|
Map<String, ContentPlatformAccount> accountMap = accountList.stream()
|
|
|
.collect(Collectors.toMap(ContentPlatformAccount::getChannel, account -> account));
|
|
|
+ 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 = 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 = 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<>();
|
|
|
for (Record record : outDataList) {
|
|
|
String channel = (String) record.get(0);
|
|
|
String subChannel = (String) record.get(1);
|
|
@@ -716,27 +730,83 @@ public class ContentPlatformDatastatJob {
|
|
|
if (firstLevelCount == 0) {
|
|
|
continue;
|
|
|
}
|
|
|
- ContentPlatformQwDataStatSubChannel item = saveMap.getOrDefault(channel, new ContentPlatformQwDataStatSubChannel());
|
|
|
+ ContentPlatformQwDataStatSubChannel item = new ContentPlatformQwDataStatSubChannel();
|
|
|
item.setDateStr(dt);
|
|
|
ContentPlatformAccount account = accountMap.get(channel);
|
|
|
if (Objects.isNull(account)) {
|
|
|
continue;
|
|
|
}
|
|
|
+ List<ContentPlatformQwPlan> qwPlans = qwPlanMap.getOrDefault(account.getId(), new ArrayList<>());
|
|
|
+ List<String> subChannelList = qwPlans.stream().map(ContentPlatformQwPlan::getSubChannel).distinct().collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(qwPlans) || !subChannelList.contains(subChannel)) {
|
|
|
+ noSubChannelRecordList.add(record);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
item.setCreateAccountId(account.getId());
|
|
|
item.setSubChannel(subChannel);
|
|
|
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);
|
|
|
+ BigDecimal rounded = num.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ item.setScore(rounded.doubleValue());
|
|
|
+ }
|
|
|
+ item.setFirstLevelCount(item.getFirstLevelCount() + firstLevelCount);
|
|
|
+ item.setCreateTimestamp(now);
|
|
|
+ saveList.add(item);
|
|
|
+ }
|
|
|
+ for (Record record : noSubChannelRecordList) {
|
|
|
+ String channel = (String) record.get(0);
|
|
|
+ int firstLevelCount = Integer.parseInt((String) record.get(2));
|
|
|
+ ContentPlatformQwDataStatSubChannel item = new ContentPlatformQwDataStatSubChannel();
|
|
|
+ item.setDateStr(dt);
|
|
|
+ ContentPlatformAccount account = accountMap.get(channel);
|
|
|
+ if (Objects.isNull(account)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ item.setCreateAccountId(account.getId());
|
|
|
+ item.setSubChannel("未知");
|
|
|
+ if (item.getFirstLevelCount() == null) {
|
|
|
+ item.setFirstLevelCount(0);
|
|
|
+ }
|
|
|
item.setFirstLevelCount(item.getFirstLevelCount() + firstLevelCount);
|
|
|
item.setCreateTimestamp(now);
|
|
|
- saveMap.put(channel, item);
|
|
|
+ saveList.add(item);
|
|
|
}
|
|
|
}
|
|
|
- List<ContentPlatformQwDataStatSubChannel> saveList = new ArrayList<>(saveMap.values());
|
|
|
if (CollectionUtils.isNotEmpty(saveList)) {
|
|
|
+ dataStatMapperExt.deleteQwDatastatReplyTotal(dt);
|
|
|
dataStatMapperExt.batchInsertQwDatastatSubChannel(saveList);
|
|
|
}
|
|
|
return ReturnT.SUCCESS;
|
|
|
}
|
|
|
|
|
|
+ private List<ContentPlatformQwPlan> getSubChannelQwPlanList() {
|
|
|
+ ContentPlatformQwPlanExample example = new ContentPlatformQwPlanExample();
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
}
|