Преглед на файлове

controller方法位置迁移

syh преди 4 години
родител
ревизия
5fe2f8c455

+ 18 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/controller/KuaishouStrategyController.java

@@ -5,6 +5,7 @@ import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouStrategy;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouStrategyService;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -12,9 +13,11 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.SecurityUtils;
 import org.checkerframework.checker.units.qual.A;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.ads.service.IAiKuaishouStrategyService;
 import org.jeecg.modules.ads.service.IAiStrategyService;
@@ -85,8 +88,6 @@ public class KuaishouStrategyController {
      * @param data
      * @return
      */
-    @AutoLog(value = "kuaishou.modules.batch-优化评估策略表-添加")
-    @ApiOperation(value = "kuaishou.modules.batch-优化评估策略表-添加", notes = "kuaishou.modules.batch-优化评估策略表-添加")
     @PostMapping(value = "/add")
     public Result<Object> add(@RequestBody JSONObject data) {
         Result<Object> result = new Result<>();
@@ -94,7 +95,21 @@ public class KuaishouStrategyController {
             if (Check.isNull(data.getLong("accountId"))) {
                 return Result.error(-1, "请选择账户");
             }
+            LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
             KuaishouStrategy strategy = JSONObject.toJavaObject(data, KuaishouStrategy.class);
+            JSONArray appStore = data.getJSONArray("appStore");
+            if(null!=appStore&&!appStore.isEmpty()){
+                strategy.setAppStore(appStore.toJSONString());
+            }
+            JSONArray siteId = data.getJSONArray("siteId");
+            if(null!=siteId&&!siteId.isEmpty()){
+                strategy.setSiteId(siteId.toJSONString());
+            }
+            JSONArray creativeTag = data.getJSONArray("creativeTag");
+            if(null!=creativeTag&&!creativeTag.isEmpty()){
+                strategy.setCreativeTag(creativeTag.toJSONString());
+            }
+            strategy.setCreateBy(user.getId());
             kuaishouStrategyService.save(strategy);
             strategyService.createCreativeByStrategy(strategy);
             result.success("添加成功!");
@@ -108,7 +123,7 @@ public class KuaishouStrategyController {
     /**
      * 编辑
      *
-     * @param kuaishouStrategy
+     * @param
      * @return
      */
     @AutoLog(value = "kuaishou.modules.batch-优化评估策略表-编辑")

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

@@ -28,7 +28,7 @@ public class AiKuaishouStrategyMapCreative {
 	/**策略_定向关联id*/
 	private Long strategyTargetUnionId;
 	/**素材签名*/
-	private String video_signature;
+	private String videoSignature;
 	/**策略id*/
 	private Long strategyId;
 	/**是否创建成功*/

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

@@ -23,9 +23,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
@@ -92,9 +90,10 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
         }
         //3:获取相应字段相应的用户定义域
         String definitionDomain = getStragyDefDomain(strategyTemplate,strategy);
+        System.out.println(definitionDomain);
         //4:计算定向拆分逻辑
         List<AiKuaishouStrategyTargetBase>getBases = splitBasesByDomain(definitionDomain,targetBases);
-        if(null == getBases){
+        if(null == getBases||getBases.isEmpty()){
             log.info("定向拆分失败=>definitionDomain:{}",definitionDomain);
             return;
         }
@@ -125,25 +124,25 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
             // 策略定向拆分数据,写入数据库
             AiKuaishouStrategyTargetUnion targetUnion = new AiKuaishouStrategyTargetUnion(strategyMiddle.getId(),item.getId(),item.getTargetContent());
             targetUnionService.save(targetUnion);
-            //拼装广告组参数
-            JSONObject unitParams = createUnitParams(token,campaignId,strategy,strategyTemplate, item,timestamp,unitCnt);
-            Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams,1);
-            Integer unitCode = (Integer) unitCreateResult.get("code");
-            String unitMessage = (String) unitCreateResult.get("message");
-            if(unitCode != 0 ){
-                log.info("组创建失败=>accountId:{};message:{}",accountId,unitMessage);
-                continue;
-            }
-            Long unitId = (Long) unitCreateResult.get("unitId");
             // 选择素材,创建创意
             for(KuaiShouVideoGet videoItem: videoGets){
-                //
-                JSONObject creativeParams = creativeParams(token,unitId,videoItem,timestamp,unitCnt,strategy);
+                //拼装广告组参数
+                JSONObject unitParams = createUnitParams(token,campaignId,strategy,strategyTemplate, item,timestamp,unitCnt);
+                Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams,1);
+                Integer unitCode = (Integer) unitCreateResult.get("code");
+                String unitMessage = (String) unitCreateResult.get("message");
+                if(unitCode != 0 ){
+                    log.info("组创建失败=>accountId:{};message:{}",accountId,unitMessage);
+                    continue;
+                }
+                Long unitId = (Long) unitCreateResult.get("unitId");
+
+                JSONObject creativeParams = creativeParams(token,unitId,videoItem,unitCnt,strategy);
                 JSONArray sceneIdJsonArray = JSONArray.parseArray(strategy.getSceneId());
                 // 如果广告位只包含 上下滑大屏广告(6),则一个素材搭配1张封面,生成1个创意
                 if (sceneIdJsonArray.contains(6) && sceneIdJsonArray.size() == 1){
                     //直接创建创意
-                    createCreative(token,creativeParams,campaignId,unitId,strategy,targetUnion,1);
+                    createCreative(token,creativeParams,campaignId,unitId,strategy,targetUnion,1,videoItem);
                 } else {
                     // 素材自带的封面 ctop_material_image_info 内部素材的自带封面,素造的没有
                     // 素材的智能抽帧封面 ctop_material_cut_frame 其中素造的为8张封面,内部的为15张封面
@@ -157,11 +156,12 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
                     int creativeCnt = 1;
                     if (null!=orgFrameList&&!orgFrameList.isEmpty()) {
                         for (int i = 0; i < orgFrameList.size(); i++) {
+                            System.out.println(creativeCnt);
                             String imageCode = orgFrameList.get(i).getCode();
                             String imageUrl = orgFrameList.get(i).getUrl();
                             String imageToken = getImageToken(imageUrl,imageCode,accountId,token.getAccessToken());
                             creativeParams.put("image_token",imageToken);
-                            createCreative(token,creativeParams,campaignId,unitId,strategy,targetUnion,creativeCnt);
+                            createCreative(token,creativeParams,campaignId,unitId,strategy,targetUnion,creativeCnt,videoItem);
                             creativeCnt++;
                             if (creativeCnt > 15) {
                                 break;
@@ -171,11 +171,12 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
 
                     if ((null!=cutFrameList&&!cutFrameList.isEmpty()) && (creativeCnt<=15)){
                         for (int i = 0; i < cutFrameList.size(); i++) {
+                            System.out.println(creativeCnt);
                             String imageCode = cutFrameList.get(i).getSignature();
                             String imageUrl = cutFrameList.get(i).getUrl();
                             String imageToken = getImageToken(imageUrl,imageCode,accountId,token.getAccessToken());
                             creativeParams.put("image_token",imageToken);
-                            createCreative(token,creativeParams,campaignId,unitId,strategy,targetUnion,creativeCnt);
+                            createCreative(token,creativeParams,campaignId,unitId,strategy,targetUnion,creativeCnt,videoItem);
                             creativeCnt ++;
                             if (creativeCnt > 15) {
                                 break;
@@ -187,30 +188,40 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
         }
     }
 
-    private JSONObject creativeParams(CtopOauthToken token,Long unitId,KuaiShouVideoGet videoItem,String timestamp,int unitCnt,KuaishouStrategy strategy){
+    private JSONObject creativeParams(CtopOauthToken token,Long unitId,KuaiShouVideoGet videoItem,int unitCnt,KuaishouStrategy strategy){
         JSONObject creativeParams = new JSONObject();
         creativeParams.put("advertiser_id",token.getAccountId());
-
         creativeParams.put("unit_id",unitId);
         creativeParams.put("photo_id",videoItem.getPhotoId());
-        creativeParams.put("creative_name","智能创意-"+timestamp+unitCnt+"-"+1);
+        String uuid = UUID.randomUUID().toString();
+        creativeParams.put("creative_name","智能创意-"+uuid+unitCnt+"-"+1);
         creativeParams.put("creative_material_type",videoItem.getMaterialType());
         creativeParams.put("action_bar_text","立即下载");
         //TODO 广告语
         creativeParams.put("description","测试广告语");
         // 安卓下载中间页ID
-        if(null == strategy.getSiteId()||!"".equals(strategy.getSiteId())){
-            creativeParams.put("site_id",strategy.getSiteId());
+        JSONArray siteIdArray = JSONArray.parseArray(strategy.getSiteId());
+        if(null == siteIdArray||!siteIdArray.isEmpty()){
+            JSONObject siteObject = siteIdArray.getJSONObject(0);
+            Long appId = siteObject.getLong("appId");
+            Long siteId = siteObject.getLong("siteId");
+            if(null!=siteId){
+                creativeParams.put("site_id",siteId);
+            }
         }
-        if(null == strategy.getClickTrackUrl()||!"".equals(strategy.getClickTrackUrl())){
+        if(null != strategy.getClickTrackUrl()&&!"".equals(strategy.getClickTrackUrl())){
             creativeParams.put("click_track_url",strategy.getClickTrackUrl());
         }
-        if(null == strategy.getImpressionUrl()||!"".equals(strategy.getImpressionUrl())){
+        if(null != strategy.getImpressionUrl()&&!"".equals(strategy.getImpressionUrl())){
             creativeParams.put("impression_url",strategy.getImpressionUrl());
         }
-        if(null == strategy.getActionbarClickUrl()||!"".equals(strategy.getActionbarClickUrl())){
+        if(null != strategy.getActionbarClickUrl()&&!"".equals(strategy.getActionbarClickUrl())){
             creativeParams.put("actionbar_click_url",strategy.getActionbarClickUrl());
         }
+        if(null!=strategy.getCreativeCategory()){
+            creativeParams.put("creative_category",strategy.getCreativeCategory());
+            creativeParams.put("creative_tag",JSONArray.parseArray(strategy.getCreativeTag()));
+        }
         return creativeParams;
     }
 
@@ -237,9 +248,10 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
         JSONObject unitParams = new JSONObject();
         unitParams.put("advertiser_id",token.getAccountId());
         unitParams.put("campaign_id",campaignId);
-        unitParams.put("unit_name", strategy.getStrategyName() + item.getTargetType() +
-                item.getTargetContent() + timestamp + unitCnt);
+        String uuid = UUID.randomUUID().toString();
+        unitParams.put("unit_name", strategy.getStrategyName() + item.getTargetType() + item.getTargetContent() + uuid + unitCnt);
         unitParams.put("bid_type",10);
+        unitParams.put("ocpx_action_type",180);
 
         if(null!=strategy.getUseAppMarket()&&!"".equals(strategy.getUseAppMarket())){
             unitParams.put("use_app_market",Integer.parseInt(strategy.getUseAppMarket()));
@@ -310,7 +322,7 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
         return unitParams;
     }
     private void createCreative(CtopOauthToken token,JSONObject creativeParams,Long campaignId,Long unitId,
-                                KuaishouStrategy strategy,AiKuaishouStrategyTargetUnion targetUnion,int creativeCnt){
+                                KuaishouStrategy strategy,AiKuaishouStrategyTargetUnion targetUnion,int creativeCnt,KuaiShouVideoGet videoGet){
         creativeParams.put("creative_name",creativeParams.getString("creative_name")+creativeCnt);
         Map<String, Object> creativeCreateResult = kuaishouInterfaceService.creativeCreate
                 (token.getAccessToken(), token.getAccountId(), creativeParams,1);
@@ -325,6 +337,8 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
         mapCreative.setAccountId(token.getAccountId());
         mapCreative.setCampaignId(campaignId);
         mapCreative.setUnitId(unitId);
+        //TODO 添加
+        mapCreative.setVideoSignature(videoGet.getSignature());
         mapCreative.setCreativeId(creativeId);
         mapCreative.setStrategyId(strategy.getId());
         mapCreative.setStrategyTargetUnionId(targetUnion.getId());
@@ -392,8 +406,12 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
      */
     private boolean checkContains(JSONArray shortArray, JSONArray longArray) {
         for (int i = 0; i < shortArray.size(); i++) {
-            if(longArray.contains(shortArray.getLong(i))){
-                return true;
+            Long s = shortArray.getLong(i);
+            for(int j=0;j<longArray.size();j++){
+                Long l = longArray.getLong(j);
+                if(s.equals(l)){
+                    return true;
+                }
             }
         }
         return false;
@@ -408,19 +426,23 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
     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) {
+    private String getContainsArray(JSONArray definitionDomainArray, JSONArray targetContentArray) {
+        log.info("definitionDomainArray:"+definitionDomainArray.toJSONString());
+        log.info("targetContentArray:"+targetContentArray.toJSONString());
         JSONArray resultArray = new JSONArray();
-        for (int i = 0; i < shortArray.size(); i++) {
-            if(longArray.contains(shortArray.getLong(i))){
-                resultArray.add(shortArray.getLong(i));
+        for (int i = 0; i < definitionDomainArray.size(); i++) {
+            Long s = definitionDomainArray.getLong(i);
+            for(int j=0;j<targetContentArray.size();j++){
+                Long l = targetContentArray.getLong(j);
+                if(l.equals(s)){
+                    resultArray.add(l);
+                }
             }
         }
+        log.info("result:"+resultArray.toJSONString());
         return resultArray.toJSONString();
     }
 }

+ 4 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaishouStrategy.java

@@ -32,6 +32,9 @@ public class KuaishouStrategy {
     @TableId(type = IdType.AUTO)
     @ApiModelProperty(value = "id")
     private Long id;
+    private String createBy;
+    private String creativeTag;
+    private Integer creativeCategory;
     /**
      * 账户ID
      */
@@ -169,7 +172,7 @@ public class KuaishouStrategy {
      */
     @Excel(name = "转化目标出价", width = 15)
     @ApiModelProperty(value = "转化目标出价")
-    private Integer cpaBid;
+    private Long cpaBid;
     /**
      * 深度转化目标 3: 付费,7: 次日留存,10: 完件, 11: 授信 ,0:无
      */

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

@@ -130,7 +130,7 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
         if(null!=accountId&&accountId!=0){
             queryWrapper.eq("account_id",accountId);
         }
-        queryWrapper.orderByDesc("state_date");
+        queryWrapper.orderByDesc("stat_date");
         if(null!=videoNums&&videoNums!=0){
             queryWrapper.last("limit "+videoNums);
         }else {