|
|
@@ -10,11 +10,13 @@ import com.moka.gdtauto.entity.AccountGroup;
|
|
|
import com.moka.gdtauto.entity.AccountGroupAccountRelationship;
|
|
|
import com.moka.gdtauto.entity.AdPlanConf;
|
|
|
import com.moka.gdtauto.entity.SysUser;
|
|
|
+import com.moka.gdtauto.entity.TencentAssetDrama;
|
|
|
import com.moka.gdtauto.entity.AdPlan;
|
|
|
import com.moka.gdtauto.entity.AdPlanCreative;
|
|
|
import com.moka.gdtauto.service.SysUserService;
|
|
|
|
|
|
import com.moka.gdtauto.mapper.AccountGroupAccountRelationshipMapper;
|
|
|
+import com.moka.gdtauto.mapper.TencentAssetDramaMapper;
|
|
|
import com.moka.gdtauto.service.AccountGroupService;
|
|
|
import com.moka.gdtauto.service.AdPlanConfService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
@@ -50,6 +52,7 @@ public class AdPlanConfController {
|
|
|
private final AccountGroupAccountRelationshipMapper relationshipMapper;
|
|
|
private final SysUserService sysUserService;
|
|
|
private final AccountGroupService accountGroupService;
|
|
|
+ private final TencentAssetDramaMapper tencentAssetDramaMapper;
|
|
|
|
|
|
@Operation(summary = "预创建广告计划配置", description = "根据账户分组ID和配置ID,重新创建广告计划配置")
|
|
|
@PostMapping("/reCreate")
|
|
|
@@ -62,7 +65,7 @@ public class AdPlanConfController {
|
|
|
new LambdaQueryWrapper<AccountGroupAccountRelationship>()
|
|
|
.eq(AccountGroupAccountRelationship::getGroupId, request.getAccountGroupId()));
|
|
|
|
|
|
- List<AdPlan> plans = buildPlans(request, accountGroup, relationships);
|
|
|
+ List<AdPlan> plans = buildPlans(sysUser.getJobNumber(), request, accountGroup, relationships);
|
|
|
|
|
|
return Result.success(plans, "重新创建广告计划配置成功");
|
|
|
} catch (Exception e) {
|
|
|
@@ -71,7 +74,7 @@ public class AdPlanConfController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private List<AdPlan> buildPlans(UpdateAdPlanConfRequest request, AccountGroup accountGroup,
|
|
|
+ private List<AdPlan> buildPlans(String jobNumber, UpdateAdPlanConfRequest request, AccountGroup accountGroup,
|
|
|
List<AccountGroupAccountRelationship> relationships) {
|
|
|
String dateTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
|
|
String accountGroupName = accountGroup.getGroupName();
|
|
|
@@ -80,65 +83,87 @@ public class AdPlanConfController {
|
|
|
String[] creativeUrlArray = creativeFileUrls.split(",");
|
|
|
String[] creativeNameArray = creativeFileNames != null ? creativeFileNames.split(",") : new String[0];
|
|
|
List<AdPlan> plans = new ArrayList<>();
|
|
|
- int i = 0;
|
|
|
+ Integer dramaAmount = request.getDramaAmount();
|
|
|
+ Long dramaId = request.getDramaId();
|
|
|
+ //获取短剧 relationships.size * dramaAmount
|
|
|
+ List<TencentAssetDrama> dramas = List.of();
|
|
|
+ if (dramaAmount > 0) {
|
|
|
+ // 随机获取短剧 order by RAND() limit dramaAmount
|
|
|
+ dramas = tencentAssetDramaMapper.selectList(new LambdaQueryWrapper<TencentAssetDrama>().eq(TencentAssetDrama::getJobNumber, jobNumber).last("order by rand() limit " + dramaAmount * relationships.size()));
|
|
|
+ if (dramas.size() < dramaAmount * relationships.size()) {
|
|
|
+ throw new IllegalArgumentException("短剧数量不足,请在短剧资产管理同步");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (dramaId != null) {
|
|
|
+ throw new IllegalArgumentException("请设置短剧相关配置");
|
|
|
+ }
|
|
|
+ dramas = tencentAssetDramaMapper.selectList(new LambdaQueryWrapper<TencentAssetDrama>().eq(TencentAssetDrama::getMarketingAssetId, dramaId).orderByDesc(TencentAssetDrama::getId).last("limit 1"));
|
|
|
+ }
|
|
|
+
|
|
|
+ String targets = request.getTargets();
|
|
|
+ String sites = request.getSites();
|
|
|
+ String[] targetArray = targets.split(",");
|
|
|
+ String[] siteArray = sites.split(",");
|
|
|
+ int dramaIndex = 0;
|
|
|
for (AccountGroupAccountRelationship relationship : relationships) {
|
|
|
Long accountId = relationship.getAccountId();
|
|
|
-
|
|
|
- String targets = request.getTargets();
|
|
|
- String sites = request.getSites();
|
|
|
-
|
|
|
- String[] targetArray = targets.split(",");
|
|
|
- String[] siteArray = sites.split(",");
|
|
|
- for (String target : targetArray) {
|
|
|
- for (String site : siteArray) {
|
|
|
- i++;
|
|
|
- // 创建广告计划配置
|
|
|
- // 广告名称:一般是“账户分组名”+“日期时间”+"自增编号"
|
|
|
- String planName = accountGroupName.trim() + "-" + dateTime + "-" + i;
|
|
|
- AdPlan adPlan = new AdPlan();
|
|
|
- adPlan.setAdPlanConfId(request.getId());
|
|
|
- adPlan.setAccountId(accountId);
|
|
|
- adPlan.setAdgroupId(0L);
|
|
|
- adPlan.setAdgroupName(planName);
|
|
|
- adPlan.setAdType(request.getAdType());
|
|
|
- adPlan.setTarget(target);
|
|
|
- adPlan.setSite(site);
|
|
|
- adPlan.setConversionId(request.getConversionId());
|
|
|
- adPlan.setDramaId(request.getDramaId());
|
|
|
- adPlan.setBidAmount(request.getBidAmount());
|
|
|
- //adType=2-ROI
|
|
|
- if (request.getAdType().equals(2)) {
|
|
|
- adPlan.setDeepConversionWorthRate(request.getDeepConversionWorthRate());
|
|
|
- } else {
|
|
|
- adPlan.setDeepConversionWorthRate(BigDecimal.ZERO);
|
|
|
- }
|
|
|
- adPlan.setWxCorpid(request.getWxCorpid());
|
|
|
- plans.add(adPlan);
|
|
|
- List<AdPlanCreative> adPlanCreatives = new ArrayList<>();
|
|
|
- adPlan.setAdCreatives(adPlanCreatives);
|
|
|
- int j = 0;
|
|
|
- for (String creativeUrl : creativeUrlArray) {
|
|
|
- String fileName = (j < creativeNameArray.length && creativeNameArray[j] != null
|
|
|
- && !creativeNameArray[j].isEmpty())
|
|
|
- ? creativeNameArray[j]
|
|
|
- : creativeUrl.substring(creativeUrl.lastIndexOf("/") + 1);
|
|
|
- String creativeName = accountGroupName.trim() + "-" + dateTime + "-" + j + "-" + fileName;
|
|
|
- AdPlanCreative adPlanCreative = new AdPlanCreative();
|
|
|
- adPlanCreative.setCreativeFileUrl(creativeUrl);
|
|
|
- adPlanCreative.setCreativeId(0L);
|
|
|
- adPlanCreative.setCreativeName(creativeName);
|
|
|
- adPlanCreative.setCreativeText(request.getCreativeText());
|
|
|
- adPlanCreative.setImageId(0L);
|
|
|
- adPlanCreative.setBrandImageId(0L);
|
|
|
- adPlanCreative.setBrandName(request.getBrandName());
|
|
|
- adPlanCreative.setBrandImageUrl(request.getBrandImageUrl());
|
|
|
- adPlanCreative.setButtonText(request.getButtonText());
|
|
|
- adPlanCreative.setPageIds(request.getPageIds());
|
|
|
- adPlanCreatives.add(adPlanCreative);
|
|
|
- j++;
|
|
|
- }
|
|
|
+ for (int k = 0; k < dramaAmount; k++) {
|
|
|
+ Long assetId = dramas.get(dramaIndex).getMarketingAssetId();
|
|
|
+ String dramaName = dramas.get(dramaIndex).getMarketingAssetName();
|
|
|
+ dramaIndex++;
|
|
|
+ for (String target : targetArray) {
|
|
|
+ for (String site : siteArray) {
|
|
|
+ // 创建广告计划配置
|
|
|
+ // 广告名称:一般是“账户分组名”+“日期时间”+"自增编号"
|
|
|
+ String planName = accountGroupName.trim() + "-" + dateTime + "-" + dramaIndex;
|
|
|
+ AdPlan adPlan = new AdPlan();
|
|
|
+ adPlan.setAdPlanConfId(request.getId());
|
|
|
+ adPlan.setAccountId(accountId);
|
|
|
+ adPlan.setAdgroupId(0L);
|
|
|
+ adPlan.setAdgroupName(planName);
|
|
|
+ adPlan.setAdType(request.getAdType());
|
|
|
+ adPlan.setTarget(target);
|
|
|
+ adPlan.setSite(site);
|
|
|
+ adPlan.setConversionId(request.getConversionId());
|
|
|
+ adPlan.setDramaId(assetId);
|
|
|
+ adPlan.setDramaName(dramaName);
|
|
|
+ adPlan.setBidAmount(request.getBidAmount());
|
|
|
+ //adType=2-ROI
|
|
|
+ if (request.getAdType().equals(2)) {
|
|
|
+ adPlan.setDeepConversionWorthRate(request.getDeepConversionWorthRate());
|
|
|
+ } else {
|
|
|
+ adPlan.setDeepConversionWorthRate(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ adPlan.setWxCorpid(request.getWxCorpid());
|
|
|
+ plans.add(adPlan);
|
|
|
+ List<AdPlanCreative> adPlanCreatives = new ArrayList<>();
|
|
|
+ adPlan.setAdCreatives(adPlanCreatives);
|
|
|
+ int j = 0;
|
|
|
+ for (String creativeUrl : creativeUrlArray) {
|
|
|
+ j++;
|
|
|
+ String fileName = (j < creativeNameArray.length && creativeNameArray[j] != null
|
|
|
+ && !creativeNameArray[j].isEmpty())
|
|
|
+ ? creativeNameArray[j]
|
|
|
+ : creativeUrl.substring(creativeUrl.lastIndexOf("/") + 1);
|
|
|
+ String creativeName = accountGroupName.trim() + "-" + dateTime + "-" + j + "-" + fileName;
|
|
|
+ AdPlanCreative adPlanCreative = new AdPlanCreative();
|
|
|
+ adPlanCreative.setCreativeFileUrl(creativeUrl);
|
|
|
+ adPlanCreative.setCreativeId(0L);
|
|
|
+ adPlanCreative.setCreativeName(creativeName);
|
|
|
+ adPlanCreative.setCreativeText(request.getCreativeText());
|
|
|
+ adPlanCreative.setImageId(0L);
|
|
|
+ adPlanCreative.setBrandImageId(0L);
|
|
|
+ adPlanCreative.setBrandName(request.getBrandName());
|
|
|
+ adPlanCreative.setBrandImageUrl(request.getBrandImageUrl());
|
|
|
+ adPlanCreative.setButtonText(request.getButtonText());
|
|
|
+ adPlanCreative.setPageIds(request.getPageIds());
|
|
|
+ adPlanCreatives.add(adPlanCreative);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
return plans;
|
|
|
}
|
|
|
@@ -172,7 +197,7 @@ public class AdPlanConfController {
|
|
|
BeanUtils.copyProperties(request, adPlanConf);
|
|
|
adPlanConfService.updateAdPlanConf(adPlanConf);
|
|
|
}
|
|
|
- List<AdPlan> plans = buildPlans(request, accountGroup, relationships);
|
|
|
+ List<AdPlan> plans = buildPlans(sysUser.getJobNumber(), request, accountGroup, relationships);
|
|
|
for (AdPlan plan : plans) {
|
|
|
plan.setAdPlanConfId(confId);
|
|
|
}
|