|
|
@@ -8,10 +8,12 @@ import cn.com.ctop.job.bytedance.data.utils.AlertUtils;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.FieldsConfig;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
|
+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;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.redisson.api.RateIntervalUnit;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -33,6 +35,8 @@ public class BytedanceMaterialReportServiceImpl implements IBytedanceMaterialRep
|
|
|
private BytedanceRefreshTokenMapper tokenMapper;
|
|
|
@Autowired
|
|
|
private RedisTemplate redisTemplate_db2;
|
|
|
+ @Autowired
|
|
|
+ private RateLimitUtil rateLimitUtil;
|
|
|
|
|
|
@Override
|
|
|
public void getBytedanceMaterialDailyReport(Long advertiserId, String accessToken, String startDate, String endDate, Integer page, Long errorId, Integer isLog, Integer isSend, int retry) {
|
|
|
@@ -120,7 +124,7 @@ public class BytedanceMaterialReportServiceImpl implements IBytedanceMaterialRep
|
|
|
}
|
|
|
|
|
|
if (!Check.isNull(materialIds)) {
|
|
|
- getBytedanceMaterialVideo(advertiserId, materialIds, accessToken, null, null, 1, null, 1, null, 1);
|
|
|
+ getBytedanceMaterialVideo(advertiserId, materialIds, null, null, 1, null, 1, null, 1);
|
|
|
}
|
|
|
|
|
|
if (page < totalPage) {
|
|
|
@@ -140,9 +144,15 @@ public class BytedanceMaterialReportServiceImpl implements IBytedanceMaterialRep
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void getBytedanceMaterialVideo(Long advertiserId, Set<Long> materialIds, String accessToken, String startTime, String endTime, Integer page, Long errorId, Integer isLog, Integer isSend, int retry) {
|
|
|
+ public void getBytedanceMaterialVideo(Long advertiserId, Set<Long> materialIds, String startTime, String endTime, Integer page, Long errorId, Integer isLog, Integer isSend, int retry) {
|
|
|
try {
|
|
|
- accessToken = tokenMapper.onlyGetToken(advertiserId);
|
|
|
+ JSONObject authConfig = tokenMapper.getAuthConfig(advertiserId);
|
|
|
+ if (Check.isNull(authConfig) || authConfig.getString("access_token") == null) {
|
|
|
+ log.info("账户id:{},获取视频素材token为空", advertiserId);
|
|
|
+ }
|
|
|
+ String accessToken = authConfig.getString("access_token");
|
|
|
+ String devAppId = authConfig.getString("app_id");
|
|
|
+
|
|
|
String url = "https://api.oceanengine.com/open_api/2/file/video/get/";
|
|
|
Map<String, Object> paramsMap = new HashMap<>();
|
|
|
paramsMap.put("advertiser_id", advertiserId);
|
|
|
@@ -160,7 +170,10 @@ public class BytedanceMaterialReportServiceImpl implements IBytedanceMaterialRep
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
|
headers.put("Access-Token", accessToken);
|
|
|
headers.put("Content-Type", "application/json");
|
|
|
- String s = HttpUtils.httpGet(url, paramsMap, headers);
|
|
|
+ String s = null;
|
|
|
+ if (rateLimitUtil.acquire(devAppId, url, 10, 1, RateIntervalUnit.SECONDS)) {
|
|
|
+ s = HttpUtils.httpGet(url, paramsMap, headers);
|
|
|
+ }
|
|
|
JSONObject result = JSONObject.parseObject(s);
|
|
|
if (Check.isNull(result)) {
|
|
|
log.info("账户id:{},获取视频素材结果返回为空", advertiserId);
|
|
|
@@ -199,7 +212,7 @@ public class BytedanceMaterialReportServiceImpl implements IBytedanceMaterialRep
|
|
|
Thread.sleep(800);
|
|
|
} catch (Exception ignored) {
|
|
|
}
|
|
|
- getBytedanceMaterialVideo(advertiserId, materialIds, accessToken, startTime, endTime, page, errorId, isLog, isSend, retry + 1);
|
|
|
+ getBytedanceMaterialVideo(advertiserId, materialIds, startTime, endTime, page, errorId, isLog, isSend, retry + 1);
|
|
|
return;
|
|
|
}
|
|
|
log.info("账户id:{},日期:{}获取视频素材失败,返回数据:{}", advertiserId, startTime, result);
|
|
|
@@ -216,7 +229,7 @@ public class BytedanceMaterialReportServiceImpl implements IBytedanceMaterialRep
|
|
|
return;
|
|
|
}
|
|
|
if (page < totalPage) {
|
|
|
- getBytedanceMaterialVideo(advertiserId, materialIds, accessToken, startTime, endTime, page + 1, errorId, isLog, isSend, 1);
|
|
|
+ getBytedanceMaterialVideo(advertiserId, materialIds, startTime, endTime, page + 1, errorId, isLog, isSend, 1);
|
|
|
} else {
|
|
|
log.info("账户ID:{}, 开始日期:{}, 结束日期:{}, totalPage:{}, 获取视频素材成功", advertiserId, startTime, endTime, totalPage);
|
|
|
if (errorId != null) {
|