|
@@ -9,6 +9,7 @@ import cn.com.ctop.common.module.utils.LoadFileUtil;
|
|
import cn.com.ctop.toutiao.modules.report.entity.BytedanceDailyReportTask;
|
|
import cn.com.ctop.toutiao.modules.report.entity.BytedanceDailyReportTask;
|
|
import cn.com.ctop.toutiao.modules.report.entity.BytedanceReportMaterialDaily;
|
|
import cn.com.ctop.toutiao.modules.report.entity.BytedanceReportMaterialDaily;
|
|
import cn.com.ctop.toutiao.modules.report.entity.BytedanceReportMaterialRetry;
|
|
import cn.com.ctop.toutiao.modules.report.entity.BytedanceReportMaterialRetry;
|
|
|
|
+import cn.com.ctop.toutiao.modules.report.entity.BytedanceReportVideoMaterialDaily;
|
|
import cn.com.ctop.toutiao.modules.report.mapper.BytedanceAdvertiserDailyReportMapper;
|
|
import cn.com.ctop.toutiao.modules.report.mapper.BytedanceAdvertiserDailyReportMapper;
|
|
import cn.com.ctop.toutiao.modules.report.mapper.BytedanceDailyReportTaskMapper;
|
|
import cn.com.ctop.toutiao.modules.report.mapper.BytedanceDailyReportTaskMapper;
|
|
import cn.com.ctop.toutiao.modules.report.mapper.BytedanceReportMapper;
|
|
import cn.com.ctop.toutiao.modules.report.mapper.BytedanceReportMapper;
|
|
@@ -710,18 +711,25 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
/////////////////////////////////////////////////////////\
|
|
/////////////////////////////////////////////////////////\
|
|
//素材报表
|
|
//素材报表
|
|
@Override
|
|
@Override
|
|
- public int bytedanceMaterialReportRetry(CtopOauthToken token, String startDate, String endDate) {
|
|
|
|
|
|
+ public int bytedanceMaterialReportRetry(Integer type, CtopOauthToken token, String startDate, String endDate) {
|
|
Long accountId = token.getAccountId();
|
|
Long accountId = token.getAccountId();
|
|
- // log.info("头条素材报表当前accountId为:" + accountId);
|
|
|
|
|
|
+ log.info("头条素材报表重试开始 当前accountId:{} {}~{},type:{}" , accountId, startDate,endDate,type);
|
|
Integer page = 1;
|
|
Integer page = 1;
|
|
Integer pageSize = 100;
|
|
Integer pageSize = 100;
|
|
- int code = bytedanceMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
|
|
|
|
|
|
+ Integer code = null;
|
|
|
|
+ if(type == 1){
|
|
|
|
+ code = bytedanceMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
|
|
|
|
+
|
|
|
|
+ }else if(type == 2){
|
|
|
|
+ code = bytedanceVideoMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
|
|
|
|
+ }
|
|
|
|
|
|
BytedanceReportMaterialRetry retry = new BytedanceReportMaterialRetry();
|
|
BytedanceReportMaterialRetry retry = new BytedanceReportMaterialRetry();
|
|
retry.setAccountId(accountId);
|
|
retry.setAccountId(accountId);
|
|
retry.setStartDate(startDate);
|
|
retry.setStartDate(startDate);
|
|
retry.setEndDate(endDate);
|
|
retry.setEndDate(endDate);
|
|
retry.setStatusCode(code);
|
|
retry.setStatusCode(code);
|
|
|
|
+ retry.setType(type);
|
|
if (code != 200 && code != 1) {
|
|
if (code != 200 && code != 1) {
|
|
retry.setStatus(0);
|
|
retry.setStatus(0);
|
|
bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
|
|
bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
|
|
@@ -729,13 +737,14 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
retry.setStatus(1);
|
|
retry.setStatus(1);
|
|
bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
|
|
bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
|
|
}
|
|
}
|
|
|
|
+ log.info("头条素材报表重试结束 当前accountId:{} {}~{},type:{},code:{}" , accountId, startDate,endDate,type,code);
|
|
return code;
|
|
return code;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public int bytedanceMaterialReport(CtopOauthToken token, String startDate, String endDate) {
|
|
public int bytedanceMaterialReport(CtopOauthToken token, String startDate, String endDate) {
|
|
Long accountId = token.getAccountId();
|
|
Long accountId = token.getAccountId();
|
|
- // log.info("头条素材报表当前accountId为:" + accountId);
|
|
|
|
|
|
+ log.info("头条素材报表开始 当前accountId:{} {}~{}" , accountId, startDate,endDate);
|
|
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);
|
|
@@ -746,8 +755,10 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
retry.setStartDate(startDate);
|
|
retry.setStartDate(startDate);
|
|
retry.setEndDate(endDate);
|
|
retry.setEndDate(endDate);
|
|
retry.setStatusCode(code);
|
|
retry.setStatusCode(code);
|
|
|
|
+ retry.setType(1);
|
|
bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
|
|
bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
|
|
}
|
|
}
|
|
|
|
+ log.info("头条素材报表结束 当前accountId为:{} {}~{}" , accountId, startDate,endDate);
|
|
return code;
|
|
return code;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -773,8 +784,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
|
|
|
JSONObject json = HttpUtils.bytedanceGetRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
|
|
JSONObject json = HttpUtils.bytedanceGetRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
|
|
if (json == null) {
|
|
if (json == null) {
|
|
- //insertMaterialRetry(accountId, startDate, endDate, -2);
|
|
|
|
- log.error("请求有误:" + JSONObject.toJSONString(data));
|
|
|
|
|
|
+ log.error("返回为空,请求有误:" + JSONObject.toJSONString(data));
|
|
return -2;
|
|
return -2;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -783,13 +793,13 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
if (!Check.isNull(json)) {
|
|
if (!Check.isNull(json)) {
|
|
Integer code = json.getInteger("code");
|
|
Integer code = json.getInteger("code");
|
|
if (code != 0) {
|
|
if (code != 0) {
|
|
- log.error("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + JSONObject.toJSONString(data));
|
|
|
|
|
|
+ log.error("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为" + json + "请求为:" + JSONObject.toJSONString(data));
|
|
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内容为空,头条accountId:" + accountId + ";返回json为:" + JSONObject.toJSONString(data));
|
|
|
|
|
|
+ log.error("获取任务列表返回信息data内容为空,头条accountId:" + accountId + ";返回json为" + json + "请求为:" + JSONObject.toJSONString(data));
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
JSONObject pageInfo = jsonData.getJSONObject("page_info");
|
|
JSONObject pageInfo = jsonData.getJSONObject("page_info");
|
|
@@ -799,7 +809,6 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
JSONArray jsonArrayay = jsonData.getJSONArray("list");
|
|
JSONArray jsonArrayay = jsonData.getJSONArray("list");
|
|
if (jsonArrayay.size() == 0) {
|
|
if (jsonArrayay.size() == 0) {
|
|
log.info("accountId:" + accountId + ";没有数据。总页数为:" + totalPage + "当前页数为:" + currentPage);
|
|
log.info("accountId:" + accountId + ";没有数据。总页数为:" + totalPage + "当前页数为:" + currentPage);
|
|
- //returnCode = 1;
|
|
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -911,19 +920,15 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
bytedanceReportMaterialDailyList.add(daily);
|
|
bytedanceReportMaterialDailyList.add(daily);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- //Long insertStartTime = System.currentTimeMillis();
|
|
|
|
bytedanceReportMaterialDailyMapper.replaceIntoBatch(bytedanceReportMaterialDailyList);
|
|
bytedanceReportMaterialDailyMapper.replaceIntoBatch(bytedanceReportMaterialDailyList);
|
|
- //Long insertEndTime = System.currentTimeMillis();
|
|
|
|
- //log.info("头条获取素材报表插入数据结束,执行耗时:{}秒", (insertEndTime - insertStartTime) / 1000);
|
|
|
|
if (currentPage >= totalPage) {
|
|
if (currentPage >= totalPage) {
|
|
- //log.info("accountId:" + accountId + "数据同步完成,开始时间:" + startDate + ",结束时间:"+ endDate);
|
|
|
|
|
|
+ log.info("头条素材报表当前accountId为:{} {}~{},接口数据拉取成功" , accountId, startDate,endDate);
|
|
return 1;
|
|
return 1;
|
|
} else {
|
|
} else {
|
|
int pageCode = bytedanceMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
|
|
int pageCode = bytedanceMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
|
|
return pageCode;
|
|
return pageCode;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- //returnCode = -1;
|
|
|
|
log.error("服务器返回为空,json:" + JSONObject.toJSONString(data));
|
|
log.error("服务器返回为空,json:" + JSONObject.toJSONString(data));
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
@@ -940,4 +945,107 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
return bytedanceReportMaterialDailyMapper.getRetryList();
|
|
return bytedanceReportMaterialDailyMapper.getRetryList();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 头条视频素材报表
|
|
|
|
+ * @param token
|
|
|
|
+ * @param startDate
|
|
|
|
+ * @param endDate
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public int bytedanceVideoMaterialReport(CtopOauthToken token, String startDate, String endDate) {
|
|
|
|
+ Long accountId = token.getAccountId();
|
|
|
|
+ log.info("头条素材报表当前accountId为:{} {}~{},开始" , accountId, startDate,endDate);
|
|
|
|
+ Integer page = 1;
|
|
|
|
+ Integer pageSize = 100;
|
|
|
|
+ int code = bytedanceVideoMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
|
|
|
|
+ if (code != 200 && code != 1) {
|
|
|
|
+ BytedanceReportMaterialRetry retry = new BytedanceReportMaterialRetry();
|
|
|
|
+ retry.setAccountId(accountId);
|
|
|
|
+ retry.setStatus(0);
|
|
|
|
+ retry.setStartDate(startDate);
|
|
|
|
+ retry.setEndDate(endDate);
|
|
|
|
+ retry.setStatusCode(code);
|
|
|
|
+ retry.setType(2); //1素材报表重试,2视频素材报表重试
|
|
|
|
+ bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
|
|
|
|
+ }
|
|
|
|
+ log.info("头条素材报表当前accountId为:{} {}~{},结束" , accountId, startDate,endDate);
|
|
|
|
+ return code;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private int bytedanceVideoMaterialReportByPage(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/video/get/";
|
|
|
|
+
|
|
|
|
+ // 请求参数
|
|
|
|
+ Map data = new HashMap();
|
|
|
|
+ data.put("advertiser_id", accountId);
|
|
|
|
+ data.put("start_date", startDate);
|
|
|
|
+ data.put("end_date", endDate);
|
|
|
|
+ data.put("page", page);
|
|
|
|
+ data.put("page_size", pageSize);
|
|
|
|
+ data.put("group_by", new String[]{"STAT_GROUP_BY_MATERIAL_ID", "STAT_GROUP_BY_TIME_DAY"});
|
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
+ try {
|
|
|
|
+ if (!Check.isNull(json)) {
|
|
|
|
+ Integer code = json.getInteger("code");
|
|
|
|
+ if (code != 0) {
|
|
|
|
+ log.error("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + json + "请求为:" + JSONObject.toJSONString(data));
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ JSONObject jsonData = json.getJSONObject("data");
|
|
|
|
+ if (Check.isNull(jsonData)) {
|
|
|
|
+ log.error("获取任务列表返回信息data内容为空,头条accountId:" + accountId + ";返回json为:" + json + "请求为:" + JSONObject.toJSONString(data));
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ JSONObject pageInfo = jsonData.getJSONObject("page_info");
|
|
|
|
+ Integer totalPage = pageInfo.getInteger("total_page");
|
|
|
|
+ Integer currentPage = pageInfo.getInteger("page");
|
|
|
|
+
|
|
|
|
+ JSONArray jsonArrayay = jsonData.getJSONArray("list");
|
|
|
|
+ if (jsonArrayay.size() == 0) {
|
|
|
|
+ log.info("accountId:" + accountId + ";没有数据。总页数为:" + totalPage + "当前页数为:" + currentPage);
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<BytedanceReportVideoMaterialDaily> bytedanceReportVideoMaterialDailyList = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < jsonArrayay.size(); i++) {
|
|
|
|
+ JSONObject detailJson = jsonArrayay.getJSONObject(i);
|
|
|
|
+ if (!Check.isNull(detailJson)) {
|
|
|
|
+ BytedanceReportVideoMaterialDaily daily = new BytedanceReportVideoMaterialDaily(detailJson, accountId);
|
|
|
|
+ bytedanceReportVideoMaterialDailyList.add(daily);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ bytedanceReportMaterialDailyMapper.replaceIntoVideoMaterialBatch(bytedanceReportVideoMaterialDailyList);
|
|
|
|
+ if (currentPage >= totalPage) {
|
|
|
|
+ log.info("头条视频素材报表当前accountId为:{} {}~{},接口数据拉取成功" , accountId, startDate,endDate);
|
|
|
|
+ return 1;
|
|
|
|
+ } else {
|
|
|
|
+ return bytedanceVideoMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ log.error("头条视频素材报表服务器返回为空,accountId:" + accountId + ",json:" + json + "请求为:" + JSONObject.toJSONString(data));
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ log.error("头条视频素材报表其他错误,accountId:" + accountId + ",json:" + json + "请求为:" + JSONObject.toJSONString(data));
|
|
|
|
+ returnCode = -3;
|
|
|
|
+ }
|
|
|
|
+ return returnCode;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|