|
@@ -2,8 +2,27 @@ package cn.com.ctop.job.bytedance.data.service.impl;
|
|
|
|
|
|
import cn.com.ctop.job.bytedance.data.constant.BytedanceConstant;
|
|
|
import cn.com.ctop.job.bytedance.data.constant.CtopAdConstant;
|
|
|
-import cn.com.ctop.job.bytedance.data.entity.*;
|
|
|
-import cn.com.ctop.job.bytedance.data.mapper.*;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.ByteDanceAdvertiserReportDTO;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.ByteDanceNewMaterialReport;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.ByteDanceV3AdvertiserReportDTO;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.BytedanceAdGet;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.BytedanceAdReportDaily;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.BytedanceAdReportHourly;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.BytedanceAdvertiserReportDaily;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.BytedanceAdvertiserReportHourly;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.BytedanceAgentReportDaily;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.BytedanceV3ProjectReportDaily;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.BytedanceV3ProjectReportHourly;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.BytedanceV3PromotionProjectReportDaily;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.OauthToken;
|
|
|
+import cn.com.ctop.job.bytedance.data.enums.InventoryEnum;
|
|
|
+import cn.com.ctop.job.bytedance.data.mapper.BytedanceAdGetMapper;
|
|
|
+import cn.com.ctop.job.bytedance.data.mapper.BytedanceAdReportDailyMapper;
|
|
|
+import cn.com.ctop.job.bytedance.data.mapper.BytedanceAdReportHourlyMapper;
|
|
|
+import cn.com.ctop.job.bytedance.data.mapper.BytedanceAdvertiserReportDailyMapper;
|
|
|
+import cn.com.ctop.job.bytedance.data.mapper.BytedanceAdvertiserReportHourlyMapper;
|
|
|
+import cn.com.ctop.job.bytedance.data.mapper.BytedanceAgentReportDailyMapper;
|
|
|
+import cn.com.ctop.job.bytedance.data.mapper.BytedanceAgentReportHourlyMapper;
|
|
|
import cn.com.ctop.job.bytedance.data.service.IByteDanceAdvertiserDataService;
|
|
|
import cn.com.ctop.job.bytedance.data.service.IBytedanceAgentReportDailyService;
|
|
|
import cn.com.ctop.job.bytedance.data.service.IBytedanceAgentReportHourlyService;
|
|
@@ -16,6 +35,8 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.PropertyNamingStrategy;
|
|
|
import com.alibaba.fastjson.serializer.SerializeConfig;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.xxl.job.core.context.XxlJobHelper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import lombok.var;
|
|
@@ -26,7 +47,11 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
@@ -76,9 +101,9 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
|
|
|
*/
|
|
|
|
|
|
public void getAd(OauthToken token, int pageNum, String ids, String date, String updateDate) {
|
|
|
- log.info("开始获取广告计划信息 accountID:{},日期{},page:{}", token.getAccountId(), updateDate,pageNum);
|
|
|
+ log.info("开始获取广告计划信息 accountID:{},日期{},page:{}", token.getAccountId(), updateDate, pageNum);
|
|
|
|
|
|
- List<Object> adAccountList = redisUtil.getList("AD"+updateDate,null);
|
|
|
+ List<Object> adAccountList = redisUtil.getList("AD" + updateDate, null);
|
|
|
|
|
|
JSONArray getIds = null;
|
|
|
if (null != ids && !"".equals(ids)) {
|
|
@@ -117,30 +142,30 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
|
|
|
log.error(
|
|
|
"获取广告计划信息接口异常==》accountId:{},message:{},code{}",
|
|
|
token.getAccountId(),
|
|
|
- resultObject.getString("message"),code);
|
|
|
+ resultObject.getString("message"), code);
|
|
|
//请求过于频繁
|
|
|
- if (40100 == code){
|
|
|
- log.info("广告计划请求频繁,code:{},准备重试,accountId:{},错误消息:{}",code,token.getAccountId(),resultObject.getString("message"));
|
|
|
+ if (40100 == code) {
|
|
|
+ log.info("广告计划请求频繁,code:{},准备重试,accountId:{},错误消息:{}", code, token.getAccountId(), resultObject.getString("message"));
|
|
|
//添加重试
|
|
|
- if (Check.isNull(adAccountList)){
|
|
|
- redisUtil.add("AD"+updateDate,Arrays.asList(token.getAccountId()), 1, TimeUnit.HOURS);
|
|
|
- }else {
|
|
|
+ if (Check.isNull(adAccountList)) {
|
|
|
+ redisUtil.add("AD" + updateDate, Arrays.asList(token.getAccountId()), 1, TimeUnit.HOURS);
|
|
|
+ } else {
|
|
|
adAccountList.add(token.getAccountId());
|
|
|
- redisUtil.add("AD"+updateDate,adAccountList, 1, TimeUnit.HOURS);
|
|
|
+ redisUtil.add("AD" + updateDate, adAccountList, 1, TimeUnit.HOURS);
|
|
|
}
|
|
|
- }else {
|
|
|
- if (adAccountList.contains(token.getAccountId())){
|
|
|
+ } else {
|
|
|
+ if (adAccountList.contains(token.getAccountId())) {
|
|
|
adAccountList.remove(token.getAccountId());
|
|
|
- redisUtil.add("AD"+updateDate,adAccountList, 1, TimeUnit.HOURS);
|
|
|
+ redisUtil.add("AD" + updateDate, adAccountList, 1, TimeUnit.HOURS);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
JSONArray data = resultObject.getJSONObject("data").getJSONArray("list");
|
|
|
- if (adAccountList.contains(token.getAccountId())){
|
|
|
+ if (adAccountList.contains(token.getAccountId())) {
|
|
|
adAccountList.remove(token.getAccountId());
|
|
|
- redisUtil.add("AD"+updateDate,adAccountList, 1, TimeUnit.HOURS);
|
|
|
+ redisUtil.add("AD" + updateDate, adAccountList, 1, TimeUnit.HOURS);
|
|
|
}
|
|
|
if (null == data || data.isEmpty()) {
|
|
|
//log.info("广告计划,accountId:{}暂无数据",token.getAccountId());
|
|
@@ -240,7 +265,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
|
|
|
conditions.setPageSize(1000);
|
|
|
conditions.setTimeGranularity(bytedanceReportTypePl);
|
|
|
conditions.setFields(conditions.getFieldsList());
|
|
|
- log.info("账户--{}正在执行广告主{}数据",conditions.getAdvertiserId(),bytedanceReportTypePl);
|
|
|
+ log.info("账户--{}正在执行广告主{}数据", conditions.getAdvertiserId(), bytedanceReportTypePl);
|
|
|
return conditions;
|
|
|
}
|
|
|
|
|
@@ -280,7 +305,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
|
|
|
JSONObject.parseObject(data.toJSONString(), BytedanceAdReportHourly.class);
|
|
|
hourlyReport.setAdvertiserId(conditions.getAdvertiserId());
|
|
|
String hour = hourlyReport.getStatDatetime().substring(11, 13);
|
|
|
- hourlyReport.setStatDatetime(hourlyReport.getStatDatetime().substring(0,10).replace("-", ""));
|
|
|
+ hourlyReport.setStatDatetime(hourlyReport.getStatDatetime().substring(0, 10).replace("-", ""));
|
|
|
hourlyReport.setHour(Integer.parseInt(hour));
|
|
|
hourlyReports.add(hourlyReport);
|
|
|
|
|
@@ -290,7 +315,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
|
|
|
BytedanceAdReportDaily dailyReport =
|
|
|
JSONObject.parseObject(data.toJSONString(), BytedanceAdReportDaily.class);
|
|
|
dailyReport.setAdvertiserId(conditions.getAdvertiserId());
|
|
|
- dailyReport.setStatDatetime(dailyReport.getStatDatetime().substring(0,10).replace("-", ""));
|
|
|
+ dailyReport.setStatDatetime(dailyReport.getStatDatetime().substring(0, 10).replace("-", ""));
|
|
|
dailyReports.add(dailyReport);
|
|
|
}
|
|
|
}
|
|
@@ -352,47 +377,48 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
|
|
|
private void getAdvertiserReportByPage(
|
|
|
OauthToken token, ByteDanceAdvertiserReportDTO conditions, Integer page) {
|
|
|
|
|
|
- List<Object> advertiserAccountList = redisUtil.getList("ADVERTISER"+conditions.getStartDate(),null);
|
|
|
+ List<Object> advertiserAccountList = redisUtil.getList("ADVERTISER" + conditions.getStartDate(), null);
|
|
|
|
|
|
- log.info("开始获取广告主账户报表,账户id:{}--时间---{},page:{}", token.getAccountId(),conditions.getStartDate(),page);
|
|
|
+ log.info("开始获取广告主账户报表,账户id:{}--时间---{},page:{}", token.getAccountId(), conditions.getStartDate(), page);
|
|
|
conditions.setPage(page);
|
|
|
SerializeConfig config = new SerializeConfig();
|
|
|
config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
|
|
|
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(conditions, config));
|
|
|
JSONObject getObject = getAdvertiserStat(token, jsonObject);
|
|
|
+// System.out.println("返回结果:" + getObject);
|
|
|
if (null == getObject) {
|
|
|
XxlJobHelper.log("头条广告主数据获取异常");
|
|
|
- log.error("头条广告主数据获取信息为空==》accountId:{}",token.getAccountId());
|
|
|
+ log.error("头条广告主数据获取信息为空==》accountId:{}", token.getAccountId());
|
|
|
return;
|
|
|
}
|
|
|
Integer code = getObject.getInteger("code");
|
|
|
String message = getObject.getString("message");
|
|
|
if (null == code || code != 0) {
|
|
|
- log.error("头条广告主数据获取异常:{}---code--{}", message,code);
|
|
|
+ log.error("头条广告主数据获取异常:{}---code--{}", message, code);
|
|
|
|
|
|
//请求过于频繁
|
|
|
- if (40100 == code){
|
|
|
- log.info("广告主日报请求频繁,code:{},准备重试,accountId:{},错误消息:{}",code,token.getAccountId(),message);
|
|
|
+ if (40100 == code) {
|
|
|
+ log.info("广告主日报请求频繁,code:{},准备重试,accountId:{},错误消息:{}", code, token.getAccountId(), message);
|
|
|
//添加重试
|
|
|
- if (Check.isNull(advertiserAccountList)){
|
|
|
- redisUtil.add("ADVERTISER"+conditions.getStartDate(),Arrays.asList(token.getAccountId()), 1, TimeUnit.HOURS);
|
|
|
- }else {
|
|
|
+ if (Check.isNull(advertiserAccountList)) {
|
|
|
+ redisUtil.add("ADVERTISER" + conditions.getStartDate(), Arrays.asList(token.getAccountId()), 1, TimeUnit.HOURS);
|
|
|
+ } else {
|
|
|
advertiserAccountList.add(token.getAccountId());
|
|
|
- redisUtil.add("ADVERTISER"+conditions.getStartDate(),advertiserAccountList, 1, TimeUnit.HOURS);
|
|
|
+ redisUtil.add("ADVERTISER" + conditions.getStartDate(), advertiserAccountList, 1, TimeUnit.HOURS);
|
|
|
}
|
|
|
- }else {
|
|
|
- if (advertiserAccountList.contains(token.getAccountId())){
|
|
|
+ } else {
|
|
|
+ if (advertiserAccountList.contains(token.getAccountId())) {
|
|
|
advertiserAccountList.remove(token.getAccountId());
|
|
|
- redisUtil.add("ADVERTISER"+conditions.getStartDate(),advertiserAccountList, 1, TimeUnit.HOURS);
|
|
|
+ redisUtil.add("ADVERTISER" + conditions.getStartDate(), advertiserAccountList, 1, TimeUnit.HOURS);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
JSONArray dataArray = getObject.getJSONObject("data").getJSONArray("list");
|
|
|
- if (advertiserAccountList.contains(token.getAccountId())){
|
|
|
+ if (advertiserAccountList.contains(token.getAccountId())) {
|
|
|
advertiserAccountList.remove(token.getAccountId());
|
|
|
- redisUtil.add("ADVERTISER"+conditions.getStartDate(),advertiserAccountList, 1, TimeUnit.HOURS);
|
|
|
+ redisUtil.add("ADVERTISER" + conditions.getStartDate(), advertiserAccountList, 1, TimeUnit.HOURS);
|
|
|
}
|
|
|
if (null == dataArray || dataArray.isEmpty()) {
|
|
|
|
|
@@ -467,6 +493,143 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
|
|
|
groupBy.add("STAT_GROUP_BY_FIELD_ID");
|
|
|
groupBy.add("STAT_GROUP_BY_FIELD_STAT_TIME");
|
|
|
conditions.put("group_by", groupBy);
|
|
|
+// System.out.println("入参:" + conditions);
|
|
|
+ return HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, conditions);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * -------------------------------------------------------------------------获取分版位广告主
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void getPositionAdvertiserReport(OauthToken token, String startDate, String endDate, String bytedanceReportTypePl) {
|
|
|
+ var conditions = getReportDTO(token, startDate, endDate, bytedanceReportTypePl);
|
|
|
+ getPositionAdvertiserReportByPage(token, conditions, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取广告主 分版位信息
|
|
|
+ */
|
|
|
+ private void getPositionAdvertiserReportByPage(OauthToken token, ByteDanceAdvertiserReportDTO conditions, Integer page) {
|
|
|
+
|
|
|
+ List<Object> advertiserAccountList = redisUtil.getList("POSITION_ADVERTISER" + conditions.getStartDate(), null);
|
|
|
+
|
|
|
+ log.info("开始获取广告主账户报表,账户id:{}--时间---{},page:{}", token.getAccountId(), conditions.getStartDate(), page);
|
|
|
+ conditions.setPage(page);
|
|
|
+ SerializeConfig config = new SerializeConfig();
|
|
|
+ config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(conditions, config));
|
|
|
+ JSONObject getObject = getPositionAdvertiserStat(token, jsonObject);
|
|
|
+// System.out.println("返回结果:" + getObject);
|
|
|
+ if (null == getObject) {
|
|
|
+ XxlJobHelper.log("头条广告主数据获取异常");
|
|
|
+ log.error("头条广告主数据获取信息为空==》accountId:{}", token.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Integer code = getObject.getInteger("code");
|
|
|
+ String message = getObject.getString("message");
|
|
|
+ if (null == code || code != 0) {
|
|
|
+ log.error("头条广告主数据获取异常:{}---code--{}", message, code);
|
|
|
+
|
|
|
+ //请求过于频繁
|
|
|
+ if (40100 == code) {
|
|
|
+ log.info("广告主日报请求频繁,code:{},准备重试,accountId:{},错误消息:{}", code, token.getAccountId(), message);
|
|
|
+ //添加重试
|
|
|
+ if (Check.isNull(advertiserAccountList)) {
|
|
|
+ redisUtil.add("POSITION_ADVERTISER" + conditions.getStartDate(), Arrays.asList(token.getAccountId()), 1, TimeUnit.HOURS);
|
|
|
+ } else {
|
|
|
+ advertiserAccountList.add(token.getAccountId());
|
|
|
+ redisUtil.add("POSITION_ADVERTISER" + conditions.getStartDate(), advertiserAccountList, 1, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (advertiserAccountList.contains(token.getAccountId())) {
|
|
|
+ advertiserAccountList.remove(token.getAccountId());
|
|
|
+ redisUtil.add("POSITION_ADVERTISER" + conditions.getStartDate(), advertiserAccountList, 1, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray dataArray = getObject.getJSONObject("data").getJSONArray("list");
|
|
|
+ if (advertiserAccountList.contains(token.getAccountId())) {
|
|
|
+ advertiserAccountList.remove(token.getAccountId());
|
|
|
+ redisUtil.add("POSITION_ADVERTISER" + conditions.getStartDate(), advertiserAccountList, 1, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+ if (null == dataArray || dataArray.isEmpty()) {
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+// List<BytedanceAdvertiserReportHourly> hourlyList = new ArrayList<>();
|
|
|
+ List<BytedanceAdvertiserReportDaily> dailyList = new ArrayList<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ for (int i = 0; i < dataArray.size(); i++) {
|
|
|
+ JSONObject data = dataArray.getJSONObject(i);
|
|
|
+// if (null != conditions.getTimeGranularity()
|
|
|
+// && conditions.getTimeGranularity().equals(CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY)) {
|
|
|
+// // 时报
|
|
|
+// BytedanceAdvertiserReportHourly hourlyReport =
|
|
|
+// JSONObject.parseObject(data.toJSONString(), BytedanceAdvertiserReportHourly.class);
|
|
|
+// hourlyReport.setAdvertiserId(conditions.getAdvertiserId());
|
|
|
+// String hour = hourlyReport.getStatDatetime().substring(11, 13);
|
|
|
+// hourlyReport.setStatDatetime(hourlyReport.getStatDatetime().substring(0, 10).replace("-", ""));
|
|
|
+// hourlyReport.setHour(Integer.parseInt(hour));
|
|
|
+// hourlyList.add(hourlyReport);
|
|
|
+//
|
|
|
+// } else {
|
|
|
+ // 日报
|
|
|
+ BytedanceAdvertiserReportDaily dailyReport =
|
|
|
+ JSONObject.parseObject(data.toJSONString(), BytedanceAdvertiserReportDaily.class);
|
|
|
+ dailyReport.setAdvertiserId(conditions.getAdvertiserId());
|
|
|
+ dailyReport.setStatDatetime(dailyReport.getStatDatetime().substring(0, 10).replace("-", ""));
|
|
|
+ dailyReport.setInventoryName(InventoryEnum.getNameByCode(dailyReport.getInventory()));
|
|
|
+ dailyList.add(dailyReport);
|
|
|
+// }
|
|
|
+ }
|
|
|
+// if (hourlyList.size() > 0) {
|
|
|
+// bytedanceAdvertiserReportHourlyMapper.insert(hourlyList);
|
|
|
+// }
|
|
|
+ if (dailyList.size() > 0) {
|
|
|
+ bytedanceAdvertiserReportDailyMapper.insertPosition(dailyList);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("获取广告主数据错误:{}", e.toString());
|
|
|
+ }
|
|
|
+ page++;
|
|
|
+ int totalPage =
|
|
|
+ getObject.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
|
|
|
+ if (page <= totalPage) {
|
|
|
+ getPositionAdvertiserReportByPage(token, conditions, page);
|
|
|
+ } else {
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("advertiser_id", token.getAccountId());
|
|
|
+ param.put("start_date", conditions.getStartDate().replace("-", ""));
|
|
|
+ param.put("end_date", conditions.getEndDate().replace("-", ""));
|
|
|
+ if (null != conditions.getTimeGranularity()
|
|
|
+ && conditions.getTimeGranularity().equals(CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY)) {
|
|
|
+ param.put("date_type", "hourly");
|
|
|
+ } else {
|
|
|
+ param.put("date_type", "daily");
|
|
|
+ }
|
|
|
+ HttpUtils.httpPostRequest(urlPath, param, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取广告主报表信息
|
|
|
+ *
|
|
|
+ * @param token
|
|
|
+ * @param conditions
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject getPositionAdvertiserStat(OauthToken token, JSONObject conditions) {
|
|
|
+ // 请求地址
|
|
|
+ String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V2_REPORT_advertiser_GET;
|
|
|
+ JSONArray groupBy = new JSONArray();
|
|
|
+ groupBy.add("STAT_GROUP_BY_FIELD_ID");
|
|
|
+ groupBy.add("STAT_GROUP_BY_FIELD_STAT_TIME");
|
|
|
+ groupBy.add("STAT_GROUP_BY_INVENTORY");
|
|
|
+ conditions.put("group_by", groupBy);
|
|
|
+// System.out.println("入参:" + conditions);
|
|
|
return HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, conditions);
|
|
|
}
|
|
|
|
|
@@ -475,21 +638,13 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
|
|
|
*/
|
|
|
@Override
|
|
|
public void getAgentReport(
|
|
|
- OauthToken token, String startDate, String endDate, String bytedanceReportTypePl) {
|
|
|
+ OauthToken token, String startDate, String endDate) {
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
- if (CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY.equals(bytedanceReportTypePl)) {
|
|
|
- // 日报
|
|
|
- jsonObject.put("agent_id", token.getAccountId());
|
|
|
- jsonObject.put("start_date", startDate);
|
|
|
- jsonObject.put("end_date", endDate);
|
|
|
- jsonObject.put("page_size", 1000);
|
|
|
- jsonObject.put("timeGranularity", bytedanceReportTypePl);
|
|
|
- } else {
|
|
|
- // 时报
|
|
|
- jsonObject.put("agent_id", token.getAccountId());
|
|
|
- jsonObject.put("page_size", 1000);
|
|
|
- jsonObject.put("timeGranularity", bytedanceReportTypePl);
|
|
|
- }
|
|
|
+ // 日报
|
|
|
+ jsonObject.put("agent_id", token.getAccountId());
|
|
|
+ jsonObject.put("start_date", startDate);
|
|
|
+ jsonObject.put("end_date", endDate);
|
|
|
+ jsonObject.put("page_size", 1000);
|
|
|
|
|
|
getAgentReportByPage(token, jsonObject, 1);
|
|
|
}
|
|
@@ -498,80 +653,485 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
|
|
|
* 获取代理商
|
|
|
*/
|
|
|
private void getAgentReportByPage(OauthToken token, JSONObject conditions, Integer page) {
|
|
|
- log.info("获取代理商数据 accountID:{},page:{}", token.getAccountId(), page);
|
|
|
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
|
|
|
- String hour = simpleDateFormat.format(new Date());
|
|
|
- String nowDate = DateUtils.getNowDate("yyyyMMdd");
|
|
|
conditions.put("page", page);
|
|
|
SerializeConfig config = new SerializeConfig();
|
|
|
config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
|
|
|
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(conditions, config));
|
|
|
+// System.out.println("----------------入参:" + jsonObject);
|
|
|
+// System.out.println("-");
|
|
|
JSONObject getObject = getAgentStat(token, jsonObject);
|
|
|
+// System.out.println("----------------结果:" + getObject);
|
|
|
if (null == getObject) {
|
|
|
XxlJobHelper.log("头条代理商数据获取异常");
|
|
|
return;
|
|
|
}
|
|
|
Integer code = getObject.getInteger("code");
|
|
|
- String message = getObject.getString("message");
|
|
|
- if (null == code || code != 0) {
|
|
|
- XxlJobHelper.log("头条代理商数据获取异常:{}", message);
|
|
|
+ if (code == 0) {
|
|
|
+ JSONArray dataArray = getObject.getJSONObject("data").getJSONArray("list");
|
|
|
+ if (null == dataArray || dataArray.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<BytedanceAgentReportDaily> dailyList = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ Integer startDate = DateUtils.getDateInteger(conditions.getString("start_date"));
|
|
|
+ for (int i = 0; i < dataArray.size(); i++) {
|
|
|
+ JSONObject data = dataArray.getJSONObject(i);
|
|
|
+ // 日报
|
|
|
+ BytedanceAgentReportDaily dailyReport = JSONObject.parseObject(data.toJSONString(), BytedanceAgentReportDaily.class);
|
|
|
+ dailyReport.setStatDatetime(String.valueOf(startDate));
|
|
|
+ dailyList.add(dailyReport);
|
|
|
+ }
|
|
|
+ if (dailyList.size() > 0) {
|
|
|
+ bytedanceAgentReportDailyMapper.insert(dailyList);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.info("获取代理商数据错误:{}", e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ page++;
|
|
|
+ int totalPage =
|
|
|
+ getObject.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
|
|
|
+ if (page <= totalPage) {
|
|
|
+ getAgentReportByPage(token, conditions, page);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取获取代理商报表信息
|
|
|
+ *
|
|
|
+ * @param token
|
|
|
+ * @param conditions
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject getAgentStat(OauthToken token, JSONObject conditions) {
|
|
|
+ // 请求地址
|
|
|
+ String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V2_REPORT_AGENT_GET_V2;
|
|
|
+ return HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, conditions);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static final ObjectMapper mapper = new ObjectMapper();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取自定义报表可用指标和维度
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void getV3AdvertiserConfig(OauthToken oauthToken) {
|
|
|
+ try {
|
|
|
+ // 请求地址
|
|
|
+ String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V3_CONFIG_ADVERTISER_GET;
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("advertiser_id", oauthToken.getAccountId());
|
|
|
+
|
|
|
+ List<String> data_topics_list = new ArrayList<>();
|
|
|
+ data_topics_list.add("BASIC_DATA");//广告基础数据
|
|
|
+// data_topics_list.add("QUERY_DATA");//搜索词数据、
|
|
|
+// data_topics_list.add("BIDWORD_DATA");//关键词数据
|
|
|
+// data_topics_list.add("MATERIAL_DATA");//素材数据、
|
|
|
+ data_topics_list.add("PRODUCT_DATA");//产品数据、
|
|
|
+// data_topics_list.add("ONE_KEY_BOOST_DATA");//一键起量(巨量广告升级版)
|
|
|
+ String data_topics = mapper.writeValueAsString(data_topics_list);
|
|
|
+ param.put("data_topics", data_topics);
|
|
|
+
|
|
|
+ Map<String, String> header = new HashMap<>();
|
|
|
+ header.put("Access-Token", oauthToken.getAccessToken());
|
|
|
+ JSONObject resultObject = JSONObject.parseObject(HttpUtils.httpGet(url, param, header));
|
|
|
+// System.out.println("指标参数:\n" + resultObject);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getV3AdvertiserReport(OauthToken token, String startDate, String endDate, String bytedanceReportType) {
|
|
|
+ String dataTopic = "BASIC_DATA"; //广告基础数据
|
|
|
+// String dataTopic = "MATERIAL_DATA";//素材数据
|
|
|
+
|
|
|
+ List<String> dimensions = new ArrayList<>();
|
|
|
+ dimensions.add(bytedanceReportType);
|
|
|
+ /**
|
|
|
+ *stat_time_hour 小时
|
|
|
+ *stat_time_day 每天
|
|
|
+ *cdp_project_id 项目ID
|
|
|
+ *cdp_project_name 项目名称
|
|
|
+ */
|
|
|
+ dimensions.add("cdp_project_id");
|
|
|
+ dimensions.add("cdp_project_name");
|
|
|
+ var conditions = new ByteDanceV3AdvertiserReportDTO(token.getAccountId(), dimensions, dataTopic, startDate, endDate, 100);
|
|
|
+ getV3AdvertiserReportByPage(token, conditions, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * V3头条项目报表
|
|
|
+ */
|
|
|
+ private void getV3AdvertiserReportByPage(OauthToken token, ByteDanceV3AdvertiserReportDTO conditions, Integer page) {
|
|
|
+ List<Object> advertiserAccountList = redisUtil.getList("V3_ADVERTISER" + conditions.getStartTime(), null);
|
|
|
+ conditions.setPage(page);
|
|
|
+ SerializeConfig config = new SerializeConfig();
|
|
|
+ config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
|
|
|
+ JSONObject params = JSONObject.parseObject(JSON.toJSONString(conditions, config));
|
|
|
+ // 请求地址
|
|
|
+ String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V3_REPORT_INTEGRATED_GET;
|
|
|
+
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Access-Token", token.getAccessToken());
|
|
|
+
|
|
|
+ String info = HttpUtils.httpGet(url, params, headers);
|
|
|
+ JSONObject result = JSONObject.parseObject(info, JSONObject.class);
|
|
|
+// System.out.println("【请求参数】:" + params + "\n【返回信息】:" + result);
|
|
|
+
|
|
|
+ if (Check.isNull(result)) {
|
|
|
+ XxlJobHelper.log("V3项目报表获取异常");
|
|
|
return;
|
|
|
}
|
|
|
- JSONArray dataArray = getObject.getJSONObject("data").getJSONArray("list");
|
|
|
- if (null == dataArray || dataArray.isEmpty()) {
|
|
|
+ Integer code = result.getInteger("code");
|
|
|
+ String message = result.getString("message");
|
|
|
+ if (code != 0) {
|
|
|
+ if (40100 == code) {
|
|
|
+ //请求过于频繁
|
|
|
+ log.info("V3项目报表请求频繁,准备重试,accountId:{}\n【错误信息】:{}", token.getAccountId(), message);
|
|
|
+ //添加重试
|
|
|
+ if (Check.isNull(advertiserAccountList)) {
|
|
|
+ redisUtil.add("V3_ADVERTISER" + conditions.getStartTime(), Arrays.asList(token.getAccountId()), 1, TimeUnit.HOURS);
|
|
|
+ } else {
|
|
|
+ advertiserAccountList.add(token.getAccountId());
|
|
|
+ redisUtil.add("V3_ADVERTISER" + conditions.getStartTime(), advertiserAccountList, 1, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("V3项目报表调取失败,账户ID:{}\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", token.getAccountId(), url, JSONObject.toJSON(params), message);
|
|
|
+ if (advertiserAccountList.contains(token.getAccountId())) {
|
|
|
+ advertiserAccountList.remove(token.getAccountId());
|
|
|
+ redisUtil.add("V3_ADVERTISER" + conditions.getStartTime(), advertiserAccountList, 1, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
- List<BytedanceAgentReportHourly> hourlyList = new ArrayList<>();
|
|
|
- List<BytedanceAgentReportDaily> dailyList = new ArrayList<>();
|
|
|
+
|
|
|
+ JSONArray rows = result.getJSONObject("data").getJSONArray("rows");
|
|
|
+ if (advertiserAccountList.contains(token.getAccountId())) {
|
|
|
+ advertiserAccountList.remove(token.getAccountId());
|
|
|
+ redisUtil.add("V3_ADVERTISER" + conditions.getStartTime(), advertiserAccountList, 1, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+ if (Check.isNull(rows)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<BytedanceV3ProjectReportHourly> hourlyList = new ArrayList<>();
|
|
|
+ List<BytedanceV3ProjectReportDaily> dailyList = new ArrayList<>();
|
|
|
try {
|
|
|
- for (int i = 0; i < dataArray.size(); i++) {
|
|
|
- JSONObject data = dataArray.getJSONObject(i);
|
|
|
- if (null != conditions.get("timeGranularity")
|
|
|
- && conditions
|
|
|
- .get("timeGranularity")
|
|
|
- .equals(CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY)) {
|
|
|
+ for (int i = 0; i < rows.size(); i++) {
|
|
|
+ JSONObject data = rows.getJSONObject(i);
|
|
|
+ JSONObject metrics = data.getJSONObject("metrics");
|
|
|
+ JSONObject dimensions = data.getJSONObject("dimensions");
|
|
|
+ Long projectId = dimensions.getLong("cdp_project_id");
|
|
|
+ String projectName = dimensions.getString("cdp_project_name");
|
|
|
+
|
|
|
+ if (conditions.getDimensions().contains(CtopAdConstant.BYTEDANCE_REPORT_V3_TYPE_HOURLY)) {
|
|
|
+ String hour = dimensions.getString("stat_time_hour").substring(11, 13);
|
|
|
+ // 时报
|
|
|
+ BytedanceV3ProjectReportHourly hourlyReport = JSONObject.parseObject(metrics.toJSONString(), BytedanceV3ProjectReportHourly.class);
|
|
|
+ hourlyReport.setAdvertiserId(token.getAccountId());
|
|
|
+ hourlyReport.setStatTimeDay(dimensions.getString("stat_time_hour").substring(0, 10).replace("-", ""));
|
|
|
+ hourlyReport.setStatHour(Integer.parseInt(hour));
|
|
|
+ hourlyReport.setCdpProjectId(projectId);
|
|
|
+ hourlyReport.setCdpProjectName(projectName);
|
|
|
+ hourlyList.add(hourlyReport);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 日报
|
|
|
+ BytedanceV3ProjectReportDaily dailyReport = JSONObject.parseObject(metrics.toJSONString(), BytedanceV3ProjectReportDaily.class);
|
|
|
+ dailyReport.setAdvertiserId(token.getAccountId());
|
|
|
+ dailyReport.setStatTimeDay(dimensions.getString("stat_time_day").substring(0, 10).replace("-", ""));
|
|
|
+ dailyReport.setCdpProjectId(projectId);
|
|
|
+ dailyReport.setCdpProjectName(projectName);
|
|
|
+ dailyList.add(dailyReport);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (hourlyList.size() > 0) {
|
|
|
+ bytedanceAdvertiserReportHourlyMapper.insertV3Project(hourlyList);
|
|
|
+ }
|
|
|
+ if (dailyList.size() > 0) {
|
|
|
+ bytedanceAdvertiserReportDailyMapper.insertV3Project(dailyList);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.info("获取广告主数据错误:", e.toString());
|
|
|
+ }
|
|
|
+ page++;
|
|
|
+
|
|
|
+ int totalPage = result.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
|
|
|
+ if (page <= totalPage) {
|
|
|
+ getV3AdvertiserReportByPage(token, conditions, page);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * V3 广告报表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void getV3PromotionProjectReport(OauthToken token, String startDate, String endDate, String bytedanceReportType) {
|
|
|
+ String dataTopic = "BASIC_DATA"; //广告基础数据
|
|
|
+// String dataTopic = "MATERIAL_DATA";//素材数据
|
|
|
+
|
|
|
+ List<String> dimensions = new ArrayList<>();
|
|
|
+ dimensions.add(bytedanceReportType);
|
|
|
+ /**
|
|
|
+ *stat_time_hour 小时
|
|
|
+ *stat_time_day 每天
|
|
|
+ *cdp_project_id 项目ID
|
|
|
+ *cdp_project_name 项目名称
|
|
|
+ *cdp_promotion_id 广告ID
|
|
|
+ *cdp_project_name 广告名称
|
|
|
+ */
|
|
|
+ dimensions.add("cdp_project_id");
|
|
|
+ dimensions.add("cdp_project_name");
|
|
|
+ dimensions.add("cdp_promotion_id");
|
|
|
+ dimensions.add("cdp_promotion_name");
|
|
|
+ var conditions = new ByteDanceV3AdvertiserReportDTO(token.getAccountId(), dimensions, dataTopic, startDate, endDate, 100);
|
|
|
+ getV3PromotionProjectReportByPage(token, conditions, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * V3头条项目报表
|
|
|
+ */
|
|
|
+ private void getV3PromotionProjectReportByPage(OauthToken token, ByteDanceV3AdvertiserReportDTO conditions, Integer page) {
|
|
|
+ List<Object> advertiserAccountList = redisUtil.getList("V3_PROMOTION_PROJECT" + conditions.getStartTime(), null);
|
|
|
+ conditions.setPage(page);
|
|
|
+ SerializeConfig config = new SerializeConfig();
|
|
|
+ config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
|
|
|
+ JSONObject params = JSONObject.parseObject(JSON.toJSONString(conditions, config));
|
|
|
+ // 请求地址
|
|
|
+ String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V3_REPORT_INTEGRATED_GET;
|
|
|
+
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Access-Token", token.getAccessToken());
|
|
|
+
|
|
|
+ String info = HttpUtils.httpGet(url, params, headers);
|
|
|
+ JSONObject result = JSONObject.parseObject(info, JSONObject.class);
|
|
|
+// System.out.println("【请求参数】:" + params + "\n【返回信息】:" + result);
|
|
|
+
|
|
|
+ if (Check.isNull(result)) {
|
|
|
+ XxlJobHelper.log("V3项目报表获取异常");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Integer code = result.getInteger("code");
|
|
|
+ String message = result.getString("message");
|
|
|
+ if (code != 0) {
|
|
|
+ if (40100 == code) {
|
|
|
+ //请求过于频繁
|
|
|
+ log.info("V3广告报表请求频繁,准备重试,accountId:{}\n【错误信息】:{}", token.getAccountId(), message);
|
|
|
+ //添加重试
|
|
|
+ if (Check.isNull(advertiserAccountList)) {
|
|
|
+ redisUtil.add("V3_PROMOTION_PROJECT" + conditions.getStartTime(), Arrays.asList(token.getAccountId()), 1, TimeUnit.HOURS);
|
|
|
+ } else {
|
|
|
+ advertiserAccountList.add(token.getAccountId());
|
|
|
+ redisUtil.add("V3_PROMOTION_PROJECT" + conditions.getStartTime(), advertiserAccountList, 1, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("V3广告报表调取失败,账户ID:{}\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", token.getAccountId(), url, JSONObject.toJSON(params), message);
|
|
|
+ if (advertiserAccountList.contains(token.getAccountId())) {
|
|
|
+ advertiserAccountList.remove(token.getAccountId());
|
|
|
+ redisUtil.add("V3_PROMOTION_PROJECT" + conditions.getStartTime(), advertiserAccountList, 1, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray rows = result.getJSONObject("data").getJSONArray("rows");
|
|
|
+ if (advertiserAccountList.contains(token.getAccountId())) {
|
|
|
+ advertiserAccountList.remove(token.getAccountId());
|
|
|
+ redisUtil.add("V3_PROMOTION_PROJECT" + conditions.getStartTime(), advertiserAccountList, 1, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+ if (Check.isNull(rows)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<BytedanceV3PromotionProjectReportDaily> hourlyList = new ArrayList<>();
|
|
|
+ List<BytedanceV3PromotionProjectReportDaily> dailyList = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ for (int i = 0; i < rows.size(); i++) {
|
|
|
+ JSONObject data = rows.getJSONObject(i);
|
|
|
+ JSONObject metrics = data.getJSONObject("metrics");
|
|
|
+ JSONObject dimensions = data.getJSONObject("dimensions");
|
|
|
+ Long projectId = dimensions.getLong("cdp_project_id");
|
|
|
+ String projectName = dimensions.getString("cdp_project_name");
|
|
|
+ Long promotionId = dimensions.getLong("cdp_promotion_id");
|
|
|
+ String promotionName = dimensions.getString("cdp_promotion_name");
|
|
|
+
|
|
|
+ if (conditions.getDimensions().contains(CtopAdConstant.BYTEDANCE_REPORT_V3_TYPE_HOURLY)) {
|
|
|
+ String hour = dimensions.getString("stat_time_hour").substring(11, 13);
|
|
|
// 时报
|
|
|
- BytedanceAgentReportHourly hourlyReport =
|
|
|
- JSONObject.parseObject(data.toJSONString(), BytedanceAgentReportHourly.class);
|
|
|
- hourlyReport.setStatDatetime(nowDate);
|
|
|
+ BytedanceV3PromotionProjectReportDaily hourlyReport = JSONObject.parseObject(metrics.toJSONString(), BytedanceV3PromotionProjectReportDaily.class);
|
|
|
+ hourlyReport.setAdvertiserId(token.getAccountId());
|
|
|
+ hourlyReport.setStatTimeDay(dimensions.getString("stat_time_hour").substring(0, 10).replace("-", ""));
|
|
|
hourlyReport.setHour(Integer.parseInt(hour));
|
|
|
+ hourlyReport.setCdpProjectId(projectId);
|
|
|
+ hourlyReport.setCdpProjectName(projectName);
|
|
|
+ hourlyReport.setPromotionId(promotionId);
|
|
|
+ hourlyReport.setPromotionName(promotionName);
|
|
|
hourlyList.add(hourlyReport);
|
|
|
} else {
|
|
|
// 日报
|
|
|
- BytedanceAgentReportDaily dailyReport =
|
|
|
- JSONObject.parseObject(data.toJSONString(), BytedanceAgentReportDaily.class);
|
|
|
- dailyReport.setStatDatetime(((String) conditions.get("start_date")).replace("-", ""));
|
|
|
+ BytedanceV3PromotionProjectReportDaily dailyReport = JSONObject.parseObject(metrics.toJSONString(), BytedanceV3PromotionProjectReportDaily.class);
|
|
|
+ dailyReport.setAdvertiserId(token.getAccountId());
|
|
|
+ dailyReport.setStatTimeDay(dimensions.getString("stat_time_day").substring(0, 10).replace("-", ""));
|
|
|
+ dailyReport.setCdpProjectId(projectId);
|
|
|
+ dailyReport.setCdpProjectName(projectName);
|
|
|
+ dailyReport.setPromotionId(promotionId);
|
|
|
+ dailyReport.setPromotionName(promotionName);
|
|
|
dailyList.add(dailyReport);
|
|
|
}
|
|
|
}
|
|
|
if (hourlyList.size() > 0) {
|
|
|
- bytedanceAgentReportHourlyMapper.insert(hourlyList);
|
|
|
+ bytedanceAdvertiserReportDailyMapper.insertV3PromotionProjectHour(hourlyList);
|
|
|
}
|
|
|
if (dailyList.size() > 0) {
|
|
|
- bytedanceAgentReportDailyMapper.insert(dailyList);
|
|
|
+ bytedanceAdvertiserReportDailyMapper.insertV3PromotionProject(dailyList);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- log.info("获取代理商数据错误:{}", e.toString());
|
|
|
+ log.info("获取广告主数据错误:", e.toString());
|
|
|
}
|
|
|
page++;
|
|
|
- int totalPage =
|
|
|
- getObject.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
|
|
|
+
|
|
|
+ int totalPage = result.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
|
|
|
if (page <= totalPage) {
|
|
|
- getAgentReportByPage(token, conditions, page);
|
|
|
+ getV3PromotionProjectReportByPage(token, conditions, page);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * 获取获取代理商报表信息
|
|
|
- *
|
|
|
- * @param token
|
|
|
- * @param conditions
|
|
|
- * @return
|
|
|
+ * V3 素材报表
|
|
|
*/
|
|
|
- public JSONObject getAgentStat(OauthToken token, JSONObject conditions) {
|
|
|
+ @Override
|
|
|
+ public void getV3PromotionMaterialReport(OauthToken token, String startDate, String endDate, String bytedanceReportType) {
|
|
|
+// String dataTopic = "BASIC_DATA"; //广告基础数据
|
|
|
+ String dataTopic = "MATERIAL_DATA";//素材数据
|
|
|
+ List<String> dimensions = new ArrayList<>();
|
|
|
+ dimensions.add(bytedanceReportType);
|
|
|
+ /**
|
|
|
+ *stat_time_hour 小时
|
|
|
+ *stat_time_day 每天
|
|
|
+ *cdp_project_id 项目ID
|
|
|
+ *cdp_project_name 项目名称
|
|
|
+ *cdp_promotion_id 广告ID
|
|
|
+ *cdp_project_name 广告名称
|
|
|
+ *material_id 素材ID
|
|
|
+ *ad_platform_material_name 素材名
|
|
|
+ */
|
|
|
+ dimensions.add("cdp_project_id");
|
|
|
+ dimensions.add("cdp_project_name");
|
|
|
+ dimensions.add("cdp_promotion_id");
|
|
|
+ dimensions.add("cdp_promotion_name");
|
|
|
+ dimensions.add("image_mode");
|
|
|
+ dimensions.add("material_id");
|
|
|
+ dimensions.add("ad_platform_material_name");
|
|
|
+ var conditions = new ByteDanceV3AdvertiserReportDTO(token.getAccountId(), dimensions, dataTopic, startDate, endDate, 100);
|
|
|
+ getV3PromotionMaterialReportByPage(token, conditions, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * V3头条项目报表
|
|
|
+ */
|
|
|
+ private void getV3PromotionMaterialReportByPage(OauthToken token, ByteDanceV3AdvertiserReportDTO conditions, Integer page) {
|
|
|
+ List<Object> advertiserAccountList = redisUtil.getList("V3_PROMOTION_MATERIAL" + conditions.getStartTime(), null);
|
|
|
+ conditions.setPage(page);
|
|
|
+ SerializeConfig config = new SerializeConfig();
|
|
|
+ config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
|
|
|
+ JSONObject params = JSONObject.parseObject(JSON.toJSONString(conditions, config));
|
|
|
// 请求地址
|
|
|
- String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V2_REPORT_AGENT_GET_V2;
|
|
|
- return HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, conditions);
|
|
|
+ String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V3_REPORT_INTEGRATED_GET;
|
|
|
+
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Access-Token", token.getAccessToken());
|
|
|
+
|
|
|
+ String info = HttpUtils.httpGet(url, params, headers);
|
|
|
+ JSONObject result = JSONObject.parseObject(info, JSONObject.class);
|
|
|
+// System.out.println("【请求参数】:" + params + "\n【返回信息】:" + result);
|
|
|
+
|
|
|
+ if (Check.isNull(result)) {
|
|
|
+ XxlJobHelper.log("V3项目报表获取异常");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Integer code = result.getInteger("code");
|
|
|
+ String message = result.getString("message");
|
|
|
+ if (code != 0) {
|
|
|
+ if (40100 == code) {
|
|
|
+ //请求过于频繁
|
|
|
+ log.info("V3素材报表请求频繁,准备重试,accountId:{}\n【错误信息】:{}", token.getAccountId(), message);
|
|
|
+ //添加重试
|
|
|
+ if (Check.isNull(advertiserAccountList)) {
|
|
|
+ redisUtil.add("V3_PROMOTION_MATERIAL" + conditions.getStartTime(), Arrays.asList(token.getAccountId()), 1, TimeUnit.HOURS);
|
|
|
+ } else {
|
|
|
+ advertiserAccountList.add(token.getAccountId());
|
|
|
+ redisUtil.add("V3_PROMOTION_MATERIAL" + conditions.getStartTime(), advertiserAccountList, 1, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("V3素材报表调取失败,账户ID:{}\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", token.getAccountId(), url, JSONObject.toJSON(params), message);
|
|
|
+ if (advertiserAccountList.contains(token.getAccountId())) {
|
|
|
+ advertiserAccountList.remove(token.getAccountId());
|
|
|
+ redisUtil.add("V3_PROMOTION_MATERIAL" + conditions.getStartTime(), advertiserAccountList, 1, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray rows = result.getJSONObject("data").getJSONArray("rows");
|
|
|
+ if (advertiserAccountList.contains(token.getAccountId())) {
|
|
|
+ advertiserAccountList.remove(token.getAccountId());
|
|
|
+ redisUtil.add("V3_PROMOTION_MATERIAL" + conditions.getStartTime(), advertiserAccountList, 1, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+ if (Check.isNull(rows)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<ByteDanceNewMaterialReport> videolist = new ArrayList<>();
|
|
|
+ List<ByteDanceNewMaterialReport> imageList = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ for (int i = 0; i < rows.size(); i++) {
|
|
|
+ JSONObject data = rows.getJSONObject(i);
|
|
|
+ JSONObject metrics = data.getJSONObject("metrics");
|
|
|
+ JSONObject dimensions = data.getJSONObject("dimensions");
|
|
|
+ Long projectId = dimensions.getLong("cdp_project_id");
|
|
|
+ String projectName = dimensions.getString("cdp_project_name");
|
|
|
+ Long promotionId = dimensions.getLong("cdp_promotion_id");
|
|
|
+ String promotionName = dimensions.getString("cdp_promotion_name");
|
|
|
+ String imageMode = dimensions.getString("image_mode");
|
|
|
+ String materialId = dimensions.getString("material_id");
|
|
|
+ String materialName = dimensions.getString("ad_platform_material_name");
|
|
|
+
|
|
|
+ ByteDanceNewMaterialReport report = JSONObject.parseObject(metrics.toJSONString(), ByteDanceNewMaterialReport.class);
|
|
|
+ report.setAdvertiserId(token.getAccountId());
|
|
|
+ report.setMaterialId(materialId);
|
|
|
+ report.setStatDatetime(DateUtils.getDateInteger(dimensions.getString("stat_time_day")));
|
|
|
+ report.setCdpProjectId(projectId);
|
|
|
+ report.setCdpProjectName(projectName);
|
|
|
+ report.setPromotionId(promotionId);
|
|
|
+ report.setPromotionName(promotionName);
|
|
|
+ report.setAdPlatformMaterialName(materialName);
|
|
|
+ if (!Check.isNull(imageMode) && imageMode.contains("视频")) {
|
|
|
+ videolist.add(report);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(imageMode) && imageMode.contains("图")) {
|
|
|
+ imageList.add(report);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!Check.isNull(videolist)) {
|
|
|
+ bytedanceAdvertiserReportDailyMapper.insertV3PromotionProjectVideo(videolist);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(imageList)) {
|
|
|
+ bytedanceAdvertiserReportDailyMapper.insertV3PromotionProjectImage(imageList);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.info("获取V3 素材数据错误:", e.toString());
|
|
|
+ }
|
|
|
+ page++;
|
|
|
+
|
|
|
+ int totalPage = result.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
|
|
|
+ if (page <= totalPage) {
|
|
|
+ getV3PromotionMaterialReportByPage(token, conditions, page);
|
|
|
+ }
|
|
|
}
|
|
|
}
|