Browse Source

头条视频素材报表编写

hcst_sunzhen 5 năm trước cách đây
mục cha
commit
d42d593d7c

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

@@ -143,7 +143,7 @@ public class BytedanceReportController {
                 return result;
             }
 
-            final ExecutorService executorService = Executors.newFixedThreadPool(3);
+            final ExecutorService executorService = Executors.newFixedThreadPool(8);
             tokens.forEach(token -> {
                 executorService.submit(new Runnable() {
                     @Override
@@ -165,7 +165,8 @@ public class BytedanceReportController {
                         }
                     }
                 });
-            });
+            }
+            );
             ////
             Long endtime = System.currentTimeMillis();
             log.info("头条获取素材报表数据任务执行结束,执行耗时:{}秒", (endtime - starttime) / 1000);
@@ -278,4 +279,54 @@ public class BytedanceReportController {
         return result;
     }
 
+
+    /**
+     * 头条视频素材报表--此接口仅有视频素材
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    @GetMapping("/bytedance/bytedanceVideoMaterialReport")
+    public Result bytedanceVideoMaterialReport(@RequestParam(name = "startDate") String startDate,
+                                                @RequestParam(name = "endDate") String endDate,
+                                               @RequestParam(name = "endDate") Long accountId) {
+        Result result = new Result<>();
+        if (StringUtils.isBlank(startDate) || StringUtils.isBlank(endDate)){
+            result.error500("开始时间和结束时间不能为空");
+            return result;
+        }
+        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.bytedanceMaterialReport(token, start, end);
+                                    }
+                                } catch (Exception e) {
+                                    e.printStackTrace();
+                                } finally {
+                                }
+
+
+            ////
+            Long endtime = System.currentTimeMillis();
+            log.info("头条获取素材报表数据任务执行结束,执行耗时:{}秒", (endtime - starttime) / 1000);
+        } catch (Exception e) {
+            log.error("头条获取素材报表数据任务执行结失败");
+            e.printStackTrace();
+            result.setSuccess(false);
+        }
+        return result;
+    }
+
 }

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

@@ -0,0 +1,176 @@
+package cn.com.ctop.toutiao.modules.report.entity;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecg.common.util.DateUtils;
+
+import java.math.BigDecimal;
+
+/**
+ * 头条视频素材日报表--仅包含视频素材
+ * @author sunzhen
+ */
+@Data
+@TableName("ctop_bytedance_report_video_material_daily")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value="ctop_bytedance_report_video_material_daily对象", description="头条视频素材日报表--仅包含视频素材")
+public class BytedanceReportVideoMaterialDaily {
+
+	/**id*/
+	@TableId(type = IdType.AUTO)
+    @ApiModelProperty(value = "id")
+	private Long id;
+	/**账户id*/
+    @ApiModelProperty(value = "广告主id")
+	private Long accountId;
+	/**数据起始时间1*/
+    @ApiModelProperty(value = "数据时间")
+	private String statDatetime;
+	/**素材id*/
+	@ApiModelProperty(value = "素材id")
+	private Long materialId;
+	/**展现数据-点击数*/
+	@ApiModelProperty(value = "展现数据-点击数")
+	private Long click;
+	/**展现数据-总花费*/
+	@ApiModelProperty(value = "展现数据-总花费")
+	private BigDecimal cost;
+	/**展现数据-总花费*/
+	@ApiModelProperty(value = "展现数据-平均点击单价")
+	private BigDecimal avgClickCost;
+	/**转化数据-深度转化数*/
+	@ApiModelProperty(value = "转化数据-深度转化数")
+	private Long deepConvert;
+	/**转化数据-深度转化成本*/
+	@ApiModelProperty(value = "转化数据-深度转化成本")
+	private BigDecimal deepConvertCost;
+	/**转化数据-深度转化率*/
+	@ApiModelProperty(value = "转化数据-深度转化率")
+	private BigDecimal deepConvertRate;
+	/**互动数据-不感兴趣数*/
+	@ApiModelProperty(value = "互动数据-不感兴趣数")
+	private Long dislike;
+	/**互动数据-举报数*/
+	@ApiModelProperty(value = "互动数据-举报数")
+	private Long report;
+	/**视频数据-2秒播放率*/
+	@ApiModelProperty(value = "视频数据-2秒播放率")
+	private BigDecimal playDuration2sRate;
+	/**视频数据-3秒播放率*/
+	@ApiModelProperty(value = "视频数据-3秒播放率")
+	private BigDecimal playDuration3sRate;
+	/**视频数据-5秒播放率*/
+	@ApiModelProperty(value = "视频数据-5秒播放率")
+	private BigDecimal playDuration5sRate;
+	/**视频数据-10秒播放率*/
+	@ApiModelProperty(value = "视频数据-10秒播放率")
+	private BigDecimal playDuration10sRate;
+	/**视频数据-25%进度播放率*/
+	@ApiModelProperty(value = "视频数据-25%进度播放率")
+	private BigDecimal play25FeedBreakRate;
+	/**视频数据-50%进度播放率*/
+	@ApiModelProperty(value = "视频数据-50%进度播放率")
+	private BigDecimal play50FeedBreakRate;
+	/**视频数据-75%进度播放率*/
+	@ApiModelProperty(value = "视频数据-75%进度播放率")
+	private BigDecimal play75FeedBreakRate;
+	/**视频数据-99%进度播放率*/
+	@ApiModelProperty(value = "视频数据-99%进度播放率")
+	private BigDecimal play100FeedBreakRate;
+	/**展现数据-平均千次展现费用*/
+	@ApiModelProperty(value = "展现数据-平均千次展现费用")
+	private BigDecimal avgShowCost;
+	/**视频数据-播放数*/
+	@ApiModelProperty(value = "视频数据-播放数")
+	private Long totalPlay;
+	/**视频数据-有效播放数*/
+	@ApiModelProperty(value = "视频数据-有效播放数")
+	private Long validPlay;
+	/**互动数据-分享数*/
+	@ApiModelProperty(value = "互动数据-分享数")
+	private Long shareMaterial;
+	/**互动数据-评论数*/
+	@ApiModelProperty(value = "互动数据-评论数")
+	private Long commentMaterial;
+	/**互动数据-新增关注数*/
+	@ApiModelProperty(value = "互动数据-新增关注数")
+	private Long follow;
+	/**视频数据-有效播放成本*/
+	@ApiModelProperty(value = "视频数据-有效播放成本")
+	private BigDecimal validPlayCost;
+	/**转化数据-转化数*/
+	@ApiModelProperty(value = "转化数据-转化数")
+	private Long convertMaterial;
+	/**视频数据-播完率*/
+	@ApiModelProperty(value = "视频数据-播完率")
+	private BigDecimal playOverRate;
+	/**展现数据-点击率*/
+	@ApiModelProperty(value = "展现数据-点击率")
+	private BigDecimal ctr;
+	/**互动数据-点赞数*/
+	@ApiModelProperty(value = "互动数据-点赞数")
+	private Long likeMaterial;
+	/**展现数据-展示数*/
+	@ApiModelProperty(value = "展现数据-展示数")
+	private Long showMaterial;
+	/**转化数据-转化率*/
+	@ApiModelProperty(value = "转化数据-转化率")
+	private BigDecimal convertRate;
+	/**视频数据-播放完成数*/
+	@ApiModelProperty(value = "视频数据-播放完成数")
+	private Long playOver;
+	/**互动数据-私信数*/
+	@ApiModelProperty(value = "互动数据-私信数")
+	private Long messageAction;
+	/**视频数据-有效播放率*/
+	@ApiModelProperty(value = "视频数据-有效播放率")
+	private BigDecimal validPlayRate;
+	/**视频数据-平均单次播放时长*/
+	@ApiModelProperty(value = "视频数据-平均单次播放时长")
+	private BigDecimal averagePlayTimePerPlay;
+	/**转化数据-转化成本*/
+	@ApiModelProperty(value = "转化数据-转化成本")
+	private BigDecimal convertCost;
+	/***/
+	@ApiModelProperty(value = "")
+	private BigDecimal convertShowRate;
+
+	public BytedanceReportVideoMaterialDaily() {
+	}
+
+	//public BytedanceReportVideoMaterialDaily(JSONObject detailJson, Long accountId) {
+	//	JSONObject dimensions = detailJson.getJSONObject("dimensions");
+	//	this.accountId = accountId;
+	//	this.setMaterialId(dimensions.getLong("material_id"));
+	//	this.setStatDatetime(dimensions.getDate("stat_datetime") == null ? null : DateUtils.formatDate(dimensions.getDate("stat_datetime"), "yyyy-MM-dd"));
+	//
+	//	JSONObject metrics = detailJson.getJSONObject("metrics");
+	//	this.setValidPlayCost(metrics.getBigDecimal("valid_play_cost"));
+	//	this.setConvertMaterial(metrics.getInteger("convert"));
+	//	this.setPlayOverRate(metrics.getBigDecimal("play_over_rate"));
+	//	this.setCtr(metrics.getBigDecimal("ctr"));
+	//	this.setLikeMaterial(metrics.getInteger("like"));
+	//	this.setClick(metrics.getInteger("click"));
+	//	this.setTotalPlay(metrics.getInteger("total_play"));
+	//	this.setShowMaterial(metrics.getInteger("show"));
+	//	this.setConvertRate(metrics.getBigDecimal("convert_rate"));
+	//	this.setShareMaterial(metrics.getInteger("share"));
+	//	this.setValidPlay(metrics.getInteger("valid_play"));
+	//	this.setCost(metrics.getBigDecimal("cost"));
+	//	this.setPlayOver(metrics.getInteger("play_over"));
+	//	this.setFollow(metrics.getInteger("follow"));
+	//	this.setValidPlayRate(metrics.getBigDecimal("valid_play_rate"));
+	//	this.setAveragePlayTimePerPlay(metrics.getBigDecimal("average_play_time_per_play"));
+	//	this.setConvertShowRate(metrics.getBigDecimal("convert_show_rate"));
+	//	this.setCommentMaterial(metrics.getInteger("comment"));
+	//	this.setConvertCost(metrics.getBigDecimal("convert_cost"));
+	//}
+}

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

