日志
This commit is contained in:
parent
18f5be7b91
commit
984dd5009b
@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.parser.JsqlParserSupport;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
|
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
|
||||||
import com.zhgd.annotation.DataScope;
|
import com.zhgd.annotation.DataScope;
|
||||||
import com.zhgd.xmgl.security.util.SecurityUtils;
|
import com.zhgd.xmgl.security.util.SecurityUtils;
|
||||||
|
import com.zhgd.xmgl.util.EnvironmentUtil;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.sf.jsqlparser.schema.Table;
|
import net.sf.jsqlparser.schema.Table;
|
||||||
@ -64,6 +65,25 @@ public class DataScopeInterceptor extends JsqlParserSupport implements InnerInte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getCallPositionForDev() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||||
|
for (StackTraceElement e : stackTrace) {
|
||||||
|
if (e.getClassName().startsWith("com.zhgd.xmgl")) {
|
||||||
|
sb.append(e.getClassName());
|
||||||
|
sb.append(".");
|
||||||
|
sb.append(e.getMethodName());
|
||||||
|
sb.append("(");
|
||||||
|
sb.append(StrUtil.subAfter(e.getClassName(), ".", true));
|
||||||
|
sb.append(".java:");
|
||||||
|
sb.append(e.getLineNumber());
|
||||||
|
sb.append(")");
|
||||||
|
sb.append("\r\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
private static String getCallPosition() {
|
private static String getCallPosition() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||||
@ -90,14 +110,27 @@ public class DataScopeInterceptor extends JsqlParserSupport implements InnerInte
|
|||||||
try {
|
try {
|
||||||
Class<?> clazz = Class.forName(ms.getId().substring(0, ms.getId().lastIndexOf(StringPool.DOT)));
|
Class<?> clazz = Class.forName(ms.getId().substring(0, ms.getId().lastIndexOf(StringPool.DOT)));
|
||||||
String methodName = ms.getId().substring(ms.getId().lastIndexOf(".") + 1);
|
String methodName = ms.getId().substring(ms.getId().lastIndexOf(".") + 1);
|
||||||
if (sct == SqlCommandType.SELECT) {
|
if (EnvironmentUtil.getActiveEnvironment().equals("gsx-other-env-show-dev")) {
|
||||||
log.debug("查询mapper方法: {} >>> {}#{}", getCallPosition(), clazz.getName(), methodName);
|
//开发环境
|
||||||
} else if (sct == SqlCommandType.UPDATE) {
|
if (sct == SqlCommandType.SELECT) {
|
||||||
log.debug("更新mapper方法: {} >>> {}#{}", getCallPosition(), clazz.getName(), methodName);
|
log.debug("查询mapper方法: {} >>> {}#{}", getCallPositionForDev(), clazz.getName(), methodName);
|
||||||
} else if (sct == SqlCommandType.INSERT) {
|
} else if (sct == SqlCommandType.UPDATE) {
|
||||||
log.debug("插入mapper方法: {} >>> {}#{}", getCallPosition(), clazz.getName(), methodName);
|
log.debug("更新mapper方法: {} >>> {}#{}", getCallPositionForDev(), clazz.getName(), methodName);
|
||||||
} else if (sct == SqlCommandType.DELETE) {
|
} else if (sct == SqlCommandType.INSERT) {
|
||||||
log.debug("删除mapper方法: {} >>> {}#{}", getCallPosition(), clazz.getName(), methodName);
|
log.debug("插入mapper方法: {} >>> {}#{}", getCallPositionForDev(), clazz.getName(), methodName);
|
||||||
|
} else if (sct == SqlCommandType.DELETE) {
|
||||||
|
log.debug("删除mapper方法: {} >>> {}#{}", getCallPositionForDev(), clazz.getName(), methodName);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
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) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user