zhaotx před 10 měsíci
rodič
revize
361871a1b8

+ 5 - 0
job-bytedance/pom.xml

@@ -197,6 +197,11 @@
             <artifactId>aliyun-sdk-oss</artifactId>
             <version>3.16.0</version>
         </dependency>
+        <dependency>
+            <groupId>com.larksuite.oapi</groupId>
+            <artifactId>oapi-sdk</artifactId>
+            <version>2.4.25</version>
+        </dependency>
 
     </dependencies>
     <build>

+ 178 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/config/FeishuRobotLinkConfig.java

@@ -0,0 +1,178 @@
+package cn.com.ctop.job.bytedance.config;
+
+
+import cn.com.ctop.job.bytedance.data.entity.AigcProductPlatform;
+import cn.com.ctop.job.bytedance.data.service.IBytedanceProductUpdateService;
+import cn.com.ctop.job.bytedance.data.service.IFeishuDocSyncService;
+import cn.com.ctop.job.bytedance.utils.FeishuRobotUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.lark.oapi.Client;
+import com.lark.oapi.core.utils.Jsons;
+import com.lark.oapi.event.EventDispatcher;
+import com.lark.oapi.event.cardcallback.model.*;
+import com.lark.oapi.service.im.ImService;
+import com.lark.oapi.service.im.v1.enums.MsgTypeEnum;
+import com.lark.oapi.service.im.v1.enums.ReceiveIdTypeEnum;
+import com.lark.oapi.service.im.v1.model.*;
+import com.lark.oapi.service.im.v1.model.ext.MessageText;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@Configuration
+public class FeishuRobotLinkConfig {
+
+    static ExecutorService executorService = Executors.newFixedThreadPool(2);
+
+    private static final Client sendClient = new Client.Builder(FeishuRobotUtil.fs_zt_appid, FeishuRobotUtil.fs_zt_appkey).build();
+
+    @Bean
+    public com.lark.oapi.ws.Client fsClient(){
+        com.lark.oapi.ws.Client receiveClient = new com.lark.oapi.ws.Client.Builder(FeishuRobotUtil.fs_zt_appid, FeishuRobotUtil.fs_zt_appkey)
+                .eventHandler(EVENT_HANDLER)
+                .build();
+        receiveClient.start();
+        return receiveClient;
+    }
+    @Autowired
+    IFeishuDocSyncService feishuDocSyncService;
+    @Autowired
+    IBytedanceProductUpdateService bytedanceProductUpdateService;
+
+    private final EventDispatcher EVENT_HANDLER = EventDispatcher.newBuilder("", "")  // 长连接不需要这两个参数,请保持空字符串
+            .onP2MessageReceiveV1(new ImService.P2MessageReceiveV1Handler() {
+                @Override
+                public void handle(P2MessageReceiveV1 event) throws Exception {
+                    System.out.println(JSON.toJSONString(event));
+                    String content = event.getEvent().getMessage().getContent();
+                    String sendUserId = event.getEvent().getSender().getSenderId().getUserId();
+                    JSONObject contentObj = JSON.parseObject(content);
+                    String text = contentObj.getString("text");
+                    System.out.println("收到消息内容: "+text+", 发送用户ID: "+sendUserId);
+                    if (text.contains("@")){
+                        String atRobotUser = getAtRobotUserId(event);
+                        if (StringUtils.isNotEmpty(atRobotUser)){
+                            text = text.replace(atRobotUser, "").trim();
+                        }
+                    }
+                    if ("帮助".equals(text)){
+                        consoleHelp(event);
+                    }
+                    else if (text.contains("同步巨量商品库")) { //异步
+                        String platformId = text.replace("同步巨量商品库", "").trim();
+                        if (StringUtils.isEmpty(platformId)){
+                            responseMessage(event, "请写明要同步的商品库ID");
+                        }else {
+                            executorService.submit(new Runnable() {
+                                @Override
+                                public void run() {
+                                    try {
+                                        responseMessage(event, "商品库同步任务已启动");
+                                        feishuDocSyncService.syncBytedanceProductPlatform();
+                                        feishuDocSyncService.syncBytedanceDysDistributeMovies();
+//                                        bytedanceProductUpdateService.runPlatform(platformId);
+                                        responseMessage(event, "商品库同步任务已完成,请登录巨量平台确认");
+//                                } catch (IOException e) {
+//                                    throw new RuntimeException(e);
+                                    }finally {
+
+                                    }
+                                }
+                            });
+                        }
+
+                    }else {
+                        responseMessage(event, "未识别的指令\n如需帮助,请@机器人并发送[帮助]");
+                    }
+                }
+            })
+            .build();
+
+    private void consoleHelp(P2MessageReceiveV1 event){
+
+        String replyContent = "操作指引:\n" +
+                "同步巨量商品库流程:\n" +
+                "1. 在https://artlinkworld.feishu.cn/wiki/WxMiwOnEsiNKmWk19yncyrgGnnf?table=tblsf6RT9HAamt8k&view=vew2h7auDC中添加商品库信息\n" +
+                "2. 如果需要立刻同步某个商品库,请输入指令(示例ID:1000000001):@机器人 同步巨量商品库1000000001";
+//                "扫描并同步端分销推广链输入指令:@机器人 同步端分销推广链";
+        responseMessage(event, replyContent);
+    }
+
+    /**
+     * 对事件来源用户回复消息
+     * @param event
+     * @param replyText 回复消息,文本,多行按\n分隔
+     */
+    private void responseMessage(P2MessageReceiveV1 event, String replyText){
+
+
+        if (event.getEvent().getMessage().getChatType().equals("p2p")){
+            MessageText.Builder messageTextBuilder = new MessageText.Builder();
+            String[] replyRows = replyText.split("\n");
+            for (String replyRow : replyRows) {
+                messageTextBuilder.textLine(replyRow);
+            }
+            String replyContent = messageTextBuilder.build();
+            CreateMessageReq req = CreateMessageReq.newBuilder()
+                    .receiveIdType(ReceiveIdTypeEnum.CHAT_ID.getValue())
+                    .createMessageReqBody(CreateMessageReqBody.newBuilder()
+                            .receiveId(event.getEvent().getMessage().getChatId())
+                            .msgType(MsgTypeEnum.MSG_TYPE_INTERACTIVE.getValue())
+                            .content(replyContent)
+                            .build())
+                    .build();
+            try {
+                CreateMessageResp resp = sendClient.im().message().create(req);
+                if (resp.getCode() != 0) {
+                    System.out.println(String.format("logId: %s, error response: \n%s",
+                            resp.getRequestId(), Jsons.DEFAULT.toJson(resp.getError())));
+                }
+            } catch (Exception e) {
+                System.out.println(e.getMessage());
+            }
+        }else {
+            MessageText.Builder messageTextBuilder = new MessageText.Builder();
+            messageTextBuilder.textLine("<at user_id=\\\""+event.getEvent().getSender().getSenderId().getOpenId()+"\\\"></at>");
+            String[] replyRows = replyText.split("\n");
+            for (String replyRow : replyRows) {
+                messageTextBuilder.textLine(replyRow);
+            }
+            String replyContent = messageTextBuilder.build();
+            ReplyMessageReq req = ReplyMessageReq.newBuilder()
+                    .messageId(event.getEvent().getMessage().getMessageId())
+                    .replyMessageReqBody(ReplyMessageReqBody.newBuilder()
+                            .content(replyContent)
+                            .msgType("text")
+                            .build())
+                    .build();
+            try {
+                // 发起请求
+                ReplyMessageResp resp = sendClient.im().message().reply(req);
+                if (resp.getCode() != 0) {
+                    System.out.println(String.format("logId: %s, error response: \n%s", resp.getRequestId(), Jsons.DEFAULT.toJson(resp.getError())));
+                }
+            } catch (Exception e) {
+                System.out.println(e.getMessage());
+            }
+        }
+    }
+
+
+
+
+    private static final String getAtRobotUserId(P2MessageReceiveV1 p2MessageReceiveV1){
+        MentionEvent[] mentionEvents = p2MessageReceiveV1.getEvent().getMessage().getMentions();
+        if (mentionEvents != null && mentionEvents.length > 0){
+            return mentionEvents[0].getKey();
+        }else {
+            return null;
+        }
+    }
+}

+ 4 - 3
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/controller/FeishuController.java

@@ -56,7 +56,7 @@ public class FeishuController {
     @PostMapping("/test")
     public void test(@RequestBody String str) throws Exception {
 //        bytedanceProductUpdateService.initNew();
-//        bytedanceProductUpdateService.run();
+        bytedanceProductUpdateService.runMp();
 //        reportsAdPushService.test();
 //        totalRankPushService.test();
 //        dateReportsPushService.preSend();
@@ -84,14 +84,15 @@ public class FeishuController {
 //        }
 //        distributionPushService.sendToday();
 //        distributionPushService.sendYesterday();
-//        movieRankPushService.send();
+//        movieRankPushService.test();
 
 //        bytedanceProductUpdateService.pullFanqiePlaylet();
 
 
+//        feishuDocSyncService.syncBytedanceIaaProductPlatform();
+//        feishuDocSyncService.syncBytedanceDysDistributeMovies();
 //        bytedanceProductUpdateService.runDysDistribute();
 //        bytedanceProductUpdateService.clearAuditFailProduct();
-//        feishuDocSyncService.syncBytedanceDysDistributeMovies();
     }
 
 

+ 9 - 8
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/BytedanceProductUpdateMapper.java

@@ -9,18 +9,17 @@ import java.util.List;
 
 public interface BytedanceProductUpdateMapper {
 
-    List<AigcProductPlatform> getIAPPlatformInitList();
-    List<AigcProductPlatform> getIAPPlatformList();
-    List<AigcProductAlbum> getIAPVideoList();
-    List<JSONObject> getIAPProductTypeEnums();
+    List<String> allPlatform();
+
+    List<AigcProductPlatform> getPlatformInitList(@Param("businessMethod") String businessMethod);
+    List<AigcProductPlatform> getPlatformList(@Param("businessMethod") String businessMethod, @Param("platformId") String platformId);
+    List<JSONObject> getProductTypeEnums(@Param("businessMethod") String businessMethod);
 
-    List<AigcProductPlatform> getIAAPlatformInitList();
-    List<AigcProductPlatform> getIAAPlatformList();
+    List<AigcProductAlbum> getIAPVideoList();
     List<AigcProductAlbum> getIAAVideoList();
-    List<JSONObject> getIAAProductTypeEnums();
 
 
-    List<AigcProductPlatform> getDysIaaPlatformList();
+    List<AigcProductPlatform> getDysIaaPlatformList(@Param("platformId") String platformId);
     List<AigcProductAlbum> getDysDistributorVideo(@Param("businessMethod") String businessMethod);
     List<String> randomFanqieMovieImgs(@Param("count") Integer count);
 
@@ -52,4 +51,6 @@ public interface BytedanceProductUpdateMapper {
 
     int batchInsertDysDistributePlayletInfo(List<AigcProductAlbum> list);
 
+    int batchInsertPlatform(List<AigcProductPlatform> platformList);
+
 }

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

@@ -24,21 +24,34 @@
     </update>
 
 
-    <select id="getIAPPlatformList" resultType="cn.com.ctop.job.bytedance.data.entity.AigcProductPlatform">
+    <select id="getPlatformList" resultType="cn.com.ctop.job.bytedance.data.entity.AigcProductPlatform">
         select t1.platform_id, t1.advertiser_id, t1.type, t1.platform_type, t1.platform_name, t1.mini_instance_id, t1.update_time, t1.create_time, t1.mi_appid, t1.membership_types, t1.max_charge, t1.min_charge, t1.recommended_charge, t1.single_price, t1._status, t1.social_credit_code, t1.movie_auth_status, t1.is_bytedance, t1.is_wechat, t1.is_dys, t1.source, ifnull(t1.mini_app_advertiser_id,t1.advertiser_id) as mini_app_advertiser_id, t3.access_token,
         '天津星链视界信息技术有限公司' as copyright_owner
         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 and t1.mini_instance_id is not null
-    </select>
-    <select id="getIAPPlatformInitList" resultType="cn.com.ctop.job.bytedance.data.entity.AigcProductPlatform">
+        where t1.`_status`=0 and platform_type=1 and t1.mini_instance_id is not null
+        <if test="businessMethod != null">
+            <choose>
+                <when test="businessMethod = 'IAP'">and t1.`type`=2 </when>
+                <when test="businessMethod = 'IAA'">and t1.`type`=1 </when>
+            </choose>
+        </if>
+        <if test="platformId != null and platformId != ''">
+            and t1.platform_id = #{platformId}
+        </if>
+    </select>
+    <select id="getPlatformInitList" resultType="cn.com.ctop.job.bytedance.data.entity.AigcProductPlatform">
         select t1.platform_id, t1.advertiser_id, t1.type, t1.platform_type, t1.platform_name, t1.mini_instance_id, t1.update_time, t1.create_time, t1.mi_appid, t1.membership_types, t1.max_charge, t1.min_charge, t1.recommended_charge, t1.single_price, t1._status, t1.social_credit_code, t1.movie_auth_status, t1.is_bytedance, t1.is_wechat, t1.is_dys, t1.source, ifnull(t1.mini_app_advertiser_id,t1.advertiser_id) as mini_app_advertiser_id, t3.access_token,
                '天津星链视界信息技术有限公司' as copyright_owner
         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.`_status`=0 and platform_type=1
+        <choose>
+            <when test="businessMethod != null and businessMethod = 'IAP'">and t1.`type`=2 </when>
+            <when test="businessMethod != null and businessMethod = 'IAA'">and t1.`type`=1 </when>
+        </choose>
     </select>
     <select id="getIAAPlatformList" resultType="cn.com.ctop.job.bytedance.data.entity.AigcProductPlatform">
         select t1.platform_id, t1.advertiser_id, t1.type, t1.platform_type, t1.platform_name, t1.mini_instance_id, t1.update_time, t1.create_time, t1.mi_appid, t1.membership_types, t1.max_charge, t1.min_charge, t1.recommended_charge, t1.single_price, t1._status, t1.social_credit_code, t1.movie_auth_status, t1.is_bytedance, t1.is_wechat, t1.is_dys, t1.source, ifnull(t1.mini_app_advertiser_id,t1.advertiser_id) as mini_app_advertiser_id, t3.access_token,
@@ -71,7 +84,7 @@
         LEFT JOIN thirtpart.ly_video_category category ON video.category_id = category.id
         LEFT JOIN (select video_id, min(sort) as sort, max(pay_amount/100.0) as maxpay, min(pay_amount/100.0) as minpay from thirtpart.ly_video_details where is_pay=1 group by video_id) payinfo ON video.id = payinfo.video_id
         where (video.is_free = 1 or (payinfo.sort is not null and maxpay>0))
-        and video.created_at > 1743436800
+        and (video.created_at > 1743436800 or video.updated_at > 1743436800)
         and video.source in (1,3)
     </select>
     <select id="getIAAVideoList" resultType="cn.com.ctop.job.bytedance.data.entity.AigcProductAlbum">
@@ -89,10 +102,14 @@
         where video.is_iaa_show=1 and video.created_at > 1743436800
         and video.source in (1,3)
     </select>
-    <select id="getIAPProductTypeEnums" resultType="com.alibaba.fastjson.JSONObject">
+    <select id="getProductTypeEnums" resultType="com.alibaba.fastjson.JSONObject">
         select first_type_name, first_type_id, second_type_name, second_type_id, third_type_name, third_type_id
         from deepthink.bytedance_product_group_types
-        where `type`=2
+        where 1=1
+        <choose>
+            <when test="businessMethod != null and businessMethod = 'IAP'">and `type`=2 </when>
+            <when test="businessMethod != null and businessMethod = 'IAA'">and`type`=1 </when>
+        </choose>
     </select>
     <select id="getIAAProductTypeEnums" resultType="com.alibaba.fastjson.JSONObject">
         select first_type_name, first_type_id, second_type_name, second_type_id, third_type_name, third_type_id
@@ -149,12 +166,18 @@
                  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.`_status`=0 and platform_type=3 and t1.is_dys=1
+        <if test="platformId != null and platformId != ''">
+            and t1.platform_id = #{platformId}
+        </if>
     </select>
     <select id="randomFanqieMovieImgs" resultType="java.lang.String">
         select movie_url
         from deepthink.changdu_movie_config
         limit #{count}
     </select>
+    <select id="allPlatform" resultType="java.lang.String">
+        select platform_id from deepthink.bytedance_product_main_advertiser where status=0
+    </select>
     <insert id="batchInsertFanqiePlayletInfo" >
         replace into deepthink.dys_distribute_promote_link
         (playlet_id, playlet_purchase_panel_id, movie_name, promote_link, business_method, movie_source)
@@ -171,4 +194,14 @@
             (#{item.playletId}, #{item.playletPurchasePanelId}, #{item.name}, #{item.albumLink}, #{item.businessMethod}, #{item.source})
         </foreach>
     </insert>
+    <insert id="batchInsertPlatform">
+        replace into deepthink.bytedance_product_main_advertiser
+        (platform_id, advertiser_id, type, platform_type, platform_name, mini_instance_id,
+         mi_appid, _status, social_credit_code, is_bytedance, is_wechat, is_dys, source)
+        values
+        <foreach collection="list" item="item" separator=",">
+            (#{item.platformId}, #{item.advertiserId}, #{item.type}, #{item.platformType}, #{item.platformName}, #{item.miniInstanceId},
+             #{item.miAppid}, #{item.status}, #{item.socialCreditCode}, #{item.isBytedance}, #{item.isWechat}, #{item.isDys}, #{item.source})
+        </foreach>
+    </insert>
 </mapper>

+ 2 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/IBytedanceProductUpdateService.java

@@ -4,6 +4,8 @@ import java.io.IOException;
 
 public interface IBytedanceProductUpdateService {
 
+    String runPlatform(String platformId) throws IOException;
+
     void runMp() throws Exception;
 
     void runDysDistribute() throws IOException;

+ 1 - 5
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/IFeishuDocSyncService.java

@@ -5,11 +5,7 @@ public interface IFeishuDocSyncService {
     /**
      * 同步巨量 IAA 商品库
      */
-    void syncBytedanceIaaProductPlatform();
-    /**
-     * 同步巨量 IAP 商品库
-     */
-    void syncBytedanceIapProductPlatform();
+    void syncBytedanceProductPlatform();
     /**
      * 同步巨量 端原生分销剧目
      */

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

@@ -45,33 +45,56 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
     //商品上传结果通知群
     public static final String HOOK_URL = "https://open.feishu.cn/open-apis/bot/v2/hook/92e2445e-76df-44fb-8f61-f55ac94f49bd";
 
+    public String runPlatform(String platformId) throws IOException {
+        List<AigcProductPlatform> platform = bytedanceProductUpdateMapper.getPlatformList(null, platformId);
+        if (platform.isEmpty()){
+            return "未找到对应的商品库信息,商品库ID:"+platformId;
+        }
+        System.out.println(JSON.toJSONString(platform.get(0)));
+        AigcProductPlatform p = platform.get(0);
+        if (p.getPlatformType() == 1 || p.getPlatformType() == 2){
+            runMiniProgram(platformId);
+        }else if (p.getPlatformType() == 3){
+            runDysDistribute(platformId);
+        }
+        return null;
+    }
+
     @Override
     public void runMp() throws Exception {
+        runMiniProgram(null);
+    }
+
+    private void runMiniProgram(String platformId) throws IOException {
         Set<String> errors = new HashSet<>();
         log.info("付费商品库更新中...");
-        List<AigcProductPlatform> iapPlatformList = bytedanceProductUpdateMapper.getIAPPlatformList(); //商品库列表
-        List<AigcProductAlbum> iapVideoList = bytedanceProductUpdateMapper.getIAPVideoList(); //剧目列表
-        List<JSONObject> iapProductTypeEnums = bytedanceProductUpdateMapper.getIAPProductTypeEnums(); //商品类型
-        Map<String, JSONObject> iapProductTypeMap = iapProductTypeEnums.stream().collect(Collectors.toMap(
-                obj -> obj.getString("third_type_name"),
-                obj -> obj,
-                (existing, replacement) -> replacement
-        ));
-        runMpProductTask(iapPlatformList, iapVideoList, iapProductTypeMap, errors, BusinessType.IAP);
+        List<AigcProductPlatform> iapPlatformList = bytedanceProductUpdateMapper.getPlatformList("IAP", platformId); //商品库列表
+        if (!iapPlatformList.isEmpty()){
+            List<AigcProductAlbum> iapVideoList = bytedanceProductUpdateMapper.getIAPVideoList(); //剧目列表
+            List<JSONObject> iapProductTypeEnums = bytedanceProductUpdateMapper.getProductTypeEnums("IAP"); //商品类型
+            Map<String, JSONObject> iapProductTypeMap = iapProductTypeEnums.stream().collect(Collectors.toMap(
+                    obj -> obj.getString("third_type_name"),
+                    obj -> obj,
+                    (existing, replacement) -> replacement
+            ));
+            runMpProductTask(iapPlatformList, iapVideoList, iapProductTypeMap, errors, BusinessType.IAP);
+        }
         log.info("付费商品库更新完成");
 
 
 
         log.info("免费商品库更新中...");
-        List<AigcProductPlatform> iaaPlatformList = bytedanceProductUpdateMapper.getIAAPlatformList(); //商品库列表
-        List<AigcProductAlbum> iaaVideoList = bytedanceProductUpdateMapper.getIAAVideoList(); //剧目列表
-        List<JSONObject> iaaProductTypeEnums = bytedanceProductUpdateMapper.getIAAProductTypeEnums(); //商品类型
-        Map<String, JSONObject> iaaProductTypeMap = iaaProductTypeEnums.stream().collect(Collectors.toMap(
-                obj -> obj.getString("third_type_name"),
-                obj -> obj,
-                (existing, replacement) -> replacement
-        ));
-        runMpProductTask(iaaPlatformList, iaaVideoList, iaaProductTypeMap, errors, BusinessType.IAA);
+        List<AigcProductPlatform> iaaPlatformList = bytedanceProductUpdateMapper.getPlatformList("IAA", platformId); //商品库列表
+        if (!iaaPlatformList.isEmpty()){
+            List<AigcProductAlbum> iaaVideoList = bytedanceProductUpdateMapper.getIAAVideoList(); //剧目列表
+            List<JSONObject> iaaProductTypeEnums = bytedanceProductUpdateMapper.getProductTypeEnums("IAA"); //商品类型
+            Map<String, JSONObject> iaaProductTypeMap = iaaProductTypeEnums.stream().collect(Collectors.toMap(
+                    obj -> obj.getString("third_type_name"),
+                    obj -> obj,
+                    (existing, replacement) -> replacement
+            ));
+            runMpProductTask(iaaPlatformList, iaaVideoList, iaaProductTypeMap, errors, BusinessType.IAA);
+        }
         log.info("免费商品库更新完成");
 
 
@@ -86,8 +109,15 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
 
     @Override
     public void runDysDistribute() throws IOException {
+        runDysDistribute(null);
+    }
+
+    private void runDysDistribute(String platformId) throws IOException {
         Set<String> errors = new HashSet<>();
-        List<AigcProductPlatform> iaaPlatformList = bytedanceProductUpdateMapper.getDysIaaPlatformList(); //商品库列表
+        List<AigcProductPlatform> iaaPlatformList = bytedanceProductUpdateMapper.getDysIaaPlatformList(platformId); //商品库列表
+        if (iaaPlatformList.isEmpty()){
+            return;
+        }
         Map<String, String> sourceCopywriteOwner = new HashMap<>();
         for (BytedanceProductDocProperties.DysDistributorLinkTable table : productDocProperties.getDysMovies()){
             sourceCopywriteOwner.put(table.getMovieSource(), table.getCopyrightOwner());
@@ -312,8 +342,8 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
      */
     @Override
     public void initNew(){
-        List<AigcProductPlatform> iapPlatformList = bytedanceProductUpdateMapper.getIAPPlatformInitList();
-        List<AigcProductPlatform> iaaPlatformList = bytedanceProductUpdateMapper.getIAAPlatformInitList();
+        List<AigcProductPlatform> iapPlatformList = bytedanceProductUpdateMapper.getPlatformInitList("IAP");
+        List<AigcProductPlatform> iaaPlatformList = bytedanceProductUpdateMapper.getPlatformInitList("IAA");
         initNew(iaaPlatformList);
         initNew(iapPlatformList);
         authMovieResource();
@@ -782,7 +812,7 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
 
     @Override
     public void clearAuditFailProduct() {
-        List<AigcProductPlatform> iaaPlatformList = bytedanceProductUpdateMapper.getDysIaaPlatformList(); //商品库列表
+        List<AigcProductPlatform> iaaPlatformList = bytedanceProductUpdateMapper.getDysIaaPlatformList(null); //商品库列表
         for (AigcProductPlatform platform : iaaPlatformList){
             List<AigcProductAlbum> albums = hasUploadProductPageList(platform, 1, 100, 2); //审核失败的商品列表
 //            albums = albums.stream().filter(al -> StringUtils.isEmpty(al.getName())).collect(Collectors.toList());

+ 39 - 17
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/FeishuDocSyncServiceImpl.java

@@ -32,10 +32,21 @@ public class FeishuDocSyncServiceImpl implements IFeishuDocSyncService {
     @Autowired
     BytedanceProductDocProperties productDocProperties;
     @Override
-    public void syncBytedanceIaaProductPlatform() {
+    public void syncBytedanceProductPlatform() {
         String readToken;
         try {
+            //iaa
             readToken = getReadToken();
+            List<AigcProductPlatform> list = readPlatformFromDoc(productDocProperties.getObjToken(),
+                    productDocProperties.getIaa().getTableId(), productDocProperties.getIaa().getViewId(), readToken, null);
+            list.forEach(p -> p.setType(1));
+            //insert if not exist
+            List<String> all = bytedanceProductUpdateMapper.allPlatform();
+            list.removeIf(a -> all.contains(a.getPlatformId()));
+            if (!list.isEmpty()){
+                System.out.println("新增商品库:"+JSON.toJSONString(list));
+//                bytedanceProductUpdateMapper.batchInsertPlatform(list);
+            }
         }catch (Exception e){
             log.error("获取飞书文档读权限token失败",e);
             return;
@@ -45,17 +56,6 @@ public class FeishuDocSyncServiceImpl implements IFeishuDocSyncService {
     }
 
     @Override
-    public void syncBytedanceIapProductPlatform() {
-        String readToken;
-        try {
-            readToken = getReadToken();
-        }catch (Exception e){
-            log.error("获取飞书文档读权限token失败",e);
-            return;
-        }
-    }
-
-    @Override
     public void syncBytedanceDysDistributeMovies() {
         if (productDocProperties.getDysMovies()==null|| productDocProperties.getDysMovies().isEmpty()){
             return;
@@ -191,12 +191,34 @@ public class FeishuDocSyncServiceImpl implements IFeishuDocSyncService {
             AigcProductPlatform platform = new AigcProductPlatform();
             platform.setPlatformId(getDocText(fields, "商品库ID"));
             platform.setAdvertiserId(getDocText(fields, "授权的广告主账户"));
-            platform.setType(1);
-            platform.setPlatformType(3);
+//            platform.setType(1); //在外面set
             platform.setPlatformName("欢瑞免费");
-            //todo
-
-            platforms.add(platform);
+            platform.setMiAppid(getDocText(fields, "抖音小程序ID"));
+            platform.setSocialCreditCode(getDocText(fields, "管家主体社会信用代码"));
+            String distributor = fields.getString("分销方");
+            if (StringUtils.isEmpty(distributor) || "无".equals(distributor)){
+                platform.setPlatformType(1);
+                platform.setIsBytedance(1);
+                platform.setIsWechat(0);
+                platform.setIsDys(1);
+                platform.setSource(1);
+            }else {
+                platform.setPlatformType(3);
+                platform.setIsBytedance(0);
+                platform.setIsWechat(0);
+                platform.setIsDys(1);
+                for (BytedanceProductDocProperties.DysDistributorLinkTable table : productDocProperties.getDysMovies()){
+                    if (table.getName().equals(distributor)){
+                        platform.setSource(Integer.valueOf(table.getMovieSource()));
+                        break;
+                    }
+                }
+            }
+            if (platform.getSource()==null){
+                log.error("未找到短剧来源");
+            }else {
+                platforms.add(platform);
+            }
         }
 
 

+ 22 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/utils/FeishuRobotUtil.java

@@ -210,6 +210,28 @@ public class FeishuRobotUtil {
         }
     }
 
+    public static void sendTextToRobot(String text, String userId, String token) throws IOException {
+        JSONObject content = new JSONObject();
+        content.put("text", text);
+        JSONObject request = new JSONObject();
+        request.put("receive_id", userId);
+        request.put("msg_type", "text");
+        request.put("content", content.toJSONString());
+        //发送
+        try (CloseableHttpClient client = HttpClients.createDefault()){
+            HttpPost httpPost = new HttpPost("https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=user_id");
+            httpPost.setHeader("Authorization", "Bearer "+token);
+            HttpEntity entity = new StringEntity(request.toJSONString(), "UTF-8");
+            httpPost.setEntity(entity);
+            httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
+            CloseableHttpResponse respon = client.execute(httpPost);
+//            System.out.println("发送结果: "+ EntityUtils.toString(respon.getEntity(), "UTF-8"));
+        }catch (IOException e){
+            System.out.println("发送飞书消息失败");
+        }
+
+    }
+
     public static void sendTextToWebhook(String text, String url) throws IOException {
         JSONObject content = new JSONObject();
         content.put("text", text);

+ 7 - 5
job-bytedance/src/main/resources/application.yml

@@ -198,37 +198,39 @@ feishu:
       objToken: AfLHbNJ9uamORqsvxq8cy63jnPc
       iaa:
         tableId: tblsf6RT9HAamt8k
+        viewId: vew2h7auDC
       iap:
         tableId: tbl5BPc8DHLIu4Ac
+        viewId: vew2h7auDC
       dysMovies[0]:
-        name: 番茄端原生推广链
+        name: 番茄
         tableId: tblPAu0mOPStWGfQ
         iaaViewId: vewnjgPWGB
         movieSource: 24
         copyrightOwner: 抖音视界有限公司
       dysMovies[1]:
-        name: 日新端原生推广链
+        name: 日新
         tableId: tblstFPWYbx172ey
         iaaViewId: vewnjgPWGB
         iapViewId: vewbYuvx4z
         movieSource: 18
         copyrightOwner: 日新端
       dysMovies[2]:
-        name: 胜事端原生推广链
+        name: 胜事
         tableId: tbl0IWs5PsvW3Q4q
         iaaViewId: vewnjgPWGB
         iapViewId: vewbYuvx4z
         movieSource: 10
         copyrightOwner: 胜事端
       dysMovies[3]:
-        name: 友和端原生推广链
+        name: 友和
         tableId: tblJWHRxZLtVEH6n
         iaaViewId: vewnjgPWGB
         iapViewId: vewbYuvx4z
         movieSource: 22
         copyrightOwner: 友和端
       dysMovies[4]:
-        name: 百川端原生推广链
+        name: 百川
         tableId: tblqN0gRgLBipgCd
         iaaViewId: vewnjgPWGB
         iapViewId: vewbYuvx4z