diff --git a/src/main/java/com/gitlink/softbot/service/user/impl/UserService.java b/src/main/java/com/gitlink/softbot/service/user/impl/UserService.java index 6d7b8ba..2032cd2 100644 --- a/src/main/java/com/gitlink/softbot/service/user/impl/UserService.java +++ b/src/main/java/com/gitlink/softbot/service/user/impl/UserService.java @@ -114,8 +114,10 @@ public class UserService extends AbstractUserBot implements IUserService { @Override // @Transactional(rollbackFor = Exception.class) public BotOutputVO registerBot(BotInputVO botVO) throws BotException { + log.info("开始注册Bot{}", JSON.toJSONString(botVO)); + //校验必填信息信息 + checkInfo(botVO); TransactionStatus transactionStatus = null; - DefaultTransactionDefinition transactionDefinition; Bot insertBot = null; try { @@ -123,10 +125,6 @@ public class UserService extends AbstractUserBot implements IUserService { transactionDefinition = new DefaultTransactionDefinition(); transactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); transactionStatus = transactionManager.getTransaction(transactionDefinition); - - log.info("开始注册Bot{}", JSON.toJSONString(botVO)); - //校验必填信息信息 - checkInfo(botVO); //插入Bot表 botMapper.insert(shiftObject(botVO)); insertBot = botMapper.selectOne(new QueryWrapper().eq("bot_name",botVO.getBotName())); @@ -141,7 +139,7 @@ public class UserService extends AbstractUserBot implements IUserService { log.info("注册Bot结束{}",JSON.toJSONString(shiftBotToBotOutputVo(botVO,insertBot))); transactionManager.commit(transactionStatus); - } catch (Exception e){ + } catch (BotException e){ if (transactionStatus != null) { transactionManager.rollback(transactionStatus); } @@ -319,20 +317,20 @@ public class UserService extends AbstractUserBot implements IUserService { public void checkInfo(BotInputVO botVO) throws BotException { if (botVO.getUserId()==null){ - throw new BotException("userId is null!"); + throw new BotException("Bot注册失败:userId不能为空!"); } if (StringUtils.isBlank(botVO.getBotName())){ - throw new BotException("botName is null!"); + throw new BotException("Bot注册失败:名称不能为空!"); } if (StringUtils.isBlank(botVO.getWebhook())){ - throw new BotException("webhook is null!"); + throw new BotException("Bot注册失败:webhook不能为空!"); } QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("bot_name",botVO.getBotName()); List botList = botMapper.selectList(wrapper); if (botList.size()>0){ - throw new BotException("该名称已经被使用!"); + throw new BotException("Bot注册失败:该名称已经被使用!"); } } public BotOutputVO getBotOutputVoFromLimitAndBot(Bot bot,List botLimitEvents,Integer userId,String login){