ソースを参照

头条视频素材报表编写

hcst_sunzhen 5 年 前
コミット
963e14ef7a

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

@@ -289,40 +289,38 @@ public class BytedanceReportController {
     @GetMapping("/bytedance/bytedanceVideoMaterialReport")
     public Result bytedanceVideoMaterialReport(@RequestParam(name = "startDate") String startDate,
                                                 @RequestParam(name = "endDate") String endDate,
-                                               @RequestParam(name = "endDate") Long accountId) {
+                                               @RequestParam(name = "accountId") Long accountId) {
         Result result = new Result<>();
         if (StringUtils.isBlank(startDate) || StringUtils.isBlank(endDate)){
             result.error500("开始时间和结束时间不能为空");
             return result;
         }
         try {
-            log.info("头条获取素材报表数据任务执行开始");
+            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;
+                                    ////间隔天数
+                                    //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.bytedanceMaterialReport(token, start, end);
-                                    }
+                                        bytedanceReportService.bytedanceVideoMaterialReport(token, startDate, endDate);
+                                //    }
                                 } catch (Exception e) {
                                     e.printStackTrace();
-                                } finally {
                                 }
 
-
             ////
             Long endtime = System.currentTimeMillis();
-            log.info("头条获取素材报表数据任务执行结束,执行耗时:{}秒", (endtime - starttime) / 1000);
+            log.info("头条获取视频素材报表数据任务执行结束,执行耗时:{}秒", (endtime - starttime) / 1000);
         } catch (Exception e) {
-            log.error("头条获取素材报表数据任务执行结失败");
+            log.error("头条获取视频素材报表数据任务执行结失败");
             e.printStackTrace();
             result.setSuccess(false);
         }

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

@@ -2,6 +2,7 @@ package cn.com.ctop.toutiao.modules.report.mapper;
 
 import cn.com.ctop.toutiao.modules.report.entity.BytedanceReportMaterialDaily;
 import cn.com.ctop.toutiao.modules.report.entity.BytedanceReportMaterialRetry;
+import cn.com.ctop.toutiao.modules.report.entity.BytedanceReportVideoMaterialDaily;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -17,6 +18,8 @@ public interface BytedanceReportMaterialDailyMapper extends BaseMapper<Bytedance
 
     void replaceIntoBatch(@Param("infos") List<BytedanceReportMaterialDaily> infos);
 
+    void replaceIntoVideoMaterialBatch(@Param("infos") List<BytedanceReportVideoMaterialDaily> infos);
+
     void replaceMaterialRetry(@Param("retry") BytedanceReportMaterialRetry retry);
 
     List<BytedanceReportMaterialRetry> getRetryList();

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

@@ -212,7 +212,8 @@
             start_date,
             end_date,
             status,
-            status_code
+            status_code,
+            type
         )
         VALUES
         (
@@ -220,7 +221,8 @@
             #{retry.startDate},
             #{retry.endDate},
             #{retry.status},
-            #{retry.statusCode}
+            #{retry.statusCode},
+            #{retry.type}
         )
 
     </insert>
@@ -247,12 +249,7 @@
         and end_date = #{retry.endDate}
     </update>
 
-
-
-
-
-
-    <insert id="replaceIntoBatch">
+    <insert id="replaceIntoVideoMaterialBatch">
         REPLACE INTO ctop_bytedance_report_material_daily
         (
         account_id,
@@ -265,10 +262,15 @@
         deep_convert_cost,
         deep_convert_rate,
         dislike,
+        report,
         replay_duration_2s_rate,
         play_duration_3s_rate,
         play_duration_5s_rate,
         play_duration_10s_rate,
+        play_25_feed_break_rate,
+        play_50_feed_break_rate,
+        play_75_feed_break_rate,
+        play_100_feed_break_rate,
         avg_show_cost,
         total_play,
         valid_play,
@@ -296,17 +298,40 @@
             #{info.materialId},
             #{info.statDatetime},
             #{info.click},
-            #{info.avg_click_cost},
-            #{info.deep_convert},
-            #{info.cost},
             #{info.cost},
-            #{info.cost},
-            #{info.cost},
-            #{info.cost},
-            #{info.cost},
-            #{info.cost},
-            #{info.cost},
-
+            #{info.avgClickCost},
+            #{info.deepConvert},
+            #{info.deepConvertCost},
+            #{info.deepConvertRate},
+            #{info.dislike},
+            #{info.report},
+            #{info.playDuration2sRate},
+            #{info.playDuration3sRate},
+            #{info.playDuration5sRate},
+            #{info.playDuration10sRate},
+            #{info.play25FeedBreakRate},
+            #{info.play50FeedBreakRate},
+            #{info.play75FeedBreakRate},
+            #{info.play100FeedBreakRate},
+            #{info.avgShowCost},
+            #{info.totalPlay},
+            #{info.validPlay},
+            #{info.shareMaterial},
+            #{info.commentMaterial},
+            #{info.follow},
+            #{info.validPlayCost},
+            #{info.convertMaterial},
+            #{info.playOverRate},
+            #{info.ctr},
+            #{info.likeMaterial},
+            #{info.showMaterial},
+            #{info.convertRate},
+            #{info.playOver},
+            #{info.messageAction},
+            #{info.validPlayRate},
+            #{info.averagePlayTimePerPlay},
+            #{info.convertCost},
+            #{info.convertShowRate}
             )
         </foreach>
     </insert>

