Просмотр исходного кода

feat: 创意日报定时任务

pudongliang 4 месяцев назад
Родитель
Сommit
4b8887dcca

+ 5 - 2
src/main/java/com/moka/gdtauto/service/DailyReportService.java

@@ -8,7 +8,6 @@ import com.moka.gdtauto.entity.AccountGroupAccountRelationship;
 import com.moka.gdtauto.entity.BaseDailyCreativeReport;
 import com.moka.gdtauto.entity.RepDailyCreativeReport;
 import com.moka.gdtauto.entity.ReqDailyCreativeReport;
-import com.moka.gdtauto.entity.TencentAccount;
 import com.moka.gdtauto.mapper.AccountGroupAccountRelationshipMapper;
 import com.moka.gdtauto.mapper.AccountGroupMapper;
 import com.moka.gdtauto.mapper.RepDailyCreativeReportMapper;
@@ -16,6 +15,7 @@ import com.moka.gdtauto.mapper.ReqDailyCreativeReportMapper;
 import com.tencent.ads.model.v3.DailyReportsGetResponseData;
 import com.tencent.ads.model.v3.ReportDateRange;
 import com.tencent.ads.model.v3.ReportStruct;
+import com.tencent.ads.model.v3.TimeLine;
 import com.tencent.ads.v3.TencentAds;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -137,7 +137,7 @@ public class DailyReportService {
                 if (rs.getDynamicCreativeId() == null || rs.getDate() == null) {
                     continue;
                 }
-                if ("REQUEST_TIME".equals(timeLine)) {
+                if (TimeLine.REQUEST_TIME.getValue().equals(timeLine)) {
                     ReqDailyCreativeReport entity = toReqEntity(accountId, groupId, groupName, rs);
                     reqMapper.upsert(entity);
                 } else {
@@ -169,6 +169,9 @@ public class DailyReportService {
      */
     public int syncAllAccounts(String startDate, String endDate, String timeLine) {
         // 查询所有账号组-账户关系
+        // TODO for test
+        LambdaQueryWrapper<AccountGroupAccountRelationship> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(AccountGroupAccountRelationship::getGroupId, 1L);
         List<AccountGroupAccountRelationship> relationships = relationshipMapper.selectList(null);
         if (relationships.isEmpty()) {
             log.warn("没有可同步的账户(AccountGroupAccountRelationship 为空)");

+ 7 - 5
src/main/java/com/moka/gdtauto/task/DailyReportSyncTask.java

@@ -1,6 +1,8 @@
 package com.moka.gdtauto.task;
 
 import com.moka.gdtauto.service.DailyReportService;
+import com.tencent.ads.model.v3.TimeLine;
+
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
@@ -18,7 +20,7 @@ import java.time.format.DateTimeFormatter;
  * @since 2026-03-03
  */
 @Slf4j
-// @Component
+@Component
 @RequiredArgsConstructor
 public class DailyReportSyncTask {
 
@@ -38,7 +40,7 @@ public class DailyReportSyncTask {
         String today = LocalDate.now().format(FMT);
         log.info("[定时任务] 同步当日 REQUEST_TIME 日报表 date={}", today);
         try {
-            int total = dailyReportService.syncAllAccounts(today, today, "REQUEST_TIME");
+            int total = dailyReportService.syncAllAccounts(today, today, TimeLine.REQUEST_TIME.getValue());
             log.info("[定时任务] 当日 REQUEST_TIME 日报表同步完成 total={}", total);
         } catch (Exception e) {
             log.error("[定时任务] 当日 REQUEST_TIME 日报表同步异常", e);
@@ -55,7 +57,7 @@ public class DailyReportSyncTask {
         String today = LocalDate.now().format(FMT);
         log.info("[定时任务] 同步当日 REPORTING_TIME 日报表 date={}", today);
         try {
-            int total = dailyReportService.syncAllAccounts(today, today, "REPORTING_TIME");
+            int total = dailyReportService.syncAllAccounts(today, today, TimeLine.REPORTING_TIME.getValue());
             log.info("[定时任务] 当日 REPORTING_TIME 日报表同步完成 total={}", total);
         } catch (Exception e) {
             log.error("[定时任务] 当日 REPORTING_TIME 日报表同步异常", e);
@@ -74,7 +76,7 @@ public class DailyReportSyncTask {
         String yesterday = LocalDate.now().minusDays(1).format(FMT);
         log.info("[定时任务] 同步昨日 REQUEST_TIME 日报表 date={}", yesterday);
         try {
-            int total = dailyReportService.syncAllAccounts(yesterday, yesterday, "REQUEST_TIME");
+            int total = dailyReportService.syncAllAccounts(yesterday, yesterday, TimeLine.REQUEST_TIME.getValue());
             log.info("[定时任务] 昨日 REQUEST_TIME 日报表同步完成 total={}", total);
         } catch (Exception e) {
             log.error("[定时任务] 昨日 REQUEST_TIME 日报表同步异常", e);
@@ -91,7 +93,7 @@ public class DailyReportSyncTask {
         String yesterday = LocalDate.now().minusDays(1).format(FMT);
         log.info("[定时任务] 同步昨日 REPORTING_TIME 日报表 date={}", yesterday);
         try {
-            int total = dailyReportService.syncAllAccounts(yesterday, yesterday, "REPORTING_TIME");
+            int total = dailyReportService.syncAllAccounts(yesterday, yesterday, TimeLine.REPORTING_TIME.getValue());
             log.info("[定时任务] 昨日 REPORTING_TIME 日报表同步完成 total={}", total);
         } catch (Exception e) {
             log.error("[定时任务] 昨日 REPORTING_TIME 日报表同步异常", e);

+ 4 - 2
src/test/java/com/moka/gdtauto/service/DailyReportTest.java

@@ -1,6 +1,8 @@
 package com.moka.gdtauto.service;
 
 import com.moka.gdtauto.GdtAutoApplication;
+import com.tencent.ads.model.v3.TimeLine;
+
 import org.junit.jupiter.api.DisplayName;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -45,7 +47,7 @@ class DailyReportTest {
                 TEST_GROUP_NAME,
                 "2026-02-20",
                 "2026-03-03",
-                "REQUEST_TIME"
+                TimeLine.REQUEST_TIME.getValue()
         );
         System.out.println("✅ REQUEST_TIME 同步完成,入库条数: " + saved);
     }
@@ -66,7 +68,7 @@ class DailyReportTest {
                 TEST_GROUP_NAME,
                 "2026-02-20",
                 "2026-03-03",
-                "REPORTING_TIME"
+                TimeLine.REPORTING_TIME.getValue()
         );
         System.out.println("✅ REPORTING_TIME 同步完成,入库条数: " + saved);
     }