|
|
@@ -0,0 +1,76 @@
|
|
|
+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.mapper.BytedancePromoterReportMapper;
|
|
|
+import cn.com.ctop.job.bytedance.data.mapper.DianZhongMapper;
|
|
|
+import cn.com.ctop.job.bytedance.data.service.IDianZhongService;
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.crypto.SecureUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class DianZhongServiceImpl implements IDianZhongService {
|
|
|
+ @Autowired
|
|
|
+ private BytedancePromoterReportMapper promoterReportMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DianZhongMapper dianZhongMapper;
|
|
|
+
|
|
|
+ public void getDownloadUrl(String dataType, String clientId, String token,
|
|
|
+ String statDay, String startTime, String endTime) {
|
|
|
+ long l = System.currentTimeMillis();
|
|
|
+ JSONObject param = new JSONObject()
|
|
|
+ .fluentPut("clientId", clientId)
|
|
|
+ .fluentPut("sdate", String.valueOf(DateUtil.parse(startTime, "yyyy-MM-dd HH:mm:ss").getTime() / 1000))
|
|
|
+ .fluentPut("edate", String.valueOf(DateUtil.parse(endTime, "yyyy-MM-dd HH:mm:ss").getTime() / 1000))
|
|
|
+ .fluentPut("timestamp", l)
|
|
|
+ .fluentPut("signKey", getSignKey(clientId, token, l));
|
|
|
+ try {
|
|
|
+ String url = "https://routine.wqxsw.com/flames/channel/query/" + dataType;
|
|
|
+ String response = HttpUtils.httpPostRequest(url, param, null);
|
|
|
+ JSONObject responseJson = JSONObject.parseObject(response);
|
|
|
+ System.out.println(response);
|
|
|
+ if ("0".equals(responseJson.getString("retCode"))) {
|
|
|
+ String taskId = responseJson.getString("data");
|
|
|
+ JSONObject jsonObject = new JSONObject()
|
|
|
+ .fluentPut("stat_date", statDay.replace("-", ""))
|
|
|
+ .fluentPut("task_id", taskId)
|
|
|
+ .fluentPut("type", dataType)
|
|
|
+ .fluentPut("client_id", clientId);
|
|
|
+ dianZhongMapper.insertDownloadTask(jsonObject);
|
|
|
+ log.info("获取点众数据下载地址成功 {} {} {}~{} ", dataType, clientId, startTime, endTime);
|
|
|
+ } else {
|
|
|
+ log.error("获取点众数据下载地址错误 {} {} {}~{} msg:{}", dataType, clientId, startTime, endTime, responseJson.getString("retMsg"));
|
|
|
+ promoterReportMapper.replaceErrorInfo(
|
|
|
+ BytedanceErrorLog.builder()
|
|
|
+ .msg(responseJson.getString("retMsg"))
|
|
|
+ .advertiserId(Long.valueOf(clientId))
|
|
|
+ .dataDimension("dianzhong")
|
|
|
+ .dataType(dataType)
|
|
|
+ .startDate(startTime)
|
|
|
+ .endDate(endTime)
|
|
|
+ .build());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获取点众数据下载地址错误 {} {} {}~{} ", dataType, clientId, startTime, endTime, e);
|
|
|
+ promoterReportMapper.replaceErrorInfo(
|
|
|
+ BytedanceErrorLog.builder()
|
|
|
+ .msg(e.getMessage())
|
|
|
+ .advertiserId(Long.valueOf(clientId))
|
|
|
+ .dataDimension("dianzhong")
|
|
|
+ .dataType(dataType)
|
|
|
+ .startDate(startTime)
|
|
|
+ .endDate(endTime)
|
|
|
+ .build());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String getSignKey(String clientId, String token, long timeStamp) {
|
|
|
+ return SecureUtil.md5(clientId + token + timeStamp).toLowerCase();
|
|
|
+ }
|
|
|
+}
|