|
@@ -3,6 +3,7 @@ package cn.com.ctop.bytedance.service.impl;
|
|
import cn.com.ctop.bytedance.entity.BytedanceAdvertiserDailyReport;
|
|
import cn.com.ctop.bytedance.entity.BytedanceAdvertiserDailyReport;
|
|
import cn.com.ctop.bytedance.entity.BytedanceDailyReportTask;
|
|
import cn.com.ctop.bytedance.entity.BytedanceDailyReportTask;
|
|
import cn.com.ctop.bytedance.entity.BytedanceReportMaterialDaily;
|
|
import cn.com.ctop.bytedance.entity.BytedanceReportMaterialDaily;
|
|
|
|
+import cn.com.ctop.bytedance.entity.BytedanceReportMaterialRetry;
|
|
import cn.com.ctop.bytedance.mapper.BytedanceAdvertiserDailyReportMapper;
|
|
import cn.com.ctop.bytedance.mapper.BytedanceAdvertiserDailyReportMapper;
|
|
import cn.com.ctop.bytedance.mapper.BytedanceDailyReportTaskMapper;
|
|
import cn.com.ctop.bytedance.mapper.BytedanceDailyReportTaskMapper;
|
|
import cn.com.ctop.bytedance.mapper.BytedanceReportMapper;
|
|
import cn.com.ctop.bytedance.mapper.BytedanceReportMapper;
|
|
@@ -972,16 +973,47 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
|
|
|
/////////////////////////////////////////////////////////\
|
|
/////////////////////////////////////////////////////////\
|
|
//素材报表
|
|
//素材报表
|
|
|
|
+ public void bytedanceMaterialReportRetry(CtopOauthToken token, String startDate, String endDate){
|
|
|
|
+ //CtopOauthToken token = ctopOauthTokenService.getTokenByAccountId(accountId);
|
|
|
|
+ Long accountId = token.getAccountId();
|
|
|
|
+ log.info("头条素材报表当前accountId为:" + accountId);
|
|
|
|
+ Integer page = 1;
|
|
|
|
+ Integer pageSize = 100;
|
|
|
|
+ int code = bytedanceMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
|
|
|
|
+
|
|
|
|
+ BytedanceReportMaterialRetry retry = new BytedanceReportMaterialRetry();
|
|
|
|
+ retry.setAccountId(accountId);
|
|
|
|
+ retry.setStartDate(startDate);
|
|
|
|
+ retry.setEndDate(endDate);
|
|
|
|
+ retry.setStatusCode(code);
|
|
|
|
+ if (code != 200 && code != 1){
|
|
|
|
+ retry.setStatus(0);
|
|
|
|
+ bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
|
|
|
|
+ }else{
|
|
|
|
+ retry.setStatus(1);
|
|
|
|
+ bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public void bytedanceMaterialReport(CtopOauthToken token, String startDate, String endDate){
|
|
public void bytedanceMaterialReport(CtopOauthToken token, String startDate, String endDate){
|
|
//CtopOauthToken token = ctopOauthTokenService.getTokenByAccountId(accountId);
|
|
//CtopOauthToken token = ctopOauthTokenService.getTokenByAccountId(accountId);
|
|
Long accountId = token.getAccountId();
|
|
Long accountId = token.getAccountId();
|
|
log.info("头条素材报表当前accountId为:" + accountId);
|
|
log.info("头条素材报表当前accountId为:" + accountId);
|
|
Integer page = 1;
|
|
Integer page = 1;
|
|
- Integer pageSize = 500;
|
|
|
|
- bytedanceMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
|
|
|
|
|
|
+ Integer pageSize = 100;
|
|
|
|
+ int code = bytedanceMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
|
|
|
|
+ if (code != 200 && code != 1){
|
|
|
|
+ BytedanceReportMaterialRetry retry = new BytedanceReportMaterialRetry();
|
|
|
|
+ retry.setAccountId(accountId);
|
|
|
|
+ retry.setStatus(0);
|
|
|
|
+ retry.setStartDate(startDate);
|
|
|
|
+ retry.setEndDate(endDate);
|
|
|
|
+ retry.setStatusCode(code);
|
|
|
|
+ bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- private void bytedanceMaterialReportByPage(Integer page, Integer pageSize, CtopOauthToken token, Long accountId, String startDate, String endDate){
|
|
|
|
|
|
+ private int bytedanceMaterialReportByPage(Integer page, Integer pageSize, CtopOauthToken token, Long accountId, String startDate, String endDate){
|
|
//log.info("当前页数:"+ page);
|
|
//log.info("当前页数:"+ page);
|
|
String access_token = token.getAccessToken();
|
|
String access_token = token.getAccessToken();
|
|
|
|
|
|
@@ -1020,7 +1052,10 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
CloseableHttpResponse response = null;
|
|
CloseableHttpResponse response = null;
|
|
CloseableHttpClient client = null;
|
|
CloseableHttpClient client = null;
|
|
|
|
|
|
|
|
+ int returnCode = 200;
|
|
try {
|
|
try {
|
|
|
|
+ //Long connectStartTime = System.currentTimeMillis();
|
|
|
|
+
|
|
client = HttpClientBuilder.create().build();
|
|
client = HttpClientBuilder.create().build();
|
|
httpEntity.setURI(URI.create(open_api_domain + path));
|
|
httpEntity.setURI(URI.create(open_api_domain + path));
|
|
httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
|
|
httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
|
|
@@ -1032,6 +1067,8 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
//httpEntity.setConfig(requestConfig);
|
|
//httpEntity.setConfig(requestConfig);
|
|
|
|
|
|
response = client.execute(httpEntity);
|
|
response = client.execute(httpEntity);
|
|
|
|
+ //Long connectEndTime = System.currentTimeMillis();
|
|
|
|
+ //log.info("头条获取素材报表数据任务获取服务器数据结束,执行耗时:{}秒", (connectEndTime - connectStartTime) / 1000);
|
|
//System.out.println(response);
|
|
//System.out.println(response);
|
|
if (response != null && response.getStatusLine().getStatusCode() == 200) {
|
|
if (response != null && response.getStatusLine().getStatusCode() == 200) {
|
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
@@ -1050,7 +1087,8 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
Integer code = json.getInteger("code");
|
|
Integer code = json.getInteger("code");
|
|
if(code != 0){
|
|
if(code != 0){
|
|
log.info("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + jsonString);
|
|
log.info("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + jsonString);
|
|
- return;
|
|
|
|
|
|
+ returnCode = -1;
|
|
|
|
+ return -1;
|
|
}
|
|
}
|
|
|
|
|
|
JSONObject jsonData = json.getJSONObject("data");
|
|
JSONObject jsonData = json.getJSONObject("data");
|
|
@@ -1064,8 +1102,10 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
JSONArray jsonArrayay = jsonData.getJSONArray("list");
|
|
JSONArray jsonArrayay = jsonData.getJSONArray("list");
|
|
if(jsonArrayay.size() == 0){
|
|
if(jsonArrayay.size() == 0){
|
|
log.info("accountId:" + accountId + ";没有数据。总页数为:" + totalPage + "当前页数为:" + currentPage);
|
|
log.info("accountId:" + accountId + ";没有数据。总页数为:" + totalPage + "当前页数为:" + currentPage);
|
|
- return;
|
|
|
|
|
|
+ returnCode = 1;
|
|
|
|
+ return 1;
|
|
}
|
|
}
|
|
|
|
+
|
|
List<BytedanceReportMaterialDaily> bytedanceReportMaterialDailyList = new ArrayList<>();
|
|
List<BytedanceReportMaterialDaily> bytedanceReportMaterialDailyList = new ArrayList<>();
|
|
for (int i = 0; i < jsonArrayay.size(); i++) {
|
|
for (int i = 0; i < jsonArrayay.size(); i++) {
|
|
BytedanceReportMaterialDaily daily = new BytedanceReportMaterialDaily();
|
|
BytedanceReportMaterialDaily daily = new BytedanceReportMaterialDaily();
|
|
@@ -1175,22 +1215,41 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
//bytedanceReportMaterialDailyMapper.insert(daily);
|
|
//bytedanceReportMaterialDailyMapper.insert(daily);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ //Long insertStartTime = System.currentTimeMillis();
|
|
bytedanceReportMaterialDailyMapper.replaceIntoBatch(bytedanceReportMaterialDailyList);
|
|
bytedanceReportMaterialDailyMapper.replaceIntoBatch(bytedanceReportMaterialDailyList);
|
|
|
|
+ //Long insertEndTime = System.currentTimeMillis();
|
|
|
|
+ //log.info("头条获取素材报表插入数据结束,执行耗时:{}秒", (insertEndTime - insertStartTime) / 1000);
|
|
if(currentPage >= totalPage){
|
|
if(currentPage >= totalPage){
|
|
- log.info("accountId:" + accountId + "数据同步完成");
|
|
|
|
- return;
|
|
|
|
|
|
+ log.info("accountId:" + accountId + "数据同步完成,开始时间:" + startDate + ",结束时间:"+ endDate);
|
|
|
|
+ //returnCode = 1;
|
|
|
|
+ return 1;
|
|
}else{
|
|
}else{
|
|
bytedanceMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
|
|
bytedanceMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
|
|
}
|
|
}
|
|
|
|
+ }else{
|
|
|
|
+ returnCode = -1;
|
|
|
|
+ log.error("服务器返回为空,json:"+jsonString);
|
|
|
|
+ return -1;
|
|
}
|
|
}
|
|
}else{
|
|
}else{
|
|
|
|
+ //BytedanceReportMaterialRetry retry = new BytedanceReportMaterialRetry();
|
|
|
|
+ //retry.setAccountId(accountId);
|
|
|
|
+ //retry.setStatus(0);
|
|
|
|
+ //retry.setStartDate(startDate);
|
|
|
|
+ //retry.setEndDate(endDate);
|
|
|
|
+ //bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
|
|
|
|
+
|
|
log.error("头条素材报表请求有误:accountId:" + accountId + ",开始时间:" + startDate + "结束时间:" + endDate + "错误返回:" +response);
|
|
log.error("头条素材报表请求有误:accountId:" + accountId + ",开始时间:" + startDate + "结束时间:" + endDate + "错误返回:" +response);
|
|
|
|
+
|
|
|
|
+ returnCode = 0; //504等状态0;-2连接服务器报错 ;-1对方服务器返回值为空;200正常;1没有数据(也属于正常)
|
|
|
|
+ return 0;
|
|
}
|
|
}
|
|
} catch (ClientProtocolException e) {
|
|
} catch (ClientProtocolException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
+ returnCode = -2;
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
+ returnCode = -2;
|
|
} finally {
|
|
} finally {
|
|
try {
|
|
try {
|
|
if (response != null) {
|
|
if (response != null) {
|
|
@@ -1201,6 +1260,11 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ return returnCode;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<BytedanceReportMaterialRetry> getRetryList(){
|
|
|
|
+ return bytedanceReportMaterialDailyMapper.getRetryList();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|