Browse Source

快手-账户流水

yangzian 3 years ago
parent
commit
fd778d27af

+ 5 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/constant/KuaishouConstant.java

@@ -29,6 +29,11 @@ public class KuaishouConstant {
     //人群分析报表
     public static final String AUDIENCE_REPORT = "/rest/openapi/v1/report/audience_report";
 
+    //账户流水
+    public static final String FUND_DAILY_FLOWS = "/rest/openapi/v1/advertiser/fund/daily_flows";
+
+
+
 
 
 }

+ 120 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/entity/KuaishouAdvertiserFundDailyFlows.java

@@ -0,0 +1,120 @@
+package cn.com.ctop.job.kuaishou.data.entity;
+
+import cn.com.ctop.job.kuaishou.data.utils.DateUtils;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 快手账户流水
+ * zian Y
+ * 2022/1/7
+ **/
+@Data
+@TableName("kuaishou_advertiser_fund_daily_flows")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "kuaishou_advertiser_fund_daily_flows快手账户流水", description = "快手账户流水")
+public class KuaishouAdvertiserFundDailyFlows {
+
+    /**
+     * 账户ID
+     */
+    @Excel(name = "账户ID", width = 15)
+    @ApiModelProperty(value = "账户ID")
+    private Long advertiserId;
+    /**
+     * 账户ID
+     */
+    @Excel(name = "日期", width = 15)
+    @ApiModelProperty(value = "账户ID")
+    private int date;
+    /**
+     * 总花费(元)
+     */
+    @Excel(name = "总花费(元)", width = 15)
+    @ApiModelProperty(value = "总花费(元)")
+    private java.math.BigDecimal dailyCharge;
+    /**
+     * 充值话费(元)
+     */
+    @Excel(name = "充值话费(元)", width = 15)
+    @ApiModelProperty(value = "充值话费(元)")
+    private java.math.BigDecimal realCharged;
+    /**
+     * 框返花费(元)
+     */
+    @Excel(name = "框返花费(元)", width = 15)
+    @ApiModelProperty(value = "框返花费(元)")
+    private java.math.BigDecimal contractRebateRealCharged;
+    /**
+     * 激励花费(元)
+     */
+    @Excel(name = "激励花费(元)", width = 15)
+    @ApiModelProperty(value = "激励花费(元)")
+    private java.math.BigDecimal directRebateRealCharged;
+    /**
+     * 转入(元)
+     */
+    @Excel(name = "转入(元)", width = 15)
+    @ApiModelProperty(value = "转入(元)")
+    private java.math.BigDecimal dailyTransferIn;
+    /**
+     * 转出(元)
+     */
+    @Excel(name = "转出(元)", width = 15)
+    @ApiModelProperty(value = "转出(元)")
+    private java.math.BigDecimal dailyTransferOut;
+    /**
+     * 日终结余(元)
+     */
+    @Excel(name = "日终结余(元)", width = 15)
+    @ApiModelProperty(value = "日终结余(元)")
+    private java.math.BigDecimal balance;
+    /**
+     * 充值转入(元)
+     */
+    @Excel(name = "充值转入(元)", width = 15)
+    @ApiModelProperty(value = "充值转入(元)")
+    private java.math.BigDecimal realRecharged;
+    /**
+     * 框返转入(元)
+     */
+    @Excel(name = "框返转入(元)", width = 15)
+    @ApiModelProperty(value = "框返转入(元)")
+    private java.math.BigDecimal contractRebateRealRecharged;
+    /**
+     * 激励转入(元)
+     */
+    @Excel(name = "激励转入(元)", width = 15)
+    @ApiModelProperty(value = "激励转入(元)")
+    private java.math.BigDecimal directRebateRealRecharged;
+
+
+    public static KuaishouAdvertiserFundDailyFlows getKuaishouFundDailyFlowsInfo(JSONObject detailJson){
+        KuaishouAdvertiserFundDailyFlows dailyFlows = new KuaishouAdvertiserFundDailyFlows();
+        dailyFlows.setAdvertiserId(detailJson.getLong("advertiser_id"));
+        dailyFlows.setDate(DateUtils.getDateInteger(detailJson.getString("date")));
+        dailyFlows.setDailyCharge(detailJson.getBigDecimal("daily_charge"));
+        dailyFlows.setRealCharged(detailJson.getBigDecimal("real_charged"));
+        dailyFlows.setContractRebateRealCharged(detailJson.getBigDecimal("contract_rebate_real_charged"));
+        dailyFlows.setDirectRebateRealCharged(detailJson.getBigDecimal("direct_rebate_real_charged"));
+        dailyFlows.setDailyTransferIn(detailJson.getBigDecimal("daily_transfer_in"));
+        dailyFlows.setDailyTransferOut(detailJson.getBigDecimal("daily_transfer_out"));
+        dailyFlows.setBalance(detailJson.getBigDecimal("balance"));
+        dailyFlows.setRealRecharged(detailJson.getBigDecimal("real_recharged"));
+        dailyFlows.setContractRebateRealRecharged(detailJson.getBigDecimal("contract_rebate_real_recharged"));
+        dailyFlows.setDirectRebateRealRecharged(detailJson.getBigDecimal("direct_rebate_real_recharged"));
+        return dailyFlows;
+    }
+
+
+}

