zhaotx пре 1 година
родитељ
комит
c03a4e8eed

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

@@ -29,14 +29,14 @@
         FROM deepthink.bytedance_product_main_advertiser t1
         left join deepthink.bytedance_advertiser_list t2 on t1.advertiser_id=t2.advertiser_id
         left join deepthink.bytedance_auth_list t3 on t2.admin_advertiser_id=t3.admin_advertiser_id
-        where t1.`type`=2 and t1.`_status`=0 and platform_type=1
+        where t1.`type`=2 and t1.`_status`=0 and platform_type=1 and tb1.mini_instance_id is not null
     </select>
     <select id="getIAAPlatformList" resultType="com.alibaba.fastjson.JSONObject">
         select t1.*, t3.access_token
         FROM deepthink.bytedance_product_main_advertiser t1
         left join deepthink.bytedance_advertiser_list t2 on t1.advertiser_id=t2.advertiser_id
         left join deepthink.bytedance_auth_list t3 on t2.admin_advertiser_id=t3.admin_advertiser_id
-        where t1.`type`=1 and t1.`_status`=0 and platform_type=1
+        where t1.`type`=1 and t1.`_status`=0 and platform_type=1 and tb1.mini_instance_id is not null
     </select>
     <select id="getIAPVideoList" resultType="com.alibaba.fastjson.JSONObject">
         select third.album_id, third.platform_type, detail.platform_config, video.id as video_id, detail.id as video_detail_id, video.name as name, video.cover_img as img,ifnull(category.name, '其他') as 'theme', video.play_platform,

+ 59 - 31
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/BytedanceProductUpdateServiceImpl.java

@@ -35,7 +35,7 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
     public void run() throws Exception {
         Set<String> errors = new HashSet<>();
         log.info("付费商品库更新中...");
-        iapProductUpdate(errors);
+//        iapProductUpdate(errors);
         log.info("付费商品库更新完成");
         log.info("免费商品库更新中...");
         iaaProductUpdate(errors);
@@ -76,18 +76,20 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
                     String res = HttpUtils.httpPostRequest(url, body, headers);
                     System.out.println("授权结果: " + res);
                     JSONObject resObj = JSONObject.parseObject(res);
-                    int code = resObj.getIntValue("code");
+                    int code = resObj.getIntValue("err_no");
                     if (code != 0){
                         log.error("授权失败,code: " + code + ", msg: " + resObj.getString("message") + ", 社会信用代码: " + socialCreditCode);
                     }else {
                         JSONObject data = resObj.getJSONObject("data");
                         if (data.getBooleanValue("authed")){
-                            log.info("授权成功,社会信用代码: " + socialCreditCode + ", 企业名称: " + obj.getJSONArray("authed_corps").toJSONString());
+                            log.info("授权成功,社会信用代码: " + socialCreditCode + ", 企业名称: " + data.getJSONArray("authed_corps").toJSONString());
                             bytedanceProductUpdateMapper.updateMovieAuthStatus(obj.getString("platform_id"));
                         }
                     }
+                    Thread.sleep(4000);
                 }
             }catch (Exception e){
+                e.printStackTrace();
                 log.error("获取字节小程序access_token失败", e);
             }
         }
@@ -102,7 +104,7 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
         List<JSONObject> iapPlatformList = bytedanceProductUpdateMapper.getIAPPlatformList();
         List<JSONObject> iaaPlatformList = bytedanceProductUpdateMapper.getIAAPlatformList();
         initNew(iaaPlatformList);
-        initNew(iapPlatformList);
+//        initNew(iapPlatformList);
         authMovieResource();
     }
 
@@ -146,18 +148,18 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
 
             String res = HttpUtils.httpPostRequest(createLinkUrl, requestBody, headers);
             if (res == null || res.isEmpty()){
-                System.out.println("创建字节小程序失败");
-                return;
+                System.out.println("创建字节小程序失败,advertiser_id:"+advertiser_id);
             }else {
                 JSONObject jsonObject = JSONObject.parseObject(res);
+                System.out.println("创建字节小程序响应: " + jsonObject.toJSONString());
                 int code = jsonObject.getIntValue("code");
                 if (code != 0) {
-                    System.out.println("创建字节小程序失败,code: " + code + ", msg: " + jsonObject.getString("message"));
-                    break;
+                    System.out.println("创建字节小程序失败,advertiser_id: "+advertiser_id+",code: " + code + ", msg: " + jsonObject.getString("message"));
                 }else {
                     String instanceId = jsonObject.getJSONObject("data").getString("instance_id");
                     //更新表
                     bytedanceProductUpdateMapper.updateInstanceId(advertiser_id, instanceId);
+                    System.out.println("创建字节小程序成功,广告主ID: " + advertiser_id + ", 实例ID: " + instanceId);
                 }
             }
         }
@@ -178,11 +180,6 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
             String advertiserId = obj.getString("advertiser_id");
             String accessToken = obj.getString("access_token");
             String instanceId = obj.getString("mini_instance_id");
