From 7ebe4cca423d23e39ac274cfe100fb83fc0b886c Mon Sep 17 00:00:00 2001 From: Parker Date: Sun, 29 Nov 2020 23:44:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B6=85=E7=BA=A7=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E5=9C=A8=E7=A7=9F=E6=88=B7=E6=9F=A5=E8=AF=A2=E6=96=B9=E9=9D=A2?= =?UTF-8?q?=E6=97=A0=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../querybuilder/chain/TenantHandler.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/TenantHandler.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/TenantHandler.java index 71a9dec..60cd50c 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/TenantHandler.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/TenantHandler.java @@ -18,9 +18,12 @@ package org.opsli.core.persistence.querybuilder.chain; import cn.hutool.core.util.ReflectUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.commons.lang3.StringUtils; +import org.opsli.api.wrapper.system.user.UserModel; import org.opsli.common.constants.MyBatisConstants; +import org.opsli.common.exception.ServiceException; import org.opsli.common.utils.HumpUtil; import org.opsli.core.base.entity.BaseEntity; +import org.opsli.core.msg.CoreMsg; import org.opsli.core.utils.UserUtil; /** @@ -57,21 +60,24 @@ public class TenantHandler implements QueryBuilderChain{ */ @Override public QueryWrapper handler(Class entityClazz, QueryWrapper wrapper) { - // 执行责任链 - if(queryBuilderChain != null){ - wrapper = queryBuilderChain.handler(entityClazz, wrapper); - } - - // 判断多租户 + // 自身责任 -- 判断多租户 boolean tenantFlag = ReflectUtil.hasField(entityClazz, MyBatisConstants.FIELD_TENANT); if(tenantFlag) { String tenantId = UserUtil.getTenantId(); - if (StringUtils.isNotEmpty(tenantId)) { - wrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_TENANT), tenantId); + UserModel user = UserUtil.getUser(); + // 超级管理员可以操作 无租户限制, 其余用户全部有租户限制 + if(!UserUtil.SUPER_ADMIN.equals(user.getUsername()) && + StringUtils.isNotEmpty(tenantId) + ){ + wrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_TENANT), tenantId); } } - return wrapper; + // 执行 子 责任链 + if(queryBuilderChain != null){ + wrapper = queryBuilderChain.handler(entityClazz, wrapper); + } + return wrapper; } }