|
@@ -0,0 +1,87 @@
|
|
|
+package cn.com.ctop.job.bytedance.data.service.impl;
|
|
|
+
|
|
|
+import cn.com.ctop.job.bytedance.data.constant.BytedanceConstant;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.BytedancePromotionList;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.OauthToken;
|
|
|
+import cn.com.ctop.job.bytedance.data.mapper.BytedancePromotionListMapper;
|
|
|
+import cn.com.ctop.job.bytedance.data.service.IBytedancePromotionListService;
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
|
+import cn.com.ctop.job.bytedance.utils.RedisUtil;
|
|
|
+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.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 获取体验版广告列表
|
|
|
+ *
|
|
|
+ * @author zianY
|
|
|
+ * 2022-10-19
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class BytedancePromotionListServiceImpl implements IBytedancePromotionListService {
|
|
|
+ @Value("${api.bytedance.api-prefix}")
|
|
|
+ private String bytedanceApiUrl;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ BytedancePromotionListMapper bytedancePromotionListMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getPromotionList(OauthToken oauthToken, String startDate, String endDate, int pageNumber, int pageSize) {
|
|
|
+ log.info("开始获取体验版-广告列表数据 accountIDL{},日期{},page:{}", oauthToken.getAccountId(), startDate,pageNumber);
|
|
|
+ // 请求地址
|
|
|
+ String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V3_PROMOTION_LIST_GET;
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("advertiser_id", oauthToken.getAccountId());
|
|
|
+ param.put("page", pageNumber);
|
|
|
+ param.put("page_size", pageSize);
|
|
|
+// JSONObject filtering = new JSONObject();
|
|
|
+// filtering.put("promotion_modify_time", startDate);
|
|
|
+// param.put("filtering", filtering);
|
|
|
+ JSONObject resultObject = HttpUtils.bytedanceGetRequest(oauthToken.getAccessToken(), url, param);
|
|
|
+ if(Check.isNull(resultObject)){
|
|
|
+ log.error("体验版-广告列表异常==》accountId:{},调用结果为null", oauthToken.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Integer code = resultObject.getInteger("code");
|
|
|
+ if (null == code || !code.equals(0)) {
|
|
|
+ log.error("获取体验版-广告列表接口异常==》accountId:{},message:{},code{}", oauthToken.getAccountId(), resultObject.getString("message"),code);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray data = resultObject.getJSONObject("data").getJSONArray("list");
|
|
|
+ if (null == data || data.isEmpty()) {
|
|
|
+ log.error("获取体验版-广告列表数据为空==》accountId:{},message:{},code{}", oauthToken.getAccountId(), resultObject.getString("message"),code);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<BytedancePromotionList> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
+ JSONObject dataObject = data.getJSONObject(i);
|
|
|
+ //log.info("info-->{}",dataObject);
|
|
|
+ BytedancePromotionList report = JSONObject.parseObject(dataObject.toJSONString(), BytedancePromotionList.class);
|
|
|
+ list.add(report);
|
|
|
+ }
|
|
|
+ bytedancePromotionListMapper.replacePromotionList(list);
|
|
|
+ pageNumber++;
|
|
|
+ int totalPage = resultObject.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
|
|
|
+ if (pageNumber <= totalPage) {
|
|
|
+ getPromotionList(oauthToken, startDate, endDate, pageNumber, 10);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|