|
|
@@ -7,6 +7,7 @@ import cn.com.ctop.job.bytedance.data.mapper.BytedancePromoterReportMapper;
|
|
|
import cn.com.ctop.job.bytedance.data.mapper.BytedanceRefreshTokenMapper;
|
|
|
import cn.com.ctop.job.bytedance.data.service.IBytedanceCdpProjectService;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.*;
|
|
|
+import cn.com.ctop.job.bytedance.utils.RateLimitUtil;
|
|
|
import cn.com.ctop.job.bytedance.utils.doris.sink.DorisMultiTableStreamLoadManager;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
@@ -44,6 +45,9 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
@Autowired
|
|
|
private BytedancePromoterReportMapper promoterReportMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RateLimitUtil rateLimitUtil;
|
|
|
+
|
|
|
@Override
|
|
|
public List<Long> queryAllAdverIdList(String type) {
|
|
|
return bytedanceCdpProjectMapper.queryAllAdverIdList(type);
|
|
|
@@ -95,11 +99,13 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
boolean hasNextPage = false;
|
|
|
Integer nextPage = null;
|
|
|
Long nextCursor = null;
|
|
|
- String accessToken = tokenMapper.onlyGetToken(advertiserId);
|
|
|
- if (Check.isNull(accessToken)) {
|
|
|
+ JSONObject authConfig = tokenMapper.getAuthConfig(advertiserId);
|
|
|
+ if (Check.isNull(authConfig)) {
|
|
|
log.error("账户({})查询token失败", advertiserId);
|
|
|
return;
|
|
|
}
|
|
|
+ String accessToken = authConfig.getString("access_token");
|
|
|
+ String devAppId = authConfig.getString("app_id");
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("advertiser_id", advertiserId);
|
|
|
JSONObject filtering = new JSONObject();
|
|
|
@@ -119,7 +125,10 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
params.put("page_size", 20);//最大20
|
|
|
}
|
|
|
String url = "https://api.oceanengine.com/open_api/v3.0/promotion/list/";
|
|
|
- String results = HttpUtils.httpGet(url, params, HttpUtils.postMHeaders(accessToken));
|
|
|
+ String results = null;
|
|
|
+ if (rateLimitUtil.acquire(devAppId, url)) {
|
|
|
+ results = HttpUtils.httpGet(url, params, HttpUtils.postMHeaders(accessToken));
|
|
|
+ }
|
|
|
JSONObject obj = JSONObject.parseObject(results);
|
|
|
if (!Check.isNull(obj)) {
|
|
|
Integer code = obj.getInteger("code");
|
|
|
@@ -161,6 +170,9 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
+ } else {
|
|
|
+ insertErrorLog(isLog, advertiserId, "-", "-", "promotion_list", results);
|
|
|
+ return;
|
|
|
}
|
|
|
if (hasNextPage) {
|
|
|
getPromotionListVo(advertiserId, ids, date, nextPage, nextCursor, 1, errorId, isLog);
|
|
|
@@ -200,11 +212,13 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
private void getProjectListVo(Long advertiserId, JSONArray ids, String type, String date, Integer page, int count, Long errorId, Integer isLog) {
|
|
|
try {
|
|
|
boolean nextPage = false;
|
|
|
- String accessToken = tokenMapper.onlyGetToken(advertiserId);
|
|
|
- if (Check.isNull(accessToken)) {
|
|
|
+ JSONObject authConfig = tokenMapper.getAuthConfig(advertiserId);
|
|
|
+ if (Check.isNull(authConfig)) {
|
|
|
log.error("账户({})查询token失败", advertiserId);
|
|
|
return;
|
|
|
}
|
|
|
+ String accessToken = authConfig.getString("access_token");
|
|
|
+ String devAppId = authConfig.getString("app_id");
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("advertiser_id", advertiserId);
|
|
|
JSONObject filtering = new JSONObject();
|
|
|
@@ -223,7 +237,10 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
params.put("page", page);
|
|
|
params.put("page_size", 100);//最大100
|
|
|
String url = "https://api.oceanengine.com/open_api/v3.0/project/list/";
|
|
|
- String results = HttpUtils.httpGet(url, params, HttpUtils.postMHeaders(accessToken));
|
|
|
+ String results = null;
|
|
|
+ if (rateLimitUtil.acquire(devAppId, url)) {
|
|
|
+ results = HttpUtils.httpGet(url, params, HttpUtils.postMHeaders(accessToken));
|
|
|
+ }
|
|
|
JSONObject obj = JSONObject.parseObject(results);
|
|
|
if (!Check.isNull(obj)) {
|
|
|
Integer code = obj.getInteger("code");
|
|
|
@@ -277,11 +294,13 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
private void getByteAppInfoVo(Long advertiserId, String searchType, Integer page, int count) {
|
|
|
try {
|
|
|
boolean nextPage = false;
|
|
|
- String accessToken = tokenMapper.onlyGetToken(advertiserId);
|
|
|
- if (Check.isNull(accessToken)) {
|
|
|
+ JSONObject authConfig = tokenMapper.getAuthConfig(advertiserId);
|
|
|
+ if (Check.isNull(authConfig)) {
|
|
|
log.error("账户({})查询token失败", advertiserId);
|
|
|
return;
|
|
|
}
|
|
|
+ String accessToken = authConfig.getString("access_token");
|
|
|
+ String devAppId = authConfig.getString("app_id");
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("advertiser_id", advertiserId);
|
|
|
params.put("page", page);
|
|
|
@@ -294,7 +313,10 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
params.put("filtering", filtering);
|
|
|
//获取微信小程序列表
|
|
|
String url = "https://api.oceanengine.com/open_api/v3.0/tools/micro_app/list/";
|
|
|
- JSONObject obj = Okhttp3Utils.bytedanceGetRequest(accessToken, url, params);
|
|
|
+ JSONObject obj = null;
|
|
|
+ if(rateLimitUtil.acquire(devAppId, url)) {
|
|
|
+ obj = Okhttp3Utils.bytedanceGetRequest(accessToken, url, params);
|
|
|
+ }
|
|
|
if (!Check.isNull(obj)) {
|
|
|
Integer code = obj.getInteger("code");
|
|
|
if (code == 0) {
|
|
|
@@ -317,6 +339,10 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
bytedanceCdpProjectMapper.insertErrorAdvertiserId(advertiserId, "tt");
|
|
|
}
|
|
|
}
|
|
|
+ }else {
|
|
|
+ log.error("账户({})获取抖小列表失败,入参:{}\n结果:{}", advertiserId, JSONObject.toJSONString(params), obj);
|
|
|
+ bytedanceCdpProjectMapper.insertErrorAdvertiserId(advertiserId, "tt");
|
|
|
+ return;
|
|
|
}
|
|
|
if (nextPage) {
|
|
|
getByteAppInfoVo(advertiserId, searchType, page + 1, 1);
|
|
|
@@ -330,18 +356,20 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
|
|
|
@Override
|
|
|
public void getByteAppLinkInfo(Long advertiserId) {
|
|
|
- String accessToken = tokenMapper.onlyGetToken(advertiserId);
|
|
|
- if (Check.isNull(accessToken)) {
|
|
|
+ JSONObject authConfig = tokenMapper.getAuthConfig(advertiserId);
|
|
|
+ if (Check.isNull(authConfig)) {
|
|
|
log.error("账户({})查询token失败", advertiserId);
|
|
|
return;
|
|
|
}
|
|
|
+ String accessToken = authConfig.getString("access_token");
|
|
|
+ String devAppId = authConfig.getString("app_id");
|
|
|
List<String> ids = bytedanceCdpProjectMapper.queryAppInstanceIdList(advertiserId);
|
|
|
for (String id : ids) {
|
|
|
- this.getByteAppLinkInfoVo(accessToken, advertiserId, id, 1, 1);
|
|
|
+ this.getByteAppLinkInfoVo(accessToken, devAppId, advertiserId, id, 1, 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void getByteAppLinkInfoVo(String accessToken, Long advertiserId, String instanceId, Integer page, int count) {
|
|
|
+ private void getByteAppLinkInfoVo(String accessToken, String devAppId, Long advertiserId, String instanceId, Integer page, int count) {
|
|
|
try {
|
|
|
boolean nextPage = false;
|
|
|
JSONObject params = new JSONObject();
|
|
|
@@ -353,7 +381,10 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
params.put("filtering", filtering);
|
|
|
//获取微信小程序列表
|
|
|
String url = "https://api.oceanengine.com/open_api/v3.0/tools/asset_link/list/";
|
|
|
- JSONObject obj = Okhttp3Utils.bytedanceGetRequest(accessToken, url, params);
|
|
|
+ JSONObject obj = null;
|
|
|
+ if(rateLimitUtil.acquire(devAppId, url)) {
|
|
|
+ obj = Okhttp3Utils.bytedanceGetRequest(accessToken, url, params);
|
|
|
+ }
|
|
|
if (!Check.isNull(obj)) {
|
|
|
Integer code = obj.getInteger("code");
|
|
|
if (code == 0) {
|
|
|
@@ -374,15 +405,19 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
//40110请求超频 51010 内部服务超时
|
|
|
if ((40110 == code || 51010 == code) && count <= 3) {
|
|
|
Thread.sleep(700);
|
|
|
- getByteAppLinkInfoVo(accessToken, advertiserId, instanceId, page, count + 1);
|
|
|
+ getByteAppLinkInfoVo(accessToken, devAppId, advertiserId, instanceId, page, count + 1);
|
|
|
} else {
|
|
|
bytedanceCdpProjectMapper.insertTTErrorAdvertiserId(advertiserId);
|
|
|
log.error("账户({})获取字节小程序/小游戏详情内容失败,入参:{}\n结果:{}", advertiserId, JSONObject.toJSONString(params), obj);
|
|
|
}
|
|
|
}
|
|
|
+ } else {
|
|
|
+ bytedanceCdpProjectMapper.insertTTErrorAdvertiserId(advertiserId);
|
|
|
+ log.error("账户({})获取字节小程序/小游戏详情内容失败,入参:{}\n结果:{}", advertiserId, JSONObject.toJSONString(params), obj);
|
|
|
+ return;
|
|
|
}
|
|
|
if (nextPage) {
|
|
|
- getByteAppLinkInfoVo(accessToken, advertiserId, instanceId, page + 1, count);
|
|
|
+ getByteAppLinkInfoVo(accessToken, devAppId, advertiserId, instanceId, page + 1, count);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
bytedanceCdpProjectMapper.insertTTErrorAdvertiserId(advertiserId);
|
|
|
@@ -400,11 +435,13 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
private void getWxAppInfoVo(Long advertiserId, String searchType, Integer page, int count) {
|
|
|
try {
|
|
|
boolean nextPage = false;
|
|
|
- String accessToken = tokenMapper.onlyGetToken(advertiserId);
|
|
|
- if (Check.isNull(accessToken)) {
|
|
|
+ JSONObject authConfig = tokenMapper.getAuthConfig(advertiserId);
|
|
|
+ if (Check.isNull(authConfig)) {
|
|
|
log.error("账户({})查询token失败", advertiserId);
|
|
|
return;
|
|
|
}
|
|
|
+ String accessToken = authConfig.getString("access_token");
|
|
|
+ String devAppId = authConfig.getString("app_id");
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("advertiser_id", advertiserId);
|
|
|
params.put("page", page);
|
|
|
@@ -418,7 +455,10 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
params.put("filtering", filtering);
|
|
|
//获取微信小程序列表
|
|
|
String url = "https://api.oceanengine.com/open_api/v3.0/tools/wechat_applet/list/";
|
|
|
- JSONObject obj = Okhttp3Utils.bytedanceGetRequest(accessToken, url, params);
|
|
|
+ JSONObject obj = null;
|
|
|
+ if(rateLimitUtil.acquire(devAppId, url)) {
|
|
|
+ obj = Okhttp3Utils.bytedanceGetRequest(accessToken, url, params);
|
|
|
+ }
|
|
|
if (!Check.isNull(obj)) {
|
|
|
Integer code = obj.getInteger("code");
|
|
|
if (code == 0) {
|
|
|
@@ -455,6 +495,10 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
bytedanceCdpProjectMapper.insertErrorAdvertiserId(advertiserId, "wx");
|
|
|
}
|
|
|
}
|
|
|
+ } else {
|
|
|
+ log.error("账户({})获取微小列表失败,入参:{}\n结果:{}", advertiserId, JSONObject.toJSONString(params), obj);
|
|
|
+ bytedanceCdpProjectMapper.insertErrorAdvertiserId(advertiserId, "wx");
|
|
|
+ return;
|
|
|
}
|
|
|
if (nextPage) {
|
|
|
getWxAppInfoVo(advertiserId, searchType, page + 1, 1);
|