Explorar el Código

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

zhaoxian hace 3 años
padre
commit
0c3e79028b

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

@@ -330,12 +330,17 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             if (null == newCampaignId) {
                 return videoCnt;
             }
+            KuaishouChannel usedchannel = null;
             if (useChannel == 1) {
-                channel = channelService.queryUsedChannel(accountId, newCampaignId, level);
-                if (Check.isNull(channel)) {
-                    return videoCnt;
+                usedchannel = channelService.queryUsedChannel(accountId, newCampaignId, level);
+                if (Check.isNull(usedchannel)) {
+                    if ("account".equals(level)) {
+                        usedchannel = channel;
+                    } else {
+                        return videoCnt;
+                    }
                 }
-                List<KuaishouChannelItems> items = channel.getItems();
+                List<KuaishouChannelItems> items = usedchannel.getItems();
                 if (!Check.isNull(items) && !items.isEmpty()) {
                     strategy.setMaterialKeyword(items.get(0).getKeyword());
                 }
@@ -369,12 +374,12 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         Result<Object> result = channelService.queryChannel(accountId, level, appName, videoItem.getPhotoName());
                         Integer code = result.getCode();
                         if (code == 200) {
-                            channel = (KuaishouChannel) result.getResult();
-                            if (Check.isNull(channel)) {
+                            usedchannel = (KuaishouChannel) result.getResult();
+                            if (Check.isNull(usedchannel)) {
                                 log.info("(组级)账户:{},{}", accountId, result.getMessage());
                                 continue;
                             } else {
-                                log.info("(组级)获取到渠道号:{}", channel.getChannelCode());
+                                log.info("(组级)获取到渠道号:{}", usedchannel.getChannelCode());
                             }
                         } else {
                             log.error("(组级)通过账户(" + accountId + ")未获取到渠道号!!!");
@@ -384,8 +389,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         e.printStackTrace();
                     }
                 }
-                String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appId, channel);
-                JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, channel);
+                String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appId, usedchannel);
+                JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, usedchannel);
                 log.info("创建广告组入参:{}", unitParams);
                 Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
                 Integer unitCode = (Integer) unitCreateResult.get("code");
@@ -405,8 +410,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 if (unitCode != 0) {
                     log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
                     unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
-                    if (!Check.isNull(channel)) {
-                        channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, null, 0);
+                    if (!Check.isNull(usedchannel)) {
+                        channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, null, 0);
                     }
                     continue;
                 }
@@ -414,10 +419,10 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 unitLevelOperationRecord.setUnitId(unitId);
                 unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                 videoCnt--;
-                if (!Check.isNull(channel)) {
-                    channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, unitId, 1);
+                if (!Check.isNull(usedchannel)) {
+                    channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, unitId, 1);
                 }
-                JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy, channel);//TODO 添加素材
+                JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy, usedchannel);//TODO 添加素材
                 createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid, null);
                 if (videoCnt <= 0) {
                     return 0L;
@@ -678,12 +683,17 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             if (null == newCampaignId) {
                 return;
             }
+            KuaishouChannel usedchannel = null;
             if (useChannel == 1) {
-                channel = channelService.queryUsedChannel(accountId, newCampaignId, level);
-                if (Check.isNull(channel)) {
-                    return;
+                usedchannel = channelService.queryUsedChannel(accountId, newCampaignId, level);
+                if (Check.isNull(usedchannel)) {
+                    if ("account".equals(level)) {
+                        usedchannel = channel;
+                    } else {
+                        return ;
+                    }
                 }
-                List<KuaishouChannelItems> items = channel.getItems();
+                List<KuaishouChannelItems> items = usedchannel.getItems();
                 if (!Check.isNull(items) && !items.isEmpty()) {
                     strategy.setMaterialKeyword(items.get(0).getKeyword());
                 }
@@ -719,12 +729,12 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         Result<Object> result = channelService.queryChannel(accountId, level, appName, videoGet.getPhotoName());
                         Integer code = result.getCode();
                         if (code == 200) {
-                            channel = (KuaishouChannel) result.getResult();
-                            if (Check.isNull(channel)) {
+                            usedchannel = (KuaishouChannel) result.getResult();
+                            if (Check.isNull(usedchannel)) {
                                 log.info("(组级)账户:{},{}", accountId, result.getMessage());
                                 continue;
                             } else {
-                                log.info("(组级)获取到渠道号:{}", channel.getChannelCode());
+                                log.info("(组级)获取到渠道号:{}", usedchannel.getChannelCode());
                             }
                         } else {
                             log.error("(组级)通过账户(" + accountId + ")未获取到渠道号!!!");
@@ -736,8 +746,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 }
 
                 //创建组
-                String unitName = getName(strategy.getGroupName(), strategy, createType, null, "unit", newCampaignId, appId, channel);
-                JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, channel);
+                String unitName = getName(strategy.getGroupName(), strategy, createType, null, "unit", newCampaignId, appId, usedchannel);                JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, usedchannel);
                 log.info("创建广告组入参:{}", unitParams);
                 Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
                 Integer unitCode = (Integer) unitCreateResult.get("code");
@@ -757,8 +766,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 if (unitCode != 0) {
                     log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
                     unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
-                    if (!Check.isNull(channel)) {
-                        channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, null, 0);
+                    if (!Check.isNull(usedchannel)) {
+                        channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, null, 0);
                     }
                     return;
                 }
@@ -768,7 +777,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 if (!Check.isNull(channel)) {
                     channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, unitId, 1);
                 }
-                JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null, channel);
+                JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null, usedchannel);
                 createProgramCreative(token, creativeParams, strategy);
             }
         }

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

@@ -1071,7 +1071,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
     @Override
     public KuaishouChannel queryUsedChannel(Long accountId, Long newCampaignId, String level) {
         KuaishouChannel channel = channelMapper.queryUsedChannel(accountId, newCampaignId, level);
-        if (!Check.isNull(channel)&&channel.getIsHaveItem() == 1) {
+        if (!Check.isNull(channel) && channel.getIsHaveItem() == 1) {
             List<KuaishouChannelItems> list = channelItemsRelService.queryItems(channel.getId());
             if (Check.isNull(list) || list.isEmpty()) {
                 return null;
@@ -1085,11 +1085,12 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
         List<KuaishouChannel> channelList = channelMapper.queryByAccountIdLevel(accountId, "account");
         if (!Check.isNull(channelList)) {
             for (KuaishouChannel channel : channelList) {
-                if(channel.getIsHaveItem() == 1){
+                if (channel.getIsHaveItem() == 1) {
                     List<KuaishouChannelItems> list = channelItemsRelService.queryItems(channel.getId());
                     if (Check.isNull(list) || list.isEmpty()) {
                         continue;
                     }
+                    channel.setItems(list);
                 }
                 KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId, appName);
                 if (Check.isNull(channelRel)) {
@@ -1131,11 +1132,12 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                 Integer usageTimes = channel.getUsageTimes();//使用次数
                 //优先判断已经循环的次数 大于 使用次数
                 if (haveCycleTimes > usageTimes) {
-                    if(channel.getIsHaveItem() == 1){
+                    if (channel.getIsHaveItem() == 1) {
                         List<KuaishouChannelItems> items = channelItemsRelService.queryItems(channel.getId());
                         if (Check.isNull(items) || items.isEmpty()) {
                             continue;
                         }
+                        channel.setItems(items);
                     }
                     // 符合条件,获取该渠道号
                     KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId, appName);