Bladeren bron

adq-z账户报表

yumeng 1 jaar geleden
bovenliggende
commit
61e4ac6774

+ 260 - 0
job-adq/src/main/java/cn/com/ctop/job/adq/data/entity/AdqAccountReportHour.java

@@ -0,0 +1,260 @@
+package cn.com.ctop.job.adq.data.entity;
+
+import java.math.BigDecimal;
+
+
+/**
+ * 广点通创意时报对象 adq_creative_report_hour
+ *
+ * @author ruoyi
+ * @date 2025-03-06
+ */
+public class AdqAccountReportHour {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 广告主ID
+     */
+    private Long advertiserId;
+
+
+    /**
+     * 数据起始时间
+     */
+    private Long statTimeDay;
+
+    /**
+     * 小时
+     */
+    private Long hour;
+
+    /**
+     * 消耗
+     */
+    private BigDecimal cost;
+
+    /**
+     * 展示
+     */
+    private Long viewCount;
+
+    /**
+     * 点击
+     */
+    private Long validClickCount;
+
+    /**
+     * 转化
+     */
+    private Long conversionsCount;
+
+    /**
+     * 深度转化
+     */
+    private Long deepConversionsCount;
+
+    /**
+     * APP激活次数
+     */
+    private Long activatedCount;
+
+    /**
+     * 注册次数
+     */
+    private Long regPv;
+
+    /**
+     * 次日留存次数
+     */
+    private Long retentionCount;
+
+    /**
+     * 视频有效播放次数
+     */
+    private Long videoOuterPlayCount;
+
+    /**
+     * 100%进度播放次数
+     */
+    private Long videoOuterPlay100Count;
+
+    /**
+     * 关键行为转化次数
+     */
+    private Long keyBehaviorConversionsCount;
+
+    /**
+     * 付费次数
+     */
+    private Long purchasePv;
+
+    /**
+     * 付费金额
+     */
+    private BigDecimal purchaseAmount;
+
+    /**
+     * 首次付费人数
+     */
+    private Long firstPayCount;
+
+    public Long getAdvertiserId() {
+        return advertiserId;
+    }
+
+    public void setAdvertiserId(Long advertiserId) {
+        this.advertiserId = advertiserId;
+    }
+
+    public Long getStatTimeDay() {
+        return statTimeDay;
+    }
+
+    public void setStatTimeDay(Long statTimeDay) {
+        this.statTimeDay = statTimeDay;
+    }
+
+    public Long getHour() {
+        return hour;
+    }
+
+    public void setHour(Long hour) {
+        this.hour = hour;
+    }
+
+    public BigDecimal getCost() {
+        return cost;
+    }
+
+    public void setCost(BigDecimal cost) {
+        this.cost = cost;
+    }
+
+    public Long getViewCount() {
+        return viewCount;
+    }
+
+    public void setViewCount(Long viewCount) {
+        this.viewCount = viewCount;
+    }
+
+    public Long getValidClickCount() {
+        return validClickCount;
+    }
+
+    public void setValidClickCount(Long validClickCount) {
+        this.validClickCount = validClickCount;
+    }
+
+    public Long getConversionsCount() {
+        return conversionsCount;
+    }
+
+    public void setConversionsCount(Long conversionsCount) {
+        this.conversionsCount = conversionsCount;
+    }
+
+    public Long getDeepConversionsCount() {
+        return deepConversionsCount;
+    }
+
+    public void setDeepConversionsCount(Long deepConversionsCount) {
+        this.deepConversionsCount = deepConversionsCount;
+    }
+
+    public Long getActivatedCount() {
+        return activatedCount;
+    }
+
+    public void setActivatedCount(Long activatedCount) {
+        this.activatedCount = activatedCount;
+    }
+
+    public Long getRegPv() {
+        return regPv;
+    }
+
+    public void setRegPv(Long regPv) {
+        this.regPv = regPv;
+    }
+
+    public Long getRetentionCount() {
+        return retentionCount;
+    }
+
+    public void setRetentionCount(Long retentionCount) {
+        this.retentionCount = retentionCount;
+    }
+
+    public Long getVideoOuterPlayCount() {
+        return videoOuterPlayCount;
+    }
+
+    public void setVideoOuterPlayCount(Long videoOuterPlayCount) {
+        this.videoOuterPlayCount = videoOuterPlayCount;
+    }
+
+    public Long getVideoOuterPlay100Count() {
+        return videoOuterPlay100Count;
+    }
+
+    public void setVideoOuterPlay100Count(Long videoOuterPlay100Count) {
+        this.videoOuterPlay100Count = videoOuterPlay100Count;
+    }
+
+    public Long getKeyBehaviorConversionsCount() {
+        return keyBehaviorConversionsCount;
+    }
+
+    public void setKeyBehaviorConversionsCount(Long keyBehaviorConversionsCount) {
+        this.keyBehaviorConversionsCount = keyBehaviorConversionsCount;
+    }
+
+    public Long getPurchasePv() {
+        return purchasePv;
+    }
+
+    public void setPurchasePv(Long purchasePv) {
+        this.purchasePv = purchasePv;
+    }
+
+    public BigDecimal getPurchaseAmount() {
+        return purchaseAmount;
+    }
+
+    public void setPurchaseAmount(BigDecimal purchaseAmount) {
+        this.purchaseAmount = purchaseAmount;
+    }
+
+    public Long getFirstPayCount() {
+        return firstPayCount;
+    }
+
+    public void setFirstPayCount(Long firstPayCount) {
+        this.firstPayCount = firstPayCount;
+    }
+
+    @Override
+    public String
+    toString() {
+        return "AdqAccountReportHour{" +
+                "advertiserId=" + advertiserId +
+                ", statTimeDay=" + statTimeDay +
+                ", hour=" + hour +
+                ", cost=" + cost +
+                ", viewCount=" + viewCount +
+                ", validClickCount=" + validClickCount +
+                ", conversionsCount=" + conversionsCount +
+                ", deepConversionsCount=" + deepConversionsCount +
+                ", activatedCount=" + activatedCount +
+                ", regPv=" + regPv +
+                ", retentionCount=" + retentionCount +
+                ", videoOuterPlayCount=" + videoOuterPlayCount +
+                ", videoOuterPlay100Count=" + videoOuterPlay100Count +
+                ", keyBehaviorConversionsCount=" + keyBehaviorConversionsCount +
+                ", purchasePv=" + purchasePv +
+                ", purchaseAmount=" + purchaseAmount +
+                ", firstPayCount=" + firstPayCount +
+                '}';
+    }
+}

