|
@@ -0,0 +1,120 @@
|
|
|
+package org.jeecg.modules.ads.service.impl;
|
|
|
+
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
|
|
|
+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 org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.Serializable;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class AiStrategyServiceImpl implements IAiStrategyService {
|
|
|
+ @Autowired
|
|
|
+ private IKuaiShouVideoGetService videoGetService;
|
|
|
+ @Autowired
|
|
|
+ private IAiKuaishouStrategyTargetBaseService targetBaseService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param strategyType
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void createCreativeByStrategy(Integer strategyType){
|
|
|
+ //获取账户id
|
|
|
+ Long accountId = 23212L;
|
|
|
+ //获取测试方向
|
|
|
+ String testDirection = "device_price";
|
|
|
+ //1:获取相应账户下的最新的5条素材信息
|
|
|
+ List<KuaiShouVideoGet> videoGets = videoGetService.getNewVideoByAccountId(accountId,5);
|
|
|
+ //2:根据测试方向获取相应的定向拆分数据类型
|
|
|
+ List<AiKuaishouStrategyTargetBase>targetBases = targetBaseService.listByType(testDirection);
|
|
|
+ //3:获取相应字段相应的用户定义域
|
|
|
+ String definitionDomain = "[1,2,3]";
|
|
|
+ //4:计算定向拆分逻辑
|
|
|
+ List<AiKuaishouStrategyTargetBase>getBases = splitBasesByDomain(definitionDomain,targetBases);
|
|
|
+ //5:循环创建计划,组,创意
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<AiKuaishouStrategyTargetBase> splitBasesByDomain(String definitionDomain, List<AiKuaishouStrategyTargetBase> targetBases) {
|
|
|
+ if(null == targetBases||targetBases.isEmpty()){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String type = targetBases.get(0).getType();
|
|
|
+ List<AiKuaishouStrategyTargetBase> resultBase = null;
|
|
|
+ //数字
|
|
|
+ if("number".equals(type)){
|
|
|
+ resultBase = targetBases.stream().filter(target -> definitionDomain.contains(target.getTargetContent().
|
|
|
+ replace("[","").replace("]",""))).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ //数组
|
|
|
+ if("array".equals(type)){
|
|
|
+ resultBase = targetBases.stream().filter(target -> checkContainsEveryOne(definitionDomain,target.getTargetContent())).map(target->{
|
|
|
+ target.setTargetContent(getContainsElement(definitionDomain,target.getTargetContent()));
|
|
|
+ return target;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ return resultBase;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 后期需要优化
|
|
|
+ * 判定是否存在交集
|
|
|
+ * @param definitionDomain
|
|
|
+ * @param targetContent
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean checkContainsEveryOne(String definitionDomain, String targetContent) {
|
|
|
+ JSONArray definitionDomainArray = JSONArray.parseArray(definitionDomain);
|
|
|
+ JSONArray targetContentArray = JSONArray.parseArray(targetContent);
|
|
|
+ if(definitionDomainArray.size()>=targetContentArray.size()){
|
|
|
+ return checkContains(targetContentArray,definitionDomainArray);
|
|
|
+ }
|
|
|
+ return checkContains(definitionDomainArray,targetContentArray);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param shortArray
|
|
|
+ * @param longArray
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean checkContains(JSONArray shortArray, JSONArray longArray) {
|
|
|
+ for (int i = 0; i < shortArray.size(); i++) {
|
|
|
+ if(longArray.contains(shortArray.getLong(i))){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取交集元素
|
|
|
+ * @param definitionDomain
|
|
|
+ * @param targetContent
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getContainsElement(String definitionDomain, String targetContent){
|
|
|
+ JSONArray definitionDomainArray = JSONArray.parseArray(definitionDomain);
|
|
|
+ JSONArray targetContentArray = JSONArray.parseArray(targetContent);
|
|
|
+ if(definitionDomainArray.size()>=targetContentArray.size()){
|
|
|
+ return getContainsArray(targetContentArray,definitionDomainArray);
|
|
|
+ }
|
|
|
+ return getContainsArray(definitionDomainArray,targetContentArray);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getContainsArray(JSONArray shortArray, JSONArray longArray) {
|
|
|
+ JSONArray resultArray = new JSONArray();
|
|
|
+ for (int i = 0; i < shortArray.size(); i++) {
|
|
|
+ if(longArray.contains(shortArray.getLong(i))){
|
|
|
+ resultArray.add(shortArray.getLong(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultArray.toJSONString();
|
|
|
+ }
|
|
|
+}
|