From f1ca3dfcaa0e472c4fb4d449829c4f01e6b110b7 Mon Sep 17 00:00:00 2001 From: aoshiguchen <1052045476@qq.com> Date: Wed, 12 Oct 2022 20:28:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3license=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=90=8E=EF=BC=8C=E7=AB=AF=E5=8F=A3=E6=98=A0?= =?UTF-8?q?=E5=B0=84=E7=AE=A1=E7=90=86=E5=BC=82=E5=B8=B8=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/PortMappingService.java | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortMappingService.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortMappingService.java index 0aa5e03e..ac06c7f0 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortMappingService.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortMappingService.java @@ -74,27 +74,34 @@ public class PortMappingService { public Page page(PageQuery pageQuery, PortMappingListReq req) { Page page = Page.create(pageQuery); portMappingMapper.page(page, req); - if (!CollectionUtil.isEmpty(page.getRecords())) { - Set licenseIds = page.getRecords().stream().map(PortMappingListRes::getLicenseId).collect(Collectors.toSet()); - List licenseList = licenseMapper.findByIds(licenseIds); - Set userIds = licenseList.stream().map(LicenseDO::getUserId).collect(Collectors.toSet()); - List userList = userMapper.findByIds(userIds); - Map licenseMap = licenseList.stream().collect(Collectors.toMap(LicenseDO::getId, Function.identity())); - Map userMap = userList.stream().collect(Collectors.toMap(UserDO::getId, Function.identity())); - page.getRecords().forEach(item -> { - LicenseDO license = licenseMap.get(item.getLicenseId()); - if (null == license) { - return; - } - item.setLicenseName(license.getName()); - item.setUserId(license.getUserId()); - UserDO user = userMap.get(license.getUserId()); - if (null == user) { - return; - } - item.setUserName(user.getName()); - }); + if (CollectionUtil.isEmpty(page.getRecords())) { + return page; } + Set licenseIds = page.getRecords().stream().map(PortMappingListRes::getLicenseId).collect(Collectors.toSet()); + if (CollectionUtil.isEmpty(licenseIds)) { + return page; + } + List licenseList = licenseMapper.findByIds(licenseIds); + if (CollectionUtil.isEmpty(licenseList)) { + return page; + } + Set userIds = licenseList.stream().map(LicenseDO::getUserId).collect(Collectors.toSet()); + List userList = userMapper.findByIds(userIds); + Map licenseMap = licenseList.stream().collect(Collectors.toMap(LicenseDO::getId, Function.identity())); + Map userMap = userList.stream().collect(Collectors.toMap(UserDO::getId, Function.identity())); + page.getRecords().forEach(item -> { + LicenseDO license = licenseMap.get(item.getLicenseId()); + if (null == license) { + return; + } + item.setLicenseName(license.getName()); + item.setUserId(license.getUserId()); + UserDO user = userMap.get(license.getUserId()); + if (null == user) { + return; + } + item.setUserName(user.getName()); + }); return page; } @@ -196,8 +203,7 @@ public class PortMappingService { ParamCheckUtil.checkNotNull(portMappingDO, ExceptionConstant.PORT_MAPPING_NOT_EXIST); LicenseDO licenseDO = licenseMapper.findById(portMappingDO.getLicenseId()); - ParamCheckUtil.checkNotNull(licenseDO, ExceptionConstant.LICENSE_NOT_EXIST); - if (!SystemContextHolder.isAdmin()) { + if (null != licenseDO && !SystemContextHolder.isAdmin()) { // 临时处理,如果当前用户不是管理员,则操作userId不能为1 ParamCheckUtil.checkExpression(!licenseDO.getUserId().equals(1), ExceptionConstant.NO_PERMISSION_VISIT); }