|
|
@@ -21,6 +21,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.stream.Collectors;
|
|
|
import java.util.ArrayList;
|
|
|
import com.moka.gdtauto.entity.AdPlan;
|
|
|
@@ -47,7 +48,6 @@ import java.security.MessageDigest;
|
|
|
import java.util.Base64;
|
|
|
import com.moka.gdtauto.common.Constant;
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 广告计划配置服务实现类
|
|
|
*
|
|
|
@@ -69,66 +69,284 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
@Autowired
|
|
|
private TencentAccountService tencentAccountService;
|
|
|
|
|
|
+ @Async
|
|
|
@Override
|
|
|
- public void suspendByConfId(Long confId) {
|
|
|
- AdPlanConf conf = this.getById(confId);
|
|
|
- String jobNumber = conf.getJobNumber();
|
|
|
- List<AdPlan> plans = adPlanService.lambdaQuery()
|
|
|
- .eq(AdPlan::getAdPlanConfId, confId)
|
|
|
- .gt(AdPlan::getAdgroupId, 0)
|
|
|
- .orderByAsc(AdPlan::getId).list();
|
|
|
+ public void gdtDeleteByConf(AdPlanConf conf) {
|
|
|
try {
|
|
|
- TencentAds tencentAds = clientFactory.getTencentAds(jobNumber, Constant.MAIN_ORG_ACCOUNT_ID);
|
|
|
- for (AdPlan plan : plans) {
|
|
|
- try {
|
|
|
- AdgroupsUpdateRequest req = new AdgroupsUpdateRequest();
|
|
|
- req.setAccountId(plan.getAccountId());
|
|
|
- req.setAdgroupId(plan.getAdgroupId());
|
|
|
- req.setConfiguredStatus(ConfiguredStatus.SUSPEND);
|
|
|
- tencentAds.adgroups().adgroupsUpdate(req);
|
|
|
- plan.setSystemStatus("ADGROUP_STATUS_SUSPEND");
|
|
|
- } catch (Exception e) {
|
|
|
- plan.setFailReason(truncateError(e.getMessage()));
|
|
|
- }
|
|
|
- adPlanService.lambdaUpdate().eq(AdPlan::getId,plan.getId())
|
|
|
- .set(AdPlan::getSystemStatus, plan.getSystemStatus())
|
|
|
- .set(AdPlan::getFailReason, plan.getFailReason())
|
|
|
- .update();
|
|
|
+ doDeletePlanAll(conf);
|
|
|
+ doDeleteCreativeAll(conf);
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .eq(AdPlanConf::getId, conf.getId())
|
|
|
+ .set(AdPlanConf::getSystemDeleteProcessStatus, 2)
|
|
|
+ .update();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("gdtDeleteByConf error", e);
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .eq(AdPlanConf::getId, conf.getId())
|
|
|
+ .set(AdPlanConf::getSystemDeleteProcessStatus, 3)
|
|
|
+ .set(AdPlanConf::getFailReason, truncateError(e.getMessage())).update();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doDeletePlanAll(AdPlanConf conf) throws Exception {
|
|
|
+ log.info("doDeletePlanAll {}", conf.getId());
|
|
|
+ TencentAds tencentAds = clientFactory.getTencentAds(conf.getJobNumber(), Constant.MAIN_ORG_ACCOUNT_ID);
|
|
|
+ int pageSize = 100;
|
|
|
+ int pageNum = 1;
|
|
|
+ while (true) {
|
|
|
+ LambdaQueryWrapper<AdPlan> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(AdPlan::getAdPlanConfId, conf.getId())
|
|
|
+ .gt(AdPlan::getAdgroupId, 0)
|
|
|
+ .orderByAsc(AdPlan::getId);
|
|
|
+ Page<AdPlan> page = adPlanService.page(new Page<>(pageNum, pageSize), queryWrapper);
|
|
|
+ List<AdPlan> plans = page.getRecords();
|
|
|
+ if (plans.isEmpty()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ doDeletePlans(tencentAds, plans);
|
|
|
+ if (!page.hasNext()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ pageNum++;
|
|
|
+ TimeUnit.SECONDS.sleep(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doDeletePlans(TencentAds tencentAds, List<AdPlan> plans) throws Exception {
|
|
|
+ for (AdPlan plan : plans) {
|
|
|
+ try {
|
|
|
+ AdgroupsDeleteRequest req = new AdgroupsDeleteRequest();
|
|
|
+ req.setAccountId(plan.getAccountId());
|
|
|
+ req.setAdgroupId(plan.getAdgroupId());
|
|
|
+ tencentAds.adgroups().adgroupsDelete(req);
|
|
|
+ } catch (Exception e) {
|
|
|
+ plan.setFailReason(truncateError(e.getMessage()));
|
|
|
+ }
|
|
|
+ adPlanService.lambdaUpdate()
|
|
|
+ .eq(AdPlan::getId, plan.getId())
|
|
|
+ .set(AdPlan::getSystemDelete, "true")
|
|
|
+ .set(AdPlan::getFailReason, plan.getFailReason())
|
|
|
+ .update();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void doDeleteCreativeAll(AdPlanConf conf) throws Exception {
|
|
|
+ log.info("doDeleteCreativeAll {}", conf.getId());
|
|
|
+ TencentAds tencentAds = clientFactory.getTencentAds(conf.getJobNumber(), Constant.MAIN_ORG_ACCOUNT_ID);
|
|
|
+ int pageSize = 100;
|
|
|
+ int pageNum = 1;
|
|
|
+ while (true) {
|
|
|
+ LambdaQueryWrapper<AdPlanCreative> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(AdPlanCreative::getAdPlanConfId, conf.getId())
|
|
|
+ .gt(AdPlanCreative::getAdgroupId, 0)
|
|
|
+ .gt(AdPlanCreative::getCreativeId, 0)
|
|
|
+ .orderByAsc(AdPlanCreative::getId);
|
|
|
+ Page<AdPlanCreative> page = adPlanCreativeService.page(new Page<>(pageNum, pageSize), queryWrapper);
|
|
|
+ List<AdPlanCreative> creatives = page.getRecords();
|
|
|
+ if (creatives.isEmpty()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ doDeleteCreative(tencentAds, creatives);
|
|
|
+ if (!page.hasNext()) {
|
|
|
+ break;
|
|
|
}
|
|
|
+ pageNum++;
|
|
|
+ TimeUnit.SECONDS.sleep(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doDeleteCreative(TencentAds tencentAds, List<AdPlanCreative> creatives) throws Exception {
|
|
|
+ for (AdPlanCreative creative : creatives) {
|
|
|
+ try {
|
|
|
+ DynamicCreativesDeleteRequest req = new DynamicCreativesDeleteRequest();
|
|
|
+ req.setAccountId(creative.getAccountId());
|
|
|
+ req.setDynamicCreativeId(creative.getCreativeId());
|
|
|
+ tencentAds.dynamicCreatives().dynamicCreativesDelete(req);
|
|
|
+ } catch (Exception e) {
|
|
|
+ creative.setFailReason(truncateError(e.getMessage()));
|
|
|
+ }
|
|
|
+ adPlanCreativeService.lambdaUpdate()
|
|
|
+ .eq(AdPlanCreative::getId, creative.getId())
|
|
|
+ .set(AdPlanCreative::getSystemDelete, "true")
|
|
|
+ .set(AdPlanCreative::getFailReason, creative.getFailReason())
|
|
|
+ .update();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Async
|
|
|
+ @Override
|
|
|
+ public void gdtDeleteByPlanIds(AdPlanConf conf, Long planIds) {
|
|
|
+ log.info("gdtDeleteByPlanIds {}", conf.getId());
|
|
|
+ try {
|
|
|
+ TencentAds tencentAds = clientFactory.getTencentAds(conf.getJobNumber(), Constant.MAIN_ORG_ACCOUNT_ID);
|
|
|
+ List<AdPlan> plans = adPlanService.lambdaQuery()
|
|
|
+ .eq(AdPlan::getAdPlanConfId, conf.getId())
|
|
|
+ .in(AdPlan::getId, planIds)
|
|
|
+ .gt(AdPlan::getAdgroupId, 0)
|
|
|
+ .orderByAsc(AdPlan::getId).list();
|
|
|
+ doDeletePlans(tencentAds, plans);
|
|
|
+
|
|
|
+ List<Long> adPlanIds = plans.stream().map(AdPlan::getId).collect(Collectors.toList());
|
|
|
+ List<AdPlanCreative> creatives = adPlanCreativeService.lambdaQuery()
|
|
|
+ .in(AdPlanCreative::getAdPlanId, adPlanIds)
|
|
|
+ .gt(AdPlanCreative::getAdgroupId, 0)
|
|
|
+ .gt(AdPlanCreative::getCreativeId, 0)
|
|
|
+ .orderByAsc(AdPlanCreative::getId)
|
|
|
+ .list();
|
|
|
+ doDeleteCreative(tencentAds, creatives);
|
|
|
+
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .eq(AdPlanConf::getId, conf.getId())
|
|
|
+ .set(AdPlanConf::getSystemDeleteProcessStatus, 2)
|
|
|
+ .update();
|
|
|
} catch (Exception e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+ log.error("gdtDeleteByPlanIds error", e);
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .eq(AdPlanConf::getId, conf.getId())
|
|
|
+ .eq(AdPlanConf::getSystemDeleteProcessStatus, 3)
|
|
|
+ .set(AdPlanConf::getFailReason, truncateError(e.getMessage())).update();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Async
|
|
|
@Override
|
|
|
- public void suspendByPlanIds(Long confId, Long planIds) {
|
|
|
- AdPlanConf conf = this.getById(confId);
|
|
|
- String jobNumber = conf.getJobNumber();
|
|
|
- List<AdPlan> plans = adPlanService.lambdaQuery()
|
|
|
- .eq(AdPlan::getAdPlanConfId, confId)
|
|
|
- .in(AdPlan::getId, planIds)
|
|
|
- .gt(AdPlan::getAdgroupId, 0)
|
|
|
- .orderByAsc(AdPlan::getId).list();
|
|
|
+ public void gdtSuspendByConf(AdPlanConf conf) {
|
|
|
try {
|
|
|
- TencentAds tencentAds = clientFactory.getTencentAds(jobNumber, Constant.MAIN_ORG_ACCOUNT_ID);
|
|
|
- for (AdPlan plan : plans) {
|
|
|
- try {
|
|
|
- AdgroupsUpdateRequest req = new AdgroupsUpdateRequest();
|
|
|
- req.setAccountId(plan.getAccountId());
|
|
|
- req.setAdgroupId(plan.getAdgroupId());
|
|
|
- req.setConfiguredStatus(ConfiguredStatus.SUSPEND);
|
|
|
- tencentAds.adgroups().adgroupsUpdate(req);
|
|
|
- plan.setSystemStatus("ADGROUP_STATUS_SUSPEND");
|
|
|
- } catch (Exception e) {
|
|
|
- plan.setFailReason(truncateError(e.getMessage()));
|
|
|
- }
|
|
|
- adPlanService.lambdaUpdate().eq(AdPlan::getId,plan.getId())
|
|
|
- .set(AdPlan::getSystemStatus, plan.getSystemStatus())
|
|
|
- .set(AdPlan::getFailReason, plan.getFailReason())
|
|
|
- .update();
|
|
|
+ doSuspendPlanAll(conf);
|
|
|
+ doSuspendCreativeAll(conf);
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .eq(AdPlanConf::getId, conf.getId())
|
|
|
+ .set(AdPlanConf::getSystemSuspendProcessStatus, 2)
|
|
|
+ .update();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("gdtSuspendByConf error", e);
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .eq(AdPlanConf::getId, conf.getId())
|
|
|
+ .set(AdPlanConf::getSystemSuspendProcessStatus, 3)
|
|
|
+ .set(AdPlanConf::getFailReason, truncateError(e.getMessage())).update();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doSuspendPlanAll(AdPlanConf conf) throws Exception {
|
|
|
+ log.info("doSuspendPlanAll {}", conf.getId());
|
|
|
+ TencentAds tencentAds = clientFactory.getTencentAds(conf.getJobNumber(), Constant.MAIN_ORG_ACCOUNT_ID);
|
|
|
+ int pageSize = 100;
|
|
|
+ int pageNum = 1;
|
|
|
+ while (true) {
|
|
|
+ LambdaQueryWrapper<AdPlan> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(AdPlan::getAdPlanConfId, conf.getId())
|
|
|
+ .gt(AdPlan::getAdgroupId, 0)
|
|
|
+ .orderByAsc(AdPlan::getId);
|
|
|
+ Page<AdPlan> page = adPlanService.page(new Page<>(pageNum, pageSize), queryWrapper);
|
|
|
+ List<AdPlan> plans = page.getRecords();
|
|
|
+ if (plans.isEmpty()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ doSuspendPlans(tencentAds, plans);
|
|
|
+ if (!page.hasNext()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ pageNum++;
|
|
|
+ TimeUnit.SECONDS.sleep(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doSuspendPlans(TencentAds tencentAds, List<AdPlan> plans) throws Exception {
|
|
|
+ for (AdPlan plan : plans) {
|
|
|
+ try {
|
|
|
+ AdgroupsUpdateRequest req = new AdgroupsUpdateRequest();
|
|
|
+ req.setAccountId(plan.getAccountId());
|
|
|
+ req.setAdgroupId(plan.getAdgroupId());
|
|
|
+ req.setConfiguredStatus(ConfiguredStatus.SUSPEND);
|
|
|
+ tencentAds.adgroups().adgroupsUpdate(req);
|
|
|
+ plan.setConfiguredStatus(ConfiguredStatus.SUSPEND.getValue());
|
|
|
+ } catch (Exception e) {
|
|
|
+ plan.setFailReason(truncateError(e.getMessage()));
|
|
|
+ }
|
|
|
+ adPlanService.lambdaUpdate()
|
|
|
+ .eq(AdPlan::getId, plan.getId())
|
|
|
+ .set(AdPlan::getConfiguredStatus, plan.getSystemStatus())
|
|
|
+ .set(AdPlan::getFailReason, plan.getFailReason())
|
|
|
+ .update();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doSuspendCreativeAll(AdPlanConf conf) throws Exception {
|
|
|
+ log.info("doSuspendCreativeAll {}", conf.getId());
|
|
|
+ TencentAds tencentAds = clientFactory.getTencentAds(conf.getJobNumber(), Constant.MAIN_ORG_ACCOUNT_ID);
|
|
|
+ int pageSize = 100;
|
|
|
+ int pageNum = 1;
|
|
|
+ while (true) {
|
|
|
+ LambdaQueryWrapper<AdPlanCreative> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(AdPlanCreative::getAdPlanConfId, conf.getId())
|
|
|
+ .gt(AdPlanCreative::getAdgroupId, 0)
|
|
|
+ .gt(AdPlanCreative::getCreativeId, 0)
|
|
|
+ .orderByAsc(AdPlanCreative::getId);
|
|
|
+ Page<AdPlanCreative> page = adPlanCreativeService.page(new Page<>(pageNum, pageSize), queryWrapper);
|
|
|
+ List<AdPlanCreative> creatives = page.getRecords();
|
|
|
+ if (creatives.isEmpty()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ doSuspendCreative(tencentAds, creatives);
|
|
|
+ if (!page.hasNext()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ pageNum++;
|
|
|
+ TimeUnit.SECONDS.sleep(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doSuspendCreative(TencentAds tencentAds, List<AdPlanCreative> creatives)
|
|
|
+ throws Exception {
|
|
|
+ for (AdPlanCreative creative : creatives) {
|
|
|
+ try {
|
|
|
+ DynamicCreativesUpdateRequest req = new DynamicCreativesUpdateRequest();
|
|
|
+ req.setAccountId(creative.getAccountId());
|
|
|
+ req.setDynamicCreativeId(creative.getCreativeId());
|
|
|
+ req.setConfiguredStatus(ConfiguredStatus.SUSPEND);
|
|
|
+ tencentAds.dynamicCreatives().dynamicCreativesUpdate(req);
|
|
|
+ creative.setConfiguredStatus(ConfiguredStatus.SUSPEND.getValue());
|
|
|
+ } catch (Exception e) {
|
|
|
+ creative.setFailReason(truncateError(e.getMessage()));
|
|
|
}
|
|
|
+ adPlanCreativeService.lambdaUpdate()
|
|
|
+ .eq(AdPlanCreative::getId, creative.getId())
|
|
|
+ .set(AdPlanCreative::getConfiguredStatus, creative.getConfiguredStatus())
|
|
|
+ .set(AdPlanCreative::getFailReason, creative.getFailReason())
|
|
|
+ .update();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Async
|
|
|
+ @Override
|
|
|
+ public void gdtSuspendByPlanIds(AdPlanConf conf, Long planIds) {
|
|
|
+ try {
|
|
|
+ TencentAds tencentAds = clientFactory.getTencentAds(conf.getJobNumber(), Constant.MAIN_ORG_ACCOUNT_ID);
|
|
|
+ List<AdPlan> plans = adPlanService.lambdaQuery()
|
|
|
+ .eq(AdPlan::getAdPlanConfId, conf.getId())
|
|
|
+ .in(AdPlan::getId, planIds)
|
|
|
+ .gt(AdPlan::getAdgroupId, 0)
|
|
|
+ .orderByAsc(AdPlan::getId).list();
|
|
|
+ doSuspendPlans(tencentAds, plans);
|
|
|
+
|
|
|
+ List<Long> adPlanIds = plans.stream().map(AdPlan::getId).collect(Collectors.toList());
|
|
|
+ List<AdPlanCreative> creatives = adPlanCreativeService.lambdaQuery()
|
|
|
+ .in(AdPlanCreative::getAdPlanId, adPlanIds)
|
|
|
+ .gt(AdPlanCreative::getAdgroupId, 0)
|
|
|
+ .gt(AdPlanCreative::getCreativeId, 0)
|
|
|
+ .orderByAsc(AdPlanCreative::getId)
|
|
|
+ .list();
|
|
|
+ doSuspendCreative(tencentAds, creatives);
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .eq(AdPlanConf::getId, conf.getId())
|
|
|
+ .set(AdPlanConf::getSystemSuspendProcessStatus, 2)
|
|
|
+ .update();
|
|
|
} catch (Exception e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+ log.error("gdtSuspendByPlanIds error", e);
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .eq(AdPlanConf::getId, conf.getId())
|
|
|
+ .set(AdPlanConf::getSystemSuspendProcessStatus, 3)
|
|
|
+ .set(AdPlanConf::getFailReason, truncateError(e.getMessage())).update();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -240,8 +458,9 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
creative.setCreativeText(conf.getCreativeText());
|
|
|
creative.setButtonText(conf.getButtonText());
|
|
|
});
|
|
|
- //group by planId
|
|
|
- Map<Long, List<AdPlanCreative>> creativeMap = creatives.stream().collect(Collectors.groupingBy(AdPlanCreative::getAdPlanId));
|
|
|
+ // group by planId
|
|
|
+ Map<Long, List<AdPlanCreative>> creativeMap = creatives.stream()
|
|
|
+ .collect(Collectors.groupingBy(AdPlanCreative::getAdPlanId));
|
|
|
for (AdPlan plan : plans) {
|
|
|
plan.setAdCreatives(creativeMap.getOrDefault(plan.getId(), new ArrayList<AdPlanCreative>()));
|
|
|
}
|
|
|
@@ -274,7 +493,7 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
log.info("开始处理广告计划,planId={}, adgroupName={}", plan.getId(), plan.getAdgroupName());
|
|
|
|
|
|
if (plan.getAdgroupId() > 0 || plan.getStatus() == AdPlanStatus.SUCCESS) {
|
|
|
- // 创建动态创意
|
|
|
+ // 创建动态创意
|
|
|
createDynamicCreatives(plan, jobNumber, Constant.MAIN_ORG_ACCOUNT_ID);
|
|
|
plan.setFailReason("");
|
|
|
plan.setStatus(AdPlanStatus.SUCCESS);
|
|
|
@@ -283,7 +502,6 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// 更新状态为执行中
|
|
|
plan.setStatus(AdPlanStatus.IN_PROGRESS);
|
|
|
adPlanService.updateById(plan);
|
|
|
@@ -292,16 +510,16 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
AdgroupsAddRequest request = buildAdgroupRequest(plan);
|
|
|
log.info("请求参数: {}", JSON.toJSON(request));
|
|
|
// 创建广告组
|
|
|
- log.info("调用腾讯API创建广告组,accountId={}, orgAccountId={}", plan.getAccountId(), Constant.MAIN_ORG_ACCOUNT_ID);
|
|
|
+ log.info("调用腾讯API创建广告组,accountId={}, orgAccountId={}", plan.getAccountId(),
|
|
|
+ Constant.MAIN_ORG_ACCOUNT_ID);
|
|
|
AdgroupsAddResponseData response = tencentAdsAdgroupService.createAdgroup(
|
|
|
- jobNumber, Constant.MAIN_ORG_ACCOUNT_ID, request
|
|
|
- );
|
|
|
+ jobNumber, Constant.MAIN_ORG_ACCOUNT_ID, request);
|
|
|
|
|
|
// 更新 adgroupId
|
|
|
plan.setAdgroupId(response.getAdgroupId());
|
|
|
log.info("广告组创建成功,adgroupId={}", response.getAdgroupId());
|
|
|
|
|
|
- // 更新状态为成功
|
|
|
+ // 更新状态为成功
|
|
|
plan.setStatus(AdPlanStatus.SUCCESS);
|
|
|
plan.setFailReason("");
|
|
|
plan.setSuccessTime(LocalDateTime.now());
|
|
|
@@ -316,7 +534,8 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
|
|
|
} catch (TencentAdsResponseException e) {
|
|
|
// 记录失败
|
|
|
- log.error("创建广告失败, planId={} code={} message={} messageCn={}", plan.getId(), e.getCode(), e.getMessage(), e.getMessageCn());
|
|
|
+ log.error("创建广告失败, planId={} code={} message={} messageCn={}", plan.getId(), e.getCode(),
|
|
|
+ e.getMessage(), e.getMessageCn());
|
|
|
plan.setStatus(AdPlanStatus.FAILED);
|
|
|
plan.setFailReason(truncateError(e.getMessageCn()));
|
|
|
adPlanService.updateById(plan);
|
|
|
@@ -341,30 +560,28 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
if (plan.getAdType() == 1) {
|
|
|
// 企微广告
|
|
|
return AdgroupsAddReqPool.getAdgroupsAddRequest(
|
|
|
- plan.getAccountId(),
|
|
|
- plan.getAdgroupName(),
|
|
|
- plan.getWxCorpid(),
|
|
|
- calculateBeginDate(),
|
|
|
- "",
|
|
|
- parseTargetConfId(plan.getTarget()),
|
|
|
- parseSiteConfId(plan.getSite()),
|
|
|
- plan.getBidAmount(),
|
|
|
- plan.getConversionId()
|
|
|
- );
|
|
|
+ plan.getAccountId(),
|
|
|
+ plan.getAdgroupName(),
|
|
|
+ plan.getWxCorpid(),
|
|
|
+ calculateBeginDate(),
|
|
|
+ "",
|
|
|
+ parseTargetConfId(plan.getTarget()),
|
|
|
+ parseSiteConfId(plan.getSite()),
|
|
|
+ plan.getBidAmount(),
|
|
|
+ plan.getConversionId());
|
|
|
} else {
|
|
|
// ROI广告
|
|
|
return AdgroupsAddReqPool.getROIAdgroupsAddRequest(
|
|
|
- plan.getAccountId(),
|
|
|
- plan.getAdgroupName(),
|
|
|
- plan.getDramaId(),
|
|
|
- calculateBeginDate(),
|
|
|
- "",
|
|
|
- parseTargetConfId(plan.getTarget()),
|
|
|
- parseSiteConfId(plan.getSite()),
|
|
|
- plan.getBidAmount(),
|
|
|
- plan.getConversionId(),
|
|
|
- plan.getDeepConversionWorthRate()
|
|
|
- );
|
|
|
+ plan.getAccountId(),
|
|
|
+ plan.getAdgroupName(),
|
|
|
+ plan.getDramaId(),
|
|
|
+ calculateBeginDate(),
|
|
|
+ "",
|
|
|
+ parseTargetConfId(plan.getTarget()),
|
|
|
+ parseSiteConfId(plan.getSite()),
|
|
|
+ plan.getBidAmount(),
|
|
|
+ plan.getConversionId(),
|
|
|
+ plan.getDeepConversionWorthRate());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -372,7 +589,7 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
* 创建动态创意
|
|
|
*/
|
|
|
private void createDynamicCreatives(AdPlan plan, String jobNumber, Long orgAccountId)
|
|
|
- throws TencentAdsResponseException, Exception {
|
|
|
+ throws TencentAdsResponseException, Exception {
|
|
|
|
|
|
TencentAds tencentAds = clientFactory.getTencentAds(jobNumber, orgAccountId);
|
|
|
|
|
|
@@ -394,7 +611,8 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
if (creativeFileUrl != null && !creativeFileUrl.isEmpty()) {
|
|
|
try {
|
|
|
log.info("开始上传创意图片,URL: {}", creativeFileUrl);
|
|
|
- Long imageId = uploadImageFromUrl(tencentAds, plan.getAccountId(), creativeFileUrl, "创意图片-" + creative.getCreativeName());
|
|
|
+ Long imageId = uploadImageFromUrl(tencentAds, plan.getAccountId(), creativeFileUrl,
|
|
|
+ "创意图片-" + creative.getCreativeName());
|
|
|
creative.setImageId(imageId);
|
|
|
adPlanCreativeService.updateById(creative);
|
|
|
log.info("创意图片上传成功,imageId: {}", imageId);
|
|
|
@@ -410,10 +628,11 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
String brandImageUrl = creative.getBrandImageUrl();
|
|
|
String brandName = creative.getBrandName();
|
|
|
if (brandImageUrl != null && !brandImageUrl.isEmpty()
|
|
|
- && brandName != null && !brandName.isEmpty()) {
|
|
|
+ && brandName != null && !brandName.isEmpty()) {
|
|
|
try {
|
|
|
log.info("开始上传品牌形象,URL: {}, 品牌名称: {}", brandImageUrl, brandName);
|
|
|
- Long brandImageId = uploadBrandFromUrl(tencentAds, plan.getAccountId(), brandImageUrl, brandName);
|
|
|
+ Long brandImageId = uploadBrandFromUrl(tencentAds, plan.getAccountId(), brandImageUrl,
|
|
|
+ brandName);
|
|
|
creative.setBrandImageId(brandImageId);
|
|
|
adPlanCreativeService.updateById(creative);
|
|
|
log.info("品牌形象上传成功,brandImageId: {}", brandImageId);
|
|
|
@@ -424,13 +643,11 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// 构建动态创意请求
|
|
|
DynamicCreativesAddRequest request = buildDynamicCreativeRequest(plan, creative);
|
|
|
|
|
|
// 调用API创建
|
|
|
- DynamicCreativesAddResponseData response =
|
|
|
- tencentAds.dynamicCreatives().dynamicCreativesAdd(request);
|
|
|
+ DynamicCreativesAddResponseData response = tencentAds.dynamicCreatives().dynamicCreativesAdd(request);
|
|
|
|
|
|
// 更新创意ID和状态
|
|
|
creative.setCreativeId(response.getDynamicCreativeId());
|
|
|
@@ -627,7 +844,7 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
|
|
|
this.updateById(conf);
|
|
|
log.info("更新广告计划配置状态,confId={}, status={}, 成功:{}, 失败:{}",
|
|
|
- confId, conf.getStatus(), successCount, failCount);
|
|
|
+ confId, conf.getStatus(), successCount, failCount);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -647,7 +864,6 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
return LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 解析定向配置ID
|
|
|
*/
|
|
|
@@ -681,14 +897,15 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
/**
|
|
|
* 从URL下载图片并上传到腾讯广告
|
|
|
*
|
|
|
- * @param tencentAds 腾讯广告SDK实例
|
|
|
- * @param accountId 账户ID
|
|
|
- * @param imageUrl 图片URL
|
|
|
+ * @param tencentAds 腾讯广告SDK实例
|
|
|
+ * @param accountId 账户ID
|
|
|
+ * @param imageUrl 图片URL
|
|
|
* @param description 图片描述
|
|
|
* @return 图片ID
|
|
|
* @throws Exception 上传失败
|
|
|
*/
|
|
|
- private Long uploadImageFromUrl(TencentAds tencentAds, Long accountId, String imageUrl, String description) throws Exception {
|
|
|
+ private Long uploadImageFromUrl(TencentAds tencentAds, Long accountId, String imageUrl, String description)
|
|
|
+ throws Exception {
|
|
|
File tempFile = null;
|
|
|
try {
|
|
|
// 1. 从URL下载图片到临时文件
|
|
|
@@ -703,26 +920,26 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
|
|
|
// 4. 调用腾讯广告API上传图片
|
|
|
ImagesAddResponseData response = tencentAds.images()
|
|
|
- .imagesAdd(
|
|
|
- "UPLOAD_TYPE_BYTES", // uploadType
|
|
|
- signature, // signature
|
|
|
- accountId, // accountId
|
|
|
- null, // organizationId
|
|
|
- null, // file
|
|
|
- base64Image, // bytes
|
|
|
- null, // imageUsage
|
|
|
- description, // description
|
|
|
- null, // resizeWidth
|
|
|
- null, // resizeHeight
|
|
|
- null // resizeFileSize
|
|
|
- );
|
|
|
+ .imagesAdd(
|
|
|
+ "UPLOAD_TYPE_BYTES", // uploadType
|
|
|
+ signature, // signature
|
|
|
+ accountId, // accountId
|
|
|
+ null, // organizationId
|
|
|
+ null, // file
|
|
|
+ base64Image, // bytes
|
|
|
+ null, // imageUsage
|
|
|
+ description, // description
|
|
|
+ null, // resizeWidth
|
|
|
+ null, // resizeHeight
|
|
|
+ null // resizeFileSize
|
|
|
+ );
|
|
|
|
|
|
if (response == null || response.getImageId() == null) {
|
|
|
throw new Exception("图片上传返回结果为空");
|
|
|
}
|
|
|
|
|
|
log.info("图片上传成功,imageId: {}, 宽度: {}px, 高度: {}px",
|
|
|
- response.getImageId(), response.getImageWidth(), response.getImageHeight());
|
|
|
+ response.getImageId(), response.getImageWidth(), response.getImageHeight());
|
|
|
|
|
|
return Long.parseLong(response.getImageId());
|
|
|
|
|
|
@@ -737,14 +954,15 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
/**
|
|
|
* 从URL下载品牌形象并上传到腾讯广告
|
|
|
*
|
|
|
- * @param tencentAds 腾讯广告SDK实例
|
|
|
- * @param accountId 账户ID
|
|
|
+ * @param tencentAds 腾讯广告SDK实例
|
|
|
+ * @param accountId 账户ID
|
|
|
* @param brandImageUrl 品牌形象图片URL
|
|
|
- * @param brandName 品牌名称
|
|
|
+ * @param brandName 品牌名称
|
|
|
* @return 品牌图片ID
|
|
|
* @throws Exception 上传失败
|
|
|
*/
|
|
|
- private Long uploadBrandFromUrl(TencentAds tencentAds, Long accountId, String brandImageUrl, String brandName) throws Exception {
|
|
|
+ private Long uploadBrandFromUrl(TencentAds tencentAds, Long accountId, String brandImageUrl, String brandName)
|
|
|
+ throws Exception {
|
|
|
File tempFile = null;
|
|
|
try {
|
|
|
// 1. 从URL下载图片到临时文件
|
|
|
@@ -752,18 +970,18 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
|
|
|
// 2. 调用腾讯广告API创建品牌形象
|
|
|
BrandAddResponseData response = tencentAds.brand()
|
|
|
- .brandAdd(
|
|
|
- accountId, // accountId
|
|
|
- brandName, // name
|
|
|
- tempFile // brandImageFile
|
|
|
- );
|
|
|
+ .brandAdd(
|
|
|
+ accountId, // accountId
|
|
|
+ brandName, // name
|
|
|
+ tempFile // brandImageFile
|
|
|
+ );
|
|
|
|
|
|
if (response == null || response.getImageId() == null) {
|
|
|
throw new Exception("品牌形象上传返回结果为空");
|
|
|
}
|
|
|
|
|
|
log.info("品牌形象上传成功,imageId: {}, 品牌名称: {}, 宽度: {}px, 高度: {}px",
|
|
|
- response.getImageId(), response.getName(), response.getWidth(), response.getHeight());
|
|
|
+ response.getImageId(), response.getName(), response.getWidth(), response.getHeight());
|
|
|
|
|
|
return Long.parseLong(response.getImageId());
|
|
|
|
|
|
@@ -820,10 +1038,16 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
|
|
|
} finally {
|
|
|
if (outputStream != null) {
|
|
|
- try { outputStream.close(); } catch (Exception e) { }
|
|
|
+ try {
|
|
|
+ outputStream.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
}
|
|
|
if (inputStream != null) {
|
|
|
- try { inputStream.close(); } catch (Exception e) { }
|
|
|
+ try {
|
|
|
+ inputStream.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
}
|
|
|
if (connection != null) {
|
|
|
connection.disconnect();
|