|
|
@@ -3,12 +3,8 @@ package com.jeeplus.config;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
|
|
|
import com.jeeplus.common.SecurityUtils;
|
|
|
-import com.jeeplus.common.TokenProvider;
|
|
|
import com.jeeplus.common.constant.CommonConstants;
|
|
|
-import com.jeeplus.sys.feign.IRoleApi;
|
|
|
import com.jeeplus.sys.feign.ITenantApi;
|
|
|
-import com.jeeplus.sys.feign.IUserApi;
|
|
|
-import com.jeeplus.sys.service.dto.RoleDTO;
|
|
|
import com.jeeplus.sys.service.dto.UserDTO;
|
|
|
import net.sf.jsqlparser.expression.Expression;
|
|
|
import net.sf.jsqlparser.expression.StringValue;
|
|
|
@@ -33,14 +29,26 @@ public class TenantLineHandlerImpl implements TenantLineHandler {
|
|
|
|
|
|
@Override
|
|
|
public Expression getTenantId() {
|
|
|
- String tenantId = SpringUtil.getBean ( ITenantApi.class ).getCurrentTenantId ( );
|
|
|
- return new StringValue ( tenantId );
|
|
|
+ try {
|
|
|
+ String tenantId = SpringUtil.getBean(ITenantApi.class).getCurrentTenantId();
|
|
|
+ if (tenantId == null) {
|
|
|
+ tenantId = CommonConstants.DEFAULT_TENANT_ID;
|
|
|
+ }
|
|
|
+ return new StringValue(tenantId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return new StringValue(CommonConstants.DEFAULT_TENANT_ID);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 排除不需要拼多租户条件的表
|
|
|
@Override
|
|
|
public boolean ignoreTable(String tableName) {
|
|
|
- tableName = tableName.toLowerCase ( );
|
|
|
+ if (tableName == null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ tableName = tableName.toLowerCase();
|
|
|
+
|
|
|
// 多租户对于以下表不过滤, 所有租户可见
|
|
|
switch (tableName) {
|
|
|
case "sys_menu":
|
|
|
@@ -67,52 +75,64 @@ public class TenantLineHandlerImpl implements TenantLineHandler {
|
|
|
case "testreimbursement":
|
|
|
return true;
|
|
|
}
|
|
|
- // flowable工作流系统表(排除扩展表)采用自身saas方案实现租户模式,在这里做忽略处理
|
|
|
- if ( (tableName.startsWith ( "act_" ) || tableName.startsWith ( "ACT_" )) ) {
|
|
|
+
|
|
|
+ // flowable工作流系统表
|
|
|
+ if (tableName.startsWith("act_") || tableName.startsWith("ACT_")) {
|
|
|
return true;
|
|
|
}
|
|
|
- // 业务表 采用自身saas方案实现租户模式,在这里做忽略处理
|
|
|
- if ( (tableName.startsWith ( "finance_" ))
|
|
|
- || (tableName.startsWith ( "changes_" ))
|
|
|
- || (tableName.startsWith ( "cw_" ))
|
|
|
- || (tableName.startsWith ( "help_" ))
|
|
|
- || (tableName.startsWith ( "job_" ))
|
|
|
- || (tableName.startsWith ( "klg_" ))
|
|
|
- || (tableName.startsWith ( "knowledge_" ))
|
|
|
- || (tableName.startsWith ( "lucky_" ))
|
|
|
- || (tableName.startsWith ( "material_" ))
|
|
|
- || (tableName.startsWith ( "psi_" ))
|
|
|
- || (tableName.startsWith ( "position_" ))
|
|
|
- || (tableName.startsWith ( "project_" ))
|
|
|
- || (tableName.startsWith ( "proofread_" ))
|
|
|
- || (tableName.startsWith ( "rank_" ))
|
|
|
- || (tableName.startsWith ( "reimbursement_" ))
|
|
|
- || (tableName.startsWith ( "roster_" ))
|
|
|
- || (tableName.startsWith ( "sys_user_" ))
|
|
|
- || (tableName.startsWith ( "work_" ))
|
|
|
- || (tableName.startsWith ( "zs_reimbursement_" ))
|
|
|
- || (tableName.startsWith ( "human_" ))
|
|
|
- || (tableName.startsWith ( "ccpm_" ))
|
|
|
- || (tableName.startsWith ( "signature_" ))
|
|
|
- || (tableName.startsWith ( "consultancy_" ))
|
|
|
- || (tableName.startsWith ( "meeting_" ))
|
|
|
- || (tableName.startsWith ( "zs_report_" ))
|
|
|
- || (tableName.startsWith ( "program_" ))) {
|
|
|
+
|
|
|
+ // 业务表忽略
|
|
|
+ if (tableName.startsWith("finance_")
|
|
|
+ || tableName.startsWith("changes_")
|
|
|
+ || tableName.startsWith("cw_")
|
|
|
+ || tableName.startsWith("help_")
|
|
|
+ || tableName.startsWith("job_")
|
|
|
+ || tableName.startsWith("klg_")
|
|
|
+ || tableName.startsWith("knowledge_")
|
|
|
+ || tableName.startsWith("lucky_")
|
|
|
+ || tableName.startsWith("material_")
|
|
|
+ || tableName.startsWith("psi_")
|
|
|
+ || tableName.startsWith("position_")
|
|
|
+ || tableName.startsWith("project_")
|
|
|
+ || tableName.startsWith("proofread_")
|
|
|
+ || tableName.startsWith("rank_")
|
|
|
+ || tableName.startsWith("reimbursement_")
|
|
|
+ || tableName.startsWith("roster_")
|
|
|
+ || tableName.startsWith("sys_user_")
|
|
|
+ || tableName.startsWith("work_")
|
|
|
+ || tableName.startsWith("zs_reimbursement_")
|
|
|
+ || tableName.startsWith("human_")
|
|
|
+ || tableName.startsWith("ccpm_")
|
|
|
+ || tableName.startsWith("signature_")
|
|
|
+ || tableName.startsWith("consultancy_")
|
|
|
+ || tableName.startsWith("meeting_")
|
|
|
+ || tableName.startsWith("zs_report_")
|
|
|
+ || tableName.startsWith("program_")) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- // 如果默认租户是平台租户, 角色,用户等系统表不过滤
|
|
|
- if ( SpringUtil.getBean ( ITenantApi.class ).getCurrentTenantId ( ).equals ( CommonConstants.DEFAULT_TENANT_ID ) ) {
|
|
|
+ // ===== 安全获取租户ID(修复空指针核心!)=====
|
|
|
+ String currentTenantId = null;
|
|
|
+ try {
|
|
|
+ currentTenantId = SpringUtil.getBean(ITenantApi.class).getCurrentTenantId();
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 忽略异常
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果是平台租户
|
|
|
+ if (CommonConstants.DEFAULT_TENANT_ID.equals(currentTenantId)) {
|
|
|
switch (tableName) {
|
|
|
case "sys_user":
|
|
|
case "sys_role":
|
|
|
case "sys_post":
|
|
|
case "sys_office":
|
|
|
+ case "work_attachment":
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
- // 如果当前租户是综合管理租户, 部门,用户表进行过滤
|
|
|
- if ( SpringUtil.getBean ( ITenantApi.class ).getCurrentTenantId ( ).equals (CommonConstants.INTEGRATED_MANAGEMENT_TENANT_ID ) ) {
|
|
|
+
|
|
|
+ // 如果是综合管理租户
|
|
|
+ if (CommonConstants.INTEGRATED_MANAGEMENT_TENANT_ID.equals(currentTenantId)) {
|
|
|
switch (tableName) {
|
|
|
case "sys_user":
|
|
|
case "sys_office":
|
|
|
@@ -122,9 +142,17 @@ public class TenantLineHandlerImpl implements TenantLineHandler {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 特殊用户
|
|
|
+ String currentUsername = null;
|
|
|
+ try {
|
|
|
+ UserDTO user = SecurityUtils.getCurrentUserDTO();
|
|
|
+ if (user != null) {
|
|
|
+ currentUsername = user.getName();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 忽略
|
|
|
+ }
|
|
|
|
|
|
- String currentUsername = SecurityUtils.getCurrentUserDTO().getName();
|
|
|
- // 如果当前租户是综合管理租户, 部门,用户表进行过滤
|
|
|
if (SPECIAL_USER_NAMES.contains(currentUsername)) {
|
|
|
switch (tableName) {
|
|
|
case "sys_user":
|
|
|
@@ -132,6 +160,7 @@ public class TenantLineHandlerImpl implements TenantLineHandler {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
-}
|
|
|
+}
|