|
@@ -1,30 +1,53 @@
|
|
|
package cn.com.ctop.bytedance.service.impl;
|
|
|
|
|
|
import cn.com.ctop.bytedance.entity.BytedanceAdvertiserDailyReport;
|
|
|
+import cn.com.ctop.bytedance.entity.BytedanceDailyReportTask;
|
|
|
+import cn.com.ctop.bytedance.entity.BytedanceReportMaterialDaily;
|
|
|
import cn.com.ctop.bytedance.mapper.BytedanceAdvertiserDailyReportMapper;
|
|
|
+import cn.com.ctop.bytedance.mapper.BytedanceDailyReportTaskMapper;
|
|
|
import cn.com.ctop.bytedance.mapper.BytedanceReportMapper;
|
|
|
+import cn.com.ctop.bytedance.mapper.BytedanceReportMaterialDailyMapper;
|
|
|
+import cn.com.ctop.bytedance.service.IBytedanceDailyReportTaskService;
|
|
|
import cn.com.ctop.bytedance.service.IBytedanceReportService;
|
|
|
+import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
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.kuaishou.modules.report.entity.KuaishouReportDailyAccount;
|
|
|
import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAccountMapper;
|
|
|
+import cn.com.ctop.kuaishou.modules.utils.DownloadUtils;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
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.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.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.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.net.URI;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
+
|
|
|
+ @Value("${jeecg.path.report-history}")
|
|
|
+ private String downloadPath;
|
|
|
@Autowired
|
|
|
private UserAllocationMapper userAllocationMapper;
|
|
|
|
|
@@ -37,6 +60,18 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
@Autowired
|
|
|
private KuaishouReportDailyAccountMapper kuaishouReportDailyAccountMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BytedanceDailyReportTaskMapper bytedanceDailyReportTaskMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IBytedanceDailyReportTaskService bytedanceDailyReportTaskService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICtopOauthTokenService ctopOauthTokenService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BytedanceReportMaterialDailyMapper bytedanceReportMaterialDailyMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 媒体昨日总消耗
|
|
|
*
|
|
@@ -634,4 +669,545 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
}
|
|
|
return reportList;
|
|
|
}
|
|
|
+
|
|
|
+ /////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
+ //创建异步任务
|
|
|
+ public void bytedanceAsyncTaskCreate () {
|
|
|
+ String startDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -1));
|
|
|
+ String endDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -31));
|
|
|
+ String type = "BYTEDANCE_LOAD_JOB_TYPE_ASYNC";
|
|
|
+ Long accountId = 1662649623517198L;
|
|
|
+
|
|
|
+ CtopOauthToken token = ctopOauthTokenService.getTokenByAccountId(accountId);
|
|
|
+ String access_token = token.getAccessToken();
|
|
|
+ Long advertiser_id = accountId;
|
|
|
+ //final Long[] ad_ids = new Long[]{1L};
|
|
|
+ //List<String> fields_list = FIELDS;
|
|
|
+ //ist<String> fields_list = new ArrayList<>();
|
|
|
+
|
|
|
+ // 请求地址
|
|
|
+ String open_api_domain = "https://ad.toutiao.com";
|
|
|
+ String path = "/open_api/2/async_task/create/";
|
|
|
+
|
|
|
+ String taskName = System.currentTimeMillis() + "";
|
|
|
+ // 请求参数
|
|
|
+ final Map filtering = new HashMap() {
|
|
|
+ {
|
|
|
+ //put("start_date", startDate);
|
|
|
+ //put("end_date", endDate);
|
|
|
+ put("start_date", "2020-04-01");
|
|
|
+ put("end_date", "2020-04-15");
|
|
|
+ put("group_by", new String[]{"STAT_GROUP_BY_CREATIVE_ID","STAT_GROUP_BY_TIME_DAY","STAT_GROUP_BY_CREATIVE_MATERIAL_MODE"}); //按照创意分组、天分组、创意类型分组查询
|
|
|
+ }
|
|
|
+ };
|
|
|
+ Map data = new HashMap() {
|
|
|
+ {
|
|
|
+ put("advertiser_id", advertiser_id);
|
|
|
+ put("task_name", taskName);
|
|
|
+ put("task_type", "REPORT");
|
|
|
+ put("task_params", filtering);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 构造请求
|
|
|
+ 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"));
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取任务列表
|
|
|
+ public void bytedanceAsyncTaskGet(){
|
|
|
+ QueryWrapper<BytedanceDailyReportTask> taskQueryWrapper = new QueryWrapper<>();
|
|
|
+ //查询三种状态的信息--任务已创建、任务执行中、任务处理中
|
|
|
+ taskQueryWrapper.in("task_status", "ASYNC_TASK_STATUS_CREATED","ASYNC_TASK_STATUS_EXECUTING","ASYNC_TASK_STATUS_EXECUTING_STAGE2");
|
|
|
+ taskQueryWrapper.orderByDesc("create_time");
|
|
|
+ List<BytedanceDailyReportTask> taskList = bytedanceDailyReportTaskService.list(taskQueryWrapper);
|
|
|
+
|
|
|
+ if (!Check.isNull(taskList)) {
|
|
|
+ for (BytedanceDailyReportTask task : taskList) {
|
|
|
+ CtopOauthToken token = ctopOauthTokenService.getTokenByAccountId(task.getAccountId());
|
|
|
+
|
|
|
+ if (!Check.isNull(token)) {
|
|
|
+ // 请求地址
|
|
|
+ String open_api_domain = "https://ad.toutiao.com";
|
|
|
+ String path = "/open_api/2/async_task/get/";
|
|
|
+
|
|
|
+ String access_token = token.getAccessToken();
|
|
|
+ Long accountId = task.getAccountId();
|
|
|
+ final Long advertiser_id = accountId;
|
|
|
+ //Long taskId = 682327L;
|
|
|
+
|
|
|
+ // 请求参数
|
|
|
+ final Map filtering = new HashMap() {
|
|
|
+ {
|
|
|
+ put("task_ids",new Long[]{task.getTaskId()});
|
|
|
+ put("task_name", task.getTaskName());
|
|
|
+ }
|
|
|
+ };
|
|
|
+ Map data = new HashMap(){
|
|
|
+ {
|
|
|
+ put("advertiser_id", advertiser_id);
|
|
|
+ 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;
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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.setTaskStatus(taskStatus);
|
|
|
+ bytedanceDailyReportTaskMapper.updateById(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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //下载任务结果
|
|
|
+ private void bytedanceAsyncTaskDownload(BytedanceDailyReportTask task, CtopOauthToken token){
|
|
|
+ // 请求地址
|
|
|
+ String open_api_domain = "https://ad.toutiao.com";
|
|
|
+ String path = "/open_api/2/async_task/download/";
|
|
|
+
|
|
|
+ Long accountId = task.getAccountId();
|
|
|
+ final Long advertiser_id = accountId;
|
|
|
+ String access_token = token.getAccessToken();
|
|
|
+ Long taskId = task.getTaskId();
|
|
|
+
|
|
|
+ //Map data = new HashMap(){
|
|
|
+ // {
|
|
|
+ // put("advertiser_id", advertiser_id);
|
|
|
+ // put("task_id", taskId);
|
|
|
+ // }
|
|
|
+ //};
|
|
|
+ //
|
|
|
+ //// 构造请求
|
|
|
+ //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();
|
|
|
+
|
|
|
+ String url = open_api_domain + path;
|
|
|
+ String fileName = task.getAccountId() + "_" + ".csv";
|
|
|
+ Map<String, Object> requestMap = new HashMap<>();
|
|
|
+ requestMap.put("advertiser_id", task.getAccountId());
|
|
|
+ requestMap.put("task_id", task.getTaskId());
|
|
|
+ String localPath = DownloadUtils.downloadByUrl(requestMap, downloadPath, url, token.getAccessToken(), fileName);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //task.setTaskStatus(5);
|
|
|
+ }
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /////////////////////////////////////////////////////////\
|
|
|
+ //素材报表
|
|
|
+ public void bytedanceMaterialReport(CtopOauthToken token, String startDate, String endDate){
|
|
|
+ //CtopOauthToken token = ctopOauthTokenService.getTokenByAccountId(accountId);
|
|
|
+ Long accountId = token.getAccountId();
|
|
|
+ Integer page = 1;
|
|
|
+ Integer pageSize = 500;
|
|
|
+ bytedanceMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void bytedanceMaterialReportByPage(Integer page, Integer pageSize, CtopOauthToken token, Long accountId, String startDate, String endDate){
|
|
|
+ //log.info("当前页数:"+ page);
|
|
|
+ String access_token = token.getAccessToken();
|
|
|
+
|
|
|
+ // 请求地址
|
|
|
+ String open_api_domain = "https://ad.oceanengine.com";
|
|
|
+ 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);
|
|
|
+ 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"});
|
|
|
+ //put("group_by", new String[]{"STAT_GROUP_BY_MATERIAL_ID"});
|
|
|
+ //put("filtering",filtering);
|
|
|
+ //put("order_field","stat_datetime");
|
|
|
+ //put("order_type","ASC");
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 构造请求
|
|
|
+ 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);
|
|
|
+ //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 );
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject jsonData = json.getJSONObject("data");
|
|
|
+ if (Check.isNull(jsonData)){
|
|
|
+ log.error("获取任务列表返回信息data内容为空");
|
|
|
+ }
|
|
|
+ JSONObject pageInfo = jsonData.getJSONObject("page_info");
|
|
|
+ Integer totalPage = pageInfo.getInteger("total_page");
|
|
|
+ Integer currentPage = pageInfo.getInteger("page");
|
|
|
+
|
|
|
+ JSONArray jsonArrayay = jsonData.getJSONArray("list");
|
|
|
+ List<BytedanceReportMaterialDaily> bytedanceReportMaterialDailyList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < jsonArrayay.size(); i++) {
|
|
|
+ BytedanceReportMaterialDaily daily = new BytedanceReportMaterialDaily();
|
|
|
+ daily.setAccountId(accountId);
|
|
|
+ JSONObject detailJson = jsonArrayay.getJSONObject(i);
|
|
|
+ if (!Check.isNull(detailJson)) {
|
|
|
+ JSONObject dimensions = detailJson.getJSONObject("dimensions");
|
|
|
+ daily.setImageMode(dimensions.getString("image_mode"));
|
|
|
+ daily.setMaterialId(dimensions.getLong("material_id"));
|
|
|
+ daily.setInventory(dimensions.getString("inventory"));
|
|
|
+ daily.setStatDatetime(dimensions.getDate("stat_datetime")==null?null:DateUtils.formatDate(dimensions.getDate("stat_datetime"),"yyyy-MM-dd"));
|
|
|
+
|
|
|
+ JSONObject metrics = detailJson.getJSONObject("metrics");
|
|
|
+ daily.setActivePayAmount(metrics.getInteger("active_pay_amount"));
|
|
|
+ daily.setValidPlayCost(metrics.getBigDecimal("valid_play_cost"));
|
|
|
+ daily.setPlay75FeedBreak(metrics.getInteger("play_75_feed_break"));
|
|
|
+ daily.setNextDayOpen(metrics.getInteger("next_day_open"));
|
|
|
+ daily.setAdvancedCreativeCouponAddition(metrics.getInteger("advanced_creative_coupon_addition"));
|
|
|
+ daily.setConvertMaterial(metrics.getInteger("convert"));
|
|
|
+ daily.setActivePayCost(metrics.getBigDecimal("active_pay_cost"));
|
|
|
+ daily.setInAppCart(metrics.getInteger("in_app_cart"));
|
|
|
+ daily.setPlay25FeedBreak(metrics.getInteger("play_25_feed_break"));
|
|
|
+ daily.setConsultEffective(metrics.getInteger("consult_effective"));
|
|
|
+ daily.setViewMaterial(metrics.getInteger("view"));
|
|
|
+ daily.setDownload(metrics.getInteger("download"));
|
|
|
+ daily.setCpa(metrics.getBigDecimal("cpa"));
|
|
|
+ daily.setCpc(metrics.getBigDecimal("cpc"));
|
|
|
+ daily.setLocationClick(metrics.getInteger("location_click"));
|
|
|
+ daily.setPhoneConfirm(metrics.getInteger("phone_confirm"));
|
|
|
+ daily.setIesMusicClick(metrics.getInteger("ies_music_click"));
|
|
|
+ daily.setPlayOverRate(metrics.getBigDecimal("play_over_rate"));
|
|
|
+ daily.setWifiPlay(metrics.getInteger("wifi_play"));
|
|
|
+ daily.setShopping(metrics.getInteger("shopping"));
|
|
|
+ daily.setQq(metrics.getInteger("qq"));
|
|
|
+ daily.setCtr(metrics.getBigDecimal("ctr"));
|
|
|
+ daily.setCpm(metrics.getBigDecimal("cpm"));
|
|
|
+ daily.setWifiPlayRate(metrics.getBigDecimal("wifi_play_rate"));
|
|
|
+ daily.setLikeMaterial(metrics.getInteger("like"));
|
|
|
+ daily.setPlay50FeedBreak(metrics.getInteger("play_50_feed_break"));
|
|
|
+ daily.setActivePayRate(metrics.getBigDecimal("active_pay_rate"));
|
|
|
+ daily.setActiveCost(metrics.getBigDecimal("active_cost"));
|
|
|
+ daily.setActive(metrics.getInteger("active"));
|
|
|
+ daily.setGameAddictionCost(metrics.getBigDecimal("game_addiction_cost"));
|
|
|
+ daily.setGameAddiction(metrics.getInteger("game_addiction"));
|
|
|
+ daily.setActiveRate(metrics.getBigDecimal("active_rate"));
|
|
|
+ daily.setClick(metrics.getInteger("click"));
|
|
|
+ daily.setPlayDuration_10s(metrics.getInteger("play_duration_10s"));
|
|
|
+ daily.setAdvancedCreativePhoneClick(metrics.getInteger("advanced_creative_phone_click"));
|
|
|
+ daily.setDownloadStart(metrics.getInteger("download_start"));
|
|
|
+ daily.setHomeVisited(metrics.getInteger("home_visited"));
|
|
|
+ daily.setPhone(metrics.getInteger("phone"));
|
|
|
+ daily.setPhoneEffective(metrics.getInteger("phone_effective"));
|
|
|
+ daily.setInAppPay(metrics.getInteger("in_app_pay"));
|
|
|
+ daily.setGameAddictionRate(metrics.getBigDecimal("game_addiction_rate"));
|
|
|
+ daily.setNextDayOpenCost(metrics.getBigDecimal("next_day_open_cost"));
|
|
|
+ daily.setIesChallengeClick(metrics.getInteger("ies_challenge_click"));
|
|
|
+ daily.setTotalPlay(metrics.getInteger("total_play"));
|
|
|
+ daily.setActiveRegisterRate(metrics.getBigDecimal("active_register_rate"));
|
|
|
+ daily.setAverageVideoPlay(metrics.getBigDecimal("average_video_play"));
|
|
|
+ daily.setDownloadFinishCost(metrics.getBigDecimal("download_finish_cost"));
|
|
|
+ daily.setPlayDuration_3s(metrics.getInteger("play_duration_3s"));
|
|
|
+ daily.setActiveRegisterCost(metrics.getBigDecimal("active_register_cost"));
|
|
|
+ daily.setShowMaterial(metrics.getInteger("show"));
|
|
|
+ daily.setNextDayOpenRate(metrics.getBigDecimal("next_day_open_rate"));
|
|
|
+ daily.setMapSearch(metrics.getInteger("map_search"));
|
|
|
+ daily.setButton(metrics.getInteger("button"));
|
|
|
+ daily.setPlayDurationSum(metrics.getInteger("play_duration_sum"));
|
|
|
+ daily.setPlay100FeedBreak(metrics.getInteger("play_100_feed_break"));
|
|
|
+ daily.setAdvancedCreativeCounselClick(metrics.getInteger("advanced_creative_counsel_click"));
|
|
|
+ daily.setConvertRate(metrics.getBigDecimal("convert_rate"));
|
|
|
+ daily.setDownloadFinishRate(metrics.getBigDecimal("download_finish_rate"));
|
|
|
+ daily.setConsult(metrics.getInteger("consult"));
|
|
|
+ daily.setShareMaterial(metrics.getInteger("share"));
|
|
|
+ daily.setVote(metrics.getInteger("vote"));
|
|
|
+ daily.setValidPlay(metrics.getInteger("valid_play"));
|
|
|
+ daily.setInstallFinishRate(metrics.getBigDecimal("install_finish_rate"));
|
|
|
+ daily.setRedirect(metrics.getInteger("redirect"));
|
|
|
+ daily.setPayCount(metrics.getInteger("pay_count"));
|
|
|
+ daily.setAdvancedCreativeFormClick(metrics.getInteger("advanced_creative_form_click"));
|
|
|
+ daily.setCost(metrics.getBigDecimal("cost"));
|
|
|
+ daily.setPhoneConnect(metrics.getInteger("phone_connect"));
|
|
|
+ daily.setCoupon(metrics.getInteger("coupon"));
|
|
|
+ daily.setDownloadStartRate(metrics.getBigDecimal("download_start_rate"));
|
|
|
+ daily.setDownloadFinish(metrics.getInteger("download_finish"));
|
|
|
+ daily.setWechat(metrics.getInteger("wechat"));
|
|
|
+ daily.setCouponSinglePage(metrics.getInteger("coupon_single_page"));
|
|
|
+ daily.setInstallFinish(metrics.getInteger("install_finish"));
|
|
|
+ daily.setLottery(metrics.getInteger("lottery"));
|
|
|
+ daily.setPlayOver(metrics.getInteger("play_over"));
|
|
|
+ daily.setInAppOrder(metrics.getInteger("in_app_order"));
|
|
|
+ daily.setDownloadStartCost(metrics.getBigDecimal("download_start_cost"));
|
|
|
+ daily.setFollow(metrics.getInteger("follow"));
|
|
|
+ daily.setMessage(metrics.getInteger("message"));
|
|
|
+ daily.setInAppDetailUv(metrics.getInteger("in_app_detail_uv"));
|
|
|
+ daily.setPlayDuration(metrics.getInteger("play_duration"));
|
|
|
+ daily.setForm(metrics.getInteger("form"));
|
|
|
+ daily.setValidPlayRate(metrics.getBigDecimal("valid_play_rate"));
|
|
|
+ daily.setAveragePlayTimePerPlay(metrics.getBigDecimal("average_play_time_per_play"));
|
|
|
+ daily.setConvertShowRate(metrics.getBigDecimal("convert_show_rate"));
|
|
|
+ daily.setInstallFinishCost(metrics.getBigDecimal("install_finish_cost"));
|
|
|
+ daily.setCommentMaterial(metrics.getInteger("comment"));
|
|
|
+ daily.setInAppUv(metrics.getInteger("in_app_uv"));
|
|
|
+ daily.setRegister(metrics.getInteger("register"));
|
|
|
+ daily.setConvertCost(metrics.getBigDecimal("convert_cost"));
|
|
|
+
|
|
|
+ bytedanceReportMaterialDailyList.add(daily);
|
|
|
+ //bytedanceReportMaterialDailyMapper.insert(daily);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ bytedanceReportMaterialDailyMapper.replaceIntoBatch(bytedanceReportMaterialDailyList);
|
|
|
+ if(currentPage >= totalPage){
|
|
|
+ return;
|
|
|
+ }else{
|
|
|
+ bytedanceMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ log.error("头条素材报表请求有误:accountId:" + accountId + ",开始时间:" + startDate + "结束时间:" + endDate + "错误返回:" +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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|