Ver Fonte

添加伪代码块

syh há 4 anos atrás
pai
commit
da7e80665a
13 ficheiros alterados com 225 adições e 40 exclusões
  1. 22 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/controller/StrategyController.java
  2. 9 8
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/entity/AiKuaishouStrategyMapCreative.java
  3. 4 4
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/entity/AiKuaishouStrategyMiddle.java
  4. 6 2
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/entity/AiKuaishouStrategyTargetBase.java
  5. 4 4
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/entity/AiKuaishouStrategyTargetUnion.java
  6. 3 3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/entity/AiKuaishouStrategyTemplate.java
  7. 3 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/IAiKuaishouStrategyTargetBaseService.java
  8. 5 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/IAiStrategyService.java
  9. 12 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/AiKuaishouStrategyTargetBaseServiceImpl.java
  10. 120 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/AiStrategyServiceImpl.java
  11. 20 19
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/TestImpl.java
  12. 2 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouVideoGetService.java
  13. 15 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouVideoGetServiceImpl.java

+ 22 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/controller/StrategyController.java

@@ -0,0 +1,22 @@
+package org.jeecg.modules.ads.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@RestController
+@Slf4j
+@RequestMapping("/ctop/strategy")
+public class StrategyController {
+    @PostMapping("previewCreative")
+    public Map<String,Object> previewCreative(@RequestBody JSONObject data){
+        Map<String,Object>result = new HashMap<>();
+        return result;
+    }
+}

+ 9 - 8
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/entity/AiKuaishouStrategyMapCreative.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 
 import lombok.Data;
+import org.omg.CORBA.LongHolder;
 
 /**
  * 策略创意表
@@ -13,22 +14,22 @@ import lombok.Data;
 @Data
 @TableName("ctop_ai_kuaishou_strategy_map_creative")
 public class AiKuaishouStrategyMapCreative {
-    
+
 	/**id*/
 	@TableId(type = IdType.AUTO)
-	private Integer id;
+	private Long id;
 	/**账户id*/
-	private Integer accountId;
+	private Long accountId;
 	/**计划id*/
-	private Integer campaignId;
+	private Long campaignId;
 	/**组id*/
-	private Integer unitId;
+	private Long unitId;
 	/**创意id*/
-	private Integer creativeId;
+	private Long creativeId;
 	/**策略_定向关联id*/
-	private Integer strategyTargetUnionId;
+	private Long strategyTargetUnionId;
 	/**策略id*/
-	private Integer strategyId;
+	private Long strategyId;
 	/**是否创建成功*/
 	private Integer createSuccess;
 	/**失败原因*/

+ 4 - 4
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/entity/AiKuaishouStrategyMiddle.java

