mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-09-06 04:18:07 +00:00
update 使用 SaStorage 优化 DataPermissionHelper.getContext() 获取
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
package com.ruoyi.common.mybatis.helper;
|
||||
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.context.model.SaStorage;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.ruoyi.common.core.utils.ServletUtils;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.dubbo.rpc.RpcContext;
|
||||
import org.apache.dubbo.rpc.RpcServiceContext;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -35,21 +33,11 @@ public class DataPermissionHelper {
|
||||
}
|
||||
|
||||
public static Map<String, Object> getContext() {
|
||||
HttpServletRequest request = ServletUtils.getRequest();
|
||||
Object attribute;
|
||||
if (request != null) {
|
||||
attribute = request.getAttribute(DATA_PERMISSION_KEY);
|
||||
if (ObjectUtil.isNull(attribute)) {
|
||||
request.setAttribute(DATA_PERMISSION_KEY, new HashMap<>());
|
||||
attribute = request.getAttribute(DATA_PERMISSION_KEY);
|
||||
}
|
||||
} else {
|
||||
RpcServiceContext context = RpcContext.getServiceContext();
|
||||
attribute = context.getObjectAttachment(DATA_PERMISSION_KEY);
|
||||
if (ObjectUtil.isNull(attribute)) {
|
||||
context.setObjectAttachment(DATA_PERMISSION_KEY, new HashMap<>());
|
||||
attribute = context.getObjectAttachment(DATA_PERMISSION_KEY);
|
||||
}
|
||||
SaStorage saStorage = SaHolder.getStorage();
|
||||
Object attribute = saStorage.get(DATA_PERMISSION_KEY);
|
||||
if (ObjectUtil.isNull(attribute)) {
|
||||
saStorage.set(DATA_PERMISSION_KEY, new HashMap<>());
|
||||
attribute = saStorage.get(DATA_PERMISSION_KEY);
|
||||
}
|
||||
if (attribute instanceof Map) {
|
||||
return (Map<String, Object>) attribute;
|
||||
|
Reference in New Issue
Block a user