|
@@ -0,0 +1,306 @@
|
|
|
|
|
+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.BytedanceXingTuReport;
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.BytedanceXingTuReportDaily;
|
|
|
|
|
+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;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * https://bytedance.larkoffice.com/docx/Jr8bdA6yvocOqRxRL1LcBDi8nJb
|
|
|
|
|
+ */
|
|
|
|
|
+@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 List<JSONObject> getXingTuActiveTask(Long advertiserId) {
|
|
|
|
|
+ return bytedanceXingTuMapper.queryXingTuActiveTask(advertiserId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<JSONObject> getXingTuReportTask(Long advertiserId) {
|
|
|
|
|
+ return bytedanceXingTuMapper.queryXingTuReportTask(advertiserId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<JSONObject> getXingTuRetryJob() {
|
|
|
|
|
+ return bytedanceXingTuMapper.queryXingTuRetryJob();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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, "xingtu_task_list", 1, null);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void getXingTuTaskInfo(Long advertiserId, Long taskId, String accessToken, Long errorId, Integer isLog, Integer isSend) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ String url = "https://api.oceanengine.com/open_api/2/star/demand/om_get_challenge/";
|
|
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
+ paramsMap.put("star_id", advertiserId);
|
|
|
|
|
+ paramsMap.put("challenge_task_id", taskId);
|
|
|
|
|
+ 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, taskId);
|
|
|
|
|
+ insertErrorLog(isLog, advertiserId, DateUtils.getNowDate("yyyy-MM-dd"), DateUtils.getNowDate("yyyy-MM-dd"), "xingtu_task_info",
|
|
|
|
|
+ new JSONObject().fluentPut("msg", "请求结果返回为空").fluentPut("taskId", taskId).toJSONString());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer code = result.getInteger("code");
|
|
|
|
|
+ if (code == 0) {
|
|
|
|
|
+ JSONObject data = result.getJSONObject("data");
|
|
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
|
|
+ JSONObject taskInfo = data.getJSONObject("task_info");
|
|
|
|
|
+ if (!Check.isNull(taskInfo)) {
|
|
|
|
|
+ JSONObject challengeInfo = taskInfo.getJSONObject("challenge_info");
|
|
|
|
|
+ JSONObject demandInfo = taskInfo.getJSONObject("demand_info");
|
|
|
|
|
+ String challengeTaskId = taskInfo.getString("challenge_task_id");
|
|
|
|
|
+ JSONObject taskJson = new JSONObject();
|
|
|
|
|
+ taskJson.put("challenge_task_id", challengeTaskId);
|
|
|
|
|
+ taskJson.put("advertiser_id", advertiserId);
|
|
|
|
|
+ taskJson.putAll(challengeInfo);
|
|
|
|
|
+ taskJson.putAll(demandInfo);
|
|
|
|
|
+ BytedanceXingTuTask task = taskJson.toJavaObject(BytedanceXingTuTask.class);
|
|
|
|
|
+ bytedanceXingTuMapper.updateTaskInfo(task);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("账户id:{} {},星图任务详情请求结果失败,返回数据:{}", advertiserId, taskId, result);
|
|
|
|
|
+ insertErrorLog(isLog, advertiserId, DateUtils.getNowDate("yyyy-MM-dd"), DateUtils.getNowDate("yyyy-MM-dd"), "xingtu_task_info",
|
|
|
|
|
+ new JSONObject().fluentPut("msg", result.getString("message")).fluentPut("taskId", taskId).toJSONString()
|
|
|
|
|
+ );
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.info("账户ID:{} {},星图任务详情请求成功", advertiserId, taskId);
|
|
|
|
|
+ if (errorId != null) {
|
|
|
|
|
+ promoterReportMapper.deleteInfoByErrorId(errorId);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isSend != null && 1 == isSend) {
|
|
|
|
|
+ AlertUtils.sendMessage(advertiserId, DateUtils.getNowDate("yyyy-MM-dd"), DateUtils.getNowDate("yyyy-MM-dd"), 1, "xingtu_task_info", 1, null);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void getXingTuTaskReport(Long advertiserId, Long taskId, String accessToken, Integer page, Long errorId, Integer isLog, Integer isSend) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ String url = "https://api.oceanengine.com/open_api/2/star/demand/om_get_challenge_items_data/";
|
|
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
+ paramsMap.put("star_id", advertiserId);
|
|
|
|
|
+ paramsMap.put("challenge_task_id", taskId);
|
|
|
|
|
+ paramsMap.put("page", page);
|
|
|
|
|
+ int limit = 30;
|
|
|
|
|
+ paramsMap.put("limit", limit);
|
|
|
|
|
+ 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, taskId);
|
|
|
|
|
+ insertErrorLog(isLog, advertiserId, DateUtils.getNowDate("yyyy-MM-dd"), DateUtils.getNowDate("yyyy-MM-dd"), "xingtu_task_report",
|
|
|
|
|
+ new JSONObject().fluentPut("msg", "请求结果返回为空").fluentPut("taskId", taskId).toJSONString());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer code = result.getInteger("code");
|
|
|
|
|
+ boolean hasMore = false;
|
|
|
|
|
+ List<BytedanceXingTuReport> reports = new ArrayList<>();
|
|
|
|
|
+ List<BytedanceXingTuReportDaily> dailyReports = new ArrayList<>();
|
|
|
|
|
+ if (code == 0) {
|
|
|
|
|
+ JSONObject data = result.getJSONObject("data");
|
|
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
|
|
+ JSONArray dataList = data.getJSONArray("data_list");
|
|
|
|
|
+ JSONObject pageInfo = data.getJSONObject("page_info");
|
|
|
|
|
+ if (!Check.isNull(pageInfo)) {
|
|
|
|
|
+ hasMore = pageInfo.getBoolean("has_more");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Check.isNull(dataList)) {
|
|
|
|
|
+ for (Object o : dataList) {
|
|
|
|
|
+ JSONObject item = (JSONObject) o;
|
|
|
|
|
+ item.put("challenge_task_id", taskId);
|
|
|
|
|
+ item.put("advertiser_id", advertiserId);
|
|
|
|
|
+ BytedanceXingTuReport report = item.toJavaObject(BytedanceXingTuReport.class);
|
|
|
|
|
+ JSONObject estAdCost = item.getJSONObject("est_ad_cost");
|
|
|
|
|
+ if (!Check.isNull(estAdCost)) {
|
|
|
|
|
+ Long value = estAdCost.getLong("value");
|
|
|
|
|
+ Long time = estAdCost.getLong("time");
|
|
|
|
|
+ report.setEstAdCostValue(value);
|
|
|
|
|
+ report.setEstAdCostTime(time);
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject estSales = item.getJSONObject("est_sales");
|
|
|
|
|
+ if (!Check.isNull(estSales)) {
|
|
|
|
|
+ Long value = estSales.getLong("value");
|
|
|
|
|
+ Long time = estSales.getLong("time");
|
|
|
|
|
+ report.setEstSalesValue(value);
|
|
|
|
|
+ report.setEstSalesTime(time);
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject play = item.getJSONObject("play");
|
|
|
|
|
+ if (!Check.isNull(play)) {
|
|
|
|
|
+ Long value = play.getLong("value");
|
|
|
|
|
+ Long time = play.getLong("time");
|
|
|
|
|
+ report.setPlayValue(value);
|
|
|
|
|
+ report.setPlayTime(time);
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject settleAdShare = item.getJSONObject("settle_ad_share");
|
|
|
|
|
+ if (!Check.isNull(settleAdShare)) {
|
|
|
|
|
+ Long value = settleAdShare.getLong("value");
|
|
|
|
|
+ Long time = settleAdShare.getLong("time");
|
|
|
|
|
+ report.setSettleAdShareValue(value);
|
|
|
|
|
+ report.setSettleAdShareTime(time);
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject settleCps = item.getJSONObject("settle_cps");
|
|
|
|
|
+ if (!Check.isNull(settleCps)) {
|
|
|
|
|
+ Long value = settleCps.getLong("value");
|
|
|
|
|
+ Long time = settleCps.getLong("time");
|
|
|
|
|
+ report.setSettleCpsValue(value);
|
|
|
|
|
+ report.setSettleCpsTime(time);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<BytedanceXingTuReportDaily> itemInfoDailyList = report.getItemInfoDailyList();
|
|
|
|
|
+ if (!Check.isNull(itemInfoDailyList)) {
|
|
|
|
|
+ itemInfoDailyList.forEach(daily -> {
|
|
|
|
|
+ daily.setAdvertiserId(advertiserId);
|
|
|
|
|
+ daily.setChallengeTaskId(taskId);
|
|
|
|
|
+ daily.setAuthorId(report.getAuthorId());
|
|
|
|
|
+ daily.setItemId(report.getItemId());
|
|
|
|
|
+ });
|
|
|
|
|
+ dailyReports.addAll(itemInfoDailyList);
|
|
|
|
|
+ }
|
|
|
|
|
+ reports.add(report);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("账户id:{} {},星图任务结算数据请求结果失败,返回数据:{}", advertiserId, taskId, result);
|
|
|
|
|
+ insertErrorLog(isLog, advertiserId, DateUtils.getNowDate("yyyy-MM-dd"), DateUtils.getNowDate("yyyy-MM-dd"), "xingtu_task_report",
|
|
|
|
|
+ new JSONObject().fluentPut("msg", result.getString("message")).fluentPut("taskId", taskId).toJSONString()
|
|
|
|
|
+ );
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!Check.isNull(reports)) {
|
|
|
|
|
+ bytedanceXingTuMapper.insertReport(reports);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Check.isNull(dailyReports)) {
|
|
|
|
|
+ bytedanceXingTuMapper.insertReportDaily(dailyReports);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (hasMore) {
|
|
|
|
|
+ getXingTuTaskReport(advertiserId, taskId, accessToken, page + 1, errorId, isLog, isSend);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.info("账户ID:{} {},星图任务结算数据请求成功", advertiserId, taskId);
|
|
|
|
|
+ if (errorId != null) {
|
|
|
|
|
+ promoterReportMapper.deleteInfoByErrorId(errorId);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isSend != null && 1 == isSend) {
|
|
|
|
|
+ AlertUtils.sendMessage(advertiserId, DateUtils.getNowDate("yyyy-MM-dd"), DateUtils.getNowDate("yyyy-MM-dd"), 1, "xingtu_task_report", 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);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|