yumeng 3 dni temu
rodzic
commit
8fd45464b2

+ 18 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/controller/BytedanceController.java

@@ -44,6 +44,24 @@ public class BytedanceController {
     @Autowired
     private IBytedanceReportNewService bytedanceReportNewService;
 
+    @GetMapping(value = "/inactive_advertiser")
+    public Map<String, String> inactive_advertiser() {
+
+        String appId = "1635316529903624";
+        String secret = "0c51523e90d6166418fc8421a4896808e90e26f4";
+     //   bytedanceReportNewService.getInactiveAdvertiser(appId, secret);
+        String accountId = "123";
+        boolean b = bytedanceReportNewService.checkInactiveAdvertiser(accountId);
+        if (!b){
+
+        }
+        System.err.println(b);
+
+
+        return null;
+    }
+
+
 
     @PostMapping(value = "/getBytedanceVideoByAccountId")
     public Map<String, String> getBytedanceVideoByAccountId(@RequestBody JSONObject jsonObject) {

+ 4 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/IBytedanceReportNewService.java

@@ -1,6 +1,5 @@
 package cn.com.ctop.job.bytedance.data.service;
 
-import cn.com.ctop.job.bytedance.data.entity.OauthToken;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 
@@ -16,4 +15,8 @@ public interface IBytedanceReportNewService {
     JSONObject getTokenInfo();
 
     List<Long> getAccountIds(Long projectId);
+
+    void getInactiveAdvertiser(String appId, String secret);
+
+    boolean checkInactiveAdvertiser(String accountId);
 }

+ 83 - 5
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/BytedanceReportNewServiceImpl.java

@@ -1,6 +1,5 @@
 package cn.com.ctop.job.bytedance.data.service.impl;
 
-import cn.com.ctop.job.bytedance.data.constant.CtopAdConstant;
 import cn.com.ctop.job.bytedance.data.entity.BytedanceAdvertiserReportDaily;
 import cn.com.ctop.job.bytedance.data.entity.BytedanceAdvertiserReportHourly;
 import cn.com.ctop.job.bytedance.data.mapper.AccountReportNewMapper;
@@ -9,6 +8,7 @@ import cn.com.ctop.job.bytedance.data.utils.Check;
 import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
 import cn.com.ctop.job.bytedance.data.utils.RateLimitUtil;
 import cn.com.ctop.job.bytedance.utils.FieldsConfig;
+import cn.com.ctop.job.bytedance.utils.RedisUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 
 @Slf4j
 @Service
@@ -26,6 +27,9 @@ public class BytedanceReportNewServiceImpl implements IBytedanceReportNewService
     @Autowired
     private RateLimitUtil rateLimitUtil;
 
+    @Autowired
+    private RedisUtil redisUtil;
+
     private String urlPath = "http://192.168.0.85:8765/webhook/bytedance_account_report";
     private static JSONArray metrics = new JSONArray();
 
@@ -51,8 +55,8 @@ public class BytedanceReportNewServiceImpl implements IBytedanceReportNewService
                 s = HttpUtils.httpGet(url, paramsMap, headers);
             }
             JSONObject result = JSONObject.parseObject(s);
-            if(Check.isNull(result)){
-                log.error("获取账户时报报返回结果为空,账户ID:{},返回结果:{}",advertiserId,s);
+            if (Check.isNull(result)) {
+                log.error("获取账户时报报返回结果为空,账户ID:{},返回结果:{}", advertiserId, s);
                 return;
             }
             List<BytedanceAdvertiserReportHourly> hours = new ArrayList<>();
@@ -155,8 +159,8 @@ public class BytedanceReportNewServiceImpl implements IBytedanceReportNewService
                 s = HttpUtils.httpGet(url, paramsMap, headers);
             }
             JSONObject result = JSONObject.parseObject(s);
-            if(Check.isNull(result)){
-                log.error("获取账户日报返回结果为空,账户ID:{},返回结果:{}",advertiserId,s);
+            if (Check.isNull(result)) {
+                log.error("获取账户日报返回结果为空,账户ID:{},返回结果:{}", advertiserId, s);
                 return;
             }
 
@@ -290,4 +294,78 @@ public class BytedanceReportNewServiceImpl implements IBytedanceReportNewService
     public List<Long> getAccountIds(Long projectId) {
         return accountReportNewMapper.getAccountIds(projectId);
     }
+
+    @Override
+    public void getInactiveAdvertiser(String appId, String secret) {
+        String url = "https://open.oceanengine.com/open_api/oauth2/app_access_token/";
+        Map<String, Object> paramsMap = new HashMap<>();
+        paramsMap.put("app_id", Long.valueOf(appId));
+        paramsMap.put("secret", secret);
+
+        String s = HttpUtils.httpPostRequest(url, paramsMap, null);
+        JSONObject jsonObject = JSONObject.parseObject(s);
+        if (!Check.isNull(jsonObject)) {
+            Integer code = jsonObject.getInteger("code");
+            if (code == 0) {
+                JSONObject data = jsonObject.getJSONObject("data");
+                if (!Check.isNull(data)) {
+                    String accessToken = data.getString("access_token");
+                    if (!Check.isNull(accessToken)) {
+                        this.getInactiveAdvertiserByToken(appId, accessToken, null);
+                    }
+                }
+            }
+        }
+
+    }
+
+    @Override
+    public boolean checkInactiveAdvertiser(String accountId) {
+        String redisKey = "inactive_advertiser:" + accountId;
+        String s = redisUtil.get(redisKey);
+        return Check.isNull(s);
+    }
+
+    private void getInactiveAdvertiserByToken(String appId, String accessToken, Long cursor) {
+        String url = "https://api.oceanengine.com/open_api/v3.0/tools/inactive_advertiser/list/";
+        JSONObject paramsMap = new JSONObject();
+        paramsMap.put("app_id", Long.valueOf(appId));
+        paramsMap.put("advertiser_type", "30_DAY_NO_COST");
+        if (!Check.isNull(cursor)) {
+            paramsMap.put("cursor", cursor);
+        }
+        Map<String, String> headers = new HashMap<>();
+        headers.put("App-Access-Token", accessToken);
+        String s = HttpUtils.httpGet(url, paramsMap, headers);
+        JSONObject jsonObject = JSONObject.parseObject(s);
+        cursor = null;
+        boolean hasMore = false;
+        if (!Check.isNull(jsonObject)) {
+            Integer code = jsonObject.getInteger("code");
+            if (code == 0) {
+                JSONObject data = jsonObject.getJSONObject("data");
+                if (!Check.isNull(data)) {
+                    hasMore = data.getBoolean("has_more");
+                    if (hasMore) {
+                        cursor = data.getLong("cursor");
+                    }
+                    JSONArray list = data.getJSONArray("list");
+                    log.info("获取非活跃账户列表ing.....,数据长度:{}", list.size());
+                    if (!Check.isNull(list)) {
+                        for (int i = 0; i < list.size(); i++) {
+                            JSONObject advertiser = list.getJSONObject(i);
+                            Long advertiserId = advertiser.getLong("advertiser_id");
+                            String redisKey = "inactive_advertiser:" + advertiserId;
+                            redisUtil.add(redisKey, advertiserId, 24, TimeUnit.HOURS);
+                        }
+                    }
+
+                }
+            }
+        }
+        if (hasMore) {
+            getInactiveAdvertiserByToken(appId, accessToken, cursor);
+        }
+
+    }
 }

+ 32 - 4
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedanceAdvertiseLoadJob.java

@@ -40,6 +40,8 @@ public class BytedanceAdvertiseLoadJob {
     @Autowired
     private IByteDanceAdvertiserDataService advertiserDataService;
 
+    @Autowired
+    private IBytedanceReportNewService bytedanceReportNewService;
 
     @Autowired
     private RedisUtil redisUtil;
@@ -47,7 +49,8 @@ public class BytedanceAdvertiseLoadJob {
 
     @XxlJob("tengxunBytedanceV3PromotionProjectReport")
     public void tengxunBytedanceV3PromotionProjectReport() throws Exception {
-        log.error("腾讯视频获取广告日报开始....");
+        return;
+        /*log.error("腾讯视频获取广告日报开始....");
         List<JSONObject> tokens = tokenService.getTengxunToken();
         if (Check.isNull(tokens)) {
             log.error("此账户未获取到相关token");
@@ -72,7 +75,7 @@ public class BytedanceAdvertiseLoadJob {
                     });
         }
 
-
+*/
     }
 
 
@@ -178,8 +181,6 @@ public class BytedanceAdvertiseLoadJob {
      * @throws Exception
      */
 
-    @Autowired
-    private IBytedanceReportNewService bytedanceReportNewService;
 
     @XxlJob("bytedanceAdvertiserHourlyReport")
     public void bytedanceAdvertiserHourlyReport() throws Exception {
@@ -188,6 +189,13 @@ public class BytedanceAdvertiseLoadJob {
             log.error("入参为空");
             return;
         }
+        boolean b = bytedanceReportNewService.checkInactiveAdvertiser(param);
+        if (!b) {
+            log.error("此账户为非活跃账户,accountId:{}", param);
+            return;
+        }
+
+
         String token = tokenService.getByAccountId(Long.valueOf(param));
         if (Check.isNull(token)) {
             log.error("此账户未获取到相关token,accountId:{}", param);
@@ -229,6 +237,11 @@ public class BytedanceAdvertiseLoadJob {
             log.error("入参为空");
             return;
         }
+        boolean b = bytedanceReportNewService.checkInactiveAdvertiser(param);
+        if (!b) {
+            log.error("此账户为非活跃账户,accountId:{}", param);
+            return;
+        }
         String token = tokenService.getByAccountId(Long.valueOf(param));
         if (Check.isNull(token)) {
             log.error("此账户未获取到相关token,accountId:{}", param);
@@ -294,6 +307,13 @@ public class BytedanceAdvertiseLoadJob {
             log.error("入参为空");
             return;
         }
+        boolean b = bytedanceReportNewService.checkInactiveAdvertiser(param);
+        if (!b) {
+            log.error("此账户为非活跃账户,accountId:{}", param);
+            return;
+        }
+
+
         String token = tokenService.getByAccountId(Long.valueOf(param));
         if (Check.isNull(token)) {
             log.error("此账户未获取到相关token,accountId:{}", param);
@@ -315,6 +335,14 @@ public class BytedanceAdvertiseLoadJob {
                 });
     }
 
+
+    @XxlJob("getInactiveAdvertiser")
+    public void getInactiveAdvertiser() throws Exception {
+        String appId = "1635316529903624";
+        String secret = "0c51523e90d6166418fc8421a4896808e90e26f4";
+        bytedanceReportNewService.getInactiveAdvertiser(appId, secret);
+    }
+
     /**
      * 广告时报
      *

+ 28 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedanceFileGetLoadJob.java

@@ -3,6 +3,7 @@ package cn.com.ctop.job.bytedance.handler;
 import cn.com.ctop.job.bytedance.data.entity.OauthToken;
 import cn.com.ctop.job.bytedance.data.service.IBytedanceFileImageGetService;
 import cn.com.ctop.job.bytedance.data.service.IBytedanceFileVideoGetService;
+import cn.com.ctop.job.bytedance.data.service.IBytedanceReportNewService;
 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;
@@ -33,7 +34,8 @@ public class BytedanceFileGetLoadJob {
 
     @Autowired
     private IBytedanceFileVideoGetService fileVideoService;
-
+    @Autowired
+    private IBytedanceReportNewService bytedanceReportNewService;
     /**
      * 获取头条图片素材
      *
@@ -46,6 +48,11 @@ public class BytedanceFileGetLoadJob {
             log.error("入参为空");
             return;
         }
+        boolean b = bytedanceReportNewService.checkInactiveAdvertiser(param);
+        if (!b){
+            log.error("此账户为非活跃账户,accountId:{}", param);
+            return;
+        }
         String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
         String yesterda = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
         String yesterda2 = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -2);
@@ -74,6 +81,11 @@ public class BytedanceFileGetLoadJob {
             log.error("入参为空");
             return;
         }
+        boolean b = bytedanceReportNewService.checkInactiveAdvertiser(param);
+        if (!b){
+            log.error("此账户为非活跃账户,accountId:{}", param);
+            return;
+        }
         String token = tokenService.getByAccountId(Long.valueOf(param));
         String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
         String yesterda = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
@@ -102,6 +114,12 @@ public class BytedanceFileGetLoadJob {
             log.error("入参为空");
             return;
         }
+        boolean b = bytedanceReportNewService.checkInactiveAdvertiser(param);
+        if (!b){
+            log.error("此账户为非活跃账户,accountId:{}", param);
+            return;
+        }
+
         String token = tokenService.getByAccountId(Long.valueOf(param));
         OauthToken oauthToken = new OauthToken();
         oauthToken.setAccessToken(token);
@@ -121,6 +139,15 @@ public class BytedanceFileGetLoadJob {
             log.error("入参为空");
             return;
         }
+
+
+        boolean b = bytedanceReportNewService.checkInactiveAdvertiser(param);
+        if (!b){
+            log.error("此账户为非活跃账户,accountId:{}", param);
+            return;
+        }
+
+
         String token = tokenService.getByAccountId(Long.valueOf(param));
         String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
 //        String yesterda = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);

+ 8 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedanceMaterialReportLoadJob.java

@@ -4,6 +4,7 @@ import cn.com.ctop.job.bytedance.data.constant.CtopAdConstant;
 import cn.com.ctop.job.bytedance.data.entity.OauthToken;
 import cn.com.ctop.job.bytedance.data.service.IByteDanceAdvertiserDataService;
 import cn.com.ctop.job.bytedance.data.service.IBytedanceMaterialReportDailyService;
+import cn.com.ctop.job.bytedance.data.service.IBytedanceReportNewService;
 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;
@@ -30,7 +31,8 @@ public class BytedanceMaterialReportLoadJob {
     private static ExecutorService dailyExecutorService = Executors.newFixedThreadPool(3);
     @Autowired
     private IBytedanceMaterialReportDailyService materialReportDailyService;
-
+    @Autowired
+    private IBytedanceReportNewService bytedanceReportNewService;
 
     /**
      * 获取头条图片素材
@@ -84,6 +86,11 @@ public class BytedanceMaterialReportLoadJob {
             log.error("入参为空");
             return;
         }
+        boolean b = bytedanceReportNewService.checkInactiveAdvertiser(param);
+        if (!b){
+            log.error("此账户为非活跃账户,accountId:{}", param);
+            return;
+        }
 
         String token = tokenService.getByAccountId(Long.valueOf(param));
         if (Check.isNull(token)) {

+ 8 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedanceProjectJob.java

@@ -2,6 +2,7 @@ package cn.com.ctop.job.bytedance.handler;
 
 import cn.com.ctop.job.bytedance.data.entity.OauthToken;
 import cn.com.ctop.job.bytedance.data.service.IBytedanceProjectService;
+import cn.com.ctop.job.bytedance.data.service.IBytedanceReportNewService;
 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;
@@ -25,7 +26,8 @@ public class BytedanceProjectJob {
 
     private static ExecutorService dailyExecutorService = Executors.newFixedThreadPool(3);
     private static ExecutorService ocpxActionTypeExecutorService = Executors.newFixedThreadPool(5);
-
+    @Autowired
+    private IBytedanceReportNewService bytedanceReportNewService;
 
     @Autowired
     private IBytedanceProjectService projectService;
@@ -41,6 +43,11 @@ public class BytedanceProjectJob {
             log.error("入参为空");
             return;
         }
+        boolean b = bytedanceReportNewService.checkInactiveAdvertiser(param);
+        if (!b){
+            log.error("此账户为非活跃账户,accountId:{}", param);
+            return;
+        }
         String token = tokenService.getByAccountId(Long.valueOf(param));
         if (Check.isNull(token)) {
             log.error("此账户未获取到相关token,accountId:{}", param);

+ 15 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedancePromotionJob.java

@@ -2,6 +2,7 @@ package cn.com.ctop.job.bytedance.handler;
 
 import cn.com.ctop.job.bytedance.data.entity.OauthToken;
 import cn.com.ctop.job.bytedance.data.service.IBytedancePromotionListService;
+import cn.com.ctop.job.bytedance.data.service.IBytedanceReportNewService;
 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;
@@ -31,7 +32,8 @@ public class BytedancePromotionJob {
 
     private static ExecutorService dailyExecutorService = Executors.newFixedThreadPool(3);
 
-
+    @Autowired
+    private IBytedanceReportNewService bytedanceReportNewService;
     @Autowired
     private IBytedancePromotionListService promotionListService;
 
@@ -48,6 +50,11 @@ public class BytedancePromotionJob {
             log.error("入参为空");
             return;
         }
+        boolean b = bytedanceReportNewService.checkInactiveAdvertiser(param);
+        if (!b){
+            log.error("此账户为非活跃账户,accountId:{}", param);
+            return;
+        }
         String token = tokenService.getByAccountId(Long.valueOf(param));
         if (Check.isNull(token)) {
             log.error("此账户未获取到相关token,accountId:{}", param);
@@ -79,6 +86,13 @@ public class BytedancePromotionJob {
             log.error("入参为空");
             return;
         }
+        boolean b = bytedanceReportNewService.checkInactiveAdvertiser(param);
+        if (!b){
+            log.error("此账户为非活跃账户,accountId:{}", param);
+            return;
+        }
+
+
         String token = tokenService.getByAccountId(Long.valueOf(param));
         if (Check.isNull(token)) {
             log.error("此账户未获取到相关token,accountId:{}", param);