huangpingkang 1 год назад
Родитель
Сommit
4f3629e0df

+ 3 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/controller/KuaiShouController.java

@@ -34,6 +34,9 @@ public class KuaiShouController {
     @Autowired
     private IKuaiShouRefreshTokenService kuaiShouRefreshTokenService;
 
+    @Autowired
+    private IKuaiShouAccountReportService kuaiShouAccountReportService;
+
 
 
     @Autowired

+ 32 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/entity/KuaishouDailyFlows.java

@@ -0,0 +1,32 @@
+package cn.com.ctop.job.kuaishou.data.entity;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+@Data
+public class KuaishouDailyFlows implements Serializable {
+    private Integer statDate;
+    private String date;
+    private BigDecimal balance;
+    private Long advertiserId;
+    private BigDecimal dailyCharge;
+    private BigDecimal dailyCommonCharge;
+    private BigDecimal realCharged;
+    private BigDecimal extendedCharged;
+    private BigDecimal contractRebateRealCharged;
+    private BigDecimal directRebateRealCharged;
+    private BigDecimal dailyTransferIn;
+    private BigDecimal realRecharged;
+    private BigDecimal contractRebateRealRecharged;
+    private BigDecimal directRebateRealRecharged;
+    private BigDecimal dailyTransferOut;
+    private BigDecimal orderTotalCharged;
+    private BigDecimal orderRealCharged;
+    private BigDecimal orderExtendedCharged;
+    private BigDecimal orderContractCharged;
+    private BigDecimal orderDirectCharged;
+    private BigDecimal dailyShareCharge;
+    private BigDecimal shareRealCharge;
+    private BigDecimal shareCreditCharge;
+}

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

@@ -2,6 +2,7 @@ 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.KuaishouAccountReportHour;
+import cn.com.ctop.job.kuaishou.data.entity.KuaishouDailyFlows;
 import com.baomidou.dynamic.datasource.annotation.DS;
 import org.apache.ibatis.annotations.Param;
 
@@ -19,4 +20,7 @@ public interface KuaiShouAccountReportMapper {
     void updateKsAccountStatus();
 
     void updateClAccountStatus();
+
+    @DS("sd_group_commit")
+    void replaceKuaiShouDailyFlows(List<KuaishouDailyFlows> addList);
 }

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

@@ -226,6 +226,27 @@
             )
         </foreach>
     </insert>
+
+    <insert id="replaceKuaiShouDailyFlows">
+        INSERT INTO media_api.kuaishou_advertiser_daily_flows (
+        stat_date, balance, advertiser_id, daily_charge, daily_common_charge,
+        real_charged, extended_charged, contract_rebate_real_charged, direct_rebate_real_charged,
+        daily_transfer_in, real_recharged, contract_rebate_real_recharged, direct_rebate_real_recharged,
+        daily_transfer_out, order_total_charged, order_real_charged, order_extended_charged,
+        order_contract_charged, order_direct_charged, daily_share_charge, share_real_charge, share_credit_charge
+        )
+        VALUES
+        <foreach collection="list" item="item" separator=",">
+            (
+            #{item.statDate}, #{item.balance}, #{item.advertiserId}, #{item.dailyCharge}, #{item.dailyCommonCharge},
+            #{item.realCharged}, #{item.extendedCharged}, #{item.contractRebateRealCharged}, #{item.directRebateRealCharged},
+            #{item.dailyTransferIn}, #{item.realRecharged}, #{item.contractRebateRealRecharged}, #{item.directRebateRealRecharged},
+            #{item.dailyTransferOut}, #{item.orderTotalCharged}, #{item.orderRealCharged}, #{item.orderExtendedCharged},
+            #{item.orderContractCharged}, #{item.orderDirectCharged}, #{item.dailyShareCharge}, #{item.shareRealCharge}, #{item.shareCreditCharge}
+            )
+        </foreach>
+    </insert>
+
     <update id="updateKsAccountStatus">
         update deepthink.advertiser_bind_info
         set advertiser_status = 2

+ 3 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/service/IKuaiShouAccountReportService.java

@@ -8,4 +8,7 @@ public interface IKuaiShouAccountReportService {
     void updateKsAccountStatus();
 
     void updateClAccountStatus();
+
+    void queryAccountDailyFlows(String accessToken, Long advertiserId, String startDate, String endDate, int page, Integer isLog, Long errId, Integer isSend);
+
 }

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

@@ -2,6 +2,7 @@ package cn.com.ctop.job.kuaishou.data.service.impl;
 
 import cn.com.ctop.job.kuaishou.data.entity.KuaishouAccountReportDaily;
 import cn.com.ctop.job.kuaishou.data.entity.KuaishouAccountReportHour;
+import cn.com.ctop.job.kuaishou.data.entity.KuaishouDailyFlows;
 import cn.com.ctop.job.kuaishou.data.mapper.KuaiShouAccountReportMapper;
 import cn.com.ctop.job.kuaishou.data.service.IKuaiShouAccountReportService;
 import cn.com.ctop.job.kuaishou.data.service.IKuaiShouErrorLogService;
@@ -150,6 +151,68 @@ public class KuaiShouAccountReportServiceImpl implements IKuaiShouAccountReportS
     }
 
     @Override
