|
|
@@ -6,14 +6,17 @@ import com.moka.gdtauto.annotation.AuthUser;
|
|
|
import com.moka.gdtauto.common.Result;
|
|
|
import com.moka.gdtauto.controller.vo.CreateAdPlanConfRequest;
|
|
|
import com.moka.gdtauto.controller.vo.UpdateAdPlanConfRequest;
|
|
|
+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.AdPlan;
|
|
|
import com.moka.gdtauto.entity.AdPlanCreative;
|
|
|
+import com.moka.gdtauto.service.SysUserService;
|
|
|
|
|
|
|
|
|
import com.moka.gdtauto.mapper.AccountGroupAccountRelationshipMapper;
|
|
|
+import com.moka.gdtauto.service.AccountGroupService;
|
|
|
import com.moka.gdtauto.service.AdPlanConfService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
@@ -26,9 +29,9 @@ import java.util.List;
|
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
|
|
/**
|
|
|
* 广告计划配置管理控制器
|
|
|
@@ -45,62 +48,21 @@ public class AdPlanConfController {
|
|
|
|
|
|
private final AdPlanConfService adPlanConfService;
|
|
|
private final AccountGroupAccountRelationshipMapper relationshipMapper;
|
|
|
+ private final SysUserService sysUserService;
|
|
|
+ private final AccountGroupService accountGroupService;
|
|
|
|
|
|
+ @Operation(summary = "预创建广告计划配置", description = "根据账户分组ID和配置ID,重新创建广告计划配置")
|
|
|
@PostMapping("/reCreate")
|
|
|
public Result<List<AdPlan>> reCreateAdPlanConf(
|
|
|
- @RequestBody CreateAdPlanConfRequest request,
|
|
|
+ @RequestBody UpdateAdPlanConfRequest request,
|
|
|
@AuthUser SysUser sysUser) {
|
|
|
try {
|
|
|
- Long accountGroupId = request.getAccountGroupId();
|
|
|
+ AccountGroup accountGroup = accountGroupService.getById(request.getAccountGroupId());
|
|
|
List<AccountGroupAccountRelationship> relationships = relationshipMapper.selectList(
|
|
|
new LambdaQueryWrapper<AccountGroupAccountRelationship>()
|
|
|
- .eq(AccountGroupAccountRelationship::getGroupId, accountGroupId));
|
|
|
- String confName = request.getName();
|
|
|
- String creativeFileUrls = request.getCreativeFileUrls();
|
|
|
- String[] creativeUrlArray = creativeFileUrls.split(",");
|
|
|
- List<AdPlan> plans = new ArrayList<>();
|
|
|
- int i = 0;
|
|
|
- for (AccountGroupAccountRelationship relationship : relationships) {
|
|
|
- Long accountId = relationship.getAccountId();
|
|
|
-
|
|
|
- String targets = request.getTargets();
|
|
|
- String sites = request.getSites();
|
|
|
+ .eq(AccountGroupAccountRelationship::getGroupId, request.getAccountGroupId()));
|
|
|
|
|
|
- String[] targetArray = targets.split(",");
|
|
|
- String[] siteArray = sites.split(",");
|
|
|
- for (String target : targetArray) {
|
|
|
- for (String site : siteArray) {
|
|
|
- i++;
|
|
|
- // 创建广告计划配置
|
|
|
- AdPlan adPlan = new AdPlan();
|
|
|
- String planName = confName + " - " + i;
|
|
|
- adPlan.setAccountId(accountId);
|
|
|
- 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());
|
|
|
- adPlan.setWxCorpid(request.getWxCorpid());
|
|
|
- plans.add(adPlan);
|
|
|
- List<AdPlanCreative> adPlanCreatives = new ArrayList<>();
|
|
|
- adPlan.setAdCreatives(adPlanCreatives);
|
|
|
- for (String creativeUrl : creativeUrlArray) {
|
|
|
- AdPlanCreative adPlanCreative = new AdPlanCreative();
|
|
|
- adPlanCreative.setCreativeFileUrl(creativeUrl);
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ List<AdPlan> plans = buildPlans(request, accountGroup, relationships);
|
|
|
|
|
|
return Result.success(plans,"重新创建广告计划配置成功");
|
|
|
} catch (Exception e) {
|
|
|
@@ -109,15 +71,84 @@ public class AdPlanConfController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private List<AdPlan> buildPlans(UpdateAdPlanConfRequest request, AccountGroup accountGroup,
|
|
|
+ List<AccountGroupAccountRelationship> relationships) {
|
|
|
+ String dateTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
|
|
+ String accountGroupName = accountGroup.getGroupName();
|
|
|
+ String creativeFileUrls = request.getCreativeFileUrls();
|
|
|
+ String creativeFileNames = request.getCreativeFileNames();
|
|
|
+ String[] creativeUrlArray = creativeFileUrls.split(",");
|
|
|
+ String[] creativeNameArray = creativeFileNames != null ? creativeFileNames.split(",") : new String[0];
|
|
|
+ List<AdPlan> plans = new ArrayList<>();
|
|
|
+ int i = 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.setAccountId(accountId);
|
|
|
+ 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());
|
|
|
+ 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.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++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return plans;
|
|
|
+ }
|
|
|
+
|
|
|
@PostMapping("/generate-plan")
|
|
|
public Result<AdPlanConf> generatePlan(
|
|
|
@RequestBody UpdateAdPlanConfRequest request,
|
|
|
@AuthUser SysUser sysUser) {
|
|
|
+
|
|
|
+ SysUser user = sysUserService.getById(sysUser.getId());
|
|
|
+ LocalDateTime userTokenExpiresAt = user.getUserTokenExpiresAt();
|
|
|
+ if (userTokenExpiresAt == null || userTokenExpiresAt.isBefore(LocalDateTime.now())) {
|
|
|
+ return Result.fail("实名认证已过期");
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
- Long accountGroupId = request.getAccountGroupId();
|
|
|
+ AccountGroup accountGroup = accountGroupService.getById(request.getAccountGroupId());
|
|
|
List<AccountGroupAccountRelationship> relationships = relationshipMapper.selectList(
|
|
|
new LambdaQueryWrapper<AccountGroupAccountRelationship>()
|
|
|
- .eq(AccountGroupAccountRelationship::getGroupId, accountGroupId));
|
|
|
+ .eq(AccountGroupAccountRelationship::getGroupId, request.getAccountGroupId()));
|
|
|
Long confId = request.getId();
|
|
|
AdPlanConf adPlanConf = new AdPlanConf();
|
|
|
if (confId == null) {
|
|
|
@@ -131,61 +162,7 @@ public class AdPlanConfController {
|
|
|
adPlanConf.setJobNumber(sysUser.getJobNumber());
|
|
|
adPlanConfService.updateAdPlanConf(adPlanConf);
|
|
|
}
|
|
|
-
|
|
|
- String confName = request.getName();
|
|
|
- String creativeFileUrls = request.getCreativeFileUrls();
|
|
|
- String[] creativeUrlArray = creativeFileUrls.split(",");
|
|
|
- List<AdPlan> plans = new ArrayList<>();
|
|
|
- int i = 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++;
|
|
|
- // 创建广告计划配置
|
|
|
- AdPlan adPlan = new AdPlan();
|
|
|
- adPlan.setAdPlanConfId(confId);
|
|
|
- String planName = confName + "-" + i;
|
|
|
- adPlan.setAccountId(accountId);
|
|
|
- adPlan.setAdgroupName(planName);
|
|
|
- adPlan.setAdgroupId(0L);
|
|
|
- adPlan.setAdType(request.getAdType());
|
|
|
- adPlan.setTarget(target);
|
|
|
- adPlan.setSite(site);
|
|
|
- adPlan.setConversionId(request.getConversionId());
|
|
|
- adPlan.setDramaId(request.getDramaId());
|
|
|
- adPlan.setBidAmount(request.getBidAmount());
|
|
|
- adPlan.setWxCorpid(request.getWxCorpid());
|
|
|
- plans.add(adPlan);
|
|
|
- List<AdPlanCreative> adPlanCreatives = new ArrayList<>();
|
|
|
- adPlan.setAdCreatives(adPlanCreatives);
|
|
|
- int j = 0;
|
|
|
- for (String creativeUrl : creativeUrlArray) {
|
|
|
- AdPlanCreative adPlanCreative = new AdPlanCreative();
|
|
|
- String creativeName = "测试创意-" + j++;
|
|
|
- adPlanCreative.setCreativeId(0L);
|
|
|
- adPlanCreative.setCreativeName(creativeName);
|
|
|
- adPlanCreative.setAdPlanConfId(confId);
|
|
|
- adPlanCreative.setAdgroupId(0L);
|
|
|
- adPlanCreative.setCreativeFileUrl(creativeUrl);
|
|
|
- adPlanCreative.setImageId(0L);
|
|
|
- adPlanCreative.setCreativeText(request.getCreativeText());
|
|
|
- adPlanCreative.setBrandName(request.getBrandName());
|
|
|
- adPlanCreative.setBrandImageUrl(request.getBrandImageUrl());
|
|
|
- adPlanCreative.setBrandImageId(0L);
|
|
|
- adPlanCreative.setButtonText(request.getButtonText());
|
|
|
- adPlanCreative.setPageIds(request.getPageIds());
|
|
|
- adPlanCreatives.add(adPlanCreative);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ List<AdPlan> plans = buildPlans(request, accountGroup, relationships);
|
|
|
|
|
|
adPlanConfService.generatePlan(plans);
|
|
|
|
|
|
@@ -201,7 +178,12 @@ public class AdPlanConfController {
|
|
|
|
|
|
|
|
|
@GetMapping("/reGeneratePlan/{id}")
|
|
|
- public Result<Void> reGeneratePlan(@PathVariable Long id) {
|
|
|
+ public Result<Void> reGeneratePlan(@PathVariable Long id, @AuthUser SysUser sysUser) {
|
|
|
+ SysUser user = sysUserService.getById(sysUser.getId());
|
|
|
+ LocalDateTime userTokenExpiresAt = user.getUserTokenExpiresAt();
|
|
|
+ if (userTokenExpiresAt == null || userTokenExpiresAt.isBefore(LocalDateTime.now())) {
|
|
|
+ return Result.fail("实名认证已过期");
|
|
|
+ }
|
|
|
adPlanConfService.asyncReGeneratePlan(id);
|
|
|
return Result.success("重新生成广告计划执行中");
|
|
|
}
|