Procházet zdrojové kódy

头条视频素材报表编写

hcst_sunzhen před 5 roky
rodič
revize
2beb4be145

+ 76 - 20
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceReportController.java

@@ -281,15 +281,14 @@ public class BytedanceReportController {
 
 
     /**
-     * 头条视频素材报表--此接口仅有视频素材
+     * 头条视频素材报表--此接口仅有视频素材,异步拉取数据
      * @param startDate
      * @param endDate
      * @return
      */
     @GetMapping("/bytedance/bytedanceVideoMaterialReport")
     public Result bytedanceVideoMaterialReport(@RequestParam(name = "startDate") String startDate,
-                                                @RequestParam(name = "endDate") String endDate,
-                                               @RequestParam(name = "accountId") Long accountId) {
+                                                @RequestParam(name = "endDate") String endDate) {
         Result result = new Result<>();
         if (StringUtils.isBlank(startDate) || StringUtils.isBlank(endDate)){
             result.error500("开始时间和结束时间不能为空");
@@ -298,24 +297,36 @@ public class BytedanceReportController {
         try {
             log.info("头条获取视频素材报表数据任务执行开始");
             Long starttime = System.currentTimeMillis();
-            CtopOauthToken token = tokenService.getAccessTokenByAccountIdAndMediaId(1,93238965516L);
-
-
-                                try {
-                                    ////间隔天数
-                                    //Long days = DateUtils.getDiscrepantDays(startDate, endDate);
-                                    //String start = null;
-                                    //String end = null;
-                                    //for (int i = 0; i <= days; i++) {
-                                    //    start = DateUtils.addDay(startDate, i);
-                                    //    end = start;
-                                        //获取头条素材报表数据
-                                        bytedanceReportService.bytedanceVideoMaterialReport(token, startDate, endDate);
-                                //    }
-                                } catch (Exception e) {
-                                    e.printStackTrace();
-                                }
+            List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
+            if (null == tokens || tokens.size() <= 0) {
+                log.info("头条获取素材报表数据任务执行失败:未获取到可用的token");
+                return result;
+            }
 
+            final ExecutorService executorService = Executors.newFixedThreadPool(8);
+            tokens.forEach(token -> {
+                executorService.submit(new Runnable() {
+                           @Override
+                           public void run() {
+
+                               try {
+                                   //间隔天数
+                                   Long days = DateUtils.getDiscrepantDays(startDate, endDate);
+                                   String start = null;
+                                   String end = null;
+                                   for (int i = 0; i <= days; i++) {
+                                       start = DateUtils.addDay(startDate, i);
+                                       end = start;
+                                       //获取头条素材报表数据
+                                       bytedanceReportService.bytedanceVideoMaterialReport(token, start, end);
+                                   }
+                               } catch (Exception e) {
+                                   e.printStackTrace();
+                               }
+
+                           }
+                       });
+                    });
             ////
             Long endtime = System.currentTimeMillis();
             log.info("头条获取视频素材报表数据任务执行结束,执行耗时:{}秒", (endtime - starttime) / 1000);
@@ -327,4 +338,49 @@ public class BytedanceReportController {
         return result;
     }
 
+    /**
+     * 头条视频素材报表--此接口仅有视频素材,单个accountId拉取数据
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    @GetMapping("/bytedance/bytedanceVideoMaterialReportByAccountId")
+    public Result bytedanceVideoMaterialReportByAccountId(@RequestParam(name = "startDate") String startDate,
+                                               @RequestParam(name = "endDate") String endDate,
+                                               @RequestParam(name = "accountId") Long accountId) {
+        Result result = new Result<>();
+        if (StringUtils.isBlank(startDate) || StringUtils.isBlank(endDate)||accountId==null){
+            result.error500("开始时间,结束时间和账户id不能为空");
+            return result;
+        }
+        try {
+            log.info("头条获取单个账户视频素材报表数据任务执行开始");
+            Long starttime = System.currentTimeMillis();
+            CtopOauthToken token = tokenService.getOauthTokenByAccountId(String.valueOf(accountId));
+            if (null == token ) {
+                log.info("头条获取单个账户视频素材报表数据任务执行失败:未获取到可用的token");
+                return result;
+            }
+
+            //间隔天数
+            Long days = DateUtils.getDiscrepantDays(startDate, endDate);
+            String start = null;
+            String end = null;
+            for (int i = 0; i <= days; i++) {
+                start = DateUtils.addDay(startDate, i);
+                end = start;
+                //获取头条素材报表数据
+                bytedanceReportService.bytedanceVideoMaterialReport(token, start, end);
+            }
+
+            Long endtime = System.currentTimeMillis();
+            log.info("头条获取视频素材报表数据任务执行结束,执行耗时:{}秒", (endtime - starttime) / 1000);
+        } catch (Exception e) {
+            log.error("头条获取视频素材报表数据任务执行结失败");
+            e.printStackTrace();
+            result.setSuccess(false);
+        }
+        return result;
+    }
+
 }

+ 16 - 13
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/entity/BytedanceReportVideoMaterialDaily.java

@@ -155,31 +155,34 @@ public class BytedanceReportVideoMaterialDaily {
 		JSONObject metrics = detailJson.getJSONObject("metrics");
 		this.setValidPlayCost(metrics.getBigDecimal("valid_play_cost"));
 		this.setClick(metrics.getLong("click"));
+		this.setDislike(metrics.getLong("dislike"));
+		this.setReport(metrics.getLong("report"));
 		this.setCost(metrics.getBigDecimal("cost"));
 		this.setAvgClickCost(metrics.getBigDecimal("avg_click_cost"));
+		this.setDeepConvert(metrics.getLong("deep_convert"));
 		this.setDeepConvertCost(metrics.getBigDecimal("deep_convert_cost"));
 		this.setDeepConvertRate(metrics.getBigDecimal("deep_convert_rate"));
-		this.setPlayDuration2sRate(metrics.getBigDecimal("playDuration2sRate"));
-		this.setPlayDuration3sRate(metrics.getBigDecimal("playDuration3sRate"));
-		this.setPlayDuration5sRate(metrics.getBigDecimal("playDuration5sRate"));
-		this.setPlayDuration10sRate(metrics.getBigDecimal("playDuration10sRate"));
-		this.setPlay25FeedBreakRate(metrics.getBigDecimal("play25FeedBreakRate"));
-		this.setPlay50FeedBreakRate(metrics.getBigDecimal("play50FeedBreakRate"));
-		this.setPlay75FeedBreakRate(metrics.getBigDecimal("play75FeedBreakRate"));
-		this.setPlay100FeedBreakRate(metrics.getBigDecimal("play100FeedBreakRate"));
+		this.setPlayDuration2sRate(metrics.getBigDecimal("play_duration_2s_rate"));
+		this.setPlayDuration3sRate(metrics.getBigDecimal("play_duration_3s_rate"));
+		this.setPlayDuration5sRate(metrics.getBigDecimal("play_duration_5s_rate"));
+		this.setPlayDuration10sRate(metrics.getBigDecimal("play_duration_10s_rate"));
+		this.setPlay25FeedBreakRate(metrics.getBigDecimal("play_25_feed_break_rate"));
+		this.setPlay50FeedBreakRate(metrics.getBigDecimal("play_50_feed_break_rate"));
+		this.setPlay75FeedBreakRate(metrics.getBigDecimal("play_75_feed_break_rate"));
+		this.setPlay100FeedBreakRate(metrics.getBigDecimal("play_100_feed_break_rate"));
 		this.setPlayOverRate(metrics.getBigDecimal("play_over_rate"));
 		this.setAvgShowCost(metrics.getBigDecimal("avg_show_cost"));
 		this.setTotalPlay(metrics.getLong("total_play"));
 		this.setValidPlay(metrics.getLong("valid_play"));
-		this.setShareMaterial(metrics.getLong("share_material"));
-		this.setCommentMaterial(metrics.getLong("comment_material"));
+		this.setShareMaterial(metrics.getLong("share"));
+		this.setCommentMaterial(metrics.getLong("comment"));
 		this.setFollow(metrics.getLong("follow"));
 		this.setValidPlayCost(metrics.getBigDecimal("valid_play_cost"));
-		this.setConvertMaterial(metrics.getLong("convert_material"));
+		this.setConvertMaterial(metrics.getLong("convert"));
 		this.setPlayOverRate(metrics.getBigDecimal("play_over_rate"));
 		this.setCtr(metrics.getBigDecimal("ctr"));
-		this.setLikeMaterial(metrics.getLong("like_material"));
-		this.setShowMaterial(metrics.getLong("show_material"));
+		this.setLikeMaterial(metrics.getLong("like"));
+		this.setShowMaterial(metrics.getLong("show"));
 		this.setConvertRate(metrics.getBigDecimal("convert_rate"));
 		this.setPlayOver(metrics.getLong("play_over"));
 		this.setMessageAction(metrics.getLong("message_action"));

+ 2 - 2
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/xml/BytedanceReportMaterialDailyMapper.xml

@@ -250,7 +250,7 @@
     </update>
 
     <insert id="replaceIntoVideoMaterialBatch">
-        REPLACE INTO ctop_bytedance_report_material_daily
+        REPLACE INTO ctop_bytedance_report_video_material_daily
         (
         account_id,
         material_id,
@@ -263,7 +263,7 @@
         deep_convert_rate,
         dislike,
         report,
-        replay_duration_2s_rate,
+        play_duration_2s_rate,
         play_duration_3s_rate,
         play_duration_5s_rate,
         play_duration_10s_rate,

+ 3 - 3
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/BytedanceReportServiceImpl.java

@@ -955,9 +955,9 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
     @Override
     public int bytedanceVideoMaterialReport(CtopOauthToken token, String startDate, String endDate) {
         Long accountId = token.getAccountId();
-        log.info("头条素材报表当前accountId为:" + accountId);
+        log.info("头条素材报表当前accountId为:{}  {}~{},开始" , accountId, startDate,endDate);
         Integer page = 1;
-        Integer pageSize = 1000;
+        Integer pageSize = 100;
         int code = bytedanceVideoMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
         if (code != 200 && code != 1) {
             BytedanceReportMaterialRetry retry = new BytedanceReportMaterialRetry();
@@ -969,7 +969,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
             retry.setType(2);  //1素材报表重试,2视频素材报表重试
             bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
         }
-        log.info("头条素材报表当前accountId为:{}  {}~{}" , accountId, startDate,endDate);
+        log.info("头条素材报表当前accountId为:{}  {}~{},结束" , accountId, startDate,endDate);
         return code;
     }