Browse Source

feat:创意日报

pudongliang 4 months ago
parent
commit
cbcdafdfbc

+ 35 - 0
.vscode/launch.json

@@ -4,6 +4,7 @@
     // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
     "version": "0.2.0",
     "configurations": [
+
         {
             "type": "java",
             "name": "Current File",
@@ -45,6 +46,40 @@
             "request": "launch",
             "mainClass": "com.moka.gdtauto.util.VideoWatermarkSimpleTest",
             "projectName": "gdt-auto"
+        },
+        {
+            "type": "java",
+            "name": "JUnit: Current File (支持虚拟线程调试)",
+            "request": "launch",
+            "mainClass": "org.junit.platform.console.ConsoleLauncher",
+            "args": "--select-class=${fileBasenameNoExtension}",
+            "classPaths": [
+                "$Auto",
+                "$Runtime"
+            ],
+            "modulePaths": [
+                "$Auto",
+                "$Runtime"
+            ],
+            "projectName": "gdt-auto",
+            "vmArgs": "-Djdk.virtualThreadScheduler.maxPoolSize=1"
+        },
+        {
+            "type": "java",
+            "name": "JUnit: 指定方法 (修改args中的类名和方法名)",
+            "request": "launch",
+            "mainClass": "org.junit.platform.console.ConsoleLauncher",
+            "args": "--select-method=com.moka.gdtauto.service.AdPlanDailyReportSyncTest#testSyncDailyCreativeReport",
+            "classPaths": [
+                "$Auto",
+                "$Runtime"
+            ],
+            "modulePaths": [
+                "$Auto",
+                "$Runtime"
+            ],
+            "projectName": "gdt-auto",
+            "vmArgs": "-Djdk.virtualThreadScheduler.maxPoolSize=1"
         }
     ]
 }

+ 8 - 0
.vscode/settings.json

@@ -34,5 +34,13 @@
         "**/target": true,
         "**/node_modules": true,
         "**/dist": true
+    },
+    // Test Explorer JVM 参数配置
+    "java.test.config": {
+        "vmArgs": [
+            "--add-opens", "java.base/java.lang=ALL-UNNAMED",
+            "--add-opens", "java.base/java.util=ALL-UNNAMED",
+            "-Djdk.virtualThreadScheduler.maxPoolSize=1"
+        ]
     }
 }

+ 1 - 1
src/main/java/com/moka/gdtauto/service/DailyAdgroupReportService.java

