Ver Fonte

头条失败重试任务

yumeng há 1 ano atrás
pai
commit
ec01263160

+ 15 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/controller/BytedanceController.java

@@ -2,6 +2,7 @@ package cn.com.ctop.job.bytedance.controller;
 
 import cn.com.ctop.job.bytedance.data.service.IBytedancePromoterReportService;
 import cn.com.ctop.job.bytedance.data.service.IBytedanceRefreshTokenService;
+import cn.com.ctop.job.bytedance.data.service.IChannelService;
 import cn.com.ctop.job.bytedance.data.utils.Check;
 import com.alibaba.fastjson.JSONObject;
 import io.swagger.annotations.Api;
@@ -33,6 +34,8 @@ public class BytedanceController {
 
     @Autowired
     private IBytedancePromoterReportService promoterReportService;
+    @Autowired
+    private IChannelService channelService;
 
     @GetMapping("/testRefreshToken")
     public void testRefreshToken() {
@@ -67,4 +70,16 @@ public class BytedanceController {
     }
 
 
+    @GetMapping("/getChannel")
+    public void getChannel() {
+        List<JSONObject> channelList = promoterReportService.getChannelInfoList();
+        for (int i = 0; i < channelList.size(); i++) {
+            JSONObject jsonObject = channelList.get(i);
+            String channelAccountId = jsonObject.getString("channelAccountId");
+            String secretKey = jsonObject.getString("secretKey");
+            channelService.getPromotionIdList(channelAccountId, secretKey, 0);
+        }
+    }
+
+
 }

+ 157 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/entity/ChannelChangdunovelInfo.java

@@ -0,0 +1,157 @@
+package cn.com.ctop.job.bytedance.data.entity;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+
+/**
+ * 番茄-推广链短剧列对象 channel_changdunovel_info
+ *
+ * @author ruoyi
+ * @date 2025-03-08
+ */
+public class ChannelChangdunovelInfo {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 推广链id
+     */
+    private Long distributorId;
+    private Long promotionId;
+
+    /**
+     * 推广链别名
+     */
+    private String promotionName;
+
+    /**
+     * 短剧id
+     */
+    private Long movieId;
+
+    /**
+     * 短剧ID
+     */
+    private String movieName;
+
+    /**
+     * 推广链url
+     */
+    private String promotionUrl;
+
+    /**
+     * 监控url
+     */
+    private String monitorUrl;
+
+    /**
+     * 短剧:1 字节、3 快手、4 腾讯(广点通)、7 百度
+     */
+    private Long mediaSource;
+
+    /**
+     * 广告回传配置id,0代表平台默认规则
+     */
+    private Long adCallbackConfigId;
+
+    /**
+     * 广告回传配置id,0代表平台默认规则
+     */
+    private String promotionHttpUrl;
+
+    public Long getPromotionId() {
+        return promotionId;
+    }
+
+    public void setPromotionId(Long promotionId) {
+        this.promotionId = promotionId;
+    }
+
+    public String getPromotionName() {
+        return promotionName;
+    }
+
+    public void setPromotionName(String promotionName) {
+        this.promotionName = promotionName;
+    }
+
+    public Long getMovieId() {
+        return movieId;
+    }
+
+    public void setMovieId(Long movieId) {
+        this.movieId = movieId;
+    }
+
+    public String getMovieName() {
+        return movieName;
+    }
+
+    public void setMovieName(String movieName) {
+        this.movieName = movieName;
+    }
+
+    public String getPromotionUrl() {
+        return promotionUrl;
+    }
+
+    public void setPromotionUrl(String promotionUrl) {
+        this.promotionUrl = promotionUrl;
+    }
+
+    public String getMonitorUrl() {
+        return monitorUrl;
+    }
+
+    public Long getDistributorId() {
+        return distributorId;
+    }
+
+    public void setDistributorId(Long distributorId) {
+        this.distributorId = distributorId;
+    }
+
+    public void setMonitorUrl(String monitorUrl) {
+        this.monitorUrl = monitorUrl;
+    }
+
+    public Long getMediaSource() {
+        return mediaSource;
+    }
+
+    public void setMediaSource(Long mediaSource) {
+        this.mediaSource = mediaSource;
+    }
+
+    public Long getAdCallbackConfigId() {
+        return adCallbackConfigId;
+    }
+
+    public void setAdCallbackConfigId(Long adCallbackConfigId) {
+        this.adCallbackConfigId = adCallbackConfigId;
+    }
+
+    public String getPromotionHttpUrl() {
+        return promotionHttpUrl;
+    }
+
+    public void setPromotionHttpUrl(String promotionHttpUrl) {
+        this.promotionHttpUrl = promotionHttpUrl;
+    }
+
+    @Override
+    public String toString() {
+        return "ChannelChangdunovelInfo{" +
+                "distributorId=" + distributorId +
+                ", promotionId=" + promotionId +
+                ", promotionName='" + promotionName + '\'' +
+                ", movieId=" + movieId +
+                ", movieName='" + movieName + '\'' +
+                ", promotionUrl='" + promotionUrl + '\'' +
+                ", monitorUrl='" + monitorUrl + '\'' +
+                ", mediaSource=" + mediaSource +
+                ", adCallbackConfigId=" + adCallbackConfigId +
+                ", promotionHttpUrl='" + promotionHttpUrl + '\'' +
+                '}';
+    }
+}

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

@@ -16,4 +16,6 @@ public interface BytedancePromoterReportMapper {
     void deleteInfoByErrorId(@Param("errorId") Long errorId);
 
     void replacePromoterReportDailies(@Param("list") List<BytedancePromoterReportDaily> promoterReportDailies);
+
+    List<JSONObject> getChannelInfoList();
 }

+ 10 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/ChannelMapper.java

@@ -0,0 +1,10 @@
+package cn.com.ctop.job.bytedance.data.mapper;
+
+import cn.com.ctop.job.bytedance.data.entity.ChannelChangdunovelInfo;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+public interface ChannelMapper {
+    void repalceChannels(@Param("adds") List<ChannelChangdunovelInfo> adds);
+}

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

@@ -13,6 +13,11 @@
                  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
     </select>
+    <select id="getChannelInfoList" resultType="com.alibaba.fastjson.JSONObject">
+        select channel_account_id as 'channelAccountId',
+                secret_key         as 'secretKey'
+        from deepthink.channel_account_info
+    </select>
 
     <insert id="replacePromoterReportHour">
         replace into bytedance_promoter_report_hour (

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

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="cn.com.ctop.job.bytedance.data.mapper.ChannelMapper">
+
+
+    <insert id="repalceChannels">
+        replace into deepthink.channel_changdunovel_info (
+        distributor_id,
+        promotion_id,
+        promotion_name,
+        movie_id,
+        movie_name,
+        promotion_url,
+        monitor_url,
+        media_source,
+        ad_callback_config_id,
+        promotion_http_url
+        )
+        values
+        <foreach collection="adds" item="item" separator=",">
+            (
+            #{item.distributorId},
+            #{item.promotionId},
+            #{item.promotionName},
+            #{item.movieId},
+            #{item.movieName},
+            #{item.promotionUrl},
+            #{item.monitorUrl},
+            #{item.mediaSource},
+            #{item.adCallbackConfigId},
+            #{item.promotionHttpUrl}
+            )
+        </foreach>
+
+    </insert>
+</mapper>

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

@@ -11,4 +11,6 @@ public interface IBytedancePromoterReportService {
     void getBytedancePromoterHourReport(Long errorId, Long advertiserId, String accessToken, String startDate, String endDate, Integer page);
 
     void getBytedancePromorteDailyReport(Long errorId, Long advertiserId, String accessToken, String startDate, String endDate, Integer page);
+
+    List<JSONObject> getChannelInfoList();
 }

+ 5 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/IChannelService.java

@@ -0,0 +1,5 @@
+package cn.com.ctop.job.bytedance.data.service;
+
+public interface IChannelService {
+     void   getPromotionIdList(String distributorId, String secretKey,Integer offset);
+}

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

@@ -183,4 +183,9 @@ public class BytedancePromoterReportServiceImpl implements IBytedancePromoterRep
 
         }
     }
