|
|
@@ -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);
|
|
|
}
|
|
|
}
|
|
|
|