|
@@ -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.mapper.UserAllocationMapper;
|
|
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
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.entity.KuaishouReportDailyAccount;
|
|
import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAccountMapper;
|
|
import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAccountMapper;
|
|
import cn.com.ctop.kuaishou.modules.utils.DownloadUtils;
|
|
import cn.com.ctop.kuaishou.modules.utils.DownloadUtils;
|
|
@@ -23,24 +24,13 @@ import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
-import org.apache.http.client.ClientProtocolException;
|
|
|
|
-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.jeecg.common.util.DateUtils;
|
|
import org.jeecg.common.util.DateUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.io.BufferedReader;
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.io.InputStreamReader;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
-import java.net.URI;
|
|
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
@@ -677,24 +667,24 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
//创建异步任务
|
|
//创建异步任务
|
|
- public void bytedanceAsyncTaskCreate(String startDate, String endDate, CtopOauthToken token, Integer type) throws ParseException {
|
|
|
|
- int diffMonths = DateUtils.calDiffMonth(DateUtils.parseDate(startDate, "yyyy-MM-dd"), DateUtils.parseDate(endDate, "yyyy-MM-dd"));
|
|
|
|
|
|
+ public void bytedanceAsyncTaskCreate (String startDate, String endDate, CtopOauthToken token, Integer type) throws ParseException {
|
|
|
|
+ int diffMonths = DateUtils.calDiffMonth(DateUtils.parseDate(startDate,"yyyy-MM-dd"),DateUtils.parseDate(endDate,"yyyy-MM-dd"));
|
|
if (diffMonths == 0) {
|
|
if (diffMonths == 0) {
|
|
bytedanceAsyncTaskCreateByMonth(startDate, endDate, token, type);
|
|
bytedanceAsyncTaskCreateByMonth(startDate, endDate, token, type);
|
|
- } else {
|
|
|
|
- for (int i = 0; i <= diffMonths; i++) {
|
|
|
|
- if (i == 0) {
|
|
|
|
- Map<String, String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate, "yyyy-MM-dd", i);
|
|
|
|
|
|
+ }else{
|
|
|
|
+ for(int i=0; i<=diffMonths ; i++){
|
|
|
|
+ if (i == 0){
|
|
|
|
+ Map<String,String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate,"yyyy-MM-dd", i);
|
|
String end = dateMap.get("endDate");
|
|
String end = dateMap.get("endDate");
|
|
//System.out.println(startDate + " ----- " + end);
|
|
//System.out.println(startDate + " ----- " + end);
|
|
bytedanceAsyncTaskCreateByMonth(startDate, end, token, type);
|
|
bytedanceAsyncTaskCreateByMonth(startDate, end, token, type);
|
|
- } else if (i == diffMonths) {
|
|
|
|
- Map<String, String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate, "yyyy-MM-dd", i);
|
|
|
|
|
|
+ }else if(i == diffMonths){
|
|
|
|
+ Map<String,String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate,"yyyy-MM-dd", i);
|
|
String start = dateMap.get("startDate");
|
|
String start = dateMap.get("startDate");
|
|
//System.out.println(start + " ----- " + endDate);
|
|
//System.out.println(start + " ----- " + endDate);
|
|
bytedanceAsyncTaskCreateByMonth(start, endDate, token, type);
|
|
bytedanceAsyncTaskCreateByMonth(start, endDate, token, type);
|
|
- } else {
|
|
|
|
- Map<String, String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate, "yyyy-MM-dd", i);
|
|
|
|
|
|
+ }else{
|
|
|
|
+ Map<String,String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate,"yyyy-MM-dd", i);
|
|
String start = dateMap.get("startDate");
|
|
String start = dateMap.get("startDate");
|
|
String end = dateMap.get("endDate");
|
|
String end = dateMap.get("endDate");
|
|
//System.out.println(start + " ----- " + end);
|
|
//System.out.println(start + " ----- " + end);
|
|
@@ -710,7 +700,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
* @param endDate
|
|
* @param endDate
|
|
* @param token
|
|
* @param token
|
|
*/
|
|
*/
|
|
- private void bytedanceAsyncTaskCreateByMonth(String startDate, String endDate, CtopOauthToken token, Integer type) {
|
|
|
|
|
|
+ private void bytedanceAsyncTaskCreateByMonth(String startDate, String endDate, CtopOauthToken token, Integer type){
|
|
String access_token = token.getAccessToken();
|
|
String access_token = token.getAccessToken();
|
|
Long accountId = token.getAccountId();
|
|
Long accountId = token.getAccountId();
|
|
|
|
|
|
@@ -724,14 +714,14 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
{
|
|
{
|
|
put("start_date", startDate);
|
|
put("start_date", startDate);
|
|
put("end_date", endDate);
|
|
put("end_date", endDate);
|
|
- if (type == 1) {//创意
|
|
|
|
- put("group_by", new String[]{"STAT_GROUP_BY_CREATIVE_ID", "STAT_GROUP_BY_TIME_DAY", "STAT_GROUP_BY_CREATIVE_MATERIAL_MODE"}); //按照创意分组、天分组、创意类型分组查询
|
|
|
|
- } else if (type == 2) {//广告主
|
|
|
|
- put("group_by", new String[]{"STAT_GROUP_BY_ADVERTISER_ID", "STAT_GROUP_BY_TIME_DAY", "STAT_GROUP_BY_PRICING_CATEGORY"}); //按照广告主分组、天分组、广告类型类型分组查询
|
|
|
|
- } else if (type == 3) {//广告组
|
|
|
|
- put("group_by", new String[]{"STAT_GROUP_BY_CAMPAIGN_ID", "STAT_GROUP_BY_TIME_DAY", "STAT_GROUP_BY_CAMPAIGN_TYPE"}); //按照广告组、天、广告组类型分组
|
|
|
|
- } else {//4广告计划
|
|
|
|
- put("group_by", new String[]{"STAT_GROUP_BY_AD_ID", "STAT_GROUP_BY_TIME_DAY", "STAT_GROUP_BY_LANDING_TYPE"}); //按照广告计划、天、推广类型分组
|
|
|
|
|
|
+ if(type == 1){//创意
|
|
|
|
+ put("group_by", new String[]{"STAT_GROUP_BY_CREATIVE_ID","STAT_GROUP_BY_TIME_DAY","STAT_GROUP_BY_CREATIVE_MATERIAL_MODE"}); //按照创意分组、天分组、创意类型分组查询
|
|
|
|
+ }else if(type == 2){//广告主
|
|
|
|
+ put("group_by", new String[]{"STAT_GROUP_BY_ADVERTISER_ID","STAT_GROUP_BY_TIME_DAY","STAT_GROUP_BY_PRICING_CATEGORY"}); //按照广告主分组、天分组、广告类型类型分组查询
|
|
|
|
+ }else if(type == 3){//广告组
|
|
|
|
+ put("group_by", new String[]{"STAT_GROUP_BY_CAMPAIGN_ID","STAT_GROUP_BY_TIME_DAY","STAT_GROUP_BY_CAMPAIGN_TYPE"}); //按照广告组、天、广告组类型分组
|
|
|
|
+ }else {//4广告计划
|
|
|
|
+ put("group_by", new String[]{"STAT_GROUP_BY_AD_ID","STAT_GROUP_BY_TIME_DAY","STAT_GROUP_BY_LANDING_TYPE"}); //按照广告计划、天、推广类型分组
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
};
|
|
@@ -744,85 +734,43 @@ 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 = HttpUtils.bytedancePostRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
|
|
|
|
+ if(json == null){
|
|
|
|
+ log.error("请求有误:" + JSONObject.toJSONString(data));
|
|
|
|
+ }
|
|
|
|
|
|
- JSONObject json = JSONObject.parseObject(result.toString());
|
|
|
|
- String jsonString = JSON.toJSONString(json);
|
|
|
|
|
|
+ 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();
|
|
|
|
|
|
+ if(!Check.isNull(json)){
|
|
|
|
+ Integer code = json.getInteger("code");
|
|
|
|
+ if(code != 0){
|
|
|
|
+ log.error("返回信息错误,错误码为:" + 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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//获取任务列表
|
|
//获取任务列表
|
|
- public void bytedanceAsyncTaskGet() {
|
|
|
|
|
|
+ public void bytedanceAsyncTaskGet(){
|
|
QueryWrapper<BytedanceDailyReportTask> taskQueryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<BytedanceDailyReportTask> taskQueryWrapper = new QueryWrapper<>();
|
|
//查询三种状态的信息--任务已创建、任务执行中、任务处理中
|
|
//查询三种状态的信息--任务已创建、任务执行中、任务处理中
|
|
- taskQueryWrapper.eq("is_download", 0);
|
|
|
|
|
|
+ taskQueryWrapper.eq("is_download",0);
|
|
//taskQueryWrapper.in("task_status", "ASYNC_TASK_STATUS_CREATED","ASYNC_TASK_STATUS_EXECUTING","ASYNC_TASK_STATUS_EXECUTING_STAGE2");
|
|
//taskQueryWrapper.in("task_status", "ASYNC_TASK_STATUS_CREATED","ASYNC_TASK_STATUS_EXECUTING","ASYNC_TASK_STATUS_EXECUTING_STAGE2");
|
|
taskQueryWrapper.notIn("task_status", "ASYNC_TASK_STATUS_FAILED");
|
|
taskQueryWrapper.notIn("task_status", "ASYNC_TASK_STATUS_FAILED");
|
|
taskQueryWrapper.orderByDesc("create_time");
|
|
taskQueryWrapper.orderByDesc("create_time");
|
|
@@ -844,136 +792,93 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
// 请求参数
|
|
// 请求参数
|
|
final Map filtering = new HashMap() {
|
|
final Map filtering = new HashMap() {
|
|
{
|
|
{
|
|
- put("task_ids", new Long[]{task.getTaskId()});
|
|
|
|
|
|
+ put("task_ids",new Long[]{task.getTaskId()});
|
|
put("task_name", task.getTaskName());
|
|
put("task_name", task.getTaskName());
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- Map data = new HashMap() {
|
|
|
|
|
|
+ Map data = new HashMap(){
|
|
{
|
|
{
|
|
put("advertiser_id", advertiser_id);
|
|
put("advertiser_id", advertiser_id);
|
|
put("filtering", filtering);
|
|
put("filtering", filtering);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
- // 构造请求
|
|
|
|
- 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.bytedanceGetRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
|
|
|
|
+ if(json == null){
|
|
|
|
+ log.error("请求有误:" + JSONObject.toJSONString(data));
|
|
|
|
+ }
|
|
|
|
|
|
try {
|
|
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);
|
|
|
|
|
|
+ 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());
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
- 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 + "taskId:" + task.getTaskId());
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- JSONObject jsonData = json.getJSONObject("data");
|
|
|
|
- if (Check.isNull(jsonData)) {
|
|
|
|
- log.error("获取任务列表返回信息data内容为空");
|
|
|
|
- }
|
|
|
|
- JSONArray jsonArrayay = jsonData.getJSONArray("list");
|
|
|
|
|
|
+ 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");
|
|
|
|
|
|
+ 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);
|
|
|
|
- }
|
|
|
|
|
|
+ if (taskStatus .equals( "ASYNC_TASK_STATUS_COMPLETED")) {
|
|
|
|
+ bytedanceAsyncTaskDownload(task,token,task.getType());
|
|
|
|
+ task.setIsDownload(1);
|
|
|
|
+ }
|
|
task.setTaskStatus(taskStatus);
|
|
task.setTaskStatus(taskStatus);
|
|
bytedanceDailyReportTaskMapper.updateById(task);
|
|
bytedanceDailyReportTaskMapper.updateById(task);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- } else {
|
|
|
|
- log.error("请求有误:" + response);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } catch (ClientProtocolException e) {
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } finally {
|
|
|
|
- try {
|
|
|
|
- if (response != null) {
|
|
|
|
- response.close();
|
|
|
|
- }
|
|
|
|
- client.close();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//下载任务结果 type 1.creative 2.account 3.campaign 4.plan
|
|
//下载任务结果 type 1.creative 2.account 3.campaign 4.plan
|
|
- private void bytedanceAsyncTaskDownload(BytedanceDailyReportTask task, CtopOauthToken token, Integer type) {
|
|
|
|
|
|
+ private void bytedanceAsyncTaskDownload(BytedanceDailyReportTask task, CtopOauthToken token, Integer type){
|
|
// 请求地址
|
|
// 请求地址
|
|
String open_api_domain = "https://ad.toutiao.com";
|
|
String open_api_domain = "https://ad.toutiao.com";
|
|
String path = "/open_api/2/async_task/download/";
|
|
String path = "/open_api/2/async_task/download/";
|
|
|
|
|
|
String url = open_api_domain + path;
|
|
String url = open_api_domain + path;
|
|
- String fileName = task.getAccountId() + "_" + "type" + type + "_" + System.currentTimeMillis() + ".csv";
|
|
|
|
|
|
+ String fileName = task.getAccountId() + "_" + "type" + type + "_" + task.getTaskId() + "_" + System.currentTimeMillis() + ".csv";
|
|
Map<String, Object> requestMap = new HashMap<>();
|
|
Map<String, Object> requestMap = new HashMap<>();
|
|
requestMap.put("advertiser_id", task.getAccountId());
|
|
requestMap.put("advertiser_id", task.getAccountId());
|
|
requestMap.put("task_id", task.getTaskId());
|
|
requestMap.put("task_id", task.getTaskId());
|
|
String localPath = DownloadUtils.downloadByUrl(requestMap, downloadPath, url, token.getAccessToken(), fileName);
|
|
String localPath = DownloadUtils.downloadByUrl(requestMap, downloadPath, url, token.getAccessToken(), fileName);
|
|
- if (task.getAccountId() != 1649961222605831L && task.getAccountId() != 1643726941045772L) {
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if (type == 1) {
|
|
|
|
- //素材异步报表
|
|
|
|
- bytedanceDailyReportTaskMapper.loadBytedanceDailyCreativeFileAsync(localPath);
|
|
|
|
- } else if (type == 2) {
|
|
|
|
- //账户异步报表
|
|
|
|
- bytedanceDailyReportTaskMapper.loadBytedanceDailyAccountFileAsync(localPath);
|
|
|
|
- } else if (type == 3) {
|
|
|
|
- //campaign异步报表
|
|
|
|
- bytedanceDailyReportTaskMapper.loadBytedanceDailyCampaignFileAsync(localPath);
|
|
|
|
- } else if (type == 4) {
|
|
|
|
- //plan异步报表
|
|
|
|
- bytedanceDailyReportTaskMapper.loadBytedanceDailyPlanFileAsync(localPath);
|
|
|
|
- } else {
|
|
|
|
- log.error("异步报表类型传入错误,task_id:" + task.getTaskId() + ";类型:" + type);
|
|
|
|
- }
|
|
|
|
|
|
+ if(type == 1){
|
|
|
|
+ //素材异步报表
|
|
|
|
+ bytedanceDailyReportTaskMapper.loadBytedanceDailyCreativeFileAsync(localPath);
|
|
|
|
+ }else if(type == 2){
|
|
|
|
+ //账户异步报表
|
|
|
|
+ bytedanceDailyReportTaskMapper.loadBytedanceDailyAccountFileAsync(localPath);
|
|
|
|
+ }else if(type == 3){
|
|
|
|
+ //campaign异步报表
|
|
|
|
+ bytedanceDailyReportTaskMapper.loadBytedanceDailyCampaignFileAsync(localPath);
|
|
|
|
+ }else if(type == 4){
|
|
|
|
+ //plan异步报表
|
|
|
|
+ bytedanceDailyReportTaskMapper.loadBytedanceDailyPlanFileAsync(localPath);
|
|
|
|
+ }else{
|
|
|
|
+ log.error("异步报表类型传入错误,task_id:" + task.getTaskId() + ";类型:" + type);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////\
|
|
/////////////////////////////////////////////////////////\
|
|
//素材报表
|
|
//素材报表
|
|
- public void bytedanceMaterialReportRetry(CtopOauthToken token, String startDate, String endDate) {
|
|
|
|
|
|
+ public void bytedanceMaterialReportRetry(CtopOauthToken token, String startDate, String endDate){
|
|
Long accountId = token.getAccountId();
|
|
Long accountId = token.getAccountId();
|
|
log.info("头条素材报表当前accountId为:" + accountId);
|
|
log.info("头条素材报表当前accountId为:" + accountId);
|
|
Integer page = 1;
|
|
Integer page = 1;
|
|
@@ -985,22 +890,22 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
retry.setStartDate(startDate);
|
|
retry.setStartDate(startDate);
|
|
retry.setEndDate(endDate);
|
|
retry.setEndDate(endDate);
|
|
retry.setStatusCode(code);
|
|
retry.setStatusCode(code);
|
|
- if (code != 200 && code != 1) {
|
|
|
|
|
|
+ if (code != 200 && code != 1){
|
|
retry.setStatus(0);
|
|
retry.setStatus(0);
|
|
bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
|
|
bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
|
|
- } else {
|
|
|
|
|
|
+ }else{
|
|
retry.setStatus(1);
|
|
retry.setStatus(1);
|
|
bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
|
|
bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public void bytedanceMaterialReport(CtopOauthToken token, String startDate, String endDate) {
|
|
|
|
|
|
+ public void bytedanceMaterialReport(CtopOauthToken token, String startDate, String endDate){
|
|
Long accountId = token.getAccountId();
|
|
Long accountId = token.getAccountId();
|
|
log.info("头条素材报表当前accountId为:" + accountId);
|
|
log.info("头条素材报表当前accountId为:" + accountId);
|
|
Integer page = 1;
|
|
Integer page = 1;
|
|
Integer pageSize = 100;
|
|
Integer pageSize = 100;
|
|
int code = bytedanceMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
|
|
int code = bytedanceMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
|
|
- if (code != 200 && code != 1) {
|
|
|
|
|
|
+ if (code != 200 && code != 1){
|
|
BytedanceReportMaterialRetry retry = new BytedanceReportMaterialRetry();
|
|
BytedanceReportMaterialRetry retry = new BytedanceReportMaterialRetry();
|
|
retry.setAccountId(accountId);
|
|
retry.setAccountId(accountId);
|
|
retry.setStatus(0);
|
|
retry.setStatus(0);
|
|
@@ -1011,7 +916,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private int 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,87 +925,46 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
String path = "/open_api/2/report/integrated/get/";
|
|
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() {
|
|
|
|
|
|
+ Map data = new HashMap(){
|
|
{
|
|
{
|
|
put("advertiser_id", accountId);
|
|
put("advertiser_id", accountId);
|
|
- put("start_date", startDate);
|
|
|
|
- put("end_date", endDate);
|
|
|
|
- put("page", page);
|
|
|
|
- put("page_size", pageSize);
|
|
|
|
- put("group_by", new String[]{"STAT_GROUP_BY_MATERIAL_ID", "STAT_GROUP_BY_INVENTORY", "STAT_GROUP_BY_IMAGE_MODE", "STAT_GROUP_BY_TIME_DAY"});
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- // 构造请求
|
|
|
|
- HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
|
|
- @Override
|
|
|
|
- public String getMethod() {
|
|
|
|
- return "GET";
|
|
|
|
|
|
+ put("start_date",startDate);
|
|
|
|
+ put("end_date",endDate);
|
|
|
|
+ put("page",page);
|
|
|
|
+ put("page_size",pageSize);
|
|
|
|
+ put("group_by", new String[]{"STAT_GROUP_BY_MATERIAL_ID","STAT_GROUP_BY_INVENTORY","STAT_GROUP_BY_IMAGE_MODE","STAT_GROUP_BY_TIME_DAY"});
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
- httpEntity.setHeader("Access-Token", access_token);
|
|
|
|
-
|
|
|
|
- CloseableHttpResponse response = null;
|
|
|
|
- CloseableHttpClient client = null;
|
|
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
|
|
int returnCode = 200;
|
|
int returnCode = 200;
|
|
try {
|
|
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)) {
|
|
|
|
|
|
+ if(!Check.isNull(json)){
|
|
Integer code = json.getInteger("code");
|
|
Integer code = json.getInteger("code");
|
|
- if (code != 0) {
|
|
|
|
- log.info("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + jsonString);
|
|
|
|
- returnCode = -1;
|
|
|
|
|
|
+ if(code != 0){
|
|
|
|
+ log.error("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + JSONObject.toJSONString(data));
|
|
|
|
+ //returnCode = -1;
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
JSONObject jsonData = json.getJSONObject("data");
|
|
JSONObject jsonData = json.getJSONObject("data");
|
|
- if (Check.isNull(jsonData)) {
|
|
|
|
|
|
+ if (Check.isNull(jsonData)){
|
|
log.error("获取任务列表返回信息data内容为空");
|
|
log.error("获取任务列表返回信息data内容为空");
|
|
|
|
+ return -1;
|
|
}
|
|
}
|
|
JSONObject pageInfo = jsonData.getJSONObject("page_info");
|
|
JSONObject pageInfo = jsonData.getJSONObject("page_info");
|
|
Integer totalPage = pageInfo.getInteger("total_page");
|
|
Integer totalPage = pageInfo.getInteger("total_page");
|
|
Integer currentPage = pageInfo.getInteger("page");
|
|
Integer currentPage = pageInfo.getInteger("page");
|
|
|
|
|
|
JSONArray jsonArrayay = jsonData.getJSONArray("list");
|
|
JSONArray jsonArrayay = jsonData.getJSONArray("list");
|
|
- if (jsonArrayay.size() == 0) {
|
|
|
|
- log.info("accountId:" + accountId + ";没有数据。总页数为:" + totalPage + "当前页数为:" + currentPage);
|
|
|
|
- returnCode = 1;
|
|
|
|
|
|
+ if(jsonArrayay.size() == 0){
|
|
|
|
+ log.info("accountId:" + accountId + ";没有数据。总页数为:" + totalPage + "当前页数为:" + currentPage);
|
|
|
|
+ //returnCode = 1;
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1114,7 +978,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
daily.setImageMode(dimensions.getString("image_mode"));
|
|
daily.setImageMode(dimensions.getString("image_mode"));
|
|
daily.setMaterialId(dimensions.getLong("material_id"));
|
|
daily.setMaterialId(dimensions.getLong("material_id"));
|
|
daily.setInventory(dimensions.getString("inventory"));
|
|
daily.setInventory(dimensions.getString("inventory"));
|
|
- daily.setStatDatetime(dimensions.getDate("stat_datetime") == null ? null : DateUtils.formatDate(dimensions.getDate("stat_datetime"), "yyyy-MM-dd"));
|
|
|
|
|
|
+ daily.setStatDatetime(dimensions.getDate("stat_datetime")==null?null:DateUtils.formatDate(dimensions.getDate("stat_datetime"),"yyyy-MM-dd"));
|
|
|
|
|
|
JSONObject metrics = detailJson.getJSONObject("metrics");
|
|
JSONObject metrics = detailJson.getJSONObject("metrics");
|
|
daily.setActivePayAmount(metrics.getInteger("active_pay_amount"));
|
|
daily.setActivePayAmount(metrics.getInteger("active_pay_amount"));
|
|
@@ -1217,60 +1081,27 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
bytedanceReportMaterialDailyMapper.replaceIntoBatch(bytedanceReportMaterialDailyList);
|
|
bytedanceReportMaterialDailyMapper.replaceIntoBatch(bytedanceReportMaterialDailyList);
|
|
//Long insertEndTime = System.currentTimeMillis();
|
|
//Long insertEndTime = System.currentTimeMillis();
|
|
//log.info("头条获取素材报表插入数据结束,执行耗时:{}秒", (insertEndTime - insertStartTime) / 1000);
|
|
//log.info("头条获取素材报表插入数据结束,执行耗时:{}秒", (insertEndTime - insertStartTime) / 1000);
|
|
- if (currentPage >= totalPage) {
|
|
|
|
- log.info("accountId:" + accountId + "数据同步完成,开始时间:" + startDate + ",结束时间:" + endDate);
|
|
|
|
|
|
+ if(currentPage >= totalPage){
|
|
|
|
+ //log.info("accountId:" + accountId + "数据同步完成,开始时间:" + startDate + ",结束时间:"+ endDate);
|
|
//returnCode = 1;
|
|
//returnCode = 1;
|
|
return 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);
|
|
|
|
|
|
+ }else{
|
|
|
|
+ //returnCode = -1;
|
|
|
|
+ log.error("服务器返回为空,json:"+JSONObject.toJSONString(data));
|
|
return -1;
|
|
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) {
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- returnCode = -2;
|
|
|
|
- } finally {
|
|
|
|
- try {
|
|
|
|
- if (response != null) {
|
|
|
|
- response.close();
|
|
|
|
- }
|
|
|
|
- client.close();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
|
|
+ returnCode = -3;
|
|
}
|
|
}
|
|
return returnCode;
|
|
return returnCode;
|
|
}
|
|
}
|
|
|
|
|
|
- public List<BytedanceReportMaterialRetry> getRetryList() {
|
|
|
|
|
|
+ public List<BytedanceReportMaterialRetry> getRetryList(){
|
|
return bytedanceReportMaterialDailyMapper.getRetryList();
|
|
return bytedanceReportMaterialDailyMapper.getRetryList();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|