Просмотр исходного кода

渠道号。。。修改查询渠道逻辑

zhaoxian 4 лет назад
Родитель
Сommit
d52122fbc2

+ 1 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/AiKuaishouAdvertiserStrategy.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.kuaishou.modules.ai.entity;
 
+import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelItems;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;

+ 38 - 17
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouCreateCreativeServiceImpl.java

@@ -38,6 +38,7 @@ import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannel;
+import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelItems;
 import cn.com.ctop.kuaishou.modules.channel.service.IKuaishouChannelService;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
@@ -289,11 +290,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         } else {
             //单一应用
             String replaceString = KuaishouCreativeMatTypeEnum.getNameByType(strategy.getUnitType().toString() + createType.toString());
-            List<KuaiShouVideoGet> newVideos = getVideosByParams(strategy, startTime, endTime, null, createType, videoCnt);
-            if (null == newVideos || newVideos.isEmpty()) {
-                log.info("账户:{},{} 到 {} 未获取到相应素材({})", accountId, startTime, endTime, replaceString);
-                return videoCnt;
-            }
             Long appId = null;
             String appName = null;
             if (strategy.getCampaignType() == 2 || strategy.getCampaignType() == 7) {
@@ -312,7 +308,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             KuaishouChannel channel = null;
             if (!Check.isNull(useChannel) && useChannel == 1 && ("account".equals(level) || "plan".equals(level))) {
                 try {
-                    Result<Object> result = channelService.queryChannel(accountId, level, appName);
+                    Result<Object> result = channelService.queryChannel(accountId, level, appName, null);
                     Integer code = result.getCode();
                     if (code == 200) {
                         channel = (KuaishouChannel) result.getResult();
@@ -334,6 +330,19 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             if (null == newCampaignId) {
                 return videoCnt;
             }
+            channel = channelService.queryUsedChannel(accountId, newCampaignId, level);
+            if (Check.isNull(channel)) {
+                return videoCnt;
+            }
+            List<KuaishouChannelItems> items = channel.getItems();
+            if (!Check.isNull(items) && !items.isEmpty()) {
+                strategy.setMaterialKeyword(items.get(0).getKeyword());
+            }
+            List<KuaiShouVideoGet> newVideos = getVideosByParams(strategy, startTime, endTime, null, createType, videoCnt);
+            if (null == newVideos || newVideos.isEmpty()) {
+                log.info("账户:{},{} 到 {} 未获取到相应素材({})", accountId, startTime, endTime, replaceString);
+                return videoCnt;
+            }
             //3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
             for (KuaiShouVideoGet videoItem : newVideos) {
                 Boolean unitOverrun = getUnitOverrun(accountId);
@@ -355,7 +364,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 //获取组级渠道号
                 if (!Check.isNull(useChannel) && useChannel == 1 && "group".equals(level)) {
                     try {
-                        Result<Object> result = channelService.queryChannel(accountId, level, appName);
+                        Result<Object> result = channelService.queryChannel(accountId, level, appName, videoItem.getPhotoName());
                         Integer code = result.getCode();
                         if (code == 200) {
                             channel = (KuaishouChannel) result.getResult();
@@ -395,7 +404,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
                     unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                     if (!Check.isNull(channel)) {
-                        channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, null,0);
+                        channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, null, 0);
                     }
                     continue;
                 }
@@ -404,7 +413,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                 videoCnt--;
                 if (!Check.isNull(channel)) {
-                    channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, unitId,1);
+                    channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, unitId, 1);
                 }
                 JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy, channel);//TODO 添加素材
                 createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid, null);
@@ -624,10 +633,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         } else {
             String replaceString = KuaishouCreativeMatTypeEnum.getNameByType(strategy.getUnitType().toString() + createType.toString());
             //单一应用
-            List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, null, createType, videoCnt);
-            if (null == allVideos) {
-                return;
-            }
             Long appId = null;
             String appName = null;
             String appIdString = strategy.getAppIdArray();
@@ -649,7 +654,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             KuaishouChannel channel = null;
             if (!Check.isNull(useChannel) && useChannel == 1 && ("account".equals(level) || "plan".equals(level))) {
                 try {
-                    Result<Object> result = channelService.queryChannel(accountId, level, appName);
+                    Result<Object> result = channelService.queryChannel(accountId, level, appName, null);
                     Integer code = result.getCode();
                     if (code == 200) {
                         channel = (KuaishouChannel) result.getResult();
@@ -671,6 +676,18 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             if (null == newCampaignId) {
                 return;
             }
+            channel = channelService.queryUsedChannel(accountId, newCampaignId, level);
+            if (Check.isNull(channel)) {
+                return;
+            }
+            List<KuaishouChannelItems> items = channel.getItems();
+            if (!Check.isNull(items) && !items.isEmpty()) {
+                strategy.setMaterialKeyword(items.get(0).getKeyword());
+            }
+            List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, null, createType, videoCnt);
+            if (null == allVideos) {
+                return;
+            }
             //创意
             List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 5);
             for (int j = 1; j < splitVideos.size() + 1; j++) {
@@ -691,7 +708,11 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 //获取组级渠道号
                 if (!Check.isNull(useChannel) && useChannel == 1 && "group".equals(level)) {
                     try {
-                        Result<Object> result = channelService.queryChannel(accountId, level, appName);
+                        KuaiShouVideoGet videoGet = splitVideos.get(1).get(0);
+                        if (Check.isNull(videoGet)) {
+                            return;
+                        }
+                        Result<Object> result = channelService.queryChannel(accountId, level, appName, videoGet.getPhotoName());
                         Integer code = result.getCode();
                         if (code == 200) {
                             channel = (KuaishouChannel) result.getResult();
@@ -733,7 +754,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
                     unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                     if (!Check.isNull(channel)) {
-                        channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, null,0);
+                        channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, null, 0);
                     }
                     return;
                 }
@@ -741,7 +762,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 unitLevelOperationRecord.setUnitId(unitId);
                 unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                 if (!Check.isNull(channel)) {
-                    channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, unitId,1);
+                    channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, unitId, 1);
                 }
                 JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null, channel);
                 createProgramCreative(token, creativeParams, strategy);

