From 1bd86d6ffd8d53bce07e594bcb2b3243fe177983 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 1 May 2022 01:12:27 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=20Oracle=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=201.=20=E8=A7=A3=E5=86=B3=20Menu=20=E7=9A=84?= =?UTF-8?q?=20permission=20=E4=B8=BA=E7=A9=BA=EF=BC=8C=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E5=88=9D=E5=A7=8B=E5=8C=96=E6=8A=A5=E9=94=99?= =?UTF-8?q?=202.=20=E5=A4=9A=E7=A7=9F=E6=88=B7=E6=8B=A6=E6=88=AA=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E8=BF=87=E6=BB=A4=E6=8E=89=20DUAL=20=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=20TENANT=5FID=20=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E4=B8=8D=E5=AD=98=E5=9C=A8=E7=9A=84=E6=8A=A5=E9=94=99=203.=20B?= =?UTF-8?q?aseDO=20=E5=A2=9E=E5=8A=A0=20creator=E3=80=81updator=20?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E7=9A=84=20jdbcType=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E8=A7=A3=E6=9E=90=20null=20=E5=80=BC=E6=8A=A5?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/db/TenantDatabaseInterceptor.java | 21 ++++++++++++++----- .../mybatis/core/dataobject/BaseDO.java | 6 +++--- .../service/permission/MenuServiceImpl.java | 5 ++++- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/db/TenantDatabaseInterceptor.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/db/TenantDatabaseInterceptor.java index 146fa0430..8ea1a96b8 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/db/TenantDatabaseInterceptor.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/db/TenantDatabaseInterceptor.java @@ -4,29 +4,40 @@ import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.tenant.config.TenantProperties; import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler; -import lombok.AllArgsConstructor; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.LongValue; +import java.util.HashSet; +import java.util.Set; + /** * 基于 MyBatis Plus 多租户的功能,实现 DB 层面的多租户的功能 * * @author 芋道源码 */ -@AllArgsConstructor public class TenantDatabaseInterceptor implements TenantLineHandler { - private final TenantProperties properties; + private final Set ignoreTables = new HashSet<>(); + + public TenantDatabaseInterceptor(TenantProperties properties) { + // 不同 DB 下,大小写的习惯不同,所以需要都添加进去 + properties.getIgnoreTables().forEach(table -> { + ignoreTables.add(table.toLowerCase()); + ignoreTables.add(table.toUpperCase()); + }); + // 在 OracleKeyGenerator 中,生成主键时,会查询这个表,查询这个表后,会自动拼接 TENANT_ID 导致报错 + ignoreTables.add("DUAL"); + } @Override public Expression getTenantId() { - return new LongValue( TenantContextHolder.getRequiredTenantId()); + return new LongValue(TenantContextHolder.getRequiredTenantId()); } @Override public boolean ignoreTable(String tableName) { return TenantContextHolder.isIgnore() // 情况一,全局忽略多租户 - || CollUtil.contains(properties.getIgnoreTables(), tableName); // 情况二,忽略多租户的表 + || CollUtil.contains(ignoreTables, tableName); // 情况二,忽略多租户的表 } } diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/dataobject/BaseDO.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/dataobject/BaseDO.java index e3df175f5..7bb555450 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/dataobject/BaseDO.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/dataobject/BaseDO.java @@ -3,8 +3,8 @@ package cn.iocoder.yudao.framework.mybatis.core.dataobject; import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableLogic; -import lombok.Builder; import lombok.Data; +import org.apache.ibatis.type.JdbcType; import java.io.Serializable; import java.util.Date; @@ -32,14 +32,14 @@ public abstract class BaseDO implements Serializable { * * 使用 String 类型的原因是,未来可能会存在非数值的情况,留好拓展性。 */ - @TableField(fill = FieldFill.INSERT) + @TableField(fill = FieldFill.INSERT, jdbcType = JdbcType.VARCHAR) private String creator; /** * 更新者,目前使用 SysUser 的 id 编号 * * 使用 String 类型的原因是,未来可能会存在非数值的情况,留好拓展性。 */ - @TableField(fill = FieldFill.INSERT_UPDATE) + @TableField(fill = FieldFill.INSERT_UPDATE, jdbcType = JdbcType.VARCHAR) private String updater; /** * 是否删除 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java index 149f6c7b4..8a7fe1892 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.system.service.permission; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuCreateReqVO; @@ -95,7 +96,9 @@ public class MenuServiceImpl implements MenuService { ImmutableMultimap.Builder permMenuCacheBuilder = ImmutableMultimap.builder(); menuList.forEach(menuDO -> { menuCacheBuilder.put(menuDO.getId(), menuDO); - permMenuCacheBuilder.put(menuDO.getPermission(), menuDO); + if (StrUtil.isNotEmpty(menuDO.getPermission())) { // 会存在 permission 为 null 的情况,导致 put 报 NPE 异常 + permMenuCacheBuilder.put(menuDO.getPermission(), menuDO); + } }); menuCache = menuCacheBuilder.build(); permissionMenuCache = permMenuCacheBuilder.build();