package com.ruoyi.common.handler;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
|
import com.ruoyi.common.config.IgnoreTableConfig;
|
import com.ruoyi.common.utils.SecurityUtils;
|
import net.sf.jsqlparser.expression.Expression;
|
import net.sf.jsqlparser.expression.LongValue;
|
import org.apache.commons.collections4.CollectionUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
import org.springframework.util.ObjectUtils;
|
|
import java.util.Set;
|
|
@Component
|
public class CustomTenantLineHandler implements TenantLineHandler {
|
|
@Override
|
public Expression getTenantId() {
|
try {
|
Integer tenantId = SecurityUtils.getLoginUser().getTenantId();
|
return new LongValue(tenantId);
|
} catch (Exception e) {
|
return null;
|
}
|
}
|
|
@Override
|
public boolean ignoreTable(String tableName) {
|
// 指定不需要添加过滤条件的表
|
Set<String> ignoreTables = IgnoreTableConfig.IGNORE_TABLES;
|
return ignoreTables.contains(tableName);
|
}
|
|
@Override
|
public String getTenantIdColumn() {
|
// 指定租户 ID 字段名称,比如 "station_id"
|
return "tenant_id";
|
}
|
}
|