@@ -50,7 +50,7 @@ public class DailyAdgroupReportService {
 
     /** 同步时请求的指标字段 */
     private static final List<String> SYNC_FIELDS = Arrays.asList(
-            "adgroup_id", "date",
+            "adgroup_id", "adgroup_name", "date",
             // 曝光点击
             "view_count", "view_user_count", "avg_view_per_user",
             "valid_click_count", "click_user_count", "cpc", "ctr",

+ 32 - 8
src/main/java/com/moka/gdtauto/service/DailyCreativeReportService.java

@@ -17,6 +17,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.moka.gdtauto.client.TencentAdsApiClientFactory;
 import com.moka.gdtauto.common.Constant;
+import com.moka.gdtauto.entity.AccountGroupAccountRelationship;
 import com.moka.gdtauto.entity.AdPlanConf;
 import com.moka.gdtauto.entity.AdPlanCreative;
 import com.moka.gdtauto.entity.BaseDailyCreativeReport;
@@ -59,8 +60,9 @@ public class DailyCreativeReportService {
     private final AdPlanCreativeService adPlanCreativeService;
 
     /** 同步时请求的指标字段 */
-    private static final List<String> SYNC_FIELDS = Arrays.asList("account_id",
-            "dynamic_creative_id", "date",
+    private static final List<String> SYNC_FIELDS = Arrays.asList(
+        "account_id",
+            "dynamic_creative_id", "dynamic_creative_name", "date",
             // 曝光点击
             "view_count", "view_user_count", "avg_view_per_user",
             "valid_click_count", "click_user_count", "cpc", "ctr",
@@ -112,19 +114,30 @@ public class DailyCreativeReportService {
                           String startDate, String endDate, String timeLine) throws Exception {
         log.info("开始同步日报表 timeLine={} [{}, {}]", timeLine, startDate, endDate);
 
-        TencentAds tencentAds = clientFactory.getTencentAds(conf.getJobNumber(), Constant.MAIN_ORG_ACCOUNT_ID);
+        TencentAds tencentAds = clientFactory.getTencentAds(null, Constant.MAIN_ORG_ACCOUNT_ID);
+        tencentAds.setDebug(true);
         ReportDateRange dateRange = new ReportDateRange();
         dateRange.setStartDate(startDate);
         dateRange.setEndDate(endDate);
         List<String> groupBy = Arrays.asList("dynamic_creative_id", "date");
 
-        // 分页查询 AdPlanCreative,条件:status=4, systemDelete='false'
+        Long accountGroupId = conf.getAccountGroupId();
+        List<AccountGroupAccountRelationship> relationships = relationshipMapper.selectList(
+            new LambdaQueryWrapper<AccountGroupAccountRelationship>()
+                .eq(AccountGroupAccountRelationship::getGroupId, accountGroupId)
+        );
+
+        for (AccountGroupAccountRelationship relationship : relationships) {
+            Long accountId = relationship.getAccountId();
+            
+            // 分页查询 AdPlanCreative,条件:status=4, systemDelete='false'
         int pageNum = 1;
         int pageSize = 100;
         while (true) {
             Page<AdPlanCreative> page = adPlanCreativeService.page(
                 new Page<>(pageNum, pageSize),
                 new LambdaQueryWrapper<AdPlanCreative>()
+                    .eq(AdPlanCreative::getAccountId, accountId)
                     .eq(AdPlanCreative::getAdPlanConfId, conf.getId())
                     .eq(AdPlanCreative::getStatus, 4)
                     .eq(AdPlanCreative::getSystemDelete, "false")
@@ -152,13 +165,13 @@ public class DailyCreativeReportService {
                     dateRange,
                     groupBy,
                     SYNC_FIELDS,
-                    null,
+                    accountId,
                     filtering,
                     null,
                     timeLine,
                     1L,
                     100L,
-                    Constant.MAIN_ORG_ACCOUNT_ID
+                    null
             );
 
             if (response == null || response.getList() == null || response.getList().isEmpty()) {
@@ -197,6 +210,9 @@ public class DailyCreativeReportService {
             }
             pageNum++;
         }
+     }
+
+        
     }
 
     /**
@@ -207,10 +223,11 @@ public class DailyCreativeReportService {
      * @param timeLine  时间口径
      * @return 成功保存总行数
      */
-    public void syncAllAccounts(String startDate, String endDate, String timeLine) {
+    public void syncAllAccounts(Long confId, String startDate, String endDate, String timeLine) {
         // 获取所有广告计划配置
         List<AdPlanConf> confList = adPlanConfService.list(
             new LambdaQueryWrapper<AdPlanConf>()
+                .eq(confId != null, AdPlanConf::getId, confId)
                 .eq(AdPlanConf::getAdType, 2)
                 .in(AdPlanConf::getStatus, List.of(4,5))
                 .eq(AdPlanConf::getDeleted, 0));
@@ -220,9 +237,16 @@ public class DailyCreativeReportService {
             return;
         }
 
+        // for (AdPlanConf conf : confList) {
+        //         try {
+        //                 syncReport(conf, startDate, endDate, timeLine);
+        //             } catch (Exception e) {
+        //                 log.error("同步创意日报 {} 失败", conf.getId(), e);
+        //             }
+        //     }
+
         // 使用 Semaphore 控制并发数为 10
         Semaphore semaphore = new Semaphore(10);
-
         // 使用虚拟线程池进行并发处理
         try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
             for (AdPlanConf conf : confList) {

+ 1 - 1
src/main/java/com/moka/gdtauto/service/impl/AdPlanCreativeServiceImpl.java

@@ -257,7 +257,7 @@ public class AdPlanCreativeServiceImpl extends ServiceImpl<AdPlanCreativeMapper,
                 null,
                 "PAGINATION_MODE_NORMAL",
                 null ,
-                null                      
+                null        
         );
 
         if (response == null || response.getList() == null || response.getList().isEmpty()) {

+ 0 - 1
src/main/java/com/moka/gdtauto/task/AdPlanDailyReportSyncTask.java

@@ -3,7 +3,6 @@ package com.moka.gdtauto.task;
 import java.time.LocalDateTime;
 
 import org.springframework.scheduling.annotation.Scheduled;
-
 import org.springframework.stereotype.Component;
 
 import com.moka.gdtauto.service.AdPlanDailyReportService;

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

@@ -40,7 +40,7 @@ public class DailyReportSyncTask {
         String today = LocalDate.now().format(FMT);
         log.info("[定时任务] 同步当日 REQUEST_TIME 日报表 date={}", today);
         try {
-            dailyReportService.syncAllAccounts(today, today, TimeLine.REQUEST_TIME.getValue());
+            dailyReportService.syncAllAccounts(null, today, today, TimeLine.REQUEST_TIME.getValue());
             log.info("[定时任务] 当日 REQUEST_TIME 日报表同步完成");
         } catch (Exception e) {
             log.error("[定时任务] 当日 REQUEST_TIME 日报表同步异常", e);
@@ -57,7 +57,7 @@ public class DailyReportSyncTask {
         String today = LocalDate.now().format(FMT);
         log.info("[定时任务] 同步当日 REPORTING_TIME 日报表 date={}", today);
         try {
-            dailyReportService.syncAllAccounts(today, today, TimeLine.REPORTING_TIME.getValue());
+            dailyReportService.syncAllAccounts(null, today, today, TimeLine.REPORTING_TIME.getValue());
             log.info("[定时任务] 当日 REPORTING_TIME 日报表同步完成");
         } catch (Exception e) {
             log.error("[定时任务] 当日 REPORTING_TIME 日报表同步异常", e);
@@ -76,7 +76,7 @@ public class DailyReportSyncTask {
         String yesterday = LocalDate.now().minusDays(1).format(FMT);
         log.info("[定时任务] 同步昨日 REQUEST_TIME 日报表 date={}", yesterday);
         try {
-            dailyReportService.syncAllAccounts(yesterday, yesterday, TimeLine.REQUEST_TIME.getValue());
+            dailyReportService.syncAllAccounts(null, yesterday, yesterday, TimeLine.REQUEST_TIME.getValue());
             log.info("[定时任务] 昨日 REQUEST_TIME 日报表同步完成");
         } catch (Exception e) {
             log.error("[定时任务] 昨日 REQUEST_TIME 日报表同步异常", e);
@@ -93,7 +93,7 @@ public class DailyReportSyncTask {
         String yesterday = LocalDate.now().minusDays(1).format(FMT);
         log.info("[定时任务] 同步昨日 REPORTING_TIME 日报表 date={}", yesterday);
         try {
-            dailyReportService.syncAllAccounts(yesterday, yesterday, TimeLine.REPORTING_TIME.getValue());
+            dailyReportService.syncAllAccounts(null, yesterday, yesterday, TimeLine.REPORTING_TIME.getValue());
             log.info("[定时任务] 昨日 REPORTING_TIME 日报表同步完成");
         } catch (Exception e) {
             log.error("[定时任务] 昨日 REPORTING_TIME 日报表同步异常", e);

+ 3 - 3
src/main/resources/spy.properties

@@ -6,9 +6,9 @@ logMessageFormat=com.p6spy.engine.spy.appender.CustomLineFormat
 customLogMessageFormat=%(currentTime) | 耗时: %(executionTime)ms | 连接信息: %(category)-%(connectionId) | SQL: %(sql)
 # 使用Slf4j日志系统记录SQL
 appender=com.p6spy.engine.spy.appender.Slf4JLogger
-# 不排除任何类别,打印所有SQL
-excludecategories=
-exclude=select 1
+# 排除result/resultset类别日志
+excludecategories=result,resultset
+exclude=(?i)^select\s+1$
 # 设置使用p6spy driver来做代理
 deregisterdrivers=true
 # 日期格式

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

@@ -17,7 +17,7 @@ import com.tencent.ads.model.v3.TimeLine;
 
 /**
  * 广告计划日报同步测试
- * mvn test -Dtest=AdPlanDailyReportSyncTest -Dspring.profiles.active=test
+ * mvn test -Dtest=AdPlanDailyReportSyncTest#testSyncDailyCreativeReport -Dspring.profiles.active=test
  */
 @SpringBootTest(classes = GdtAutoApplication.class)
 @ActiveProfiles("test")
@@ -48,6 +48,6 @@ public class AdPlanDailyReportSyncTest {
     public void testSyncDailyCreativeReport() {
         DateTimeFormatter FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd");
         String today = LocalDate.now().format(FMT);
-        dailyCreativeReportService.syncAllAccounts(today, today, TimeLine.REQUEST_TIME.getValue());
+        dailyCreativeReportService.syncAllAccounts(62L, today, today, TimeLine.REQUEST_TIME.getValue());
     }
 }