diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/security/TenantSecurityWebFilter.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/security/TenantSecurityWebFilter.java index 5995dc02d..41ffef03b 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/security/TenantSecurityWebFilter.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/security/TenantSecurityWebFilter.java @@ -78,8 +78,8 @@ public class TenantSecurityWebFilter extends ApiRequestFilter { // 2. 如果请求未带租户的编号,不允许访问。 if (tenantId == null) { log.error("[doFilterInternal][URL({}/{}) 未传递租户编号]", request.getRequestURI(), request.getMethod()); - String msg = "请求的租户标识未传递,请进行排查"; - ServletUtils.writeJSON(response, CommonResult.error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(), msg)); + ServletUtils.writeJSON(response, CommonResult.error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(), + "请求的租户标识未传递,请进行排查")); return; } // 3. 校验租户是合法,例如说被禁用、到期 diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java index 33a108bc4..342fa4611 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java @@ -1,6 +1,8 @@ package cn.iocoder.yudao.framework.mybatis.core.query; import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; @@ -40,14 +42,14 @@ public class LambdaQueryWrapperX extends LambdaQueryWrapper { } public LambdaQueryWrapperX eqIfPresent(SFunction column, Object val) { - if (val instanceof String && StringUtils.hasText((String) val) || !(val instanceof String) && val != null) { + if (ObjectUtil.isNotEmpty(val)) { return (LambdaQueryWrapperX) super.eq(column, val); } return this; } public LambdaQueryWrapperX neIfPresent(SFunction column, Object val) { - if (val instanceof String && StringUtils.hasText((String) val) || !(val instanceof String) && val != null) { + if (ObjectUtil.isNotEmpty(val)) { return (LambdaQueryWrapperX) super.ne(column, val); } return this; diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 693c9b8ef..344a13d4c 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -103,7 +103,7 @@ public interface ErrorCodeConstants { ErrorCode TENANT_DISABLE = new ErrorCode(1002015001, "名字为【{}】的租户已被禁用"); ErrorCode TENANT_EXPIRE = new ErrorCode(1002015002, "名字为【{}】的租户已过期"); ErrorCode TENANT_CAN_NOT_UPDATE_SYSTEM = new ErrorCode(1002015003, "系统租户不能进行修改、删除等操作!"); - ErrorCode TENANT_NAME_DUPLICATE = new ErrorCode(1002015004, "已经存在该名称的租户"); + ErrorCode TENANT_NAME_DUPLICATE = new ErrorCode(1002015004, "名字为【{}】的租户已存在"); // ========== 租户套餐 1002016000 ========== ErrorCode TENANT_PACKAGE_NOT_EXISTS = new ErrorCode(1002016000, "租户套餐不存在"); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenant/TenantMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenant/TenantMapper.java index 92a0f9975..8731e4628 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenant/TenantMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenant/TenantMapper.java @@ -38,12 +38,6 @@ public interface TenantMapper extends BaseMapperX { .orderByDesc(TenantDO::getId)); } - default Long selectCountByName(String name, Long id) { - return selectCount(new LambdaQueryWrapperX() - .eqIfPresent(TenantDO::getName, name) - .neIfPresent(TenantDO::getId, id)); - } - default TenantDO selectByName(String name) { return selectOne(TenantDO::getName, name); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java index ad1fa180f..1664ff6e3 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java @@ -29,7 +29,6 @@ import cn.iocoder.yudao.module.system.service.permission.RoleService; import cn.iocoder.yudao.module.system.service.tenant.handler.TenantInfoHandler; import cn.iocoder.yudao.module.system.service.tenant.handler.TenantMenuHandler; import cn.iocoder.yudao.module.system.service.user.AdminUserService; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; @@ -99,8 +98,7 @@ public class TenantServiceImpl implements TenantService { @Transactional(rollbackFor = Exception.class) public Long createTenant(TenantCreateReqVO createReqVO) { // 校验租户名称是否重复 - validTenantName(createReqVO.getName(), null); - + validTenantNameDuplicate(createReqVO.getName(), null); // 校验套餐被禁用 TenantPackageDO tenantPackage = tenantPackageService.validTenantPackage(createReqVO.getPackageId()); @@ -143,10 +141,8 @@ public class TenantServiceImpl implements TenantService { public void updateTenant(TenantUpdateReqVO updateReqVO) { // 校验存在 TenantDO tenant = validateUpdateTenant(updateReqVO.getId()); - // 校验租户名称是否重复 - validTenantName(updateReqVO.getName(), updateReqVO.getId()); - + validTenantNameDuplicate(updateReqVO.getName(), updateReqVO.getId()); // 校验套餐被禁用 TenantPackageDO tenantPackage = tenantPackageService.validTenantPackage(updateReqVO.getPackageId()); @@ -159,9 +155,17 @@ public class TenantServiceImpl implements TenantService { } } - protected void validTenantName(String tenantName, Long id) { - if (tenantMapper.selectCountByName(tenantName, id) > 0) { - throw exception(TENANT_NAME_DUPLICATE); + private void validTenantNameDuplicate(String name, Long id) { + TenantDO tenant = tenantMapper.selectByName(name); + if (tenant == null) { + return; + } + // 如果 id 为空,说明不用比较是否为相同名字的租户 + if (id == null) { + throw exception(TENANT_NAME_DUPLICATE, name); + } + if (!tenant.getId().equals(id)) { + throw exception(TENANT_NAME_DUPLICATE, name); } } diff --git a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java index 5a8da1b20..b118e5fe7 100644 --- a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java +++ b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java @@ -5,7 +5,6 @@ import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.util.collection.SetUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.io.FileUtils; import java.io.File; import java.nio.charset.StandardCharsets; @@ -87,7 +86,7 @@ public class ProjectReactor { } private static Collection listFiles(String projectBaseDir) { - Collection files = FileUtils.listFiles(new File(projectBaseDir), null, true); + Collection files = FileUtil.loopFiles(projectBaseDir); // 移除 IDEA、Git 自身的文件、Node 编译出来的文件 files = files.stream() .filter(file -> !file.getPath().contains(separator + "target" + separator)