Browse Source

快手代理商数据

yangzian 3 years ago
parent
commit
c63ce96c6d

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

@@ -23,6 +23,9 @@ public class KuaishouConstant {
     //获取广告计划信息
     public static final String CAMPAIGN_LIST = "/rest/openapi/v1/campaign/list";
 
+    //获取代理商数据
+    public static final String ANGENT_REPORT = "/rest/openapi/v1/agent/report";
+
 
 
 }

+ 217 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/entity/KuaiShouDailyAgent.java

@@ -0,0 +1,217 @@
+package cn.com.ctop.job.kuaishou.data.entity;
+
+import cn.com.ctop.job.kuaishou.data.utils.Check;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+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 org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+/**
+ * 代理商报表
+ *
+ * @author zian Y
+ * @version V1.0
+ * @date 2022-01-06
+ */
+@Data
+@TableName("kuaishou_agent_report_daily")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "kuaishou_agent_report_daily对象", description = "代理商报表")
+public class KuaiShouDailyAgent {
+
+
+    /**
+     * 代理商id
+     */
+    @Excel(name = "代理商id", width = 15)
+    @ApiModelProperty(value = "代理商id")
+    private Long agentId;
+    /**
+     * 账户ID
+     */
+    @Excel(name = "账户ID", width = 15)
+    @ApiModelProperty(value = "账户ID")
+    private Long advertiserId;
+    /**
+     * 日期
+     */
+    @Excel(name = "日期", width = 15)
+    @ApiModelProperty(value = "日期")
+    private String statDate;
+    /**
+     * user_id
+     */
+    @Excel(name = "user_id", width = 15)
+    @ApiModelProperty(value = "user_id")
+    private Long userId;
+    /**
+     * 广告主名称
+     */
+    @Excel(name = "广告主名称", width = 15)
+    @ApiModelProperty(value = "广告主名称")
+    private String accountName;
+    /**
+     * 总消耗(元)
+     */
+    @Excel(name = "总消耗(元)", width = 15)
+    @ApiModelProperty(value = "总消耗(元)")
+    private java.math.BigDecimal totalChargedInYuan;
+    /**
+     * 总余额(元)
+     */
+    @Excel(name = "总余额(元)", width = 15)
+    @ApiModelProperty(value = "总余额(元)")
+    private java.math.BigDecimal totalBalanceInYuan;
+    /**
+     * 现金消耗(元)
+     */
+    @Excel(name = "现金消耗(元)", width = 15)
+    @ApiModelProperty(value = "现金消耗(元)")
+    private java.math.BigDecimal realChargedInYuan;
+    /**
+     * 返点消耗(元)
+     */
+    @Excel(name = "返点消耗(元)", width = 15)
+    @ApiModelProperty(value = "返点消耗(元)")
+    private java.math.BigDecimal totalRebateRealChargedInYuan;
+    /**
+     * 框返消耗(元)
+     */
+    @Excel(name = "框返消耗(元)", width = 15)
+    @ApiModelProperty(value = "框返消耗(元)")
+    private java.math.BigDecimal contractRebateRealChargedInYuan;
+    /**
+     * 激励消耗(元)
+     */
+    @Excel(name = "激励消耗(元)", width = 15)
+    @ApiModelProperty(value = "激励消耗(元)")
+    private java.math.BigDecimal directRebateRealChargedInYuan;
+    /**
+     * 信用消耗(元)
+     */
+    @Excel(name = "信用消耗(元)", width = 15)
+    @ApiModelProperty(value = "信用消耗(元)")
+    private java.math.BigDecimal creditRealChargedInYuan;
+    /**
+     * 消耗环比
+     */
+    @Excel(name = "消耗环比", width = 15)
+    @ApiModelProperty(value = "消耗环比")
+    private String chargeDayOnDayPercent;
+    /**
+     * 封面曝光数
+     */
+    @Excel(name = "封面曝光数", width = 15)
+    @ApiModelProperty(value = "封面曝光数")
+    private Long adPhotoImpression;
+    /**
+     * 封面点击数
+     */
+    @Excel(name = "封面点击数", width = 15)
+    @ApiModelProperty(value = "封面点击数")
+    private Long adPhotoClick;
+    /**
+     * 素材曝光数
+     */
+    @Excel(name = "素材曝光数", width = 15)
+    @ApiModelProperty(value = "素材曝光数")
+    private Long adItemImpression;
+    /**
+     * 行为数
+     */
+    @Excel(name = "行为数", width = 15)
+    @ApiModelProperty(value = "行为数")
+    private Long adItemClick;
+    /**
+     * 封面点击率
+     */
+    @Excel(name = "封面点击率", width = 15)
+    @ApiModelProperty(value = "封面点击率")
+    private String photoClickRatio;
+    /**
+     * 行为点击率
+     */
+    @Excel(name = "行为点击率", width = 15)
+    @ApiModelProperty(value = "行为点击率")
+    private String itemClickRatio;
+    /**
+     * 有消费计划数
+     */
+    @Excel(name = "有消费计划数", width = 15)
+    @ApiModelProperty(value = "有消费计划数")
+    private Long chargedCampaignCount;
+    /**
+     * 产品名
+     */
+    @Excel(name = "产品名", width = 15)
+    @ApiModelProperty(value = "产品名")
+    private String productName;
+    /**
+     * 企业名称
+     */
+    @Excel(name = "企业名称", width = 15)
+    @ApiModelProperty(value = "企业名称")
+    private String corporationName;
+    /**
+     * 首次消耗日期
+     */
+    @Excel(name = "首次消耗日期", width = 15)
+    @ApiModelProperty(value = "首次消耗日期")
+    private String firstCostDay;
+    /**
+     * 一级行业
+     */
+    @Excel(name = "一级行业", width = 15)
+    @ApiModelProperty(value = "一级行业")
+    private String industry;
+    /**
+     * 二级行业
+     */
+    @Excel(name = "二级行业", width = 15)
+    @ApiModelProperty(value = "二级行业")
+    private String secondIndustry;
+
+
+    public static KuaiShouDailyAgent getKuaishouAgentDailyInfo(JSONObject detailJson){
+        KuaiShouDailyAgent agent = new KuaiShouDailyAgent();
+        agent.setAgentId(detailJson.getLong("agent_id"));
+        agent.setAdvertiserId(detailJson.getLong("account_id"));
+        agent.setStatDate(detailJson.getString("date_time").replace("-",""));
+        agent.setUserId(detailJson.getLong("user_id"));
+        agent.setAccountName(detailJson.getString("account_name"));
+        agent.setTotalChargedInYuan(detailJson.getBigDecimal("total_charged_in_yuan"));
+        agent.setTotalBalanceInYuan(detailJson.getBigDecimal("total_balance_in_yuan"));
+        agent.setRealChargedInYuan(detailJson.getBigDecimal("real_charged_in_yuan"));
+        agent.setTotalRebateRealChargedInYuan(detailJson.getBigDecimal("total_rebate_real_charged_in_yuan"));
+        agent.setContractRebateRealChargedInYuan(detailJson.getBigDecimal("contract_rebate_real_charged_in_yuan"));
+        agent.setDirectRebateRealChargedInYuan(detailJson.getBigDecimal("direct_rebate_real_charged_in_yuan"));
+        agent.setCreditRealChargedInYuan(detailJson.getBigDecimal("credit_real_charged_in_yuan"));
+        agent.setChargeDayOnDayPercent(detailJson.getString("charge_day_on_day_percent"));
+        agent.setAdPhotoImpression(detailJson.getLong("ad_photo_impression"));
+        agent.setAdPhotoClick(detailJson.getLong("ad_photo_click"));
+        agent.setAdItemImpression(detailJson.getLong("ad_item_impression"));
+        agent.setAdItemClick(detailJson.getLong("ad_item_click"));
+        agent.setPhotoClickRatio(detailJson.getString("photo_click_ratio"));
+        agent.setItemClickRatio(detailJson.getString("item_click_ratio"));
+        agent.setChargedCampaignCount(detailJson.getLong("charged_campaign_count"));
+        agent.setProductName(detailJson.getString("product_name"));
+        agent.setCorporationName(detailJson.getString("corporation_name"));
+        agent.setFirstCostDay(Check.isNull(detailJson.getString("first_cost_day").replace("-","")) ? "0" : detailJson.getString("first_cost_day").replace("-",""));
+        agent.setIndustry(detailJson.getString("industry"));
+        agent.setSecondIndustry(detailJson.getString("second_industry"));
+        return agent;
+    }
+
+
+
+}

