修复涉及到bot名称修改时的重复检测问题

This commit is contained in:
623756217 2023-03-15 10:20:28 +08:00
parent 757c1e64d5
commit 05e88b2b65
2 changed files with 36 additions and 17 deletions

View File

@ -12,6 +12,9 @@ public interface IUserService {
BotOutputVO updateBot(BotInputVO botInputVO) throws BotException;
//返回用用户注册所有的Bot信息
GetBotResponse getBots(Integer userId);
void checkBotName(Integer botId, String botName) throws BotException;
//删除Bot
void deleteBot (DeleteBotRequest deleteBotRequest) throws BotException;
//上市Bot

View File

@ -168,6 +168,8 @@ public class UserService extends AbstractUserBot implements IUserService {
@Transactional(rollbackFor = Exception.class)
public BotOutputVO updateBot(BotInputVO botInputVO) throws BotException {
log.info("开始配置Bot{}",JSON.toJSONString(botInputVO));
// 检查 修改名称是够有重复
checkBotName(botInputVO.getBotId(),botInputVO.getBotName());
//校验是否将权限改为私有
if (botInputVO.getIsPublic()==0){
//判断是数据库中有没有安装的Bot有的话返回异常
@ -313,6 +315,18 @@ public class UserService extends AbstractUserBot implements IUserService {
return getBotResponse;
}
@Override
public void checkBotName(Integer botId, String botName) throws BotException {
QueryWrapper<Bot> wrapper = new QueryWrapper<>();
wrapper.eq("bot_name",botName);
List<Bot> botList = botMapper.selectList(wrapper);
if (botList!=null && botList.size()>0 ){
if(!botId.equals(botList.get(0).getId())){
throw new BotException("该名称已经被使用!");
}
}
}
@Override
public void checkInfo(BotInputVO botVO) throws BotException {
@ -508,6 +522,7 @@ public class UserService extends AbstractUserBot implements IUserService {
throw new BotException("该Bot未公开");
}
//判断Bot上市名称是否重复
checkBotName(botToMarketRequest.getBotId(),botToMarketRequest.getMarketName());
try {
List<MarketBot> marketBotList = marketBotMapper.selectList(new QueryWrapper<MarketBot>()
.eq("market_name", botToMarketRequest.getMarketName()));
@ -1228,24 +1243,25 @@ public class UserService extends AbstractUserBot implements IUserService {
@Override
@Transactional(rollbackFor = Exception.class)
public void updateMarketBot(BotToMarketRequest botToMarketRequest) throws BotException{
try {
MarketBot marketBot = marketBotMapper.selectOne(Wrappers
.<MarketBot>lambdaQuery().eq(MarketBot::getBotId,botToMarketRequest.getBotId()));
if (marketBot!=null){
MarketBot updateMarketBot = getDBMarketBot(botToMarketRequest);
updateMarketBot.setId(marketBot.getId());
marketBotMapper.updateById(updateMarketBot);
//同步更新bot表信息
Bot bot = botMapper.selectById(marketBot.getBotId());
bot.setBotDes(updateMarketBot.getMarketIntro());
bot.setLogo(updateMarketBot.getLogo());
bot.setBotName(updateMarketBot.getMarketName());
botMapper.updateById(bot);
}
checkBotName(botToMarketRequest.getBotId(),botToMarketRequest.getMarketName());
try {
MarketBot marketBot = marketBotMapper.selectOne(Wrappers
.<MarketBot>lambdaQuery().eq(MarketBot::getBotId,botToMarketRequest.getBotId()));
if (marketBot!=null){
MarketBot updateMarketBot = getDBMarketBot(botToMarketRequest);
updateMarketBot.setId(marketBot.getId());
marketBotMapper.updateById(updateMarketBot);
//同步更新bot表信息
Bot bot = botMapper.selectById(marketBot.getBotId());
bot.setBotDes(updateMarketBot.getMarketIntro());
bot.setLogo(updateMarketBot.getLogo());
bot.setBotName(updateMarketBot.getMarketName());
botMapper.updateById(bot);
}
}catch (Exception e){
throw new BotException("更新失败!");
}
}catch (Exception e){
throw new BotException("更新失败!");
}
}