+ 2 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/mapper/KuaishouChannelMapper.java

@@ -45,4 +45,6 @@ public interface KuaishouChannelMapper extends BaseMapper<KuaishouChannel> {
     List<KuaishouChannel> queryChannelByHaveCycleTimes(@Param("haveCycleTimes") Integer haveCycleTimes, @Param("usageLevel") String usageLevel, @Param("strategys") List<KuaishouChannelCreateStrategy> strategys);
 
     List<JSONObject> queryItemsListByAccountId(@Param("accountId") Long accountId, @Param("appName") String appName);
+
+    KuaishouChannel queryUsedChannel(@Param("accountId") Long accountId,@Param("campaignId") Long campaignId,@Param("level") String level);
 }

+ 11 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/mapper/xml/KuaishouChannelMapper.xml

@@ -269,4 +269,15 @@
             tt2.item_name
     </select>
 
+
+    <select id="queryUsedChannel" resultType="cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannel">
+        SELECT t2.* FROM ctop_kuaishou_channel_rel t1
+        INNER JOIN ctop_kuaishou_channel t2 ON t1.account_id = t2.account_id AND t1.channel_code = t2.channel_code
+        WHERE t2.account_id = #{accountId}
+          AND t2.usage_level = #{level}
+          AND t2.state = 1
+          AND t1.campaign_id =#{campaignId}
+          LIMIT 1
+    </select>
+
 </mapper>

+ 1 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/service/IKuaishouChannelRelService.java

@@ -12,7 +12,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IKuaishouChannelRelService extends IService<KuaishouChannelRel> {
 
-    KuaishouChannelRel queryByAccountChannelCode(String channelCode, Long accountId,String appName);
+    KuaishouChannelRel queryByAccountChannelCode(String channelCode, Long accountId, String appName);
 
     Integer queryUsePlanCount(Long accountId, String channelCode);
 

+ 4 - 2
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/service/IKuaishouChannelService.java

@@ -30,9 +30,11 @@ public interface IKuaishouChannelService extends IService<KuaishouChannel> {
 
     Result<Object> customizedCreate(JSONObject request, Integer createType) throws Exception;
 
-    Result<Object> queryChannel(Long accountId, String usageLevel,String appName) throws Exception;
+    Result<Object> queryChannel(Long accountId, String usageLevel, String appName, String photoName) throws Exception;
 
     Result<Object> queryChannelLevel(JSONObject request);
 
-    void callBackUpdateChannelRel(String level, String channelCode, Long accoountId, Long planId, Long groupId,Integer state);
+    void callBackUpdateChannelRel(String level, String channelCode, Long accoountId, Long planId, Long groupId, Integer state);
+
+    KuaishouChannel queryUsedChannel(Long accountId, Long newCampaignId, String level);
 }

+ 3 - 3
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/service/impl/KuaishouChannelRelServiceImpl.java

@@ -20,17 +20,17 @@ public class KuaishouChannelRelServiceImpl extends ServiceImpl<KuaishouChannelRe
     private KuaishouChannelRelMapper channelRelMapper;
 
     @Override
-    public KuaishouChannelRel queryByAccountChannelCode(String channelCode, Long accountId,String appName) {
+    public KuaishouChannelRel queryByAccountChannelCode(String channelCode, Long accountId, String appName) {
         return channelRelMapper.queryByAccountChannelCode(channelCode, accountId, appName);
     }
 
     @Override
     public Integer queryUsePlanCount(Long accountId, String channelCode) {
-        return channelRelMapper.queryUsePlanCount(accountId,  channelCode);
+        return channelRelMapper.queryUsePlanCount(accountId, channelCode);
     }
 
     @Override
     public Integer queryUseGroupCount(Long accountId, String channelCode) {
-        return channelRelMapper.queryUseGroupCount(accountId,  channelCode);
+        return channelRelMapper.queryUseGroupCount(accountId, channelCode);
     }
 }

+ 31 - 6
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/service/impl/KuaishouChannelServiceImpl.java

@@ -152,7 +152,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
         List<JSONObject> list = channelMapper.channelNumberUsageDetailsList(kuaishouChannel);
         for (JSONObject jsonObject : list) {
             String time = kuaiShouCreativeService.querMaxCreateTime(jsonObject.getLong("unitId"));
-            jsonObject.put("createTime",time);
+            jsonObject.put("createTime", time);
         }
         PageInfo pageInfo = new PageInfo(list);
         pageInfo.setTotal(total);
@@ -962,7 +962,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
     }
 
     @Override
