Procházet zdrojové kódy

代理商数据获取

yumeng před 1 rokem
rodič
revize
d51b42bb0a

+ 19 - 17
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/controller/BytedanceController.java

@@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.ExecutorService;
@@ -31,7 +32,7 @@ public class BytedanceController {
     @Autowired
     private IBytedanceProductReportService productReportService;
 
-    private static final ExecutorService dailyRetrExecutorService = Executors.newFixedThreadPool(5);
+    private static final ExecutorService dailyRetrExecutorService = Executors.newFixedThreadPool(3);
 
     @Autowired
     private IAdminAdvertiserListService adminAdvertiserListService;
@@ -57,27 +58,28 @@ public class BytedanceController {
 
     @GetMapping("/agentData")
     public void agentData() {
-        List<JSONObject> adminAdvertiserList = adminAdvertiserListService.getAdminAdvertiserList();
+        List<JSONObject> adminAdvertiserList = adminAdvertiserListService.getNotAgentAdvertiserList();
+
         for (JSONObject adminAdvertiserJson : adminAdvertiserList) {
             Long adminAdvertiserId = adminAdvertiserJson.getLong("adminAdvertiserId");
             String accessToken = adminAdvertiserJson.getString("accessToken");
-            List<Long> infos = adminAdvertiserListService.getAgentAdvertiserList(adminAdvertiserId);
-            if (Check.isNull(infos)) {
-                log.info("没有需要获取代理商信息的账户id,adminAdvertiserId:{}", adminAdvertiserId);
-                continue;
-            }
-            List<List<Long>> advertiserList = Lists.partition(infos, 50);
-            for (List<Long> longs : advertiserList) {
-                dailyRetrExecutorService.submit(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (!Check.isNull(accessToken)) {
-                            adminAdvertiserListService.getAgentInfo(adminAdvertiserId, accessToken, longs);
-
+            Long advertiserId = adminAdvertiserJson.getLong("advertiserId");
+            List<Long> ids = new ArrayList<>();
+            ids.add(advertiserId);
+            dailyRetrExecutorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    if (!Check.isNull(accessToken)) {
+                        try {
+                            adminAdvertiserListService.getAgentInfo(adminAdvertiserId, accessToken, ids);
+                        } catch (InterruptedException e) {
+                            throw new RuntimeException(e);
                         }
+
                     }
-                });
-            }
+                }
+            });
+
         }
     }
 

+ 2 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/AdminAdvertiserListMapper.java

@@ -23,4 +23,6 @@ public interface AdminAdvertiserListMapper {
     List<JSONObject> getAdminAdvertiserList();
 
     void addAgentList(@Param("adds") List<BytedanceAgentAdvertiserList> adds);
+
+    List<JSONObject> getNotAgentAdvertiserList();
 }

+ 8 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/xml/AdminAdvertiserListMapper.xml

@@ -114,4 +114,12 @@
         from deepthink.bytedance_auth_list
         group by admin_advertiser_id
     </select>
+    <select id="getNotAgentAdvertiserList" resultType="com.alibaba.fastjson.JSONObject">
+        select t1.advertiser_id as 'advertiserId', t1.admin_advertiser_id as 'adminAdvertiserId', t3.access_token as 'accessToken'
+        from deepthink.bytedance_advertiser_list t1
+                 left join deepthink.bytedance_agent_advertiser_list t2
+                           on t1.advertiser_id = t2.advertiser_id
+                 left join deepthink.bytedance_auth_list t3 on t1.admin_advertiser_id = t3.admin_advertiser_id
+        where t2.advertiser_id is null
+    </select>
 </mapper>

+ 3 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/IAdminAdvertiserListService.java

@@ -19,5 +19,7 @@ public interface IAdminAdvertiserListService {
 
     List<JSONObject> getAdminAdvertiserList();
 
-    void getAgentInfo(Long adminAdvertiserId, String accessToken, List<Long> longs);
+    void getAgentInfo(Long adminAdvertiserId, String accessToken, List<Long> longs) throws InterruptedException;
+
+    List<JSONObject> getNotAgentAdvertiserList();
 }

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

@@ -130,8 +130,8 @@ public class AdminAdvertiserListServiceImpl implements IAdminAdvertiserListServi
     }
 
     @Override