@@ -14,14 +14,14 @@ import lombok.Data;
 @Data
 @TableName("ctop_ai_kuaishou_strategy_middle")
 public class AiKuaishouStrategyMiddle {
-    
+
 	/**middle_id*/
 	@TableId(type = IdType.AUTO)
-	private Integer id;
+	private Long id;
 	/**策略id*/
-	private Integer strategyId;
+	private Long strategyId;
 	/**策略模板id*/
-	private Integer strategyTemplateId;
+	private Long strategyTemplateId;
 	/**createTime*/
     @ApiModelProperty(value = "createTime")
 	private Date createTime;

+ 6 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/entity/AiKuaishouStrategyTargetBase.java

@@ -14,16 +14,20 @@ import lombok.Data;
 @Data
 @TableName("ctop_ai_kuaishou_strategy_target_base")
 public class AiKuaishouStrategyTargetBase {
-    
+
 	/**target_base_id*/
 	@TableId(type = IdType.AUTO)
-	private Integer id;
+	private Long id;
 	/**定向类型:age|devices|用户行为|行业偏好等*/
 	private String targetType;
 	/**定向内容: 24-30|31-40|41-49 等*/
 	private String targetContent;
 	/**状态1可用 0不可用*/
 	private Integer status;
+	/**
+	 * 数据类型
+	 */
+	private String type;
 	/**createTime*/
     @ApiModelProperty(value = "createTime")
 	private Date createTime;

+ 4 - 4
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/entity/AiKuaishouStrategyTargetUnion.java

@@ -14,14 +14,14 @@ import lombok.Data;
 @Data
 @TableName("ctop_ai_kuaishou_strategy_target_union")
 public class AiKuaishouStrategyTargetUnion {
-    
+
 	/**strategy_target_union_id*/
 	@TableId(type = IdType.AUTO)
-	private Integer id;
+	private Long id;
 	/**middle_id*/
-	private Integer strategyMiddleId;
+	private Long strategyMiddleId;
 	/**定向id*/
-	private Integer strategyTargetId;
+	private Long strategyTargetId;
 	/**实际使用定向内用*/
 	private String actualTargetContent;
 	/**createTime*/

+ 3 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/entity/AiKuaishouStrategyTemplate.java

@@ -14,12 +14,12 @@ import lombok.Data;
 @Data
 @TableName("ctop_ai_kuaishou_strategy_template")
 public class AiKuaishouStrategyTemplate {
-    
+
 	/**策略模板id*/
 	@TableId(type = IdType.AUTO)
-	private Integer id;
+	private Long id;
 	/**账户id*/
-	private Integer accountId;
+	private Long accountId;
 	/**策略模板名称*/
 	private String templateName;
 	/**策略类型 1:素材+定向  2:时间+出价 3:素材+出价*/

+ 3 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/IAiKuaishouStrategyTargetBaseService.java

@@ -3,6 +3,8 @@ package org.jeecg.modules.ads.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.modules.ads.entity.AiKuaishouStrategyTargetBase;
 
+import java.util.List;
+
 /**
  * @Description: 定向基础表
  * @Author: jeecg-boot
@@ -11,4 +13,5 @@ import org.jeecg.modules.ads.entity.AiKuaishouStrategyTargetBase;
  */
 public interface IAiKuaishouStrategyTargetBaseService extends IService<AiKuaishouStrategyTargetBase> {
 
+    List<AiKuaishouStrategyTargetBase> listByType(String testDirection);
 }

+ 5 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/IAiStrategyService.java

@@ -0,0 +1,5 @@
+package org.jeecg.modules.ads.service;
+
+public interface IAiStrategyService {
+    void createCreativeByStrategy(Integer strategyType);
+}

+ 12 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/AiKuaishouStrategyTargetBaseServiceImpl.java

@@ -1,11 +1,14 @@
 package org.jeecg.modules.ads.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.jeecg.modules.ads.entity.AiKuaishouStrategyTargetBase;
 import org.jeecg.modules.ads.mapper.AiKuaishouStrategyTargetBaseMapper;
 import org.jeecg.modules.ads.service.IAiKuaishouStrategyTargetBaseService;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * 定向基础表
  * @author jeecg-boot
@@ -15,4 +18,13 @@ import org.springframework.stereotype.Service;
 @Service
 public class AiKuaishouStrategyTargetBaseServiceImpl extends ServiceImpl<AiKuaishouStrategyTargetBaseMapper, AiKuaishouStrategyTargetBase> implements IAiKuaishouStrategyTargetBaseService {
 
+    @Override
+    public List<AiKuaishouStrategyTargetBase> listByType(String testDirection) {
+        QueryWrapper<AiKuaishouStrategyTargetBase>queryWrapper =new QueryWrapper<>();
+        if(null!=testDirection&&!testDirection.trim().equals("")){
+            queryWrapper.eq("target_type",testDirection);
+        }
+        queryWrapper.eq("status",1);
+        return this.list(queryWrapper);
+    }
 }

+ 120 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/AiStrategyServiceImpl.java

@@ -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();
+    }
+}

+ 20 - 19
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/TestImpl.java

@@ -47,31 +47,32 @@ public class TestImpl implements Test {
     public List<String> getMaterialId(){
         // 获取素材组合方式
         // 下面这三个字段从前端传给的JSON数据进行解析得到
-        Long accountId = 7087890L;
-        Integer strategyType = 1;
-        List<AiKuaishouStrategyTemplate> StrategyTemplate =
-                strategyTemplateMapper.getStrategyTemplate(accountId,strategyType);
-
-        String materialCombinationMode = StrategyTemplate.get(0).getMaterialCombinationMode();
-        JSONObject JsonObject = JSONObject.parseObject(materialCombinationMode);
-        Integer intervalDays = (Integer) JsonObject.getJSONObject("highQualityMaterial").get("intervalDays");
-        Integer highQualityMaterialNum = (Integer) JsonObject.getJSONObject("highQualityMaterial").get("highQualityMaterialNum");
-        Integer newQualityMaterialNum = (Integer) JsonObject.get("newMaterialNum");
-
-        // 获取优质素材的签名
-        List<String> materialIds = new ArrayList<>();
-        List<KuaiShouReportDailyMaterial> highQualityMaterialIds =
-                        dailyMaterialMapper.getHighQualityMaterialId(accountId,intervalDays,highQualityMaterialNum);
-        for (KuaiShouReportDailyMaterial item: highQualityMaterialIds){
-            materialIds.add(item.getSignature());
-        }
+//        Long accountId = 7087890L;
+//        Integer strategyType = 1;
+//        List<AiKuaishouStrategyTemplate> StrategyTemplate =
+//                strategyTemplateMapper.getStrategyTemplate(accountId,strategyType);
+//
+//        String materialCombinationMode = StrategyTemplate.get(0).getMaterialCombinationMode();
+//        JSONObject JsonObject = JSONObject.parseObject(materialCombinationMode);
+//        Integer intervalDays = (Integer) JsonObject.getJSONObject("highQualityMaterial").get("intervalDays");
+//        Integer highQualityMaterialNum = (Integer) JsonObject.getJSONObject("highQualityMaterial").get("highQualityMaterialNum");
+//        Integer newQualityMaterialNum = (Integer) JsonObject.get("newMaterialNum");
+//
+//        // 获取优质素材的签名
+//        List<String> materialIds = new ArrayList<>();
+//        List<KuaiShouReportDailyMaterial> highQualityMaterialIds =
+//                        dailyMaterialMapper.getHighQualityMaterialId(accountId,intervalDays,highQualityMaterialNum);
+//        for (KuaiShouReportDailyMaterial item: highQualityMaterialIds){
+//            materialIds.add(item.getSignature());
+//        }
 
         // 获取最新上线素材的签名
 
 
 
-        return materialIds;
+//        return materialIds;
 
+        return null;
     }
 
     public static void main(String[] args) {

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouVideoGetService.java

@@ -19,4 +19,6 @@ public interface IKuaiShouVideoGetService extends IService<KuaiShouVideoGet> {
     void getKeyFrame(String token, Long accountId, String md5, String photoId);
 
     List<KuaiShouVideoGetVo> getVideoList(Map<String, Object> stringObjectMap);
+
+    List<KuaiShouVideoGet> getNewVideoByAccountId(Long accountId,Integer videoNums);
 }

+ 15 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouVideoGetServiceImpl.java

@@ -123,4 +123,19 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
     public List<KuaiShouVideoGetVo> getVideoList(Map<String, Object> requestMap) {
         return videoGetMapper.getVideoList(requestMap);
     }
+
+    @Override
+    public List<KuaiShouVideoGet> getNewVideoByAccountId(Long accountId,Integer videoNums) {
+        QueryWrapper<KuaiShouVideoGet>queryWrapper = new QueryWrapper<>();
+        if(null!=accountId&&accountId!=0){
+            queryWrapper.eq("account_id",accountId);
+        }
+        queryWrapper.orderByDesc("state_date");
+        if(null!=videoNums&&videoNums!=0){
+            queryWrapper.last("limit "+videoNums);
+        }else {
+            queryWrapper.last("limit 10");
+        }
+        return this.list(queryWrapper);
+    }
 }