+ 20 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/mapper/KuaishouAdvertiserFundDailyFlowsMapper.java

@@ -0,0 +1,20 @@
+package cn.com.ctop.job.kuaishou.data.mapper;
+
+import cn.com.ctop.job.kuaishou.data.entity.KuaishouAdvertiserFundDailyFlows;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 快手账户流水
+ * zian Y
+ * 2022/1/7
+ **/
+public interface KuaishouAdvertiserFundDailyFlowsMapper {
+
+  //批量插入 快手-账户流水
+  void replaceBatchKsFundDailyFlows(@Param("addList") List<KuaishouAdvertiserFundDailyFlows> addList);
+
+
+
+}

+ 41 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/mapper/xml/KuaishouAdvertiserFundDailyFlowsMapper.xml

@@ -0,0 +1,41 @@
+<?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.kuaishou.data.mapper.KuaishouAdvertiserFundDailyFlowsMapper">
+
+    <!-- 快手-账户流水-->
+    <insert id="replaceBatchKsFundDailyFlows">
+        replace into kuaishou_advertiser_fund_daily_flows(
+            `advertiser_id`,
+            `date`,
+            `daily_charge`,
+            `real_charged`,
+            `contract_rebate_real_charged`,
+            `direct_rebate_real_charged`,
+            `daily_transfer_in`,
+            `daily_transfer_out`,
+            `balance`,
+            `real_recharged`,
+            `contract_rebate_real_recharged`,
+            `direct_rebate_real_recharged`
+            )
+            values
+            <foreach collection="addList" item="add" separator=",">
+                (
+                #{add.advertiserId},
+                #{add.date},
+                #{add.dailyCharge},
+                #{add.realCharged},
+                #{add.contractRebateRealCharged},
+                #{add.directRebateRealCharged},
+                #{add.dailyTransferIn},
+                #{add.dailyTransferOut},
+                #{add.balance},
+                #{add.realRecharged},
+                #{add.contractRebateRealRecharged},
+                #{add.directRebateRealRecharged}
+                )
+            </foreach>
+        </insert>
+
+
+</mapper>

+ 5 - 2
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/service/IAdUnitReportService.java

