|
@@ -4,7 +4,6 @@ import cn.com.ctop.job.kuaishou.data.constant.KuaishouConstant;
|
|
|
import cn.com.ctop.job.kuaishou.data.entity.*;
|
|
import cn.com.ctop.job.kuaishou.data.entity.*;
|
|
|
import cn.com.ctop.job.kuaishou.data.mapper.*;
|
|
import cn.com.ctop.job.kuaishou.data.mapper.*;
|
|
|
import cn.com.ctop.job.kuaishou.data.service.IAdUnitReportService;
|
|
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.Check;
|
|
|
import cn.com.ctop.job.kuaishou.data.utils.DateUtils;
|
|
import cn.com.ctop.job.kuaishou.data.utils.DateUtils;
|
|
|
import cn.com.ctop.job.kuaishou.data.utils.HttpUtils;
|
|
import cn.com.ctop.job.kuaishou.data.utils.HttpUtils;
|
|
@@ -12,7 +11,6 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.xxl.job.core.context.XxlJobHelper;
|
|
import com.xxl.job.core.context.XxlJobHelper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
@@ -54,486 +52,490 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
|
|
|
private KuaishouAdvertiserFundDailyFlowsMapper fundDailyFlowsMapper;
|
|
private KuaishouAdvertiserFundDailyFlowsMapper fundDailyFlowsMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 获取广告组信息
|
|
|
|
|
- * @param advertiserId
|
|
|
|
|
- * @param accessToken
|
|
|
|
|
- * @param startDate
|
|
|
|
|
- * @param endDate
|
|
|
|
|
- * @param page
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取广告组信息
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param advertiserId
|
|
|
|
|
+ * @param accessToken
|
|
|
|
|
+ * @param startDate
|
|
|
|
|
+ * @param endDate
|
|
|
|
|
+ * @param page
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
public void getAdUnitReport(Long advertiserId, String accessToken, String startDate, String endDate, int page) {
|
|
public void getAdUnitReport(Long advertiserId, String accessToken, String startDate, String endDate, int page) {
|
|
|
- log.info("accountId:=={}=====获取广告组数据信息====page--{}===》》》》",advertiserId,page);
|
|
|
|
|
- Integer page_size = 500;
|
|
|
|
|
-
|
|
|
|
|
- Map<String, String> headers = new HashMap<>();
|
|
|
|
|
- headers.put("Access-Token", accessToken);
|
|
|
|
|
-
|
|
|
|
|
- Map<String, Object> param = new HashMap<>();
|
|
|
|
|
- param.put("advertiser_id", advertiserId);
|
|
|
|
|
- //param.put("campaign_id", 530536212);
|
|
|
|
|
- //param.put("unit_id", 1016212250);
|
|
|
|
|
- param.put("start_date", startDate);
|
|
|
|
|
- param.put("end_date", endDate);
|
|
|
|
|
- param.put("page_size", page_size);
|
|
|
|
|
- param.put("page", page);
|
|
|
|
|
-
|
|
|
|
|
- if (!Check.isNull(startDate) && !Check.isNull(endDate)) {
|
|
|
|
|
|
|
+ log.info("accountId:=={}=====获取广告组数据信息====page--{}===》》》》", advertiserId, page);
|
|
|
|
|
+ Integer page_size = 500;
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
|
|
+ param.put("advertiser_id", advertiserId);
|
|
|
|
|
+ //param.put("campaign_id", 530536212);
|
|
|
|
|
+ //param.put("unit_id", 1016212250);
|
|
|
param.put("start_date", startDate);
|
|
param.put("start_date", startDate);
|
|
|
param.put("end_date", endDate);
|
|
param.put("end_date", endDate);
|
|
|
- }
|
|
|
|
|
- String result = HttpUtils.httpPostRequest(postUrl + KuaishouConstant.AD_UNIT_LIST, param, headers);
|
|
|
|
|
-
|
|
|
|
|
- JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
|
|
- if (Check.isNull(resultJson)) {
|
|
|
|
|
- log.info("accountId:=={}=====广告组数据信息====暂无====》》》》",advertiserId);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- 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.info("快手广告组数据为空=》accountId:{}", advertiserId);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- List<KuaishouAdUnitList> ksAdUnitList = new ArrayList<>();
|
|
|
|
|
- for (Object detail : details) {
|
|
|
|
|
- JSONObject unitDetail = (JSONObject) detail;
|
|
|
|
|
- unitDetail.put("advertiser_id",advertiserId);
|
|
|
|
|
- KuaishouAdUnitList ksAdunit = KuaishouAdUnitList.getAdUnitListInfo(unitDetail);
|
|
|
|
|
-
|
|
|
|
|
- ksAdUnitList.add(ksAdunit);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (!Check.isNull(ksAdUnitList)) {
|
|
|
|
|
- adUnitReportMapper.replaceBatchKsAdUnit(ksAdUnitList);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- //是否有下一页
|
|
|
|
|
- Boolean toGet = true;
|
|
|
|
|
- if (details.size() < page_size) {
|
|
|
|
|
- toGet = false;
|
|
|
|
|
- }
|
|
|
|
|
- if (toGet) {
|
|
|
|
|
- getAdUnitReport(advertiserId, accessToken, startDate, endDate, page + 1);
|
|
|
|
|
- } else {
|
|
|
|
|
- log.info("快手广告组数据获取完成:accountId:{}", advertiserId);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ param.put("page_size", page_size);
|
|
|
|
|
+ param.put("page", page);
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!Check.isNull(startDate) && !Check.isNull(endDate)) {
|
|
|
|
|
+ param.put("start_date", startDate);
|
|
|
|
|
+ param.put("end_date", endDate);
|
|
|
|
|
+ }
|
|
|
|
|
+ String result = HttpUtils.httpPostRequest(postUrl + KuaishouConstant.AD_UNIT_LIST, param, headers);
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 快手广告计划信息
|
|
|
|
|
- * @param advertiserId
|
|
|
|
|
- * @param accessToken
|
|
|
|
|
- * @param startDate
|
|
|
|
|
- * @param endDate
|
|
|
|
|
- * @param page
|
|
|
|
|
- */
|
|
|
|
|
- @Override
|
|
|
|
|
- public void getAdPlanReport(Long advertiserId, String accessToken, String startDate, String endDate, int page) {
|
|
|
|
|
-
|
|
|
|
|
- log.info("accountId:=={}=====获取广告计划数据信息====page--{}===》》》》",advertiserId,page);
|
|
|
|
|
- Integer page_size = 500;
|
|
|
|
|
-
|
|
|
|
|
- JSONObject param = new JSONObject();
|
|
|
|
|
- param.put("advertiser_id", advertiserId);
|
|
|
|
|
- param.put("start_date", startDate);
|
|
|
|
|
- param.put("end_date", endDate);
|
|
|
|
|
- param.put("page_size", 500);
|
|
|
|
|
- param.put("page", page);
|
|
|
|
|
-
|
|
|
|
|
- Map<String, String> headers = new HashMap<>();
|
|
|
|
|
- headers.put("Access-Token", accessToken);
|
|
|
|
|
- headers.put("Content-Type", "application/json");
|
|
|
|
|
-
|
|
|
|
|
- String result = HttpUtils.httpPostRequest(postUrl + KuaishouConstant.CAMPAIGN_LIST, param, headers);
|
|
|
|
|
- JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
|
|
- if (Check.isNull(resultJson)) {
|
|
|
|
|
- XxlJobHelper.log("获取广告计划接口异常,advertiserId:{}", advertiserId);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- Integer code = resultJson.getInteger("code");
|
|
|
|
|
- if (null == code || code != 0) {
|
|
|
|
|
- XxlJobHelper.log("获取广告计划返回结果异常,advertiserId:{},异常信息:{}", advertiserId, resultJson);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
|
|
|
|
|
- if (Check.isNull(details)) {
|
|
|
|
|
- log.info("快手广告计划数据为空=》accountId:{}", advertiserId);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
|
|
+ if (Check.isNull(resultJson)) {
|
|
|
|
|
+ log.info("accountId:=={}=====广告组数据信息====暂无====》》》》", advertiserId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ 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.info("快手广告组数据为空=》accountId:{}", advertiserId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- List<KuaishouCampaignList> kscampaignList = new ArrayList<>();
|
|
|
|
|
- for (Object detail : details) {
|
|
|
|
|
- JSONObject unitDetail = (JSONObject) detail;
|
|
|
|
|
- unitDetail.put("advertiser_id",advertiserId);
|
|
|
|
|
- KuaishouCampaignList ksAdunit = KuaishouCampaignList.getKuaishouCampaignListInfo(unitDetail);
|
|
|
|
|
- kscampaignList.add(ksAdunit);
|
|
|
|
|
- }
|
|
|
|
|
- if (!Check.isNull(kscampaignList)) {
|
|
|
|
|
- adUnitReportMapper.replaceBatchKsCampaign(kscampaignList);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ List<KuaishouAdUnitList> ksAdUnitList = new ArrayList<>();
|
|
|
|
|
+ for (Object detail : details) {
|
|
|
|
|
+ JSONObject unitDetail = (JSONObject) detail;
|
|
|
|
|
+ unitDetail.put("advertiser_id", advertiserId);
|
|
|
|
|
+ KuaishouAdUnitList ksAdunit = KuaishouAdUnitList.getAdUnitListInfo(unitDetail);
|
|
|
|
|
+
|
|
|
|
|
+ ksAdUnitList.add(ksAdunit);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!Check.isNull(ksAdUnitList)) {
|
|
|
|
|
+ adUnitReportMapper.replaceBatchKsAdUnit(ksAdUnitList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //是否有下一页
|
|
|
|
|
+ Boolean toGet = true;
|
|
|
|
|
+ if (details.size() < page_size) {
|
|
|
|
|
+ toGet = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (toGet) {
|
|
|
|
|
+ getAdUnitReport(advertiserId, accessToken, startDate, endDate, page + 1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("快手广告组数据获取完成:accountId:{}", advertiserId);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- //是否有下一页
|
|
|
|
|
- Boolean toGet = true;
|
|
|
|
|
- if (details.size() < page_size) {
|
|
|
|
|
- toGet = false;
|
|
|
|
|
- }
|
|
|
|
|
- if (toGet) {
|
|
|
|
|
- getAdPlanReport(advertiserId, accessToken, startDate, endDate, page + 1);
|
|
|
|
|
- } else {
|
|
|
|
|
- log.info("快手广告计划数据获取完成:accountId:{}", advertiserId);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 快手-代理商数据
|
|
|
|
|
- */
|
|
|
|
|
- @Override
|
|
|
|
|
- public void getAgentReport() {
|
|
|
|
|
- // 前一天 时间
|
|
|
|
|
- String date = DateUtils.getAnotherDay("yyyy-MM-dd", DateUtils.getNowDate("yyyy-MM-dd"), -2);
|
|
|
|
|
- String date1 = DateUtils.getAnotherDay("yyyy-MM-dd", DateUtils.getNowDate("yyyy-MM-dd"), -1);
|
|
|
|
|
-/* String date = "2022-04-19";
|
|
|
|
|
- String date1 = "2022-04-27";*/
|
|
|
|
|
- //查询代理商token
|
|
|
|
|
- List<OauthAgentToken> list = agentTokenMapper.getOauthAgentTokenKs();
|
|
|
|
|
- if (!Check.isNull(list)) {
|
|
|
|
|
- for (OauthAgentToken agentToken : list) {
|
|
|
|
|
- getAgentReport(agentToken.getAccessToken(), agentToken.getAgentId(), date, date1, 1);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 快手广告计划信息
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param advertiserId
|
|
|
|
|
+ * @param accessToken
|
|
|
|
|
+ * @param startDate
|
|
|
|
|
+ * @param endDate
|
|
|
|
|
+ * @param page
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void getAdPlanReport(Long advertiserId, String accessToken, String startDate, String endDate, int page) {
|
|
|
|
|
+
|
|
|
|
|
+ log.info("accountId:=={}=====获取广告计划数据信息====page--{}===》》》》", advertiserId, page);
|
|
|
|
|
+ Integer page_size = 500;
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
|
|
+ param.put("advertiser_id", advertiserId);
|
|
|
|
|
+ param.put("start_date", startDate);
|
|
|
|
|
+ param.put("end_date", endDate);
|
|
|
|
|
+ param.put("page_size", 500);
|
|
|
|
|
+ param.put("page", page);
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
|
|
+
|
|
|
|
|
+ String result = HttpUtils.httpPostRequest(postUrl + KuaishouConstant.CAMPAIGN_LIST, param, headers);
|
|
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
|
|
+ if (Check.isNull(resultJson)) {
|
|
|
|
|
+ XxlJobHelper.log("获取广告计划接口异常,advertiserId:{}", advertiserId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
|
|
+ if (null == code || code != 0) {
|
|
|
|
|
+ XxlJobHelper.log("获取广告计划返回结果异常,advertiserId:{},异常信息:{}", advertiserId, resultJson);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
|
|
|
|
|
+ if (Check.isNull(details)) {
|
|
|
|
|
+ log.info("快手广告计划数据为空=》accountId:{}", advertiserId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<KuaishouCampaignList> kscampaignList = new ArrayList<>();
|
|
|
|
|
+ for (Object detail : details) {
|
|
|
|
|
+ JSONObject unitDetail = (JSONObject) detail;
|
|
|
|
|
+ unitDetail.put("advertiser_id", advertiserId);
|
|
|
|
|
+ KuaishouCampaignList ksAdunit = KuaishouCampaignList.getKuaishouCampaignListInfo(unitDetail);
|
|
|
|
|
+ kscampaignList.add(ksAdunit);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Check.isNull(kscampaignList)) {
|
|
|
|
|
+ adUnitReportMapper.replaceBatchKsCampaign(kscampaignList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //是否有下一页
|
|
|
|
|
+ Boolean toGet = true;
|
|
|
|
|
+ if (details.size() < page_size) {
|
|
|
|
|
+ toGet = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (toGet) {
|
|
|
|
|
+ getAdPlanReport(advertiserId, accessToken, startDate, endDate, page + 1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("快手广告计划数据获取完成:accountId:{}", advertiserId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 获取代理商数据
|
|
|
|
|
- * @param token
|
|
|
|
|
- * @param agentId
|
|
|
|
|
- * @param startDate
|
|
|
|
|
- * @param endDate
|
|
|
|
|
- * @param page
|
|
|
|
|
- */
|
|
|
|
|
- private void getAgentReport(String token, Long agentId, String startDate, String endDate, int page) {
|
|
|
|
|
- try {
|
|
|
|
|
- Integer page_size = 1000;
|
|
|
|
|
- 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", page_size);
|
|
|
|
|
- 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);
|
|
|
|
|
- }
|
|
|
|
|
- //是否有下一页
|
|
|
|
|
- Boolean toGet = true;
|
|
|
|
|
- if (details.size() < page_size) {
|
|
|
|
|
- toGet = false;
|
|
|
|
|
- }
|
|
|
|
|
- if (toGet) {
|
|
|
|
|
- getAgentReport(token, agentId, startDate, endDate, page + 1);
|
|
|
|
|
- } else {
|
|
|
|
|
- log.info("快手代理商数据获取完成========");
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 快手-代理商数据
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void getAgentReport() {
|
|
|
|
|
+ // 前一天 时间
|
|
|
|
|
+ String date = DateUtils.getAnotherDay("yyyy-MM-dd", DateUtils.getNowDate("yyyy-MM-dd"), -2);
|
|
|
|
|
+ String date1 = DateUtils.getAnotherDay("yyyy-MM-dd", DateUtils.getNowDate("yyyy-MM-dd"), -1);
|
|
|
|
|
+ List<Long> appList = new ArrayList<>();
|
|
|
|
|
+ appList.add(27L);
|
|
|
|
|
+ appList.add(165893351L);
|
|
|
|
|
+ for (int i = 0; i < appList.size(); i++) {
|
|
|
|
|
+ Long appId = appList.get(i);
|
|
|
|
|
+ log.info("获取代理商数据appId:{}", appId);
|
|
|
|
|
+ OauthAgentToken agentToken = agentTokenMapper.getTokenByAppId(appId);
|
|
|
|
|
+ log.info("获取代理商数据授权信息:{}", agentToken);
|
|
|
|
|
+ getAgentReport(agentToken.getAccessToken(), agentToken.getAgentId(), date, date1, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- *
|
|
|
|
|
- * @description: 广告主数据
|
|
|
|
|
- *
|
|
|
|
|
- * @param advertiserId
|
|
|
|
|
- * @param accessToken
|
|
|
|
|
- * @param startDate
|
|
|
|
|
- * @param endDate
|
|
|
|
|
- * @param page
|
|
|
|
|
- * @param temporalGranularity 天粒度(DAILY)/小时粒度(HOURLY),默认支持天粒度数据
|
|
|
|
|
- * @param reportDims "adScene":按广告场景;"placementType":按广告范围,快手/联盟;不传/传空/传空数组:不限
|
|
|
|
|
- * @return: void
|
|
|
|
|
- * @author: zianY
|
|
|
|
|
- * @time: 2022/1/6
|
|
|
|
|
- */
|
|
|
|
|
- @Override
|
|
|
|
|
- public void getKuaishouAccountAdSceneDaily(Long advertiserId, String accessToken, String startDate, String endDate, int page,String temporalGranularity,List<String> reportDims) {
|
|
|
|
|
- log.info("获取账户日报====广告场景====,账户id:{},开始时间:{},结束时间:{},page--{}", advertiserId, startDate, endDate,page);
|
|
|
|
|
- Integer page_size = 2000;
|
|
|
|
|
- String url = postUrl + KuaishouConstant.ACCOUNT_REPORT;
|
|
|
|
|
- Map<String, String> headers = new HashMap<>();
|
|
|
|
|
- headers.put("Access-Token", accessToken);
|
|
|
|
|
- Map<String, Object> param = new HashMap<>();
|
|
|
|
|
- param.put("start_date", startDate);
|
|
|
|
|
- param.put("end_date", endDate);
|
|
|
|
|
- param.put("advertiser_id", advertiserId);
|
|
|
|
|
- param.put("temporal_granularity", temporalGranularity);
|
|
|
|
|
- param.put("report_dims", reportDims);
|
|
|
|
|
- param.put("page_size", page_size);
|
|
|
|
|
- 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<KuaishouAccountAdSceneReportDaily> addList = new ArrayList<>();
|
|
|
|
|
- for (int i = 0; i < details.size(); i++) {
|
|
|
|
|
- JSONObject returnJson = details.getJSONObject(i);
|
|
|
|
|
- returnJson.put("advertiser_id",advertiserId);
|
|
|
|
|
- KuaishouAccountAdSceneReportDaily reportDaily = KuaishouAccountAdSceneReportDaily.getKuaishouAccountAdsecneInfo(returnJson);
|
|
|
|
|
- addList.add(reportDaily);
|
|
|
|
|
- }
|
|
|
|
|
- if (!Check.isNull(addList)) {
|
|
|
|
|
- accountAdSceneReportDailyMapper.replaceBatchKsAccountAdScene(addList);
|
|
|
|
|
- }
|
|
|
|
|
- //是否有下一页
|
|
|
|
|
- Boolean toGet = true;
|
|
|
|
|
- if (details.size() < page_size) {
|
|
|
|
|
- toGet = false;
|
|
|
|
|
- }
|
|
|
|
|
- if (toGet) {
|
|
|
|
|
- getKuaishouAccountAdSceneDaily(advertiserId, accessToken, startDate, endDate, page + 1,temporalGranularity,reportDims);
|
|
|
|
|
- } else {
|
|
|
|
|
- log.info("账户日报数据====广告场景=====获取完成:accountId:{}", advertiserId);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取代理商数据
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param token
|
|
|
|
|
+ * @param agentId
|
|
|
|
|
+ * @param startDate
|
|
|
|
|
+ * @param endDate
|
|
|
|
|
+ * @param page
|
|
|
|
|
+ */
|
|
|
|
|
+ private void getAgentReport(String token, Long agentId, String startDate, String endDate, int page) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Integer page_size = 1000;
|
|
|
|
|
+ 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", page_size);
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
|
|
+ //是否有下一页
|
|
|
|
|
+ Boolean toGet = true;
|
|
|
|
|
+ if (details.size() < page_size) {
|
|
|
|
|
+ toGet = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (toGet) {
|
|
|
|
|
+ getAgentReport(token, agentId, startDate, endDate, page + 1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("快手代理商数据获取完成========");
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 快手-人群报表
|
|
|
|
|
- * @param advertiserId
|
|
|
|
|
- * @param accessToken
|
|
|
|
|
- * @param date
|
|
|
|
|
- * @param campaignIds 广告计划 ID 集
|
|
|
|
|
- * @param unitIds 广告组 ID 集
|
|
|
|
|
- * @param reportDims 人群报表类型
|
|
|
|
|
- * @param page
|
|
|
|
|
- */
|
|
|
|
|
- @Override
|
|
|
|
|
- public void crowdAnalysisReport(Long advertiserId, String accessToken, String date, List<Long> campaignIds,List<Long> unitIds, List<String> reportDims,Integer page) {
|
|
|
|
|
- log.info("获取人群报表===={}====,账户id:{},开始时间:{},结束时间:{},page==={}", reportDims,advertiserId, date, date,page);
|
|
|
|
|
- try {
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param advertiserId
|
|
|
|
|
+ * @param accessToken
|
|
|
|
|
+ * @param startDate
|
|
|
|
|
+ * @param endDate
|
|
|
|
|
+ * @param page
|
|
|
|
|
+ * @param temporalGranularity 天粒度(DAILY)/小时粒度(HOURLY),默认支持天粒度数据
|
|
|
|
|
+ * @param reportDims "adScene":按广告场景;"placementType":按广告范围,快手/联盟;不传/传空/传空数组:不限
|
|
|
|
|
+ * @description: 广告主数据
|
|
|
|
|
+ * @return: void
|
|
|
|
|
+ * @author: zianY
|
|
|
|
|
+ * @time: 2022/1/6
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void getKuaishouAccountAdSceneDaily(Long advertiserId, String accessToken, String startDate, String endDate, int page, String temporalGranularity, List<String> reportDims) {
|
|
|
|
|
+ log.info("获取账户日报====广告场景====,账户id:{},开始时间:{},结束时间:{},page--{}", advertiserId, startDate, endDate, page);
|
|
|
Integer page_size = 2000;
|
|
Integer page_size = 2000;
|
|
|
|
|
+ String url = postUrl + KuaishouConstant.ACCOUNT_REPORT;
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
Map<String, String> headers = new HashMap<>();
|
|
|
headers.put("Access-Token", accessToken);
|
|
headers.put("Access-Token", accessToken);
|
|
|
- headers.put("Content-Type", "application/json");
|
|
|
|
|
- JSONObject requestJson = new JSONObject();
|
|
|
|
|
- requestJson.put("advertiser_id", advertiserId);
|
|
|
|
|
- requestJson.put("start_date", date);
|
|
|
|
|
- requestJson.put("end_date", date);
|
|
|
|
|
- requestJson.put("campaign_ids", campaignIds);
|
|
|
|
|
- requestJson.put("unit_ids", unitIds);
|
|
|
|
|
- requestJson.put("report_dims", reportDims);
|
|
|
|
|
- requestJson.put("page", page);
|
|
|
|
|
- requestJson.put("page_size", page_size);
|
|
|
|
|
- String result = HttpUtils.httpPostRequest(postUrl + KuaishouConstant.AUDIENCE_REPORT, requestJson, headers);
|
|
|
|
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
|
|
+ param.put("start_date", startDate);
|
|
|
|
|
+ param.put("end_date", endDate);
|
|
|
|
|
+ param.put("advertiser_id", advertiserId);
|
|
|
|
|
+ param.put("temporal_granularity", temporalGranularity);
|
|
|
|
|
+ param.put("report_dims", reportDims);
|
|
|
|
|
+ param.put("page_size", page_size);
|
|
|
|
|
+ param.put("page", page);
|
|
|
|
|
+ String result = HttpUtils.httpPostRequest(url, param, headers);
|
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
Integer code = resultJson.getInteger("code");
|
|
Integer code = resultJson.getInteger("code");
|
|
|
|
|
+ String message = resultJson.getString("message");
|
|
|
if (null == code || code != 0) {
|
|
if (null == code || code != 0) {
|
|
|
- log.error("获取快手======{}===人群报表=====异常:{},accountId:{}",reportDims, resultJson.getString("message"), advertiserId);
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ log.error("获取快手广告主日报===按广告场景=====异常:{},accountId:{}", message, advertiserId);
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
|
|
JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
|
|
|
if (null == details || details.size() <= 0) {
|
|
if (null == details || details.size() <= 0) {
|
|
|
- log.error("快手人群报表==={}=====返回详情为空,accountId:{}", reportDims,advertiserId);
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ log.error("快手日报===按广告场景=====返回详情为空,accountId:{}", advertiserId);
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
- List<KuaishouAudienceReportDaily> provinceList = new ArrayList<>();
|
|
|
|
|
- List<KuaishouAudienceReportDaily> cityList = new ArrayList<>();
|
|
|
|
|
- List<KuaishouAudienceReportDaily> ageList = new ArrayList<>();
|
|
|
|
|
- List<KuaishouAudienceReportDaily> genderList = new ArrayList<>();
|
|
|
|
|
|
|
+ List<KuaishouAccountAdSceneReportDaily> addList = new ArrayList<>();
|
|
|
for (int i = 0; i < details.size(); i++) {
|
|
for (int i = 0; i < details.size(); i++) {
|
|
|
- JSONObject returnJson = details.getJSONObject(i);
|
|
|
|
|
- returnJson.put("advertiser_id",advertiserId);
|
|
|
|
|
- KuaishouAudienceReportDaily reportDaily = KuaishouAudienceReportDaily.getKuaishouAudienceInfo(returnJson);
|
|
|
|
|
- //省份
|
|
|
|
|
- if (reportDims.contains("province")){
|
|
|
|
|
- provinceList.add(reportDaily);
|
|
|
|
|
- }
|
|
|
|
|
- //城市
|
|
|
|
|
- if (reportDims.contains("city")){
|
|
|
|
|
- cityList.add(reportDaily);
|
|
|
|
|
- }
|
|
|
|
|
- //年龄
|
|
|
|
|
- if (reportDims.contains("ageSegment")){
|
|
|
|
|
- ageList.add(reportDaily);
|
|
|
|
|
- }
|
|
|
|
|
- //性别
|
|
|
|
|
- if (reportDims.contains("gender")){
|
|
|
|
|
- genderList.add(reportDaily);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (reportDims.contains("province")){
|
|
|
|
|
- audienceReportDailyMapper.replaceBatchKsAudienceProvince(provinceList);
|
|
|
|
|
- }
|
|
|
|
|
- if (reportDims.contains("city")){
|
|
|
|
|
- audienceReportDailyMapper.replaceBatchKsAudienceCity(cityList);
|
|
|
|
|
- }
|
|
|
|
|
- if (reportDims.contains("ageSegment")){
|
|
|
|
|
- audienceReportDailyMapper.replaceBatchKsAudienceAge(ageList);
|
|
|
|
|
- }
|
|
|
|
|
- if (reportDims.contains("gender")){
|
|
|
|
|
- audienceReportDailyMapper.replaceBatchKsAudienceGender(genderList);
|
|
|
|
|
- }
|
|
|
|
|
- //是否有下一页
|
|
|
|
|
- Boolean toGet = true;
|
|
|
|
|
- if (details.size() < page_size) {
|
|
|
|
|
- toGet = false;
|
|
|
|
|
- }
|
|
|
|
|
- if (toGet) {
|
|
|
|
|
- crowdAnalysisReport(advertiserId, accessToken, date,campaignIds,unitIds, reportDims,page+1);
|
|
|
|
|
- } else {
|
|
|
|
|
- log.info("快手人群报表==={}==========获取完成:accountId:{}", reportDims,advertiserId);
|
|
|
|
|
- }
|
|
|
|
|
- }catch (Exception e){
|
|
|
|
|
- log.info(String.valueOf(e));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ JSONObject returnJson = details.getJSONObject(i);
|
|
|
|
|
+ returnJson.put("advertiser_id", advertiserId);
|
|
|
|
|
+ KuaishouAccountAdSceneReportDaily reportDaily = KuaishouAccountAdSceneReportDaily.getKuaishouAccountAdsecneInfo(returnJson);
|
|
|
|
|
+ addList.add(reportDaily);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Check.isNull(addList)) {
|
|
|
|
|
+ accountAdSceneReportDailyMapper.replaceBatchKsAccountAdScene(addList);
|
|
|
|
|
+ }
|
|
|
|
|
+ //是否有下一页
|
|
|
|
|
+ Boolean toGet = true;
|
|
|
|
|
+ if (details.size() < page_size) {
|
|
|
|
|
+ toGet = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (toGet) {
|
|
|
|
|
+ getKuaishouAccountAdSceneDaily(advertiserId, accessToken, startDate, endDate, page + 1, temporalGranularity, reportDims);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("账户日报数据====广告场景=====获取完成:accountId:{}", advertiserId);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 快手-账户流水
|
|
|
|
|
- * @param advertiserId
|
|
|
|
|
- * @param accessToken
|
|
|
|
|
- * @param page
|
|
|
|
|
- */
|
|
|
|
|
- @Override
|
|
|
|
|
- public void getKuaishouDailyFlows(Long advertiserId, String accessToken,int page) {
|
|
|
|
|
- log.info("获取账户流水========,账户id:{},page--{}", advertiserId,page);
|
|
|
|
|
- Integer page_size = 500;
|
|
|
|
|
- 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", page_size);
|
|
|
|
|
- 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);
|
|
|
|
|
- }
|
|
|
|
|
- //是否有下一页
|
|
|
|
|
- Boolean toGet = true;
|
|
|
|
|
- if (details.size() < page_size) {
|
|
|
|
|
- toGet = false;
|
|
|
|
|
- }
|
|
|
|
|
- if (toGet) {
|
|
|
|
|
- getKuaishouDailyFlows(advertiserId, accessToken, page + 1);
|
|
|
|
|
- } else {
|
|
|
|
|
- log.info("账户流水========获取完成:accountId:{}", advertiserId);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 快手-账户余额
|
|
|
|
|
- * @param advertiserId
|
|
|
|
|
- */
|
|
|
|
|
- @Override
|
|
|
|
|
- public void getKuaishouDailyFundGet(Long advertiserId,String accessToken) {
|
|
|
|
|
- log.info("获取账户余额========,账户id:{}", advertiserId);
|
|
|
|
|
- String url = postUrl + KuaishouConstant.FUND_GET;
|
|
|
|
|
- Map<String, String> headers = new HashMap<>();
|
|
|
|
|
- headers.put("Access-Token", accessToken);
|
|
|
|
|
- Map<String, Object> param = new HashMap<>();
|
|
|
|
|
- param.put("advertiser_id", advertiserId);
|
|
|
|
|
- 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;
|
|
|
|
|
- }
|
|
|
|
|
- JSONObject details = resultJson.getJSONObject("data");
|
|
|
|
|
- if (null == details || details.size() <= 0) {
|
|
|
|
|
- log.error("快手账户余额=====返回详情为空,accountId:{}", advertiserId);
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 快手-人群报表
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param advertiserId
|
|
|
|
|
+ * @param accessToken
|
|
|
|
|
+ * @param date
|
|
|
|
|
+ * @param campaignIds 广告计划 ID 集
|
|
|
|
|
+ * @param unitIds 广告组 ID 集
|
|
|
|
|
+ * @param reportDims 人群报表类型
|
|
|
|
|
+ * @param page
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void crowdAnalysisReport(Long advertiserId, String accessToken, String date, List<Long> campaignIds, List<Long> unitIds, List<String> reportDims, Integer page) {
|
|
|
|
|
+ log.info("获取人群报表===={}====,账户id:{},开始时间:{},结束时间:{},page==={}", reportDims, advertiserId, date, date, page);
|
|
|
|
|
+ try {
|
|
|
|
|
+ Integer page_size = 2000;
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
|
|
+ JSONObject requestJson = new JSONObject();
|
|
|
|
|
+ requestJson.put("advertiser_id", advertiserId);
|
|
|
|
|
+ requestJson.put("start_date", date);
|
|
|
|
|
+ requestJson.put("end_date", date);
|
|
|
|
|
+ requestJson.put("campaign_ids", campaignIds);
|
|
|
|
|
+ requestJson.put("unit_ids", unitIds);
|
|
|
|
|
+ requestJson.put("report_dims", reportDims);
|
|
|
|
|
+ requestJson.put("page", page);
|
|
|
|
|
+ requestJson.put("page_size", page_size);
|
|
|
|
|
+ String result = HttpUtils.httpPostRequest(postUrl + KuaishouConstant.AUDIENCE_REPORT, requestJson, headers);
|
|
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
|
|
+ if (null == code || code != 0) {
|
|
|
|
|
+ log.error("获取快手======{}===人群报表=====异常:{},accountId:{}", reportDims, resultJson.getString("message"), advertiserId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
|
|
|
|
|
+ if (null == details || details.size() <= 0) {
|
|
|
|
|
+ log.error("快手人群报表==={}=====返回详情为空,accountId:{}", reportDims, advertiserId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<KuaishouAudienceReportDaily> provinceList = new ArrayList<>();
|
|
|
|
|
+ List<KuaishouAudienceReportDaily> cityList = new ArrayList<>();
|
|
|
|
|
+ List<KuaishouAudienceReportDaily> ageList = new ArrayList<>();
|
|
|
|
|
+ List<KuaishouAudienceReportDaily> genderList = new ArrayList<>();
|
|
|
|
|
+ for (int i = 0; i < details.size(); i++) {
|
|
|
|
|
+ JSONObject returnJson = details.getJSONObject(i);
|
|
|
|
|
+ returnJson.put("advertiser_id", advertiserId);
|
|
|
|
|
+ KuaishouAudienceReportDaily reportDaily = KuaishouAudienceReportDaily.getKuaishouAudienceInfo(returnJson);
|
|
|
|
|
+ //省份
|
|
|
|
|
+ if (reportDims.contains("province")) {
|
|
|
|
|
+ provinceList.add(reportDaily);
|
|
|
|
|
+ }
|
|
|
|
|
+ //城市
|
|
|
|
|
+ if (reportDims.contains("city")) {
|
|
|
|
|
+ cityList.add(reportDaily);
|
|
|
|
|
+ }
|
|
|
|
|
+ //年龄
|
|
|
|
|
+ if (reportDims.contains("ageSegment")) {
|
|
|
|
|
+ ageList.add(reportDaily);
|
|
|
|
|
+ }
|
|
|
|
|
+ //性别
|
|
|
|
|
+ if (reportDims.contains("gender")) {
|
|
|
|
|
+ genderList.add(reportDaily);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (reportDims.contains("province")) {
|
|
|
|
|
+ audienceReportDailyMapper.replaceBatchKsAudienceProvince(provinceList);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (reportDims.contains("city")) {
|
|
|
|
|
+ audienceReportDailyMapper.replaceBatchKsAudienceCity(cityList);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (reportDims.contains("ageSegment")) {
|
|
|
|
|
+ audienceReportDailyMapper.replaceBatchKsAudienceAge(ageList);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (reportDims.contains("gender")) {
|
|
|
|
|
+ audienceReportDailyMapper.replaceBatchKsAudienceGender(genderList);
|
|
|
|
|
+ }
|
|
|
|
|
+ //是否有下一页
|
|
|
|
|
+ Boolean toGet = true;
|
|
|
|
|
+ if (details.size() < page_size) {
|
|
|
|
|
+ toGet = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (toGet) {
|
|
|
|
|
+ crowdAnalysisReport(advertiserId, accessToken, date, campaignIds, unitIds, reportDims, page + 1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("快手人群报表==={}==========获取完成:accountId:{}", reportDims, advertiserId);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.info(String.valueOf(e));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
- details.put("advertiser_id",advertiserId);
|
|
|
|
|
- KuaishouAdvertiserFundGet reportDaily = KuaishouAdvertiserFundGet.getKuaishouFundGetInfo(details);
|
|
|
|
|
- if (!Check.isNull(reportDaily)) {
|
|
|
|
|
- fundDailyFlowsMapper.replaceBatchKsFundGetBalance(reportDaily);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 快手-账户流水
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param advertiserId
|
|
|
|
|
+ * @param accessToken
|
|
|
|
|
+ * @param page
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void getKuaishouDailyFlows(Long advertiserId, String accessToken, int page) {
|
|
|
|
|
+ log.info("获取账户流水========,账户id:{},page--{}", advertiserId, page);
|
|
|
|
|
+ Integer page_size = 500;
|
|
|
|
|
+ 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", page_size);
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
|
|
+ //是否有下一页
|
|
|
|
|
+ Boolean toGet = true;
|
|
|
|
|
+ if (details.size() < page_size) {
|
|
|
|
|
+ toGet = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (toGet) {
|
|
|
|
|
+ getKuaishouDailyFlows(advertiserId, accessToken, page + 1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("账户流水========获取完成:accountId:{}", advertiserId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
- log.info("账户余额========获取完成:accountId:{}", advertiserId);
|
|
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 快手-账户余额
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param advertiserId
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void getKuaishouDailyFundGet(Long advertiserId, String accessToken) {
|
|
|
|
|
+ log.info("获取账户余额========,账户id:{}", advertiserId);
|
|
|
|
|
+ String url = postUrl + KuaishouConstant.FUND_GET;
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
|
|
+ param.put("advertiser_id", advertiserId);
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject details = resultJson.getJSONObject("data");
|
|
|
|
|
+ if (null == details || details.size() <= 0) {
|
|
|
|
|
+ log.error("快手账户余额=====返回详情为空,accountId:{}", advertiserId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ details.put("advertiser_id", advertiserId);
|
|
|
|
|
+ KuaishouAdvertiserFundGet reportDaily = KuaishouAdvertiserFundGet.getKuaishouFundGetInfo(details);
|
|
|
|
|
+ if (!Check.isNull(reportDaily)) {
|
|
|
|
|
+ fundDailyFlowsMapper.replaceBatchKsFundGetBalance(reportDaily);
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("账户余额========获取完成:accountId:{}", advertiserId);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|