391 lines
12 KiB
Markdown
391 lines
12 KiB
Markdown
# FMS 新系统核心表结构
|
|
|
|
> 目标结构基于 2026-09-04 只读拉取的 `FMS-NEW` 数据库整理。
|
|
> 平台配置使用字符串业务键;未来业务数据表使用 `bigint` 雪花 ID。
|
|
|
|
## 1. 用户表
|
|
|
|
```sql
|
|
create table dbo.b_user (
|
|
b_id varchar(50) not null primary key, -- 用户账号本身
|
|
b_name nvarchar(100) null,
|
|
b_bz nvarchar(400) null,
|
|
b_password nvarchar(255) not null,
|
|
b_canuse tinyint not null default 1,
|
|
b_logintime tinyint not null default 0
|
|
);
|
|
```
|
|
|
|
## 2. 模块
|
|
|
|
```sql
|
|
create table dbo.s_module (
|
|
b_id varchar(50) not null primary key, -- 模块编码本身,创建后不可修改
|
|
b_parent_id varchar(50) null,
|
|
b_name nvarchar(200) not null,
|
|
b_i18n varchar(150) null,
|
|
b_module_type varchar(20) not null,
|
|
b_viewtable varchar(128) null,
|
|
b_savetable varchar(128) null,
|
|
b_keyfield varchar(50) null,
|
|
b_orderfield varchar(500) null,
|
|
b_delete_policy varchar(20) null,
|
|
b_canuse tinyint not null default 1,
|
|
b_xh int not null default 0,
|
|
b_bz nvarchar(2000) null,
|
|
b_edit_mode varchar(10) null
|
|
);
|
|
|
|
create index ix_s_module_parent
|
|
on dbo.s_module (b_parent_id, b_xh, b_canuse, b_id);
|
|
|
|
create index ix_s_module_order
|
|
on dbo.s_module (b_xh, b_id);
|
|
|
|
create index ix_s_module_savetable
|
|
on dbo.s_module (b_savetable);
|
|
```
|
|
|
|
## 3. 字段和字段布局
|
|
|
|
> 状态字段统一使用 `tinyint` 保存 0/1,由业务层负责校验取值。`b_canuse` 表示记录或配置是否启用、是否参与运行;`b_visible` 表示当前列表或编辑场景是否展示,二者语义不同,不互相替代。
|
|
|
|
```sql
|
|
create table dbo.s_field (
|
|
b_module_id varchar(50) not null,
|
|
b_field varchar(50) not null,
|
|
b_name nvarchar(200) not null,
|
|
b_i18n varchar(150) null,
|
|
b_type varchar(30) not null,
|
|
b_dbtype varchar(30) not null,
|
|
b_length int null,
|
|
b_precision int null,
|
|
b_scale int null,
|
|
b_nullable tinyint not null default 1,
|
|
b_default_value nvarchar(1000) null,
|
|
b_db_default nvarchar(1000) null,
|
|
b_writemode varchar(20) not null default 'direct',
|
|
b_options nvarchar(max) null,
|
|
b_canuse tinyint not null default 1,
|
|
b_xh int not null default 0, -- 字段定义顺序:模块「同步字段」时按查询视图列序(10 起步)重排
|
|
primary key (b_module_id, b_field)
|
|
);
|
|
|
|
create index ix_s_field_module_order
|
|
on dbo.s_field (b_module_id, b_xh, b_field);
|
|
|
|
create table dbo.s_field_group (
|
|
b_id varchar(50) not null, -- 分组编码本身,模块内唯一,创建后不可修改
|
|
b_module_id varchar(50) not null,
|
|
b_parent_id varchar(50) null, -- 父分组编码,NULL 表示根分组
|
|
b_title nvarchar(200) not null,
|
|
b_i18n varchar(150) null,
|
|
b_xh int not null default 0,
|
|
b_canuse tinyint not null default 1,
|
|
b_colspan int not null default 48,
|
|
b_layout_direction varchar(10) null default 'vertical',
|
|
primary key (b_module_id, b_id)
|
|
);
|
|
|
|
create index ix_s_field_group_parent
|
|
on dbo.s_field_group (b_module_id, b_parent_id, b_xh, b_id);
|
|
|
|
create index ix_s_field_group_order
|
|
on dbo.s_field_group (b_module_id, b_xh, b_id);
|
|
|
|
create table dbo.s_field_view (
|
|
b_module_id varchar(50) not null,
|
|
b_field varchar(50) not null,
|
|
b_group_id varchar(50) null, -- 引用同模块 s_field_group.b_id
|
|
b_visible tinyint not null default 1,
|
|
b_xh int not null default 0,
|
|
b_width int null,
|
|
primary key (b_module_id, b_field)
|
|
);
|
|
|
|
create index ix_s_field_view_order
|
|
on dbo.s_field_view (b_module_id, b_xh, b_field);
|
|
|
|
create table dbo.s_field_edit (
|
|
b_module_id varchar(50) not null,
|
|
b_field varchar(50) not null,
|
|
b_group_id varchar(50) null, -- 引用同模块 s_field_group.b_id
|
|
b_visible tinyint not null default 1,
|
|
b_required tinyint not null default 0,
|
|
b_readonly tinyint not null default 0,
|
|
b_disabled tinyint not null default 0,
|
|
b_xh int not null default 0,
|
|
b_width int null,
|
|
b_placeholder nvarchar(400) null,
|
|
b_colspan int not null default 12,
|
|
b_height int null,
|
|
primary key (b_module_id, b_field)
|
|
);
|
|
|
|
create index ix_s_field_edit_order
|
|
on dbo.s_field_edit (b_module_id, b_xh, b_field);
|
|
|
|
create table dbo.s_field_query (
|
|
b_module_id varchar(50) not null,
|
|
b_field varchar(50) not null,
|
|
b_component varchar(30) null,
|
|
b_condition_no int not null default 1,
|
|
b_operator varchar(20) not null,
|
|
b_default_value nvarchar(1000) null,
|
|
b_canuse tinyint not null default 1,
|
|
b_xh int not null default 0,
|
|
primary key (b_module_id, b_field, b_condition_no)
|
|
);
|
|
|
|
create index ix_s_field_query_order
|
|
on dbo.s_field_query (b_module_id, b_xh, b_field, b_condition_no);
|
|
```
|
|
|
|
## 4. 自动编码
|
|
|
|
```sql
|
|
create table dbo.s_autocode (
|
|
b_module_id varchar(50) not null,
|
|
b_field varchar(50) not null,
|
|
b_prefix nvarchar(200) not null default N'',
|
|
b_dateformat varchar(30) not null default 'yyyyMM',
|
|
b_separator nvarchar(20) not null default N'-',
|
|
b_seqwidth int not null default 5,
|
|
b_resettype varchar(10) not null default 'month',
|
|
b_startvalue bigint not null default 1,
|
|
b_currentperiod varchar(8) null,
|
|
b_currentvalue bigint not null default 0,
|
|
b_canuse tinyint not null default 1,
|
|
primary key (b_module_id, b_field)
|
|
);
|
|
```
|
|
|
|
## 5. 模块关系
|
|
|
|
```sql
|
|
create table dbo.s_relation (
|
|
b_module_id varchar(50) not null,
|
|
b_target_module_id varchar(50) not null,
|
|
b_relation_type varchar(20) not null,
|
|
b_field varchar(50) not null,
|
|
b_target_field varchar(50) not null,
|
|
b_foreign_side varchar(10) null,
|
|
b_junction_module_id varchar(50) null,
|
|
b_junction_field varchar(50) null,
|
|
b_junction_target_field varchar(50) null,
|
|
b_ownership varchar(20) not null default 'reference',
|
|
b_owner_side varchar(10) null,
|
|
b_delete_policy varchar(20) null,
|
|
b_order_module_id varchar(50) null,
|
|
b_order_field varchar(50) null,
|
|
b_canuse tinyint not null default 1,
|
|
b_xh int not null default 0,
|
|
primary key (b_module_id, b_field, b_target_module_id, b_target_field)
|
|
);
|
|
|
|
create index ix_s_relation_module
|
|
on dbo.s_relation (b_module_id, b_canuse, b_xh, b_field, b_target_module_id);
|
|
|
|
create index ix_s_relation_target
|
|
on dbo.s_relation (b_target_module_id);
|
|
```
|
|
|
|
## 6. 菜单
|
|
|
|
```sql
|
|
create table dbo.s_menu (
|
|
b_id varchar(50) not null primary key, -- 菜单编码本身
|
|
b_parent_id varchar(50) null,
|
|
b_name nvarchar(200) not null,
|
|
b_i18n varchar(150) null,
|
|
b_menu_type varchar(20) not null,
|
|
b_route varchar(200) null,
|
|
b_module_id varchar(50) null,
|
|
b_icon varchar(50) null,
|
|
b_xh int not null default 0,
|
|
b_canuse tinyint not null default 1
|
|
);
|
|
|
|
create index ix_s_menu_parent
|
|
on dbo.s_menu (b_parent_id, b_xh, b_canuse, b_id);
|
|
|
|
create index ix_s_menu_order
|
|
on dbo.s_menu (b_xh, b_id);
|
|
|
|
create index ix_s_menu_module
|
|
on dbo.s_menu (b_module_id);
|
|
|
|
create index ix_s_menu_route
|
|
on dbo.s_menu (b_route, b_canuse, b_id);
|
|
```
|
|
|
|
## 7. 权限
|
|
|
|
```sql
|
|
create table dbo.s_power (
|
|
b_id varchar(50) not null primary key, -- 权限编码本身
|
|
b_name nvarchar(200) not null,
|
|
b_i18n varchar(150) null,
|
|
b_power_type varchar(20) not null,
|
|
b_resource varchar(128) null,
|
|
b_module_id varchar(50) null,
|
|
b_field varchar(50) null,
|
|
b_operation varchar(30) not null,
|
|
b_canuse tinyint not null default 1,
|
|
b_xh int not null default 0
|
|
);
|
|
|
|
create index ix_s_power_module
|
|
on dbo.s_power (b_module_id, b_field, b_canuse);
|
|
|
|
create index ix_s_power_resource
|
|
on dbo.s_power (b_power_type, b_resource, b_canuse);
|
|
```
|
|
|
|
## 8. 多语言
|
|
|
|
```sql
|
|
-- b_i18n / b_key 保存完整资源键,不追加 .name 或 .title 后缀:
|
|
-- s_module.b_i18n = module.<module_id>
|
|
-- s_field.b_i18n = field.<module_id>.<b_field>
|
|
-- s_field_group.b_i18n = field_group.<module_id>.<b_id>
|
|
-- s_menu.b_i18n = menu.<b_id>
|
|
|
|
create table dbo.s_i18n_type (
|
|
b_id varchar(20) not null primary key, -- 语言编码本身
|
|
b_name nvarchar(200) not null,
|
|
b_canuse tinyint not null default 1,
|
|
b_default tinyint not null default 0,
|
|
b_xh int not null default 0
|
|
);
|
|
|
|
create table dbo.s_i18n (
|
|
b_id varchar(200) not null primary key, -- b_key + ':' + b_locale
|
|
b_key varchar(150) not null,
|
|
b_locale varchar(20) not null,
|
|
b_value nvarchar(1000) not null,
|
|
b_i18ntype varchar(20) null,
|
|
b_canuse tinyint not null default 1,
|
|
b_module_id varchar(50) null,
|
|
unique (b_key, b_locale)
|
|
);
|
|
|
|
create index ix_s_i18n_module_key
|
|
on dbo.s_i18n (b_module_id, b_key, b_locale);
|
|
|
|
create index ix_s_i18n_locale
|
|
on dbo.s_i18n (b_locale, b_canuse);
|
|
```
|
|
|
|
## 9. 日志
|
|
|
|
> 日志主键由业务层统一生成 UUIDv7。UUID 主键使用非聚集索引;技术、登录、审计日志按发生时间建立聚集索引,审计字段明细按审计事件建立聚集索引。日志顺序以 `b_occurdatetime` 为准,不依赖 UUID 排序。
|
|
|
|
```sql
|
|
create table dbo.s_log_technical (
|
|
b_id uniqueidentifier not null, -- 业务层生成的 UUIDv7
|
|
b_user_id varchar(50) null, -- 稳定用户/账号标识;未认证请求时为 NULL
|
|
b_sourcetype varchar(20) null,
|
|
b_loglevel varchar(16) not null,
|
|
b_logcategory varchar(64) null,
|
|
b_operation varchar(100) null,
|
|
b_module_id varchar(50) null,
|
|
b_request_id varchar(64) null,
|
|
b_trace_id varchar(64) null,
|
|
b_server_node varchar(128) null,
|
|
b_duration_ms bigint null,
|
|
b_result_code varchar(50) null,
|
|
b_error_code varchar(50) null,
|
|
b_error_message nvarchar(4000) null,
|
|
b_exception_text nvarchar(max) null,
|
|
b_context_text nvarchar(max) null,
|
|
b_occurdatetime datetime2 default sysutcdatetime(),
|
|
constraint pk_s_log_technical primary key nonclustered (b_id)
|
|
);
|
|
|
|
create table dbo.s_log_login (
|
|
b_id uniqueidentifier not null, -- 业务层生成的 UUIDv7
|
|
b_user_id varchar(50) null, -- 当前系统中账号即用户稳定标识;登录失败且账号不存在时为 NULL
|
|
b_login_type varchar(20) not null,
|
|
b_login_result tinyint not null default 0,
|
|
b_fail_reason nvarchar(400) null,
|
|
b_ip varchar(50) null,
|
|
b_ip_location nvarchar(400) null,
|
|
b_browser varchar(100) null,
|
|
b_browser_version varchar(50) null,
|
|
b_os varchar(100) null,
|
|
b_os_version varchar(50) null,
|
|
b_device_type varchar(20) null,
|
|
b_user_agent nvarchar(max) null,
|
|
b_session_id varchar(50) null,
|
|
b_request_id varchar(64) null,
|
|
b_trace_id varchar(64) null,
|
|
b_occurdatetime datetime2 default sysutcdatetime(),
|
|
constraint pk_s_log_login primary key nonclustered (b_id)
|
|
);
|
|
|
|
create table dbo.s_log_audit (
|
|
b_id uniqueidentifier not null, -- 业务层生成的 UUIDv7
|
|
b_event_code varchar(50) not null,
|
|
b_module_id varchar(50) null,
|
|
b_data_id varchar(50) null,
|
|
b_business_no varchar(50) null,
|
|
b_operation varchar(100) null,
|
|
b_operator_id varchar(50) null,
|
|
b_operator_name nvarchar(200) null,
|
|
b_source_type varchar(20) not null default 'user',
|
|
b_visibility varchar(20) not null default 'internal',
|
|
b_request_id varchar(64) null,
|
|
b_trace_id varchar(64) null,
|
|
b_payload_text nvarchar(max) null,
|
|
b_occurdatetime datetime2 default sysutcdatetime(),
|
|
constraint pk_s_log_audit primary key nonclustered (b_id)
|
|
);
|
|
|
|
create table dbo.s_log_audit_field (
|
|
b_id uniqueidentifier not null, -- 业务层生成的 UUIDv7
|
|
b_event_id uniqueidentifier not null,
|
|
b_module_id varchar(50) null,
|
|
b_data_id varchar(50) null,
|
|
b_field varchar(50) not null,
|
|
b_field_label nvarchar(200) null,
|
|
b_before_value nvarchar(max) null,
|
|
b_after_value nvarchar(max) null,
|
|
b_before_display nvarchar(1000) null,
|
|
b_after_display nvarchar(1000) null,
|
|
b_visibility varchar(20) not null default 'internal',
|
|
constraint pk_s_log_audit_field primary key nonclustered (b_id)
|
|
);
|
|
|
|
create clustered index cx_s_log_technical_occur
|
|
on dbo.s_log_technical (b_occurdatetime, b_id);
|
|
|
|
create clustered index cx_s_log_login_occur
|
|
on dbo.s_log_login (b_occurdatetime, b_id);
|
|
|
|
create clustered index cx_s_log_audit_occur
|
|
on dbo.s_log_audit (b_occurdatetime, b_id);
|
|
|
|
create clustered index cx_s_log_audit_field_event
|
|
on dbo.s_log_audit_field (b_event_id, b_id);
|
|
|
|
create index ix_s_log_technical_trace
|
|
on dbo.s_log_technical (b_trace_id, b_occurdatetime);
|
|
|
|
create index ix_s_log_login_user
|
|
on dbo.s_log_login (b_user_id, b_occurdatetime);
|
|
|
|
create index ix_s_log_audit_module
|
|
on dbo.s_log_audit (b_module_id, b_data_id, b_occurdatetime);
|
|
```
|
|
|
|
## 10. 业务表主键约定
|
|
|
|
```sql
|
|
create table dbo.b_example (
|
|
b_id bigint not null primary key, -- 应用层雪花 ID
|
|
b_inputuser_id varchar(50) null, -- 引用 b_user.b_id
|
|
b_inputdatetime datetime2 default sysutcdatetime()
|
|
);
|
|
```
|