日志
This commit is contained in:
parent
5f4e04251d
commit
18f5be7b91
@ -2,10 +2,7 @@ package com.zhgd.mybatis;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.parser.SqlParserHelper;
|
||||
import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.extension.parser.JsqlParserSupport;
|
||||
@ -17,7 +14,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.jsqlparser.schema.Table;
|
||||
import net.sf.jsqlparser.statement.insert.Insert;
|
||||
import net.sf.jsqlparser.statement.select.*;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.ibatis.executor.Executor;
|
||||
import org.apache.ibatis.executor.statement.StatementHandler;
|
||||
import org.apache.ibatis.mapping.BoundSql;
|
||||
@ -92,18 +88,16 @@ public class DataScopeInterceptor extends JsqlParserSupport implements InnerInte
|
||||
MappedStatement ms = mpSh.mappedStatement();
|
||||
SqlCommandType sct = ms.getSqlCommandType();
|
||||
try {
|
||||
if (sct == SqlCommandType.INSERT) {
|
||||
Class<?> clazz = Class.forName(ms.getId().substring(0, ms.getId().lastIndexOf(StringPool.DOT)));
|
||||
//注解判断
|
||||
DataScope annotation = clazz.getAnnotation(DataScope.class);
|
||||
if (annotation == null || annotation.type() == 2) {
|
||||
return;
|
||||
}
|
||||
if (InterceptorIgnoreHelper.willIgnoreTenantLine(ms.getId())) return;
|
||||
if (SqlParserHelper.getSqlParserInfo(ms)) return;
|
||||
PluginUtils.MPBoundSql mpBs = mpSh.mPBoundSql();
|
||||
Map param = JSONObject.parseObject(JSON.toJSONString(mpBs.parameterObject()), Map.class);
|
||||
mpBs.sql(parserMulti(mpBs.sql(), MapUtils.getString(param, "engineeringSn")));
|
||||
String methodName = ms.getId().substring(ms.getId().lastIndexOf(".") + 1);
|
||||
if (sct == SqlCommandType.SELECT) {
|
||||
log.debug("查询mapper方法: {} >>> {}#{}", getCallPosition(), clazz.getName(), methodName);
|
||||
} else if (sct == SqlCommandType.UPDATE) {
|
||||
log.debug("更新mapper方法: {} >>> {}#{}", getCallPosition(), clazz.getName(), methodName);
|
||||
} else if (sct == SqlCommandType.INSERT) {
|
||||
log.debug("插入mapper方法: {} >>> {}#{}", getCallPosition(), clazz.getName(), methodName);
|
||||
} else if (sct == SqlCommandType.DELETE) {
|
||||
log.debug("删除mapper方法: {} >>> {}#{}", getCallPosition(), clazz.getName(), methodName);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
@ -126,7 +120,6 @@ public class DataScopeInterceptor extends JsqlParserSupport implements InnerInte
|
||||
Method[] declaredMethods = clazz.getDeclaredMethods();
|
||||
Optional<DataScope> dsOption = Arrays.stream(declaredMethods).filter(method -> method.getName().equals(methodName)).map(method -> method.getAnnotation(DataScope.class)).filter(Objects::nonNull).findFirst();
|
||||
annotation = dsOption.orElseGet(() -> clazz.getAnnotation(DataScope.class));
|
||||
log.debug("查询mapper方法: {} >>> {}#{}", getCallPosition(), clazz.getName(), methodName);
|
||||
if (findIgnoreDataScope(parameter, annotation) && isNotSqlTest()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user