Browse Source

新增数据项

wangyunpeng 1 tháng trước cách đây
mục cha
commit
146f7ee854

+ 49 - 6
api-module/src/main/java/com/tzld/piaoquan/api/job/ContentPlatformVideoJob.java

@@ -21,6 +21,8 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 import org.springframework.util.StringUtils;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -196,7 +198,7 @@ public class ContentPlatformVideoJob {
         if (StringUtils.hasText(param)) {
             aggDt = param;
         }
-        List<String> dtList = DateUtil.getBeforeDays(aggDt, null, 7);
+        List<String> dtList = DateUtil.getBeforeDays(aggDt, aggDt, 6);
         // 轮询查询大数据获取最近14天视频
         for (String dt : dtList) {
             long videoGroupScoreCount = getVideoGroupScoreCount(dt);
@@ -212,8 +214,8 @@ public class ContentPlatformVideoJob {
                 List<ContentPlatformVideoDataStat> saveList = new ArrayList<>();
                 for (Record record : dataList) {
                     ContentPlatformVideoDataStat item = new ContentPlatformVideoDataStat();
-                    String type =(String) record.get(0);
-                    String channel =(String) record.get(1);
+                    String type = (String) record.get(0);
+                    String channel = (String) record.get(1);
                     Long videoId = Long.parseLong((String) record.get(2));
                     Long firstLevel = Long.parseLong((String) record.get(3));
                     Long fission0 = Long.parseLong((String) record.get(4));
@@ -251,14 +253,55 @@ public class ContentPlatformVideoJob {
 
     private List<ContentPlatformVideoDataStatAgg> buildVideoDataStatAggList(String aggDt, List<String> dtList) {
         Long now = System.currentTimeMillis();
+        List<ContentPlatformVideoDataStat> dataStatList = getVideoDatastatList(dtList);
+        Map<Long, Map<String, Map<String, List<ContentPlatformVideoDataStat>>>> videoIdMap = dataStatList.stream()
+                .filter(o -> {
+                    if ("sum".equals(o.getChannel())) {
+                        return o.getFirstLevel() > 300;
+                    } else {
+                        return o.getFirstLevel() > 100;
+                    }
+                })
+                .collect(Collectors.groupingBy(ContentPlatformVideoDataStat::getVideoId,
+                        Collectors.groupingBy(ContentPlatformVideoDataStat::getType,
+                                Collectors.groupingBy(ContentPlatformVideoDataStat::getChannel))));
         List<ContentPlatformVideoDataStatAgg> result = new ArrayList<>();
-        for (ContentPlatformVideoDataStatAgg item : result) {
-            item.setDt(aggDt);
-            item.setCreateTimestamp(now);
+        for (Map.Entry<Long, Map<String, Map<String, List<ContentPlatformVideoDataStat>>>> entry : videoIdMap.entrySet()) {
+            Long videoId = entry.getKey();
+            Map<String, Map<String, List<ContentPlatformVideoDataStat>>> typeMap = entry.getValue();
+            for (Map.Entry<String, Map<String, List<ContentPlatformVideoDataStat>>> typeEntry : typeMap.entrySet()) {
+                String type = typeEntry.getKey();
+                Map<String, List<ContentPlatformVideoDataStat>> channelMap = typeEntry.getValue();
+                for (Map.Entry<String, List<ContentPlatformVideoDataStat>> channelEntry : channelMap.entrySet()) {
+                    String channel = channelEntry.getKey();
+                    List<ContentPlatformVideoDataStat> statList = channelEntry.getValue();
+                    Long sumFirstLevel = statList.stream().map(ContentPlatformVideoDataStat::getFirstLevel).reduce(0L, Long::sum);
+                    Long sumFission0 = statList.stream().map(ContentPlatformVideoDataStat::getFission0).reduce(0L, Long::sum);
+                    ContentPlatformVideoDataStatAgg item = new ContentPlatformVideoDataStatAgg();
+                    item.setDt(aggDt);
+                    item.setVideoId(videoId);
+                    item.setType(type);
+                    item.setChannel(channel);
+                    item.setFirstLevel(sumFirstLevel);
+                    item.setFission0(sumFission0);
+                    if (sumFirstLevel > 0) {
+                        BigDecimal fissionRate = new BigDecimal(sumFission0).divide(new BigDecimal(sumFirstLevel), 4, RoundingMode.HALF_UP);
+                        item.setFissionRate(fissionRate.doubleValue());
+                    }
+                    item.setCreateTimestamp(now);
+                    result.add(item);
+                }
+            }
         }
         return result;
     }
 
+    private List<ContentPlatformVideoDataStat> getVideoDatastatList(List<String> dtList) {
+        ContentPlatformVideoDataStatExample example = new ContentPlatformVideoDataStatExample();
+        example.createCriteria().andDtIn(dtList);
+        return videoDataStatMapper.selectByExample(example);
+    }
+
 }
 
 

+ 6 - 12
api-module/src/main/java/com/tzld/piaoquan/api/service/contentplatform/impl/ContentPlatformPlanServiceImpl.java

@@ -469,7 +469,7 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
         String type = getVideoContentListType(param.getType());
         String channel = getVideoContentListChannel(param.getSort(), user.getChannel());
         List<ContentPlatformVideo> videoList = planMapperExt.getVideoList(param, dt, datastatDt, type, channel, videoMinScore, offset, param.getPageSize(), sort);
-        List<VideoContentItemVO> list = buildVideoContentItemVOList(videoList, type, user.getChannel(), datastatDt);
+        List<VideoContentItemVO> list = buildVideoContentItemVOList(videoList, type, channel, user.getChannel(), datastatDt);
         result.setObjs(list);
         return result;
     }
@@ -510,7 +510,7 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
     }
 
     private List<VideoContentItemVO> buildVideoContentItemVOList(List<ContentPlatformVideo> videoList,
-                                                                 String type, String channel, String datastatDt) {
+                                                                 String type, String channel, String userChannel, String datastatDt) {
         if (CollectionUtils.isEmpty(videoList)) {
             return null;
         }
@@ -524,10 +524,10 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
             Set<Long> ids = new HashSet<>(partition);
             coverMap.putAll(messageAttachmentService.getVideoDetail(ids));
         }
-        List<ContentPlatformVideoDataStatAgg> typeVideoDataStatAggList = getTypeVideoDataStatAggList(datastatDt, type, videoIds);
+        List<ContentPlatformVideoDataStatAgg> typeVideoDataStatAggList = getTypeChannelVideoDataStatAggList(datastatDt, type, channel, videoIds);
         Map<Long, Double> typeVideoScoreMap = typeVideoDataStatAggList.stream().collect(Collectors.toMap(
                 ContentPlatformVideoDataStatAgg::getVideoId, ContentPlatformVideoDataStatAgg::getFissionRate));
-        List<ContentPlatformVideoDataStatAgg> channelVideoDataStatAggList = getChannelVideoDataStatAggList(datastatDt, channel, videoIds);
+        List<ContentPlatformVideoDataStatAgg> channelVideoDataStatAggList = getTypeChannelVideoDataStatAggList(datastatDt, type, userChannel, videoIds);
         Map<Long, Double> channelVideoScoreMap = channelVideoDataStatAggList.stream().collect(Collectors.toMap(
                 ContentPlatformVideoDataStatAgg::getVideoId, ContentPlatformVideoDataStatAgg::getFissionRate));
         List<VideoContentItemVO> result = new ArrayList<>();
@@ -550,15 +550,9 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
         return result;
     }
 
-    private List<ContentPlatformVideoDataStatAgg> getChannelVideoDataStatAggList(String datastatDt, String channel, List<Long> videoIds) {
+    private List<ContentPlatformVideoDataStatAgg> getTypeChannelVideoDataStatAggList(String datastatDt, String type, String channel, List<Long> videoIds) {
         ContentPlatformVideoDataStatAggExample example = new ContentPlatformVideoDataStatAggExample();
-        example.createCriteria().andVideoIdIn(videoIds).andDtEqualTo(datastatDt).andChannelEqualTo(channel);
-        return videoDataStatAggMapper.selectByExample(example);
-    }
-
-    private List<ContentPlatformVideoDataStatAgg> getTypeVideoDataStatAggList(String datastatDt, String type, List<Long> videoIds) {
-        ContentPlatformVideoDataStatAggExample example = new ContentPlatformVideoDataStatAggExample();
-        example.createCriteria().andVideoIdIn(videoIds).andDtEqualTo(datastatDt).andTypeEqualTo(type);
+        example.createCriteria().andVideoIdIn(videoIds).andDtEqualTo(datastatDt).andTypeEqualTo(type).andChannelEqualTo(channel);
         return videoDataStatAggMapper.selectByExample(example);
     }