From 4b95146c98aa1dc053f2876a69fa0e9d58df79d2 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 7 Dec 2021 13:31:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=AE=9E=E4=BD=93=E7=BB=A7?= =?UTF-8?q?=E6=89=BF=E5=A4=9A=E7=A7=9F=E6=88=B7=E7=9A=84=20DO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + .../system/dal/dataobject/dept/SysDeptDO.java | 4 +- .../system/dal/dataobject/dept/SysPostDO.java | 5 +- .../dataobject/logger/SysOperateLogDO.java | 4 +- .../dal/dataobject/notice/SysNoticeDO.java | 6 +- .../src/main/resources/application.yaml | 4 +- .../infra/dal/dataobject/file/InfFileDO.java | 3 +- .../dataobject/logger/InfApiAccessLogDO.java | 4 +- .../dataobject/logger/InfApiErrorLogDO.java | 6 +- .../member/dal/dataobject/user/MbrUserDO.java | 4 +- yudao-framework/pom.xml | 1 + .../pom.xml | 66 +++++++++++++++++++ .../framework/datascope/package-info.java | 4 ++ .../core/db/TenantDatabaseInterceptor.java | 7 ++ .../core/web/TenantContextWebFilter.java | 3 - 更新日志.md | 20 +++++- 16 files changed, 116 insertions(+), 26 deletions(-) create mode 100644 yudao-framework/yudao-spring-boot-starter-datascope/pom.xml create mode 100644 yudao-framework/yudao-spring-boot-starter-datascope/src/main/java/cn/iocoder/yudao/framework/datascope/package-info.java diff --git a/README.md b/README.md index c5a210733..7643e877b 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ | | 菜单管理 | 配置系统菜单,操作权限,按钮权限标识等 | | | 部门管理 | 配置系统组织机构(公司、部门、小组),树结构展现支持数据权限 | | | 岗位管理 | 配置系统用户所属担任职务 | +| | 租户管理 | 配置系统租户,支持 SaaS 场景下的多租户功能 | | | 字典管理 | 对系统中经常使用的一些较为固定的数据进行维护 | | 🚀 | 短信管理 | 短信渠道、短息模板、短信日志,对接阿里云、云片等主流短信平台 | | 🚀 | 操作日志 | 系统正常操作日志记录和查询,集成 Swagger 生成日志内容 | diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/dept/SysDeptDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/dept/SysDeptDO.java index 46d7b9818..b10c13b7e 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/dept/SysDeptDO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/dept/SysDeptDO.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @@ -15,7 +15,7 @@ import lombok.EqualsAndHashCode; @TableName("sys_dept") @Data @EqualsAndHashCode(callSuper = true) -public class SysDeptDO extends BaseDO { +public class SysDeptDO extends TenantBaseDO { /** * 部门ID diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/dept/SysPostDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/dept/SysPostDO.java index 52b19c7ea..29652a0d8 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/dept/SysPostDO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/dept/SysPostDO.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @@ -15,14 +15,13 @@ import lombok.EqualsAndHashCode; @TableName("sys_post") @Data @EqualsAndHashCode(callSuper = true) -public class SysPostDO extends BaseDO { +public class SysPostDO extends TenantBaseDO { /** * 岗位序号 */ @TableId private Long id; - /** * 岗位名称 */ diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/logger/SysOperateLogDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/logger/SysOperateLogDO.java index e937327ee..417c6f45f 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/logger/SysOperateLogDO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/logger/SysOperateLogDO.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger; import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -22,7 +22,7 @@ import java.util.Map; @TableName(value = "sys_operate_log", autoResultMap = true) @Data @EqualsAndHashCode(callSuper = true) -public class SysOperateLogDO extends BaseDO { +public class SysOperateLogDO extends TenantBaseDO { /** * {@link #javaMethodArgs} 的最大长度 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/notice/SysNoticeDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/notice/SysNoticeDO.java index 1ddff6537..c61398fe6 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/notice/SysNoticeDO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/notice/SysNoticeDO.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.notice; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.adminserver.modules.system.enums.notice.SysNoticeTypeEnum; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @@ -16,7 +16,7 @@ import lombok.EqualsAndHashCode; @TableName("sys_notice") @Data @EqualsAndHashCode(callSuper = true) -public class SysNoticeDO extends BaseDO { +public class SysNoticeDO extends TenantBaseDO { /** * 公告ID diff --git a/yudao-admin-server/src/main/resources/application.yaml b/yudao-admin-server/src/main/resources/application.yaml index 18b3b2eb7..fc399a3a8 100644 --- a/yudao-admin-server/src/main/resources/application.yaml +++ b/yudao-admin-server/src/main/resources/application.yaml @@ -73,7 +73,7 @@ yudao: constants-class-list: - cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants - cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants - tenant: - tables: sys_user, sys_user_session + tenant: # 多租户相关配置项 + tables: # 配置需要开启多租户的表;如果实体已经继承 TenantBaseDO 类,则无需重复配置 debug: false diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/file/InfFileDO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/file/InfFileDO.java index 1b4a73328..83a03b3ca 100644 --- a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/file/InfFileDO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/file/InfFileDO.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; @@ -21,7 +22,7 @@ import java.io.InputStream; @Builder @NoArgsConstructor @AllArgsConstructor -public class InfFileDO extends BaseDO { +public class InfFileDO extends TenantBaseDO { /** * 文件路径 diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/logger/InfApiAccessLogDO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/logger/InfApiAccessLogDO.java index bd7554405..3191a98be 100644 --- a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/logger/InfApiAccessLogDO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/logger/InfApiAccessLogDO.java @@ -2,7 +2,7 @@ package cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.*; @@ -21,7 +21,7 @@ import java.util.Date; @Builder @NoArgsConstructor @AllArgsConstructor -public class InfApiAccessLogDO extends BaseDO { +public class InfApiAccessLogDO extends TenantBaseDO { /** * 编号 diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/logger/InfApiErrorLogDO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/logger/InfApiErrorLogDO.java index 4cd4ebf40..7f8094caf 100644 --- a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/logger/InfApiErrorLogDO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/logger/InfApiErrorLogDO.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger; -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.coreservice.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.*; @@ -21,7 +21,7 @@ import java.util.Date; @Builder @NoArgsConstructor @AllArgsConstructor -public class InfApiErrorLogDO extends BaseDO { +public class InfApiErrorLogDO extends TenantBaseDO { /** * 编号 diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/dal/dataobject/user/MbrUserDO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/dal/dataobject/user/MbrUserDO.java index 57221f614..02efd598b 100644 --- a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/dal/dataobject/user/MbrUserDO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/dal/dataobject/user/MbrUserDO.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.*; @@ -22,7 +22,7 @@ import java.util.Date; @Builder @NoArgsConstructor @AllArgsConstructor -public class MbrUserDO extends BaseDO { +public class MbrUserDO extends TenantBaseDO { /** * 用户ID diff --git a/yudao-framework/pom.xml b/yudao-framework/pom.xml index 63fc2c33c..0d58b1416 100644 --- a/yudao-framework/pom.xml +++ b/yudao-framework/pom.xml @@ -33,6 +33,7 @@ yudao-spring-boot-starter-biz-weixin yudao-spring-boot-starter-extension yudao-spring-boot-starter-tenant + yudao-spring-boot-starter-datascope yudao-framework diff --git a/yudao-framework/yudao-spring-boot-starter-datascope/pom.xml b/yudao-framework/yudao-spring-boot-starter-datascope/pom.xml new file mode 100644 index 000000000..5718e05c9 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-datascope/pom.xml @@ -0,0 +1,66 @@ + + + + yudao-framework + cn.iocoder.boot + ${revision} + + 4.0.0 + yudao-spring-boot-starter-datascope + jar + + ${artifactId} + 数据权限 + https://github.com/YunaiV/ruoyi-vue-pro + + + + cn.iocoder.boot + yudao-common + + + + + org.springframework.boot + spring-boot-starter-web + + + + cn.iocoder.boot + yudao-spring-boot-starter-security + + + + + cn.iocoder.boot + yudao-spring-boot-starter-mybatis + + + + cn.iocoder.boot + yudao-spring-boot-starter-redis + + + + + cn.iocoder.boot + yudao-spring-boot-starter-job + + + + + cn.iocoder.boot + yudao-spring-boot-starter-mq + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + diff --git a/yudao-framework/yudao-spring-boot-starter-datascope/src/main/java/cn/iocoder/yudao/framework/datascope/package-info.java b/yudao-framework/yudao-spring-boot-starter-datascope/src/main/java/cn/iocoder/yudao/framework/datascope/package-info.java new file mode 100644 index 000000000..116013c7e --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-datascope/src/main/java/cn/iocoder/yudao/framework/datascope/package-info.java @@ -0,0 +1,4 @@ +/** + * 基于 JSqlParser 解析 SQL,增加数据权限的 WHERE 条件 + */ +package cn.iocoder.yudao.framework.datascope; diff --git a/yudao-framework/yudao-spring-boot-starter-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/db/TenantDatabaseInterceptor.java b/yudao-framework/yudao-spring-boot-starter-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/db/TenantDatabaseInterceptor.java index 055a76a1e..283bd4497 100644 --- a/yudao-framework/yudao-spring-boot-starter-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/db/TenantDatabaseInterceptor.java +++ b/yudao-framework/yudao-spring-boot-starter-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/db/TenantDatabaseInterceptor.java @@ -3,6 +3,8 @@ package cn.iocoder.yudao.framework.tenant.core.db; 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.core.metadata.TableInfo; +import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler; import lombok.AllArgsConstructor; import net.sf.jsqlparser.expression.Expression; @@ -25,6 +27,11 @@ public class TenantDatabaseInterceptor implements TenantLineHandler { @Override public boolean ignoreTable(String tableName) { + // 如果实体类继承 TenantBaseDO 类,则是多租户表,不进行忽略 + TableInfo tableInfo = TableInfoHelper.getTableInfo(tableName); + if (tableInfo != null && TenantBaseDO.class.isAssignableFrom(tableInfo.getEntityType())) { + return false; + } // 不包含,说明要过滤 return !CollUtil.contains(properties.getTables(), tableName); } diff --git a/yudao-framework/yudao-spring-boot-starter-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/web/TenantContextWebFilter.java b/yudao-framework/yudao-spring-boot-starter-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/web/TenantContextWebFilter.java index ac43dca61..ec159e0ec 100644 --- a/yudao-framework/yudao-spring-boot-starter-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/web/TenantContextWebFilter.java +++ b/yudao-framework/yudao-spring-boot-starter-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/web/TenantContextWebFilter.java @@ -14,9 +14,6 @@ import java.io.IOException; * 多租户 Context Web 过滤器 * 将请求 Header 中的 tenant-id 解析出来,添加到 {@link TenantContextHolder} 中,这样后续的 DB 等操作,可以获得到租户编号。 * - * Q:会不会存在模拟 tenant-id 导致跨租户的问题? - * A:用户登陆后,获得的 Token 是基于租户级别隔离,从而保证授权失败。 - * * @author 芋道源码 */ public class TenantContextWebFilter extends OncePerRequestFilter { diff --git a/更新日志.md b/更新日志.md index 748a6d2d9..266eacbbd 100644 --- a/更新日志.md +++ b/更新日志.md @@ -20,10 +20,24 @@ ## [v1.2.0] 进行中 -* 新增用户前台的昵称、头像的修改 -* 修复通知和字典查询权限 Bug +### ⚠️ Warning -TODO +这是一个多租户的预览版本,涉及的改动较大。 + +### ⭐ New Features + +* 【新增】多租户,支持 Web、Security、Job、MQ、Async、DB、Redis 组件 +* 【新增】用户前台的昵称、头像的修改 + +### 🐞 Bug Fixes + +* 【修复】通知和字典查询权限 Bug + +### 🔨 Dependency Upgrades + +暂无 + +### 📝 TODO * 支付 * 用户前台的社交登陆