New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
建议加入saas多租户模式 #166
Comments
3q |
@zhangdaiscott @wjxjasin 请问租户用户登录时/sys/login时也会到这里,但登录中拿不到TENANT_ID,这时如何处理呢? |
我在登陆的这个表放开不进入拦截------------------ 原始邮件 ------------------
发件人: "张俊辉"<notifications@github.com>
发送时间: 2019年8月2日(星期五) 下午2:57
收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>;
抄送: "wjxjasin"<wjxjasin@foxmail.com>;"Mention"<mention@noreply.github.com>;
主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166)
@zhangdaiscott @wjxjasin 请问租户用户登录时/sys/login时也会到这里,但登录中拿不到TENANT_ID,这时如何处理呢?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@wjxjasin 你好,我也计划在自己的项目中增加多租户的支持,能否把provider这个表的定义提供下?另外是不是需要手工在jeecg-boot内置的各个表中加上租户id的字段,比如sys_user,加上租户id字段来标示用户属于哪个租户的。 |
@liaoyongxiong 你好,我今天也在搞这个多租户的问题,是否需要每个表加字段,每个实体类加字段,前端页面字段是否需要加?? |
看群
…------------------ 原始邮件 ------------------
发件人: "pingyougou"<notifications@github.com>;
发送时间: 2019年11月11日(星期一) 下午4:47
收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>;
抄送: "jasin"<wjxjasin@foxmail.com>; "Mention"<mention@noreply.github.com>;
主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166)
@liaoyongxiong 你好,我今天也在搞这个多租户的问题,是否需要每个表加字段,每个实体类加字段,前端页面字段是否需要加??
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
嗯嗯,谢谢,我在群里看到了 |
@wjxjasin 你好,我在数据库表里面加了租户id字段和后端实体字段,现在运行报错,错误如下: Original SQL: select * from sys_user where username = ? and del_flag = '0' Error querying database. Cause: java.lang.NullPointerExceptionThe error may exist in file [D:\code\bronze-cps-crm\bronze-cps-crm-back\bronze-cps-module-system\target\classes\org\jeecg\modules\system\mapper\xml\SysUserMapper.xml]The error may involve org.jeecg.modules.system.mapper.SysUserMapper.getUserByNameThe error occurred while executing a queryCause: java.lang.NullPointerExceptionorg.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: Error querying database. Cause: java.lang.NullPointerExceptionThe error may exist in file [D:\code\bronze-cps-crm\bronze-cps-crm-back\bronze-cps-module-system\target\classes\org\jeecg\modules\system\mapper\xml\SysUserMapper.xml]The error may involve org.jeecg.modules.system.mapper.SysUserMapper.getUserByName请问,要实现多租户,除了加字段之后,还需要加什么配置吗?? |
@wjxjasin 现在是首页登陆不进去,我将拦截器去掉就行了?请问什么原因 |
我知道你这种情况,用户表需要在mybatis plus的配置sys_user忽略注入
…------------------ 原始邮件 ------------------
发件人: "pingyougou"<notifications@github.com>;
发送时间: 2019年11月11日(星期一) 晚上6:53
收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>;
抄送: "jasin"<wjxjasin@foxmail.com>; "Mention"<mention@noreply.github.com>;
主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166)
@wjxjasin 现在是首页登陆不进去,我将拦截器去掉就行了?请问什么原因
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
原因是,在一开始mybatisplus拿不到当前线程的用户信息,user为null , 导致报错。
…------------------ 原始邮件 ------------------
发件人: "pingyougou"<notifications@github.com>;
发送时间: 2019年11月11日(星期一) 晚上6:53
收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>;
抄送: "jasin"<wjxjasin@foxmail.com>; "Mention"<mention@noreply.github.com>;
主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166)
@wjxjasin 现在是首页登陆不进去,我将拦截器去掉就行了?请问什么原因
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@wjxjasin 好的,谢谢大佬,我去试试 |
@wjxjasin 你好,昨天搞完多租户后,现在其中一个页面数据查询报错 Error querying database. Cause: java.lang.NullPointerExceptionThe error may exist in com/zp/bronze/cps/crm/mapper/CrmContractMapper.java (best guess)The error may involve com.zp.bronze.cps.crm.mapper.CrmContractMapper.selectPageThe error occurred while executing a query前台200,后台500,昨天加租户之前还是好的,现在报错,是不是加完租户之后导致这样的? |
@wjxjasin 我已经解决了,谢谢 |
请问您怎么解决的 ,我也遇到这个问题了 |
请问群是多少啊? 我也在解决这个问题 |
什么问题
…------------------ 原始邮件 ------------------
发件人: "743636214"<notifications@github.com>;
发送时间: 2019年11月13日(星期三) 中午1:37
收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>;
抄送: "jasin"<wjxjasin@foxmail.com>; "Mention"<mention@noreply.github.com>;
主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166)
看群
…
------------------ 原始邮件 ------------------ 发件人: "pingyougou"<notifications@github.com>; 发送时间: 2019年11月11日(星期一) 下午4:47 收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>; 抄送: "jasin"<wjxjasin@foxmail.com>; "Mention"<mention@noreply.github.com>; 主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166) @liaoyongxiong 你好,我今天也在搞这个多租户的问题,是否需要每个表加字段,每个实体类加字段,前端页面字段是否需要加?? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
请问群是多少啊? 我也在解决这个问题
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
感谢您的回复, 就是登陆不了,不知道怎么使用mybatis 忽略sys_user |
就是您说到过的,登陆时mybatis获取不到user,为null了,就报错,要忽略掉 |
登录的时候会查询用户表,此时我们还获取不到当前用户的信息注入到配置中,租户配置这里拿到的用户为null。
…------------------ 原始邮件 ------------------
发件人: "743636214"<notifications@github.com>;
发送时间: 2019年11月13日(星期三) 中午1:43
收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>;
抄送: "jasin"<wjxjasin@foxmail.com>; "Mention"<mention@noreply.github.com>;
主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166)
什么问题
…
------------------ 原始邮件 ------------------ 发件人: "743636214"<notifications@github.com>; 发送时间: 2019年11月13日(星期三) 中午1:37 收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>; 抄送: "jasin"<wjxjasin@foxmail.com>; "Mention"<mention@noreply.github.com>; 主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166) 看群 … ------------------ 原始邮件 ------------------ 发件人: "pingyougou"<notifications@github.com>; 发送时间: 2019年11月11日(星期一) 下午4:47 收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>; 抄送: "jasin"<wjxjasin@foxmail.com>; "Mention"<mention@noreply.github.com>; 主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166) @liaoyongxiong 你好,我今天也在搞这个多租户的问题,是否需要每个表加字段,每个实体类加字段,前端页面字段是否需要加?? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. 请问群是多少啊? 我也在解决这个问题 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
就是您说到过的,登陆时mybatis获取不到user,为null了,就报错,要忽略掉
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
1.在MybatisPlusConfig设置忽略不需要注入的表
//忽略不需要注入的表 sys_role,sys_user必须忽略注入
private static final List<String> IGNORE_TENANT_TABLES =
Lists.newArrayList("sys_role","sys_user","sys_permission","sys_dict","sys_dict_item","sys_user_role");
2.在paginationInterceptor方法里面加上上面设置的过滤的表
@OverRide
public boolean doTableFilter(String tableName) {
// 忽略掉一些表
return IGNORE_TENANT_TABLES.stream().anyMatch((e) -> e.equalsIgnoreCase(tableName));
}
…------------------ 原始邮件 ------------------
发件人: "743636214"<notifications@github.com>;
发送时间: 2019年11月13日(星期三) 中午1:41
收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>;
抄送: "jasin"<wjxjasin@foxmail.com>; "Mention"<mention@noreply.github.com>;
主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166)
什么问题
…
------------------ 原始邮件 ------------------ 发件人: "743636214"<notifications@github.com>; 发送时间: 2019年11月13日(星期三) 中午1:37 收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>; 抄送: "jasin"<wjxjasin@foxmail.com>; "Mention"<mention@noreply.github.com>; 主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166) 看群 … ------------------ 原始邮件 ------------------ 发件人: "pingyougou"<notifications@github.com>; 发送时间: 2019年11月11日(星期一) 下午4:47 收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>; 抄送: "jasin"<wjxjasin@foxmail.com>; "Mention"<mention@noreply.github.com>; 主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166) @liaoyongxiong 你好,我今天也在搞这个多租户的问题,是否需要每个表加字段,每个实体类加字段,前端页面字段是否需要加?? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. 请问群是多少啊? 我也在解决这个问题 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
感谢您的回复, 就是登陆不了,不知道怎么使用mybatis 忽略sys_user
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@wjxjasin 谢谢大佬的讲解 |
284271917这是群号 |
不敢当,我也是依托作者的开源项目,更改适合自己的需求,问题提的比较早而已。
…------------------ 原始邮件 ------------------
发件人: "pingyougou"<notifications@github.com>;
发送时间: 2019年11月13日(星期三) 中午1:55
收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>;
抄送: "jasin"<wjxjasin@foxmail.com>; "Mention"<mention@noreply.github.com>;
主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166)
@wjxjasin 谢谢大佬的讲解
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
非常感谢 |
大佬您好,我这个过滤已经生效了,但是我的业务是每个用户只能看到自己的数据,所以要根据条件去模糊查询而不是等于,最终sql语句预计是这样的: |
抱歉,太麻烦您了,但是不知道能不能这样做? |
每个用户只能看到自己的数据,你可以用这个项目自带的设置数据规则去做。
…------------------ 原始邮件 ------------------
发件人: "743636214"<notifications@github.com>;
发送时间: 2019年11月13日(星期三) 下午3:13
收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>;
抄送: "jasin"<wjxjasin@foxmail.com>; "Mention"<mention@noreply.github.com>;
主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166)
不敢当,我也是依托作者的开源项目,更改适合自己的需求,问题提的比较早而已。
…
------------------ 原始邮件 ------------------ 发件人: "pingyougou"<notifications@github.com>; 发送时间: 2019年11月13日(星期三) 中午1:55 收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>; 抄送: "jasin"<wjxjasin@foxmail.com>; "Mention"<mention@noreply.github.com>; 主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166) @wjxjasin 谢谢大佬的讲解 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
大佬您好,我这个过滤已经生效了,但是我的业务是每个用户只能看到自己的数据,所以要根据条件去模糊查询而不是等于,最终sql语句预计是这样的:
SELECT COUNT(1) FROM ana_gra_info WHERE ana_gra_info.sys_org_code like '%A03A01%' AND del_flag = '0' ,
但是现在是这样的:
SELECT COUNT(1) FROM ana_gra_info WHERE ana_gra_info.sys_org_code = A03A01 AND del_flag = '0'
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
模糊搜索可以去文档看,里面有 |
试过了,这个项目里面的好像是针对的单表的,所以选择了mybatis的,还是感谢您的解答 |
好的,谢谢您的提醒 |
我也做了类似的每个用户只能看到自己的数据,多表的话,我是通过写视图,当成单表,用数据规则就可以做,仅供参考,这样做性能会没有直接写好,但是好实现类似功能。
…------------------ 原始邮件 ------------------
发件人: "743636214"<notifications@github.com>;
发送时间: 2019年11月13日(星期三) 下午3:20
收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>;
抄送: "jasin"<wjxjasin@foxmail.com>; "Mention"<mention@noreply.github.com>;
主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166)
每个用户只能看到自己的数据,你可以用这个项目自带的设置数据规则去做。
…
------------------ 原始邮件 ------------------ 发件人: "743636214"<notifications@github.com>; 发送时间: 2019年11月13日(星期三) 下午3:13 收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>; 抄送: "jasin"<wjxjasin@foxmail.com>; "Mention"<mention@noreply.github.com>; 主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166) 不敢当,我也是依托作者的开源项目,更改适合自己的需求,问题提的比较早而已。 … ------------------ 原始邮件 ------------------ 发件人: "pingyougou"<notifications@github.com>; 发送时间: 2019年11月13日(星期三) 中午1:55 收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>; 抄送: "jasin"<wjxjasin@foxmail.com>; "Mention"<mention@noreply.github.com>; 主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166) @wjxjasin 谢谢大佬的讲解 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. 大佬您好,我这个过滤已经生效了,但是我的业务是每个用户只能看到自己的数据,所以要根据条件去模糊查询而不是等于,最终sql语句预计是这样的: SELECT COUNT(1) FROM ana_gra_info WHERE ana_gra_info.sys_org_code like '%A03A01%' AND del_flag = '0' , 但是现在是这样的: SELECT COUNT(1) FROM ana_gra_info WHERE ana_gra_info.sys_org_code = A03A01 AND del_flag = '0' — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
试过了,这个项目里面的好像是针对的单表的,所以选择了mybatis的,还是感谢您的解答
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
是的,这样确实也挺好,比较好操作,再加上这个框架自带了可视化过滤数据 |
` MyTenantParser myTenantParser = new MyTenantParser()
重写TenantSqlParser类, 就能使用模糊查询了, 把EquesTo类换成LikeExpression 类就行了。 |
@wjxjasin 你好,请教一下,我今天将最新版本的代码合入到代码中,发现 |
请教一下哈,现在想增加很多的用户账号,是分表创建一个新的user表,还是依旧使用sys_user 表,还有就是怎么确保新增加的user账号的权限(包括 role permission depart等表权限),我目前的设想是分表创建新user表,但是授权的话,难道就是向每个权限表里面插入记录,那样的话,数据还是不好管理??所以请教下大佬,希望大佬指点一下?? |
涉及数据过多的话,可以看看市面上很多像mycat,sharding等分库分表的中间件,这样可以不用改变代码逻辑。个人观点,你可以多了解了解选择最适合你自己的。------------------ 原始邮件 ------------------
发件人: "pingyougou"<notifications@github.com>
发送时间: 2019年11月29日(星期五) 晚上8:08
收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>;
抄送: "wjxjasin"<wjxjasin@foxmail.com>;"Mention"<mention@noreply.github.com>;
主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166)
请教一下哈,现在想增加很多的用户账号,是分表创建一个新的user表,还是依旧使用sys_user 表,还有就是怎么确保新增加的user账号的权限(包括 role permission depart等表权限),我目前的设想是分表创建新user表,但是授权的话,难道就是向每个权限表里面插入记录,那样的话,数据还是不好管理??所以请教下大佬,希望大佬指点一下??
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
你好,其实最主要问题是我每当创建一个账号信息的时候,都需要去插入相关表的信息,这样会有问题,第一,每个表都要去插入相关的数据权限,感觉很繁琐,第二,往这些表里面插入数据的话,会导致 系统表 sys_ 开头的那些表里面的数据独立性就被破坏了,有没有其他的方法呢,可不可以使用代理的方式实现?? |
看了下你们问题最后都解决了对吧,你们之前说的很多消息是在QQ群里说的?现在看不到也没在群里,所以不知道最终完整的解决办法是什么,能否在这里贴一下呢? |
1.需要租户控制的表必须要加,不需要的在配置里面过滤掉
2.表里面加了对应的实体肯定也要加字段
3.租户表需要租户码(int),租户名称(varchar)等
…------------------ 原始邮件 ------------------
发件人: "lifuchao"<notifications@github.com>;
发送时间: 2019年12月5日(星期四) 中午11:49
收件人: "zhangdaiscott/jeecg-boot"<jeecg-boot@noreply.github.com>;
抄送: "jasin"<wjxjasin@foxmail.com>; "Mention"<mention@noreply.github.com>;
主题: Re: [zhangdaiscott/jeecg-boot] 建议加入saas多租户模式 (#166)
@liaoyongxiong 你好,我今天也在搞这个多租户的问题,是否需要每个表加字段,每个实体类加字段,前端页面字段是否需要加??
看了下你们问题最后都解决了对吧,你们之前说的很多消息是在QQ群里说的?现在看不到也没在群里,所以不知道最终完整的解决办法是什么,能否在这里贴一下呢?
是先需要有个provider表(表结构长啥样呢?),然后所有表加上租户id字段,然后再如楼主所说的改MybatisPlusConfig类吗
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
大佬,请问多租户改造是不是做了这几步就可以了呢?最重要的就是在配置里面如何过滤不需要控制的表? |
@zhangdaiscott 建议升级多租户的方式,很多私有化,都要弄 |
您好,我想问一下,如何设置一个用户登录后选择租户首页显示不同的页面,权限要怎么分配 |
使用mybatis plus多租户 SQL 解析器,
在MybatisPlusConfig中
//需要注入的字段
private static final String SYSTEM_TENANT_ID = "within_code";
分页插件方法里面加入
// SQL解析处理拦截:增加租户处理回调。
TenantSqlParser tenantSqlParser = new TenantSqlParser()
.setTenantHandler(new TenantHandler() {
The text was updated successfully, but these errors were encountered: