Просмотр исходного кода

Merge branch 'master' of codeup.aliyun.com:60c06368dbbed34fe0f0c263/job/hr_job-bytedance into pingkang

hpk 11 месяцев назад
Родитель
Сommit
e59f086088
19 измененных файлов с 492 добавлено и 120 удалено
  1. 5 0
      job-bytedance/pom.xml
  2. 178 0
      job-bytedance/src/main/java/cn/com/ctop/job/bytedance/config/FeishuRobotLinkConfig.java
  3. 4 3
      job-bytedance/src/main/java/cn/com/ctop/job/bytedance/controller/FeishuController.java
  4. 9 8
      job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/BytedanceProductUpdateMapper.java
  5. 3 1
      job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/ReportsAdPushMapper.java
  6. 41 8
      job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/xml/BytedanceProductUpdateMapper.xml
  7. 36 10
      job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/xml/CPSReportMapper.xml
  8. 26 16
      job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/xml/ReportsAdPushMapper.xml
  9. 2 0
      job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/IBytedanceProductUpdateService.java
  10. 1 5
      job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/IFeishuDocSyncService.java
  11. 2 0
      job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/IMovieRankPushService.java
  12. 52 22
      job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/BytedanceProductUpdateServiceImpl.java
  13. 39 17
      job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/FeishuDocSyncServiceImpl.java
  14. 44 12
      job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/MovieRankPushServiceImpl.java
  15. 2 2
      job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/ReportsAdPushServiceImpl.java
  16. 6 5
      job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/ReportsByBusinessPushServiceImpl.java
  17. 13 6
      job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/TotalRankPushServiceImpl.java
  18. 22 0
      job-bytedance/src/main/java/cn/com/ctop/job/bytedance/utils/FeishuRobotUtil.java
  19. 7 5
      job-bytedance/src/main/resources/application.yml

+ 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);
+
 }

+ 3 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/ReportsAdPushMapper.java

