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

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

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

/**
 * Created by 1 at 2022-07-28 19:15:18
 * 实体【[角色表](SYS_ROLE)】的缓存类
 */
@SwCache(ident = "SYS_ROLE", title = "角色表")
public class RoleCache extends AbstractEntityCache<Role> {
    //缓存key：按编码
    public final static String mk_code = "code";

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

    public RoleCache() {
        //缓存key：按编码
        regMap(mk_code, "srl_code");
    }

    //缓存key：按编码
    public final Role getByCode(String key) {
        return getByKey(mk_code, key);
    }

    public final String getNamesByIds(Set<Long> key) {
        Set<String> names = new HashSet<>();
        key.forEach(k -> {
            names.add(get(k).getName());
        });
        return StringUtil.join(names,",");
    }
}
