|
|
@@ -0,0 +1,88 @@
|
|
|
+package cn.com.ctop.job.adq.data.service.impl;
|
|
|
+
|
|
|
+import cn.com.ctop.job.adq.data.entity.AdqAdvertiserList;
|
|
|
+import cn.com.ctop.job.adq.data.mapper.AdqAdminAdvertiserListMapper;
|
|
|
+import cn.com.ctop.job.adq.data.service.IAdqAdminAdvertiserListService;
|
|
|
+import cn.com.ctop.job.adq.data.utils.Check;
|
|
|
+import cn.com.ctop.job.adq.data.utils.HttpUtils;
|
|
|
+import cn.com.ctop.job.adq.utils.RandomStringGenerator;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.Instant;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class AdqAdminAdvertiserListServiceImpl implements IAdqAdminAdvertiserListService {
|
|
|
+ @Autowired
|
|
|
+ private AdqAdminAdvertiserListMapper adminAdvertiserListMapper;
|
|
|
+ @Override
|
|
|
+ public void getAdminAdvertiserList(Long adminAdvertiserId, String accessToken, Integer cursor) {
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
+ paramsMap.put("access_token", accessToken);
|
|
|
+ long timestamp = Instant.now().getEpochSecond();
|
|
|
+ paramsMap.put("timestamp", String.valueOf(timestamp));
|
|
|
+ paramsMap.put("nonce", RandomStringGenerator.generateRandomString(32));
|
|
|
+ paramsMap.put("pagination_mode", "PAGINATION_MODE_CURSOR");
|
|
|
+ if (!Check.isNull(cursor)) {
|
|
|
+ paramsMap.put("cursor", cursor);
|
|
|
+ }
|
|
|
+ paramsMap.put("page_size", 100);
|
|
|
+ String s = HttpUtils.httpGet("https://api.e.qq.com/v3.0/organization_account_relation/get", paramsMap, null);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
+ List<AdqAdvertiserList> addList = new ArrayList<>();
|
|
|
+ if (!Check.isNull(jsonObject)) {
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
+ JSONArray list = data.getJSONArray("list");
|
|
|
+ if (!Check.isNull(list)) {
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ JSONObject accountJson = list.getJSONObject(i);
|
|
|
+ AdqAdvertiserList adqAdvertiserList = new AdqAdvertiserList();
|
|
|
+ adqAdvertiserList.setAdminAdvertiserId(adminAdvertiserId);
|
|
|
+ Long accountId = accountJson.getLong("account_id");
|
|
|
+ adqAdvertiserList.setAdvertiserId(accountId);
|
|
|
+ adqAdvertiserList.setAdvertiserName(String.valueOf(accountId));
|
|
|
+ String corporation_name = accountJson.getString("corporation_name");
|
|
|
+ adqAdvertiserList.setCorporationName(corporation_name);
|
|
|
+ Boolean isAdx = accountJson.getBoolean("is_adx");
|
|
|
+ if (isAdx) {
|
|
|
+ adqAdvertiserList.setIsAdx(1);
|
|
|
+ } else {
|
|
|
+ adqAdvertiserList.setIsAdx(2);
|
|
|
+ }
|
|
|
+ Boolean isMp = accountJson.getBoolean("is_mp");
|
|
|
+ if (isMp) {
|
|
|
+ adqAdvertiserList.setIsMp(1);
|
|
|
+ } else {
|
|
|
+ adqAdvertiserList.setIsMp(2);
|
|
|
+ }
|
|
|
+ addList.add(adqAdvertiserList);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(addList)) {
|
|
|
+ adminAdvertiserListMapper.replaceAdqAccountList(addList);
|
|
|
+ log.info("adq账户入库成功,入库条数:{}", addList.size());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONObject cursorPageInfo = data.getJSONObject("cursor_page_info");
|
|
|
+ Boolean hasMore = cursorPageInfo.getBoolean("has_more");
|
|
|
+ if (hasMore) {
|
|
|
+ Integer cursor1 = cursorPageInfo.getInteger("cursor");
|
|
|
+ getAdminAdvertiserList(adminAdvertiserId, accessToken, cursor1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("adq获取账户列表失败,accountId:{},返回信息:{}", adminAdvertiserId, jsonObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|