|
@@ -1,12 +1,12 @@
|
|
package cn.com.ctop.kuaishou.modules.batch.service.impl;
|
|
package cn.com.ctop.kuaishou.modules.batch.service.impl;
|
|
|
|
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
|
+import cn.com.ctop.common.module.entity.UserAllocation;
|
|
|
|
+import cn.com.ctop.common.module.service.IUserAllocationService;
|
|
import cn.com.ctop.common.module.utils.*;
|
|
import cn.com.ctop.common.module.utils.*;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.*;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.*;
|
|
import cn.com.ctop.kuaishou.modules.batch.mapper.*;
|
|
import cn.com.ctop.kuaishou.modules.batch.mapper.*;
|
|
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreativeService;
|
|
|
|
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
|
|
|
|
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
|
|
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.*;
|
|
import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResult;
|
|
import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResult;
|
|
import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResultToken;
|
|
import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResultToken;
|
|
import cn.com.ctop.kuaishou.modules.report.entity.*;
|
|
import cn.com.ctop.kuaishou.modules.report.entity.*;
|
|
@@ -226,7 +226,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
log.info("快手视频列表信息为空=》accountId:{}", token.getAccountId());
|
|
log.info("快手视频列表信息为空=》accountId:{}", token.getAccountId());
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ System.out.println(details.toJSONString());
|
|
for (int i = 0; i < details.size(); i++) {
|
|
for (int i = 0; i < details.size(); i++) {
|
|
var detailJson = details.getJSONObject(i);
|
|
var detailJson = details.getJSONObject(i);
|
|
var kuaiShouVideoGet = JSONObject.toJavaObject(detailJson, KuaiShouVideoGet.class);
|
|
var kuaiShouVideoGet = JSONObject.toJavaObject(detailJson, KuaiShouVideoGet.class);
|
|
@@ -691,11 +691,41 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
var creative = JSONObject.toJavaObject(detailJson, KuaishouReportDailyCreative.class);
|
|
var creative = JSONObject.toJavaObject(detailJson, KuaishouReportDailyCreative.class);
|
|
creative.setAccountId(token.getAccountId());
|
|
creative.setAccountId(token.getAccountId());
|
|
creative.setId("" + creative.getAccountId() + creative.getCreativeId() + creative.getStatDate());
|
|
creative.setId("" + creative.getAccountId() + creative.getCreativeId() + creative.getStatDate());
|
|
|
|
+ KuaishouReportDailyCreativeStatistic statistic = setDailyStatistic(creative, token);
|
|
|
|
+ dailyCreativeStatisticService.saveOrUpdate(statistic);
|
|
dailyCreativeService.saveOrUpdate(creative);
|
|
dailyCreativeService.saveOrUpdate(creative);
|
|
}
|
|
}
|
|
getAdvertiserCreativeReportDailyByPage(token, startDate, endDate, page + 1);
|
|
getAdvertiserCreativeReportDailyByPage(token, startDate, endDate, page + 1);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private KuaishouReportDailyCreativeStatistic setDailyStatistic(KuaishouReportDailyCreative creative, CtopOauthToken token) {
|
|
|
|
+ KuaishouReportDailyCreativeStatistic statistic = new KuaishouReportDailyCreativeStatistic(creative);
|
|
|
|
+ KuaiShouCreative getCreative = kuaiShouCreativeService.getById(creative.getId());
|
|
|
|
+ if (null != getCreative) {
|
|
|
|
+ statistic.setCreativeName(getCreative.getCreativeName());
|
|
|
|
+ KuaiShouCampaign getCampaign = kuaiShouCampaignService.getById(getCreative.getCampaignId());
|
|
|
|
+ if (null != getCampaign) {
|
|
|
|
+ statistic.setCampaignId(getCampaign.getCampaignId());
|
|
|
|
+ statistic.setCampaignName(getCampaign.getCampaignName());
|
|
|
|
+ }
|
|
|
|
+ KuaiShouGroup getGroup = kuaiShouGroupService.getById(getCreative.getUnitId());
|
|
|
|
+ if (null != getGroup) {
|
|
|
|
+ statistic.setUnitId(getGroup.getUnitId());
|
|
|
|
+ statistic.setUnitName(getGroup.getUnitName());
|
|
|
|
+ }
|
|
|
|
+ KuaiShouVideoGet getVideo = kuaiShouVideoGetService.getById("" + token.getAccountId() + getCreative.getPhotoId());
|
|
|
|
+ if (null != getVideo) {
|
|
|
|
+ statistic.setSignature(getVideo.getSignature());
|
|
|
|
+ statistic.setUrl(getVideo.getUrl());
|
|
|
|
+ }
|
|
|
|
+ UserAllocation allocation = userAllocationService.getByAccountId(token.getAccountId());
|
|
|
|
+ if (null != allocation) {
|
|
|
|
+ statistic.setAccountName(allocation.getAuthName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return statistic;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public KuaishouResult<KuaishouReportDailyCreative> getCreativeDailyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum) {
|
|
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;
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_REPORT;
|
|
@@ -733,6 +763,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
getAdvertiserCreativeReportHourlyByPage(token, startDate, endDate, 1);
|
|
getAdvertiserCreativeReportHourlyByPage(token, startDate, endDate, 1);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
private void getAdvertiserCreativeReportHourlyByPage(CtopOauthToken token, Date startDate, Date endDate, int page) {
|
|
private void getAdvertiserCreativeReportHourlyByPage(CtopOauthToken token, Date startDate, Date endDate, int page) {
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_REPORT;
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_REPORT;
|
|
Map<String, String> headers = new HashMap<>();
|
|
Map<String, String> headers = new HashMap<>();
|
|
@@ -768,11 +799,54 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
var creative = JSONObject.toJavaObject(detailJson, KuaishouReportHourlyCreative.class);
|
|
var creative = JSONObject.toJavaObject(detailJson, KuaishouReportHourlyCreative.class);
|
|
creative.setAccountId(token.getAccountId());
|
|
creative.setAccountId(token.getAccountId());
|
|
creative.setId("" + creative.getAccountId() + creative.getCreativeId() + creative.getStatDate() + creative.getStatHour());
|
|
creative.setId("" + creative.getAccountId() + creative.getCreativeId() + creative.getStatDate() + creative.getStatHour());
|
|
|
|
+ KuaishouReportHourlyCreativeStatistic statistic = setHourlyStatistic(creative, token);
|
|
|
|
+ hourlyCreativeStatisticService.saveOrUpdate(statistic);
|
|
hourlyCreativeService.saveOrUpdate(creative);
|
|
hourlyCreativeService.saveOrUpdate(creative);
|
|
}
|
|
}
|
|
getAdvertiserCreativeReportHourlyByPage(token, startDate, endDate, page + 1);
|
|
getAdvertiserCreativeReportHourlyByPage(token, startDate, endDate, page + 1);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaiShouCreativeService kuaiShouCreativeService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaiShouCampaignService kuaiShouCampaignService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaiShouGroupService kuaiShouGroupService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IUserAllocationService userAllocationService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaishouReportHourlyCreativeStatisticService hourlyCreativeStatisticService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaishouReportDailyCreativeStatisticService dailyCreativeStatisticService;
|
|
|
|
+
|
|
|
|
+ private KuaishouReportHourlyCreativeStatistic setHourlyStatistic(KuaishouReportHourlyCreative creative, CtopOauthToken token) {
|
|
|
|
+ KuaishouReportHourlyCreativeStatistic statistic = new KuaishouReportHourlyCreativeStatistic(creative);
|
|
|
|
+ KuaiShouCreative getCreative = kuaiShouCreativeService.getById(creative.getId());
|
|
|
|
+ if (null != getCreative) {
|
|
|
|
+ statistic.setCreativeName(getCreative.getCreativeName());
|
|
|
|
+ KuaiShouCampaign getCampaign = kuaiShouCampaignService.getById(getCreative.getCampaignId());
|
|
|
|
+ if (null != getCampaign) {
|
|
|
|
+ statistic.setCampaignId(getCampaign.getCampaignId());
|
|
|
|
+ statistic.setCampaignName(getCampaign.getCampaignName());
|
|
|
|
+ }
|
|
|
|
+ KuaiShouGroup getGroup = kuaiShouGroupService.getById(getCreative.getUnitId());
|
|
|
|
+ if (null != getGroup) {
|
|
|
|
+ statistic.setUnitId(getGroup.getUnitId());
|
|
|
|
+ statistic.setUnitName(getGroup.getUnitName());
|
|
|
|
+ }
|
|
|
|
+ KuaiShouVideoGet getVideo = kuaiShouVideoGetService.getById("" + token.getAccountId() + getCreative.getPhotoId());
|
|
|
|
+ if (null != getVideo) {
|
|
|
|
+ statistic.setSignature(getVideo.getSignature());
|
|
|
|
+ statistic.setUrl(getVideo.getUrl());
|
|
|
|
+ }
|
|
|
|
+ UserAllocation allocation = userAllocationService.getByAccountId(token.getAccountId());
|
|
|
|
+ if (null != allocation) {
|
|
|
|
+ statistic.setAccountName(allocation.getAuthName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return statistic;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public KuaishouResult<KuaishouReportHourlyCreative> getCreativeHourlyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum) {
|
|
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;
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_REPORT;
|
|
@@ -972,6 +1046,42 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
return returnMap;
|
|
return returnMap;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void getCampaignList(CtopOauthToken token) {
|
|
|
|
+ getCampaignListByPage(token.getAccessToken(), token.getAccountId(), 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void getCampaignListByPage(String accessToken, Long accountId, int page) {
|
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_LIST;
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
|
+ param.put("advertiser_id", accountId);
|
|
|
|
+ param.put("page", page);
|
|
|
|
+ param.put("page_size", 200);
|
|
|
|
+
|
|
|
|
+ String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
|
+ if (Check.isNull(resultJson)) {
|
|
|
|
+ log.error("获取广告计划信息返回结果异常,advertiserId:{}", accountId);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
|
+ if (null == code || code != 0) {
|
|
|
|
+ log.error("获取广告计划信息返回结果异常,advertiserId:{},异常信息:{}", accountId, resultJson);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
|
+ JSONArray details = dataJson.getJSONArray("details");
|
|
|
|
+ if (Check.isNull(details)) {
|
|
|
|
+ log.info("获取广告计划信息返回结果为空,advertiserId:{}", accountId);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ addCampaign(accountId, details);
|
|
|
|
+ getCreativeListByPage(accessToken, accountId, page + 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 获取广告计划信息
|
|
* 获取广告计划信息
|
|
*
|
|
*
|
|
@@ -981,12 +1091,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public void getCampaignList(String accessToken, Long advertiserId, Integer page) {
|
|
public void getCampaignList(String accessToken, Long advertiserId, Integer page) {
|
|
- // 第一次请求删除历史数据
|
|
|
|
- if (page == 1) {
|
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
|
- map.put("account_id", advertiserId);
|
|
|
|
- campaignMapper.deleteByMap(map);
|
|
|
|
- }
|
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_LIST;
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_LIST;
|
|
Map<String, String> headers = new HashMap<>();
|
|
Map<String, String> headers = new HashMap<>();
|
|
headers.put("Access-Token", accessToken);
|
|
headers.put("Access-Token", accessToken);
|
|
@@ -1072,6 +1176,40 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void getGroupList(CtopOauthToken token) {
|
|
|
|
+ getGroupListByPage(token, 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void getGroupListByPage(CtopOauthToken token, int page) {
|
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GROUP_LIST;
|
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
|
+ param.put("advertiser_id", token.getAccountId());
|
|
|
|
+ param.put("page_size", 200);
|
|
|
|
+ param.put("page", page);
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
+ headers.put("Access-Token", token.getAccessToken());
|
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
|
|
+
|
|
|
|
+ String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
|
+ if (Check.isNull(resultJson)) {
|
|
|
|
+ log.error("获取广告组接口异常,advertiserId:{}", token.getAccountId());
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
|
+ if (null == code || code != 0) {
|
|
|
|
+ log.error("获取广告组返回结果异常,advertiserId:{},异常信息:{}", token.getAccountId(), resultJson);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
|
|
|
|
+ if (Check.isNull(details)) {
|
|
|
|
+ log.info("获取广告组返回结果为空,advertiserId:{}", token.getAccountId());
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ addGroup(token.getAccountId(), details);
|
|
|
|
+ getGroupListByPage(token, page + 1);
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取广告组信息 全量
|
|
* 获取广告组信息 全量
|
|
@@ -1230,6 +1368,11 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void getCreativeList(CtopOauthToken token) {
|
|
|
|
+ getCreativeListByPage(token.getAccessToken(), token.getAccountId(), 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
public void getCreativeListByPage(String accessToken, Long advertiserId, Integer page) {
|
|
public void getCreativeListByPage(String accessToken, Long advertiserId, Integer page) {
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_LIST;
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_LIST;
|
|
Map<String, String> headers = new HashMap<>();
|
|
Map<String, String> headers = new HashMap<>();
|
|
@@ -1319,7 +1462,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
videoGet.setAccountId(advertiserId);
|
|
videoGet.setAccountId(advertiserId);
|
|
videoGet.setWidth(detailJson.getInteger("width"));
|
|
videoGet.setWidth(detailJson.getInteger("width"));
|
|
videoGet.setHeight(detailJson.getInteger("height"));
|
|
videoGet.setHeight(detailJson.getInteger("height"));
|
|
- videoGet.setUrl(detailJson.getLong("unit_id"));
|
|
|
|
|
|
+ videoGet.setUrl(detailJson.getString("url"));
|
|
videoGet.setCoverUrl(detailJson.getString("creative_name"));
|
|
videoGet.setCoverUrl(detailJson.getString("creative_name"));
|
|
videoGet.setPhotoId(detailJson.getString("photo_id"));
|
|
videoGet.setPhotoId(detailJson.getString("photo_id"));
|
|
//videoGet.setSignature(UUID.randomUUID().toString());
|
|
//videoGet.setSignature(UUID.randomUUID().toString());
|