+    public void queryAccountDailyFlows(String accessToken, Long advertiserId, String startDate, String endDate, int page, Integer isLog, Long errId, Integer isSend) {
+        String url = "https://ad.e.kuaishou.com/rest/openapi/v1/advertiser/fund/daily_flows";
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Content-Type", "application/json");
+        headers.put("Access-Token", accessToken);
+        Map<String, Object> param = new HashMap<>();
+        if (!Check.isNull(startDate)) {
+            param.put("start_date", startDate);
+        }
+        if (!Check.isNull(endDate)) {
+            param.put("end_date", endDate);
+        }
+        int pageSize = 500;
+        param.put("advertiser_id", advertiserId);
+        param.put("page_size", pageSize);
+        param.put("page", page);
+        String result = HttpUtils.httpPostRequest(url, param, headers);
+        if (Check.isNull(result)) {
+            log.error("获取快手广告账户流水信息异常:{},accountId:{}", "返回结果为空", advertiserId);
+            if (isLog != null && isLog == 1) {
+                errorLogService.addError(advertiserId, startDate, endDate, "daily_flows", "daily", "返回结果为空", 2);
+            }
+            return;
+        }
+        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);
+            if (isLog != null && isLog == 1) {
+                errorLogService.addError(advertiserId, startDate, endDate, "daily_flows", "daily", message, 2);
+            }
+            return;
+        }
+        JSONObject data = resultJson.getJSONObject("data");
+        JSONArray details = data.getJSONArray("details");
+        int totalCount = data.getIntValue("total_count");
+        int totalPage = (int)Math.ceil(totalCount * 1.0 / pageSize);
+        List<KuaishouDailyFlows> addList = new ArrayList<>();
+        if (!Check.isNull(details)) {
+            for (int i = 0; i < details.size(); i++) {
+                JSONObject detailJson = details.getJSONObject(i);
+                detailJson.put("stat_date", DateUtils.getIntegerDate(detailJson.getString("date")));
+                KuaishouDailyFlows accountReportDaily = JSONObject.toJavaObject(detailJson, KuaishouDailyFlows.class);
+                accountReportDaily.setAdvertiserId(advertiserId);
+                addList.add(accountReportDaily);
+            }
+        }
+        if (!Check.isNull(addList)) {
+            accountReportMapper.replaceKuaiShouDailyFlows(addList);
+        }
+        if (page < totalPage) {
+            queryAccountDailyFlows(accessToken, advertiserId, startDate, endDate, page + 1,isLog, errId, isSend);
+        } else {
+            if (errId != null) {
+                errorLogService.deleteInfoByErrorId(errId);
+            }
+            log.info("【{}】获取快手广告账户流水信息完成", advertiserId);
+        }
+    }
+
+    @Override
     public void updateKsAccountStatus() {
         accountReportMapper.updateKsAccountStatus();
     }

+ 43 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaiShouAccountReportJob.java

@@ -103,5 +103,48 @@ public class KuaiShouAccountReportJob {
         accountReportService.updateClAccountStatus();
     }
 
+    @XxlJob("queryYesterdayAccountDailyFlows")
+    public void queryYesterdayAccountDailyFlows() {
+        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];
+
+        String nowDate = DateUtil.formatDate(new Date());
+        String yesDate = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
+
+        yesAccountExecutorService.submit(new Runnable() {
+            @Override
+            public void run() {
+                accountReportService.queryAccountDailyFlows(accessToken, advertiserId, yesDate, yesDate, 1,1,null,2);
+            }
+        });
+    }
+
+    @XxlJob("queryTodayAccountDailyFlows")
+    public void queryTodayAccountDailyFlows() {
+        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];
+
+        String nowDate = DateUtil.formatDate(new Date());
+
+        yesAccountExecutorService.submit(new Runnable() {
+            @Override
+            public void run() {
+                accountReportService.queryAccountDailyFlows(accessToken, advertiserId, nowDate, nowDate, 1,1,null,2);
+            }
+        });
+    }
+
 
 }

+ 13 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaiShouRetryReportJob.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.job.kuaishou.handler;
 
 
+import cn.com.ctop.job.kuaishou.data.service.IKuaiShouAccountReportService;
 import cn.com.ctop.job.kuaishou.data.service.IKuaiShouAdSocialService;
 import cn.com.ctop.job.kuaishou.data.service.IKuaiShouDramaService;
 import cn.com.ctop.job.kuaishou.data.service.IKuaiShouRetryReportService;
@@ -41,6 +42,9 @@ public class KuaiShouRetryReportJob {
     @Autowired
     private IKuaiShouAdSocialService kuaiShouAdSocialService;
 
+    @Autowired
+    private IKuaiShouAccountReportService accountReportService;
+
     @XxlJob("kuaiShouRetryReport")
     public void promoterReport() throws Exception {
         List<JSONObject> accountList = retryReportService.getErrorLogs();
@@ -101,6 +105,15 @@ public class KuaiShouRetryReportJob {
                         });
                     }
 
+                }else if ("daily_flows".equals(dataDimension)) {
+                    dailyAccountExecutorService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            if (!Check.isNull(accessToken)) {
+                                accountReportService.queryAccountDailyFlows(accessToken, advertiserId, startDate, endDate, 1,null,id, isSend);
+                            }
+                        }
+                    });
                 }
             }
         } else {