解决license数据删除后,端口映射管理异常的问题

This commit is contained in:
aoshiguchen
2022-10-12 20:28:24 +08:00
parent 5a928d1660
commit 94fe6f8aef
@@ -74,9 +74,17 @@ public class PortMappingService {
public Page<PortMappingListRes> page(PageQuery pageQuery, PortMappingListReq req) { public Page<PortMappingListRes> page(PageQuery pageQuery, PortMappingListReq req) {
Page<PortMappingListRes> page = Page.create(pageQuery); Page<PortMappingListRes> page = Page.create(pageQuery);
portMappingMapper.page(page, req); portMappingMapper.page(page, req);
if (!CollectionUtil.isEmpty(page.getRecords())) { if (CollectionUtil.isEmpty(page.getRecords())) {
return page;
}
Set<Integer> licenseIds = page.getRecords().stream().map(PortMappingListRes::getLicenseId).collect(Collectors.toSet()); Set<Integer> licenseIds = page.getRecords().stream().map(PortMappingListRes::getLicenseId).collect(Collectors.toSet());
if (CollectionUtil.isEmpty(licenseIds)) {
return page;
}
List<LicenseDO> licenseList = licenseMapper.findByIds(licenseIds); List<LicenseDO> licenseList = licenseMapper.findByIds(licenseIds);
if (CollectionUtil.isEmpty(licenseList)) {
return page;
}
Set<Integer> userIds = licenseList.stream().map(LicenseDO::getUserId).collect(Collectors.toSet()); Set<Integer> userIds = licenseList.stream().map(LicenseDO::getUserId).collect(Collectors.toSet());
List<UserDO> userList = userMapper.findByIds(userIds); List<UserDO> userList = userMapper.findByIds(userIds);
Map<Integer, LicenseDO> licenseMap = licenseList.stream().collect(Collectors.toMap(LicenseDO::getId, Function.identity())); Map<Integer, LicenseDO> licenseMap = licenseList.stream().collect(Collectors.toMap(LicenseDO::getId, Function.identity()));
@@ -94,7 +102,6 @@ public class PortMappingService {
} }
item.setUserName(user.getName()); item.setUserName(user.getName());
}); });
}
return page; return page;
} }
@@ -196,8 +203,7 @@ public class PortMappingService {
ParamCheckUtil.checkNotNull(portMappingDO, ExceptionConstant.PORT_MAPPING_NOT_EXIST); ParamCheckUtil.checkNotNull(portMappingDO, ExceptionConstant.PORT_MAPPING_NOT_EXIST);
LicenseDO licenseDO = licenseMapper.findById(portMappingDO.getLicenseId()); LicenseDO licenseDO = licenseMapper.findById(portMappingDO.getLicenseId());
ParamCheckUtil.checkNotNull(licenseDO, ExceptionConstant.LICENSE_NOT_EXIST); if (null != licenseDO && !SystemContextHolder.isAdmin()) {
if (!SystemContextHolder.isAdmin()) {
// 临时处理,如果当前用户不是管理员,则操作userId不能为1 // 临时处理,如果当前用户不是管理员,则操作userId不能为1
ParamCheckUtil.checkExpression(!licenseDO.getUserId().equals(1), ExceptionConstant.NO_PERMISSION_VISIT); ParamCheckUtil.checkExpression(!licenseDO.getUserId().equals(1), ExceptionConstant.NO_PERMISSION_VISIT);
} }