@@ -30,7 +30,7 @@ public interface ReportsAdPushMapper {
     Map<String, String> adDailyData(@Param("date") Long date);
     Map<String, String> adHourData(@Param("date") Long date, @Param("hour") String hour);
 
-    List<JSONObject> todayTopMovie(@Param("date") Long date, @Param("hour") String hour);
+    List<JSONObject> todayTopMovie(@Param("date") Long date, @Param("hour") String hour, @Param("sort") String sort);
     //所有优化师消耗排名
     List<Map<String, String>> optimizerCostRank(@Param("date") Long date, @Param("hour") String hour);
     //优化师当日数据
@@ -40,6 +40,8 @@ public interface ReportsAdPushMapper {
     //全部部门排行
     List<Map<String, String>> deptCostRank(@Param("date") Long date, @Param("hour") String hour);
 
+    String hourUpdateTime(@Param("date") Long date, @Param("hour") Integer hour);
+
 
 
     //漏绑账户预警

+ 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>

+ 36 - 10
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/xml/CPSReportMapper.xml

@@ -404,7 +404,7 @@
 
     <insert id="runCPSIapSettlementData">
         replace into deepthink.distribution_iap_settlement
-        (stat_date, link_id, app_id, person_id, person_pid, company_id, all_pay_amount, all_refund_amount, all_settlement_amount, virtual_pay_amount, virtual_commission_amount, virtual_refund_amount, virtual_settlement_amount, un_virtual_pay_amount, un_virtual_commission_amount, un_virtual_refund_amount, un_virtual_settlement_amount)
+        (stat_date, link_id, app_id, person_id, person_pid, company_id, all_pay_amount, all_refund_amount, all_settlement_amount, virtual_pay_amount, virtual_commission_amount, virtual_refund_amount, virtual_settlement_amount, un_virtual_pay_amount, un_virtual_commission_amount, un_virtual_refund_amount, un_virtual_settlement_amount,virtual_ad_amount,virtual_ad_settlement_amount)
         select
         #{dateLong} as stat_date,
         ifnull(link_id, 0) as link_id,
@@ -424,7 +424,9 @@
         (wx_common_commission_amount+tt_common_commission_amount) un_virtual_commission_amount,
         (wx_common_refund_amount+tt_common_refund_amount) un_virtual_refund_amount,
         (wx_common_pay_amount-wx_common_commission_amount-wx_common_refund_amount) * wx_common_scale_rate
-        + (tt_common_pay_amount-tt_common_commission_amount-tt_common_refund_amount) * tt_common_scale_rate as un_virtual_settlement_amount
+        + (tt_common_pay_amount-tt_common_commission_amount-tt_common_refund_amount) * tt_common_scale_rate as un_virtual_settlement_amount,
+        wx_virtual_pay_amount * 0.05 as virtual_ad_amount,
+        wx_virtual_pay_amount * 0.05 * wx_ad_amount_scale_rate as virtual_ad_settlement_amount
         from
         (select
         stat_date, t2.*,
@@ -465,8 +467,22 @@
         ifnull(scale_wx_common.scale/100.0, 0) as wx_common_scale_rate,
         ifnull(scale_wx_common.commission_scale/100.0, 0) as wx_common_commission_rate,
         ifnull(scale_tt_common.scale/100.0, 0) as tt_common_scale_rate,
-        ifnull(scale_tt_common.commission_scale/100.0, 0) as tt_common_commission_rate
+        ifnull(scale_tt_common.commission_scale/100.0, 0) as tt_common_commission_rate,
+        ifnull(scale_wx_ad_amount.scale/100.0, 0) as wx_ad_amount_scale_rate
         from thirtpart.ly_link l
+            join
+        (
+        select  link_id
+        from thirtpart.ly_pay_record p
+        where consume_date=#{dateLong} and status=1
+        group by 1
+        union
+        select link_id
+        from thirtpart.ly_refund_record lrr
+        where refund_time &gt;= concat(#{dateStr}, ' 00:00:00') and refund_time &lt;= concat(#{dateStr}, ' 23:59:59')
+        and status = 1
+        group by 1
+        ) t1 on l.id = t1.link_id
         join thirtpart.ly_responsibility_person p on l.responsibility_person_id = p.id
         left join thirtpart.ly_official_accounts a on l.official_account_id = a.id
         left join thirtpart.ly_applet la on a.applet_id = la.id
@@ -475,12 +491,15 @@
         ) scale_wx_virtual on p.company_id = scale_wx_virtual.company_id
         left join (select company_id, scale, ifnull(commission_scale, 1) as commission_scale from thirtpart.ly_responsibility_person_scale where source=1
         and #{st} &gt;= start_time and #{st} &lt;= end_time
-        ) scale_wx_common on p.company_id = scale_wx_virtual.company_id
+        ) scale_wx_common on p.company_id = scale_wx_common.company_id
         left join (select company_id, scale, ifnull(commission_scale, 1) as commission_scale from thirtpart.ly_responsibility_person_scale where source=2
         and #{st} &gt;= start_time and #{st} &lt;= end_time
         ) scale_tt_common on p.company_id = scale_tt_common.company_id
+        left join (select company_id, scale from thirtpart.ly_responsibility_person_scale where source=12
+        and #{st} &gt;= start_time and #{st} &lt;= end_time
+        ) scale_wx_ad_amount on p.company_id = scale_wx_ad_amount.company_id
 <!--        where p.is_distributor = 1 or p.pid in (select id from thirtpart.ly_responsibility_person where is_distributor=1)-->
-        group by 1,2,3,4,5,6,7,8,9,10,11
+        group by 1,2,3,4,5,6,7,8,9,10,11,12
         ) t2 on t1.link_id = t2.link_id
         left join
         (
@@ -497,7 +516,7 @@
         and status = 1
         group by 1,2,3
         )t4 on t1.stat_date = t4.refund_date and t1.link_id = t4.link_id and t1.pay_merchant=t4.pay_merchant
-        group by consume_date, t2.person_id) tb
+        group by consume_date, t2.person_id, t2.link_id) tb
 
     </insert>
     <select id="runCPSIaaDySettlementData" resultType="com.alibaba.fastjson.JSONObject">
@@ -543,9 +562,11 @@
     <select id="runCPSIaaWxSettlementData" resultType="com.alibaba.fastjson.JSONObject">
         select stat_date, link_id, app_id, person_id, person_pid, company_id,
         ad_total_income, ad_play_user_count,
-        ad_total_income*scale/100.0 ad_settlement_amount
+        ad_total_income*scale/100.0 ad_settlement_amount,
+        ad_total_income*0.1 ad_amount,
+        ad_total_income*0.1*ad_scale/100.0 ad_amount_scale_rate
         from