-    public Result<Object> queryChannel(Long accountId, String level, String appName) throws Exception {
+    public Result<Object> queryChannel(Long accountId, String level, String appName, String photoName) throws Exception {
         //查询账户策略
         List<KuaishouChannelCreateStrategy> strategys = channelCreateStrategyService.queryChannelStrategyByAccountId(accountId);
         if (Check.isNull(strategys) || strategys.isEmpty()) {
@@ -989,7 +989,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                 return doPlanLevel(accountId, strategys, appName, 0);
             } else if ("group".equals(usageLevel)) {
                 //---------------------组层级---------------------
-                return doGroupLevel(accountId, strategys, appName, 0);
+                return doGroupLevel(accountId, strategys, appName, 0, photoName);
             }
         } else {
             /**============================项目范围============================*/
@@ -1001,7 +1001,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                 return doPlanLevel(accountId, strategys, appName, 0);
             } else if ("group".equals(usageLevel)) {
                 //---------------------组层级---------------------
-                return doGroupLevel(accountId, strategys, appName, 0);
+                return doGroupLevel(accountId, strategys, appName, 0, photoName);
             }
         }
         return Result.error("未查到渠道号");
@@ -1068,6 +1068,19 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
         }
     }
 
+    @Override
+    public KuaishouChannel queryUsedChannel(Long accountId, Long newCampaignId, String level) {
+        KuaishouChannel channel = channelMapper.queryUsedChannel(accountId, newCampaignId, level);
+        if (channel.getIsHaveItem() == 1) {
+            List<KuaishouChannelItems> list = channelItemsRelService.queryItems(channel.getId());
+            if (Check.isNull(list) || list.isEmpty()) {
+                return null;
+            }
+            channel.setItems(list);
+        }
+        return channel;
+    }
+
     private Result<Object> doAccountRangeAccountLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys, String appName) throws Exception {
         List<KuaishouChannel> channelList = channelMapper.queryByAccountIdLevel(accountId, "account");
         if (!Check.isNull(channelList)) {
@@ -1153,7 +1166,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
     }
 
     //通过项目范围广告组层级查询
-    private Result<Object> doGroupLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys, String appName, int count) throws Exception {
+    private Result<Object> doGroupLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys, String appName, int count, String photoName) throws Exception {
         List<Integer> haveCycleTimesList = channelMapper.queryUsedLevel(strategys);
         if (Check.isNull(haveCycleTimesList)) {
             return Result.error("渠道号已无效");
@@ -1169,6 +1182,18 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                 Integer usageTimes = channel.getUsageTimes();//使用次数
                 //优先判断已经循环的次数 大于 使用次数
                 if (haveCycleTimes > usageTimes) {
+                    if (!Check.isNull(channel.getIsHaveItem()) && channel.getIsHaveItem() == 1) {
+                        //有单品
+                        List<KuaishouChannelItems> itemsList = channelItemsRelService.queryItems(channel.getId());
+                        if (Check.isNull(itemsList) || itemsList.isEmpty()) {
+                            continue;
+                        }
+                        //素材名字和单品关键字做匹配
+                        String keyword = itemsList.get(0).getKeyword();
+                        if (!photoName.contains(keyword)) {
+                            continue;
+                        }
+                    }
                     // 符合条件,获取该渠道号
                     KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId, appName);
                     if (Check.isNull(channelRel)) {
@@ -1204,7 +1229,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
             }
         }
         if (count == 0) {
-            return doGroupLevel(accountId, strategys, appName, 1);
+            return doGroupLevel(accountId, strategys, appName, 1, photoName);
         }
         return Result.ok("未查询到渠道号");
     }