|
|
@@ -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) {
|