|
@@ -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;
|
|
@@ -722,6 +723,7 @@ 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);
|
|
if (code != 200 && code != 1) {
|
|
if (code != 200 && code != 1) {
|
|
retry.setStatus(0);
|
|
retry.setStatus(0);
|
|
bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
|
|
bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
|
|
@@ -746,6 +748,7 @@ 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);
|
|
log.info("头条素材报表当前accountId为:{} {}~{}" , accountId, startDate,endDate);
|
|
@@ -758,8 +761,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
|
|
|
// 请求地址
|
|
// 请求地址
|
|
String open_api_domain = "https://ad.oceanengine.com";
|
|
String open_api_domain = "https://ad.oceanengine.com";
|
|
- //String path = "/open_api/2/report/integrated/get/";
|
|
|
|
- String path = "/open_api/2/report/video/get/";
|
|
|
|
|
|
+ String path = "/open_api/2/report/integrated/get/";
|
|
|
|
|
|
// 请求参数
|
|
// 请求参数
|
|
Map data = new HashMap() {
|
|
Map data = new HashMap() {
|
|
@@ -769,7 +771,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
put("end_date", endDate);
|
|
put("end_date", endDate);
|
|
put("page", page);
|
|
put("page", page);
|
|
put("page_size", pageSize);
|
|
put("page_size", pageSize);
|
|
- put("group_by", new String[]{"STAT_GROUP_BY_MATERIAL_ID", "STAT_GROUP_BY_TIME_DAY"});
|
|
|
|
|
|
+ put("group_by", new String[]{"STAT_GROUP_BY_MATERIAL_ID", "STAT_GROUP_BY_INVENTORY", "STAT_GROUP_BY_IMAGE_MODE", "STAT_GROUP_BY_TIME_DAY"});
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
@@ -942,4 +944,120 @@ 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);
|
|
|
|
+ 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";
|
|
|
|
+ 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为:" + JSONObject.toJSONString(data));
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ JSONObject jsonData = json.getJSONObject("data");
|
|
|
|
+ if (Check.isNull(jsonData)) {
|
|
|
|
+ log.error("获取任务列表返回信息data内容为空,头条accountId:" + accountId + ";返回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);
|
|
|
|
+ //returnCode = 1;
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<BytedanceReportVideoMaterialDaily> bytedanceReportVideoMaterialDailyList = 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)) {
|
|
|
|
+ BytedanceReportVideoMaterialDaily daily = new BytedanceReportVideoMaterialDaily(detailJson, accountId);
|
|
|
|
+
|
|
|
|
+ bytedanceReportVideoMaterialDailyList.add(daily);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //Long insertStartTime = System.currentTimeMillis();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ bytedanceReportMaterialDailyMapper.replaceIntoBatch(bytedanceReportVideoMaterialDailyList);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //Long insertEndTime = System.currentTimeMillis();
|
|
|
|
+ //log.info("头条获取素材报表插入数据结束,执行耗时:{}秒", (insertEndTime - insertStartTime) / 1000);
|
|
|
|
+ if (currentPage >= totalPage) {
|
|
|
|
+ //log.info("accountId:" + accountId + "数据同步完成,开始时间:" + startDate + ",结束时间:"+ endDate);
|
|
|
|
+ return 1;
|
|
|
|
+ } else {
|
|
|
|
+ int pageCode = bytedanceVideoMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
|
|
|
|
+ return pageCode;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //returnCode = -1;
|
|
|
|
+ log.error("服务器返回为空,json:" + JSONObject.toJSONString(data));
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ log.error("头条报表其他错误,accountId:" + accountId + ",json:" + JSONObject.toJSONString(data));
|
|
|
|
+ returnCode = -3;
|
|
|
|
+ }
|
|
|
|
+ return returnCode;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|