Data Dictionary
提供可动态维护的业务字典类型和条目。业务代码通过 DictionaryService 读取启用条目;数据保存在关系数据库,修改后无需重新部署。它不承担
ConfigCenter 的应用配置职责。
引入
<dependency>
<groupId>io.github.loadup-cloud</groupId>
<artifactId>loadup-modules-dictionary-core</artifactId>
</dependency>模块使用 JDBC,数据库连接与驱动由消费应用配置;模块引入 Flyway,迁移脚本为
db/migration/framework/dictionary/V20261002000002__create_data_dictionary.sql。Pay 消费基线为 PostgreSQL。已有非空库首次启用
Flyway 时,按应用现有配置处理 baseline。需要 HTTP 接口时再引入 loadup-modules-dictionary-web。
业务 API
注入 DictionaryService,通过 listEnabledItems(tenantId, typeCode)
读取有效条目。类型或条目禁用后立即不再出现在结果中;管理端列表仍能查看禁用记录。类型编码创建后不可更改,统一转为小写;条目
value 创建后不可更改。同一租户内类型编码唯一,同一类型内 value 唯一。
类型支持创建、更新、分页查询、空类型删除;条目支持创建、更新、分页查询、删除。删除类型前必须先删除其条目。页大小为
1–100。没有租户上下文时使用保留租户 __default__。设置 loadup.modules.dictionary.enabled: false 可关闭服务自动装配。
设计与持久化边界见 ARCHITECTURE.md。
模块选择
本目录的 Maven 坐标 loadup-modules-dictionary 为聚合 POM。业务接入选择具体 jar,版本由根 BOM 管理:
| 子模块 | 用途 |
|---|---|
client |
对外 DTO、请求契约;不依赖 Spring 或持久化实现 |
core |
领域模型、用例服务、DTO 映射、JDBC Gateway 与 Flyway 迁移;程序化接入入口 |
web |
可选 Spring MVC 适配;自动引入 core |
DictionaryService 现在位于 io.github.loadup.modules.dictionary.app.service;公开结果位于
io.github.loadup.modules.dictionary.client.dto。领域 Gateway 不引用客户端 DTO,也不引用数据库或 Spring API。HTTP
适配使用客户端契约,接口路径及 JSON 字段保持一致。
配置统一归入 loadup.modules.dictionary:
loadup:
modules:
dictionary:
enabled: true
web:
enabled: true仅引入 core 时不注册 Controller;关闭 web 开关保留程序化服务,关闭模块 enabled 开关同时停止默认应用与持久化 Bean 装配。配置开关不控制 Flyway 对已在 classpath 上的脚本执行。不要在已有数据库重复复制迁移脚本。
公共分页与时间约定
分页请求、DTO、HTTP 响应结构及共享时间规则见 commons-dto 文档。
字典创建项直接提交 {typeCode, value, label, description, sortOrder, enabled};更新类型或条目直接提交 {id, ...更新字段}。
错误码契约
公开错误枚举位于 io.github.loadup.modules.dictionary.client.error.DictionaryResultCodeEnum,错误码以 DICTIONARY_
开头。服务/领域/仓储使用 CommonException(enum);系统原因可作为 cause 保留,响应文案仅来自枚举。WebMVC 统一返回 HTTP 200 的
result/data。枚举码按稳定公开契约维护,不用字符串消息覆盖。
Flyway 迁移目录
正式迁移位于 db/migration/framework/dictionary/,文件名、版本和 SQL 内容保持不变。消费应用在
loadup.flyway.locations 中显式加入 classpath:db/migration/framework/dictionary,与应用自己的迁移共同自动执行。
不要用共享根 classpath:db/migration 表达应用隔离;它也会扫描依赖 JAR。已执行版本只追加升级,不改写历史。
设计与实现
职责与边界
loadup-modules-dictionary 提供 DictionaryService、纯 Java 记录模型、DictionaryGateway 契约和 JDBC 实现;
loadup-modules-dictionary-web 是可选 MVC 适配。模块不依赖 UPMS、审计中心或 ConfigCenter。
类型/条目管理 → DictionaryService → DictionaryGateway → JDBC / 关系数据库
有效条目读取 → DictionaryService → 启用类型检查 → 启用条目有序查询数据与一致性
dictionary_type 按 type_code 唯一,dictionary_item 按 (type_id, item_value) 唯一,条目通过外键引用类型。两表保留标准
id、created_at、updated_at、deleted 列,不含 tenant_id;当前删除为物理删除,类型有条目时拒绝删除。类型编码和值不可修改,避免已被业务引用的含义发生漂移。
写操作由 @Transactional 包裹。管理查询返回含停用数据的分页结果;业务读取只有在类型启用时才返回启用条目,按排序值、标签、value
排序。每次读取直接访问数据库,因此修改立即可见,不引入缓存失效问题。
租户与扩展
租户身份仍由可信执行上下文传递,不接受客户端在请求体中指定租户;但 Repository 不使用 tenant_id 行谓词。当前 TenantFilter 绑定默认租户,
schema 路由未实现,因此该模块目前只在默认 schema 中运行,不提供租户间数据库隔离。详见数据库 README。模块提供 Flyway 迁移,不声明必需的数据库厂商;数据库连接与驱动由消费应用配置,Pay 消费基线为 PostgreSQL。
接入方式见 README.md。
COLA 职责与装配
web → app → domain
↓ ↑
client infrastructure → JDBC / Flyway- client 定义不可变请求和 DTO,domain 保留领域模型与
DictionaryGateway端口;应用边界由DictionaryDTOConverter以 MapStruct Spring 模式映射。 DictionaryPersistenceAutoConfiguration归 infrastructure,按 DataSource 和loadup.modules.dictionary.enabled提供默认 Gateway,消费者可覆盖接口 Bean。- app 在持久化装配之后按 Gateway 及所需组件条件创建
DictionaryService。生成的 converter 通过显式@Import注册,避免 REGISTER_BEAN 阶段条件与组件扫描冲突。 - web 只负责路由、可信身份/租户、方法授权和 HTTP 投影;请求契约归 client。全局响应、Jackson 与
/api前缀由 WebMVC 组件处理。 - 仓储使用 Spring JDBC 与 Spring MapStruct;显式处理锁、幂等及状态条件。Flyway 初始脚本使用 PostgreSQL 结构。
- 所有子模块 parent 指向根
loadup-parent,所有内部依赖坐标由 BOM 管理。
配置契约迁移到 loadup.modules.dictionary.*,不保留旧前缀别名。自动装配、覆盖默认 Gateway 和关闭功能的回归源码见
DictionaryAutoConfigurationTest;真实数据库与 HTTP 验收由消费工程完成。
公共边界与映射约束
Facade 是 client 的业务契约,应用服务直接实现;Controller 和跨模块消费者依赖 Facade。domain 保留业务状态、规则与 Gateway,表示层字段转换交给 Spring 管理的 MapStruct。共享配置固定 Spring 模式、构造器注入和目标字段严格校验。
仓储显式维护 ID、审计时间、租户和逻辑删除字段。字典删除与文件引用解绑明确使用物理删除;文件状态、通知归档和任务生命周期是业务状态,独立于 BaseDO 的 deleted。
所有数据对象的诊断文本使用 commons-json;诊断序列化与真实 API JSON 分离,避免因 HTTP 脱敏设置改变日志中的凭证披露规则。
Client 入参与分页边界
client.command 表达业务写动作,client.query 表达只读条件;Controller 和 Facade 共用入参契约。模块专用 PageDTO 已移除,app 将领域分页对象映射为 commons-dto 的 PageDTO;Web 输出 PageResponse,避免分页结构随模块变化。领域 Gateway 的分页返回值不携带 HTTP envelope。
通用输入与时间约定
分页缺省 page=1、size=20,size 上限 100;非法输入使用稳定业务错误码。业务时间与持久化使用 Spring 共享的 Clock,默认采用系统本地时区;测试或消费工程可提供 Clock Bean 覆盖默认值。
错误码契约
公开错误枚举位于 io.github.loadup.modules.dictionary.client.error.DictionaryResultCodeEnum,错误码以 DICTIONARY_
开头。服务/领域/仓储使用 CommonException(enum);系统原因可作为 cause 保留,响应文案仅来自枚举。WebMVC 统一返回 HTTP 200 的
result/data。枚举码按稳定公开契约维护,不用字符串消息覆盖。
Unified pagination contract
Pure pagination inputs reuse io.github.loadup.commons.dto.PageQuery. HTTP fields remain page and size, with
omitted/null values defaulting to 1 and 20; explicit invalid bounds are rejected and size is capped at 100. Business
queries retain their filter fields and flat pagination fields but delegate policy to PageQuery.normalized, preserving
their declared module error code. Mutable UPMS queries expose pagination() for validation at the service boundary.
Sort whitelists remain business-specific.
Domain Gateway results use io.github.loadup.commons.domain.PageResult<T>, shared with UPMS. Seven duplicate business
Page wrappers have been removed. Application mapping uses the injected Spring MapStruct item converter and
PageResult.map; PageDTO.of(result) adapts the unchanged total/page/size metadata. Facades return PageDTO, and
Controllers return PageResponse. No HTTP envelope enters a Gateway.
The response remains {result, data: [...], pageInfo: {totalCount, pageIndex, pageSize, ...}}; data is the current-page
array. SuccessResponse serves ordinary success data only; its duplicate pagination field and ofPage factories have been
removed. Empty PageDTO defaults to an empty array and metadata 0/1/20. Existing consumer code referencing removed
business Page wrappers, DictionaryTypePageQuery, AccountLoginPageQuery or SuccessResponse.ofPage must use the shared
contracts. No URL or frontend payload-field migration is required.