类 DictCache

java.lang.Object
net.sohelp.boot.admin.core.cache.DictCache
所有已实现的接口:
ISohelpCache

@Component public class DictCache extends Object implements ISohelpCache
字典缓存(永不过期,按需失效)

整个字典 Map(dictName → List<item>)作为单条 JSON 存入 Key "__all__"。 NONE 模式每次调用触发全量数据库 reload,不持久化任何数据。

实现 ISohelpCache 接口,由 SohelpCacheManageService 统一管理缓存的 重载、清空等操作。

从以下版本开始:
2023/7/17 13:35
作者:
AaronFung
  • 构造器详细资料

    • DictCache

      public DictCache()
  • 方法详细资料

    • init

      @PostConstruct public void init()
      Bean 初始化回调,在依赖注入完成后创建缓存提供者。

      通过 SohelpCacheManager.createProvider(String, long) 创建名称为 "dict"、 永不过期(ttl = 0)的缓存提供者。

    • cacheName

      public String cacheName()
      返回该缓存的唯一名称标识。
      指定者:
      cacheName 在接口中 ISohelpCache
      返回:
      缓存名称,固定为 "dict"
    • cacheDescription

      public String cacheDescription()
      返回该缓存的中文描述信息,用于管理界面展示。
      指定者:
      cacheDescription 在接口中 ISohelpCache
      返回:
      缓存描述,固定为 "字典缓存"
    • reload

      @Comment("\u91cd\u65b0\u52a0\u8f7d\u5185\u5b58") public void reload()
      重新加载字典缓存。

      从数据库全量加载字典数据,并在缓存提供者可用时将数据写入缓存。 如果缓存提供者为 NONE 模式(isEnabled() == false),则只执行数据库查询, 不进行缓存写入。

      指定者:
      reload 在接口中 ISohelpCache
    • getDictData

      @Comment("\u83b7\u53d6\u5168\u90e8\u5b57\u5178") public Map<String,List<Map<String,Object>>> getDictData()
      获取全部字典数据。

      返回所有字典分类及其下属字典项的完整映射。

      返回:
      字典全路径名称 → 字典项列表的映射
    • getDictData

      @Comment("\u6839\u636e\u79df\u6237\u83b7\u53d6\u5b57\u5178\u5217\u8868") public Map<String,List<Map<String,Object>>> getDictData(@Comment("\u79df\u6237ID") Object tenantId)
      根据租户ID获取字典数据。

      在全量字典数据基础上,按 tenant_id 字段过滤,仅返回属于指定租户的字典项。

      参数:
      tenantId - 租户ID,用于过滤字典项中的 tenant_id 字段
      返回:
      字典全路径名称 → 该租户下字典项列表的映射
    • getDict

      @Comment("\u6839\u636e\u5b57\u5178\u83b7\u53d6\u6570\u636e\u5217\u8868") public List<Map<String,Object>> getDict(@Comment("\u5b57\u5178\u540d\u79f0") String dictName)
      根据字典名称获取该字典下的所有数据项。
      参数:
      dictName - 字典全路径名称(如 "系统.状态"
      返回:
      字典项列表;字典名称为空或不存在时返回空列表
    • getDict

      @Comment("\u6839\u636e\u79df\u6237\u83b7\u53d6\u5b57\u5178") public List<Map<String,Object>> getDict(@Comment("\u79df\u6237ID") Object tenantId, @Comment("\u5b57\u5178\u540d\u79f0") String dictName)
      根据租户ID和字典名称获取该字典下属于指定租户的数据项。
      参数:
      tenantId - 租户ID,用于过滤字典项中的 tenant_id 字段
      dictName - 字典全路径名称(如 "系统.状态"
      返回:
      属于指定租户的字典项列表;字典名称为空或不存在时返回空列表
    • getDefaultValue

      public Map<String,Object> getDefaultValue(String dictName)
      获取指定字典中标记为默认值的字典项。

      从字典项列表中查找 isDefault 字段值为 1 的记录。

      参数:
      dictName - 字典全路径名称(如 "系统.状态"
      返回:
      默认字典项的 Map;字典不存在时返回空 Map,字典存在但无默认项时返回 null
    • getValue

      @Comment("\u83b7\u53d6\u5b57\u5178\u548c\u6807\u7b7e\u83b7\u53d6\u67d0\u4e00\u9879\u503c") public Object getValue(@Comment("\u5b57\u5178\u540d\u79f0") String dictName, @Comment("\u6807\u7b7e\u540d") String label)
      根据字典名称和标签名获取对应的字典值。

      在指定字典的所有项中查找 label 字段与给定标签匹配的项,返回其 value

      参数:
      dictName - 字典全路径名称(如 "系统.状态"
      label - 标签名,用于匹配字典项中的 label 字段
      返回:
      匹配项的 value 值;未找到或字典不存在时返回 null
    • getValue

      @Comment("\u6839\u636e\u79df\u6237\u83b7\u53d6\u5b57\u5178\u503c") public Object getValue(@Comment("\u79df\u6237ID") Object tenantId, @Comment("\u5b57\u5178\u540d\u79f0") String dictName, @Comment("\u6807\u7b7e\u540d") String label)
      根据租户ID、字典名称和标签名获取对应的字典值。

      先按租户过滤字典项,再在过滤后的列表中查找 label 字段匹配的项。

      参数:
      tenantId - 租户ID,用于过滤字典项
      dictName - 字典全路径名称(如 "系统.状态"
      label - 标签名,用于匹配字典项中的 label 字段
      返回:
      匹配项的 value 值;未找到或字典不存在时返回 null
    • getLabel

      @Comment("\u6839\u636e\u5b57\u5178\u548c\u503c\uff0c\u83b7\u53d6\u6807\u7b7e") public String getLabel(@Comment("\u5b57\u5178\u540d\u79f0") String dictName, @Comment("\u503c") Object value)
      根据字典名称和值获取对应的标签名。

      在指定字典的所有项中查找 value 字段(转为字符串后)与给定值匹配的项, 返回其 label

      参数:
      dictName - 字典全路径名称(如 "系统.状态"
      value - 字典值,用于匹配字典项中的 value 字段(按字符串比较)
      返回:
      匹配项的 label 标签名;字典不存在时返回空串,未匹配时返回 null
    • getLabel

      @Comment("\u6839\u636e\u79df\u6237\u83b7\u53d6\u5b57\u5178\u6807\u7b7e") public String getLabel(@Comment("\u79df\u6237ID") Object tenantId, @Comment("\u5b57\u5178\u540d\u79f0") String dictName, @Comment("\u503c") Object value)
      根据租户ID、字典名称和值获取对应的标签名。

      先按租户过滤字典项,再在过滤后的列表中查找 value 字段匹配的项。

      参数:
      tenantId - 租户ID,用于过滤字典项
      dictName - 字典全路径名称(如 "系统.状态"
      value - 字典值,用于匹配字典项中的 value 字段(按字符串比较)
      返回:
      匹配项的 label 标签名;字典不存在时返回空串,未匹配时返回 null