+ 2 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/IBytedanceReportService.java

@@ -42,4 +42,6 @@ public interface IBytedanceReportService {
     int bytedanceMaterialReportRetry(CtopOauthToken token, String startDate, String endDate);
 
     List<BytedanceReportMaterialRetry> getRetryList();
+
+    int bytedanceVideoMaterialReport(CtopOauthToken token, String startDate, String endDate);
 }

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

@@ -952,12 +952,12 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
      * @param endDate
      * @return
      */
-    //@Override
+    @Override
     public int bytedanceVideoMaterialReport(CtopOauthToken token, String startDate, String endDate) {
         Long accountId = token.getAccountId();
         log.info("头条素材报表当前accountId为:" + accountId);
         Integer page = 1;
-        Integer pageSize = 100;
+        Integer pageSize = 1000;
         int code = bytedanceVideoMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
         if (code != 200 && code != 1) {
             BytedanceReportMaterialRetry retry = new BytedanceReportMaterialRetry();
@@ -974,11 +974,11 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
     }
 
     private int bytedanceVideoMaterialReportByPage(Integer page, Integer pageSize, CtopOauthToken token, Long accountId, String startDate, String endDate) {
-        //log.info("当前页数:"+ page);
+        log.info("当前页数:"+ page);
         String access_token = token.getAccessToken();
 
         // 请求地址
-        String open_api_domain = "https";
+        String open_api_domain = "https://ad.oceanengine.com";
         String path = "/open_api/2/report/video/get/";
 
         // 请求参数
@@ -1017,38 +1017,25 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                 JSONArray jsonArrayay = jsonData.getJSONArray("list");
                 if (jsonArrayay.size() == 0) {
                     log.info("accountId:" + accountId + ";没有数据。总页数为:" + totalPage + "当前页数为:" + currentPage);
-                    //returnCode = 1;
                     return 1;
                 }
 
                 List<BytedanceReportVideoMaterialDaily> bytedanceReportVideoMaterialDailyList = new ArrayList<>();
                 for (int i = 0; i < jsonArrayay.size(); i++) {
-                    //BytedanceReportMaterialDaily daily = new BytedanceReportMaterialDaily();
-                    //daily.setAccountId(accountId);
                     JSONObject detailJson = jsonArrayay.getJSONObject(i);
                     if (!Check.isNull(detailJson)) {
                         BytedanceReportVideoMaterialDaily daily = new BytedanceReportVideoMaterialDaily(detailJson, accountId);
-
                         bytedanceReportVideoMaterialDailyList.add(daily);
                     }
                 }
-                //Long insertStartTime = System.currentTimeMillis();
-
-
-                bytedanceReportMaterialDailyMapper.replaceIntoBatch(bytedanceReportVideoMaterialDailyList);
-
-
-                //Long insertEndTime = System.currentTimeMillis();
-                //log.info("头条获取素材报表插入数据结束,执行耗时:{}秒", (insertEndTime - insertStartTime) / 1000);
+                bytedanceReportMaterialDailyMapper.replaceIntoVideoMaterialBatch(bytedanceReportVideoMaterialDailyList);
                 if (currentPage >= totalPage) {
-                    //log.info("accountId:" + accountId + "数据同步完成,开始时间:" + startDate + ",结束时间:"+ endDate);
                     return 1;
                 } else {
                     int pageCode = bytedanceVideoMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
                     return pageCode;
                 }
             } else {
-                //returnCode = -1;
                 log.error("服务器返回为空,json:" + JSONObject.toJSONString(data));
                 return -1;
             }