ZHAOXIAN 1 год назад
Родитель
Сommit
f54179bd31

+ 7 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/controller/BytedanceController.java

@@ -136,5 +136,11 @@ public class BytedanceController {
 
         });
     }
+    @Autowired
+    IBytedanceCdpProjectService bytedanceCdpProjectService;
+    @GetMapping("/testB")
+    public void testB(Long id) {
+        bytedanceCdpProjectService.getByteAppLinkInfo(id);
+    }
 
-}
+}

+ 11 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/BytedanceCdpProjectMapper.java

@@ -2,6 +2,7 @@ package cn.com.ctop.job.bytedance.data.mapper;
 
 import cn.com.ctop.job.bytedance.data.entity.BytedanceCdpProject;
 import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -22,12 +23,18 @@ public interface BytedanceCdpProjectMapper {
 
     List<Long> queryErrApps(@Param("type") String type);
 
+    List<Long> queryTTErrApps();
+
     boolean delErrApps(@Param("type") String type);
 
+    boolean delTTErrApps();
+
     List<Long> queryAdvertiserIds(@Param("db") String db, @Param("date") String date);
 
     int replaceBytedanceByteAppInfo(@Param("list") JSONArray list, @Param("advertiserId") Long advertiserId);
 
+    int replaceBytedanceByteAppLinkInfo(@Param("list") JSONArray list);
+
     int replaceBytedanceWxAppInfo(@Param("list") JSONArray list, @Param("advertiserId") Long advertiserId);
 
     List<Long> queryMediaAdverIds(@Param("date") String date, @Param("mediaType") String mediaType);
@@ -36,4 +43,8 @@ public interface BytedanceCdpProjectMapper {
 
     List<Long> queryADQAdverIds(String date);
 
+    List<String> queryAppInstanceIdList(@Param("advertiserId") Long advertiserId);
+
+    void insertTTErrorAdvertiserId(Long advertiserId);
+
 }

+ 54 - 2
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/xml/BytedanceCdpProjectListMapper.xml

@@ -86,6 +86,34 @@
     </insert>
 
 
+    <insert id="replaceBytedanceByteAppLinkInfo">
+        replace into media_api.bytedance_tools_asset_link_list (
+        advertiser_id,
+        link_id,
+        instance_id,
+        app_id,
+        link,
+        link_remark,
+        start_page,
+        start_param
+        )
+        values
+        <foreach collection="list" item="item" separator=",">
+            (
+            #{item.advertiser_id},
+            #{item.link_id},
+            #{item.instance_id},
+            #{item.app_id},
+            #{item.link},
+            #{item.link_remark},
+            #{item.start_page},
+            #{item.start_param}
+
+            )
+        </foreach>
+    </insert>
+
+
     <insert id="replaceBytedanceWxAppInfo">
         replace into media_api.bytedance_wx_app_info (
         advertiser_id,
@@ -115,10 +143,17 @@
         )
     </insert>
 
+    <insert id="insertTTErrorAdvertiserId">
+        replace
+        into media_api.error_advertiser_tt (advertiser_id)
+        values(
+        #{advertiserId}
+        )
+    </insert>
+
     <select id="queryAllAdverIdList" resultType="Long">
         SELECT DISTINCT advertiser_id
-        FROM media_api.bytedance_cdp_project_list
-        where micro_promotion_type = #{mediaType}
+        FROM media_api.bytedance_byte_app_info
     </select>
 
     <select id="queryErrApps" resultType="Long">
@@ -128,12 +163,23 @@
         order by create_time
     </select>
 
+    <select id="queryTTErrApps" resultType="Long">
+        SELECT advertiser_id
+        FROM media_api.error_advertiser_tt
+        order by create_time
+    </select>
+
     <delete id="delErrApps">
         DELETE
         FROM media_api.error_advertiser
         WHERE type = #{type}
     </delete>
 
+    <delete id="delTTErrApps">
+        DELETE
+        FROM media_api.error_advertiser_tt
+    </delete>
+
 
     <select id="queryAdvertiserIds" resultType="Long">
         SELECT DISTINCT advertiser_id
@@ -177,5 +223,11 @@
         FROM deepthink.adq_advertiser_list
     </select>
 
+    <select id="queryAppInstanceIdList" resultType="String">
+        SELECT instance_id
+        FROM media_api.bytedance_byte_app_info
+        where advertiser_id = #{advertiserId}
+    </select>
+
 
 </mapper>

+ 6 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/IBytedanceCdpProjectService.java

@@ -17,10 +17,14 @@ public interface IBytedanceCdpProjectService {
 
     boolean delErrApps(String type);
 
+    boolean delTTErrApps();
+
     List<Long> queryAdvertiserIds(String db, String date);
 
     void getByteAppInfo(Long advertiserId);
 
+    void getByteAppLinkInfo(Long advertiserId);
+
     void getWxAppInfo(Long advertiserId);
 
     List<Long> queryMediaAdverIds(String date, String mediaType);
@@ -29,4 +33,6 @@ public interface IBytedanceCdpProjectService {
 
     void getAdqCreatives(Long advertiserId, String date);
 
+    List<Long> queryTTErrApps();
+
 }

+ 72 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/BytedanceCdpProjectServiceImpl.java

@@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
 
 import java.time.Instant;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -52,11 +53,21 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
     }
 
     @Override
+    public List<Long> queryTTErrApps() {
+        return bytedanceCdpProjectMapper.queryTTErrApps();
+    }
+
+    @Override
     public boolean delErrApps(String type) {
         return bytedanceCdpProjectMapper.delErrApps(type);
     }
 
     @Override
+    public boolean delTTErrApps() {
+        return bytedanceCdpProjectMapper.delTTErrApps();
+    }
+
+    @Override
     public List<Long> queryAdvertiserIds(String db, String date) {
         return bytedanceCdpProjectMapper.queryAdvertiserIds(db, date);
     }
@@ -129,6 +140,7 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
     public void getByteAppInfo(Long advertiserId) {
         this.getByteAppInfoVo(advertiserId, "CREATE_ONLY", 1, 1);
         this.getByteAppInfoVo(advertiserId, "SHARE_ONLY", 1, 1);
+        this.getByteAppLinkInfo(advertiserId);
     }
 
     private void getByteAppInfoVo(Long advertiserId, String searchType, Integer page, int count) {
@@ -186,6 +198,66 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
     }
 
     @Override
+    public void getByteAppLinkInfo(Long advertiserId) {
+        String accessToken = tokenMapper.onlyGetToken(advertiserId);
+        if (Check.isNull(accessToken)) {
+            log.error("账户({})查询token失败", advertiserId);
+            return;
+        }
+        List<String> ids = bytedanceCdpProjectMapper.queryAppInstanceIdList(advertiserId);
+        for (String id : ids) {
+            this.getByteAppLinkInfoVo(accessToken, advertiserId, id, 1, 1);
+        }
+    }
+
+    private void getByteAppLinkInfoVo(String accessToken, Long advertiserId, String instanceId, Integer page, int count) {
+        try {
+            boolean nextPage = false;
+            JSONObject params = new JSONObject();
+            params.put("advertiser_id", advertiserId);
+            params.put("page", page);
+            params.put("page_size", 100);
+            JSONObject filtering = new JSONObject();
+            filtering.put("instance_id", Long.valueOf(instanceId));
+            params.put("filtering", filtering);
+            //获取微信小程序列表
+            String url = "https://api.oceanengine.com/open_api/v3.0/tools/asset_link/list/";
+            JSONObject obj = Okhttp3Utils.bytedanceGetRequest(accessToken, url, params);
+            if (!Check.isNull(obj)) {
+                Integer code = obj.getInteger("code");
+                if (code == 0) {
+                    JSONObject data = obj.getJSONObject("data");
+                    System.out.println(data);
+                    Integer totalPage = data.getJSONObject("page_info").getInteger("total_page");
+                    if (totalPage != 0 && totalPage > data.getJSONObject("page_info").getInteger("page")) {
+                        nextPage = true;
+                    }
+                    JSONArray list = data.getJSONArray("list");
+                    if (!Check.isNull(list))
+                        if (bytedanceCdpProjectMapper.replaceBytedanceByteAppLinkInfo(list) > 0)
+                            log.info("---账户({})抖小详情信息更新成功", advertiserId);
+                } else {
+                    //40110请求超频 51010 内部服务超时
+                    if ((40110 == code || 51010 == code) && count <= 3) {
+                        Thread.sleep(700);
+                        getByteAppLinkInfoVo(accessToken, advertiserId, instanceId, page, count + 1);
+                    } else {
+                        bytedanceCdpProjectMapper.insertTTErrorAdvertiserId(advertiserId);
+                        log.error("账户({})获取字节小程序/小游戏详情内容失败,入参:{}\n结果:{}", advertiserId, JSONObject.toJSONString(params), obj);
+                    }
+                }
+            }
+            if (nextPage) {
+                getByteAppLinkInfoVo(accessToken, advertiserId, instanceId, page + 1, count);
+            }
+        } catch (Exception e) {
+            bytedanceCdpProjectMapper.insertTTErrorAdvertiserId(advertiserId);
+            e.printStackTrace();
+            log.error(e.getMessage());
+        }
+    }
+
+    @Override
     public void getWxAppInfo(Long advertiserId) {
         this.getWxAppInfoVo(advertiserId, "CREATE_ONLY", 1, 1);
         this.getWxAppInfoVo(advertiserId, "SHARE_ONLY", 1, 1);

+ 12 - 4
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedanceCdpProjectJob.java

@@ -26,37 +26,45 @@ public class BytedanceCdpProjectJob {
 
     private static ExecutorService allttService = Executors.newFixedThreadPool(2);
     private static ExecutorService allwxService = Executors.newFixedThreadPool(2);
+    private static ExecutorService allt2Service = Executors.newFixedThreadPool(2);
 
     private static ExecutorService projectExecutorService = Executors.newFixedThreadPool(3);
     private static ExecutorService ttAppsExecutorService = Executors.newFixedThreadPool(3);
     private static ExecutorService wxAppsExecutorService = Executors.newFixedThreadPool(3);
     private static ExecutorService createiveAppsExecutorService = Executors.newFixedThreadPool(3);
 
-
     @XxlJob("getAll")
     public void getAll() {
         log.info("[getAll] 任务启动...");
         List<Long> wxlist = cdpProjectService.queryAllAdverIdList("WECHAT_APP");
         if (!Check.isNull(wxlist)) {
-            wxlist.forEach(id -> allwxService.submit(() -> cdpProjectService.getWxAppInfo(id)));
+            wxlist.forEach(id -> allwxService.submit(() -> cdpProjectService.getByteAppLinkInfo(id)));
         }
     }
 
     @XxlJob("errAppAgain")
     public void errAppAgain() {
         log.info("[errAppAgain] 任务启动...");
-        List<Long> ttList = cdpProjectService.queryAllAdverIdList("tt");
+        List<Long> ttList = cdpProjectService.queryErrApps("tt");
         if (!Check.isNull(ttList)) {
             if (cdpProjectService.delErrApps("tt"))
                 log.info("[errAppAgain] ---移除抖小失败记录");
             ttList.forEach(id -> allttService.submit(() -> cdpProjectService.getByteAppInfo(id)));
         }
-        List<Long> wxlist = cdpProjectService.queryAllAdverIdList("wx");
+
+        List<Long> wxlist = cdpProjectService.queryErrApps("wx");
         if (!Check.isNull(wxlist)) {
             if (cdpProjectService.delErrApps("wx"))
                 log.info("[errAppAgain] ---移除微小失败记录");
             wxlist.forEach(id -> allwxService.submit(() -> cdpProjectService.getWxAppInfo(id)));
         }
+
+        List<Long> tt2list = cdpProjectService.queryTTErrApps();
+        if (!Check.isNull(tt2list)) {
+            if (cdpProjectService.delTTErrApps())
+                log.info("[errAppAgain] ---移除抖小详情失败记录");
+            tt2list.forEach(id -> allt2Service.submit(() -> cdpProjectService.getByteAppLinkInfo(id)));
+        }
     }
 
     @XxlJob("nowProjects")