|
@@ -1,15 +1,19 @@
|
|
package cn.com.ctop.job.bytedance.data.service.impl;
|
|
package cn.com.ctop.job.bytedance.data.service.impl;
|
|
|
|
|
|
import cn.com.ctop.job.bytedance.data.constant.BytedanceConstant;
|
|
import cn.com.ctop.job.bytedance.data.constant.BytedanceConstant;
|
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.ByteDanceNewMaterialReport;
|
|
import cn.com.ctop.job.bytedance.data.entity.BytedanceMaterialReportDaily;
|
|
import cn.com.ctop.job.bytedance.data.entity.BytedanceMaterialReportDaily;
|
|
import cn.com.ctop.job.bytedance.data.entity.OauthToken;
|
|
import cn.com.ctop.job.bytedance.data.entity.OauthToken;
|
|
import cn.com.ctop.job.bytedance.data.mapper.BytedanceMaterialReportDailyMapper;
|
|
import cn.com.ctop.job.bytedance.data.mapper.BytedanceMaterialReportDailyMapper;
|
|
|
|
+import cn.com.ctop.job.bytedance.data.mapper.BytedanceNewMaterialReportMapper;
|
|
import cn.com.ctop.job.bytedance.data.service.IBytedanceMaterialReportDailyService;
|
|
import cn.com.ctop.job.bytedance.data.service.IBytedanceMaterialReportDailyService;
|
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.DateUtils;
|
|
import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -34,6 +38,9 @@ public class BytedanceMaterialReportDailyServiceImpl implements IBytedanceMateri
|
|
@Resource
|
|
@Resource
|
|
BytedanceMaterialReportDailyMapper bytedanceMaterialReportDailyMapper;
|
|
BytedanceMaterialReportDailyMapper bytedanceMaterialReportDailyMapper;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private BytedanceNewMaterialReportMapper bytedanceNewMaterialReportMapper;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void bytedanceDailyMaterialReportJob(OauthToken oauthToken, String yesterda, String yesterda1, int page, int pageSize) {
|
|
public void bytedanceDailyMaterialReportJob(OauthToken oauthToken, String yesterda, String yesterda1, int page, int pageSize) {
|
|
log.info("开始获取图片和视频素材日报 accountID:{},page:{} date:{}", oauthToken.getAccountId(), page,yesterda);
|
|
log.info("开始获取图片和视频素材日报 accountID:{},page:{} date:{}", oauthToken.getAccountId(), page,yesterda);
|
|
@@ -101,4 +108,167 @@ public class BytedanceMaterialReportDailyServiceImpl implements IBytedanceMateri
|
|
bytedanceDailyMaterialReportJob(oauthToken, yesterda, yesterda1, page, 1000);
|
|
bytedanceDailyMaterialReportJob(oauthToken, yesterda, yesterda1, page, 1000);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //头条-体验版素材日报--视频
|
|
|
|
+ @Override
|
|
|
|
+ public void bytedanceDailyMaterialReportJobV3Video(OauthToken oauthToken, String yesterda, String yesterda1, int page, int pageSize) throws Exception {
|
|
|
|
+ log.info("开始获取体验版-视频-素材日报 accountID:{},page:{} date:{}", oauthToken.getAccountId(), page,yesterda);
|
|
|
|
+ // 请求地址
|
|
|
|
+ String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V3_REPORT_INTEGRATED_GET;
|
|
|
|
+ Map<String,Object> param = new HashMap<>();
|
|
|
|
+ param.put("advertiser_id",oauthToken.getAccountId());
|
|
|
|
+ param.put("start_date",yesterda);
|
|
|
|
+ param.put("end_date",yesterda1);
|
|
|
|
+ param.put("page",page);
|
|
|
|
+ param.put("page_size",pageSize);
|
|
|
|
+ //List<String> fields = Arrays.asList("stat_cost");
|
|
|
|
+ //String fields1 = "[\"stat_cost\",\"show_cnt\",\"image_mode\"]";
|
|
|
|
+ // fields 入参 为拼接字符串数组形式 与入参 video_image_mode数组 && image_image_mode数组 格式不同
|
|
|
|
+ String fields = ByteDanceNewMaterialReport.getParamsFields();
|
|
|
|
+ param.put("fields",fields);
|
|
|
|
+ param.put("time_granularity","STAT_TIME_GRANULARITY_DAILY");
|
|
|
|
+ //param.put("group_by","STAT_GROUP_BY_DELIVERY_MODE");
|
|
|
|
+
|
|
|
|
+ Map<String,String> header = new HashMap<>();
|
|
|
|
+ header.put("Access-Token",oauthToken.getAccessToken());
|
|
|
|
+
|
|
|
|
+ //String video_image_mode = "[\"CREATIVE_IMAGE_MODE_VIDEO\",\"CREATIVE_IMAGE_MODE_VIDEO_VERTICAL\"]";
|
|
|
|
+ String[] video_image_mode = new String[]{"CREATIVE_IMAGE_MODE_VIDEO","CREATIVE_IMAGE_MODE_VIDEO_VERTICAL"};
|
|
|
|
+ //String image_image_mode = "[\"CREATIVE_IMAGE_MODE_LARGE\",\"CREATIVE_IMAGE_MODE_LARGE_VERTICAL\",\"CREATIVE_IMAGE_MODE_SMALL\"]";
|
|
|
|
+ String[] image_image_mode = new String[]{"CREATIVE_IMAGE_MODE_LARGE","CREATIVE_IMAGE_MODE_LARGE_VERTICAL","CREATIVE_IMAGE_MODE_SMALL"};
|
|
|
|
+
|
|
|
|
+ JSONObject filtering = new JSONObject();
|
|
|
|
+ Map<String,Object> video_material = new HashMap<>();
|
|
|
|
+ video_material.put("image_mode",video_image_mode);
|
|
|
|
+
|
|
|
|
+ Map<String,Object> image_material = new HashMap<>();
|
|
|
|
+ image_material.put("image_mode",image_image_mode);
|
|
|
|
+
|
|
|
|
+ filtering.put("video_material",video_material);
|
|
|
|
+ //filtering.put("image_material",image_material);
|
|
|
|
+
|
|
|
|
+ param.put("filtering",filtering);
|
|
|
|
+ JSONObject resultObject = JSONObject.parseObject(HttpUtils.httpGet(url, param,header));
|
|
|
|
+
|
|
|
|
+ Integer code = resultObject.getInteger("code");
|
|
|
|
+ if (null == code || !code.equals(0)) {
|
|
|
|
+ log.error("获取体验版-视频-素材日报接口异常==》accountId:{},message:{}", oauthToken.getAccountId(), resultObject.getString("message"));
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ JSONArray data = resultObject.getJSONObject("data").getJSONArray("list");
|
|
|
|
+ if (null == data || data.isEmpty()) {
|
|
|
|
+ log.error("获取体验版-视频-素材数据为空==》accountId:{}", oauthToken.getAccountId());
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ List<ByteDanceNewMaterialReport> list = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
|
+ JSONObject dataObject = data.getJSONObject(i);
|
|
|
|
+ Long materialId = dataObject.getLong("material_id");
|
|
|
|
+ String statDatetime = dataObject.getString("stat_datetime");
|
|
|
|
+ Integer dateTime = DateUtils.getDateInteger(statDatetime);
|
|
|
|
+ JSONArray data1 = dataObject.getJSONArray("data");
|
|
|
|
+ for (Object o : data1) {
|
|
|
|
+ JSONObject j = JSONObject.parseObject(o.toString());
|
|
|
|
+ ByteDanceNewMaterialReport report = JSONObject.parseObject(j.toJSONString(), ByteDanceNewMaterialReport.class);
|
|
|
|
+ report.setAdvertiserId(oauthToken.getAccountId());
|
|
|
|
+ report.setMaterialId(materialId);
|
|
|
|
+ report.setStatDatetime(dateTime);
|
|
|
|
+ list.add(report);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ bytedanceNewMaterialReportMapper.replaceBytedanceNewMaterialVideoDaily(list);
|
|
|
|
+
|
|
|
|
+ page++;
|
|
|
|
+ int totalPage = resultObject.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
|
|
|
|
+ if (page <= totalPage) {
|
|
|
|
+ bytedanceDailyMaterialReportJobV3Video(oauthToken, yesterda, yesterda1, page, 100);
|
|
|
|
+ }
|
|
|
|
+ log.error("获取体验版-视频-素材数据完成==》accountId:{}", oauthToken.getAccountId());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //头条-体验版素材日报--图片
|
|
|
|
+ @Override
|
|
|
|
+ public void bytedanceDailyMaterialReportJobV3Image(OauthToken oauthToken, String yesterda, String yesterda1, int page, int pageSize) throws Exception {
|
|
|
|
+ log.info("开始获取体验版-图片-素材日报 accountID:{},page:{} date:{}", oauthToken.getAccountId(), page,yesterda);
|
|
|
|
+ // 请求地址
|
|
|
|
+ String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V3_REPORT_INTEGRATED_GET;
|
|
|
|
+ Map<String,Object> param = new HashMap<>();
|
|
|
|
+ param.put("advertiser_id",oauthToken.getAccountId());
|
|
|
|
+ param.put("start_date",yesterda);
|
|
|
|
+ param.put("end_date",yesterda1);
|
|
|
|
+ param.put("page",page);
|
|
|
|
+ param.put("page_size",pageSize);
|
|
|
|
+ //List<String> fields = Arrays.asList("stat_cost");
|
|
|
|
+ //String fields1 = "[\"stat_cost\",\"show_cnt\",\"image_mode\"]";
|
|
|
|
+ // fields 入参 为拼接字符串数组形式 与入参 video_image_mode数组 && image_image_mode数组 格式不同
|
|
|
|
+ String fields = ByteDanceNewMaterialReport.getParamsFields();
|
|
|
|
+ param.put("fields",fields);
|
|
|
|
+ param.put("time_granularity","STAT_TIME_GRANULARITY_DAILY");
|
|
|
|
+ //param.put("group_by","STAT_GROUP_BY_DELIVERY_MODE");
|
|
|
|
+
|
|
|
|
+ Map<String,String> header = new HashMap<>();
|
|
|
|
+ header.put("Access-Token",oauthToken.getAccessToken());
|
|
|
|
+
|
|
|
|
+ //String video_image_mode = "[\"CREATIVE_IMAGE_MODE_VIDEO\",\"CREATIVE_IMAGE_MODE_VIDEO_VERTICAL\"]";
|
|
|
|
+ String[] video_image_mode = new String[]{"CREATIVE_IMAGE_MODE_VIDEO","CREATIVE_IMAGE_MODE_VIDEO_VERTICAL"};
|
|
|
|
+ //String image_image_mode = "[\"CREATIVE_IMAGE_MODE_LARGE\",\"CREATIVE_IMAGE_MODE_LARGE_VERTICAL\",\"CREATIVE_IMAGE_MODE_SMALL\"]";
|
|
|
|
+ String[] image_image_mode = new String[]{"CREATIVE_IMAGE_MODE_LARGE","CREATIVE_IMAGE_MODE_LARGE_VERTICAL","CREATIVE_IMAGE_MODE_SMALL"};
|
|
|
|
+
|
|
|
|
+ JSONObject filtering = new JSONObject();
|
|
|
|
+ Map<String,Object> video_material = new HashMap<>();
|
|
|
|
+ video_material.put("image_mode",video_image_mode);
|
|
|
|
+
|
|
|
|
+ Map<String,Object> image_material = new HashMap<>();
|
|
|
|
+ image_material.put("image_mode",image_image_mode);
|
|
|
|
+
|
|
|
|
+// filtering.put("video_material",video_material);
|
|
|
|
+ filtering.put("image_material",image_material);
|
|
|
|
+
|
|
|
|
+ param.put("filtering",filtering);
|
|
|
|
+ JSONObject resultObject = JSONObject.parseObject(HttpUtils.httpGet(url, param,header));
|
|
|
|
+
|
|
|
|
+ Integer code = resultObject.getInteger("code");
|
|
|
|
+ if (null == code || !code.equals(0)) {
|
|
|
|
+ log.error("获取体验版-图片-素材日报接口异常==》accountId:{},message:{}", oauthToken.getAccountId(), resultObject.getString("message"));
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ JSONArray data = resultObject.getJSONObject("data").getJSONArray("list");
|
|
|
|
+ if (null == data || data.isEmpty()) {
|
|
|
|
+ log.error("获取体验版-图片-素材数据为空==》accountId:{}", oauthToken.getAccountId());
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ List<ByteDanceNewMaterialReport> list = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
|
+ JSONObject dataObject = data.getJSONObject(i);
|
|
|
|
+ Long materialId = dataObject.getLong("material_id");
|
|
|
|
+ String statDatetime = dataObject.getString("stat_datetime");
|
|
|
|
+ Integer dateTime = DateUtils.getDateInteger(statDatetime);
|
|
|
|
+ JSONArray data1 = dataObject.getJSONArray("data");
|
|
|
|
+ for (Object o : data1) {
|
|
|
|
+ JSONObject j = JSONObject.parseObject(o.toString());
|
|
|
|
+ ByteDanceNewMaterialReport report = JSONObject.parseObject(j.toJSONString(), ByteDanceNewMaterialReport.class);
|
|
|
|
+ report.setAdvertiserId(oauthToken.getAccountId());
|
|
|
|
+ report.setMaterialId(materialId);
|
|
|
|
+ report.setStatDatetime(dateTime);
|
|
|
|
+ list.add(report);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ bytedanceNewMaterialReportMapper.replaceBytedanceNewMaterialImageDaily(list);
|
|
|
|
+
|
|
|
|
+ page++;
|
|
|
|
+ int totalPage = resultObject.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
|
|
|
|
+ if (page <= totalPage) {
|
|
|
|
+ bytedanceDailyMaterialReportJobV3Image(oauthToken, yesterda, yesterda1, page, 100);
|
|
|
|
+ }
|
|
|
|
+ log.error("获取体验版-图片-素材数据完成==》accountId:{}", oauthToken.getAccountId());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|