|
|
@@ -23,9 +23,9 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
- * token信息
|
|
|
+ * 快手 定时任务
|
|
|
*
|
|
|
- * @author jeecg-boot 2021-09-07
|
|
|
+ * @author zian Y 2022-01-05
|
|
|
* @version V1.0
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@@ -121,6 +121,7 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
|
|
|
} else {
|
|
|
log.info("快手广告组数据获取完成:accountId:{}", advertiserId);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -184,6 +185,7 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
|
|
|
} else {
|
|
|
log.info("快手广告计划数据获取完成:accountId:{}", advertiserId);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -200,6 +202,7 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
|
|
|
getAgentReport(agentToken.getAccessToken(), agentToken.getAgentId(), date, date, 1);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -214,8 +217,8 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
|
|
|
*/
|
|
|
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);
|
|
|
@@ -223,7 +226,7 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
|
|
|
param.put("start_date", startDate);
|
|
|
param.put("end_date", endDate);
|
|
|
param.put("agent_id", agentId);
|
|
|
- param.put("page_size", 1000);
|
|
|
+ param.put("page_size", page_size);
|
|
|
param.put("page", page);
|
|
|
|
|
|
String result = HttpUtils.httpPostRequest(postUrl + KuaishouConstant.ANGENT_REPORT, param, headers);
|
|
|
@@ -259,10 +262,20 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
|
|
|
if (!Check.isNull(agentList)) {
|
|
|
adUnitReportMapper.replaceBatchAgentReport(agentList);
|
|
|
}
|
|
|
- getAgentReport(token, agentId, startDate, endDate, page + 1);
|
|
|
+ //是否有下一页
|
|
|
+ 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();
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -284,6 +297,7 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
|
|
|
@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);
|
|
|
@@ -293,7 +307,7 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
|
|
|
param.put("advertiser_id", advertiserId);
|
|
|
param.put("temporal_granularity", temporalGranularity);
|
|
|
param.put("report_dims", reportDims);
|
|
|
- param.put("page_size", 2000);
|
|
|
+ param.put("page_size", page_size);
|
|
|
param.put("page", page);
|
|
|
String result = HttpUtils.httpPostRequest(url, param, headers);
|
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
@@ -318,8 +332,17 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
|
|
|
if (!Check.isNull(addList)) {
|
|
|
accountAdSceneReportDailyMapper.replaceBatchKsAccountAdScene(addList);
|
|
|
}
|
|
|
- getKuaishouAccountAdSceneDaily(advertiserId, accessToken, startDate, endDate, page + 1,temporalGranularity,reportDims);
|
|
|
- log.info("账户日报数据====广告场景=====获取完成:accountId:{}", advertiserId);
|
|
|
+ //是否有下一页
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -337,6 +360,7 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
|
|
|
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");
|
|
|
@@ -348,11 +372,9 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
|
|
|
requestJson.put("unit_ids", unitIds);
|
|
|
requestJson.put("report_dims", reportDims);
|
|
|
requestJson.put("page", page);
|
|
|
- requestJson.put("page_size", 2000);
|
|
|
-
|
|
|
+ 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);
|
|
|
@@ -363,12 +385,10 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
|
|
|
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);
|
|
|
@@ -403,9 +423,16 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
|
|
|
if (reportDims.contains("gender")){
|
|
|
audienceReportDailyMapper.replaceBatchKsAudienceGender(genderList);
|
|
|
}
|
|
|
-
|
|
|
- crowdAnalysisReport(advertiserId, accessToken, date,campaignIds,unitIds, reportDims,page+1);
|
|
|
+ //是否有下一页
|
|
|
+ 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));
|
|
|
}
|
|
|
@@ -421,12 +448,13 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
|
|
|
@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", 500);
|
|
|
+ param.put("page_size", page_size);
|
|
|
param.put("page", page);
|
|
|
String result = HttpUtils.httpPostRequest(url, param, headers);
|
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
@@ -450,10 +478,51 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
|
|
|
if (!Check.isNull(addList)) {
|
|
|
fundDailyFlowsMapper.replaceBatchKsFundDailyFlows(addList);
|
|
|
}
|
|
|
- getKuaishouDailyFlows(advertiserId, accessToken, page + 1);
|
|
|
- log.info("账户流水========获取完成:accountId:{}", advertiserId);
|
|
|
+ //是否有下一页
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ details.put("advertiser_id",advertiserId);
|
|
|
+ KuaishouAdvertiserFundGet reportDaily = KuaishouAdvertiserFundGet.getKuaishouFundGetInfo(details);
|
|
|
+ if (!Check.isNull(reportDaily)) {
|
|
|
+ fundDailyFlowsMapper.replaceBatchKsFundGetBalance(reportDaily);
|
|
|
+ }
|
|
|
+ log.info("账户余额========获取完成:accountId:{}", advertiserId);
|
|
|
|
|
|
}
|
|
|
|