|
@@ -7,15 +7,19 @@ import cn.com.ctop.job.bytedance.data.mapper.BytedanceCampaignGetMapper;
|
|
|
import cn.com.ctop.job.bytedance.data.service.IBytedanceCampaignGetService;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
|
+import cn.com.ctop.job.bytedance.utils.RedisUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* 获取定向包
|
|
@@ -32,15 +36,24 @@ public class BytedanceCampaignGetServiceImpl implements IBytedanceCampaignGetSer
|
|
|
@Resource
|
|
|
BytedanceCampaignGetMapper bytedanceCampaignGetMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public void getCampaignData(OauthToken oauthToken, String startDate, String endDate, int pageNumber, int pageSize) {
|
|
|
log.info("开始获取广告组全量数据 accountIDL{},page:{}", oauthToken.getAccountId(), pageNumber);
|
|
|
+ List<Object> campAccountList = redisUtil.getList("CAMP"+startDate,null);
|
|
|
+
|
|
|
// 请求地址
|
|
|
String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V2_CAMPAIGN_GET;
|
|
|
JSONObject param = new JSONObject();
|
|
|
param.put("advertiser_id", oauthToken.getAccountId());
|
|
|
param.put("page", pageNumber);
|
|
|
param.put("page_size", pageSize);
|
|
|
+ JSONObject param2 = new JSONObject();
|
|
|
+ param2.put("campaign_create_time", startDate);
|
|
|
+ param.put("filtering", param2);
|
|
|
|
|
|
|
|
|
JSONObject resultObject = HttpUtils.bytedanceGetRequest(oauthToken.getAccessToken(), url, param);
|
|
@@ -52,9 +65,25 @@ public class BytedanceCampaignGetServiceImpl implements IBytedanceCampaignGetSer
|
|
|
Integer code = resultObject.getInteger("code");
|
|
|
if (null == code || !code.equals(0)) {
|
|
|
log.error("获取广告组接口异常==》accountId:{},message:{}", oauthToken.getAccountId(), resultObject.getString("message"));
|
|
|
+
|
|
|
+ //请求过于频繁
|
|
|
+ if (40100 == code){
|
|
|
+ log.info("广告组请求频繁,code:{},准备重试,accountId:{},错误消息:{}",code,oauthToken.getAccountId(),resultObject.getString("message"));
|
|
|
+ //添加重试
|
|
|
+ if (Check.isNull(campAccountList)){
|
|
|
+ redisUtil.add("CAMP"+startDate, Arrays.asList(oauthToken.getAccountId()), 1, TimeUnit.HOURS);
|
|
|
+ }else {
|
|
|
+ campAccountList.add(oauthToken.getAccountId());
|
|
|
+ redisUtil.add("CAMP"+startDate,campAccountList, 1, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
JSONArray data = resultObject.getJSONObject("data").getJSONArray("list");
|
|
|
+ if (campAccountList.contains(oauthToken.getAccountId())){
|
|
|
+ campAccountList.remove(oauthToken.getAccountId());
|
|
|
+ redisUtil.add("CAMP"+startDate,campAccountList, 1, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
if (null == data || data.isEmpty()) {
|
|
|
return;
|
|
|
}
|