|
|
@@ -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();
|
|
|
}
|