Browse Source

feat:图片上传优化

pudongliang 4 months ago
parent
commit
09cb99bb30

+ 0 - 1
.qoder/rules/always_on_rule.md

@@ -7,7 +7,6 @@ trigger: always_on
 前端代码直接放在了portal目录下,典型的vue3 vite搭建,依赖了element-plus,样式采用了tailwindcss
 在进行前后端接口对接的时候使用 package com.moka.gdtauto.common.Result 进行相应;前端判定业务逻辑成功使用success字段
 前端界面风格参考 portal/src/conversion/index.vue
-带上具体的方法上下文时,如果要进行更改,只改动该方法的行为,其他更改给提醒确认后进行
 如果创建新表的CRUD,请修改java.com.moka.gdtauto.BaseCodeGenerator的TABLE_NAMES后执行其main方法
 不要读取resources目录下的配置文件,需要时给出确认提示
 不要读取target, node_modules, dist目录下的内容

+ 38 - 3
src/main/java/com/moka/gdtauto/service/impl/AdPlanConfServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.moka.gdtauto.controller.AssetDramaSyncConfController;
 import com.moka.gdtauto.entity.AdPlanConf;
 import com.moka.gdtauto.mapper.AdPlanConfMapper;
 import com.moka.gdtauto.service.AdPlanConfService;
@@ -21,7 +22,7 @@ import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.*;
 import java.util.stream.Collectors;
 import java.util.ArrayList;
 import com.moka.gdtauto.entity.AdPlan;
@@ -62,6 +63,7 @@ import com.moka.gdtauto.common.Constant;
 @Service
 public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanConf> implements AdPlanConfService {
 
+    private final AssetDramaSyncConfController assetDramaSyncConfController;
     @Autowired
     private AdPlanService adPlanService;
     @Autowired
@@ -79,6 +81,10 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
     @Autowired
     private TencentAccountIdBrandImageService tencentAccountIdBrandImageService;
 
+    AdPlanConfServiceImpl(AssetDramaSyncConfController assetDramaSyncConfController) {
+        this.assetDramaSyncConfController = assetDramaSyncConfController;
+    }
+
     @Async
     @Override
     public void gdtDeleteByConf(AdPlanConf conf) {
@@ -630,8 +636,37 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
                     .flatMap(plan -> plan.getAdCreatives().stream())
                     .collect(Collectors.toList());
 
-            for (AdPlanCreative creative : allCreatives) {
-                prepareSingleCreativeAsset(tencentAds, accountId, creative);
+            // 使用虚拟线程并发处理创意资产,Semaphore限制最大并发数为100
+            Semaphore semaphore = new Semaphore(100);
+            CountDownLatch latch = new CountDownLatch(allCreatives.size());
+            
+            try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
+                for (AdPlanCreative creative : allCreatives) {
+                    executor.submit(() -> {
+                        try {
+                            semaphore.acquire();
+                            prepareSingleCreativeAsset(tencentAds, accountId, creative);
+                            
+                        } catch (Exception e) {
+                            log.error("准备创意资产失败, accountId={}, creativeId={}, creativeName={}", 
+                                    accountId, creative.getId(), creative.getCreativeName(), e);
+                            adPlanCreativeService.lambdaUpdate()
+                                .eq(AdPlanCreative::getId, creative.getId())
+                                .set(AdPlanCreative::getFailReason, truncateError(e.getMessage()))
+                                .set(AdPlanCreative::getStatus, AdPlanStatus.FAILED)
+                                .update();
+                        } finally {
+                            semaphore.release();
+                            latch.countDown();
+                        }
+                    });
+                }
+                
+                // 等待所有任务完成
+                latch.await();
+            } catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
+                log.error("等待创意资产准备完成被中断, accountId={}", accountId, e);
             }
         }