|
@@ -1,47 +1,163 @@
|
|
package org.jeecg.modules.ads.service.impl;
|
|
package org.jeecg.modules.ads.service.impl;
|
|
|
|
|
|
|
|
+import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
|
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
|
|
+import cn.com.ctop.common.module.service.IOauthAgentTokenService;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouStrategy;
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
-import org.jeecg.modules.ads.entity.AiKuaishouStrategyTargetBase;
|
|
|
|
-import org.jeecg.modules.ads.service.IAiKuaishouStrategyTargetBaseService;
|
|
|
|
-import org.jeecg.modules.ads.service.IAiStrategyService;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import groovy.util.logging.Slf4j;
|
|
|
|
+import org.jeecg.modules.ads.entity.*;
|
|
|
|
+import org.jeecg.modules.ads.service.*;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.Serializable;
|
|
import java.io.Serializable;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
+@Slf4j
|
|
@Service
|
|
@Service
|
|
public class AiStrategyServiceImpl implements IAiStrategyService {
|
|
public class AiStrategyServiceImpl implements IAiStrategyService {
|
|
@Autowired
|
|
@Autowired
|
|
private IKuaiShouVideoGetService videoGetService;
|
|
private IKuaiShouVideoGetService videoGetService;
|
|
@Autowired
|
|
@Autowired
|
|
private IAiKuaishouStrategyTargetBaseService targetBaseService;
|
|
private IAiKuaishouStrategyTargetBaseService targetBaseService;
|
|
-
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IAiKuaishouStrategyTemplateService templateService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IAiKuaishouStrategyMiddleService middleService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IAiKuaishouStrategyTargetUnionService targetUnionService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaishouInterfaceService kuaishouInterfaceService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ICtopOauthTokenService tokenService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IAiKuaishouStrategyMapCreativeService mapCreativeService;
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
- * @param strategyType
|
|
|
|
|
|
+ * @param strategy
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public void createCreativeByStrategy(Integer strategyType){
|
|
|
|
|
|
+ public void createCreativeByStrategy(KuaishouStrategy strategy){
|
|
//获取账户id
|
|
//获取账户id
|
|
- Long accountId = 23212L;
|
|
|
|
- //获取测试方向
|
|
|
|
- String testDirection = "device_price";
|
|
|
|
- //1:获取相应账户下的最新的5条素材信息
|
|
|
|
|
|
+ Long accountId = strategy.getAccountId();
|
|
|
|
+ CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
|
|
|
|
+ if(null == token){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ //策略类型
|
|
|
|
+ String scenes = strategy.getScenes();
|
|
|
|
+ //根据策略类型获取策略模板信息
|
|
|
|
+ AiKuaishouStrategyTemplate strategyTemplate = templateService.getOneByParams(scenes, 1);
|
|
|
|
+ if(null == strategyTemplate){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ //1:获取相应账户下的最新的5条素材信息 TODO
|
|
List<KuaiShouVideoGet> videoGets = videoGetService.getNewVideoByAccountId(accountId,5);
|
|
List<KuaiShouVideoGet> videoGets = videoGetService.getNewVideoByAccountId(accountId,5);
|
|
|
|
+ if(null == videoGets){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
//2:根据测试方向获取相应的定向拆分数据类型
|
|
//2:根据测试方向获取相应的定向拆分数据类型
|
|
- List<AiKuaishouStrategyTargetBase>targetBases = targetBaseService.listByType(testDirection);
|
|
|
|
|
|
+ List<AiKuaishouStrategyTargetBase>targetBases = targetBaseService.listByType(strategyTemplate.getTestDirection());
|
|
|
|
+ if(null == targetBases){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
//3:获取相应字段相应的用户定义域
|
|
//3:获取相应字段相应的用户定义域
|
|
- String definitionDomain = "[1,2,3]";
|
|
|
|
|
|
+ String definitionDomain = null;
|
|
|
|
+
|
|
|
|
+ if (strategyTemplate.getTestDirection().equals("age"))
|
|
|
|
+ definitionDomain = strategy.getAgesRange();
|
|
|
|
+ if (strategyTemplate.getTestDirection().equals("gender"))
|
|
|
|
+ definitionDomain = strategy.getGender().toString();
|
|
|
|
+ if (strategyTemplate.getTestDirection().equals("region"))
|
|
|
|
+ definitionDomain = strategy.getRegion();
|
|
|
|
+ if (strategyTemplate.getTestDirection().equals("operation_system"))
|
|
|
|
+ definitionDomain = strategy.getPlatformOs().toString();
|
|
|
|
+
|
|
//4:计算定向拆分逻辑
|
|
//4:计算定向拆分逻辑
|
|
List<AiKuaishouStrategyTargetBase>getBases = splitBasesByDomain(definitionDomain,targetBases);
|
|
List<AiKuaishouStrategyTargetBase>getBases = splitBasesByDomain(definitionDomain,targetBases);
|
|
|
|
+ if(null == getBases){
|
|
|
|
+ //TODO
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ //5、策略--策略模板 关联表,写入数据库
|
|
|
|
+ AiKuaishouStrategyMiddle strategyMiddle =
|
|
|
|
+ new AiKuaishouStrategyMiddle(strategyTemplate.getId(),strategy.getId());
|
|
|
|
+ middleService.save(strategyMiddle);
|
|
|
|
+
|
|
|
|
+ //6、策略定向拆分数据,写入数据库
|
|
|
|
+ for (AiKuaishouStrategyTargetBase item:getBases) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
//5:循环创建计划,组,创意
|
|
//5:循环创建计划,组,创意
|
|
|
|
+ //拼装计划创建 入参 json
|
|
|
|
+ JSONObject campaignParams = new JSONObject();
|
|
|
|
+ Map<String, Object> campaignCreateResult = kuaishouInterfaceService.campaignCreate(token.getAccessToken(),
|
|
|
|
+ token.getAccountId(), campaignParams);
|
|
|
|
+ Integer code = (Integer) campaignCreateResult.get("code");
|
|
|
|
+ if(code != 0 ){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ Long campaignId = (Long) campaignCreateResult.get("campaignId");
|
|
|
|
+ for (AiKuaishouStrategyTargetBase item:getBases) {
|
|
|
|
+ AiKuaishouStrategyTargetUnion targetUnion = new AiKuaishouStrategyTargetUnion();
|
|
|
|
+ targetUnion.setStrategyMiddleId(strategyMiddle.getId());
|
|
|
|
+ targetUnion.setStrategyTargetId(item.getId());
|
|
|
|
+ targetUnion.setActualTargetContent(item.getTargetContent());
|
|
|
|
+ targetUnionService.save(targetUnion);
|
|
|
|
+
|
|
|
|
+ for(KuaiShouVideoGet videoItem: videoGets){
|
|
|
|
+ JSONObject unitParams = new JSONObject();
|
|
|
|
+ Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(),
|
|
|
|
+ token.getAccountId(), unitParams,1);
|
|
|
|
+ Integer unitCode = (Integer) unitCreateResult.get("code");
|
|
|
|
+ if(unitCode != 0 ){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ JSONObject creativeParams = new JSONObject();
|
|
|
|
+ Map<String, Object> creativeCreateResult = kuaishouInterfaceService.creativeCreate
|
|
|
|
+ (token.getAccessToken(), token.getAccountId(), creativeParams,1);
|
|
|
|
+ Integer creativeCode = (Integer) creativeCreateResult.get("code");
|
|
|
|
+ if(creativeCode != 0 ){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ Long creativeId = (Long) creativeCreateResult.get("creativeId");
|
|
|
|
+ AiKuaishouStrategyMapCreative mapCreative = new AiKuaishouStrategyMapCreative();
|
|
|
|
+ mapCreative.setAccountId(token.getAccountId());
|
|
|
|
+ mapCreative.setCampaignId(campaignId);
|
|
|
|
+ mapCreative.setUnitId(unitId);
|
|
|
|
+ mapCreative.setCreativeId(creativeId);
|
|
|
|
+ mapCreative.setStrategyId(strategy.getId());
|
|
|
|
+ mapCreative.setStrategyTargetUnionId(targetUnion.getId());
|
|
|
|
+ mapCreativeService.save(mapCreative);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
- private List<AiKuaishouStrategyTargetBase> splitBasesByDomain(String definitionDomain, List<AiKuaishouStrategyTargetBase> targetBases) {
|
|
|
|
|
|
+ private List<AiKuaishouStrategyTargetBase> splitBasesByDomain(String definitionDomain,
|
|
|
|
+ List<AiKuaishouStrategyTargetBase> targetBases) {
|
|
|
|
+ if(null==definitionDomain){
|
|
|
|
+ return targetBases;
|
|
|
|
+ }
|
|
if(null == targetBases||targetBases.isEmpty()){
|
|
if(null == targetBases||targetBases.isEmpty()){
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
@@ -49,8 +165,8 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
|
|
List<AiKuaishouStrategyTargetBase> resultBase = null;
|
|
List<AiKuaishouStrategyTargetBase> resultBase = null;
|
|
//数字
|
|
//数字
|
|
if("number".equals(type)){
|
|
if("number".equals(type)){
|
|
- resultBase = targetBases.stream().filter(target -> definitionDomain.contains(target.getTargetContent().
|
|
|
|
- replace("[","").replace("]",""))).collect(Collectors.toList());
|
|
|
|
|
|
+ resultBase = targetBases.stream().filter(target -> definitionDomain.equals(target.getTargetContent())).
|
|
|
|
+ collect(Collectors.toList());
|
|
}
|
|
}
|
|
//数组
|
|
//数组
|
|
if("array".equals(type)){
|
|
if("array".equals(type)){
|