|
|
@@ -1,34 +1,31 @@
|
|
|
package com.moka.gdtauto.service.impl;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
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.client.TencentAdsApiClientFactory;
|
|
|
import com.moka.gdtauto.common.Constant;
|
|
|
-import com.moka.gdtauto.entity.AdPlan;
|
|
|
import com.moka.gdtauto.entity.AdPlanCreative;
|
|
|
import com.moka.gdtauto.mapper.AdPlanCreativeMapper;
|
|
|
import com.moka.gdtauto.service.AdPlanCreativeService;
|
|
|
import com.moka.gdtauto.service.AdPlanService;
|
|
|
-import com.tencent.ads.model.v3.AdgroupsGetResponseData;
|
|
|
import com.tencent.ads.model.v3.DynamicCreativesGetResponseData;
|
|
|
import com.tencent.ads.model.v3.FilterOperator;
|
|
|
import com.tencent.ads.model.v3.FilteringStruct;
|
|
|
import com.tencent.ads.v3.TencentAds;
|
|
|
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-
|
|
|
-import org.springframework.scheduling.annotation.Async;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
-
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
/**
|
|
|
* 广告计划创意服务实现类
|
|
|
@@ -162,15 +159,16 @@ public class AdPlanCreativeServiceImpl extends ServiceImpl<AdPlanCreativeMapper,
|
|
|
.orderByAsc(AdPlanCreative::getId));
|
|
|
}
|
|
|
|
|
|
- @Async
|
|
|
@Override
|
|
|
- public void syncAdPlanCreativeStatus(Long confId) {
|
|
|
+ public void adPlanCreativeStatus(Long confId) {
|
|
|
final int PAGE_SIZE = 500;
|
|
|
final int BATCH_LIMIT = 100; // 腾讯广告 adgroup_id IN 最大 100
|
|
|
|
|
|
log.info("[定时任务] 开始同步广告创意 system_status");
|
|
|
int totalUpdated = 0;
|
|
|
try {
|
|
|
+ // 获取 TencentAds 实例(使用主 orgAccountId)
|
|
|
+ TencentAds tencentAds = clientFactory.getTencentAds(null, Constant.MAIN_ORG_ACCOUNT_ID);
|
|
|
int pageNum = 1;
|
|
|
while (true) {
|
|
|
// 1. 分页查询 status=4 的广告创意,ID 降序
|
|
|
@@ -202,7 +200,7 @@ public class AdPlanCreativeServiceImpl extends ServiceImpl<AdPlanCreativeMapper,
|
|
|
List<AdPlanCreative> batch = plansOfAccount.subList(fromIdx, toIdx);
|
|
|
|
|
|
try {
|
|
|
- int updated = syncBatch(accountId, batch);
|
|
|
+ int updated = syncBatch(tencentAds, accountId, batch);
|
|
|
totalUpdated += updated;
|
|
|
} catch (Exception e) {
|
|
|
log.error("[定时任务] 同步 accountId={} 的广告状态失败,batch index={}", accountId, i, e);
|
|
|
@@ -221,10 +219,18 @@ public class AdPlanCreativeServiceImpl extends ServiceImpl<AdPlanCreativeMapper,
|
|
|
}
|
|
|
|
|
|
log.info("[定时任务] 同步广告创意 system_status 完成,共更新 {} 条", totalUpdated);
|
|
|
-
|
|
|
+ // 统计素材情况
|
|
|
+
|
|
|
+ adPlanCreativeMapper.md5ApprovalCount();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Async
|
|
|
+ @Override
|
|
|
+ public void syncAdPlanCreativeStatus(Long confId) {
|
|
|
+ adPlanCreativeStatus(confId);
|
|
|
}
|
|
|
|
|
|
- private int syncBatch(Long accountId, List<AdPlanCreative> batch) throws Exception {
|
|
|
+ private int syncBatch(TencentAds tencentAds, Long accountId, List<AdPlanCreative> batch) throws Exception {
|
|
|
final int BATCH_LIMIT = 100; // 腾讯广告 adgroup_id IN 最大 100
|
|
|
final List<String> FIELDS = List.of("adgroup_id", "dynamic_creative_id", "configured_status", "creative_set_approval_status", "is_deleted");
|
|
|
|
|
|
@@ -241,9 +247,7 @@ public class AdPlanCreativeServiceImpl extends ServiceImpl<AdPlanCreativeMapper,
|
|
|
List<FilteringStruct> filtering = new ArrayList<>();
|
|
|
filtering.add(filter);
|
|
|
|
|
|
- // 获取 TencentAds 实例(使用主 orgAccountId)
|
|
|
- TencentAds tencentAds = clientFactory.getTencentAds(null, Constant.MAIN_ORG_ACCOUNT_ID);
|
|
|
-
|
|
|
+
|
|
|
DynamicCreativesGetResponseData response = tencentAds.dynamicCreatives().dynamicCreativesGet(
|
|
|
accountId,
|
|
|
filtering,
|