From ee5549ebb04cffd976a95fbe3a585dbfaa8b8ac2 Mon Sep 17 00:00:00 2001 From: wanjia <553039491@qq.com> Date: Fri, 31 Mar 2023 11:29:16 +0800 Subject: [PATCH] =?UTF-8?q?getAllInstallBots=E6=8E=A5=E5=8F=A3=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E4=BB=93=E5=BA=93=E5=8F=82=E6=95=B0=EF=BC=9BjudgeIsIn?= =?UTF-8?q?stallBot=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9=E5=8F=82=E6=95=B0?= =?UTF-8?q?=20=E4=BB=93=E5=BA=93=E6=8B=A5=E6=9C=89=E8=80=85->=E4=BB=93?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/user/UserController.java | 13 ++++--- .../softbot/service/user/IUserService.java | 5 +-- .../service/user/impl/UserService.java | 37 ++++++++++++------- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/gitlink/softbot/controller/user/UserController.java b/src/main/java/com/gitlink/softbot/controller/user/UserController.java index a48418c..a75e907 100644 --- a/src/main/java/com/gitlink/softbot/controller/user/UserController.java +++ b/src/main/java/com/gitlink/softbot/controller/user/UserController.java @@ -291,14 +291,14 @@ public class UserController { /** * 判断是否安装该bot - * @param repoOwners + * @param repos * @param botId * @return */ @GetMapping("/judgeIsIntallBot") - public Result judgeIsInstallBot(@RequestParam("repo_owner") List repoOwners, @RequestParam("bot_id") Integer botId){ + public Result judgeIsInstallBot(@RequestParam("repos") String repos, @RequestParam("bot_id") Integer botId){ - JudgeIsInstallBotResponse judgeIsInstallBotResponse = userService.judgeIsInstallBot(repoOwners,botId); + JudgeIsInstallBotResponse judgeIsInstallBotResponse = userService.judgeIsInstallBot(repos,botId); Result result = new Result<>(); return result.build(judgeIsInstallBotResponse).build(200).build("success!"); } @@ -309,9 +309,12 @@ public class UserController { * @return */ @GetMapping("/getAllInstallBots") - public Result getAllInstallBots(@RequestParam("user_id") Integer userId){ - GetAllInstallBotsResponse getAllInstallBotsResponse = userService.getAllInstallBots(userId); + public Result getAllInstallBots(@RequestParam("user_id") Integer userId, @RequestParam("repos") String repos){ Result result = new Result<>(); + if(userId == null && (repos == null || "".equals(repos))) { + return result.build("传入参数不能全空").build(500).build("fail!"); + } + GetAllInstallBotsResponse getAllInstallBotsResponse = userService.getAllInstallBots(userId, repos); return result. build(getAllInstallBotsResponse). build(200). diff --git a/src/main/java/com/gitlink/softbot/service/user/IUserService.java b/src/main/java/com/gitlink/softbot/service/user/IUserService.java index 29ea366..397d218 100644 --- a/src/main/java/com/gitlink/softbot/service/user/IUserService.java +++ b/src/main/java/com/gitlink/softbot/service/user/IUserService.java @@ -2,7 +2,6 @@ package com.gitlink.softbot.service.user; import com.gitlink.softbot.global.exception.BotException; import com.gitlink.softbot.vo.*; -import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -52,9 +51,9 @@ public interface IUserService { //拒绝接收转让Bot void refuseTransferBot(RefuseTransferBotRequest refuseTransferBotRequest) throws BotException; //判断是否安装过此bot - JudgeIsInstallBotResponse judgeIsInstallBot(List repoOwners, Integer botId); + JudgeIsInstallBotResponse judgeIsInstallBot(String repos, Integer botId); - GetAllInstallBotsResponse getAllInstallBots(Integer userId); + GetAllInstallBotsResponse getAllInstallBots(Integer userId, String repos); GetStoreAllInstallBotResponse getStoreAllInstallBots(Integer storeId); 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 733e1b3..bbb3d61 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 @@ -1129,29 +1129,30 @@ public class UserService extends AbstractUserBot implements IUserService { /** * 判断该用户是否安装此bot - * @param repoOwners + * @param repos * @param botId * @return */ @Override - public JudgeIsInstallBotResponse judgeIsInstallBot(List repoOwners, Integer botId) { + public JudgeIsInstallBotResponse judgeIsInstallBot(String repos, Integer botId) { JudgeIsInstallBotResponse judgeIsInstallBotResponse = new JudgeIsInstallBotResponse(); - List installOwnerList = new ArrayList<>(); - List unInstallOwnerList = new ArrayList<>(); - for (String repoOwner : repoOwners) { + List installRepoList = new ArrayList<>(); + List unInstallRepoList = new ArrayList<>(); + List repoList = Arrays.asList(repos.split(",")); + for (String repo : repoList) { //如果公开,则判断安装表里面有没有该用户安装的bot List installBots = installMapper.selectList(Wrappers. lambdaQuery().eq(InstallBot::getBotId, botId) - .eq(InstallBot::getRepoOwner, repoOwner)); + .eq(InstallBot::getStoreRepo, repo)); if (!Objects.isNull(installBots) && installBots.size() > 0) { - installOwnerList.add(repoOwner); + installRepoList.add(repo); } else { - unInstallOwnerList.add(repoOwner); + unInstallRepoList.add(repo); } } - judgeIsInstallBotResponse.setInstallOwners(installOwnerList); - judgeIsInstallBotResponse.setUninstallOwners(unInstallOwnerList); + judgeIsInstallBotResponse.setInstallOwners(installRepoList); + judgeIsInstallBotResponse.setUninstallOwners(unInstallRepoList); return judgeIsInstallBotResponse; } @@ -1190,14 +1191,22 @@ public class UserService extends AbstractUserBot implements IUserService { /** * 获取用户安装所有bot信息 * @param userId + * @param repos * @return */ @Override - public GetAllInstallBotsResponse getAllInstallBots(Integer userId) { - - List installBots = installMapper.selectList(Wrappers.lambdaQuery() - .eq(InstallBot::getInstallerId,userId)); + public GetAllInstallBotsResponse getAllInstallBots(Integer userId, String repos) { + List installBots = new ArrayList<>(); + List repoList = Arrays.asList(repos.split(",")); + if(userId != null) { + installBots = installMapper.selectList(Wrappers.lambdaQuery() + .eq(InstallBot::getInstallerId,userId)); + } + if(repos != null && repoList.size() > 0) { + installBots = installMapper.selectList(Wrappers.lambdaQuery() + .in(InstallBot::getStoreRepo, repoList)); + } Map botAndAllRepoOwnerMap = new HashMap<>(); for(InstallBot installBot : installBots) {