From ff50cdce0fa9094264adf552062fd293bff530fd Mon Sep 17 00:00:00 2001 From: tonglin <97326827@qq.com> Date: Mon, 9 Jan 2023 11:23:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0bot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../advice/GlobalExceptionAdvice.java | 3 +- .../service/user/impl/UserService.java | 41 ++++++++++++------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/gitlink/softbot/global/exception/advice/GlobalExceptionAdvice.java b/src/main/java/com/gitlink/softbot/global/exception/advice/GlobalExceptionAdvice.java index b500980..49d241e 100644 --- a/src/main/java/com/gitlink/softbot/global/exception/advice/GlobalExceptionAdvice.java +++ b/src/main/java/com/gitlink/softbot/global/exception/advice/GlobalExceptionAdvice.java @@ -14,8 +14,9 @@ public class GlobalExceptionAdvice { public Result handleCouponException( HttpServletRequest request, BotException exception ){ - Result response = new Result<>(-1,"business error!"); + Result response = new Result<>(500,"server error!"); response.setData(exception.getMessage()); + response.setMessage(exception.getMessage()); return response; } } 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 ba4564d..2e644c3 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 @@ -121,14 +121,17 @@ public class UserService extends AbstractUserBot implements IUserService { Bot updateBot = shiftObject(botInputVO); Integer id = botInputVO.getBotId(); updateBot.setId(id); - MarketBot marketBot = marketBotMapper.selectById(id); - marketBot.setMarketIntro(updateBot.getBotDes()); - marketBot.setLogo(updateBot.getLogo()); try { - marketBotMapper.updateById(marketBot); + MarketBot marketBot = marketBotMapper.selectById(id); + if (marketBot!=null){ + marketBot.setMarketIntro(updateBot.getBotDes()); + marketBot.setLogo(updateBot.getLogo()); + marketBot.setMarketName(updateBot.getBotName()); + marketBotMapper.updateById(marketBot); + } botMapper.updateById(updateBot); }catch (DuplicateKeyException e){ - throw new BotException("Bot名称已经存在!"); + throw new BotException("Bot更新失败!"); } boolean flag = false; @@ -421,12 +424,18 @@ public class UserService extends AbstractUserBot implements IUserService { MarketBot marketBot = getDBMarketBot(botToMarketRequest); //更新市场bot的安装次数,bot在上市前,可能通过详情页面被安装过 marketBot.setInstallNum(bot.getInstallNum()); + + //更新bot表中详细信息 + bot.setBotDes(marketBot.getMarketIntro()); + bot.setBotName(marketBot.getMarketName()); + bot.setLogo(marketBot.getLogo()); + botMapper.updateById(bot); marketBotMapper.insert(marketBot); // //2.es添加数据 // com.gitlink.softbot.entity.es.MarketBot marketBot1 = getESMarketBot(botToMarketRequest); // marketService.saveMarketBot(marketBot1); }catch (DuplicateKeyException e){ - throw new BotException("bot已经上市!"); + throw new BotException("上市失败!"); } log.info("Bot上市成功!{}",botToMarketRequest); } @@ -905,14 +914,18 @@ public class UserService extends AbstractUserBot implements IUserService { try { MarketBot marketBot = marketBotMapper.selectOne(Wrappers .lambdaQuery().eq(MarketBot::getBotId,botToMarketRequest.getBotId())); - MarketBot updateMarketBot = getDBMarketBot(botToMarketRequest); - updateMarketBot.setId(marketBot.getId()); - marketBotMapper.updateById(updateMarketBot); - //同步更新bot表信息 - Bot bot = botMapper.selectById(marketBot.getId()); - bot.setBotDes(updateMarketBot.getMarketIntro()); - bot.setLogo(updateMarketBot.getLogo()); - botMapper.updateById(bot); + if (marketBot!=null){ + MarketBot updateMarketBot = getDBMarketBot(botToMarketRequest); + updateMarketBot.setId(marketBot.getId()); + marketBotMapper.updateById(updateMarketBot); + //同步更新bot表信息 + Bot bot = botMapper.selectById(marketBot.getId()); + bot.setBotDes(updateMarketBot.getMarketIntro()); + bot.setLogo(updateMarketBot.getLogo()); + bot.setBotName(updateMarketBot.getMarketName()); + botMapper.updateById(bot); + } + }catch (Exception e){ throw new BotException("更新失败!"); }