use of com.mendmix.mybatis.plugin.JeesuiteMybatisInterceptor in project jeesuite-libs by vakinge.
the class SqlRewriteHandler method start.
@Override
public void start(JeesuiteMybatisInterceptor context) {
isFieldSharddingTenant = MybatisConfigs.isFieldSharddingTenant(context.getGroupName());
softDeleteColumnName = MybatisConfigs.getSoftDeleteColumn(context.getGroupName());
softDeleteFalseValue = MybatisConfigs.getSoftDeletedFalseValue(context.getGroupName());
deptColumnName = MybatisConfigs.getDeptColumnName(context.getGroupName());
ownerColumnName = MybatisConfigs.getOwnerColumnName(context.getGroupName());
orgBasePermKey = MybatisConfigs.getCurrentOrgPermKey(context.getGroupName());
Properties properties = ResourceUtils.getAllProperties("mendmix.mybatis.permission.table-column-mappings");
properties.forEach((k, v) -> {
String tableName = k.toString().substring(k.toString().indexOf("[") + 1).replace("]", "").trim();
buildTableDataPermissionMapping(tableName, v.toString());
});
dynaDataPermEnabled = !dataPermMappings.isEmpty();
final List<MapperMetadata> mappers = MybatisMapperParser.getMapperMetadatas(context.getGroupName());
//
initColumnConfig(mappers, deptColumnName, deptMappedStatements);
// 软删除
initColumnConfig(mappers, softDeleteColumnName, softDeleteMappedStatements);
// 字段隔离租户模式
if (isFieldSharddingTenant) {
String tenantField = MybatisConfigs.getTenantSharddingField(context.getGroupName());
ColumnMetadata tenantColumn;
for (MapperMetadata mapper : mappers) {
tenantColumn = mapper.getEntityMetadata().getColumns().stream().filter(o -> {
return o.getColumn().equals(tenantField) || o.getProperty().equals(tenantField);
}).findFirst().orElse(null);
if (tenantColumn == null)
continue;
if (tenantColumnName == null)
tenantColumnName = tenantColumn.getColumn();
if (tenantPropName == null)
tenantPropName = tenantColumn.getProperty();
if (!dataPermMappings.containsKey(mapper.getTableName())) {
dataPermMappings.put(mapper.getTableName(), new LinkedHashMap<>());
}
dataPermMappings.get(mapper.getTableName()).put(tenantPropName, tenantColumnName);
}
}
logger.info("dataProfileMappings >> {}", dataPermMappings);
}
use of com.mendmix.mybatis.plugin.JeesuiteMybatisInterceptor in project jeesuite-libs by vakinge.
the class JeesuiteMybatisEnhancer method handle.
public static void handle(String group, Configuration configuration) throws Exception {
if ("tkMapper".equals(MybatisConfigs.getCrudDriver())) {
Class<?> helperClazz = Class.forName("tk.mybatis.mapper.mapperhelper.MapperHelper");
Object helper = helperClazz.newInstance();
Class<?> configClazz = Class.forName("tk.mybatis.mapper.entity.Config");
Object config = configClazz.newInstance();
Method method = configClazz.getDeclaredMethod("setNotEmpty", boolean.class);
method.invoke(config, false);
method = helperClazz.getDeclaredMethod("setConfig", configClazz);
method.invoke(helper, config);
method = helperClazz.getDeclaredMethod("registerMapper", Class.class);
List<MapperMetadata> mappers = MybatisMapperParser.getMapperMetadatas(group);
for (MapperMetadata mapper : mappers) {
method.invoke(helper, mapper.getMapperClass());
}
method = helperClazz.getDeclaredMethod("processConfiguration", Configuration.class);
method.invoke(helper, configuration);
} else {
new GeneralSqlGenerator(group, configuration).generate();
}
// pageHelper
try {
Class<?> pageHelperClazz = Class.forName("com.github.pagehelper.PageInterceptor");
Interceptor pageInterceptor = (Interceptor) pageHelperClazz.newInstance();
configuration.addInterceptor(pageInterceptor);
} catch (Exception e) {
}
// 注册拦截器
String[] hanlderNames = MybatisConfigs.getHandlerNames(group);
JeesuiteMybatisInterceptor interceptor = new JeesuiteMybatisInterceptor(group, hanlderNames);
configuration.addInterceptor(interceptor);
interceptor.afterRegister();
logger.info(">> JeesuiteMybatisEnhancer finshed -> group:{},hanlderNames:{}", group, hanlderNames);
}
Aggregations