+ 4 - 4
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/mapper/AdUnitReportMapper.java

@@ -1,9 +1,6 @@
 package cn.com.ctop.job.kuaishou.data.mapper;
 
-import cn.com.ctop.job.kuaishou.data.entity.KuaishouAccountReportDaily;
-import cn.com.ctop.job.kuaishou.data.entity.KuaishouAdUnitList;
-import cn.com.ctop.job.kuaishou.data.entity.KuaishouCampaignList;
-import cn.com.ctop.job.kuaishou.data.entity.OauthToken;
+import cn.com.ctop.job.kuaishou.data.entity.*;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -23,4 +20,7 @@ public interface AdUnitReportMapper{
   //批量插入 快手-广告计划信息
   void replaceBatchKsCampaign(@Param("addList") List<KuaishouCampaignList> addList);
 
+  //批量插入 快手-代理商数据
+  void replaceBatchAgentReport(@Param("addList") List<KuaiShouDailyAgent> addList);
+
 }

+ 6 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/mapper/OauthAgentTokenMapper.java

@@ -5,6 +5,8 @@ import cn.com.ctop.job.kuaishou.data.entity.OauthToken;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 /**
  * 代理商token信息
  *
@@ -14,4 +16,8 @@ import org.apache.ibatis.annotations.Param;
  */
 public interface OauthAgentTokenMapper extends BaseMapper<OauthAgentToken> {
 
+    //查询快手代理商信息
+    List<OauthAgentToken> getOauthAgentTokenKs();
+
+
 }

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