-    public void getAgentInfo(Long adminAdvertiserId, String accessToken, List<Long> longs) {
-
+    public void getAgentInfo(Long adminAdvertiserId, String accessToken, List<Long> longs) throws InterruptedException {
+        Thread.sleep(1000L);
         String url = "https://api.oceanengine.com/open_api/2/agent/advertiser_info/query/";
         Map<String, Object> paramsMap = new HashMap<>();
         paramsMap.put("account_ids", longs);
@@ -141,6 +141,7 @@ public class AdminAdvertiserListServiceImpl implements IAdminAdvertiserListServi
 
         String s = HttpUtils.httpGet(url, paramsMap, headers);
         JSONObject jsonObject = JSONObject.parseObject(s);
+
         List<BytedanceAgentAdvertiserList> adds = new ArrayList<>();
         if (!Check.isNull(jsonObject)) {
             Integer code = jsonObject.getInteger("code");
@@ -158,6 +159,8 @@ public class AdminAdvertiserListServiceImpl implements IAdminAdvertiserListServi
 
                     }
                 }
+            } else {
+                log.error("获取代理商接口失败,account_ids:{},返回信息:{}", longs, jsonObject);
             }
 
         }
@@ -168,6 +171,11 @@ public class AdminAdvertiserListServiceImpl implements IAdminAdvertiserListServi
 
     }
 
+    @Override
+    public List<JSONObject> getNotAgentAdvertiserList() {
+        return adminAdvertiserListMapper.getNotAgentAdvertiserList();
+    }
+
     // 分页结果包装类
     static class PageResult {
         private final int pageNumber;

+ 20 - 17
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/AdminAdvertiserListJob.java

@@ -3,6 +3,7 @@ package cn.com.ctop.job.bytedance.handler;
 
 import cn.com.ctop.job.bytedance.data.service.IAdminAdvertiserListService;
 import cn.com.ctop.job.bytedance.data.utils.Check;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
 import com.xxl.job.core.context.XxlJobHelper;
@@ -12,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.web.bind.annotation.GetMapping;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -28,32 +30,33 @@ public class AdminAdvertiserListJob {
     @Autowired
     private IAdminAdvertiserListService adminAdvertiserListService;
     private static ExecutorService adminService = Executors.newFixedThreadPool(2);
-    private static ExecutorService agentExecutorService = Executors.newFixedThreadPool(5);
+    private static ExecutorService agentExecutorService = Executors.newFixedThreadPool(3);
 
 
     @XxlJob("agentData")
     public void agentData() {
-        List<JSONObject> adminAdvertiserList = adminAdvertiserListService.getAdminAdvertiserList();
+        List<JSONObject> adminAdvertiserList = adminAdvertiserListService.getNotAgentAdvertiserList();
+
         for (JSONObject adminAdvertiserJson : adminAdvertiserList) {
             Long adminAdvertiserId = adminAdvertiserJson.getLong("adminAdvertiserId");
             String accessToken = adminAdvertiserJson.getString("accessToken");
-            List<Long> infos = adminAdvertiserListService.getAgentAdvertiserList(adminAdvertiserId);
-            if (Check.isNull(infos)) {
-                log.info("没有需要获取代理商信息的账户id,adminAdvertiserId:{}", adminAdvertiserId);
-                continue;
-            }
-            List<List<Long>> advertiserList = Lists.partition(infos, 50);
-            for (List<Long> longs : advertiserList) {
-                agentExecutorService.submit(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (!Check.isNull(accessToken)) {
-                            adminAdvertiserListService.getAgentInfo(adminAdvertiserId, accessToken, longs);
-
+            Long advertiserId = adminAdvertiserJson.getLong("advertiserId");
+            List<Long> ids = new ArrayList<>();
+            ids.add(advertiserId);
+            agentExecutorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    if (!Check.isNull(accessToken)) {
+                        try {
+                            adminAdvertiserListService.getAgentInfo(adminAdvertiserId, accessToken, ids);
+                        } catch (InterruptedException e) {
+                            throw new RuntimeException(e);
                         }
+
                     }
-                });
-            }
+                }
+            });
+
         }
     }