Selaa lähdekoodia

广告主日报-遗漏数据补充

yangzian 3 vuotta sitten
vanhempi
commit
4724939b29

+ 24 - 2
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/ByteDanceAdvertiserDataServiceImpl.java

@@ -351,7 +351,10 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
      */
     private void getAdvertiserReportByPage(
             OauthToken token, ByteDanceAdvertiserReportDTO conditions, Integer page) {
-        log.info("获取账户报表,账户id:{}", token.getAccountId());
+
+        List<Object> advertiserAccountList = redisUtil.getList("ADVERTISER"+conditions.getStartDate(),null);
+
+        log.info("开始获取广告主账户报表,账户id:{}--时间---{},page:{}", token.getAccountId(),conditions.getStartDate(),page);
         conditions.setPage(page);
         SerializeConfig config = new SerializeConfig();
         config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
@@ -359,12 +362,31 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         JSONObject getObject = getAdvertiserStat(token, jsonObject);
         if (null == getObject) {
             XxlJobHelper.log("头条广告主数据获取异常");
+            log.error("头条广告主数据获取信息为空==》accountId:{}",token.getAccountId());
             return;
         }
         Integer code = getObject.getInteger("code");
         String message = getObject.getString("message");
         if (null == code || code != 0) {
-            log.error("头条广告主数据获取异常:{}", message);
+            log.error("头条广告主数据获取异常:{}---code--{}", message,code);
+
+            //请求过于频繁
+            if (40100 == code){
+                log.info("广告主日报请求频繁,code:{},准备重试,accountId:{},错误消息:{}",code,token.getAccountId(),message);
+                //添加重试
+                if (Check.isNull(advertiserAccountList)){
+                    redisUtil.add("ADVERTISER"+conditions.getStartDate(),Arrays.asList(token.getAccountId()), 1, TimeUnit.HOURS);
+                }else {
+                    advertiserAccountList.add(token.getAccountId());
+                    redisUtil.add("ADVERTISER"+conditions.getStartDate(),advertiserAccountList, 1, TimeUnit.HOURS);
+                }
+            }else {
+                if (advertiserAccountList.contains(token.getAccountId())){
+                    advertiserAccountList.remove(token.getAccountId());
+                    redisUtil.add("ADVERTISER"+conditions.getStartDate(),advertiserAccountList, 1, TimeUnit.HOURS);
+                }
+            }
+
             return;
         }
         JSONArray dataArray = getObject.getJSONObject("data").getJSONArray("list");

+ 75 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedanceAdvertiseLoadJob.java

@@ -6,6 +6,7 @@ import cn.com.ctop.job.bytedance.data.service.IByteDanceAdvertiserDataService;
 import cn.com.ctop.job.bytedance.data.service.IOauthTokenService;
 import cn.com.ctop.job.bytedance.data.utils.Check;
 import cn.com.ctop.job.bytedance.data.utils.DateUtils;
+import cn.com.ctop.job.bytedance.utils.RedisUtil;
 import com.xxl.job.core.context.XxlJobHelper;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import lombok.extern.slf4j.Slf4j;
@@ -13,7 +14,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
+import java.util.Set;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -34,6 +38,77 @@ public class BytedanceAdvertiseLoadJob {
     private IByteDanceAdvertiserDataService advertiserDataService;
 
 
+
+
+
+    @Autowired
+    private RedisUtil redisUtil;
+
+    /**
+     * 获取广告主日报-遗漏数据补充
+     *
+     * @throws Exception
+     */
+    @XxlJob("bytedanceAdvertiserDailyReportSupplement")
+    public void bytedanceAdvertiserDailyReportSupplement() throws Exception {
+
+        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+
+        //获取广告主信息异常的key
+        Set<String> set = redisUtil.kesy("ADVERTISER*");
+        if (Check.isNull(set)){
+            return;
+        }
+
+        List<String> list = new ArrayList<>(set);
+
+        for (String key : list) {
+
+            //添加重试
+            List<Object> adAccountList;
+            adAccountList = redisUtil.getList(key,null);
+            //遍历key下的所有信息
+            for (Object accountId : adAccountList) {
+
+                log.info("广告主遗漏数据补充,日期:{},accountId:{}",key,adAccountList.toString());
+                String token = tokenService.getByAccountId(Long.valueOf(String.valueOf(accountId)));
+                if (Check.isNull(token)) {
+                    log.error("此账户未获取到相关token,accountId:{}", accountId);
+                    return;
+                }
+
+                OauthToken oauthToken = new OauthToken();
+                oauthToken.setAccessToken(token);
+                oauthToken.setAccountId(Long.valueOf(String.valueOf(accountId)));
+
+                advertiserDataService.getAdvertiserReport(oauthToken, key.replaceAll("ADVERTISER",""), key.replaceAll("ADVERTISER",""), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+
+                adAccountList = redisUtil.getList(key,null);
+
+                if (adAccountList.size() == 0){
+                    redisUtil.delete(key);
+                }
+
+                try {
+                    Thread.sleep(1000*2);
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
+
+            }
+
+        }
+
+
+
+
+    }
+
+
+
+
+
+
     /**
      * 广告主日报
      *