|
@@ -0,0 +1,116 @@
|
|
|
|
|
+package cn.com.ctop.job.bytedance.data.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.BytedanceErrorLog;
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.BytedanceXingTuTask;
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.mapper.BytedancePromoterReportMapper;
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.mapper.BytedanceXingTuMapper;
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.service.IBytedanceXingTuService;
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.AlertUtils;
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.DateUtils;
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
|
|
|
+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.util.ArrayList;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+@Service
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+public class BytedanceXingTuServiceImpl implements IBytedanceXingTuService {
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private BytedanceXingTuMapper bytedanceXingTuMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private BytedancePromoterReportMapper promoterReportMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<JSONObject> getXingTuAccount(Long advertiserId) {
|
|
|
|
|
+ return bytedanceXingTuMapper.queryXingTuAccount(advertiserId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void getXingTuTaskList(Long advertiserId, String accessToken, String startDate, String endDate, Integer page,
|
|
|
|
|
+ Long errorId, Integer isLog, Integer isSend) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ String url = "https://api.oceanengine.com/open_api/2/star/demand/om_get_demand_list/";
|
|
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
+ paramsMap.put("star_id", advertiserId);
|
|
|
|
|
+ paramsMap.put("page_no", page);
|
|
|
|
|
+ int pageSize = 100;
|
|
|
|
|
+ paramsMap.put("page_size", pageSize);
|
|
|
|
|
+ Long startT = DateUtils.getTimestampFormat("yyyy-MM-dd HH:mm:ss", startDate + " 00:00:00");
|
|
|
|
|
+ Long endT = DateUtils.getTimestampFormat("yyyy-MM-dd HH:mm:ss", endDate + " 23:59:59");
|
|
|
|
|
+ paramsMap.put("create_start_time", startT);
|
|
|
|
|
+ paramsMap.put("create_end_time", endT);
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
|
|
+ String s = HttpUtils.httpGet(url, paramsMap, headers);
|
|
|
|
|
+ JSONObject result = JSONObject.parseObject(s);
|
|
|
|
|
+ if (Check.isNull(result)) {
|
|
|
|
|
+ log.info("账户id:{},星图任务列表请求结果返回为空", advertiserId);
|
|
|
|
|
+ insertErrorLog(isLog, advertiserId, startDate, endDate, "xingtu_task_list", "请求结果返回为空");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<BytedanceXingTuTask> tasks = new ArrayList<>();
|
|
|
|
|
+ Integer code = result.getInteger("code");
|
|
|
|
|
+ boolean hasMore = false;
|
|
|
|
|
+ if (code == 0) {
|
|
|
|
|
+ JSONObject data = result.getJSONObject("data");
|
|
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
|
|
+ JSONArray rows = data.getJSONArray("demands");
|
|
|
|
|
+ if (!Check.isNull(rows)) {
|
|
|
|
|
+ hasMore = rows.size() == pageSize;
|
|
|
|
|
+ for (int i = 0; i < rows.size(); i++) {
|
|
|
|
|
+ JSONObject rowJson = rows.getJSONObject(i);
|
|
|
|
|
+ Long demandId = rowJson.getLong("demand_id");
|
|
|
|
|
+ BytedanceXingTuTask task = new BytedanceXingTuTask();
|
|
|
|
|
+ task.setChallengeTaskId(demandId);
|
|
|
|
|
+ task.setAdvertiserId(advertiserId);
|
|
|
|
|
+ tasks.add(task);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("账户id:{},日期:{}星图任务列表请求结果失败,返回数据:{}", advertiserId, startDate, result);
|
|
|
|
|
+ insertErrorLog(isLog, advertiserId, startDate, endDate, "xingtu_task_list", result.getString("message"));
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Check.isNull(tasks)) {
|
|
|
|
|
+ bytedanceXingTuMapper.insertTaskId(tasks);
|
|
|
|
|
+ log.info("账户ID:{},星图任务列表请求成功,开始日期:{},结束日期:{},page:{}", advertiserId, startDate, endDate, page);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (hasMore) {
|
|
|
|
|
+ getXingTuTaskList(advertiserId, accessToken, startDate, endDate, page + 1, errorId, isLog, isSend);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("账户ID:{},日期:{}~{},星图任务列表请求成功", advertiserId, startDate,endDate);
|
|
|
|
|
+ if (errorId != null) {
|
|
|
|
|
+ promoterReportMapper.deleteInfoByErrorId(errorId);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isSend != null && 1 == isSend) {
|
|
|
|
|
+ AlertUtils.sendMessage(advertiserId, startDate, endDate, 1, "product_daily", 1, null);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void insertErrorLog(Integer isLog, Long advertiserId, String startDate, String endDate, String dataDimension, String msg) {
|
|
|
|
|
+ if (isLog != null && 1 == isLog) {
|
|
|
|
|
+ BytedanceErrorLog errorInfo = new BytedanceErrorLog();
|
|
|
|
|
+ errorInfo.setAdvertiserId(advertiserId);
|
|
|
|
|
+ errorInfo.setStartDate(startDate);
|
|
|
|
|
+ errorInfo.setEndDate(endDate);
|
|
|
|
|
+ errorInfo.setMsg(msg);
|
|
|
|
|
+ errorInfo.setDataDimension(dataDimension);
|
|
|
|
|
+ errorInfo.setDataType("daily");
|
|
|
|
|
+ promoterReportMapper.replaceErrorInfo(errorInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|