refactor: flatten infrastructure packages
This commit is contained in:
58
src/main/java/com/label/config/MybatisPlusConfig.java
Normal file
58
src/main/java/com/label/config/MybatisPlusConfig.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package com.label.config;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
|
||||
import com.label.common.context.CompanyContext;
|
||||
import net.sf.jsqlparser.expression.Expression;
|
||||
import net.sf.jsqlparser.expression.LongValue;
|
||||
import net.sf.jsqlparser.expression.NullValue;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
// Tables that do NOT need tenant isolation (either global or tenant root tables)
|
||||
private static final List<String> IGNORED_TABLES = Arrays.asList(
|
||||
"sys_company", // the tenant root table itself
|
||||
"sys_config", // has company_id=NULL for global defaults; service handles this manually
|
||||
"video_process_job" // accessed by unauthenticated callback endpoint; service validates companyId manually
|
||||
);
|
||||
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
|
||||
// 1. Tenant isolation - auto-injects WHERE company_id = ?
|
||||
interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(new TenantLineHandler() {
|
||||
@Override
|
||||
public Expression getTenantId() {
|
||||
Long companyId = CompanyContext.get();
|
||||
if (companyId == null) {
|
||||
return new NullValue();
|
||||
}
|
||||
return new LongValue(companyId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTenantIdColumn() {
|
||||
return "company_id";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignoreTable(String tableName) {
|
||||
return IGNORED_TABLES.contains(tableName);
|
||||
}
|
||||
}));
|
||||
|
||||
// 2. Pagination interceptor (required for MyBatis Plus Page queries)
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
|
||||
|
||||
return interceptor;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user