|
@@ -1,5 +1,6 @@
|
|
|
package cn.com.ctop.kuaishou.modules.batch.service.impl;
|
|
|
|
|
|
+import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
|
import cn.com.ctop.common.module.utils.HttpUtils;
|
|
|
import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
|
|
@@ -24,6 +25,7 @@ import com.fasterxml.jackson.databind.JsonMappingException;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fasterxml.jackson.databind.type.TypeFactory;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import lombok.var;
|
|
|
import org.apache.http.ParseException;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
import org.jeecg.common.util.LoadFileUtil;
|
|
@@ -101,6 +103,50 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
@Autowired
|
|
|
private KuaiShouAdvertiserBaseInfoMapper advertiserBaseInfoMapper;
|
|
|
|
|
|
+ @Override
|
|
|
+ public void getAdvertiserReportHourly(CtopOauthToken token, Date startDate, Date endDate) {
|
|
|
+ getAdvertiserReportHourlyByPage(token, startDate, endDate, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getAdvertiserReportHourlyByPage(CtopOauthToken token, Date startDate, Date endDate, int page) {
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.ACCOUNT_REPORT;
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Access-Token", token.getAccessToken());
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("start_date", DateUtils.formatDate(startDate));
|
|
|
+ param.put("end_date", DateUtils.formatDate(endDate));
|
|
|
+ param.put("advertiser_id", token.getAccountId());
|
|
|
+ param.put("temporal_granularity", "HOURLY");
|
|
|
+ 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, token.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
|
|
|
+ if (null == details || details.size() <= 0) {
|
|
|
+ log.info("快手广告主时报表信息为空=》accountId:{}", token.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < details.size(); i++) {
|
|
|
+ JSONObject detailJson = details.getJSONObject(i);
|
|
|
+ var show = detailJson.getLong("show");
|
|
|
+ detailJson.put("photo_show", show);
|
|
|
+ var like = detailJson.getLong("like");
|
|
|
+ detailJson.put("photo_like", like);
|
|
|
+ var kuaishouReportHourlyAccount = JSONObject.toJavaObject(detailJson, KuaishouReportHourlyAccount.class);
|
|
|
+ kuaishouReportHourlyAccount.setAccountId(token.getAccountId());
|
|
|
+ kuaishouReportHourlyAccount.setId("" + token.getAccountId() + kuaishouReportHourlyAccount.getStatDate() + kuaishouReportHourlyAccount.getStatHour());
|
|
|
+ hourlyAccountService.saveOrUpdate(kuaishouReportHourlyAccount);
|
|
|
+ }
|
|
|
+ getAdvertiserReportHourlyByPage(token, startDate, endDate, page + 1);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 广告主日报表信息
|
|
|
*
|
|
@@ -110,7 +156,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
* @param endDate
|
|
|
* @param pageSize
|
|
|
* @param pageNum
|
|
|
- * @return
|
|
|
*/
|
|
|
@Override
|
|
|
public KuaishouResult<KuaishouReportHourlyAccount> getAccountHourlyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum) {
|
|
@@ -152,23 +197,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- /*String result = HttpUtils.httpPostRequest(url, param, headers);
|
|
|
- JSONObject resultJson = JSONArray.parseObject(result);
|
|
|
- if (!Check.isNull(resultJson)) {
|
|
|
-
|
|
|
- }
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
- kuaishouResult = mapper.readValue(result, new TypeReference<KuaishouResult<KuaishouReportHourlyAccount>>() {
|
|
|
- });
|
|
|
- List<KuaishouReportHourlyAccount> hourlyAccounts = kuaishouResult.getData().getDetails();
|
|
|
- hourlyAccounts.forEach((hourlyAccount) -> {
|
|
|
- hourlyAccount.setAccountId(advertiserId);
|
|
|
- hourlyAccount.setId("" + hourlyAccount.getAccountId() + hourlyAccount.getStatDate() + hourlyAccount.getStatHour());
|
|
|
- hourlyAccountService.saveOrUpdate(hourlyAccount);
|
|
|
- });*/
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -176,6 +204,52 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void getAdvertiserReportDaily(CtopOauthToken token, Date startDate, Date endDate) {
|
|
|
+ getAccountDailyReportByPage(token, startDate, endDate, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void getAccountDailyReportByPage(CtopOauthToken token, Date startDate, Date endDate, int page) {
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.ACCOUNT_REPORT;
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ headers.put("Access-Token", token.getAccessToken());
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("start_date", DateUtils.formatDate(startDate));
|
|
|
+ param.put("end_date", DateUtils.formatDate(endDate));
|
|
|
+ param.put("advertiser_id", token.getAccountId());
|
|
|
+ param.put("temporal_granularity", "DAILY");
|
|
|
+ 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, token.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
|
|
|
+ if (null == details || details.size() <= 0) {
|
|
|
+ log.info("快手广告主报表信息为空=》accountId:{}", token.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < details.size(); i++) {
|
|
|
+ var detailJson = details.getJSONObject(i);
|
|
|
+ var show = detailJson.getLong("show");
|
|
|
+ detailJson.put("photo_show", show);
|
|
|
+ var like = detailJson.getLong("like");
|
|
|
+ detailJson.put("photo_like", like);
|
|
|
+ var kuaishouReportDailyAccount = JSONObject.toJavaObject(detailJson, KuaishouReportDailyAccount.class);
|
|
|
+ kuaishouReportDailyAccount.setAccountId(token.getAccountId());
|
|
|
+ kuaishouReportDailyAccount.setId("" + token.getAccountId() + kuaishouReportDailyAccount.getStatDate());
|
|
|
+ dailyAccountService.saveOrUpdate(kuaishouReportDailyAccount);
|
|
|
+ }
|
|
|
+ getAccountDailyReportByPage(token, startDate, endDate, page + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public KuaishouResult<KuaishouReportDailyAccount> getAccountDailyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum) {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.ACCOUNT_REPORT;
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
@@ -208,9 +282,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
kuaishouReportDailyAccount.setId("" + advertiserId + kuaishouReportDailyAccount.getStatDate());
|
|
|
dailyAccountService.saveOrUpdate(kuaishouReportDailyAccount);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -221,6 +293,53 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void getAdvertiserCampaignReportDaily(CtopOauthToken token, Date startDate, Date endDate) {
|
|
|
+ getCampaignDailyReportByPage(token, startDate, endDate, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getCampaignDailyReportByPage(CtopOauthToken token, Date startDate, Date endDate, int page) {
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_REPORT;
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ headers.put("Access-Token", token.getAccessToken());
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("start_date", DateUtils.formatDate(startDate));
|
|
|
+ param.put("end_date", DateUtils.formatDate(endDate));
|
|
|
+ param.put("advertiser_id", token.getAccountId());
|
|
|
+ param.put("temporal_granularity", "DAILY");
|
|
|
+ param.put("page_size", 500);
|
|
|
+ param.put("page", page);
|
|
|
+
|
|
|
+ String result = HttpUtils.httpPostRequest(url, param, headers);
|
|
|
+ System.out.println(result);
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ String message = resultJson.getString("message");
|
|
|
+ if (null == code || code != 0) {
|
|
|
+ log.error("获取快手广告计划报表异常:{},accountId:{}", message, token.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
|
|
|
+ if (null == details || details.size() <= 0) {
|
|
|
+ log.info("快手广告计划报表信息为空=》accountId:{}", token.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < details.size(); i++) {
|
|
|
+ var detailJson = details.getJSONObject(i);
|
|
|
+ var show = detailJson.getLong("show");
|
|
|
+ detailJson.put("photo_show", show);
|
|
|
+ var like = detailJson.getLong("like");
|
|
|
+ detailJson.put("photo_like", like);
|
|
|
+ var campaign = JSONObject.toJavaObject(detailJson, KuaishouReportDailyCampaign.class);
|
|
|
+ campaign.setAccountId(token.getAccountId());
|
|
|
+ campaign.setId("" + campaign.getAccountId() + campaign.getCampaignId() + campaign.getStatDate());
|
|
|
+ dailyCampaignService.saveOrUpdate(campaign);
|
|
|
+ }
|
|
|
+ getCampaignDailyReportByPage(token, startDate, endDate, page + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public KuaishouResult<KuaishouReportDailyCampaign> getCampaignDailyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum) {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_REPORT;
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
@@ -254,6 +373,52 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void getAdvertiserCampaignReportHourly(CtopOauthToken token, Date startDate, Date endDate) {
|
|
|
+ getCampaignReportHourlyByPage(token, startDate, endDate, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getCampaignReportHourlyByPage(CtopOauthToken token, Date startDate, Date endDate, int page) {
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_REPORT;
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ headers.put("Access-Token", token.getAccessToken());
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("start_date", DateUtils.formatDate(startDate));
|
|
|
+ param.put("end_date", DateUtils.formatDate(endDate));
|
|
|
+ param.put("advertiser_id", token.getAccountId());
|
|
|
+ param.put("temporal_granularity", "HOURLY");
|
|
|
+ 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, token.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
|
|
|
+ if (null == details || details.size() <= 0) {
|
|
|
+ log.info("快手广告计划时报表信息为空=》accountId:{}", token.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < details.size(); i++) {
|
|
|
+ JSONObject detailJson = details.getJSONObject(i);
|
|
|
+ var show = detailJson.getLong("show");
|
|
|
+ detailJson.put("photo_show", show);
|
|
|
+ var like = detailJson.getLong("like");
|
|
|
+ detailJson.put("photo_like", like);
|
|
|
+ var hourlyCampaign = JSONObject.toJavaObject(detailJson, KuaishouReportHourlyCampaign.class);
|
|
|
+ hourlyCampaign.setAccountId(token.getAccountId());
|
|
|
+ hourlyCampaign.setId("" + hourlyCampaign.getAccountId() + hourlyCampaign.getCampaignId() + hourlyCampaign.getStatDate() + hourlyCampaign.getStatHour());
|
|
|
+ hourlyCampaignService.saveOrUpdate(hourlyCampaign);
|
|
|
+ }
|
|
|
+ getAdvertiserReportHourlyByPage(token, startDate, endDate, page + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
public KuaishouResult<KuaishouReportHourlyCampaign> getCampaignHourlyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum) {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_REPORT;
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
@@ -299,6 +464,51 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
private IKuaishouReportHourlyCreativeService hourlyCreativeService;
|
|
|
|
|
|
@Override
|
|
|
+ public void getAdvertiserGroupReportDaily(CtopOauthToken token, Date startDate, Date endDate) {
|
|
|
+ getAdvertiserGroupReportDailyByPage(token, startDate, endDate, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getAdvertiserGroupReportDailyByPage(CtopOauthToken token, Date startDate, Date endDate, int page) {
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GTOUP_REPORT;
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ headers.put("Access-Token", token.getAccessToken());
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("start_date", DateUtils.formatDate(startDate));
|
|
|
+ param.put("end_date", DateUtils.formatDate(endDate));
|
|
|
+ param.put("advertiser_id", token.getAccountId());
|
|
|
+ param.put("temporal_granularity", "DAILY");
|
|
|
+ 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, token.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
|
|
|
+ if (null == details || details.size() <= 0) {
|
|
|
+ log.info("快手广告组报表信息为空=》accountId:{}", token.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < details.size(); i++) {
|
|
|
+ var detailJson = details.getJSONObject(i);
|
|
|
+ var show = detailJson.getLong("show");
|
|
|
+ detailJson.put("photo_show", show);
|
|
|
+ var like = detailJson.getLong("like");
|
|
|
+ detailJson.put("photo_like", like);
|
|
|
+ var dailyGroup = JSONObject.toJavaObject(detailJson, KuaishouReportDailyGroup.class);
|
|
|
+ dailyGroup.setAccountId(token.getAccountId());
|
|
|
+ dailyGroup.setId("" + dailyGroup.getAccountId() + dailyGroup.getGroupId() + dailyGroup.getStatDate());
|
|
|
+ dailyGroupService.saveOrUpdate(dailyGroup);
|
|
|
+ }
|
|
|
+ getAdvertiserGroupReportDailyByPage(token, startDate, endDate, page + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public KuaishouResult<KuaishouReportDailyGroup> getGroupDailyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum) {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GTOUP_REPORT;
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
@@ -331,6 +541,51 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void getAdvertiserGroupReportHourly(CtopOauthToken token, Date startDate, Date endDate) {
|
|
|
+ getGroupHourlyReportByPage(token, startDate, endDate, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getGroupHourlyReportByPage(CtopOauthToken token, Date startDate, Date endDate, int page) {
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GTOUP_REPORT;
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ headers.put("Access-Token", token.getAccessToken());
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("start_date", DateUtils.formatDate(startDate));
|
|
|
+ param.put("end_date", DateUtils.formatDate(endDate));
|
|
|
+ param.put("advertiser_id", token.getAccountId());
|
|
|
+ param.put("temporal_granularity", "HOURLY");
|
|
|
+ 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, token.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
|
|
|
+ if (null == details || details.size() <= 0) {
|
|
|
+ log.info("快手广告组时报表信息为空=》accountId:{}", token.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < details.size(); i++) {
|
|
|
+ JSONObject detailJson = details.getJSONObject(i);
|
|
|
+ var show = detailJson.getLong("show");
|
|
|
+ detailJson.put("photo_show", show);
|
|
|
+ var like = detailJson.getLong("like");
|
|
|
+ detailJson.put("photo_like", like);
|
|
|
+ var hourlyGroup = JSONObject.toJavaObject(detailJson, KuaishouReportHourlyGroup.class);
|
|
|
+ hourlyGroup.setAccountId(token.getAccountId());
|
|
|
+ hourlyGroup.setId("" + hourlyGroup.getAccountId() + hourlyGroup.getGroupId() + hourlyGroup.getStatDate() + hourlyGroup.getStatHour());
|
|
|
+ hourlyGroupService.saveOrUpdate(hourlyGroup);
|
|
|
+ }
|
|
|
+ getGroupHourlyReportByPage(token, startDate, endDate, page + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public KuaishouResult<KuaishouReportHourlyGroup> getGroupHourlyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum) {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GTOUP_REPORT;
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
@@ -363,6 +618,52 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void getAdvertiserCreativeReportDaily(CtopOauthToken token, Date startDate, Date endDate) {
|
|
|
+ getAdvertiserCreativeReportDailyByPage(token, startDate, endDate, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getAdvertiserCreativeReportDailyByPage(CtopOauthToken token, Date startDate, Date endDate, int page) {
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_REPORT;
|
|
|
+ Map<String, String> headers = new HashMap<String, String>();
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ headers.put("Access-Token", token.getAccessToken());
|
|
|
+ Map<String, Object> param = new HashMap<String, Object>();
|
|
|
+ param.put("start_date", DateUtils.formatDate(startDate));
|
|
|
+ param.put("end_date", DateUtils.formatDate(endDate));
|
|
|
+ param.put("advertiser_id", token.getAccountId());
|
|
|
+ param.put("temporal_granularity", "DAILY");
|
|
|
+ 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, token.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
|
|
|
+ if (null == details || details.size() <= 0) {
|
|
|
+ log.info("快手广告创意报表信息为空=》accountId:{}", token.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < details.size(); i++) {
|
|
|
+ var detailJson = details.getJSONObject(i);
|
|
|
+ var show = detailJson.getLong("show");
|
|
|
+ detailJson.put("photo_show", show);
|
|
|
+ var like = detailJson.getLong("like");
|
|
|
+ detailJson.put("photo_like", like);
|
|
|
+ var creative = JSONObject.toJavaObject(detailJson, KuaishouReportDailyCreative.class);
|
|
|
+ creative.setAccountId(token.getAccountId());
|
|
|
+ creative.setId("" + creative.getAccountId() + creative.getCreativeId() + creative.getStatDate());
|
|
|
+ dailyCreativeService.saveOrUpdate(creative);
|
|
|
+ }
|
|
|
+ getAdvertiserCreativeReportDailyByPage(token, startDate, endDate, page + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public KuaishouResult<KuaishouReportDailyCreative> getCreativeDailyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum) {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_REPORT;
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
@@ -395,6 +696,51 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void getAdvertiserCreativeReportHourly(CtopOauthToken token, Date startDate, Date endDate) {
|
|
|
+ getAdvertiserCreativeReportHourlyByPage(token, startDate, endDate, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getAdvertiserCreativeReportHourlyByPage(CtopOauthToken token, Date startDate, Date endDate, int page) {
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_REPORT;
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ headers.put("Access-Token", token.getAccessToken());
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("start_date", DateUtils.formatDate(startDate));
|
|
|
+ param.put("end_date", DateUtils.formatDate(endDate));
|
|
|
+ param.put("advertiser_id", token.getAccountId());
|
|
|
+ param.put("temporal_granularity", "HOURLY");
|
|
|
+ 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, token.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
|
|
|
+ if (null == details || details.size() <= 0) {
|
|
|
+ log.info("快手广告创意时报表信息为空=》accountId:{}", token.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < details.size(); i++) {
|
|
|
+ JSONObject detailJson = details.getJSONObject(i);
|
|
|
+ var show = detailJson.getLong("show");
|
|
|
+ detailJson.put("photo_show", show);
|
|
|
+ var like = detailJson.getLong("like");
|
|
|
+ detailJson.put("photo_like", like);
|
|
|
+ var creative = JSONObject.toJavaObject(detailJson, KuaishouReportHourlyCreative.class);
|
|
|
+ creative.setAccountId(token.getAccountId());
|
|
|
+ creative.setId("" + creative.getAccountId() + creative.getCreativeId() + creative.getStatDate() + creative.getStatHour());
|
|
|
+ hourlyCreativeService.saveOrUpdate(creative);
|
|
|
+ }
|
|
|
+ getAdvertiserCreativeReportHourlyByPage(token, startDate, endDate, page + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public KuaishouResult<KuaishouReportHourlyCreative> getCreativeHourlyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum) {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_REPORT;
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
@@ -430,10 +776,9 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
/**
|
|
|
* 创建广告计划
|
|
|
*
|
|
|
- * @param accessToken
|
|
|
- * @param advertiserId
|
|
|
- * @param requestJson
|
|
|
- * @return
|
|
|
+ * @param accessToken token信息
|
|
|
+ * @param advertiserId 广告主id
|
|
|
+ * @param requestJson 请求参数拼装
|
|
|
*/
|
|
|
@Override
|
|
|
public Map<String, Object> campaignCreate(String accessToken, Long advertiserId, JSONObject requestJson) {
|