+ 0 - 2
job-adq/src/main/java/cn/com/ctop/job/adq/data/mapper/AdqCreativeReportMapper.java

@@ -15,8 +15,6 @@ public interface AdqCreativeReportMapper {
 
     void addsDaily(@Param("adds") List<AdqCreativeReportDaily> dailies);
 
-    void replaceErrorInfo(AdqErrorLog errorInfo);
-
     List<JSONObject> getErrorLogs();
 
     void deleteInfoByErrorId(@Param("errorId") Long errorId);

+ 7 - 0
job-adq/src/main/java/cn/com/ctop/job/adq/data/mapper/AdqErrorLogMapper.java

@@ -0,0 +1,7 @@
+package cn.com.ctop.job.adq.data.mapper;
+
+import cn.com.ctop.job.adq.data.entity.AdqErrorLog;
+
+public interface AdqErrorLogMapper {
+    void replaceErrorInfo(AdqErrorLog errorInfo);
+}

+ 0 - 18
job-adq/src/main/java/cn/com/ctop/job/adq/data/mapper/xml/IAdqCreativeReportService.xml

@@ -105,25 +105,7 @@
         </foreach>
 
     </insert>
-    <insert id="replaceErrorInfo">
-        replace into adq_error_log
-        <trim prefix="(" suffix=")" suffixOverrides=",">
-            <if test="advertiserId != null">advertiser_id,</if>
-            <if test="startDate != null">start_date,</if>
-            <if test="endDate != null">end_date,</if>
-            <if test="dataDimension != null">data_dimension,</if>
-            <if test="dataType != null">data_type,</if>
 
-        </trim>
-        <trim prefix="values (" suffix=")" suffixOverrides=",">
-            <if test="advertiserId != null">#{advertiserId},</if>
-            <if test="startDate != null">#{startDate},</if>
-            <if test="endDate != null">#{endDate},</if>
-            <if test="dataDimension != null">#{dataDimension},</if>
-            <if test="dataType != null">#{dataType},</if>
-
-        </trim>
-    </insert>
     <delete id="deleteInfoByErrorId">
         DELETE
         FROM adq_error_log

+ 27 - 0
job-adq/src/main/java/cn/com/ctop/job/adq/data/mapper/xml/AdqErrorLogMapper.xml

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="cn.com.ctop.job.adq.data.mapper.AdqErrorLogMapper">
+
+
+
+    <insert id="replaceErrorInfo">
+        replace into adq_error_log
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="advertiserId != null">advertiser_id,</if>
+            <if test="startDate != null">start_date,</if>
+            <if test="endDate != null">end_date,</if>
+            <if test="dataDimension != null">data_dimension,</if>
+            <if test="dataType != null">data_type,</if>
+
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="advertiserId != null">#{advertiserId},</if>
+            <if test="startDate != null">#{startDate},</if>
+            <if test="endDate != null">#{endDate},</if>
+            <if test="dataDimension != null">#{dataDimension},</if>
+            <if test="dataType != null">#{dataType},</if>
+
+        </trim>
+    </insert>
+
+</mapper>

+ 1 - 0
job-adq/src/main/java/cn/com/ctop/job/adq/data/service/IAdqAccountReportService.java

@@ -1,4 +1,5 @@
 package cn.com.ctop.job.adq.data.service;
 
 public interface IAdqAccountReportService {
+    void getAdqAccountHour(Long advertiserId, String accessToken, String startDate, String endDate,Integer page,Integer isLog);
 }

+ 96 - 0
job-adq/src/main/java/cn/com/ctop/job/adq/data/service/impl/AdqAccountReportServiceImpl.java

@@ -1,8 +1,104 @@
 package cn.com.ctop.job.adq.data.service.impl;
 
+import cn.com.ctop.job.adq.data.entity.AdqAccountReportHour;
+import cn.com.ctop.job.adq.data.entity.AdqCreativeReportHour;
+import cn.com.ctop.job.adq.data.entity.AdqErrorLog;
+import cn.com.ctop.job.adq.data.mapper.AdqAccountReportMapper;
+import cn.com.ctop.job.adq.data.mapper.AdqErrorLogMapper;
 import cn.com.ctop.job.adq.data.service.IAdqAccountReportService;
+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 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.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 @Service
+@Slf4j
 public class AdqAccountReportServiceImpl implements IAdqAccountReportService {
+    @Autowired
+    private AdqErrorLogMapper adqErrorLogMapper;
+
+
+    @Override
+    public void getAdqAccountHour(Long advertiserId, String accessToken, String startDate, String endDate, Integer page, Integer isLog) {
+        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", "REPORT_LEVEL_ADVERTISER");
+            JSONObject date_range = new JSONObject();
+            date_range.put("start_date", startDate);
+            date_range.put("end_date", endDate);
+            paramsMap.put("date_range", date_range);
+            JSONArray group_by = new JSONArray();
+            group_by.add("hour");
+            paramsMap.put("group_by", group_by);
+            JSONArray fieldsList = FieldsConfig.getFieldsList();
+            paramsMap.put("fields", fieldsList);
+            Integer totalNumber = 0;
+            List<AdqAccountReportHour> hourList = new ArrayList<>();
+            String s = HttpUtils.httpGet("https://api.e.qq.com/v3.0/hourly_reports/get", paramsMap, null);
+            JSONObject jsonObject = JSONObject.parseObject(s);
+            System.err.println(jsonObject);
+            if (!Check.isNull(jsonObject)) {
+                Integer code = jsonObject.getInteger("code");
+                if (code == 0) {
+                    JSONObject data = jsonObject.getJSONObject("data");
+                    if (!Check.isNull(data)) {
+                        JSONObject pageInfo = data.getJSONObject("page_info");
+                        if (!Check.isNull(pageInfo)) {
+                            totalNumber = pageInfo.getInteger("total_number");
+                        }
+                        JSONArray list = data.getJSONArray("list");
+                        if (!Check.isNull(list)) {
+                            for (int i = 0; i < list.size(); i++) {
+                                JSONObject dataJson = list.getJSONObject(i);
+                                AdqAccountReportHour hourReport = JSONObject.parseObject(dataJson.toJSONString(), AdqAccountReportHour.class);
+                                hourReport.setAdvertiserId(advertiserId);
+                                hourReport.setStatTimeDay(Long.valueOf(startDate.replace("-", "")));
+                                hourList.add(hourReport);
+                            }
+                        }
+                    }
+                } 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("creative");
+                        errorInfo.setDataType("hour");
+                       // adqErrorLogMapper.replaceErrorInfo(errorInfo);
+                    }
+                    return;
+                }
+            }
+            if (!Check.isNull(hourList)) {
+            //    accountReportMapper.addsHourList(hourList);
+            }
+            if (totalNumber >= 1000) {
+                getAdqAccountHour(advertiserId, accessToken, startDate, endDate, page + 1, isLog);
+            } else {
+                log.error("请求创意时报完成,account_id:{},日期:{}", advertiserId, startDate);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 }

+ 6 - 2
job-adq/src/main/java/cn/com/ctop/job/adq/data/service/impl/AdqCreativeCreativeReportServiceImpl.java

@@ -4,6 +4,7 @@ import cn.com.ctop.job.adq.data.entity.AdqCreativeReportDaily;
 import cn.com.ctop.job.adq.data.entity.AdqCreativeReportHour;
 import cn.com.ctop.job.adq.data.entity.AdqErrorLog;
 import cn.com.ctop.job.adq.data.mapper.AdqCreativeReportMapper;
+import cn.com.ctop.job.adq.data.mapper.AdqErrorLogMapper;
 import cn.com.ctop.job.adq.data.service.IAdqCreativeReportService;
 import cn.com.ctop.job.adq.data.utils.Check;
 import cn.com.ctop.job.adq.data.utils.FieldsConfig;
@@ -27,6 +28,9 @@ public class AdqCreativeCreativeReportServiceImpl implements IAdqCreativeReportS
     @Autowired
     private AdqCreativeReportMapper adqReportMapper;
 
+    @Autowired
+    private AdqErrorLogMapper adqErrorLogMapper;
+
     @Override
     public void getAdqCreativeHour(Long advertiserId, String accessToken, String startDate, String endDate, Integer page, Integer isLog) {
         try {
@@ -83,7 +87,7 @@ public class AdqCreativeCreativeReportServiceImpl implements IAdqCreativeReportS
                         errorInfo.setEndDate(endDate);
                         errorInfo.setDataDimension("creative");
                         errorInfo.setDataType("hour");
-                        adqReportMapper.replaceErrorInfo(errorInfo);
+                        adqErrorLogMapper.replaceErrorInfo(errorInfo);
                     }
                     return;
                 }
@@ -162,7 +166,7 @@ public class AdqCreativeCreativeReportServiceImpl implements IAdqCreativeReportS
                         errorInfo.setEndDate(endDate);
                         errorInfo.setDataDimension("creative");
                         errorInfo.setDataType("daily");
-                        adqReportMapper.replaceErrorInfo(errorInfo);
+                        adqErrorLogMapper.replaceErrorInfo(errorInfo);
                     }
                     return;
                 }

