diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/DataFilterAspect.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/DataFilterAspect.java index b7d6d64e44..dcb26335ed 100644 --- a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/DataFilterAspect.java +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/DataFilterAspect.java @@ -51,6 +51,9 @@ public class DataFilterAspect { */ private static final ThreadLocal hasConditions = new ThreadLocal(); + /** + * 用于向DataFilterInterceptor传递权限过滤的sql片段(需要在Controller相关的AOP中进行清理,防止变量残留) + */ public static final ThreadLocal sqlFilter = new ThreadLocal(); //public static final ThreadLocal gridIdTL = new ThreadLocal(); @@ -71,7 +74,7 @@ public class DataFilterAspect { public void dataFilter(JoinPoint point) { //清空 - sqlFilter.set(null); + //sqlFilter.remove(); // 取到注解属性 MethodSignature methodSignature = (MethodSignature) point.getSignature(); @@ -309,29 +312,6 @@ public class DataFilterAspect { hasConditions.set(true); } - //private void genInGrid(StringBuilder sb, Set gridIdList, String tableAlias) { - // //if (StringUtils.isBlank(tableAlias)) { - // // sb.append(hasConditions.get() ? " OR " : "").append(" GRID_ID ='").append(gridId).append("' "); - // //} else { - // // sb.append(hasConditions.get() ? " OR " : "").append(tableAlias).append(".GRID_ID ='").append(gridId).append("' "); - // //} - // - // if (hasConditions.get()) { - // // 之前没有条件 - // sb.append(" OR "); - // } - // // OR GRID_ID = 'XXX' OR GRID_ID = 'QQQ' - // for (String gridId : gridIdList) { - // if (StringUtils.isBlank(tableAlias)) { - // sb.append(" GRID_ID = '").append(gridId).append("' OR"); - // } else { - // sb.append(" ").append(tableAlias).append(".GRID_ID ='").append(gridId).append("' OR "); - // } - // } - // sb.replace(sb.lastIndexOf("OR"), sb.lastIndexOf("OR") + 3, ""); - // hasConditions.set(true); - //} - /** * sql:我发起的 * diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/ThreadLocalPreCleanAspect.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/ThreadLocalPreCleanAspect.java new file mode 100644 index 0000000000..532283a355 --- /dev/null +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/ThreadLocalPreCleanAspect.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2018 人人开源 All rights reserved. + *

+ * https://www.renren.io + *

+ * 版权所有,侵权必究! + */ + +package com.epmet.commons.mybatis.aspect; + +import com.epmet.commons.tools.exception.ExceptionUtils; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +/** + * 每次请求,清理ThreadLocal线程中的变量 + * @Author wxz + * @Description + * @Date 2020/4/23 16:16 + **/ +@Aspect +@Component +public class ThreadLocalPreCleanAspect { + + private static final Logger log = LoggerFactory.getLogger(ThreadLocalPreCleanAspect.class); + + @Before(value = "execution(* com.epmet.controller.*Controller*.*(..)) ") + public void before(JoinPoint point) throws Throwable { + // 清理权限过滤中的变量残留 + try { + DataFilterAspect.sqlFilter.remove(); + } catch (Exception e) { + log.error("清理sqlFilter缓存失败:{}", ExceptionUtils.getErrorStackTrace(e)); + } + } +}