|
@@ -90,6 +90,9 @@ public class PermissionAspect implements Interceptor {
|
|
|
public void pointcut() {
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ Map<String,JSONObject> userIdMap = new HashMap<>();
|
|
|
+
|
|
|
//前置通知
|
|
|
@Before("pointcut()")
|
|
|
public void beforeMethod(JoinPoint joinPoint) {
|
|
@@ -130,66 +133,12 @@ public class PermissionAspect implements Interceptor {
|
|
|
|
|
|
|
|
|
//人员和部门数据为空
|
|
|
- if (user == null || dept == null ) {
|
|
|
+ if ( user == null || dept == null ||null == post) {
|
|
|
try {
|
|
|
- //反射扫包会比较慢,这里做了个懒加载
|
|
|
- if (classNames == null) {
|
|
|
- //扫描指定包路径下所有包含指定注解的类
|
|
|
- Set<Class<?>> classSet = ClassUtil.scanPackageByAnnotation(packagePath, DataPermission.class);
|
|
|
- if (classSet == null && classSet.size() == 0) {
|
|
|
- classNames = new ArrayList<>();
|
|
|
- } else {
|
|
|
- //取得类全名
|
|
|
- classNames = classSet.stream().map(Class::getName).collect(Collectors.toList());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 拿到mybatis的一些对象
|
|
|
- StatementHandler statementHandler = PluginUtils.realTarget(invocation.getTarget());
|
|
|
- MetaObject metaObject = SystemMetaObject.forObject(statementHandler);
|
|
|
- MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement");
|
|
|
-
|
|
|
- // mappedStatement.getId()为执行的mapper方法的全路径名,newId为执行的mapper方法的类全名
|
|
|
- String newId = mappedStatement.getId().substring(0, mappedStatement.getId().lastIndexOf("."));
|
|
|
- // 如果不是指定的方法,直接结束拦截
|
|
|
- if (!classNames.contains(newId)) {
|
|
|
- return invocation.proceed();
|
|
|
- }
|
|
|
- String newName = mappedStatement.getId().substring(mappedStatement.getId().lastIndexOf(".") + 1, mappedStatement.getId().length());
|
|
|
- Class<?> clazz = Class.forName(newId);
|
|
|
-
|
|
|
- if (!methodNames.containsKey(newId + "-" + newName)){
|
|
|
- for (Method method : clazz.getDeclaredMethods()) {
|
|
|
- //方法是否含有DataPermission注解,如果含有注解则将数据结果过滤
|
|
|
- if (method.isAnnotationPresent(DataPermission.class)) {
|
|
|
- DataPermission dataPermission = method.getAnnotation(DataPermission.class);
|
|
|
- if (dataPermission != null) {
|
|
|
- methodNames.put(newId + "-" + method.getName(), dataPermission.isPermission());
|
|
|
- }
|
|
|
- } else {
|
|
|
- methodNames.put(newId + "-" + method.getName(), true);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //是否开启数据权限
|
|
|
- boolean isPermission = true;
|
|
|
- isPermission = null != methodNames.get(newId + "-" + newName) ?methodNames.get(newId + "-" + newName) :false;
|
|
|
- if (isPermission) {
|
|
|
- // 获取到原始sql语句
|
|
|
- String sql = statementHandler.getBoundSql().getSql();
|
|
|
- // 解析并返回新的SQL语句,只处理查询sql
|
|
|
- if (mappedStatement.getSqlCommandType().toString().equals("SELECT")) {
|
|
|
- sql = getSql(sql, "");
|
|
|
- }
|
|
|
- // 修改sql
|
|
|
- metaObject.setValue("delegate.boundSql.sql", sql);
|
|
|
- }
|
|
|
+ return invocation.proceed();
|
|
|
} catch (Exception e) {
|
|
|
log.error("数据权限隔离异常:", e);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
return invocation.proceed();
|
|
|
}
|
|
|
|
|
@@ -315,7 +264,14 @@ public class PermissionAspect implements Interceptor {
|
|
|
|
|
|
@Cacheable(cacheNames = "user_id",key= "#userId")
|
|
|
public List<PostUser> getUserPostList(String userId) {
|
|
|
- JSONObject postuserjson = (JSONObject)postUserService.getUserPostList(null,null,userId,request);
|
|
|
+ JSONObject postuserjson = null;
|
|
|
+ if(null == userIdMap.get(userId)){
|
|
|
+ postuserjson = (JSONObject)postUserService.getUserPostList(null,null,userId,request);
|
|
|
+ userIdMap.put(userId,postuserjson);
|
|
|
+ }else {
|
|
|
+ postuserjson = userIdMap.get(userId);
|
|
|
+ }
|
|
|
+
|
|
|
if(null !=postuserjson){
|
|
|
PagResult pagResult = JSONObject.parseObject(postuserjson.toJSONString(), PagResult.class);
|
|
|
List<PostUser> list = pagResult.getRecords().toJavaList(PostUser.class);
|