|
@@ -1,6 +1,8 @@
|
|
|
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.entity.BytedanceErrorLog;
|
|
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.entity.BytedanceXingTuTask;
|
|
|
import cn.com.ctop.job.bytedance.data.mapper.BytedancePromoterReportMapper;
|
|
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.mapper.BytedanceXingTuMapper;
|
|
@@ -20,6 +22,9 @@ import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * https://bytedance.larkoffice.com/docx/Jr8bdA6yvocOqRxRL1LcBDi8nJb
|
|
|
|
|
+ */
|
|
|
@Service
|
|
@Service
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
public class BytedanceXingTuServiceImpl implements IBytedanceXingTuService {
|
|
public class BytedanceXingTuServiceImpl implements IBytedanceXingTuService {
|
|
@@ -34,6 +39,14 @@ public class BytedanceXingTuServiceImpl implements IBytedanceXingTuService {
|
|
|
return bytedanceXingTuMapper.queryXingTuAccount(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 void getXingTuTaskList(Long advertiserId, String accessToken, String startDate, String endDate, Integer page,
|
|
public void getXingTuTaskList(Long advertiserId, String accessToken, String startDate, String endDate, Integer page,
|
|
|
Long errorId, Integer isLog, Integer isSend) {
|
|
Long errorId, Integer isLog, Integer isSend) {
|
|
|
try {
|
|
try {
|
|
@@ -93,7 +106,7 @@ public class BytedanceXingTuServiceImpl implements IBytedanceXingTuService {
|
|
|
promoterReportMapper.deleteInfoByErrorId(errorId);
|
|
promoterReportMapper.deleteInfoByErrorId(errorId);
|
|
|
}
|
|
}
|
|
|
if (isSend != null && 1 == isSend) {
|
|
if (isSend != null && 1 == isSend) {
|
|
|
- AlertUtils.sendMessage(advertiserId, startDate, endDate, 1, "product_daily", 1, null);
|
|
|
|
|
|
|
+ AlertUtils.sendMessage(advertiserId, startDate, endDate, 1, "xingtu_task_list", 1, null);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -101,6 +114,179 @@ public class BytedanceXingTuServiceImpl implements IBytedanceXingTuService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ 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) {
|
|
private void insertErrorLog(Integer isLog, Long advertiserId, String startDate, String endDate, String dataDimension, String msg) {
|
|
|
if (isLog != null && 1 == isLog) {
|
|
if (isLog != null && 1 == isLog) {
|
|
|
BytedanceErrorLog errorInfo = new BytedanceErrorLog();
|
|
BytedanceErrorLog errorInfo = new BytedanceErrorLog();
|