|
@@ -24,29 +24,18 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.http.client.ClientProtocolException;
|
|
|
-import org.apache.http.client.config.RequestConfig;
|
|
|
-import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
-import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
|
|
-import org.apache.http.entity.ContentType;
|
|
|
-import org.apache.http.entity.StringEntity;
|
|
|
-import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
-import org.apache.http.impl.client.HttpClientBuilder;
|
|
|
-import org.bytedeco.javacpp.freenect2;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.io.BufferedReader;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStreamReader;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
-import java.net.URI;
|
|
|
-import java.sql.Timestamp;
|
|
|
import java.text.ParseException;
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
@@ -749,36 +738,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
if(json == null){
|
|
|
log.error("请求有误:" + JSONObject.toJSONString(data));
|
|
|
}
|
|
|
- //
|
|
|
- //// 构造请求
|
|
|
- //HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
|
- // @Override
|
|
|
- // public String getMethod() {
|
|
|
- // return "POST";
|
|
|
- // }
|
|
|
- //};
|
|
|
- //
|
|
|
- //httpEntity.setHeader("Access-Token", access_token);
|
|
|
- //
|
|
|
- //CloseableHttpResponse response = null;
|
|
|
- //CloseableHttpClient client = null;
|
|
|
-
|
|
|
- //try {
|
|
|
- // client = HttpClientBuilder.create().build();
|
|
|
- // httpEntity.setURI(URI.create(open_api_domain + path));
|
|
|
- // httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
|
|
|
- //
|
|
|
- // response = client.execute(httpEntity);
|
|
|
- // if (response != null && response.getStatusLine().getStatusCode() == 200) {
|
|
|
- // BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
- // StringBuffer result = new StringBuffer();
|
|
|
- // String line = "";
|
|
|
- // while ((line = bufferedReader.readLine()) != null) {
|
|
|
- // result.append(line);
|
|
|
- // }
|
|
|
- // bufferedReader.close();
|
|
|
-
|
|
|
- //JSONObject json = JSONObject.parseObject(result.toString());
|
|
|
+
|
|
|
String jsonString = JSON.toJSONString(json);
|
|
|
|
|
|
if(!Check.isNull(json)){
|
|
@@ -804,24 +764,6 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
task.setStatus(1); //状态1正常 0废弃
|
|
|
bytedanceDailyReportTaskMapper.insert(task);
|
|
|
}
|
|
|
- //
|
|
|
- // }else{
|
|
|
- // log.error("请求有误:" + response );
|
|
|
- // }
|
|
|
- //} catch (ClientProtocolException e) {
|
|
|
- // e.printStackTrace();
|
|
|
- //} catch (IOException e) {
|
|
|
- // e.printStackTrace();
|
|
|
- //} finally {
|
|
|
- // try {
|
|
|
- // if (response != null) {
|
|
|
- // response.close();
|
|
|
- // }
|
|
|
- // client.close();
|
|
|
- // } catch (IOException e) {
|
|
|
- // e.printStackTrace();
|
|
|
- // }
|
|
|
- //}
|
|
|
}
|
|
|
|
|
|
//获取任务列表
|
|
@@ -861,81 +803,45 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- JSONObject json = HttpUtils.bytedancePostRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
|
|
|
+ JSONObject json = HttpUtils.bytedanceGetRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
|
|
|
if(json == null){
|
|
|
log.error("请求有误:" + JSONObject.toJSONString(data));
|
|
|
}
|
|
|
|
|
|
- //
|
|
|
- //// 构造请求
|
|
|
- //HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
|
- // @Override
|
|
|
- // public String getMethod() {
|
|
|
- // return "GET";
|
|
|
- // }
|
|
|
- //};
|
|
|
- //
|
|
|
- //httpEntity.setHeader("Access-Token",access_token);
|
|
|
- //
|
|
|
- //CloseableHttpResponse response = null;
|
|
|
- //CloseableHttpClient client = null;
|
|
|
-
|
|
|
try {
|
|
|
- //client = HttpClientBuilder.create().build();
|
|
|
- //httpEntity.setURI(URI.create(open_api_domain + path));
|
|
|
- //httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
|
|
|
- //
|
|
|
- //response = client.execute(httpEntity);
|
|
|
- //log.info("response为:" + response);
|
|
|
- //if (response != null && response.getStatusLine().getStatusCode() == 200) {
|
|
|
- // BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
- // StringBuffer result = new StringBuffer();
|
|
|
- // String line = "";
|
|
|
- // while((line = bufferedReader.readLine()) != null) {
|
|
|
- // result.append(line);
|
|
|
- // }
|
|
|
- // bufferedReader.close();
|
|
|
-
|
|
|
- // JSONObject json = JSONObject.parseObject(result.toString());
|
|
|
- String jsonString = JSON.toJSONString(json);
|
|
|
- log.info("返回json为" + jsonString);
|
|
|
-
|
|
|
- if(!Check.isNull(json)){
|
|
|
- Integer code = json.getInteger("code");
|
|
|
- if(code != 0){
|
|
|
- log.info("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + "taskId:" + task.getTaskId());
|
|
|
- return;
|
|
|
- }
|
|
|
+ String jsonString = JSON.toJSONString(json);
|
|
|
+ log.info("返回json为" + jsonString);
|
|
|
+
|
|
|
+ if(!Check.isNull(json)){
|
|
|
+ Integer code = json.getInteger("code");
|
|
|
+ if(code != 0){
|
|
|
+ log.info("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + "taskId:" + task.getTaskId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- JSONObject jsonData = json.getJSONObject("data");
|
|
|
- if (Check.isNull(jsonData)){
|
|
|
- log.error("获取任务列表返回信息data内容为空");
|
|
|
- }
|
|
|
- JSONArray jsonArrayay = jsonData.getJSONArray("list");
|
|
|
-
|
|
|
- for (int i = 0; i < jsonArrayay.size(); i++) {
|
|
|
- JSONObject detailJson = jsonArrayay.getJSONObject(i);
|
|
|
- if (!Check.isNull(detailJson)) {
|
|
|
- String taskStatus = detailJson.getString("task_status");
|
|
|
-
|
|
|
- if (taskStatus .equals( "ASYNC_TASK_STATUS_COMPLETED")) {
|
|
|
- bytedanceAsyncTaskDownload(task,token,task.getType());
|
|
|
- task.setIsDownload(1);
|
|
|
- }
|
|
|
- task.setTaskStatus(taskStatus);
|
|
|
- bytedanceDailyReportTaskMapper.updateById(task);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ JSONObject jsonData = json.getJSONObject("data");
|
|
|
+ if (Check.isNull(jsonData)){
|
|
|
+ log.error("获取任务列表返回信息data内容为空");
|
|
|
+ }
|
|
|
+ JSONArray jsonArrayay = jsonData.getJSONArray("list");
|
|
|
|
|
|
- //}else{
|
|
|
- // log.error("请求有误:" + response);
|
|
|
- //}
|
|
|
+ for (int i = 0; i < jsonArrayay.size(); i++) {
|
|
|
+ JSONObject detailJson = jsonArrayay.getJSONObject(i);
|
|
|
+ if (!Check.isNull(detailJson)) {
|
|
|
+ String taskStatus = detailJson.getString("task_status");
|
|
|
|
|
|
+ if (taskStatus .equals( "ASYNC_TASK_STATUS_COMPLETED")) {
|
|
|
+ bytedanceAsyncTaskDownload(task,token,task.getType());
|
|
|
+ task.setIsDownload(1);
|
|
|
+ }
|
|
|
+ task.setTaskStatus(taskStatus);
|
|
|
+ bytedanceDailyReportTaskMapper.updateById(task);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -953,7 +859,6 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
requestMap.put("advertiser_id", task.getAccountId());
|
|
|
requestMap.put("task_id", task.getTaskId());
|
|
|
String localPath = DownloadUtils.downloadByUrl(requestMap, downloadPath, url, token.getAccessToken(), fileName);
|
|
|
- // if(task.getAccountId() !=1649961222605831L && task.getAccountId() != 1643726941045772L){
|
|
|
if(type == 1){
|
|
|
//素材异步报表
|
|
|
bytedanceDailyReportTaskMapper.loadBytedanceDailyCreativeFileAsync(localPath);
|
|
@@ -969,7 +874,6 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
}else{
|
|
|
log.error("异步报表类型传入错误,task_id:" + task.getTaskId() + ";类型:" + type);
|
|
|
}
|
|
|
- // }
|
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////\
|
|
@@ -1021,12 +925,6 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
String path = "/open_api/2/report/integrated/get/";
|
|
|
|
|
|
// 请求参数
|
|
|
- final Map filtering = new HashMap() {
|
|
|
- {
|
|
|
- put("image_mode",new String[]{"MATERIAL_IMAGE_MODE_TITLE"});
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
Map data = new HashMap(){
|
|
|
{
|
|
|
put("advertiser_id", accountId);
|
|
@@ -1038,59 +936,18 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- JSONObject json = HttpUtils.bytedancePostRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
|
|
|
+ JSONObject json = HttpUtils.bytedanceGetRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
|
|
|
if(json == null){
|
|
|
log.error("请求有误:" + JSONObject.toJSONString(data));
|
|
|
+ return -2;
|
|
|
}
|
|
|
- //
|
|
|
- //// 构造请求
|
|
|
- //HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
|
- // @Override
|
|
|
- // public String getMethod() {
|
|
|
- // return "GET";
|
|
|
- // }
|
|
|
- //};
|
|
|
- //
|
|
|
- //httpEntity.setHeader("Access-Token",access_token);
|
|
|
- //
|
|
|
- //CloseableHttpResponse response = null;
|
|
|
- //CloseableHttpClient client = null;
|
|
|
- //
|
|
|
+
|
|
|
int returnCode = 200;
|
|
|
try {
|
|
|
- //Long connectStartTime = System.currentTimeMillis();
|
|
|
-
|
|
|
- //client = HttpClientBuilder.create().build();
|
|
|
- //httpEntity.setURI(URI.create(open_api_domain + path));
|
|
|
- //httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
|
|
|
-
|
|
|
- //RequestConfig requestConfig = RequestConfig.custom()
|
|
|
- // .setConnectTimeout(60000).setConnectionRequestTimeout(60000)
|
|
|
- // .setSocketTimeout(60000).build();
|
|
|
-
|
|
|
- //httpEntity.setConfig(requestConfig);
|
|
|
-
|
|
|
- //response = client.execute(httpEntity);
|
|
|
- //Long connectEndTime = System.currentTimeMillis();
|
|
|
- //log.info("头条获取素材报表数据任务获取服务器数据结束,执行耗时:{}秒", (connectEndTime - connectStartTime) / 1000);
|
|
|
- //System.out.println(response);
|
|
|
- //if (response != null && response.getStatusLine().getStatusCode() == 200) {
|
|
|
- //BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
- //StringBuffer result = new StringBuffer();
|
|
|
- //String line = "";
|
|
|
- //while((line = bufferedReader.readLine()) != null) {
|
|
|
- // result.append(line);
|
|
|
- //}
|
|
|
- //bufferedReader.close();
|
|
|
- //
|
|
|
- //JSONObject json = JSONObject.parseObject(result.toString());
|
|
|
- //String jsonString = JSON.toJSONString(json);
|
|
|
- //log.info("返回值为:" + jsonString);
|
|
|
-
|
|
|
if(!Check.isNull(json)){
|
|
|
Integer code = json.getInteger("code");
|
|
|
if(code != 0){
|
|
|
- log.info("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + JSONObject.toJSONString(data));
|
|
|
+ log.error("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + JSONObject.toJSONString(data));
|
|
|
//returnCode = -1;
|
|
|
return -1;
|
|
|
}
|
|
@@ -1098,6 +955,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
JSONObject jsonData = json.getJSONObject("data");
|
|
|
if (Check.isNull(jsonData)){
|
|
|
log.error("获取任务列表返回信息data内容为空");
|
|
|
+ return -1;
|
|
|
}
|
|
|
JSONObject pageInfo = jsonData.getJSONObject("page_info");
|
|
|
Integer totalPage = pageInfo.getInteger("total_page");
|
|
@@ -1235,14 +1093,9 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
log.error("服务器返回为空,json:"+JSONObject.toJSONString(data));
|
|
|
return -1;
|
|
|
}
|
|
|
- // }else{
|
|
|
- // log.error("头条素材报表请求有误:accountId:" + accountId + ",开始时间:" + startDate + "结束时间:" + endDate + "错误返回:" +response);
|
|
|
- // returnCode = 0; //504等状态0;-2连接服务器报错 ;-1对方服务器返回值为空;200正常;1没有数据(也属于正常)
|
|
|
- // return 0;
|
|
|
- // }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- returnCode = -2;
|
|
|
+ returnCode = -3;
|
|
|
}
|
|
|
return returnCode;
|
|
|
}
|
|
@@ -1252,19 +1105,3 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|