-            if (instanceId == null){
-                errorBlanket.add("没有找到字节小程序的实例ID: " + advertiserId);
-                System.out.println("没有找到字节小程序的实例ID: " + advertiserId);
-                continue;
-            }
             List<JSONObject> iapVideoDouyinList = iapVideoList.stream().filter(obj1 -> "1".equals(obj1.getString("platform_type"))).collect(Collectors.toList());
             Map<String, String> albumIdToLinkMap = getBytedancePlayletPromoteLink(advertiserId, accessToken, instanceId, iapVideoDouyinList, errorBlanket);
             advertiserToLinkMap.put(advertiserId, albumIdToLinkMap);
@@ -271,15 +268,35 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
         Map<String, String> linkObj = advertiserToLinkMap.get(platform.getString("advertiser_id"));
         String play_platform = album.getString("play_platform");
         List<String> ad_carrier = new ArrayList<>();
-        if (linkObj != null){
-            profession.put("micro_app_link", linkObj.get(album_id));
+//        if (linkObj != null){
+//            profession.put("micro_app_link", linkObj.get(album_id));
+//            ad_carrier.add("字节小程序");
+//            if (play_platform.contains("1")){
+//                if (bytedanceProductUpdateMapper.getWeixinAuditStatus(album.getLong("video_id"))>0){
+//                    ad_carrier.add("微信小程序");
+//                }
+//            }
+//        }else {
+//            profession.put("album_id", album_id);
+//            ad_carrier.add("微信小程序");
+//        }
+        Integer is_bytedance = platform.getInteger("is_bytedance");
+        Integer is_wechat = platform.getInteger("is_wechat");
+        Integer is_dys = platform.getInteger("is_dys");
+        if (is_bytedance == 1){
             ad_carrier.add("字节小程序");
-            if (play_platform.contains("1")){
-                ad_carrier.add("微信小程序");
-            }
+        }
+        if (is_wechat == 1){
+            ad_carrier.add("微信小程序");
+        }
+        if (is_dys == 1){
+            ad_carrier.add("端原生组件");
+        }
+
+        if (is_bytedance == 1){
+            profession.put("micro_app_link", linkObj.get(album_id));
         }else {
             profession.put("album_id", album_id);
-            ad_carrier.add("微信小程序");
         }
         profession.put("ad_carrier", JSON.toJSONString(ad_carrier));
 
@@ -315,11 +332,7 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
             String advertiserId = obj.getString("advertiser_id");
             String accessToken = obj.getString("access_token");
             String instanceId = obj.getString("mini_instance_id");
-            if (instanceId == null){
-                errorBlanket.add("没有找到字节小程序的实例ID: " + advertiserId);
-                System.out.println("没有找到字节小程序的实例ID: " + advertiserId);
-                continue; //todo
-            }
+
             List<JSONObject> iaaVideoDouyinList = iaaVideoList.stream().filter(obj1 -> "1".equals(obj1.getString("platform_type"))).collect(Collectors.toList());
             Map<String, String> albumIdToLinkMap = getBytedancePlayletPromoteLink(advertiserId, accessToken, instanceId, iaaVideoDouyinList, errorBlanket);
             advertiserToLinkMap.put(advertiserId, albumIdToLinkMap);
@@ -387,18 +400,33 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
         profession.put("membership_types", "5");
         profession.put("starting_unlock_episode", album.getString("starting_unlock_episode"));
         Map<String, String> linkObj = advertiserToLinkMap.get(platform.getString("advertiser_id"));
-        String play_platform = album.getString("play_platform");
         List<String> ad_carrier = new ArrayList<>();
-        if (linkObj != null){
-            profession.put("micro_app_link", linkObj.get(album_id));
+//        if (linkObj != null){
+//            profession.put("micro_app_link", linkObj.get(album_id));
+//            ad_carrier.add("字节小程序");
+//        }else {
+//            profession.put("album_id", album_id);
+//            ad_carrier.add("微信小程序");
+//        }
+        Integer is_bytedance = platform.getInteger("is_bytedance");
+        Integer is_wechat = platform.getInteger("is_wechat");
+        Integer is_dys = platform.getInteger("is_dys");
+        if (is_bytedance == 1){
             ad_carrier.add("字节小程序");
-            if (play_platform.contains("1")){
-                ad_carrier.add("微信小程序");
-            }
+        }
+        if (is_wechat == 1){
+            ad_carrier.add("微信小程序");
+        }
+        if (is_dys == 1){
+            ad_carrier.add("端原生组件");
+        }
+
+        if (is_bytedance == 1){
+            profession.put("micro_app_link", linkObj.get(album_id));
         }else {
             profession.put("album_id", album_id);
-            ad_carrier.add("微信小程序");
         }
+
         profession.put("ad_carrier", JSON.toJSONString(ad_carrier));
 
         product_info.put("profession", profession);