|
@@ -1,14 +1,16 @@
|
|
|
package com.ims.eval.config.permission;
|
|
|
|
|
|
import cn.hutool.core.util.ClassUtil;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.ims.eval.cache.CacheContext;
|
|
|
import com.ims.eval.entity.DataDictionary;
|
|
|
+import com.ims.eval.entity.custom.PostUser;
|
|
|
import com.ims.eval.entity.dto.response.MyuserResDTO;
|
|
|
+import com.ims.eval.entity.dto.result.PagResult;
|
|
|
import com.ims.eval.feign.RemoteServiceBuilder;
|
|
|
+import com.ims.eval.service.custom.PostUserService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import net.sf.jsqlparser.JSQLParserException;
|
|
|
import net.sf.jsqlparser.expression.Expression;
|
|
@@ -30,10 +32,10 @@ import org.aspectj.lang.annotation.Aspect;
|
|
|
import org.aspectj.lang.annotation.Before;
|
|
|
import org.aspectj.lang.annotation.Pointcut;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
-import springfox.documentation.annotations.Cacheable;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.lang.reflect.Method;
|
|
@@ -53,6 +55,12 @@ public class PermissionAspect implements Interceptor {
|
|
|
@Autowired
|
|
|
private RemoteServiceBuilder serviceBuilder;
|
|
|
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private HttpServletRequest request;
|
|
|
+ @Autowired
|
|
|
+ private PostUserService postUserService;
|
|
|
+
|
|
|
//扫描的包路径,需要权限的加在mapper类及方法上
|
|
|
private String packagePath = "com.ims.eval.dao";
|
|
|
private final static String DEPT_ID = "dept_id";
|
|
@@ -93,9 +101,36 @@ public class PermissionAspect implements Interceptor {
|
|
|
|
|
|
@Override
|
|
|
public Object intercept(Invocation invocation) throws Throwable {
|
|
|
+ //部门权限
|
|
|
MyuserResDTO user = getSysUser(code);
|
|
|
DataDictionary dept = getSysDept(user);
|
|
|
- if (user == null || dept == null) {
|
|
|
+
|
|
|
+ //岗位权限
|
|
|
+ DataDictionary post = null;
|
|
|
+ // 比较Scope字段并取最大值
|
|
|
+ Integer scope = 2;//1:全部;2部门;3个人
|
|
|
+ if(null !=user){
|
|
|
+ if(null != dept){
|
|
|
+ scope = dept.getScope();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PostUser> postUserList = getUserPostList(user.getId());
|
|
|
+ post = getSysPost(postUserList);
|
|
|
+ // 比较Scope字段并取最大值
|
|
|
+ if(null != post){
|
|
|
+ scope = Integer.min(scope, post.getScope());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //权限最大值不需要后续处理
|
|
|
+ if (scope.equals(DATA_SCOPE_ALL)){
|
|
|
+ return invocation.proceed();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //人员和部门数据为空
|
|
|
+ if (user == null || dept == null ) {
|
|
|
try {
|
|
|
//反射扫包会比较慢,这里做了个懒加载
|
|
|
if (classNames == null) {
|
|
@@ -139,7 +174,7 @@ public class PermissionAspect implements Interceptor {
|
|
|
|
|
|
//是否开启数据权限
|
|
|
boolean isPermission = true;
|
|
|
- isPermission = methodNames.get(newId + "-" + newName);
|
|
|
+ isPermission = null != methodNames.get(newId + "-" + newName) ?methodNames.get(newId + "-" + newName) :false;
|
|
|
if (isPermission) {
|
|
|
// 获取到原始sql语句
|
|
|
String sql = statementHandler.getBoundSql().getSql();
|
|
@@ -158,10 +193,6 @@ public class PermissionAspect implements Interceptor {
|
|
|
return invocation.proceed();
|
|
|
}
|
|
|
|
|
|
- Integer scope = dept.getScope();
|
|
|
- if (scope.equals(DATA_SCOPE_ALL)){
|
|
|
- return invocation.proceed();
|
|
|
- }
|
|
|
if (scope.equals(DATA_SCOPE_DEPT)) {
|
|
|
String deptId = dept.getDataKey();
|
|
|
try {
|
|
@@ -273,7 +304,7 @@ public class PermissionAspect implements Interceptor {
|
|
|
}
|
|
|
|
|
|
@Cacheable(value = "user_code")
|
|
|
- private MyuserResDTO getSysUser(String code) {
|
|
|
+ public MyuserResDTO getSysUser(String code) {
|
|
|
if (StringUtils.isBlank(code) || code.toLowerCase().equals("null")){
|
|
|
return null;
|
|
|
}
|
|
@@ -282,11 +313,36 @@ public class PermissionAspect implements Interceptor {
|
|
|
return user;
|
|
|
}
|
|
|
|
|
|
- private DataDictionary getSysDept(MyuserResDTO user){
|
|
|
+ @Cacheable(cacheNames = "user_id",key= "#userId")
|
|
|
+ public List<PostUser> getUserPostList(String userId) {
|
|
|
+ JSONObject postuserjson = (JSONObject)postUserService.getUserPostList(null,null,userId,request);
|
|
|
+ if(null !=postuserjson){
|
|
|
+ PagResult pagResult = JSONObject.parseObject(postuserjson.toJSONString(), PagResult.class);
|
|
|
+ List<PostUser> list = pagResult.getRecords().toJavaList(PostUser.class);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Cacheable(cacheNames = "user_code_dept",key="#user.id")
|
|
|
+ public DataDictionary getSysDept(MyuserResDTO user){
|
|
|
if (user != null && CacheContext.ddSuperKeyMap.containsKey(DEPT_MARK)){
|
|
|
Optional<DataDictionary> any = CacheContext.ddSuperKeyMap.get(DEPT_MARK).stream().filter(t -> t.getKeyName().equals(user.getDeptName())).findAny();
|
|
|
return any.isPresent() ? any.get() : null;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Cacheable(value = "user_id_post")
|
|
|
+ public DataDictionary getSysPost(List<PostUser> postUsers){
|
|
|
+ if (postUsers != null && postUsers.size()>0 && CacheContext.ddSuperKeyMap.containsKey(POS_MARK)){
|
|
|
+ List<DataDictionary> list = CacheContext.ddSuperKeyMap.get(POS_MARK).stream()
|
|
|
+ .filter(data -> postUsers.stream().anyMatch(user -> user.getPosCode().equals(data.getDataKey()))).collect(Collectors.toList());
|
|
|
+ DataDictionary maxScopeData = list.stream().min(Comparator.comparing(DataDictionary::getScope))
|
|
|
+ .orElse(null);
|
|
|
+ return maxScopeData;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|