+ 22 - 1
job-adq/src/main/java/cn/com/ctop/job/adq/handler/AdqAccountReportJob.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.job.adq.handler;
 
 
+import cn.com.ctop.job.adq.data.service.IAdqAccountReportService;
 import cn.com.ctop.job.adq.data.service.IAdqCreativeReportService;
 import cn.com.ctop.job.adq.data.utils.Check;
 import cn.com.ctop.job.adq.data.utils.DateUtils;
@@ -22,9 +23,29 @@ import java.util.concurrent.Executors;
 @Slf4j
 @Component
 public class AdqAccountReportJob {
+    @Autowired
+    private IAdqAccountReportService accountReportService;
     private static ExecutorService hourExecutorService = Executors.newFixedThreadPool(3);
     private static ExecutorService dailyExecutorService = Executors.newFixedThreadPool(3);
 
-
+    @XxlJob("nowDateAccounteHour")
+    public void creativeHour() throws Exception {
+        String param = XxlJobHelper.getJobParam(); // 执行参数
+        if (Check.isNull(param)) {
+            log.error("入参为空");
+            return;
+        }
+
+        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+        String[] s = param.split("_");
+        Long advertiserId = Long.valueOf(s[0]);
+        String accessToken = s[1];
+        hourExecutorService.submit(new Runnable() {
+            @Override
+            public void run() {
+                accountReportService.getAdqAccountHour(advertiserId, accessToken, nowDate, nowDate, 1, 2);
+            }
+        });
+    }
 
 }