package cc.smtweb.system.bpm.web.sys.user.menu;

import cc.smtweb.framework.core.annotation.SwCache;
import cc.smtweb.framework.core.cache.AbstractEntityCache;
import cc.smtweb.framework.core.cache.CacheManager;

import java.util.HashSet;
import java.util.Set;

/**
 * Created by 1 at 2022-08-03 18:04:34
 * 实体【[菜单定义](SYS_MENU)】的缓存类
 */
@SwCache(ident = "SYS_MENU", title = "菜单定义")
public class MenuCache extends AbstractEntityCache<Menu> {
    //缓存key：按目录
    public final static String mk_m = "m";

    public static MenuCache getInstance() {
        return CacheManager.getIntance().getCache(MenuCache.class);
    }

    public MenuCache() {
        //缓存key：按目录
        regList(mk_m, "sm_mc_id");
    }

    //缓存key：按目录
    public final Set<Menu> getByM(String key) {
        return getListByKey(mk_m, key);
    }


    public final String getPath(long menu_id) {
        Menu menu = get(menu_id);
        if (menu == null) return "";
        return menu.getPath();
    }

    public final String getPageId(long menu_id) {
        Menu menu = get(menu_id);
        if (menu == null) return "";
        return menu.getPageId();
    }

    public final Set<String> getRight(long menu_id, String type) {
        Menu menu = get(menu_id);
        if (menu == null) return new HashSet<>();
        return menu.getRightSet(type);
    }
}
