|
|
@@ -6,6 +6,7 @@ import cn.com.ctop.job.bytedance.data.mapper.BytedanceRefreshTokenMapper;
|
|
|
import cn.com.ctop.job.bytedance.data.service.IBytedanceCdpProjectService;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.Okhttp3Utils;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -43,12 +44,21 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void getProjectList(Long advertiserId, String type, Integer page) {
|
|
|
+ public List<Long> queryAdvertiserIds(String db, String date) {
|
|
|
+ return bytedanceCdpProjectMapper.queryAdvertiserIds(db, date);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getProjectList(Long advertiserId, String type, String date, Integer page) {
|
|
|
if (!Check.isNull(type))
|
|
|
log.info("--------执行:{}", advertiserId);
|
|
|
try {
|
|
|
boolean nextPage = false;
|
|
|
String accessToken = tokenMapper.onlyGetToken(advertiserId);
|
|
|
+ if (Check.isNull(accessToken)) {
|
|
|
+ log.error("账户({})查询token失败", advertiserId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("advertiser_id", advertiserId);
|
|
|
if (!Check.isNull(type)) {
|
|
|
@@ -84,7 +94,7 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
bytedanceCdpProjectMapper.insertErrorAdvertiserId(advertiserId);
|
|
|
}
|
|
|
if (nextPage) {
|
|
|
- getProjectList(advertiserId, type, page + 1);
|
|
|
+ getProjectList(advertiserId, type, date, page + 1);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
bytedanceCdpProjectMapper.insertErrorAdvertiserId(advertiserId);
|
|
|
@@ -93,4 +103,107 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void getByteAppInfo(Long advertiserId) {
|
|
|
+ this.getByteAppInfoVo(advertiserId, "CREATE_ONLY", 1, 1);
|
|
|
+ this.getByteAppInfoVo(advertiserId, "SHARE_ONLY", 1, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getByteAppInfoVo(Long advertiserId, String searchType, Integer page, int count) {
|
|
|
+ log.info("------执行{}", advertiserId);
|
|
|
+ boolean nextPage = false;
|
|
|
+ String accessToken = tokenMapper.onlyGetToken(advertiserId);
|
|
|
+ if (Check.isNull(accessToken)) {
|
|
|
+ log.error("账户({})查询token失败", advertiserId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ params.put("advertiser_id", advertiserId);
|
|
|
+ params.put("page", page);
|
|
|
+ //页面大小,默认值为10,最大值100
|
|
|
+ params.put("page_size", 100);
|
|
|
+ JSONObject filtering = new JSONObject();
|
|
|
+ //CREATE_ONLY本户创建,SHARE_ONLY 只查共享应用
|
|
|
+ filtering.put("search_type", searchType);
|
|
|
+// filtering.put("audit_status", "AUDIT_ACCEPTED");
|
|
|
+ params.put("filtering", filtering);
|
|
|
+ //获取微信小程序列表
|
|
|
+ String url = "https://api.oceanengine.com/open_api/v3.0/tools/micro_app/list/";
|
|
|
+ JSONObject obj = Okhttp3Utils.bytedanceGetRequest(accessToken, url, params);
|
|
|
+ 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 list = data.getJSONArray("list");
|
|
|
+ if (!Check.isNull(list)) {
|
|
|
+ bytedanceCdpProjectMapper.replaceBytedanceByteAppInfo(list, advertiserId);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //40110请求超频
|
|
|
+ if (40110 == code && count <= 3)
|
|
|
+ getByteAppInfoVo(advertiserId, searchType, page, count + 1);
|
|
|
+ log.error("账户{}获取字节小程序列表失败,入参:{}\n结果:{}", advertiserId, JSONObject.toJSONString(params), obj);
|
|
|
+ }
|
|
|
+ if (nextPage) {
|
|
|
+ getByteAppInfoVo(advertiserId, searchType, page + 1, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getWxAppInfo(Long advertiserId) {
|
|
|
+ this.getWxAppInfoVo(advertiserId, "CREATE_ONLY", 1, 1);
|
|
|
+ this.getWxAppInfoVo(advertiserId, "SHARE_ONLY", 1, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getWxAppInfoVo(Long advertiserId, String searchType, Integer page, int count) {
|
|
|
+ boolean nextPage = false;
|
|
|
+ String accessToken = tokenMapper.onlyGetToken(advertiserId);
|
|
|
+ if (Check.isNull(accessToken)) {
|
|
|
+ log.error("账户({})查询token失败", advertiserId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ params.put("advertiser_id", advertiserId);
|
|
|
+ params.put("page", page);
|
|
|
+ //页面大小,默认值为10,最大值100
|
|
|
+ params.put("page_size", 100);
|
|
|
+ JSONObject filtering = new JSONObject();
|
|
|
+ //CREATE_ONLY本户创建,SHARE_ONLY 只查共享应用
|
|
|
+ filtering.put("search_type", searchType);
|
|
|
+ //状态 审核通过:AUDIT_ACCEPTED
|
|
|
+// filtering.put("audit_status", "AUDIT_ACCEPTED");
|
|
|
+ params.put("filtering", filtering);
|
|
|
+ //获取微信小程序列表
|
|
|
+ String url = "https://api.oceanengine.com/open_api/v3.0/tools/wechat_applet/list/";
|
|
|
+ JSONObject obj = Okhttp3Utils.bytedanceGetRequest(accessToken, url, params);
|
|
|
+ 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 list = data.getJSONArray("list");
|
|
|
+ if (!Check.isNull(list)) {
|
|
|
+ bytedanceCdpProjectMapper.replaceBytedanceWxAppInfo(list, advertiserId);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //40110请求超频
|
|
|
+ if (40110 == code && count <= 3)
|
|
|
+ getByteAppInfoVo(advertiserId, searchType, page, count + 1);
|
|
|
+ log.error("账户{}获取微信小程序列表失败,入参:{}\n结果:{}", advertiserId, JSONObject.toJSONString(params), obj);
|
|
|
+ }
|
|
|
+ if (nextPage) {
|
|
|
+ getWxAppInfoVo(advertiserId, searchType, page + 1, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Long> queryMediaAdverIds(String date, String mediaType) {
|
|
|
+ return bytedanceCdpProjectMapper.queryMediaAdverIds(date, mediaType);
|
|
|
+ }
|
|
|
+
|
|
|
}
|