|
@@ -1,6 +1,8 @@
|
|
|
package cn.com.ctop.job.bytedance.data.service.impl;
|
|
package cn.com.ctop.job.bytedance.data.service.impl;
|
|
|
|
|
|
|
|
import cn.com.ctop.job.bytedance.data.entity.BytedanceErrorLog;
|
|
import cn.com.ctop.job.bytedance.data.entity.BytedanceErrorLog;
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.BytedanceMaterialReportDaily;
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.mapper.BytedanceMaterialReportMapper;
|
|
|
import cn.com.ctop.job.bytedance.data.mapper.BytedancePromoterReportMapper;
|
|
import cn.com.ctop.job.bytedance.data.mapper.BytedancePromoterReportMapper;
|
|
|
import cn.com.ctop.job.bytedance.data.mapper.BytedanceRefreshTokenMapper;
|
|
import cn.com.ctop.job.bytedance.data.mapper.BytedanceRefreshTokenMapper;
|
|
|
import cn.com.ctop.job.bytedance.data.service.IBytedanceMaterialReportService;
|
|
import cn.com.ctop.job.bytedance.data.service.IBytedanceMaterialReportService;
|
|
@@ -8,6 +10,7 @@ import cn.com.ctop.job.bytedance.data.utils.AlertUtils;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.FieldsConfig;
|
|
import cn.com.ctop.job.bytedance.data.utils.FieldsConfig;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.JsonUtils;
|
|
|
import cn.com.ctop.job.bytedance.utils.RateLimitUtil;
|
|
import cn.com.ctop.job.bytedance.utils.RateLimitUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -19,7 +22,6 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -27,21 +29,18 @@ public class BytedanceMaterialReportServiceImpl implements IBytedanceMaterialRep
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private BytedancePromoterReportMapper promoterReportMapper;
|
|
private BytedancePromoterReportMapper promoterReportMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private BytedanceRefreshTokenMapper tokenMapper;
|
|
|
|
|
|
|
+ private BytedanceMaterialReportMapper materialReportMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private RedisTemplate redisTemplate_db2;
|
|
|
|
|
|
|
+ private BytedanceRefreshTokenMapper tokenMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RateLimitUtil rateLimitUtil;
|
|
private RateLimitUtil rateLimitUtil;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private RedisTemplate redisTemplate_db2;
|
|
|
|
|
+ private static String devAppId = "1876837323659296"; // ByteDance Developer App ID
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void getBytedanceMaterialDailyReport(Long advertiserId, String startDate, String endDate, Integer page, Long errorId, Integer isLog, Integer isSend, int retry) {
|
|
|
|
|
|
|
+ public void getBytedanceMaterialDailyReport(Long advertiserId,String accessToken, String startDate, String endDate, Integer page, Long errorId, Integer isLog, Integer isSend, int retry) {
|
|
|
try {
|
|
try {
|
|
|
- JSONObject authConfig = tokenMapper.getAuthConfig(advertiserId);
|
|
|
|
|
- if (Check.isNull(authConfig)) {
|
|
|
|
|
- log.info("账户id:{},获取素材日报token为空", advertiserId);
|
|
|
|
|
- }
|
|
|
|
|
- String accessToken = authConfig.getString("access_token");
|
|
|
|
|
- String devAppId = authConfig.getString("app_id");
|
|
|
|
|
String url = "https://api.oceanengine.com/open_api/v3.0/report/custom/get/";
|
|
String url = "https://api.oceanengine.com/open_api/v3.0/report/custom/get/";
|
|
|
Map<String, Object> paramsMap = new HashMap<>();
|
|
Map<String, Object> paramsMap = new HashMap<>();
|
|
|
paramsMap.put("advertiser_id", advertiserId);
|
|
paramsMap.put("advertiser_id", advertiserId);
|
|
@@ -62,14 +61,15 @@ public class BytedanceMaterialReportServiceImpl implements IBytedanceMaterialRep
|
|
|
s = HttpUtils.httpGet(url, paramsMap, headers);
|
|
s = HttpUtils.httpGet(url, paramsMap, headers);
|
|
|
}
|
|
}
|
|
|
JSONObject result = JSONObject.parseObject(s);
|
|
JSONObject result = JSONObject.parseObject(s);
|
|
|
- Set<Long> materialIds = new HashSet<>();
|
|
|
|
|
|
|
+ List<BytedanceMaterialReportDaily> materialReportDailies = new ArrayList<>();
|
|
|
|
|
+ Set<Long> videoIds = new HashSet<>();
|
|
|
if (Check.isNull(result)) {
|
|
if (Check.isNull(result)) {
|
|
|
log.info("账户id:{},素材日报请求结果返回为空", advertiserId);
|
|
log.info("账户id:{},素材日报请求结果返回为空", advertiserId);
|
|
|
if (isLog == 1) {
|
|
if (isLog == 1) {
|
|
|
BytedanceErrorLog errorInfo = new BytedanceErrorLog();
|
|
BytedanceErrorLog errorInfo = new BytedanceErrorLog();
|
|
|
errorInfo.setAdvertiserId(advertiserId);
|
|
errorInfo.setAdvertiserId(advertiserId);
|
|
|
- errorInfo.setStartDate(startDate);
|
|
|
|
|
- errorInfo.setEndDate(endDate);
|
|
|
|
|
|
|
+ errorInfo.setStartDate(Check.isNull(startDate) ? "" : startDate);
|
|
|
|
|
+ errorInfo.setEndDate(Check.isNull(endDate) ? "" : endDate);
|
|
|
errorInfo.setDataDimension("material");
|
|
errorInfo.setDataDimension("material");
|
|
|
errorInfo.setDataType("daily");
|
|
errorInfo.setDataType("daily");
|
|
|
errorInfo.setMsg("请求结果返回为空");
|
|
errorInfo.setMsg("请求结果返回为空");
|
|
@@ -90,15 +90,23 @@ public class BytedanceMaterialReportServiceImpl implements IBytedanceMaterialRep
|
|
|
JSONObject metricsJson = rowJson.getJSONObject("metrics");
|
|
JSONObject metricsJson = rowJson.getJSONObject("metrics");
|
|
|
JSONObject dimensionsJson = rowJson.getJSONObject("dimensions");
|
|
JSONObject dimensionsJson = rowJson.getJSONObject("dimensions");
|
|
|
|
|
|
|
|
- dimensionsJson.putAll(metricsJson);
|
|
|
|
|
- dimensionsJson.put("stat_time_day", dimensionsJson.getString("stat_time_day").replace("-", ""));
|
|
|
|
|
- dimensionsJson.put("advertiser_id", advertiserId);
|
|
|
|
|
-
|
|
|
|
|
Long materialId = dimensionsJson.getLong("material_id");
|
|
Long materialId = dimensionsJson.getLong("material_id");
|
|
|
String imageMode = dimensionsJson.getString("image_mode");
|
|
String imageMode = dimensionsJson.getString("image_mode");
|
|
|
- if (!materialIds.contains(materialId) && imageMode.contains("视频") && !redisTemplate_db2.hasKey("mvid:1:" + materialId)) {
|
|
|
|
|
- materialIds.add(materialId);
|
|
|
|
|
|
|
+ // 标题素材行与视频素材行重复归因同一份消耗,剔除避免消耗统计翻倍
|
|
|
|
|
+ if (imageMode != null && imageMode.contains("标题")) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (imageMode != null && imageMode.contains("视频")) {
|
|
|
|
|
+ videoIds.add(materialId);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ BytedanceMaterialReportDaily materialReportDaily = JSONObject.parseObject(JsonUtils.normalizeMetrics(metricsJson).toJSONString(), BytedanceMaterialReportDaily.class);
|
|
|
|
|
+ materialReportDaily.setAdvertiserId(advertiserId);
|
|
|
|
|
+ materialReportDaily.setStatTimeDay(Integer.valueOf(dimensionsJson.getString("stat_time_day").replace("-", "")));
|
|
|
|
|
+ materialReportDaily.setMaterialId(materialId);
|
|
|
|
|
+ materialReportDaily.setImageMode(imageMode);
|
|
|
|
|
+ materialReportDaily.setMaterialName(dimensionsJson.getString("ad_platform_material_name"));
|
|
|
|
|
+ materialReportDailies.add(materialReportDaily);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -108,15 +116,15 @@ public class BytedanceMaterialReportServiceImpl implements IBytedanceMaterialRep
|
|
|
Thread.sleep(800);
|
|
Thread.sleep(800);
|
|
|
} catch (Exception ignored) {
|
|
} catch (Exception ignored) {
|
|
|
}
|
|
}
|
|
|
- getBytedanceMaterialDailyReport(advertiserId, startDate, endDate, page, errorId, isLog, isSend, retry + 1);
|
|
|
|
|
|
|
+ getBytedanceMaterialDailyReport(advertiserId, accessToken,startDate, endDate, page, errorId, isLog, isSend, retry + 1);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
log.info("账户id:{},日期:{}素材日报请求结果失败,返回数据:{}", advertiserId, startDate, result);
|
|
log.info("账户id:{},日期:{}素材日报请求结果失败,返回数据:{}", advertiserId, startDate, result);
|
|
|
if (isLog == 1) {
|
|
if (isLog == 1) {
|
|
|
BytedanceErrorLog errorInfo = new BytedanceErrorLog();
|
|
BytedanceErrorLog errorInfo = new BytedanceErrorLog();
|
|
|
errorInfo.setAdvertiserId(advertiserId);
|
|
errorInfo.setAdvertiserId(advertiserId);
|
|
|
- errorInfo.setStartDate(startDate);
|
|
|
|
|
- errorInfo.setEndDate(endDate);
|
|
|
|
|
|
|
+ errorInfo.setStartDate(Check.isNull(startDate) ? "" : startDate);
|
|
|
|
|
+ errorInfo.setEndDate(Check.isNull(endDate) ? "" : endDate);
|
|
|
errorInfo.setDataDimension("material");
|
|
errorInfo.setDataDimension("material");
|
|
|
errorInfo.setDataType("daily");
|
|
errorInfo.setDataType("daily");
|
|
|
errorInfo.setMsg(result.getString("message"));
|
|
errorInfo.setMsg(result.getString("message"));
|
|
@@ -125,12 +133,13 @@ public class BytedanceMaterialReportServiceImpl implements IBytedanceMaterialRep
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!Check.isNull(materialIds)) {
|
|
|
|
|
- getBytedanceMaterialVideo(advertiserId, materialIds, null, null, 1, null, 1, null, 1);
|
|
|
|
|
|
|
+ if (!Check.isNull(materialReportDailies)) {
|
|
|
|
|
+ fillVideoInfo(advertiserId, accessToken, videoIds, materialReportDailies);
|
|
|
|
|
+ materialReportMapper.replaceMaterialReportDailies(materialReportDailies);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (page < totalPage) {
|
|
if (page < totalPage) {
|
|
|
- getBytedanceMaterialDailyReport(advertiserId, startDate, endDate, page + 1, errorId, isLog, isSend, 1);
|
|
|
|
|
|
|
+ getBytedanceMaterialDailyReport(advertiserId, accessToken, startDate, endDate, page + 1, errorId, isLog, isSend, 1);
|
|
|
} else {
|
|
} else {
|
|
|
log.info("账户ID:{}, 开始日期:{}, 结束日期:{}, totalPage:{}, 素材日报数据请求成功", advertiserId, startDate, endDate, totalPage);
|
|
log.info("账户ID:{}, 开始日期:{}, 结束日期:{}, totalPage:{}, 素材日报数据请求成功", advertiserId, startDate, endDate, totalPage);
|
|
|
if (errorId != null) {
|
|
if (errorId != null) {
|
|
@@ -146,110 +155,81 @@ public class BytedanceMaterialReportServiceImpl implements IBytedanceMaterialRep
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void getBytedanceMaterialVideo(Long advertiserId, Set<Long> materialIds, String startTime, String endTime, Integer page, Long errorId, Integer isLog, Integer isSend, int retry) {
|
|
|
|
|
- try {
|
|
|
|
|
- JSONObject authConfig = tokenMapper.getAuthConfig(advertiserId);
|
|
|
|
|
- if (Check.isNull(authConfig) || authConfig.getString("access_token") == null) {
|
|
|
|
|
- log.info("账户id:{},获取视频素材token为空", advertiserId);
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 视频素材批量补充播放链接和封面图(每批最多100个),获取失败不影响指标数据落库
|
|
|
|
|
+ */
|
|
|
|
|
+ private void fillVideoInfo(Long advertiserId, String accessToken, Set<Long> videoIds, List<BytedanceMaterialReportDaily> materialReportDailies) {
|
|
|
|
|
+ if (Check.isNull(videoIds)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<Long, JSONObject> videoInfoMap = new HashMap<>();
|
|
|
|
|
+ // 优先从redis缓存取视频地址(以素材ID为key),取不到的再批量调接口
|
|
|
|
|
+ List<Long> missIds = new ArrayList<>();
|
|
|
|
|
+ for (Long materialId : videoIds) {
|
|
|
|
|
+ Object cache = redisTemplate_db2.opsForValue().get("mvid:info:" + materialId);
|
|
|
|
|
+ if (!Check.isNull(cache)) {
|
|
|
|
|
+ videoInfoMap.put(materialId, JSONObject.parseObject(cache.toString()));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ missIds.add(materialId);
|
|
|
}
|
|
}
|
|
|
- String accessToken = authConfig.getString("access_token");
|
|
|
|
|
- String devAppId = authConfig.getString("app_id");
|
|
|
|
|
-
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
String url = "https://api.oceanengine.com/open_api/2/file/video/get/";
|
|
String url = "https://api.oceanengine.com/open_api/2/file/video/get/";
|
|
|
- Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
- paramsMap.put("advertiser_id", advertiserId);
|
|
|
|
|
- JSONObject filtering = new JSONObject();
|
|
|
|
|
- if (!Check.isNull(startTime) && !Check.isNull(endTime)) {
|
|
|
|
|
- filtering.put("start_time", startTime);
|
|
|
|
|
- filtering.put("end_time", endTime);
|
|
|
|
|
- }
|
|
|
|
|
- if (!Check.isNull(materialIds)) {
|
|
|
|
|
- List<Long> collect = materialIds.stream().filter(id -> !redisTemplate_db2.hasKey("mvid:1:" + id)).collect(Collectors.toList());
|
|
|
|
|
- if (!Check.isNull(collect)) {
|
|
|
|
|
- filtering.put("material_ids", collect);
|
|
|
|
|
- } else {
|
|
|
|
|
- if (errorId != null) {
|
|
|
|
|
- promoterReportMapper.deleteInfoByErrorId(errorId);
|
|
|
|
|
- }
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ List<Long> materialIds = new ArrayList<>(missIds);
|
|
|
|
|
+ for (int i = 0; i < materialIds.size(); i += 100) {
|
|
|
|
|
+ List<Long> batch = materialIds.subList(i, Math.min(i + 100, materialIds.size()));
|
|
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
+ paramsMap.put("advertiser_id", advertiserId);
|
|
|
|
|
+ JSONObject filtering = new JSONObject();
|
|
|
|
|
+ filtering.put("material_ids", batch);
|
|
|
|
|
+ paramsMap.put("filtering", filtering);
|
|
|
|
|
+ paramsMap.put("page", 1);
|
|
|
|
|
+ paramsMap.put("page_size", 100);
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
|
|
+ String s = null;
|
|
|
|
|
+ if (rateLimitUtil.acquire(devAppId, url)) {
|
|
|
|
|
+ s = HttpUtils.httpGet(url, paramsMap, headers);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- paramsMap.put("filtering", filtering);
|
|
|
|
|
- paramsMap.put("page", page);
|
|
|
|
|
- paramsMap.put("page_size", 100);
|
|
|
|
|
- Map<String, String> headers = new HashMap<>();
|
|
|
|
|
- headers.put("Access-Token", accessToken);
|
|
|
|
|
- headers.put("Content-Type", "application/json");
|
|
|
|
|
- String s = null;
|
|
|
|
|
- if (rateLimitUtil.acquire(devAppId, url)) {
|
|
|
|
|
- s = HttpUtils.httpGet(url, paramsMap, headers);
|
|
|
|
|
- }
|
|
|
|
|
- JSONObject result = JSONObject.parseObject(s);
|
|
|
|
|
- if (Check.isNull(result)) {
|
|
|
|
|
- log.info("账户id:{},获取视频素材结果返回为空", advertiserId);
|
|
|
|
|
- if (isLog == 1) {
|
|
|
|
|
- BytedanceErrorLog errorInfo = new BytedanceErrorLog();
|
|
|
|
|
- errorInfo.setAdvertiserId(advertiserId);
|
|
|
|
|
- errorInfo.setStartDate(Check.isNull(startTime) ? "" : startTime);
|
|
|
|
|
- errorInfo.setEndDate(Check.isNull(endTime) ? "" : endTime);
|
|
|
|
|
- errorInfo.setDataDimension("material_video_get");
|
|
|
|
|
- errorInfo.setDataType("daily");
|
|
|
|
|
- errorInfo.setMsg(new JSONObject().fluentPut("msg", "结果为空").fluentPut("material_ids", materialIds).toJSONString());
|
|
|
|
|
- promoterReportMapper.replaceErrorInfo(errorInfo);
|
|
|
|
|
|
|
+ JSONObject result = JSONObject.parseObject(s);
|
|
|
|
|
+ if (Check.isNull(result) || result.getInteger("code") == null || result.getInteger("code") != 0) {
|
|
|
|
|
+ log.info("账户id:{},获取视频素材播放链接失败,返回数据:{}", advertiserId, result);
|
|
|
|
|
+ continue;
|
|
|
}
|
|
}
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- Integer code = result.getInteger("code");
|
|
|
|
|
- int totalPage = 1;
|
|
|
|
|
- if (code == 0) {
|
|
|
|
|
JSONObject data = result.getJSONObject("data");
|
|
JSONObject data = result.getJSONObject("data");
|
|
|
- if (!Check.isNull(data)) {
|
|
|
|
|
- totalPage = data.getJSONObject("page_info").getIntValue("total_page");
|
|
|
|
|
- JSONArray rows = data.getJSONArray("list");
|
|
|
|
|
- if (!Check.isNull(rows)) {
|
|
|
|
|
- for (int i = 0; i < rows.size(); i++) {
|
|
|
|
|
- JSONObject rowJson = rows.getJSONObject(i);
|
|
|
|
|
- String materialId = rowJson.getString("material_id");
|
|
|
|
|
- redisTemplate_db2.opsForValue().set("mvid:1:" + materialId, materialId, Duration.ofSeconds(30 * 24 * 3600 + (int) (Math.random() * 7200)));
|
|
|
|
|
- rowJson.put("advertiser_id", advertiserId);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (Check.isNull(data) || Check.isNull(data.getJSONArray("list"))) {
|
|
|
|
|
+ continue;
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- if (retry <= 5 && code != 40110) {
|
|
|
|
|
- try {
|
|
|
|
|
- Thread.sleep(800);
|
|
|
|
|
- } catch (Exception ignored) {
|
|
|
|
|
- }
|
|
|
|
|
- getBytedanceMaterialVideo(advertiserId, materialIds, startTime, endTime, page, errorId, isLog, isSend, retry + 1);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- log.info("账户id:{},日期:{}获取视频素材失败,返回数据:{}", advertiserId, startTime, result);
|
|
|
|
|
- if (isLog == 1) {
|
|
|
|
|
- BytedanceErrorLog errorInfo = new BytedanceErrorLog();
|
|
|
|
|
- errorInfo.setAdvertiserId(advertiserId);
|
|
|
|
|
- errorInfo.setStartDate(Check.isNull(startTime) ? "" : startTime);
|
|
|
|
|
- errorInfo.setEndDate(Check.isNull(endTime) ? "" : endTime);
|
|
|
|
|
- errorInfo.setDataDimension("material_video_get");
|
|
|
|
|
- errorInfo.setDataType("daily");
|
|
|
|
|
- errorInfo.setMsg(result.fluentPut("material_ids", materialIds).toJSONString());
|
|
|
|
|
- promoterReportMapper.replaceErrorInfo(errorInfo);
|
|
|
|
|
- }
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- if (page < totalPage) {
|
|
|
|
|
- getBytedanceMaterialVideo(advertiserId, materialIds, startTime, endTime, page + 1, errorId, isLog, isSend, 1);
|
|
|
|
|
- } else {
|
|
|
|
|
- log.info("账户ID:{}, 开始日期:{}, 结束日期:{}, totalPage:{}, 获取视频素材成功", advertiserId, startTime, endTime, totalPage);
|
|
|
|
|
- if (errorId != null) {
|
|
|
|
|
- promoterReportMapper.deleteInfoByErrorId(errorId);
|
|
|
|
|
- }
|
|
|
|
|
- if (isSend != null && 1 == isSend) {
|
|
|
|
|
- AlertUtils.sendMessage(advertiserId, startTime, endTime, 1, "material", 1, null);
|
|
|
|
|
|
|
+ JSONArray list = data.getJSONArray("list");
|
|
|
|
|
+ for (int j = 0; j < list.size(); j++) {
|
|
|
|
|
+ JSONObject rowJson = list.getJSONObject(j);
|
|
|
|
|
+ Long materialId = rowJson.getLong("material_id");
|
|
|
|
|
+ // 接口实际返回字段:url=播放地址,poster_url=封面图
|
|
|
|
|
+ String videoUrl = Check.isNull(rowJson.getString("url")) ? rowJson.getString("video_url") : rowJson.getString("url");
|
|
|
|
|
+ String coverImageUrl = Check.isNull(rowJson.getString("poster_url")) ? rowJson.getString("cover_image_url") : rowJson.getString("poster_url");
|
|
|
|
|
+ rowJson.put("video_url", videoUrl);
|
|
|
|
|
+ rowJson.put("cover_image_url", coverImageUrl);
|
|
|
|
|
+ videoInfoMap.put(materialId, rowJson);
|
|
|
|
|
+ // 缓存视频和封面地址,30天+随机0~2小时过期
|
|
|
|
|
+ JSONObject cacheJson = new JSONObject();
|
|
|
|
|
+ cacheJson.put("video_url", videoUrl);
|
|
|
|
|
+ cacheJson.put("cover_image_url", coverImageUrl);
|
|
|
|
|
+ redisTemplate_db2.opsForValue().set("mvid:info:" + materialId, cacheJson.toJSONString(), Duration.ofSeconds(30 * 24 * 3600 + (int) (Math.random() * 7200)));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
|
+ log.error("账户id:{},获取视频素材播放链接异常", advertiserId, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Check.isNull(videoInfoMap)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (BytedanceMaterialReportDaily reportDaily : materialReportDailies) {
|
|
|
|
|
+ JSONObject videoInfo = videoInfoMap.get(reportDaily.getMaterialId());
|
|
|
|
|
+ if (!Check.isNull(videoInfo)) {
|
|
|
|
|
+ reportDaily.setVideoUrl(videoInfo.getString("video_url"));
|
|
|
|
|
+ reportDaily.setCoverImageUrl(videoInfo.getString("cover_image_url"));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|