yumeng 8 месяцев назад
Родитель
Сommit
80a1a0a331

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

@@ -57,6 +57,18 @@ public class BytedanceController {
 
     @Autowired
     private IClTaskStatusService clTaskStatusService;
+    @Autowired
+    private IAdvertiserFundGetServer advertiserFundGetServer;
+
+
+    @GetMapping("/getAdvertiserFundGet")
+    public void getAdvertiserFundGet() {
+        Long advertiserId =1851213792607364L;
+        String accessToken = "d99c62d791180d2a6adfe149f5996e0a769acbdd";
+        advertiserFundGetServer.getAdvertiserFundGet( advertiserId, accessToken );
+
+
+    }
 
 
     @GetMapping("/getCLTaskStatus")

+ 289 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/entity/BytedanceAdvertiserFund.java

@@ -0,0 +1,289 @@
+package cn.com.ctop.job.bytedance.data.entity;
+
+import java.math.BigDecimal;
+
+public class BytedanceAdvertiserFund {
+    private Long advertiserId;
+
+    /**
+     * 数据起始时间
+     */
+    private Integer statDate;
+
+    /**
+     * 账户绑定的子钱包的可用共享余额(单位元)
+     */
+    private BigDecimal walletTotalBalanceValid;
+
+    /**
+     * 返货可用余额(单位元),仅支持部分客户
+     */
+    private BigDecimal validReturnGoodsAbs;
+
+    /**
+     * 返货支出(单位元),仅支持部分客户
+     */
+    private BigDecimal returnGoodsCost;
+
+    /**
+     * 默认投放版位可用赠款余额(单位元)
+     */
+    private BigDecimal defaultGrant;
+
+    /**
+     * 账户总余额(单位元)
+     */
+    private BigDecimal balance;
+
+    /**
+     * 返货余额(单位元),仅支持部分客户
+     */
+    private BigDecimal returnGoodsAbs;
+
+    /**
+     * 现金可用余额(单位元)
+     */
+    private BigDecimal validCash;
+
+    /**
+     * 搜索投放版位可用赠款余额(单位元)
+     */
+    private BigDecimal searchGrant;
+
+    /**
+     * 通用投放版位可用赠款余额(单位元)
+     */
+    private BigDecimal commonGrant;
+
+    /**
+     * 账户可用总余额(单位元)
+     */
+    private BigDecimal validBalance;
+
+    /**
+     * 赠款余额(单位元)
+     * 注意:grant是MySQL保留字,映射时需特殊处理
+     */
+    private BigDecimal grant;
+
+    /**
+     * 现金余额(单位元)
+     */
+    private BigDecimal cash;
+
+    /**
+     * 赠款可用余额(单位元)
+     */
+    private BigDecimal validGrant;
+
+    /**
+     * 穿山甲投放版位可用赠款余额(单位元)
+     */
+    private BigDecimal unionGrant;
+
+    /**
+     * 钱包名称(投放账户绑定的共享子钱包名称)
+     */
+    private String walletName;
+
+    /**
+     * 账户名
+     */
+    private String name;
+
+    /**
+     * 钱包id(投放账户绑定的共享子钱包id)
+     */
+    private String walletId;
+
+    /**
+     * 联系邮箱
+     */
+    private String email;
+
+    public Long getAdvertiserId() {
+        return advertiserId;
+    }
+
+    public void setAdvertiserId(Long advertiserId) {
+        this.advertiserId = advertiserId;
+    }
+
+    public Integer getStatDate() {
+        return statDate;
+    }
+
+    public void setStatDate(Integer statDate) {
+        this.statDate = statDate;
+    }
+
+    public BigDecimal getWalletTotalBalanceValid() {
+        return walletTotalBalanceValid;
+    }
+
+    public void setWalletTotalBalanceValid(BigDecimal walletTotalBalanceValid) {
+        this.walletTotalBalanceValid = walletTotalBalanceValid;
+    }
+
+    public BigDecimal getValidReturnGoodsAbs() {
+        return validReturnGoodsAbs;
+    }
+
+    public void setValidReturnGoodsAbs(BigDecimal validReturnGoodsAbs) {
+        this.validReturnGoodsAbs = validReturnGoodsAbs;
+    }
+
+    public BigDecimal getReturnGoodsCost() {
+        return returnGoodsCost;
+    }
+
+    public void setReturnGoodsCost(BigDecimal returnGoodsCost) {
+        this.returnGoodsCost = returnGoodsCost;
+    }
+
+    public BigDecimal getDefaultGrant() {
+        return defaultGrant;
+    }
+
+    public void setDefaultGrant(BigDecimal defaultGrant) {
+        this.defaultGrant = defaultGrant;
+    }
+
+    public BigDecimal getBalance() {
+        return balance;
+    }
+
+    public void setBalance(BigDecimal balance) {
+        this.balance = balance;
+    }
+
+    public BigDecimal getReturnGoodsAbs() {
+        return returnGoodsAbs;
+    }
+
+    public void setReturnGoodsAbs(BigDecimal returnGoodsAbs) {
+        this.returnGoodsAbs = returnGoodsAbs;
+    }
+
+    public BigDecimal getValidCash() {
+        return validCash;
+    }
+
+    public void setValidCash(BigDecimal validCash) {
+        this.validCash = validCash;
+    }
+
+    public BigDecimal getSearchGrant() {
+        return searchGrant;
+    }
+
+    public void setSearchGrant(BigDecimal searchGrant) {
+        this.searchGrant = searchGrant;
+    }
+
+    public BigDecimal getCommonGrant() {
+        return commonGrant;
+    }
+
+    public void setCommonGrant(BigDecimal commonGrant) {
+        this.commonGrant = commonGrant;
+    }
+
+    public BigDecimal getValidBalance() {
+        return validBalance;
+    }
+
+    public void setValidBalance(BigDecimal validBalance) {
+        this.validBalance = validBalance;
+    }
+
+    public BigDecimal getGrant() {
+        return grant;
+    }
+
+    public void setGrant(BigDecimal grant) {
+        this.grant = grant;
+    }
+
+    public BigDecimal getCash() {
+        return cash;
+    }
+
+    public void setCash(BigDecimal cash) {
+        this.cash = cash;
+    }
+
+    public BigDecimal getValidGrant() {
+        return validGrant;
+    }
+
+    public void setValidGrant(BigDecimal validGrant) {
+        this.validGrant = validGrant;
+    }
+
+    public BigDecimal getUnionGrant() {
+        return unionGrant;
+    }
+
+    public void setUnionGrant(BigDecimal unionGrant) {
+        this.unionGrant = unionGrant;
+    }
+
+    public String getWalletName() {
+        return walletName;
+    }
+
+    public void setWalletName(String walletName) {
+        this.walletName = walletName;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getWalletId() {
+        return walletId;
+    }
+
+    public void setWalletId(String walletId) {
+        this.walletId = walletId;
+    }
+
+    public String getEmail() {
+        return email;
+    }
+
+    public void setEmail(String email) {
+        this.email = email;
+    }
+
+    @Override
+    public String toString() {
+        return "BytedanceAdvertiserFund{" +
+                "advertiserId=" + advertiserId +
+                ", statDate=" + statDate +
+                ", walletTotalBalanceValid=" + walletTotalBalanceValid +
+                ", validReturnGoodsAbs=" + validReturnGoodsAbs +
+                ", returnGoodsCost=" + returnGoodsCost +
+                ", defaultGrant=" + defaultGrant +
+                ", balance=" + balance +
+                ", returnGoodsAbs=" + returnGoodsAbs +
+                ", validCash=" + validCash +
+                ", searchGrant=" + searchGrant +
+                ", commonGrant=" + commonGrant +
+                ", validBalance=" + validBalance +
+                ", grant=" + grant +
+                ", cash=" + cash +
+                ", validGrant=" + validGrant +
+                ", unionGrant=" + unionGrant +
+                ", walletName='" + walletName + '\'' +
+                ", name='" + name + '\'' +
+                ", walletId='" + walletId + '\'' +
+                ", email='" + email + '\'' +
+                '}';
+    }
+}

+ 7 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/AdvertiserFundGetMapper.java

@@ -0,0 +1,7 @@
+package cn.com.ctop.job.bytedance.data.mapper;
+
+import cn.com.ctop.job.bytedance.data.entity.BytedanceAdvertiserFund;
+
+public interface AdvertiserFundGetMapper {
+    void insertData(BytedanceAdvertiserFund advertiserFund);
+}

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

@@ -0,0 +1,51 @@
+<?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.AdvertiserFundGetMapper">
+
+
+    <insert id="insertData">
+        replace INTO media_api.bytedance_advertiser_fund (
+            advertiser_id,
+            stat_date,
+            wallet_total_balance_valid,
+            valid_return_goods_abs,
+            return_goods_cost,
+            default_grant,
+            balance,
+            return_goods_abs,
+            valid_cash,
+            search_grant,
+            common_grant,
+            valid_balance,
+            `grant`,
+            cash,
+            valid_grant,
+            union_grant,
+            wallet_name,
+            name,
+            wallet_id,
+            email
+        ) VALUES (
+                     #{advertiserId},
+                     #{statDate},
+                     #{walletTotalBalanceValid},
+                     #{validReturnGoodsAbs},
+                     #{returnGoodsCost},
+                     #{defaultGrant},
+                     #{balance},
+                     #{returnGoodsAbs},
+                     #{validCash},
+                     #{searchGrant},
+                     #{commonGrant},
+                     #{validBalance},
+                     #{grant},
+                     #{cash},
+                     #{validGrant},
+                     #{unionGrant},
+                     #{walletName},
+                     #{name},
+                     #{walletId},
+                     #{email}
+                 )
+    </insert>
+</mapper>

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

@@ -0,0 +1,5 @@
+package cn.com.ctop.job.bytedance.data.service;
+
+public interface IAdvertiserFundGetServer {
+    void getAdvertiserFundGet(Long advertiserId, String accessToken);
+}

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

@@ -0,0 +1,64 @@
+package cn.com.ctop.job.bytedance.data.service.impl;
+
+import cn.com.ctop.job.bytedance.data.entity.BytedanceAdvertiserFund;
+import cn.com.ctop.job.bytedance.data.mapper.AdvertiserFundGetMapper;
+import cn.com.ctop.job.bytedance.data.service.IAdvertiserFundGetServer;
+import cn.com.ctop.job.bytedance.data.utils.Check;
+import cn.com.ctop.job.bytedance.data.utils.DateUtils;
+import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
+import cn.com.ctop.job.bytedance.utils.RateLimitUtil;
+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.HashMap;
+import java.util.Map;
+
+@Slf4j
+@Service
+public class AdvertiserFundGetServerImpl implements IAdvertiserFundGetServer {
+    @Autowired
+    private AdvertiserFundGetMapper advertiserFundGetMapper;
+
+    @Autowired
+    private RateLimitUtil rateLimitUtil;
+
+    private static String devAppId = "1742489802322972";
+
+    @Override
+    public void getAdvertiserFundGet(Long advertiserId, String accessToken) {
+        String url = "https://ad.oceanengine.com/open_api/2/advertiser/fund/get/";
+        Map<String, Object> paramsMap = new HashMap<>();
+        paramsMap.put("advertiser_id", advertiserId);
+
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", accessToken);
+        headers.put("Content-Type", "application/json;charset=UTF-8");
+        String s = null;
+        if (rateLimitUtil.acquire(devAppId, url)) {
+            s = HttpUtils.httpGet(url, paramsMap, headers);
+        }
+        JSONObject result = JSONObject.parseObject(s);
+        if (Check.isNull(result)) {
+            log.info("获取账户余额返回结果为空,账户id:{},请求结果返回为空", advertiserId);
+            return;
+        }
+        Integer code = result.getInteger("code");
+        if (code != 0) {
+            log.error("获取余额信息失败,账户ID:{},返回信息:{}", advertiserId, result);
+            return;
+        }
+        JSONObject data = result.getJSONObject("data");
+        if (Check.isNull(data)) {
+            log.error("获取余额信息失败返回data为空,账户ID:{}", advertiserId);
+            return;
+        }
+
+        Integer statDate = Integer.valueOf(DateUtils.getNowDate("yyyyMMdd"));
+        BytedanceAdvertiserFund advertiserFund = JSONObject.parseObject(data.toJSONString(), BytedanceAdvertiserFund.class);
+        advertiserFund.setStatDate(statDate);
+        advertiserFundGetMapper.insertData(advertiserFund);
+
+    }
+}

+ 47 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/AdvertiserFundGetJob.java

@@ -0,0 +1,47 @@
+package cn.com.ctop.job.bytedance.handler;
+
+
+import cn.com.ctop.job.bytedance.data.service.IAdminAdvertiserListService;
+import cn.com.ctop.job.bytedance.data.service.IAdvertiserFundGetServer;
+import cn.com.ctop.job.bytedance.data.utils.Check;
+import com.alibaba.fastjson.JSONObject;
+import com.xxl.job.core.context.XxlJobHelper;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+
+@Slf4j
+@Component
+public class AdvertiserFundGetJob {
+    @Autowired
+    private IAdvertiserFundGetServer advertiserFundGetServer;
+    private static ExecutorService executorService = Executors.newFixedThreadPool(10);
+
+    @XxlJob("getAdvertiserFundGet")
+    public void getAdvertiserFundGet() throws Exception {
+        String param = XxlJobHelper.getJobParam(); // 执行参数
+        if (Check.isNull(param)) {
+            log.error("入参为空");
+            return;
+        }
+        String[] s = param.split("_");
+        Long advertiserId = Long.valueOf(s[0]);
+        String accessToken = s[1];
+        executorService.submit(new Runnable() {
+            @Override
+            public void run() {
+                advertiserFundGetServer.getAdvertiserFundGet(advertiserId, accessToken);
+
+            }
+        });
+
+
+    }
+
+
+}

+ 1 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/utils/RateLimitUtil.java

@@ -44,6 +44,7 @@ public class RateLimitUtil {
             .put("/open_api/2/dpa/product/delete/", 50)
             .put("/open_api/2/dpa/product/create/", 10)
             .put("/open_api/2/dpa/product/update/", 10)
+            .put("/open_api/2/advertiser/fund/get/", 50)
             .build();
 
     /**