-            (select t1.stat_date, t1.link_id,t1.app_id, lrp.id as person_id, lrp.pid as person_pid, lrp.company_id, scale.scale,
+            (select t1.stat_date, t1.link_id,t1.app_id, lrp.id as person_id, lrp.pid as person_pid, lrp.company_id, scale.scale,ad_scale.scale as ad_scale,
                     (ifnull(income,0))/100*(link_count/all_count) ad_total_income,
                     ifnull(user_count, 0) ad_play_user_count
              from (
@@ -586,6 +607,9 @@
                       left join (select company_id, scale, ifnull(commission_scale, 10) as commission_scale from tidb.thirtpart.ly_responsibility_person_scale
                                  where source=8 and #{st} &gt;= start_time and #{st} &lt;= end_time
              ) scale on lrp.company_id = scale.company_id
+                      left join (select company_id, scale from tidb.thirtpart.ly_responsibility_person_scale
+                                 where source=13 and #{st} &gt;= start_time and #{st} &lt;= end_time
+             ) ad_scale on lrp.company_id = ad_scale.company_id
              where link_id is not null and link_id != ''
             )tb
     </select>
@@ -595,7 +619,7 @@
     <update id="saveIaaWxSettlementData">
         replace into deepthink.distrubution_iaa_weixin_settlement
         (stat_date, link_id, app_id, person_id, person_pid, company_id,
-        ad_total_income, ad_play_user_count, ad_settlement_amount)
+        ad_total_income, ad_play_user_count, ad_settlement_amount,ad_amount,ad_amount_scale_rate)
         values
         <foreach collection="list" item="item" separator=",">
             (
@@ -607,7 +631,9 @@
             #{item.company_id},
             #{item.ad_total_income},
             #{item.ad_play_user_count},
-            #{item.ad_settlement_amount}
+            #{item.ad_settlement_amount},
+            #{item.ad_amount},
+            #{item.ad_amount_scale_rate}
             )
         </foreach>
     </update>

+ 26 - 16
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/xml/ReportsAdPushMapper.xml

@@ -108,7 +108,7 @@
         ) tb2
     </select>
     <select id="tmpTopMovie" resultType="java.util.Map">
-        select tb4.standard_movie_name as movie_name, tb4.movie_project_source, tb5.dict_name as movie_project_source_name,
+        select tb4.ly_movie_name as movie_name, tb4.movie_project_source, tb5.dict_name as movie_project_source_name,
         group_concat(distinct case tb4.movie_source when 2 then '2' else '1' end) as movie_source,
         rank() over (order by sum(iaa_amount)+sum(pay_amount) desc) as rk,
         <include refid="endAmount"/>,
@@ -148,13 +148,13 @@
         group by movie_id
         ) tb3 on tb1.movie_id=tb3.movie_id
         left join
