✨ 用户编辑支持数据管理权限多选组织并与角色权限并集
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+32
@@ -35,6 +35,9 @@ import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.system.pojo.entity.User;
|
||||
import org.springblade.system.feign.IUserClient;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.springblade.core.cache.constant.CacheConstant.USER_CACHE;
|
||||
import static org.springblade.core.launch.constant.FlowConstant.TASK_USR_PREFIX;
|
||||
|
||||
@@ -47,6 +50,7 @@ import static org.springblade.core.launch.constant.FlowConstant.TASK_USR_PREFIX;
|
||||
public class UserCache {
|
||||
private static final String USER_CACHE_ID = "user:id:";
|
||||
private static final String USER_CACHE_ACCOUNT = "user:account:";
|
||||
private static final String USER_CACHE_MANAGE_DEPT = "user:manage-dept:";
|
||||
|
||||
private static IUserClient userClient;
|
||||
|
||||
@@ -89,6 +93,26 @@ public class UserCache {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户「数据管理权限」组织(含下级展开)
|
||||
*
|
||||
* @param userId 用户主键
|
||||
* @return 可管理组织 ID 集合
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Long> getManageDeptIds(Long userId) {
|
||||
if (userId == null || userId <= 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
try {
|
||||
List<Long> deptIdList = CacheUtil.get(USER_CACHE, USER_CACHE_MANAGE_DEPT, userId, () -> loadManageDeptIds(userId));
|
||||
return deptIdList == null ? Collections.emptyList() : deptIdList;
|
||||
} catch (RuntimeException exception) {
|
||||
log.warn("用户数据管理组织缓存读取失败,改为直连查询, userId={}", userId, exception);
|
||||
return loadManageDeptIds(userId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户姓名
|
||||
*
|
||||
@@ -153,6 +177,14 @@ public class UserCache {
|
||||
return result.getData();
|
||||
}
|
||||
|
||||
private static List<Long> loadManageDeptIds(Long userId) {
|
||||
R<List<Long>> result = getUserClient().manageDeptIds(userId);
|
||||
if (result == null || !result.isSuccess() || result.getData() == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return result.getData();
|
||||
}
|
||||
|
||||
private static void clearBrokenUserCache() {
|
||||
CacheUtil.clear(USER_CACHE);
|
||||
CacheUtil.clear(USER_CACHE, Boolean.FALSE);
|
||||
|
||||
+12
@@ -37,6 +37,8 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User Feign接口类
|
||||
*
|
||||
@@ -62,6 +64,7 @@ public interface IUserClient {
|
||||
String REGISTER_USER = API_PREFIX + "/register-user";
|
||||
String REMOVE_USER = API_PREFIX + "/remove-user";
|
||||
String BIND_WX_MINI_OPENID = API_PREFIX + "/bind-wx-mini-openid";
|
||||
String MANAGE_DEPT_IDS = API_PREFIX + "/manage-dept-ids";
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
@@ -72,6 +75,15 @@ public interface IUserClient {
|
||||
@GetMapping(USER_BY_ID)
|
||||
R<User> userInfoById(@RequestParam("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 解析用户「数据管理权限」组织(含下级)
|
||||
*
|
||||
* @param userId 用户主键
|
||||
* @return 可管理组织 ID 集合
|
||||
*/
|
||||
@GetMapping(MANAGE_DEPT_IDS)
|
||||
R<List<Long>> manageDeptIds(@RequestParam("userId") Long userId);
|
||||
|
||||
|
||||
/**
|
||||
* 根据账号获取用户信息
|
||||
|
||||
Reference in New Issue
Block a user