|
|
@@ -15,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
import java.time.Instant;
|
|
|
import java.util.*;
|
|
|
|
|
|
@@ -150,7 +151,7 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
for (int i = 0; i < array.size(); i++) {
|
|
|
JSONObject jsonObject = array.getJSONObject(i);
|
|
|
Long projectId = jsonObject.getLong("project_id");
|
|
|
- if (projectId == null){
|
|
|
+ if (projectId == null) {
|
|
|
insertErrorLog(isLog, advertiserId, "-", "-", "promotion_list", "bytedance_promotion_list字段缺失 " + results);
|
|
|
log.info("bytedance_promotion_list 检测到字段缺失,跳过入库:{}", jsonObject);
|
|
|
continue;
|
|
|
@@ -203,7 +204,7 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
entity.put("app_id", miniProgramInfo.getString("app_id"));
|
|
|
entity.put("url", miniProgramInfo.getString("url"));
|
|
|
}
|
|
|
- if(!Check.isNull(playletSeriesUrlList)){
|
|
|
+ if (!Check.isNull(playletSeriesUrlList)) {
|
|
|
try {
|
|
|
JSONArray playletUrlArr = JSONObject.parseArray(playletSeriesUrlList);
|
|
|
String playletUrl = playletUrlArr.getString(0);
|
|
|
@@ -230,7 +231,7 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
log.error("广告({})playlet_series_url_list字段解析失败", entity.getString("promotion_id"));
|
|
|
}
|
|
|
}
|
|
|
@@ -242,7 +243,6 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public void getProjectList(Long advertiserId, JSONArray ids, String type, String date, Long errorId, Integer isLog) {
|
|
|
this.getProjectListVo(advertiserId, ids, type, date, 1, 1, errorId, isLog);
|
|
|
@@ -329,6 +329,92 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void getUniProjectList(Long advertiserId, JSONArray ids, String name, String statusFirst, String statusSecond, Long errorId, Integer isLog) {
|
|
|
+ this.getUniProjectListVo(advertiserId, ids, name, statusFirst, statusSecond, 1, 1, errorId, isLog);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getUniProjectListVo(Long advertiserId, JSONArray ids, String name, String statusFirst, String statusSecond, Integer page, int count, Long errorId, Integer isLog) {
|
|
|
+ try {
|
|
|
+ boolean nextPage = false;
|
|
|
+ JSONObject authConfig = tokenMapper.getAuthConfig(advertiserId);
|
|
|
+ if (Check.isNull(authConfig)) {
|
|
|
+ log.error("账户({})查询token失败", advertiserId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String accessToken = authConfig.getString("access_token");
|
|
|
+ String devAppId = authConfig.getString("app_id");
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("advertiser_id", advertiserId);
|
|
|
+ JSONObject filtering = new JSONObject();
|
|
|
+ if (!Check.isNull(ids)) {
|
|
|
+ filtering.put("project_id", ids);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(name)) {
|
|
|
+ filtering.put("name", name);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(statusFirst)) {
|
|
|
+ filtering.put("status_first", statusFirst);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(statusSecond)) {
|
|
|
+ filtering.put("status_second", statusSecond);
|
|
|
+ }
|
|
|
+ params.put("filtering", filtering);
|
|
|
+ params.put("page", page);
|
|
|
+ params.put("page_size", 100);//最大100
|
|
|
+ String url = "https://api.oceanengine.com/open_api/v3.0/uni_project_list/get/";
|
|
|
+ String results = null;
|
|
|
+ if (rateLimitUtil.acquire(devAppId, url)) {
|
|
|
+ results = HttpUtils.httpGet(url, params, HttpUtils.postMHeaders(accessToken));
|
|
|
+ }
|
|
|
+ JSONObject obj = JSONObject.parseObject(results);
|
|
|
+ if (!Check.isNull(obj)) {
|
|
|
+ Integer code = obj.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject data = obj.getJSONObject("data");
|
|
|
+ Integer totalPage = data.getJSONObject("page_info").getInteger("total_page");
|
|
|
+ if (totalPage != 0 && totalPage > data.getJSONObject("page_info").getInteger("page")) {
|
|
|
+ nextPage = true;
|
|
|
+ }
|
|
|
+ JSONArray array = data.getJSONArray("list");
|
|
|
+ for (int i = 0; i < array.size(); i++) {
|
|
|
+ JSONObject jsonObject = array.getJSONObject(i);
|
|
|
+ Long projectId = jsonObject.getLong("project_id");
|
|
|
+ if (projectId == null) {
|
|
|
+ insertErrorLog(isLog, advertiserId, "-", "-", "uni_project_list", "bytedance_uni_project_list字段缺失 " + results);
|
|
|
+ log.info("bytedance_uni_project_list 检测到字段缺失,跳过入库:{}", jsonObject);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ jsonObject.put("advertiser_id", advertiserId);
|
|
|
+ dorisLoadManager.add("media_api", "bytedance_uni_project_list", jsonObject);
|
|
|
+ }
|
|
|
+ log.info("---账户({})全域投放项目列表第{}页更新成功", advertiserId, page);
|
|
|
+ } else {
|
|
|
+ if (count <= 5 && code != 40110) {
|
|
|
+ Thread.sleep(800);
|
|
|
+ getUniProjectListVo(advertiserId, ids, name, statusFirst, statusSecond, page, count + 1, errorId, isLog);
|
|
|
+ } else {
|
|
|
+ insertErrorLog(isLog, advertiserId, "-", "-", "uni_project_list", results);
|
|
|
+ log.error("获取全域投放项目列表失败(url:{}),入参:{}\n结果:{}", url, JSONObject.toJSONString(params), obj);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ insertErrorLog(isLog, advertiserId, "-", "-", "uni_project_list", results);
|
|
|
+ log.error("获取全域投放项目列表失败(url:{}),入参:{}\n结果:{}", url, JSONObject.toJSONString(params), obj);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (nextPage) {
|
|
|
+ getUniProjectListVo(advertiserId, ids, name, statusFirst, statusSecond, page + 1, 1, errorId, isLog);
|
|
|
+ } else if (errorId != null) {
|
|
|
+ promoterReportMapper.deleteInfoByErrorId(errorId);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public void getByteAppInfo(Long advertiserId) {
|
|
|
this.getByteAppInfoVo(advertiserId, "CREATE_ONLY", 1, 1);
|
|
|
this.getByteAppInfoVo(advertiserId, "SHARE_ONLY", 1, 1);
|
|
|
@@ -357,7 +443,7 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
//获取微信小程序列表
|
|
|
String url = "https://api.oceanengine.com/open_api/v3.0/tools/micro_app/list/";
|
|
|
JSONObject obj = null;
|
|
|
- if(rateLimitUtil.acquire(devAppId, url)) {
|
|
|
+ if (rateLimitUtil.acquire(devAppId, url)) {
|
|
|
obj = Okhttp3Utils.bytedanceGetRequest(accessToken, url, params);
|
|
|
}
|
|
|
if (!Check.isNull(obj)) {
|
|
|
@@ -382,7 +468,7 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
bytedanceCdpProjectMapper.insertErrorAdvertiserId(advertiserId, "tt");
|
|
|
}
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
log.error("账户({})获取抖小列表失败,入参:{}\n结果:{}", advertiserId, JSONObject.toJSONString(params), obj);
|
|
|
bytedanceCdpProjectMapper.insertErrorAdvertiserId(advertiserId, "tt");
|
|
|
return;
|
|
|
@@ -425,7 +511,7 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
//获取微信小程序列表
|
|
|
String url = "https://api.oceanengine.com/open_api/v3.0/tools/asset_link/list/";
|
|
|
JSONObject obj = null;
|
|
|
- if(rateLimitUtil.acquire(devAppId, url)) {
|
|
|
+ if (rateLimitUtil.acquire(devAppId, url)) {
|
|
|
obj = Okhttp3Utils.bytedanceGetRequest(accessToken, url, params);
|
|
|
}
|
|
|
if (!Check.isNull(obj)) {
|
|
|
@@ -499,7 +585,7 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
//获取微信小程序列表
|
|
|
String url = "https://api.oceanengine.com/open_api/v3.0/tools/wechat_applet/list/";
|
|
|
JSONObject obj = null;
|
|
|
- if(rateLimitUtil.acquire(devAppId, url)) {
|
|
|
+ if (rateLimitUtil.acquire(devAppId, url)) {
|
|
|
obj = Okhttp3Utils.bytedanceGetRequest(accessToken, url, params);
|
|
|
}
|
|
|
if (!Check.isNull(obj)) {
|
|
|
@@ -884,7 +970,142 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void getOcProjectMaterial(Long advertiserId, Long projectId, Long errorId, Integer isLog) {
|
|
|
+ String[] materialTypes = {"VIDEO", "TITLE", "IMAGE", "CAROUSEL", "TRIAL_PLAY_MATERIAL", "INSTANT_PLAY_MATERIAL", "MINI_PROGRAM_INFO", "OTHER"};
|
|
|
+ for (String materialType : materialTypes) {
|
|
|
+ this.getOcProjectMaterialVo(advertiserId, projectId, materialType, 1, 1, errorId, isLog);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getOcProjectMaterial(String materialType, Long advertiserId, Long projectId, Long errorId, Integer isLog) {
|
|
|
+ this.getOcProjectMaterialVo(advertiserId, projectId, materialType, 1, 1, errorId, isLog);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getOcProjectMaterialVo(Long advertiserId, Long projectId, String materialType, Integer page, int count, Long errorId, Integer isLog) {
|
|
|
+ try {
|
|
|
+ boolean hasNextPage = false;
|
|
|
+ JSONObject authConfig = tokenMapper.getAuthConfig(advertiserId);
|
|
|
+ if (Check.isNull(authConfig)) {
|
|
|
+ log.error("账户({})查询token失败", advertiserId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String accessToken = authConfig.getString("access_token");
|
|
|
+ String devAppId = authConfig.getString("app_id");
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("advertiser_id", advertiserId);
|
|
|
+ params.put("project_id", projectId);
|
|
|
+ JSONObject filtering = new JSONObject();
|
|
|
+ filtering.put("material_type", materialType);
|
|
|
+ params.put("filtering", filtering);
|
|
|
+ // page/page_size 仅 VIDEO/IMAGE/CAROUSEL/TRIAL_PLAY_MATERIAL 时支持传入
|
|
|
+ if ("VIDEO".equals(materialType) || "IMAGE".equals(materialType) || "CAROUSEL".equals(materialType) || "TRIAL_PLAY_MATERIAL".equals(materialType)) {
|
|
|
+ params.put("page", page);
|
|
|
+ if ("VIDEO".equals(materialType)) {
|
|
|
+ params.put("page_size", 100);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String url = "https://api.oceanengine.com/open_api/v3.0/oc_project/material/get/";
|
|
|
+ String results = null;
|
|
|
+ if (rateLimitUtil.acquire(devAppId, url)) {
|
|
|
+ results = HttpUtils.httpGet(url, params, HttpUtils.postMHeaders(accessToken));
|
|
|
+ }
|
|
|
+ JSONObject obj = JSONObject.parseObject(results);
|
|
|
+ if (!Check.isNull(obj)) {
|
|
|
+ Integer code = obj.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject data = obj.getJSONObject("data");
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
+ JSONObject pageInfo = data.getJSONObject("page_info");
|
|
|
+ if (!Check.isNull(pageInfo)) {
|
|
|
+ Integer totalPage = pageInfo.getInteger("total_page");
|
|
|
+ if (totalPage != null && totalPage != 0 && totalPage > pageInfo.getInteger("page")) {
|
|
|
+ hasNextPage = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ processMaterialResponse(data, advertiserId, projectId, materialType);
|
|
|
+ log.info("---账户({})项目({})素材类型({})第{}页获取成功", advertiserId, projectId, materialType, page);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (count <= 5 && code != 40110) {
|
|
|
+ Thread.sleep(800);
|
|
|
+ getOcProjectMaterialVo(advertiserId, projectId, materialType, page, count + 1, errorId, isLog);
|
|
|
+ } else {
|
|
|
+ insertErrorLog(isLog, advertiserId, "-", "-", "uni_project_material",
|
|
|
+ new JSONObject()
|
|
|
+ .fluentPut("material_type", materialType)
|
|
|
+ .fluentPut("results", results)
|
|
|
+ .fluentPut("project_id", projectId).toJSONString());
|
|
|
+ log.error("获取投放项目下素材失败(url:{}),入参:{}\n结果:{}", url, JSONObject.toJSONString(params), obj);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ insertErrorLog(isLog, advertiserId, "-", "-", "uni_project_material", new JSONObject()
|
|
|
+ .fluentPut("material_type", materialType)
|
|
|
+ .fluentPut("results", results)
|
|
|
+ .fluentPut("project_id", projectId).toJSONString());
|
|
|
+ log.error("获取投放项目下素材失败(url:{}),入参:{}\n结果:{}", url, JSONObject.toJSONString(params), obj);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (hasNextPage) {
|
|
|
+ getOcProjectMaterialVo(advertiserId, projectId, materialType, page + 1, 1, errorId, isLog);
|
|
|
+ } else if (errorId != null) {
|
|
|
+ promoterReportMapper.deleteInfoByErrorId(errorId);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void processMaterialResponse(JSONObject data, Long advertiserId, Long projectId, String materialType) {
|
|
|
+ data.put("advertiser_id", advertiserId);
|
|
|
+ data.put("project_id", projectId);
|
|
|
+ if (materialType.equals("OTHER")) {
|
|
|
+ JSONArray playletSeriesUrlInfo = data.getJSONArray("playlet_series_url_info");
|
|
|
+ if (!Check.isNull(playletSeriesUrlInfo)) {
|
|
|
+ for (int i = 0; i < playletSeriesUrlInfo.size(); i++) {
|
|
|
+ JSONObject item = playletSeriesUrlInfo.getJSONObject(i);
|
|
|
+ // 获取 playlet_series_url_type
|
|
|
+ String playletSeriesUrlType = item.getString("playlet_series_url_type");
|
|
|
+ if (StringUtils.isNotBlank(playletSeriesUrlType)) {
|
|
|
+ // 解析 advertise_param 并 base64 解码,获取 media_id
|
|
|
+ String playletSeriesUrl = item.getString("playlet_series_url");
|
|
|
+ if (StringUtils.isNotBlank(playletSeriesUrl)) {
|
|
|
+ String playletId = HttpUtils.extractQueryParam(playletSeriesUrl, "playlet_id");
|
|
|
+ data.put(playletSeriesUrlType.toLowerCase() + "_playlet_id", playletId);
|
|
|
+ String advertiseParam = HttpUtils.extractQueryParam(playletSeriesUrl, "advertise_param");
|
|
|
+ if (StringUtils.isNotBlank(advertiseParam)) {
|
|
|
+ try {
|
|
|
+ String decodedParam = new String(Base64.getDecoder().decode(advertiseParam), "UTF-8");
|
|
|
+ JSONObject advertiseObj = JSONObject.parseObject(decodedParam);
|
|
|
+ if (!Check.isNull(advertiseObj)) {
|
|
|
+ Long mediaId = advertiseObj.getLong("media_id");
|
|
|
+ if (mediaId != null) {
|
|
|
+ data.put(playletSeriesUrlType.toLowerCase() + "_account_mid", mediaId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("账户({})项目({})advertise_param base64解码失败: {}", advertiserId, projectId, advertiseParam);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dorisLoadManager.add("media_api", "bytedance_oc_project_material_other", data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private void insertErrorLog(Integer isLog, Long advertiserId, String startDate, String endDate, String dataDimension, String msg) {
|
|
|
+ insertErrorLog(isLog, advertiserId, startDate, endDate, dataDimension, msg, "daily");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void insertErrorLog(Integer isLog, Long advertiserId, String startDate, String endDate, String dataDimension, String msg, String dataType) {
|
|
|
if (isLog != null && 1 == isLog) {
|
|
|
BytedanceErrorLog errorInfo = new BytedanceErrorLog();
|
|
|
errorInfo.setAdvertiserId(advertiserId);
|
|
|
@@ -892,7 +1113,7 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
errorInfo.setEndDate(endDate);
|
|
|
errorInfo.setMsg(msg);
|
|
|
errorInfo.setDataDimension(dataDimension);
|
|
|
- errorInfo.setDataType("daily");
|
|
|
+ errorInfo.setDataType(dataType);
|
|
|
promoterReportMapper.replaceErrorInfo(errorInfo);
|
|
|
}
|
|
|
}
|