|
@@ -1,6 +1,5 @@
|
|
|
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.constant.CtopAdConstant;
|
|
|
|
|
import cn.com.ctop.job.bytedance.data.entity.BytedanceAdvertiserReportDaily;
|
|
import cn.com.ctop.job.bytedance.data.entity.BytedanceAdvertiserReportDaily;
|
|
|
import cn.com.ctop.job.bytedance.data.entity.BytedanceAdvertiserReportHourly;
|
|
import cn.com.ctop.job.bytedance.data.entity.BytedanceAdvertiserReportHourly;
|
|
|
import cn.com.ctop.job.bytedance.data.mapper.AccountReportNewMapper;
|
|
import cn.com.ctop.job.bytedance.data.mapper.AccountReportNewMapper;
|
|
@@ -9,6 +8,7 @@ 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.HttpUtils;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.RateLimitUtil;
|
|
import cn.com.ctop.job.bytedance.data.utils.RateLimitUtil;
|
|
|
import cn.com.ctop.job.bytedance.utils.FieldsConfig;
|
|
import cn.com.ctop.job.bytedance.utils.FieldsConfig;
|
|
|
|
|
+import cn.com.ctop.job.bytedance.utils.RedisUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
@@ -26,6 +27,9 @@ public class BytedanceReportNewServiceImpl implements IBytedanceReportNewService
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RateLimitUtil rateLimitUtil;
|
|
private RateLimitUtil rateLimitUtil;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private RedisUtil redisUtil;
|
|
|
|
|
+
|
|
|
private String urlPath = "http://192.168.0.85:8765/webhook/bytedance_account_report";
|
|
private String urlPath = "http://192.168.0.85:8765/webhook/bytedance_account_report";
|
|
|
private static JSONArray metrics = new JSONArray();
|
|
private static JSONArray metrics = new JSONArray();
|
|
|
|
|
|
|
@@ -51,8 +55,8 @@ public class BytedanceReportNewServiceImpl implements IBytedanceReportNewService
|
|
|
s = HttpUtils.httpGet(url, paramsMap, headers);
|
|
s = HttpUtils.httpGet(url, paramsMap, headers);
|
|
|
}
|
|
}
|
|
|
JSONObject result = JSONObject.parseObject(s);
|
|
JSONObject result = JSONObject.parseObject(s);
|
|
|
- if(Check.isNull(result)){
|
|
|
|
|
- log.error("获取账户时报报返回结果为空,账户ID:{},返回结果:{}",advertiserId,s);
|
|
|
|
|
|
|
+ if (Check.isNull(result)) {
|
|
|
|
|
+ log.error("获取账户时报报返回结果为空,账户ID:{},返回结果:{}", advertiserId, s);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
List<BytedanceAdvertiserReportHourly> hours = new ArrayList<>();
|
|
List<BytedanceAdvertiserReportHourly> hours = new ArrayList<>();
|
|
@@ -155,8 +159,8 @@ public class BytedanceReportNewServiceImpl implements IBytedanceReportNewService
|
|
|
s = HttpUtils.httpGet(url, paramsMap, headers);
|
|
s = HttpUtils.httpGet(url, paramsMap, headers);
|
|
|
}
|
|
}
|
|
|
JSONObject result = JSONObject.parseObject(s);
|
|
JSONObject result = JSONObject.parseObject(s);
|
|
|
- if(Check.isNull(result)){
|
|
|
|
|
- log.error("获取账户日报返回结果为空,账户ID:{},返回结果:{}",advertiserId,s);
|
|
|
|
|
|
|
+ if (Check.isNull(result)) {
|
|
|
|
|
+ log.error("获取账户日报返回结果为空,账户ID:{},返回结果:{}", advertiserId, s);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -290,4 +294,78 @@ public class BytedanceReportNewServiceImpl implements IBytedanceReportNewService
|
|
|
public List<Long> getAccountIds(Long projectId) {
|
|
public List<Long> getAccountIds(Long projectId) {
|
|
|
return accountReportNewMapper.getAccountIds(projectId);
|
|
return accountReportNewMapper.getAccountIds(projectId);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void getInactiveAdvertiser(String appId, String secret) {
|
|
|
|
|
+ String url = "https://open.oceanengine.com/open_api/oauth2/app_access_token/";
|
|
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
+ paramsMap.put("app_id", Long.valueOf(appId));
|
|
|
|
|
+ paramsMap.put("secret", secret);
|
|
|
|
|
+
|
|
|
|
|
+ String s = HttpUtils.httpPostRequest(url, paramsMap, null);
|
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
|
|
+ if (!Check.isNull(jsonObject)) {
|
|
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
|
|
+ if (code == 0) {
|
|
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
|
|
+ String accessToken = data.getString("access_token");
|
|
|
|
|
+ if (!Check.isNull(accessToken)) {
|
|
|
|
|
+ this.getInactiveAdvertiserByToken(appId, accessToken, null);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean checkInactiveAdvertiser(String accountId) {
|
|
|
|
|
+ String redisKey = "inactive_advertiser:" + accountId;
|
|
|
|
|
+ String s = redisUtil.get(redisKey);
|
|
|
|
|
+ return Check.isNull(s);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void getInactiveAdvertiserByToken(String appId, String accessToken, Long cursor) {
|
|
|
|
|
+ String url = "https://api.oceanengine.com/open_api/v3.0/tools/inactive_advertiser/list/";
|
|
|
|
|
+ JSONObject paramsMap = new JSONObject();
|
|
|
|
|
+ paramsMap.put("app_id", Long.valueOf(appId));
|
|
|
|
|
+ paramsMap.put("advertiser_type", "30_DAY_NO_COST");
|
|
|
|
|
+ if (!Check.isNull(cursor)) {
|
|
|
|
|
+ paramsMap.put("cursor", cursor);
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("App-Access-Token", accessToken);
|
|
|
|
|
+ String s = HttpUtils.httpGet(url, paramsMap, headers);
|
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
|
|
+ cursor = null;
|
|
|
|
|
+ boolean hasMore = false;
|
|
|
|
|
+ if (!Check.isNull(jsonObject)) {
|
|
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
|
|
+ if (code == 0) {
|
|
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
|
|
+ hasMore = data.getBoolean("has_more");
|
|
|
|
|
+ if (hasMore) {
|
|
|
|
|
+ cursor = data.getLong("cursor");
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONArray list = data.getJSONArray("list");
|
|
|
|
|
+ log.info("获取非活跃账户列表ing.....,数据长度:{}", list.size());
|
|
|
|
|
+ if (!Check.isNull(list)) {
|
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
+ JSONObject advertiser = list.getJSONObject(i);
|
|
|
|
|
+ Long advertiserId = advertiser.getLong("advertiser_id");
|
|
|
|
|
+ String redisKey = "inactive_advertiser:" + advertiserId;
|
|
|
|
|
+ redisUtil.add(redisKey, advertiserId, 24, TimeUnit.HOURS);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (hasMore) {
|
|
|
|
|
+ getInactiveAdvertiserByToken(appId, accessToken, cursor);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|