Browse Source

自动投放修改2.1

zhaoxian 3 years ago
parent
commit
c28dd9bc03

+ 16 - 4
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/AiKuaishouAccountAutoStrategyController.java

@@ -20,6 +20,8 @@ import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.common.util.RedisUtil;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.system.service.ISysRoleService;
 import org.jeecgframework.poi.excel.ExcelImportUtil;
@@ -48,6 +50,7 @@ import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -81,6 +84,9 @@ public class AiKuaishouAccountAutoStrategyController {
     @Autowired
     private IAiKuaishouAdvertiserStrategyService aiKuaishouAdvertiserStrategyService;
 
+    @Autowired
+    private RedisUtil redisUtil;
+
     /**
      * 分页列表查询
      *
@@ -96,7 +102,7 @@ public class AiKuaishouAccountAutoStrategyController {
                                                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                          HttpServletRequest req) {
         Result<PageInfo<AiKuaishouAccountAutoStrategy>> result = new Result<>();
-        if(Check.isNull(aiKuaishouAccountAutoStrategy.getUserId())){
+        if (Check.isNull(aiKuaishouAccountAutoStrategy.getUserId())) {
             result.setSuccess(false);
             result.setMessage("请选择用户");
             return result;
@@ -109,6 +115,7 @@ public class AiKuaishouAccountAutoStrategyController {
         PageInfo<AiKuaishouAccountAutoStrategy> pageInfo = aiKuaishouAccountAutoStrategyService.queryList(aiKuaishouAccountAutoStrategy);
         List<AiKuaishouAccountAutoStrategy> list = pageInfo.getList();
         List<AiKuaishouAccountAutoStrategy> setData = new ArrayList<>();
+        String date = DateUtils.formatDate(new Date());
         if (null != list && !list.isEmpty()) {
             list.forEach(record -> {
                 Long accountId = record.getAccountId();
@@ -116,9 +123,14 @@ public class AiKuaishouAccountAutoStrategyController {
                 if (null != allocation) {
                     record.setAuthName(allocation.getAuthName());
                 }
-                //TODO
-                record.setCustomCreatedUnitCnt(0);
-                record.setProgramCreatedUnitCnt(0);
+                String customkey = date + "_auto_custom_cnt_" + accountId;
+                Integer customUnitCnt = (Integer) redisUtil.get(customkey);
+                customUnitCnt = Check.isNull(customUnitCnt) ? 0 : customUnitCnt;
+                record.setCustomCreatedUnitCnt(customUnitCnt);
+                String programkey = date + "_auto_program_cnt_" + accountId;
+                Integer programUnitCnt = (Integer) redisUtil.get(programkey);
+                programUnitCnt = Check.isNull(programUnitCnt) ? 0 : programUnitCnt;
+                record.setProgramCreatedUnitCnt(programUnitCnt);
             });
         }
         pageInfo.setList(list);

+ 6 - 27
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouAccountAutoDoServiceImpl.java

@@ -356,16 +356,13 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                         Integer redisCnt = (Integer) redisUtil.get(redisKey);
                         redisUtil.set(redisKey, redisCnt - 1, 100000L);
                         unitLevelOperationRecordService.saveOrUpdate(unitRecord);
-                        if (!Check.isNull(usedchannel)) {
-                            channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, null, 0);
-                        }
                         continue;
                     }
                     Long unitId = (Long) unitCreateResult.get("unitId");
                     unitRecord.setUnitId(unitId);
                     unitLevelOperationRecordService.saveOrUpdate(unitRecord);
                     if (!Check.isNull(usedchannel)) {
-                        channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, unitId, 1);
+                        channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, unitId);
                     }
                     videoCnt--;
                     //更新自定义创建组数量
@@ -389,9 +386,6 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             } catch (Exception e) {
                 e.printStackTrace();
                 log.error("(单应用)创建自定义广告组异常", e);
-                if (!Check.isNull(usedchannel)) {
-                    channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, null, 0);
-                }
             }
         } else {
             //多应用
@@ -773,16 +767,13 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                     if (unitCode != 0) {
                         log.error("****** 程序化账户({})组创建失败,message:{}", accountId, unitMessage);
                         unitLevelOperationRecordService.saveOrUpdate(unitRecord);
-                        if (!Check.isNull(usedchannel)) {
-                            channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, null, 0);
-                        }
                         continue;
                     }
                     Long unitId = (Long) unitCreateResult.get("unitId");
                     unitRecord.setUnitId(unitId);
                     unitLevelOperationRecordService.saveOrUpdate(unitRecord);
                     if (!Check.isNull(usedchannel)) {
-                        channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, unitId, 1);
+                        channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, unitId);
                     }
                     videoCnt--;
                     //更新程序化创建组数量
@@ -808,9 +799,6 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             } catch (Exception e) {
                 e.printStackTrace();
                 log.error("(单应用)创建自定义广告组异常", e);
-                if (!Check.isNull(usedchannel)) {
-                    channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, null, 0);
-                }
             }
         } else {
             log.info("--------------------账户({})执行程序化多应用自动投放搭建:{}-----------------", accountId, typeName);
@@ -1041,16 +1029,13 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             if (unitCode != 0) {
                 log.error("****** 账户({})组创建失败,入参:{},message:{}", accountId, unitParams.toString(), unitMessage);
                 unitLevelOperationRecordService.saveOrUpdate(unitRecord);
-                if (!Check.isNull(channel)) {
-                    channelService.callBackUpdateChannelRel("group", channel.getChannelCode(), accountId, newCampaignId, null, 0);
-                }
                 continue;
             }
             Long unitId = (Long) unitCreateResult.get("unitId");
             unitRecord.setUnitId(unitId);
             unitLevelOperationRecordService.saveOrUpdate(unitRecord);
             if (!Check.isNull(channel)) {
-                channelService.callBackUpdateChannelRel("group", channel.getChannelCode(), accountId, newCampaignId, unitId, 1);
+                channelService.callBackUpdateChannelRel("group", channel.getChannelCode(), accountId, newCampaignId, unitId);
             }
             videoCnt--;
             //更新自定义创建组数量
@@ -1174,16 +1159,13 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             if (unitCode != 0) {
                 log.error("****** 程序化账户({})组创建失败,入参:{},message:{}", accountId, unitParams, unitMessage);
                 unitLevelOperationRecordService.saveOrUpdate(unitRecord);
-                if (!Check.isNull(channel)) {
-                    channelService.callBackUpdateChannelRel("group", channel.getChannelCode(), accountId, newCampaignId, null, 0);
-                }
                 continue;
             }
             Long unitId = (Long) unitCreateResult.get("unitId");
             unitRecord.setUnitId(unitId);
             unitLevelOperationRecordService.saveOrUpdate(unitRecord);
             if (!Check.isNull(channel)) {
-                channelService.callBackUpdateChannelRel("group", channel.getChannelCode(), accountId, newCampaignId, unitId, 1);
+                channelService.callBackUpdateChannelRel("group", channel.getChannelCode(), accountId, newCampaignId, unitId);
             }
             videoCnt--;
             //更新程序化创建组数量
@@ -1810,15 +1792,12 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                 log.error("****** 自动投放重构创建计划失败,入参:{},message:{}", campaignParams.toJSONString(), message);
                 record.setCampaignId(0L);
                 aiKuaishouCampaignLevelOperationRecordService.saveOrUpdate(record);
-                if (!Check.isNull(channel)) {
-                    channelService.callBackUpdateChannelRel("plan", channel.getChannelCode(), token.getAccountId(), null, null, 0);
-                }
                 return null;
             }
             campaignId = (Long) campaignCreateResult.get("campaignId");
-            //回滚channel使用锁
+
             if (!Check.isNull(channel)) {
-                channelService.callBackUpdateChannelRel("plan", channel.getChannelCode(), token.getAccountId(), campaignId, null, 1);
+                channelService.callBackUpdateChannelRel("plan", channel.getChannelCode(), token.getAccountId(), campaignId, null);
             }
             record.setCampaignId(campaignId);
             aiKuaishouCampaignLevelOperationRecordService.saveOrUpdate(record);

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

@@ -8,14 +8,35 @@ import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
 import cn.com.ctop.common.module.utils.PropertiesUtils;
-import cn.com.ctop.kuaishou.modules.ai.entity.*;
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaiShouAppInfo;
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAdvertiserStrategy;
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouCampaignLevelOperationRecord;
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouCreativeLevelOperationRecord;
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouUnitLevelOperationRecord;
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaiShouAppMultipleBids;
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouAccountCreativeOverrunInfo;
 import cn.com.ctop.kuaishou.modules.ai.enums.KuaishouCreativeAdsenceTypeEnum;
 import cn.com.ctop.kuaishou.modules.ai.enums.KuaishouCreativeMatTypeEnum;
-import cn.com.ctop.kuaishou.modules.ai.service.*;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaiShouAppInfoService;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCampaignLevelOperationRecordService;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCreateCreativeService;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCreativeLevelOperationRecordService;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouUnitLevelOperationRecordService;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouAppMultipleBidsService;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouAccountCreativeOverrunInfoService;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouLandpagePackageService;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouAppList;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
-import cn.com.ctop.kuaishou.modules.batch.service.*;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouAppListService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCampaignService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupTemplateService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService;
+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;
@@ -33,7 +54,14 @@ import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.text.ParseException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.UUID;
 
 @Slf4j
 @Service
@@ -299,9 +327,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 }
                 newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid, channel);
                 if (null == newCampaignId) {
-                    if (!Check.isNull(channel)) {
-                        channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, null, 0);
-                    }
                     return videoCnt;
                 }
                 if (useChannel == 1) {
@@ -312,9 +337,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                             if ("account".equals(level)) {
                                 usedchannel = channel;
                             } else {
-                                if (!Check.isNull(channel)) {
-                                    channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, null, 0);
-                                }
                                 return videoCnt;
                             }
                         }
@@ -389,9 +411,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     if (unitCode != 0) {
                         log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
                         unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
-                        if (!Check.isNull(usedchannel)) {
-                            channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, null, 0);
-                        }
                         continue;
                     }
                     Long unitId = (Long) unitCreateResult.get("unitId");
@@ -399,7 +418,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                     videoCnt--;
                     if (!Check.isNull(usedchannel)) {
-                        channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, unitId, 1);
+                        channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, unitId);
                     }
                     JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy, usedchannel);//TODO 添加素材
                     createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid, null);
@@ -411,9 +430,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             } catch (Exception e) {
                 e.printStackTrace();
                 log.error("创建自定义广告组异常", e);
-                if (!Check.isNull(usedchannel)) {
-                    channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, null, 0);
-                }
             }
         }
         return videoCnt;
@@ -667,9 +683,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 }
                 newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid, channel);
                 if (null == newCampaignId) {
-                    if (!Check.isNull(channel)) {
-                        channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, null, 0);
-                    }
                     return;
                 }
                 if (useChannel == 1) {
@@ -680,9 +693,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                             if ("account".equals(level)) {
                                 usedchannel = channel;
                             } else {
-                                if (!Check.isNull(channel)) {
-                                    channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, null, 0);
-                                }
                                 return;
                             }
                         }
@@ -761,16 +771,13 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     if (unitCode != 0) {
                         log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
                         unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
-                        if (!Check.isNull(usedchannel)) {
-                            channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, null, 0);
-                        }
                         continue;
                     }
                     Long unitId = (Long) unitCreateResult.get("unitId");
                     unitLevelOperationRecord.setUnitId(unitId);
                     unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                     if (!Check.isNull(usedchannel)) {
-                        channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, unitId, 1);
+                        channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, unitId);
                     }
                     JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null, usedchannel);
                     createProgramCreative(token, creativeParams, strategy);
@@ -778,9 +785,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             } catch (Exception e) {
                 e.printStackTrace();
                 log.error("创建程序化广告组异常", e);
-                if (!Check.isNull(usedchannel)) {
-                    channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, null, 0);
-                }
             }
         }
 
@@ -801,7 +805,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         Long unitNum = customUnitCnt * hour / 20;
         log.info("{}当前时间内需要创建组总数:{}", strategy.getAccountId(), unitNum);
         //查询当前账户创建自定义类型组数量
-        int unitCreateCnt = groupService.queryToDayBuiltCount(strategy.getAccountId(),4);
+        int unitCreateCnt = groupService.queryToDayBuiltCount(strategy.getAccountId(), 4);
         log.info("{}截止目前创建组总数:{}", strategy.getAccountId(), unitCreateCnt);
         long remindCnt = unitNum - unitCreateCnt;
         if (remindCnt >= 1) {
@@ -834,7 +838,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
         log.info("{}当天可创建组总数:{}", strategy.getAccountId(), unitNum);
         //查询当前账户创建自定义类型组数量
-        int unitCreateCnt = groupService.queryToDayBuiltCount(strategy.getAccountId(),4);
+        int unitCreateCnt = groupService.queryToDayBuiltCount(strategy.getAccountId(), 4);
         log.info("{}截止目前创建组总数:{}", strategy.getAccountId(), unitCreateCnt);
         long remindCnt = unitNum - unitCreateCnt;
         if (remindCnt >= 1) {
@@ -1131,7 +1135,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
         campaignId = (Long) campaignCreateResult.get("campaignId");
         if (!Check.isNull(channel)) {
-            channelService.callBackUpdateChannelRel("plan", channel.getChannelCode(), token.getAccountId(), campaignId, null, 1);
+            channelService.callBackUpdateChannelRel("plan", channel.getChannelCode(), token.getAccountId(), campaignId, null);
         }
         record.setCampaignId(campaignId);
         aiKuaishouCampaignLevelOperationRecordService.saveOrUpdate(record);

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

@@ -32,7 +32,7 @@ public interface IKuaishouChannelService extends IService<KuaishouChannel> {
 
     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);
 
     KuaishouChannel queryUsedChannel(Long accountId, Long newCampaignId, String level);
 

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

@@ -1000,7 +1000,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
 
     @Override
     public void callBackUpdateChannelRel(String level, String channelCode, Long accountId, Long planId, Long
-            groupId, Integer state) {
+            groupId) {
         try {
             QueryWrapper<KuaishouChannel> queryWrapper = new QueryWrapper<>();
             queryWrapper.eq("account_id", accountId);
@@ -1008,33 +1008,26 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
             KuaishouChannel one = this.getOne(queryWrapper);
             if (!Check.isNull(one)) {
                 one.setUpdateTime(new Date());
-                if (0 == state) {
-                    this.saveOrUpdate(one);
-                } else {
-                    QueryWrapper<KuaishouChannelRel> relqueryWrapper = new QueryWrapper<>();
-                    relqueryWrapper.eq("account_id", accountId);
-                    relqueryWrapper.eq("channel_code", channelCode).orderByAsc("create_time").last("limit 1");
-                    KuaishouChannelRel rel = channelRelService.getOne(relqueryWrapper);
-                    if (!Check.isNull(rel)) {
-                        if (!Check.isNull(rel.getCampaignId())) {
-                            rel.setId(null);
-                        }
-                        rel.setCampaignId(planId);
-                        rel.setUnitId(groupId);
-                        rel.setUpdateTime(new Date());
-                        channelRelService.save(rel);
-                        if ("plan".equals(level)) {
-                            Integer usageTimes = channelRelService.queryUsePlanCount(accountId, channelCode);
-                            one.setUsageTimes(usageTimes);
-//                            if (usageTimes > one.getHaveCycleTimes()) {
-//                                one.setHaveCycleTimes(usageTimes);
-//                            }
-                            this.saveOrUpdate(one);
-                        } else if ("group".equals(level)) {
-                            Integer usageTimes = channelRelService.queryUseGroupCount(accountId, channelCode);
-                            one.setUsageTimes(usageTimes);
-                            this.saveOrUpdate(one);
-                        }
+                QueryWrapper<KuaishouChannelRel> relqueryWrapper = new QueryWrapper<>();
+                relqueryWrapper.eq("account_id", accountId);
+                relqueryWrapper.eq("channel_code", channelCode).orderByAsc("create_time").last("limit 1");
+                KuaishouChannelRel rel = channelRelService.getOne(relqueryWrapper);
+                if (!Check.isNull(rel)) {
+                    if (!Check.isNull(rel.getCampaignId())) {
+                        rel.setId(null);
+                    }
+                    rel.setCampaignId(planId);
+                    rel.setUnitId(groupId);
+                    rel.setUpdateTime(new Date());
+                    channelRelService.save(rel);
+                    if ("plan".equals(level)) {
+                        Integer usageTimes = channelRelService.queryUsePlanCount(accountId, channelCode);
+                        one.setUsageTimes(usageTimes);
+                        this.saveOrUpdate(one);
+                    } else if ("group".equals(level)) {
+                        Integer usageTimes = channelRelService.queryUseGroupCount(accountId, channelCode);
+                        one.setUsageTimes(usageTimes);
+                        this.saveOrUpdate(one);
                     }
                 }
             }