+
+    @Override
+    public List<JSONObject> getChannelInfoList() {
+        return promoterReportMapper.getChannelInfoList();
+    }
 }

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

@@ -0,0 +1,90 @@
+package cn.com.ctop.job.bytedance.data.service.impl;
+
+import cn.com.ctop.job.bytedance.data.entity.BytedancePromoterReportHour;
+import cn.com.ctop.job.bytedance.data.entity.ChannelChangdunovelInfo;
+import cn.com.ctop.job.bytedance.data.mapper.ChannelMapper;
+import cn.com.ctop.job.bytedance.data.service.IChannelService;
+import cn.com.ctop.job.bytedance.data.utils.Check;
+import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.crypto.SecureUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@Service
+@Slf4j
+public class ChannelServiceImpl implements IChannelService {
+    @Autowired
+    private ChannelMapper channelMapper;
+
+    @Override
+    public void getPromotionIdList(String distributorId, String secretKey, Integer offset) {
+        try {
+            String url = "https://www.changdunovel.com/novelsale/openapi/promotion/list/v1";
+            String ts = String.valueOf(System.currentTimeMillis()).substring(0, 10);
+            String sign = getSign(distributorId, secretKey, ts);
+            Map<String, Object> params = new JSONObject();
+            params.put("distributor_id", distributorId);
+            params.put("ts", ts);
+            params.put("offset", offset);
+            params.put("limit", 1000);
+            params.put("sign", sign);
+            Boolean has_more = false;
+            String s = HttpUtils.httpGet(url, params, null);
+            JSONObject jsonObject = JSONObject.parseObject(s);
+            List<ChannelChangdunovelInfo> adds = new ArrayList<>();
+            if (!Check.isNull(jsonObject)) {
+                Integer code = jsonObject.getInteger("code");
+                if (code == 200) {
+                    has_more = jsonObject.getBoolean("has_more");
+                    offset = jsonObject.getInteger("next_offset");
+                    JSONArray result = jsonObject.getJSONArray("result");
+                    if (!Check.isNull(result)) {
+                        for (int i = 0; i < result.size(); i++) {
+                            JSONObject resultJson = result.getJSONObject(i);
+                            ChannelChangdunovelInfo channelChangdunovelInfo = JSONObject.parseObject(resultJson.toJSONString(), ChannelChangdunovelInfo.class);
+                            channelChangdunovelInfo.setMovieId(resultJson.getLong("book_id"));
+                            channelChangdunovelInfo.setMovieName(resultJson.getString("book_name"));
+                            channelChangdunovelInfo.setDistributorId(Long.valueOf(distributorId));
+                            adds.add(channelChangdunovelInfo);
+                        }
+                    }
+                } else {
+                    log.error("番茄请求失败,返回信息:{}", jsonObject);
+                    return;
+                }
+            } else {
+                log.error("返回数据为空");
+            }
+
+            if (!Check.isNull(adds)) {
+                channelMapper.repalceChannels(adds);
+            }
+
+            if (has_more) {
+                getPromotionIdList(distributorId, secretKey, offset);
+            } else {
+                log.info("番茄推广链拉取成功,distributorId:{}", distributorId);
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+
+        }
+
+    }
+
+
+    private static String getSign(String distributorId, String secretKey, String ts) {
+        return SecureUtil.md5(distributorId + secretKey + ts).toLowerCase();
+    }
+
+
+}

+ 19 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedancePromoterReportJob.java

@@ -2,6 +2,7 @@ package cn.com.ctop.job.bytedance.handler;
 
 
 import cn.com.ctop.job.bytedance.data.service.IBytedancePromoterReportService;
+import cn.com.ctop.job.bytedance.data.service.IChannelService;
 import cn.com.ctop.job.bytedance.data.utils.Check;
 import com.alibaba.fastjson.JSONObject;
 import com.xxl.job.core.handler.annotation.XxlJob;
@@ -24,6 +25,8 @@ import java.util.concurrent.Executors;
 public class BytedancePromoterReportJob {
     @Autowired
     private IBytedancePromoterReportService promoterReportService;
+    @Autowired
+    private IChannelService channelService;
     private static ExecutorService dailyExecutorService = Executors.newFixedThreadPool(2);
     private static ExecutorService hourrExecutorService = Executors.newFixedThreadPool(2);
 
@@ -75,4 +78,20 @@ public class BytedancePromoterReportJob {
     }
 
 
+    @XxlJob("getPromoterList")
+    public void getPromoterList() throws Exception {
+        List<JSONObject>  channelList = promoterReportService.getChannelInfoList();
+        for (int i = 0; i < channelList.size(); i++) {
+            JSONObject jsonObject = channelList.get(i);
+            String channelAccountId = jsonObject.getString("channelAccountId");
+            String secretKey = jsonObject.getString("secretKey");
+            channelService.getPromotionIdList(channelAccountId,secretKey,0);
+        }
+
+
+
+
+    }
+
+
 }