|
@@ -0,0 +1,136 @@
|
|
|
|
|
+package cn.com.ctop.job.adq.data.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import cn.com.ctop.job.adq.data.entity.AdqErrorLog;
|
|
|
|
|
+import cn.com.ctop.job.adq.data.mapper.AdqErrorLogMapper;
|
|
|
|
|
+import cn.com.ctop.job.adq.data.service.IAdqMaterialReportService;
|
|
|
|
|
+import cn.com.ctop.job.adq.data.utils.AlertUtils;
|
|
|
|
|
+import cn.com.ctop.job.adq.data.utils.Check;
|
|
|
|
|
+import cn.com.ctop.job.adq.data.utils.FieldsConfig;
|
|
|
|
|
+import cn.com.ctop.job.adq.data.utils.HttpUtils;
|
|
|
|
|
+import cn.com.ctop.job.adq.utils.RandomStringGenerator;
|
|
|
|
|
+import cn.com.ctop.job.adq.utils.doris.sink.DorisMultiTableStreamLoadManager;
|
|
|
|
|
+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.time.Instant;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@Service
|
|
|
|
|
+public class AdqMaterialReportServiceImpl implements IAdqMaterialReportService {
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private DorisMultiTableStreamLoadManager dorisLoadManager;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private AdqErrorLogMapper adqErrorLogMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void getAdqMaterialDailyReport(Long advertiserId, String accessToken, String startDate, String endDate, Integer page, Integer isLog, Long errId, Integer isSend) {
|
|
|
|
|
+ getAdqMaterialDailyReport(advertiserId, accessToken, "REPORT_LEVEL_MATERIAL_IMAGE", startDate, endDate, page, isLog, errId, isSend);
|
|
|
|
|
+ getAdqMaterialDailyReport(advertiserId, accessToken, "REPORT_LEVEL_MATERIAL_VIDEO", startDate, endDate, page, isLog, errId, isSend);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
|
|
+ level REPORT_LEVEL_MATERIAL_IMAGE REPORT_LEVEL_MATERIAL_VIDEO
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void getAdqMaterialDailyReport(Long advertiserId, String accessToken, String level, String startDate, String endDate, Integer page, Integer isLog, Long errId, Integer isSend) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
+ paramsMap.put("access_token", accessToken);
|
|
|
|
|
+ long timestamp = Instant.now().getEpochSecond();
|
|
|
|
|
+ paramsMap.put("timestamp", String.valueOf(timestamp));
|
|
|
|
|
+ paramsMap.put("nonce", RandomStringGenerator.generateRandomString(32));
|
|
|
|
|
+ paramsMap.put("page", page);
|
|
|
|
|
+ paramsMap.put("page_size", 1000);
|
|
|
|
|
+ paramsMap.put("account_id", advertiserId);
|
|
|
|
|
+ paramsMap.put("level", level);
|
|
|
|
|
+ JSONObject date_range = new JSONObject();
|
|
|
|
|
+ date_range.put("start_date", startDate);
|
|
|
|
|
+ date_range.put("end_date", endDate);
|
|
|
|
|
+ paramsMap.put("date_range", date_range);
|
|
|
|
|
+ paramsMap.put("time_line", "REPORTING_TIME");
|
|
|
|
|
+ JSONArray group_by = new JSONArray();
|
|
|
|
|
+ group_by.add("date");
|
|
|
|
|
+ group_by.add("adgroup_id");
|
|
|
|
|
+ JSONArray fieldsList = FieldsConfig.getMaterialDailyFieldsList();
|
|
|
|
|
+ if ("REPORT_LEVEL_MATERIAL_IMAGE".equals(level)) {
|
|
|
|
|
+ group_by.add("image_id");
|
|
|
|
|
+ fieldsList.add("image_id");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ group_by.add("video_id");
|
|
|
|
|
+ fieldsList.add("video_id");
|
|
|
|
|
+ }
|
|
|
|
|
+ paramsMap.put("group_by", group_by);
|
|
|
|
|
+ paramsMap.put("fields", fieldsList);
|
|
|
|
|
+ String s = HttpUtils.httpGet("https://api.e.qq.com/v3.0/daily_reports/get", paramsMap, null);
|
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
|
|
+ int totalPage = 1;
|
|
|
|
|
+ if (Check.isNull(jsonObject)) {
|
|
|
|
|
+ log.error("请求素材日报失败,account_id:{},返回为空。", advertiserId);
|
|
|
|
|
+ if (isLog == 1) {
|
|
|
|
|
+ AdqErrorLog errorInfo = new AdqErrorLog();
|
|
|
|
|
+ errorInfo.setAdvertiserId(advertiserId);
|
|
|
|
|
+ errorInfo.setStartDate(startDate);
|
|
|
|
|
+ errorInfo.setEndDate(endDate);
|
|
|
|
|
+ errorInfo.setDataDimension("material");
|
|
|
|
|
+ errorInfo.setDataType("daily");
|
|
|
|
|
+ adqErrorLogMapper.replaceErrorInfo(errorInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+ return;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
|
|
+ if (code == 0) {
|
|
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
|
|
+ totalPage = data.getJSONObject("page_info").getIntValue("total_page");
|
|
|
|
|
+ JSONArray list = data.getJSONArray("list");
|
|
|
|
|
+ if (!Check.isNull(list)) {
|
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
+ JSONObject dataJson = list.getJSONObject(i);
|
|
|
|
|
+ dataJson.put("stat_time_day", dataJson.getString("date").replace("-", ""));
|
|
|
|
|
+ dataJson.put("advertiser_id", advertiserId);
|
|
|
|
|
+ if ("REPORT_LEVEL_MATERIAL_IMAGE".equals(level)) {
|
|
|
|
|
+ dataJson.put("material_id", dataJson.getString("image_id"));
|
|
|
|
|
+ dataJson.put("material_type", "IMAGE");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ dataJson.put("material_id", dataJson.getString("video_id"));
|
|
|
|
|
+ dataJson.put("material_type", "VIDEO");
|
|
|
|
|
+ }
|
|
|
|
|
+ dorisLoadManager.add("media_api", "adq_material_report_daily", dataJson);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.error("请求素材日报失败,account_id:{},返回信息:{}", advertiserId, jsonObject);
|
|
|
|
|
+ if (isLog == 1) {
|
|
|
|
|
+ AdqErrorLog errorInfo = new AdqErrorLog();
|
|
|
|
|
+ errorInfo.setAdvertiserId(advertiserId);
|
|
|
|
|
+ errorInfo.setStartDate(startDate);
|
|
|
|
|
+ errorInfo.setEndDate(endDate);
|
|
|
|
|
+ errorInfo.setDataDimension("material");
|
|
|
|
|
+ errorInfo.setDataType("daily");
|
|
|
|
|
+ adqErrorLogMapper.replaceErrorInfo(errorInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (page < totalPage) {
|
|
|
|
|
+ getAdqMaterialDailyReport(advertiserId, accessToken, level, startDate, endDate, page + 1, isLog, errId, isSend);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("请求创意日报完成,account_id:{},开始日期:{},结束日期:{} totalPage:{}", advertiserId, startDate, endDate, totalPage);
|
|
|
|
|
+ if (errId != null) {
|
|
|
|
|
+ adqErrorLogMapper.deleteInfoByErrorId(errId);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isSend != null && isSend == 1) {
|
|
|
|
|
+ AlertUtils.sendMessage(advertiserId, startDate, endDate, 3, "daily", 1, "asset");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|