|
@@ -2,12 +2,13 @@ package com.moka.gdtauto.service;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.moka.gdtauto.client.TencentAdsApiClientFactory;
|
|
|
import com.moka.gdtauto.entity.TencentAdsAdgroup;
|
|
import com.moka.gdtauto.entity.TencentAdsAdgroup;
|
|
|
import com.moka.gdtauto.mapper.TencentAdsAdgroupMapper;
|
|
import com.moka.gdtauto.mapper.TencentAdsAdgroupMapper;
|
|
|
-import com.tencent.ads.model.v3.AdgroupsGetListStruct;
|
|
|
|
|
-import com.tencent.ads.model.v3.AdgroupsGetResponseData;
|
|
|
|
|
-import com.tencent.ads.model.v3.FilterOperator;
|
|
|
|
|
-import com.tencent.ads.model.v3.FilteringStruct;
|
|
|
|
|
|
|
+import com.tencent.ads.exception.TencentAdsResponseException;
|
|
|
|
|
+import com.tencent.ads.exception.TencentAdsSDKException;
|
|
|
|
|
+import com.tencent.ads.model.v3.*;
|
|
|
|
|
+import com.tencent.ads.v3.TencentAds;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -29,6 +30,7 @@ public class TencentAdsAdgroupService extends ServiceImpl<TencentAdsAdgroupMappe
|
|
|
|
|
|
|
|
private final TencentAdsAccountService accountService;
|
|
private final TencentAdsAccountService accountService;
|
|
|
private final TencentAdsAdgroupMapper adgroupMapper;
|
|
private final TencentAdsAdgroupMapper adgroupMapper;
|
|
|
|
|
+ private final TencentAdsApiClientFactory clientFactory;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 同步指定账户的广告组数据
|
|
* 同步指定账户的广告组数据
|
|
@@ -53,7 +55,7 @@ public class TencentAdsAdgroupService extends ServiceImpl<TencentAdsAdgroupMappe
|
|
|
|
|
|
|
|
// 构建返回字段
|
|
// 构建返回字段
|
|
|
List<String> fields = buildFields();
|
|
List<String> fields = buildFields();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 调用API获取数据
|
|
// 调用API获取数据
|
|
|
AdgroupsGetResponseData response = accountService.getAdgroupsWithFiltering(
|
|
AdgroupsGetResponseData response = accountService.getAdgroupsWithFiltering(
|
|
|
accountId, page, pageSize, filtering, fields);
|
|
accountId, page, pageSize, filtering, fields);
|
|
@@ -117,6 +119,7 @@ public class TencentAdsAdgroupService extends ServiceImpl<TencentAdsAdgroupMappe
|
|
|
*/
|
|
*/
|
|
|
private List<String> buildFields() {
|
|
private List<String> buildFields() {
|
|
|
return List.of(
|
|
return List.of(
|
|
|
|
|
+ // 保留的旧字段
|
|
|
"adgroup_id",
|
|
"adgroup_id",
|
|
|
"adgroup_name",
|
|
"adgroup_name",
|
|
|
"configured_status",
|
|
"configured_status",
|
|
@@ -124,7 +127,25 @@ public class TencentAdsAdgroupService extends ServiceImpl<TencentAdsAdgroupMappe
|
|
|
"created_time",
|
|
"created_time",
|
|
|
"marketing_scene",
|
|
"marketing_scene",
|
|
|
"last_modified_time",
|
|
"last_modified_time",
|
|
|
- "is_deleted"
|
|
|
|
|
|
|
+ "is_deleted",
|
|
|
|
|
+ // 新增字段
|
|
|
|
|
+ "marketing_goal",
|
|
|
|
|
+ "marketing_asset_outer_spec",
|
|
|
|
|
+ "marketing_target_type",
|
|
|
|
|
+ "marketing_asset_outer_id",
|
|
|
|
|
+ "marketing_asset_outer_name",
|
|
|
|
|
+ "marketing_carrier_type",
|
|
|
|
|
+ "optimization_goal",
|
|
|
|
|
+ "conversion_id",
|
|
|
|
|
+ "site_set",
|
|
|
|
|
+ "targeting",
|
|
|
|
|
+ "bid_mode",
|
|
|
|
|
+ "bid_scene",
|
|
|
|
|
+ "begin_date",
|
|
|
|
|
+ "end_date",
|
|
|
|
|
+ "time_series",
|
|
|
|
|
+ "auto_derived_creative_enabled",
|
|
|
|
|
+ "creative_components"
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -146,8 +167,62 @@ public class TencentAdsAdgroupService extends ServiceImpl<TencentAdsAdgroupMappe
|
|
|
entity.setMarketingScene(api.getMarketingScene() != null ?
|
|
entity.setMarketingScene(api.getMarketingScene() != null ?
|
|
|
api.getMarketingScene().toString() : null);
|
|
api.getMarketingScene().toString() : null);
|
|
|
entity.setLastModifiedTime(api.getLastModifiedTime());
|
|
entity.setLastModifiedTime(api.getLastModifiedTime());
|
|
|
- // 注意:SDK可能没有isDeleted字段,设置为0
|
|
|
|
|
- entity.setIsDeleted(0);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // isDeleted字段处理(SDK中Boolean类型getter可能是isDeleted())
|
|
|
|
|
+ try {
|
|
|
|
|
+ Boolean isDeleted = (Boolean) api.getClass().getMethod("isDeleted").invoke(api);
|
|
|
|
|
+ entity.setIsDeleted(isDeleted != null && isDeleted ? 1 : 0);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ entity.setIsDeleted(0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 新增字段转换(根据SDK实际字段类型)
|
|
|
|
|
+ // 枚举类型转String
|
|
|
|
|
+ entity.setMarketingGoal(api.getMarketingGoal() != null ? api.getMarketingGoal().toString() : null);
|
|
|
|
|
+ entity.setMarketingAssetOuterSpec(api.getMarketingAssetOuterSpec() != null ? api.getMarketingAssetOuterSpec().toString() : null);
|
|
|
|
|
+ entity.setMarketingTargetType(api.getMarketingTargetType() != null ? api.getMarketingTargetType().toString() : null);
|
|
|
|
|
+ entity.setMarketingCarrierType(api.getMarketingCarrierType() != null ? api.getMarketingCarrierType().toString() : null);
|
|
|
|
|
+ entity.setOptimizationGoal(api.getOptimizationGoal() != null ? api.getOptimizationGoal().toString() : null);
|
|
|
|
|
+ entity.setBidMode(api.getBidMode() != null ? api.getBidMode().toString() : null);
|
|
|
|
|
+ entity.setBidScene(api.getBidScene() != null ? api.getBidScene().toString() : null);
|
|
|
|
|
+
|
|
|
|
|
+ // Long类型转String
|
|
|
|
|
+ entity.setConversionId(api.getConversionId() != null ? api.getConversionId().toString() : null);
|
|
|
|
|
+
|
|
|
|
|
+ // List<String>转逗号分隔字符串
|
|
|
|
|
+ if (api.getSiteSet() != null && !api.getSiteSet().isEmpty()) {
|
|
|
|
|
+ entity.setSiteSet(String.join(",", api.getSiteSet()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 复杂对象转JSON字符串(ReadTargetingSetting)
|
|
|
|
|
+ if (api.getTargeting() != null) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ entity.setTargeting(api.getTargeting().toString());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("转换targeting失败: {}", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // String类型直接赋值
|
|
|
|
|
+ entity.setBeginDate(api.getBeginDate());
|
|
|
|
|
+ entity.setEndDate(api.getEndDate());
|
|
|
|
|
+ entity.setTimeSeries(api.getTimeSeries());
|
|
|
|
|
+
|
|
|
|
|
+ // Boolean类型转String(使用反射处理)
|
|
|
|
|
+ try {
|
|
|
|
|
+ Boolean autoDerived = (Boolean) api.getClass().getMethod("getAutoDerivedCreativeEnabled").invoke(api);
|
|
|
|
|
+ entity.setAutoDerivedCreativeEnabled(autoDerived != null ? autoDerived.toString() : null);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // SDK不支持该字段
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // creative_components - SDK中未找到此字段,保留为null
|
|
|
|
|
+ // marketing_asset_outer_id - SDK中字段为marketingAssetId (Long)
|
|
|
|
|
+ entity.setMarketingAssetOuterId(api.getMarketingAssetId() != null ?
|
|
|
|
|
+ api.getMarketingAssetId().toString() : null);
|
|
|
|
|
+
|
|
|
|
|
+ // marketing_asset_outer_name - SDK中未找到,使用conversionName代替
|
|
|
|
|
+ entity.setMarketingAssetOuterName(api.getConversionName());
|
|
|
|
|
|
|
|
result.add(entity);
|
|
result.add(entity);
|
|
|
}
|
|
}
|
|
@@ -205,4 +280,35 @@ public class TencentAdsAdgroupService extends ServiceImpl<TencentAdsAdgroupMappe
|
|
|
|
|
|
|
|
return count(wrapper);
|
|
return count(wrapper);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 创建广告
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param accountId 广告主账户ID
|
|
|
|
|
+ * @param request 创建广告请求参数
|
|
|
|
|
+ * @return 创建成功的广告信息
|
|
|
|
|
+ * @throws TencentAdsResponseException API响应异常
|
|
|
|
|
+ * @throws TencentAdsSDKException SDK异常
|
|
|
|
|
+ * @throws Exception 其他异常
|
|
|
|
|
+ */
|
|
|
|
|
+ public AdgroupsAddResponseData createAdgroup(String accountId, AdgroupsAddRequest request)
|
|
|
|
|
+ throws TencentAdsResponseException, TencentAdsSDKException, Exception {
|
|
|
|
|
+ log.info("开始创建广告,accountId={}, adgroupName={}", accountId, request.getAdgroupName());
|
|
|
|
|
+
|
|
|
|
|
+ // 获取TencentAds实例
|
|
|
|
|
+ TencentAds tencentAds = clientFactory.getTencentAdsWithoutUserToken(accountId);
|
|
|
|
|
+
|
|
|
|
|
+ // 设置账户ID
|
|
|
|
|
+ request.setAccountId(Long.parseLong(accountId));
|
|
|
|
|
+
|
|
|
|
|
+ // 调用SDK创建广告
|
|
|
|
|
+ AdgroupsAddResponseData response = tencentAds.adgroups()
|
|
|
|
|
+ .adgroupsAdd(request);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("创建广告成功,adgroupId={}",
|
|
|
|
|
+ response.getAdgroupId());
|
|
|
|
|
+
|
|
|
|
|
+ return response;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|