-        (select moive_id, standard_movie_id, standard_movie_name, movie_source, movie_project_source from tidb.deepthink.all_moive
+        (select moive_id, standard_movie_id, standard_movie_name, movie_source, movie_project_source,ly_movie_name from tidb.deepthink.all_moive
         ) tb4 on tb1.movie_id=tb4.moive_id
         left join
         (select dict_key, dict_name from tidb.deepthink.dt_dictionary where select_key='movie_project_source'
         ) tb5 on tb4.movie_project_source=tb5.dict_key
         where 1=1 and tb1.movie_id!='-9999'
-        group by tb4.standard_movie_name, tb4.movie_project_source, tb5.dict_name
+        group by tb4.ly_movie_name, tb4.movie_project_source, tb5.dict_name
         order by sum(iaa_amount)+sum(pay_amount) desc
         limit 20
     </select>
@@ -184,7 +184,7 @@
 
     <select id="todayTopMovie" resultType="com.alibaba.fastjson.JSONObject" >
         select
-        tb4.standard_movie_name as movie_name, tb4.movie_project_source, tb6.dict_name as movie_project_source_name,
+        tb4.ly_movie_name as movie_name, tb4.movie_project_source, tb6.dict_name as movie_project_source_name,
         case
         when (DATEDIFF(STR_TO_DATE(tb1.stat_date, '%Y%m%d'), STR_TO_DATE(tb4.project_ad_date, '%Y%m%d')) + 1) between 1
         and 3 then '新剧1阶'
@@ -203,6 +203,8 @@
         <include refid="iapRoi"/>,
         <include refid="sharePayAmount"/>,
         <include refid="shareIaaAmount3"/>,
+        <include refid="iaaCostAmount"/>,
+        <include refid="iapCostAmount"/>,
         round(ifnull(sum(hour_cost_amount), 0), 2) as hour_cost_amount
         from
         (select ${date} as stat_date, movie_id from application.media_ad_report_daily where stat_date=${date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_type not in (2,4,6))
@@ -232,7 +234,7 @@
         group by movie_id
         ) tb3 on tb1.movie_id=tb3.movie_id
         left join
-        (select moive_id, standard_movie_id, standard_movie_name, movie_source, movie_project_source,project_ad_date from tidb.deepthink.all_moive
+        (select moive_id, standard_movie_id, standard_movie_name, movie_source, movie_project_source,project_ad_date, ly_movie_name from tidb.deepthink.all_moive
         ) tb4 on tb1.movie_id=tb4.moive_id
         left join
         (select movie_id, ifnull(sum(cost_amount), 0) as hour_cost_amount from application.media_ad_report_hourly
@@ -243,7 +245,7 @@
         ) tb6 on tb4.movie_project_source=tb6.dict_key
         where 1=1 and tb1.movie_id != '-9999'
         group by 1,2,3,4
-        order by end_amount desc
+        order by ${sort}
         limit 20
     </select>
 
@@ -255,7 +257,7 @@
         <include refid="iaaRoi"/>,
         <include refid="iapRoi"/>
         from
-        (select cast(advertiser_id as char) advertiser_id, user_id from tidb.deepthink.advertiser_bind_info) tb1
+        (select cast(advertiser_id as char) advertiser_id, user_id from tidb.deepthink.advertiser_bind_info where user_id is not null) tb1
         left join
         (select advertiser_id, sum(iaa_cost_amount) as iaa_cost_amount, sum(iaa_real_cost_amount) as iaa_real_cost_amount,
         sum(iap_cost_amount) as iap_cost_amount, sum(iap_real_cost_amount) as iap_real_cost_amount,
@@ -302,7 +304,7 @@
         <include refid="endAmount"/>,
         rank() over (order by sum(cost_amount) desc) as rk
         from
-        (select cast(advertiser_id as char) advertiser_id, user_id from tidb.deepthink.advertiser_bind_info) tb1
+        (select cast(advertiser_id as char) advertiser_id, user_id from tidb.deepthink.advertiser_bind_info where user_id is not null) tb1
         left join
         (select advertiser_id, sum(cost_amount) as cost_amount, sum(real_cost_amount) as real_cost_amount, max(update_time) as update_time
         from application.media_ad_report_daily
@@ -335,7 +337,7 @@
         <include refid="endAmount"/>,
         max(tb2.update_time) as update_time
         from
-        (select cast(advertiser_id as char) advertiser_id, user_id from tidb.deepthink.advertiser_bind_info) tb1
+        (select cast(advertiser_id as char) advertiser_id, user_id from tidb.deepthink.advertiser_bind_info where user_id is not null) tb1
         left join
         (select advertiser_id, sum(cost_amount) as cost_amount, sum(real_cost_amount) as real_cost_amount, max(update_time) as update_time
         from application.media_ad_report_hourly
@@ -360,7 +362,7 @@
         <include refid="costAmount"/>,
         ifnull(sum(cost_amount_hour), 0) as cost_amount_hour
         from
-        (select cast(advertiser_id as char) advertiser_id, user_id from tidb.deepthink.advertiser_bind_info) tb1
+        (select cast(advertiser_id as char) advertiser_id, user_id from tidb.deepthink.advertiser_bind_info where user_id is not null) tb1
         left join (select advertiser_id, sum(cost_amount) as cost_amount, sum(real_cost_amount) as real_cost_amount
         from application.media_ad_report_daily where stat_date=#{date}  and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_type not in (2,4,6))
         group by advertiser_id) tb2
@@ -379,7 +381,6 @@
         select dept_id, dept_name, dept_id as sub_dept_id, dept_name as sub_dept_name from tidb.deepthink.sys_dept where parent_id in (select dept_id from tidb.deepthink.sys_dept where parent_id=300)
         ) tb5
         on tb4.dept_id = tb5.sub_dept_id
-        where tb1.user_id is not null
         group by tb5.dept_id, tb5.dept_name
         having sum(cost_amount)>1
         order by rk asc
@@ -458,7 +459,7 @@
         <include refid="iaaRoi"/>,
         <include refid="iapRoi"/>
         from
-        (select cast(advertiser_id as char) advertiser_id, user_id from tidb.deepthink.advertiser_bind_info) tb1
+        (select cast(advertiser_id as char) advertiser_id, user_id from tidb.deepthink.advertiser_bind_info where user_id is not null) tb1
         left join
         (select advertiser_id, sum(iaa_cost_amount) as iaa_cost_amount, sum(iaa_real_cost_amount) as iaa_real_cost_amount,
         sum(iap_cost_amount) as iap_cost_amount, sum(iap_real_cost_amount) as iap_real_cost_amount,
@@ -550,10 +551,11 @@
         ) tb2
     </select>
     <select id="allBusinessTopMovie" resultType="java.util.Map">
-        select tb4.standard_movie_name as movie_name, tb4.movie_project_source, tb5.dict_name as movie_project_source_name,
+        select tb4.ly_movie_name as movie_name, tb4.movie_project_source, tb5.dict_name as movie_project_source_name,
         group_concat(distinct case tb4.movie_source when 2 then '2' else '1' end) as movie_source,
         rank() over (order by sum(share_iaa_amount)+sum(share_pay_amount) desc) as rk,
         <include refid="endAmount"/>,
+        <include refid="waterEndAmount"/>,
         <include refid="costAmount"/>
         from
         (select movie_id from application.media_ad_report_daily where stat_date=${date}
@@ -574,13 +576,13 @@
         group by movie_id
         ) tb3 on tb1.movie_id=tb3.movie_id
         left join
-        (select moive_id, standard_movie_id, standard_movie_name, movie_source, movie_project_source from tidb.deepthink.all_moive
+        (select moive_id, standard_movie_id, standard_movie_name, movie_source, movie_project_source, ly_movie_name from tidb.deepthink.all_moive
         ) tb4 on tb1.movie_id=tb4.moive_id
         left join
         (select dict_key, dict_name from tidb.deepthink.dt_dictionary where select_key='movie_project_source'
         ) tb5 on tb4.movie_project_source=tb5.dict_key
         where 1=1 and tb1.movie_id!='-9999'
-        group by tb4.standard_movie_name, tb4.movie_project_source, tb5.dict_name
+        group by tb4.ly_movie_name, tb4.movie_project_source, tb5.dict_name
         order by sum(share_iaa_amount)+sum(share_pay_amount) desc
         limit 20
     </select>
@@ -624,7 +626,8 @@
         when sum(tb5.cost_amount) &gt;= 5000000 and sum(tb5.cost_amount) &lt; 10000000 then '500W-1000W'
         when sum(tb5.cost_amount) &lt;= 10000000 then '1000W以上'
         else '未知' end as cost_history,
-        ifnull(sum(tb4.cost_amount), 0) as cost_hour_number
+        ifnull(sum(tb4.cost_amount), 0) as cost_hour_number,
+        ifnull(sum(tb1.cost_amount), 0) as cost_today_number
         from (select ${date} as stat_date, movie_id, sum(cost_amount) as cost_amount from
         application.media_ad_report_daily
         where stat_date=${date}
@@ -651,4 +654,11 @@
           and (u.dept_id in (203,204,205,206)
             or d.parent_id in (203,204,205,206))
     </select>
+    <select id="hourUpdateTime" resultType="java.lang.String">
+        select max(update_time)
+            from
+        (select cast(advertiser_id as char) advertiser_id, user_id from tidb.deepthink.advertiser_bind_info where user_id is not null) tb1
+        left join (select advertiser_id, update_time from application.media_ad_report_hourly where stat_date=#{date} and `hour`=#{hour}) tb2
+        on tb1.advertiser_id=tb2.advertiser_id
+    </select>
 </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();
     /**
      * 同步巨量 端原生分销剧目
      */

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

@@ -4,4 +4,6 @@ public interface IMovieRankPushService {
 
 
     void send();
+
+    void test();
 }

+ 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);
+            }
         }
 
 

+ 44 - 12
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/MovieRankPushServiceImpl.java

@@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
@@ -31,7 +32,7 @@ public class MovieRankPushServiceImpl implements IMovieRankPushService {
     ReportsAdPushMapper reportsAdPushMapper;
 
     public static final String TEMPLATE_ID = "AAqhiuoh0Nohp";
-    public static final String TEMPLATE_VERSION = "1.0.9";
+    public static final String TEMPLATE_VERSION = "1.0.14";
 
     @Override
     public void send() {
@@ -49,10 +50,15 @@ public class MovieRankPushServiceImpl implements IMovieRankPushService {
         List<String> chatIds = Arrays.asList(
 
         );
-        send(userIds, chatIds);
+        send(userIds, chatIds, true);
     }
 
-    private void send(List<String> userIds, List<String> chatIds) {
+    @Override
+    public void test() {
+        send(Arrays.asList("44fbaed6"), Arrays.asList(), false);
+    }
+
+    private void send(List<String> userIds, List<String> chatIds, boolean sendToOptimizers) {
         try {
 
             String today = DateUtils.getNowDate("yyyy-MM-dd");
@@ -61,18 +67,43 @@ public class MovieRankPushServiceImpl implements IMovieRankPushService {
             int lastHour = hour - 1;
             int lastLastHour = hour - 2;
 
-            List<JSONObject> t1 = reportsAdPushMapper.movieTop(todayLong, lastHour, 1, "IAP");
-            List<JSONObject> t2 = reportsAdPushMapper.movieTop(todayLong, lastHour, 1, "IAA");
-            List<JSONObject> t3 = reportsAdPushMapper.movieTop(todayLong, lastHour, 4, "IAP");
-            List<JSONObject> t4 = reportsAdPushMapper.movieTop(todayLong, lastHour, 4, "IAA");
+//            List<JSONObject> t1 = reportsAdPushMapper.movieTop(todayLong, lastHour, 1, "IAP");
+//            List<JSONObject> t2 = reportsAdPushMapper.movieTop(todayLong, lastHour, 1, "IAA");
+//            List<JSONObject> t3 = reportsAdPushMapper.movieTop(todayLong, lastHour, 4, "IAP");
+//            List<JSONObject> t4 = reportsAdPushMapper.movieTop(todayLong, lastHour, 4, "IAA");
 
             JSONObject template_variables = new JSONObject();
             template_variables.put("thisHour", String.valueOf(hour));
             template_variables.put("lastHour", String.valueOf(lastHour));
-            template_variables.put("table_raw_array_1", buildFeishuTable(t1));
-            template_variables.put("table_raw_array_2", buildFeishuTable(t2));
-            template_variables.put("table_raw_array_3", buildFeishuTable(t3));
-            template_variables.put("table_raw_array_4", buildFeishuTable(t4));
+//            template_variables.put("table_raw_array_1", buildFeishuTable(t1));
+//            template_variables.put("table_raw_array_2", buildFeishuTable(t2));
+//            template_variables.put("table_raw_array_3", buildFeishuTable(t3));
+//            template_variables.put("table_raw_array_4", buildFeishuTable(t4));
+
+            List<JSONObject> topMovies = reportsAdPushMapper.todayTopMovie(todayLong, String.valueOf(lastHour), "cost_amount desc");
+            List<JSONObject> object_list = new ArrayList<>();
+            for (JSONObject m : topMovies){
+                JSONObject obj = new JSONObject();
+                Double hourCostAmount = m.getDoubleValue("hour_cost_amount");
+                Double dayCostAmount = m.getDoubleValue("cost_amount");
+                if (hourCostAmount >= 20000 || dayCostAmount >=60000){
+                    obj.put("movieName", "<font color='red'>"+m.getString("movie_name")+"(起量)</font>");
+                    obj.put("hourCostAmount", "<font color='red'>"+hourCostAmount+"</font>");
+                }else {
+                    obj.put("movieName", m.getString("movie_name"));
+                    obj.put("hourCostAmount", ""+hourCostAmount);
+                }
+                obj.put("iaaCostAmount", m.getString("iaa_cost_amount"));
+                obj.put("iapCostAmount", m.getString("iap_cost_amount"));
+                String movieProjectSource = String.valueOf(m.get("movie_project_source_name"));
+                String projectAdStep = m.getString("project_ad_step");
+                String sb = "<text_tag color='blue'>" + movieProjectSource + "</text_tag>" +
+                        "<text_tag color='green'>" + projectAdStep + "</text_tag>";
+                obj.put("movieProjectSource", sb);
+                object_list.add(obj);
+            }
+            template_variables.put("table_raw_array_5", object_list);
+
             List<JSONObject> users = reportsAdPushMapper.selectOptimizerList();
             List<String> mobiles = users.stream().map(user -> user.getString("phonenumber"))
                     .filter(s -> s != null && s.length() == 11)
@@ -113,7 +144,8 @@ public class MovieRankPushServiceImpl implements IMovieRankPushService {
         for (JSONObject t : t1) {
             JSONObject row = new JSONObject();
             Double hourSpeed = t.getDouble("cost_hour_number");
-            if (hourSpeed >= 20000.0) {
+            Double todaySpeed = t.getDouble("cost_today_number");
+            if (hourSpeed >= 20000.0 || todaySpeed >= 60000.0) {
                 row.put("movie_name", "<font color='red'>" + t.getString("standard_movie_name") + "(起量)</font>");
             } else {
                 row.put("movie_name", t.getString("standard_movie_name"));

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

@@ -128,7 +128,7 @@ public class ReportsAdPushServiceImpl implements IReportsAdPushService {
         }
         template_variables.put("object_list_1", object_list_1);
 
-        List<JSONObject> topMovies = reportsPushMapper.todayTopMovie(todayLong, String.valueOf(lastHour));
+        List<JSONObject> topMovies = reportsPushMapper.todayTopMovie(todayLong, String.valueOf(lastHour), "end_amount desc");
         JSONArray object_list_2 = new JSONArray();
         for (JSONObject m : topMovies){
 //            int movieSource = m.getIntValue("movie_source");
@@ -140,7 +140,7 @@ public class ReportsAdPushServiceImpl implements IReportsAdPushService {
 //            obj.put("movieRealRoi", m.get("real_roi"));
             Double hourCostAmount = m.getDoubleValue("hour_cost_amount");
             Double dayCostAmount = m.getDoubleValue("cost_amount");
-            if (hourCostAmount >= 30000 || dayCostAmount >=60000){
+            if (hourCostAmount >= 20000 || dayCostAmount >=60000){
                 obj.put("movieName", "<font color='red'>"+m.getString("movie_name")+"(起量)</font>");
                 obj.put("hourCostAmount", "<font color='red'>"+hourCostAmount+"</font>");
             }else {

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

@@ -36,7 +36,7 @@ public class ReportsByBusinessPushServiceImpl implements IReportsByBusinessPushS
     @Autowired
     ReportsAdPushMapper reportsPushMapper;
 
-    private static final String TEMPLATE_VERSION = "1.0.7";
+    private static final String TEMPLATE_VERSION = "1.0.8";
     private static final String TEMPLATE_ID = "AAq4oeDXECopo";
 
 
@@ -75,10 +75,10 @@ public class ReportsByBusinessPushServiceImpl implements IReportsByBusinessPushS
     public void test(){
         sendParam("", Arrays.asList(
                 "44fbaed6"
-                ,"ebeeced9" //yumeng
-                ,"58e7a98a"  //xsq
-                ,"2ga9669f" //angaoqi
-                ,"43gb7fbc" //huangpingkang
+//                ,"ebeeced9" //yumeng
+//                ,"58e7a98a"  //xsq
+//                ,"2ga9669f" //angaoqi
+//                ,"43gb7fbc" //huangpingkang
                 )
                 , Collections.EMPTY_LIST);
     }
@@ -176,6 +176,7 @@ public class ReportsByBusinessPushServiceImpl implements IReportsByBusinessPushS
             obj.put("movieProjectSource", ms);
             obj.put("rank", String.valueOf(movie.get("rk")));
             obj.put("movieName", movieName);
+            obj.put("waterEndAmount", String.valueOf(movie.get("water_end_amount")));
             obj.put("endAmount", String.valueOf(movie.get("end_amount")));
             movieRankTable.add(obj);
         }

Разница между файлами не показана из-за своего большого размера
+ 13 - 6
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/TotalRankPushServiceImpl.java


+ 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