@@ -202,5 +202,66 @@
         </foreach>
     </insert>
 
+    <!-- 快手代理商数据 -->
+    <insert id="replaceBatchAgentReport">
+        replace into kuaishou_agent_report_daily(
+        agent_id,
+        advertiser_id,
+        stat_date,
+        user_id,
+        account_name,
+        total_charged_in_yuan,
+        total_balance_in_yuan,
+        real_charged_in_yuan,
+        total_rebate_real_charged_in_yuan,
+        contract_rebate_real_charged_in_yuan,
+        direct_rebate_real_charged_in_yuan,
+        credit_real_charged_in_yuan,
+        charge_day_on_day_percent,
+        ad_photo_impression,
+        ad_photo_click,
+        ad_item_impression,
+        ad_item_click,
+        photo_click_ratio,
+        item_click_ratio,
+        charged_campaign_count,
+        product_name,
+        corporation_name,
+        first_cost_day,
+        industry,
+        second_industry
+        )
+        values
+        <foreach collection="addList" item="agent" separator=",">
+            (
+            #{agent.agentId},
+            #{agent.advertiserId},
+            #{agent.statDate},
+            #{agent.userId},
+            #{agent.accountName},
+            #{agent.totalChargedInYuan},
+            #{agent.totalBalanceInYuan},
+            #{agent.realChargedInYuan},
+            #{agent.totalRebateRealChargedInYuan},
+            #{agent.contractRebateRealChargedInYuan},
+            #{agent.directRebateRealChargedInYuan},
+            #{agent.creditRealChargedInYuan},
+            #{agent.chargeDayOnDayPercent},
+            #{agent.adPhotoImpression},
+            #{agent.adPhotoClick},
+            #{agent.adItemImpression},
+            #{agent.adItemClick},
+            #{agent.photoClickRatio},
+            #{agent.itemClickRatio},
+            #{agent.chargedCampaignCount},
+            #{agent.productName},
+            #{agent.corporationName},
+            #{agent.firstCostDay},
+            #{agent.industry},
+            #{agent.secondIndustry}
+            )
+        </foreach>
+
+    </insert>
 
 </mapper>

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

@@ -2,4 +2,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.OauthAgentTokenMapper">
 
+    <!-- 查询快手代理商信息 -->
+    <select id="getOauthAgentTokenKs" resultType="cn.com.ctop.job.kuaishou.data.entity.OauthAgentToken">
+        select * from `jeecg-boot`.ctop_oauth_agent_token where media_id = 2
+    </select>
 </mapper>

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

@@ -18,4 +18,6 @@ public interface IAdUnitReportService{
 
     public void getAdPlanReport(Long advertiserId, String accessToken, String startDate, String endDate, int page);
 
+    public void getAgentReport();
+
 }

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

@@ -3,13 +3,16 @@ package cn.com.ctop.job.kuaishou.data.service.impl;
 import cn.com.ctop.job.kuaishou.data.constant.KuaishouConstant;
 import cn.com.ctop.job.kuaishou.data.entity.*;
 import cn.com.ctop.job.kuaishou.data.mapper.AdUnitReportMapper;
