|
@@ -15,6 +15,7 @@ import cn.com.ctop.common.module.entity.UserAllocation;
|
|
|
import cn.com.ctop.common.module.mapper.UserAllocationMapper;
|
|
|
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
|
+import cn.com.ctop.common.module.utils.HttpUtils;
|
|
|
import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyAccount;
|
|
|
import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAccountMapper;
|
|
|
import cn.com.ctop.kuaishou.modules.utils.DownloadUtils;
|
|
@@ -744,78 +745,83 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- // 构造请求
|
|
|
- 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)){
|
|
|
- Integer code = json.getInteger("code");
|
|
|
- if(code != 0){
|
|
|
- log.info("返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ",message:"+ json.getString("message"));
|
|
|
- return;
|
|
|
- }
|
|
|
- JSONObject dataJson = json.getJSONObject("data");
|
|
|
-
|
|
|
- //解析数据并入库
|
|
|
- BytedanceDailyReportTask task = new BytedanceDailyReportTask();
|
|
|
- task.setAccountId(accountId);
|
|
|
- task.setTaskCreateTime(dataJson.getDate("create_time") == null ? null : dataJson.getDate("create_time"));
|
|
|
- task.setTaskId(dataJson.getLong("task_id") == null ? null : dataJson.getLong("task_id") );
|
|
|
- task.setTaskName(dataJson.getString("task_name") == null ? null : dataJson.getString("task_name"));
|
|
|
- task.setTaskParams(JSON.toJSONString(dataJson.getJSONObject("task_params")));
|
|
|
- task.setJson(jsonString);
|
|
|
- task.setTaskStatus(dataJson.getString("task_status"));
|
|
|
- task.setTaskType(dataJson.getString("task_type"));
|
|
|
- task.setType(type);
|
|
|
- task.setIsDownload(0);
|
|
|
- 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();
|
|
|
+ JSONObject json = HttpUtils.bytedancePostRequest(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 "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)){
|
|
|
+ Integer code = json.getInteger("code");
|
|
|
+ if(code != 0){
|
|
|
+ log.info("返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ",message:"+ json.getString("message"));
|
|
|
+ return;
|
|
|
}
|
|
|
+ JSONObject dataJson = json.getJSONObject("data");
|
|
|
+
|
|
|
+ //解析数据并入库
|
|
|
+ BytedanceDailyReportTask task = new BytedanceDailyReportTask();
|
|
|
+ task.setAccountId(accountId);
|
|
|
+ task.setTaskCreateTime(dataJson.getDate("create_time") == null ? null : dataJson.getDate("create_time"));
|
|
|
+ task.setTaskId(dataJson.getLong("task_id") == null ? null : dataJson.getLong("task_id") );
|
|
|
+ task.setTaskName(dataJson.getString("task_name") == null ? null : dataJson.getString("task_name"));
|
|
|
+ task.setTaskParams(JSON.toJSONString(dataJson.getJSONObject("task_params")));
|
|
|
+ task.setJson(jsonString);
|
|
|
+ task.setTaskStatus(dataJson.getString("task_status"));
|
|
|
+ task.setTaskType(dataJson.getString("task_type"));
|
|
|
+ task.setType(type);
|
|
|
+ task.setIsDownload(0);
|
|
|
+ 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();
|
|
|
+ // }
|
|
|
+ //}
|
|
|
}
|
|
|
|
|
|
//获取任务列表
|
|
@@ -855,36 +861,42 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- // 构造请求
|
|
|
- HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
|
- @Override
|
|
|
- public String getMethod() {
|
|
|
- return "GET";
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- httpEntity.setHeader("Access-Token",access_token);
|
|
|
+ JSONObject json = HttpUtils.bytedancePostRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
|
|
|
+ if(json == null){
|
|
|
+ log.error("请求有误:" + JSONObject.toJSONString(data));
|
|
|
+ }
|
|
|
|
|
|
- CloseableHttpResponse response = null;
|
|
|
- CloseableHttpClient client = null;
|
|
|
+ //
|
|
|
+ //// 构造请求
|
|
|
+ //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());
|
|
|
+ //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);
|
|
|
|
|
@@ -916,25 +928,12 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- }else{
|
|
|
- log.error("请求有误:" + response);
|
|
|
- }
|
|
|
+ //}else{
|
|
|
+ // log.error("请求有误:" + response);
|
|
|
+ //}
|
|
|
|
|
|
- } catch (ClientProtocolException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (Exception e) {
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- }finally {
|
|
|
- try {
|
|
|
- if (response != null) {
|
|
|
- response.close();
|
|
|
- }
|
|
|
- client.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -1039,26 +1038,31 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- // 构造请求
|
|
|
- HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
|
- @Override
|
|
|
- public String getMethod() {
|
|
|
- return "GET";
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- httpEntity.setHeader("Access-Token",access_token);
|
|
|
-
|
|
|
- CloseableHttpResponse response = null;
|
|
|
- CloseableHttpClient client = null;
|
|
|
-
|
|
|
+ JSONObject json = HttpUtils.bytedancePostRequest(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;
|
|
|
+ //
|
|
|
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));
|
|
|
+ //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)
|
|
@@ -1066,28 +1070,28 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
|
|
|
//httpEntity.setConfig(requestConfig);
|
|
|
|
|
|
- response = client.execute(httpEntity);
|
|
|
+ //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);
|
|
|
+ //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为:" + jsonString);
|
|
|
- returnCode = -1;
|
|
|
+ log.info("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + JSONObject.toJSONString(data));
|
|
|
+ //returnCode = -1;
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -1102,7 +1106,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
JSONArray jsonArrayay = jsonData.getJSONArray("list");
|
|
|
if(jsonArrayay.size() == 0){
|
|
|
log.info("accountId:" + accountId + ";没有数据。总页数为:" + totalPage + "当前页数为:" + currentPage);
|
|
|
- returnCode = 1;
|
|
|
+ //returnCode = 1;
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
@@ -1227,30 +1231,18 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
bytedanceMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
|
|
|
}
|
|
|
}else{
|
|
|
- returnCode = -1;
|
|
|
- log.error("服务器返回为空,json:"+jsonString);
|
|
|
+ //returnCode = -1;
|
|
|
+ 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 (ClientProtocolException e) {
|
|
|
- e.printStackTrace();
|
|
|
- returnCode = -2;
|
|
|
- } catch (IOException e) {
|
|
|
+ // }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;
|
|
|
- } finally {
|
|
|
- try {
|
|
|
- if (response != null) {
|
|
|
- response.close();
|
|
|
- }
|
|
|
- client.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
}
|
|
|
return returnCode;
|
|
|
}
|