@@ -8,9 +8,10 @@ import java.util.List;
 import java.util.PrimitiveIterator;
 
 /**
- * token信息
+ * 定时任务
  *
- * @author jeecg-boot 2021-09-07
+ * @author zian Y
+ * 2022-01-05
  * @version V1.0
  */
 public interface IAdUnitReportService{
@@ -24,4 +25,6 @@ public interface IAdUnitReportService{
     void getKuaishouAccountAdSceneDaily(Long advertiserId, String accessToken, String startDate, String endDate, int page, String temporalGranularity, List<String> reportDims);
 
     void crowdAnalysisReport(Long advertiserId, String accessToken, String date,  List<Long> campaignIds,List<Long> unitIds, List<String> reportDims,Integer page);
+
+    void getKuaishouDailyFlows(Long advertiserId, String accessToken,int page);
 }

+ 48 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/service/impl/AdUnitReportServiceImpl.java

@@ -50,6 +50,9 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
     @Resource
     private KuaishouAudienceReportDailyMapper audienceReportDailyMapper;
 
+    @Resource
+    private KuaishouAdvertiserFundDailyFlowsMapper fundDailyFlowsMapper;
+
 
   /**
    * 获取广告组信息
@@ -409,5 +412,50 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
 
   }
 
+  /**
+   * 快手-账户流水
+   * @param advertiserId
+   * @param accessToken
+   * @param page
+   */
+  @Override
+  public void getKuaishouDailyFlows(Long advertiserId, String accessToken,int page) {
+    log.info("获取账户流水========,账户id:{},page--{}", advertiserId,page);
+    String url = postUrl + KuaishouConstant.FUND_DAILY_FLOWS;
+    Map<String, String> headers = new HashMap<>();
+    headers.put("Access-Token", accessToken);
+    Map<String, Object> param = new HashMap<>();
+    param.put("advertiser_id", advertiserId);
+    param.put("page_size", 500);
+    param.put("page", page);
+    String result = HttpUtils.httpPostRequest(url, param, headers);
+    JSONObject resultJson = JSONObject.parseObject(result);
+    Integer code = resultJson.getInteger("code");
+    String message = resultJson.getString("message");
+    if (null == code || code != 0) {
+      log.error("获取快手账户流水======异常:{},accountId:{}", message, advertiserId);
+      return;
+    }
+    JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
+    if (null == details || details.size() <= 0) {
+      log.error("快手账户流水=====返回详情为空,accountId:{}", advertiserId);
+      return;
+    }
+    List<KuaishouAdvertiserFundDailyFlows> addList = new ArrayList<>();
+    for (int i = 0; i < details.size(); i++) {
+      JSONObject returnJson = details.getJSONObject(i);
+      KuaishouAdvertiserFundDailyFlows reportDaily = KuaishouAdvertiserFundDailyFlows.getKuaishouFundDailyFlowsInfo(returnJson);
+      addList.add(reportDaily);
+    }
+    if (!Check.isNull(addList)) {
+      fundDailyFlowsMapper.replaceBatchKsFundDailyFlows(addList);
+    }
+    getKuaishouDailyFlows(advertiserId, accessToken, page + 1);
+    log.info("账户流水========获取完成:accountId:{}", advertiserId);
+
+
+
+  }
+
 
 }

+ 31 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/AdUnitReportJob.java

@@ -196,6 +196,37 @@ public class AdUnitReportJob {
 
 
 
+  /**
+   * 快手-账户流水
+   * 默认是当天
+   * @throws Exception
+   */
+  @XxlJob("kuaishouFundDailyFlowsJob")
+  public void kuaishouFundDailyFlowsJob() throws Exception {
+    String param = XxlJobHelper.getJobParam(); // 执行参数
+    if (Check.isNull(param)) {
+      log.error("入参为空");
+      return;
+    }
+    String token = tokenService.getByAccountId(Long.valueOf(param));
+    if (Check.isNull(token)) {
+      log.error("此账户未获取到相关token,accountId:{}", param);
+      return;
+    }
+    dailyExecutorService.submit(
+            new Runnable() {
+              @Override
+              public void run() {
+                adUnitReportService.getKuaishouDailyFlows(Long.valueOf(param), token,1);
+              }
+            });
+  }
+
+
+
+
+
+
 
 
 }