liuyun d2c75bd04c chore(openspec): sync foundation specs to main, archive init-shared-foundation
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-10 21:17:45 +08:00

61 lines
2.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Data Model Specification
## Purpose
定义系统数据模型的字段字典:实体目录、公共字段、枚举、状态机与命名约定,作为前后端字段一致性的唯一锚点。
## Requirements
### Requirement: 业务实体公共字段
所有业务软删实体 SHALL 携带公共字段:id(UUID v7)、tenant_code、created_at、created_by、updated_at、deleted_at;日志/会话类实体不携带 deleted_at。
#### Scenario: 创建记录
- **WHEN** 创建任一业务实体记录
- **THEN** 系统自动填充 id、tenant_code、created_at、created_by
#### Scenario: 软删
- **WHEN** 删除业务实体
- **THEN** 系统置 deleted_at 而非物理删除
### Requirement: 实体目录
系统 SHALL 包含实体 tenant、user、role、resource、org、dict_type、dict_item、config、audit_log、login_log、refresh_token,以及关联表 user_role、role_resource、role_org。
#### Scenario: 字典拆分
- **WHEN** 维护数据字典
- **THEN** 字典分为 dict_type(类型)与 dict_item(项)两类,经 dict_type_code 关联
### Requirement: 资源类型与代码
resource 实体 SHALL 通过 type 字段区分菜单(menu)、按钮(button)、接口(api)三种类型;「目录」由菜单节点是否拥有菜单子节点推导,不设独立类型。每个 resource SHALL 拥有租户内唯一的 code,作为关联键与权限标识。
#### Scenario: 按钮鉴权点
- **WHEN** 前端需要按钮级权限
- **THEN** 该按钮登记为 type=button 的资源,并携带 code 权限标识
### Requirement: 引用键约定
所有跨实体引用 SHALL 优先使用业务键:角色、资源、组织、字典类型、租户用 code,树的父引用用 parent_code;对用户的引用 SHALL 使用用户 id。关联表 sys_user_role、sys_role_resource、sys_role_org 分别保存 user_id+role_code、role_code+resource_code、role_code+org_code;其余引用(user.org_code、dict_item.dict_type_code、resource.parent_code、org.parent_code)同理。
#### Scenario: 为角色分配资源
- **WHEN** 管理员为角色分配资源
- **THEN** 关联记录保存 role_code 与 resource_code
### Requirement: 数据权限档位
role 实体 SHALL 通过 data_scope 字段支持全部/本部门/本部门及以下/本人/自定义五档;「自定义」经 role_org 关联表声明可见部门。
#### Scenario: 本部门及以下
- **WHEN** 角色数据权限为「本部门及以下」
- **THEN** 该角色用户仅可见本部门及下级部门的数据
### Requirement: 命名与表前缀
所有脚手架表 SHALL 以 sys_ 前缀命名,数据库列名采用 snake_case。
#### Scenario: 表命名
- **WHEN** 新建脚手架表
- **THEN** 表名以 sys_ 开头,列名使用 snake_case
### Requirement: 用户状态机
user 实体 SHALL 支持启用/停用/锁定状态;停用与锁定的用户 SHALL 无法登录。
#### Scenario: 锁定登录
- **WHEN** 锁定用户尝试登录
- **THEN** 系统拒绝登录并提示账号已锁定