|
@@ -81,13 +81,20 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void getPromotionList(Long advertiserId, JSONArray ids, String date, Long errorId, Integer isLog) {
|
|
public void getPromotionList(Long advertiserId, JSONArray ids, String date, Long errorId, Integer isLog) {
|
|
|
- this.getPromotionListVo(advertiserId, ids, date, 1, 1, errorId, isLog);
|
|
|
|
|
|
|
+ if (ids == null || ids.isEmpty()) { //总数超过1万条必须使用 cursor count 分页,且不能和ids过滤一起使用
|
|
|
|
|
+ this.getPromotionListVo(advertiserId, ids, date, null, 0L, 1, errorId, isLog);
|
|
|
|
|
+ } else { //page page_size 分页
|
|
|
|
|
+ this.getPromotionListVo(advertiserId, ids, date, 1, null, 1, errorId, isLog);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void getPromotionListVo(Long advertiserId, JSONArray ids, String date, Integer page, int count, Long errorId, Integer isLog) {
|
|
|
|
|
|
|
+ private void getPromotionListVo(Long advertiserId, JSONArray ids, String date, Integer page, Long cursor, int count, Long errorId, Integer isLog) {
|
|
|
try {
|
|
try {
|
|
|
log.info("执行id:{}", advertiserId);
|
|
log.info("执行id:{}", advertiserId);
|
|
|
- boolean nextPage = false;
|
|
|
|
|
|
|
+ boolean hasNextPage = false;
|
|
|
|
|
+ Integer nextPage = null;
|
|
|
|
|
+ Long nextCursor = null;
|
|
|
String accessToken = tokenMapper.onlyGetToken(advertiserId);
|
|
String accessToken = tokenMapper.onlyGetToken(advertiserId);
|
|
|
if (Check.isNull(accessToken)) {
|
|
if (Check.isNull(accessToken)) {
|
|
|
log.error("账户({})查询token失败", advertiserId);
|
|
log.error("账户({})查询token失败", advertiserId);
|
|
@@ -104,8 +111,13 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
filtering.put("ids", ids);
|
|
filtering.put("ids", ids);
|
|
|
}
|
|
}
|
|
|
params.put("filtering", filtering);
|
|
params.put("filtering", filtering);
|
|
|
- params.put("page", page);
|
|
|
|
|
- params.put("page_size", 20);//最大20
|
|
|
|
|
|
|
+ if (cursor != null) {
|
|
|
|
|
+ params.put("cursor", cursor);
|
|
|
|
|
+ params.put("count", 20);//最大20
|
|
|
|
|
+ } else {
|
|
|
|
|
+ params.put("page", page);
|
|
|
|
|
+ params.put("page_size", 20);//最大20
|
|
|
|
|
+ }
|
|
|
String url = "https://api.oceanengine.com/open_api/v3.0/promotion/list/";
|
|
String url = "https://api.oceanengine.com/open_api/v3.0/promotion/list/";
|
|
|
String results = HttpUtils.httpGet(url, params, HttpUtils.postMHeaders(accessToken));
|
|
String results = HttpUtils.httpGet(url, params, HttpUtils.postMHeaders(accessToken));
|
|
|
JSONObject obj = JSONObject.parseObject(results);
|
|
JSONObject obj = JSONObject.parseObject(results);
|
|
@@ -113,9 +125,18 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
Integer code = obj.getInteger("code");
|
|
Integer code = obj.getInteger("code");
|
|
|
if (code == 0) {
|
|
if (code == 0) {
|
|
|
JSONObject data = obj.getJSONObject("data");
|
|
JSONObject data = obj.getJSONObject("data");
|
|
|
- Integer totalPage = data.getJSONObject("page_info").getInteger("total_page");
|
|
|
|
|
- if (totalPage != 0 && totalPage > data.getJSONObject("page_info").getInteger("page")) {
|
|
|
|
|
- nextPage = true;
|
|
|
|
|
|
|
+ if (cursor != null) {
|
|
|
|
|
+ JSONObject cursorInfo = data.getJSONObject("cursor_info");
|
|
|
|
|
+ hasNextPage = cursorInfo.getBoolean("has_more");
|
|
|
|
|
+ if (hasNextPage) {
|
|
|
|
|
+ nextCursor = cursorInfo.getLong("cursor");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Integer totalPage = data.getJSONObject("page_info").getInteger("total_page");
|
|
|
|
|
+ if (totalPage != 0 && totalPage > data.getJSONObject("page_info").getInteger("page")) {
|
|
|
|
|
+ hasNextPage = true;
|
|
|
|
|
+ nextPage = page + 1;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
JSONArray array = data.getJSONArray("list");
|
|
JSONArray array = data.getJSONArray("list");
|
|
|
for (int i = 0; i < array.size(); i++) {
|
|
for (int i = 0; i < array.size(); i++) {
|
|
@@ -134,7 +155,7 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
//40100请求超频 (40100 == code || 40110 == code || 40130 == code) &&
|
|
//40100请求超频 (40100 == code || 40110 == code || 40130 == code) &&
|
|
|
if (count <= 5) {
|
|
if (count <= 5) {
|
|
|
Thread.sleep(800);
|
|
Thread.sleep(800);
|
|
|
- getPromotionListVo(advertiserId, ids, date, page, count + 1, errorId, isLog);
|
|
|
|
|
|
|
+ getPromotionListVo(advertiserId, ids, date, page, cursor, count + 1, errorId, isLog);
|
|
|
} else {
|
|
} else {
|
|
|
insertErrorLog(isLog, advertiserId, "-", "-", "promotion_list", results);
|
|
insertErrorLog(isLog, advertiserId, "-", "-", "promotion_list", results);
|
|
|
log.error("获取广告列表失败(url:{}),入参:{}\n结果:{}", url, JSONObject.toJSONString(params), obj);
|
|
log.error("获取广告列表失败(url:{}),入参:{}\n结果:{}", url, JSONObject.toJSONString(params), obj);
|
|
@@ -142,8 +163,8 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (nextPage) {
|
|
|
|
|
- getPromotionListVo(advertiserId, ids, date, page + 1, 1, errorId, isLog);
|
|
|
|
|
|
|
+ if (hasNextPage) {
|
|
|
|
|
+ getPromotionListVo(advertiserId, ids, date, nextPage, nextCursor, 1, errorId, isLog);
|
|
|
} else if (errorId != null) {
|
|
} else if (errorId != null) {
|
|
|
promoterReportMapper.deleteInfoByErrorId(errorId);
|
|
promoterReportMapper.deleteInfoByErrorId(errorId);
|
|
|
}
|
|
}
|