|
@@ -1,6 +1,7 @@
|
|
package com.dayou.aspect;
|
|
package com.dayou.aspect;
|
|
|
|
|
|
import com.dayou.annotation.DataPermission;
|
|
import com.dayou.annotation.DataPermission;
|
|
|
|
+import com.dayou.common.SimpleListModel;
|
|
import com.dayou.service.IUserService;
|
|
import com.dayou.service.IUserService;
|
|
import com.dayou.utils.LoginContext;
|
|
import com.dayou.utils.LoginContext;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -14,7 +15,9 @@ import org.springframework.stereotype.Component;
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Field;
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
|
|
+import java.util.List;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 类说明:
|
|
* 类说明:
|
|
@@ -39,17 +42,28 @@ public class DataPermissionAop {
|
|
|
|
|
|
@Around("dataPermissionPointcut() && @annotation(dataPermission)")
|
|
@Around("dataPermissionPointcut() && @annotation(dataPermission)")
|
|
public Object beforeHandle(ProceedingJoinPoint joinPoint, DataPermission dataPermission) throws Throwable {
|
|
public Object beforeHandle(ProceedingJoinPoint joinPoint, DataPermission dataPermission) throws Throwable {
|
|
- Set<Long> users = new HashSet<>();
|
|
|
|
- Long userId = LoginContext.getUserId();
|
|
|
|
- if (dataPermission.child()){
|
|
|
|
|
|
+
|
|
|
|
+ Object arg = joinPoint.getArgs()[0];
|
|
|
|
+
|
|
|
|
+ if (dataPermission.department()){
|
|
|
|
+ List<Long> departmentIds = LoginContext.getLoginCacheUserBO().getDepartmentList().stream()
|
|
|
|
+ .map(SimpleListModel::getId).collect(Collectors.toList());
|
|
|
|
+ Field departments = arg.getClass().getDeclaredField("departmentIds");
|
|
|
|
+ departments.setAccessible(Boolean.TRUE);
|
|
|
|
+ departments.set(arg,departmentIds);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (dataPermission.postChild()){
|
|
|
|
+ Set<Long> users = new HashSet<>();
|
|
|
|
+ Long userId = LoginContext.getUserId();
|
|
//根据当前登录人获取下属员工id
|
|
//根据当前登录人获取下属员工id
|
|
users = userService.getJuniorUserId(userId);
|
|
users = userService.getJuniorUserId(userId);
|
|
|
|
+ users.add(userId);
|
|
|
|
+ Field userIds = arg.getClass().getDeclaredField("userIds");
|
|
|
|
+ userIds.setAccessible(Boolean.TRUE);
|
|
|
|
+ userIds.set(arg,users);
|
|
}
|
|
}
|
|
- users.add(userId);
|
|
|
|
- Object arg = joinPoint.getArgs()[0];
|
|
|
|
- Field userIds = arg.getClass().getDeclaredField("userIds");
|
|
|
|
- userIds.setAccessible(Boolean.TRUE);
|
|
|
|
- userIds.set(arg,users);
|
|
|
|
|
|
+
|
|
return joinPoint.proceed();
|
|
return joinPoint.proceed();
|
|
|
|
|
|
}
|
|
}
|