+import cn.com.ctop.job.kuaishou.data.mapper.OauthAgentTokenMapper;
 import cn.com.ctop.job.kuaishou.data.mapper.OauthTokenMapper;
 import cn.com.ctop.job.kuaishou.data.service.IAdUnitReportService;
 import cn.com.ctop.job.kuaishou.data.service.IOauthTokenService;
 import cn.com.ctop.job.kuaishou.data.utils.Check;
+import cn.com.ctop.job.kuaishou.data.utils.DateUtils;
 import cn.com.ctop.job.kuaishou.data.utils.HttpUtils;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xxl.job.core.context.XxlJobHelper;
 import lombok.extern.slf4j.Slf4j;
@@ -40,6 +43,9 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
     private OauthTokenMapper tokenMapper;
 
     @Resource
+    private OauthAgentTokenMapper agentTokenMapper;
+
+    @Resource
     private AdUnitReportMapper adUnitReportMapper;
 
 
@@ -173,9 +179,85 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
     } else {
       log.info("快手广告计划数据获取完成:accountId:{}", advertiserId);
     }
+  }
 
+  /**
+   * 快手-代理商数据
+   */
+  @Override
+  public void getAgentReport() {
+    // 前一天 时间
+    String date = DateUtils.getAnotherDay("yyyy-MM-dd", DateUtils.getNowDate("yyyy-MM-dd"), -1);
+    //查询代理商token
+    List<OauthAgentToken> list = agentTokenMapper.getOauthAgentTokenKs();
+    if (!Check.isNull(list)) {
+      for (OauthAgentToken agentToken : list) {
+        getAgentReport(agentToken.getAccessToken(), agentToken.getAgentId(), date, date, 1);
+      }
+    }
+  }
+
+  /**
+   * 获取代理商数据
+   * @param token
+   * @param agentId
+   * @param startDate
+   * @param endDate
+   * @param page
+   */
+  private void getAgentReport(String token, Long agentId, String startDate, String endDate, int page) {
+    try {
+      log.info("=====获取代理商数据信息====page--{}===《《《《《", page);
+
+      Map<String, String> headers = new HashMap<String, String>();
+      headers.put("Content-Type", " application/json");
+      headers.put("Access-Token", token);
+      JSONObject param = new JSONObject();
+      param.put("start_date", startDate);
+      param.put("end_date", endDate);
+      param.put("agent_id", agentId);
+      param.put("page_size", 1000);
+      param.put("page", page);
 
+      String result = HttpUtils.httpPostRequest(postUrl + KuaishouConstant.ANGENT_REPORT, param, headers);
+      JSONObject resultJson = JSONObject.parseObject(result);
+      if (Check.isNull(resultJson)) {
+        log.info("代理商数据返回为空");
+        return;
+      }
+      Integer code = resultJson.getInteger("code");
+      if (code != 0) {
+        log.error("代理商报表返回code错误,返回:{}", resultJson);
+        return;
+      }
+      JSONObject data = resultJson.getJSONObject("data");
+      if (Check.isNull(data)) {
+        log.error("代理商报表返回data节点为空");
+        return;
+      }
+      JSONArray details = data.getJSONArray("details");
+      if (Check.isNull(details)) {
+        log.error("代理商报表返回details节点为空");
+        return;
+      }
+      List<KuaiShouDailyAgent> agentList = new ArrayList<>();
+      for (int i = 0; i < details.size(); i++) {
+        JSONObject detailJson = details.getJSONObject(i);
+        if (!Check.isNull(detailJson)) {
+          detailJson.put("agent_id",agentId);
+          KuaiShouDailyAgent agent = KuaiShouDailyAgent.getKuaishouAgentDailyInfo(detailJson);
+          agentList.add(agent);
+        }
+      }
+      if (!Check.isNull(agentList)) {
+        adUnitReportMapper.replaceBatchAgentReport(agentList);
+      }
+      getAgentReport(token, agentId, startDate, endDate, page + 1);
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
   }
 
 
-}
+
+  }

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

@@ -104,4 +104,15 @@ public class AdUnitReportJob {
 
 
 
+  /**
+   * 代理商t-1数据获取
+   *
+   * @throws
+   */
+  @XxlJob("kuaiShouAgentReportJob")
+  public void kuaiShouAgentReportJob() throws Exception {
+    adUnitReportService.getAgentReport();
+  }
+
+
 }