All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zznote.basecommon.common.helper.DataPermissionHelper Maven / Gradle / Ivy

The newest version!
package com.zznote.basecommon.common.helper;


import cn.hutool.core.util.ObjectUtil;
import com.zznote.basecommon.common.util.ServletUtils;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 数据权限助手
 *
 * @author zhangzhen
 * @version 3.5.0
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@SuppressWarnings("unchecked cast")
public class DataPermissionHelper {

    private static final String DATA_PERMISSION_KEY = "data:permission";

    public static  T getVariable(String key) {
        Map context = getContext();
        return (T) context.get(key);
    }


    public static void setVariable(String key, Object value) {
        Map context = getContext();
        context.put(key, value);
    }

    public static Map getContext() {
        HttpServletRequest request = ServletUtils.getRequest();
        Object attribute = request.getAttribute(DATA_PERMISSION_KEY);
        if (ObjectUtil.isNull(attribute)) {
            request.setAttribute(DATA_PERMISSION_KEY, new HashMap<>());
            attribute = request.getAttribute(DATA_PERMISSION_KEY);
        }
        if (attribute instanceof Map) {
            return (Map) attribute;
        }
        throw new NullPointerException("data permission context type exception");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy