20260905172534
This commit is contained in:
1 parent
1b01a31252
commit
7b00eeb88c
711 files changed
+2849
-959
No files matched your search
+85
-68
@@ -9,26 +9,10 @@
|
||||
create table dbo.b_user (
|
||||
b_id varchar(50) not null primary key, -- 用户账号本身
|
||||
b_name nvarchar(100) null,
|
||||
b_department nvarchar(100) null,
|
||||
b_subcode nvarchar(100) null,
|
||||
b_machineid nvarchar(100) null,
|
||||
b_bz nvarchar(400) null,
|
||||
b_password nvarchar(255) not null,
|
||||
b_canuse tinyint not null default 1,
|
||||
b_othermachinelogin tinyint not null default 0,
|
||||
b_salesman tinyint not null default 0,
|
||||
b_docman tinyint not null default 0,
|
||||
b_dealman tinyint not null default 0,
|
||||
b_receivelevel tinyint null,
|
||||
b_paylevel tinyint null,
|
||||
b_visible_customer tinyint not null default 0,
|
||||
b_visible_supply tinyint not null default 0,
|
||||
b_levelvisible tinyint not null default 0,
|
||||
b_fromcustomer tinyint not null default 0,
|
||||
b_logintime tinyint not null default 0,
|
||||
b_checkxy tinyint not null default 0,
|
||||
b_loginfee tinyint not null default 0,
|
||||
b_phone nvarchar(100) null
|
||||
b_logintime tinyint not null default 0
|
||||
);
|
||||
```
|
||||
|
||||
@@ -46,25 +30,26 @@ create table dbo.s_module (
|
||||
b_keyfield varchar(50) null,
|
||||
b_orderfield varchar(500) null,
|
||||
b_delete_policy varchar(20) null,
|
||||
b_canuse int not null default 1,
|
||||
b_canuse tinyint not null default 1,
|
||||
b_xh int not null default 0,
|
||||
b_bz nvarchar(2000) null,
|
||||
b_inputuser_id varchar(50) null,
|
||||
b_inputdatetime datetime2 default sysutcdatetime(),
|
||||
b_updateuser_id varchar(50) null,
|
||||
b_updatedatetime datetime2 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,
|
||||
@@ -76,52 +61,59 @@ create table dbo.s_field (
|
||||
b_length int null,
|
||||
b_precision int null,
|
||||
b_scale int null,
|
||||
b_nullable int not null default 1,
|
||||
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 int not null default 1,
|
||||
b_inputuser_id varchar(50) null,
|
||||
b_inputdatetime datetime2 default sysutcdatetime(),
|
||||
b_updateuser_id varchar(50) null,
|
||||
b_updatedatetime datetime2 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 uniqueidentifier not null primary key, -- 应用层生成的 UUID
|
||||
b_id varchar(50) not null, -- 分组编码本身,模块内唯一,创建后不可修改
|
||||
b_module_id varchar(50) not null,
|
||||
b_parent_id uniqueidentifier 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 int not null default 1,
|
||||
b_canuse tinyint not null default 1,
|
||||
b_colspan int not null default 48,
|
||||
b_layout_direction varchar(10) null default 'vertical'
|
||||
b_layout_direction varchar(10) null default 'vertical',
|
||||
primary key (b_module_id, b_id)
|
||||
);
|
||||
|
||||
create index ix_s_field_group_module
|
||||
on dbo.s_field_group (b_module_id, b_parent_id, b_xh, b_canuse, 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 uniqueidentifier null,
|
||||
b_visible int not null default 1,
|
||||
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 uniqueidentifier null,
|
||||
b_visible int not null default 1,
|
||||
b_required int not null default 0,
|
||||
b_readonly int not null default 0,
|
||||
b_disabled int not null default 0,
|
||||
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,
|
||||
@@ -130,6 +122,9 @@ create table dbo.s_field_edit (
|
||||
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,
|
||||
@@ -137,10 +132,13 @@ create table dbo.s_field_query (
|
||||
b_condition_no int not null default 1,
|
||||
b_operator varchar(20) not null,
|
||||
b_default_value nvarchar(1000) null,
|
||||
b_canuse int not null default 1,
|
||||
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. 自动编码
|
||||
@@ -157,7 +155,7 @@ create table dbo.s_autocode (
|
||||
b_startvalue bigint not null default 1,
|
||||
b_currentperiod varchar(8) null,
|
||||
b_currentvalue bigint not null default 0,
|
||||
b_canuse int not null default 1,
|
||||
b_canuse tinyint not null default 1,
|
||||
primary key (b_module_id, b_field)
|
||||
);
|
||||
```
|
||||
@@ -180,7 +178,7 @@ create table dbo.s_relation (
|
||||
b_delete_policy varchar(20) null,
|
||||
b_order_module_id varchar(50) null,
|
||||
b_order_field varchar(50) null,
|
||||
b_canuse int not null default 1,
|
||||
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)
|
||||
);
|
||||
@@ -205,14 +203,20 @@ create table dbo.s_menu (
|
||||
b_module_id varchar(50) null,
|
||||
b_icon varchar(50) null,
|
||||
b_xh int not null default 0,
|
||||
b_canuse int not null default 1
|
||||
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. 权限
|
||||
@@ -227,7 +231,7 @@ create table dbo.s_power (
|
||||
b_module_id varchar(50) null,
|
||||
b_field varchar(50) null,
|
||||
b_operation varchar(30) not null,
|
||||
b_canuse int not null default 1,
|
||||
b_canuse tinyint not null default 1,
|
||||
b_xh int not null default 0
|
||||
);
|
||||
|
||||
@@ -250,8 +254,8 @@ create index ix_s_power_resource
|
||||
create table dbo.s_i18n_type (
|
||||
b_id varchar(20) not null primary key, -- 语言编码本身
|
||||
b_name nvarchar(200) not null,
|
||||
b_canuse int not null default 1,
|
||||
b_default int not null default 0,
|
||||
b_canuse tinyint not null default 1,
|
||||
b_default tinyint not null default 0,
|
||||
b_xh int not null default 0
|
||||
);
|
||||
|
||||
@@ -261,13 +265,13 @@ create table dbo.s_i18n (
|
||||
b_locale varchar(20) not null,
|
||||
b_value nvarchar(1000) not null,
|
||||
b_i18ntype varchar(20) null,
|
||||
b_canuse int not null default 1,
|
||||
b_canuse tinyint not null default 1,
|
||||
b_module_id varchar(50) null,
|
||||
unique (b_key, b_locale)
|
||||
);
|
||||
|
||||
create index ix_s_i18n_module_id
|
||||
on dbo.s_i18n (b_module_id);
|
||||
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);
|
||||
@@ -275,15 +279,16 @@ create index ix_s_i18n_locale
|
||||
|
||||
## 9. 日志
|
||||
|
||||
> 日志主键由业务层统一生成 UUIDv7。UUID 主键使用非聚集索引;技术、登录、审计日志按发生时间建立聚集索引,审计字段明细按审计事件建立聚集索引。日志顺序以 `b_occurdatetime` 为准,不依赖 UUID 排序。
|
||||
|
||||
```sql
|
||||
create table dbo.s_log_technical (
|
||||
b_id uniqueidentifier not null primary key, -- 应用层生成的 UUID
|
||||
b_user_id varchar(50) null,
|
||||
b_account varchar(50) null,
|
||||
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_operation varchar(100) null,
|
||||
b_module_id varchar(50) null,
|
||||
b_request_id varchar(64) null,
|
||||
b_trace_id varchar(64) null,
|
||||
@@ -294,15 +299,15 @@ create table dbo.s_log_technical (
|
||||
b_error_message nvarchar(4000) null,
|
||||
b_exception_text nvarchar(max) null,
|
||||
b_context_text nvarchar(max) null,
|
||||
b_occurdatetime datetime2 default sysutcdatetime()
|
||||
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 primary key, -- 应用层生成的 UUID
|
||||
b_user_id varchar(50) null,
|
||||
b_account varchar(50) null,
|
||||
b_id uniqueidentifier not null, -- 业务层生成的 UUIDv7
|
||||
b_user_id varchar(50) null, -- 当前系统中账号即用户稳定标识;登录失败且账号不存在时为 NULL
|
||||
b_login_type varchar(20) not null,
|
||||
b_login_result int not null default 0,
|
||||
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,
|
||||
@@ -315,11 +320,12 @@ create table dbo.s_log_login (
|
||||
b_session_id varchar(50) null,
|
||||
b_request_id varchar(64) null,
|
||||
b_trace_id varchar(64) null,
|
||||
b_occurdatetime datetime2 default sysutcdatetime()
|
||||
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 primary key, -- 应用层生成的 UUID
|
||||
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,
|
||||
@@ -332,11 +338,12 @@ create table dbo.s_log_audit (
|
||||
b_request_id varchar(64) null,
|
||||
b_trace_id varchar(64) null,
|
||||
b_payload_text nvarchar(max) null,
|
||||
b_occurdatetime datetime2 default sysutcdatetime()
|
||||
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 primary key, -- 应用层生成的 UUID
|
||||
b_id uniqueidentifier not null, -- 业务层生成的 UUIDv7
|
||||
b_event_id uniqueidentifier not null,
|
||||
b_module_id varchar(50) null,
|
||||
b_data_id varchar(50) null,
|
||||
@@ -346,9 +353,22 @@ create table dbo.s_log_audit_field (
|
||||
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'
|
||||
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);
|
||||
|
||||
@@ -357,9 +377,6 @@ create index ix_s_log_login_user
|
||||
|
||||
create index ix_s_log_audit_module
|
||||
on dbo.s_log_audit (b_module_id, b_data_id, b_occurdatetime);
|
||||
|
||||
create index ix_s_log_audit_field_event
|
||||
on dbo.s_log_audit_field (b_event_id);
|
||||
```
|
||||
|
||||
## 10. 业务表主键约定
|
||||
|
||||
Reference in new issue
Block a user