|
@@ -29,7 +29,6 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
-import java.text.ParseException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -764,7 +763,6 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
}
|
|
|
|
|
|
private int bytedanceMaterialReportByPage(Integer page, Integer pageSize, CtopOauthToken token, Long accountId, String startDate, String endDate) {
|
|
|
- //log.info("当前页数:"+ page);
|
|
|
String access_token = token.getAccessToken();
|
|
|
|
|
|
// 请求地址
|
|
@@ -976,13 +974,8 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
}
|
|
|
|
|
|
private int bytedanceVideoMaterialReportByPage(Integer page, Integer pageSize, CtopOauthToken token, Long accountId, String startDate, String endDate) {
|
|
|
- log.info("当前页数:"+ page);
|
|
|
- String access_token = token.getAccessToken();
|
|
|
-
|
|
|
// 请求地址
|
|
|
- String open_api_domain = "https://ad.oceanengine.com";
|
|
|
- String path = "/open_api/2/report/video/get/";
|
|
|
-
|
|
|
+ String url = "https://ad.oceanengine.com/open_api/2/report/video/get/";
|
|
|
// 请求参数
|
|
|
Map data = new HashMap();
|
|
|
data.put("advertiser_id", accountId);
|
|
@@ -992,61 +985,51 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
data.put("page_size", pageSize);
|
|
|
data.put("group_by", new String[]{"STAT_GROUP_BY_MATERIAL_ID", "STAT_GROUP_BY_TIME_DAY"});
|
|
|
|
|
|
- JSONObject json = HttpUtils.bytedanceGetRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
|
|
|
+ JSONObject json = HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, JSONObject.parseObject(JSONObject.toJSONString(data)));
|
|
|
if (json == null) {
|
|
|
log.error("返回为空,请求有误:" + JSONObject.toJSONString(data));
|
|
|
return -2;
|
|
|
}
|
|
|
|
|
|
- int returnCode = 200;
|
|
|
try {
|
|
|
- if (!Check.isNull(json)) {
|
|
|
- Integer code = json.getInteger("code");
|
|
|
- if (code != 0) {
|
|
|
- log.error("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + json + "请求为:" + JSONObject.toJSONString(data));
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- JSONObject jsonData = json.getJSONObject("data");
|
|
|
- if (Check.isNull(jsonData)) {
|
|
|
- log.error("获取任务列表返回信息data内容为空,头条accountId:" + accountId + ";返回json为:" + json + "请求为:" + JSONObject.toJSONString(data));
|
|
|
- return -1;
|
|
|
- }
|
|
|
- JSONObject pageInfo = jsonData.getJSONObject("page_info");
|
|
|
- Integer totalPage = pageInfo.getInteger("total_page");
|
|
|
- Integer currentPage = pageInfo.getInteger("page");
|
|
|
-
|
|
|
- JSONArray jsonArrayay = jsonData.getJSONArray("list");
|
|
|
- if (jsonArrayay.size() == 0) {
|
|
|
- log.info("accountId:" + accountId + ";没有数据。总页数为:" + totalPage + "当前页数为:" + currentPage);
|
|
|
- return 1;
|
|
|
- }
|
|
|
-
|
|
|
- List<BytedanceReportVideoMaterialDaily> bytedanceReportVideoMaterialDailyList = new ArrayList<>();
|
|
|
- for (int i = 0; i < jsonArrayay.size(); i++) {
|
|
|
- JSONObject detailJson = jsonArrayay.getJSONObject(i);
|
|
|
- if (!Check.isNull(detailJson)) {
|
|
|
- BytedanceReportVideoMaterialDaily daily = new BytedanceReportVideoMaterialDaily(detailJson, accountId);
|
|
|
- bytedanceReportVideoMaterialDailyList.add(daily);
|
|
|
- }
|
|
|
- }
|
|
|
- bytedanceReportMaterialDailyMapper.replaceIntoVideoMaterialBatch(bytedanceReportVideoMaterialDailyList);
|
|
|
- if (currentPage >= totalPage) {
|
|
|
- log.info("头条视频素材报表当前accountId为:{} {}~{},接口数据拉取成功" , accountId, startDate,endDate);
|
|
|
- return 1;
|
|
|
- } else {
|
|
|
- return bytedanceVideoMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
|
|
|
+ Integer code = json.getInteger("code");
|
|
|
+ if (code != 0) {
|
|
|
+ log.error("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + json + "请求为:" + JSONObject.toJSONString(data));
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ JSONObject jsonData = json.getJSONObject("data");
|
|
|
+ if (Check.isNull(jsonData)) {
|
|
|
+ log.error("获取任务列表返回信息data内容为空,头条accountId:" + accountId + ";返回json为:" + json + "请求为:" + JSONObject.toJSONString(data));
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ JSONObject pageInfo = jsonData.getJSONObject("page_info");
|
|
|
+ Integer totalPage = pageInfo.getInteger("total_page");
|
|
|
+ Integer currentPage = pageInfo.getInteger("page");
|
|
|
+ JSONArray jsonArrayay = jsonData.getJSONArray("list");
|
|
|
+ if (jsonArrayay.size() == 0) {
|
|
|
+ log.info("accountId:" + accountId + ";没有数据。总页数为:" + totalPage + "当前页数为:" + currentPage);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ List<BytedanceReportVideoMaterialDaily> bytedanceReportVideoMaterialDailyList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < jsonArrayay.size(); i++) {
|
|
|
+ JSONObject detailJson = jsonArrayay.getJSONObject(i);
|
|
|
+ if (!Check.isNull(detailJson)) {
|
|
|
+ BytedanceReportVideoMaterialDaily daily = new BytedanceReportVideoMaterialDaily(detailJson, accountId);
|
|
|
+ bytedanceReportVideoMaterialDailyList.add(daily);
|
|
|
}
|
|
|
+ }
|
|
|
+ bytedanceReportMaterialDailyMapper.replaceIntoVideoMaterialBatch(bytedanceReportVideoMaterialDailyList);
|
|
|
+ if (currentPage >= totalPage) {
|
|
|
+ log.info("头条视频素材报表当前accountId为:{} {}~{},接口数据拉取成功" , accountId, startDate,endDate);
|
|
|
+ return 1;
|
|
|
} else {
|
|
|
- log.error("头条视频素材报表服务器返回为空,accountId:" + accountId + ",json:" + json + "请求为:" + JSONObject.toJSONString(data));
|
|
|
- return -1;
|
|
|
+ return bytedanceVideoMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
log.error("头条视频素材报表其他错误,accountId:" + accountId + ",json:" + json + "请求为:" + JSONObject.toJSONString(data));
|
|
|
- returnCode = -3;
|
|
|
+ return -3;
|
|
|
}
|
|
|
- return returnCode;
|
|
|
}
|
|
|
|
|
|
}
|