修改bot注册失败时信息提示

This commit is contained in:
623756217 2023-03-14 19:55:10 +08:00
parent bc37b5521f
commit fff5fe241f
1 changed files with 8 additions and 10 deletions

View File

@ -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<Bot>().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<Bot> wrapper = new QueryWrapper<>();
wrapper.eq("bot_name",botVO.getBotName());
List<Bot> botList = botMapper.selectList(wrapper);
if (botList.size()>0){
throw new BotException("该名称已经被使用!");
throw new BotException("Bot注册失败该名称已经被使用!");
}
}
public BotOutputVO getBotOutputVoFromLimitAndBot(Bot bot,List<BotLimitEvent> botLimitEvents,Integer userId,String login){