@@ -735,7 +735,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
     @Override
     public int bytedanceMaterialReport(CtopOauthToken token, String startDate, String endDate) {
         Long accountId = token.getAccountId();
-        // log.info("头条素材报表当前accountId为:" + accountId);
+        log.info("头条素材报表当前accountId为:" + accountId);
         Integer page = 1;
         Integer pageSize = 100;
         int code = bytedanceMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
@@ -748,6 +748,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
             retry.setStatusCode(code);
             bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
         }
+        log.info("头条素材报表当前accountId为:{}  {}~{}" , accountId, startDate,endDate);
         return code;
     }
 
@@ -757,7 +758,8 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
 
         // 请求地址
         String open_api_domain = "https://ad.oceanengine.com";
-        String path = "/open_api/2/report/integrated/get/";
+        //String path = "/open_api/2/report/integrated/get/";
+        String path = "/open_api/2/report/video/get/";
 
         // 请求参数
         Map data = new HashMap() {
@@ -767,7 +769,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                 put("end_date", endDate);
                 put("page", page);
                 put("page_size", pageSize);
-                put("group_by", new String[]{"STAT_GROUP_BY_MATERIAL_ID", "STAT_GROUP_BY_INVENTORY", "STAT_GROUP_BY_IMAGE_MODE", "STAT_GROUP_BY_TIME_DAY"});
+                put("group_by", new String[]{"STAT_GROUP_BY_MATERIAL_ID", "STAT_GROUP_BY_TIME_DAY"});
             }
         };