فهرست منبع

feat:记录暂停信息

pudongliang 4 ماه پیش
والد
کامیت
af31f7d7aa

+ 39 - 8
src/main/java/com/moka/gdtauto/service/AdAutoExecutor.java

@@ -100,6 +100,37 @@ public class AdAutoExecutor {
      * @param allPlansToSuspend 收集所有待暂停广告(跨 conf 汇总用)
      * @return
      */
+
+    public void checkRule(Long adPlanConfId, AdAutoConf autoConf,
+            List<AutoPlanRule> rules) {
+                // 1. 根据 jobNumber 查询 AdPlanConf 列表
+        List<AdPlanConf> adPlanConfs = adPlanConfService.lambdaQuery()
+                .eq(autoConf.getAdGroupId() > 0, AdPlanConf::getAccountGroupId, autoConf.getAdGroupId())
+                .eq(AdPlanConf::getId, adPlanConfId)
+                .list();
+        if (adPlanConfs == null || adPlanConfs.isEmpty()) {
+            log.warn("[AdAutoExecutor] 未找到 AdPlanConf,jobNumber={}", autoConf.getJobNumber());
+            throw new RuntimeException("未找到关联广告计划配置");
+        }
+        
+        List<AdPlan> plansToSuspend = new ArrayList<>();
+        for (AdPlanConf adPlanConf : adPlanConfs) {
+            List<AdPlan> plans = adPlanService.lambdaQuery()
+                    .eq(AdPlan::getAdPlanConfId, adPlanConf.getId())
+                    .eq(AdPlan::getDeleted, 0)
+                    .list();
+                 for (AdPlan plan : plans) {
+                    if (shouldSuspend(plan, rules, autoConf.getNewAdDays())) {
+                        plansToSuspend.add(plan);
+                    }
+                }
+        }
+        for (AdPlan plan : plansToSuspend) {
+            adPlanService.lambdaUpdate().set(AdPlan::getFailReason, plan.getFailReason()).eq(AdPlan::getId, plan.getId()).update();
+        }
+               
+    }
+
     private void processOneConf(AdAutoConf autoConf,
             AdPlanConf adPlanConf,
             List<AutoPlanRule> rules,
@@ -213,16 +244,16 @@ public class AdAutoExecutor {
         if (rule.getType() == 1) {
             if (rule.getMinCost() == 0) {
                 if (plan.getReqIncomeRoi1().compareTo(rule.getMinIor()) < 0) {
-                String s = String.format(isNewAd? "[新广告]" : "[老广告]" + " 不考虑消耗 ROI:%.2f < 阈值:%.2f",
-                            isNewAd, plan.getReqIncomeRoi1(), rule.getMinIor());
+                String s = String.format((isNewAd? "[新广告]" : "[老广告]") + " 不考虑消耗 ROI:%.2f < 阈值:%.2f",
+                            plan.getReqIncomeRoi1(), rule.getMinIor());
                     plan.setFailReason(s);
                     return true;
                 }
             } else {
                 // getReqIncomeRoi1 < minIor 关闭
                 if (constYuan > rule.getMinCost() && plan.getReqIncomeRoi1().compareTo(rule.getMinIor()) < 0) {
-                    String s = String.format(isNewAd? "[新广告]" : "[老广告]" + " 消耗%d > 阈值%d ROI:%.2f < 阈值:%.2f",
-                        isNewAd, constYuan, rule.getMinCost(), plan.getReqIncomeRoi1(), rule.getMinIor());
+                    String s = String.format((isNewAd? "[新广告]" : "[老广告]") + " 消耗%d > 阈值%d ROI:%.2f < 阈值:%.2f",
+                       constYuan, rule.getMinCost(), plan.getReqIncomeRoi1(), rule.getMinIor());
                     plan.setFailReason(s);
                     return true;
                 }
@@ -231,15 +262,15 @@ public class AdAutoExecutor {
             // minCost == 0 表示不限制消耗门槛
             if (rule.getMinCost() == 0) {
                 if (scanCostYuan > rule.getScanMaxCost()) {
-                    String s = String.format(isNewAd? "[新广告]" : "[老广告]" + " 不考虑消耗 粉价消耗%d > 阈值%d",
-                            isNewAd, scanCostYuan, rule.getScanMaxCost());
+                    String s = String.format((isNewAd? "[新广告]" : "[老广告]") + " 不考虑消耗 粉价消耗%d > 阈值%d",
+                            scanCostYuan, rule.getScanMaxCost());
                     plan.setFailReason(s);
                     return true;
                 }
             } else {
                 if (scanCostYuan > rule.getScanMaxCost() && constYuan > rule.getMinCost()) {
-                    String s = String.format(isNewAd? "[新广告]" : "[老广告]" + " 消耗%d > 阈值%d; 粉价消耗%d > 阈值%d",
-                        isNewAd, constYuan, rule.getMinCost(), scanCostYuan, rule.getScanMaxCost());
+                    String s = String.format((isNewAd? "[新广告]" : "[老广告]") + " 消耗%d > 阈值%d; 粉价消耗%d > 阈值%d",
+                        constYuan, rule.getMinCost(), scanCostYuan, rule.getScanMaxCost());
                     plan.setFailReason(s);
                     return true;
                 }

+ 6 - 0
src/test/java/com/moka/gdtauto/service/AdAutoTest.java

@@ -27,6 +27,12 @@ public class AdAutoTest {
     private AdAutoExecutor adAutoExecutor;
 
     @Test
+    public void testCheckRule() {
+        AdAutoConf conf = adAutoConfService.getById(11);
+        adAutoExecutor.checkRule(55L, conf, JSON.parseArray(conf.getRules(), AutoPlanRule.class));
+    }
+
+    @Test
     public void testCompareTO() {
         AdPlan plan = adPlanService.lambdaQuery()
             .eq(AdPlan::getAdgroupId, 87878621549L).one();