20260909224013
This commit is contained in:
1 parent
d8acf69533
commit
19267be58d
4 files changed
+1372
-538
No files matched your search
+8
-143
@@ -113,24 +113,12 @@
|
||||
|
||||
## 1. 表结构
|
||||
|
||||
> 权限相关表的完整 DDL、索引与业务层约束统一维护在《FMS新系统核心表结构设计.md》「8. 权限」;用户个性化偏好表见同文档「4. 用户个性化」。本章只保留设计说明与计算规则。
|
||||
|
||||
### 1.1 s_menu_module(菜单-模块关系表)
|
||||
|
||||
菜单页面与业务模块是多对多关系。菜单记录既表示导航入口,也表示对应的逻辑页面;Vue 路由和公共组件只作为技术实现,不参与权限标识。
|
||||
|
||||
```sql
|
||||
create table dbo.s_menu_module (
|
||||
b_menu_id varchar(100) not null,
|
||||
b_module_id varchar(50) not null,
|
||||
b_main bit not null default 0,
|
||||
b_xh int not null default 0,
|
||||
b_canuse tinyint not null default 1,
|
||||
primary key (b_menu_code, b_module_id)
|
||||
);
|
||||
|
||||
create index IX_s_menu_module_module
|
||||
on dbo.s_menu_module (b_module_id, b_canuse, b_menu_code);
|
||||
```
|
||||
|
||||
业务层约束:
|
||||
|
||||
- `b_menu_code`、`b_module_id` 必须引用已启用的菜单和模块;
|
||||
@@ -141,114 +129,19 @@ create index IX_s_menu_module_module
|
||||
|
||||
### 1.2 s_power(权限定义表)
|
||||
|
||||
```sql
|
||||
create table dbo.s_power (
|
||||
b_id varchar(100) not null, -- menu.cw_fee_list.access / module.cw_fee.access / action.cw_fee.audit
|
||||
b_name nvarchar(200) not null,
|
||||
b_i18n varchar(150) null,
|
||||
b_power_type varchar(20) not null, -- menu/module/action
|
||||
b_owner_type varchar(20) not null, -- menu / module
|
||||
b_owner_id varchar(50) not null, -- 菜单或模块编码
|
||||
b_capability varchar(30) null, -- action 的操作或动作编码;menu/module 为 access
|
||||
b_operation varchar(30) null, -- 兼容列:access/execute,由 b_power_type 派生,后续可移除
|
||||
b_canuse tinyint not null default 1,
|
||||
b_xh int not null default 0,
|
||||
constraint PK_s_power primary key (b_id)
|
||||
);
|
||||
|
||||
create index IX_s_power_owner
|
||||
on dbo.s_power (b_power_type, b_owner_type, b_owner_id, b_capability, b_canuse);
|
||||
```
|
||||
|
||||
业务层约束(数据库不建 check 约束,由业务层校验):
|
||||
|
||||
- `b_id` 由 `类型.对象[.能力]` 规则生成(见「权限编码规范」),**生成后不可编辑**,变更时删除重建;
|
||||
- `b_power_type` 只能取 `menu / module / action`;
|
||||
- `menu` 类型编码为 `menu.<菜单编码>.access`,`b_owner_type = 'menu'`,`b_capability = 'access'`,`b_operation = 'access'`;
|
||||
- `module` 类型编码为 `module.<模块编码>.access`,`b_owner_type = 'module'`,`b_capability = 'access'`,`b_operation = 'access'`;
|
||||
- `action` 类型 `b_owner_type` 固定为 `module`,`b_owner_id` 和 `b_capability` 必填,`b_operation` 固定为 `execute`;
|
||||
- **动作归属模块、不归属菜单**:同一个模块动作只配置一次;页面是否允许使用该动作由 `s_menu_module.b_allow_*` 限制;
|
||||
- `b_id` 与 `(b_power_type, b_owner_type, b_owner_id, b_capability)` 一一对应,新建前先按组合查重。
|
||||
|
||||
> 与现有库(FMS-NEW)的差异:现有 `s_power` 已采用 `b_id varchar(50)` 编码主键,并含 `b_resource`、`b_module_id`、`b_operation` 列。迁移时把 `b_id` 放宽到 `varchar(100)`,补 `b_owner_type` / `b_owner_id` / `b_capability` 三列;兼容列可保留,但新代码统一按上述权限编码和归属规则读写。
|
||||
定义见《FMS新系统核心表结构设计.md》「8. 权限」。
|
||||
|
||||
### 1.3 s_user_power(用户权限授权表)
|
||||
|
||||
```sql
|
||||
create table dbo.s_user_power (
|
||||
b_user_id varchar(50) not null,
|
||||
b_power_id varchar(100) not null, -- 引用 s_power.b_id,即权限编码:menu.cw_fee / action.cw_fee.audit
|
||||
b_canuse tinyint not null default 1,
|
||||
b_updatedatetime datetime2 null,
|
||||
constraint PK_s_user_power primary key (b_user_id, b_power_id)
|
||||
);
|
||||
|
||||
create index IX_s_user_power_user
|
||||
on dbo.s_user_power (b_user_id, b_canuse, b_power_id);
|
||||
```
|
||||
|
||||
业务层约束:
|
||||
|
||||
- `b_power_id` 存权限**编码**而非内部 ID,可直接阅读与按前缀查询,判断时无需 join `s_power`;
|
||||
- 统一采用默认拒绝策略:只保存 `b_canuse = 1` 的授权记录,没有记录即无权限;
|
||||
- 权限点本身 `b_canuse = 0` 时,所有用户的该权限一律不生效。
|
||||
定义见《FMS新系统核心表结构设计.md》「8. 权限」。
|
||||
|
||||
### 1.4 s_user_field_permission(用户字段访问策略表)
|
||||
|
||||
```sql
|
||||
create table dbo.s_user_field_permission (
|
||||
b_user_id varchar(50) not null,
|
||||
b_module_id varchar(50) not null,
|
||||
b_field varchar(50) not null,
|
||||
b_access_mode varchar(10) not null, -- hidden / view / edit
|
||||
b_allow_query tinyint not null default 0,
|
||||
b_allow_export tinyint not null default 0,
|
||||
b_canuse tinyint not null default 1,
|
||||
b_updatedatetime datetime2 null,
|
||||
constraint PK_s_user_field_permission
|
||||
primary key (b_user_id, b_module_id, b_field)
|
||||
);
|
||||
|
||||
create index IX_s_user_field_permission_module
|
||||
on dbo.s_user_field_permission (b_user_id, b_module_id, b_canuse, b_field);
|
||||
```
|
||||
|
||||
业务层约束(数据库不建 check 约束,由业务层校验):
|
||||
|
||||
- `b_access_mode` 只能取 `hidden / view / edit`;
|
||||
- `b_access_mode = 'hidden'` 时,`b_allow_query` 和 `b_allow_export` 必须同时为 `0`;
|
||||
- 没有 `b_canuse = 1` 的有效记录时,该字段按模块字段默认配置执行,不视为 `hidden`。
|
||||
定义见《FMS新系统核心表结构设计.md》「8. 权限」。
|
||||
|
||||
### 1.5 s_user_data_scope(用户数据范围授权表)
|
||||
|
||||
```sql
|
||||
create table dbo.s_user_data_scope (
|
||||
b_user_id varchar(50) not null,
|
||||
|
||||
b_module_id varchar(50) not null,
|
||||
|
||||
b_operation varchar(30) not null,
|
||||
-- * / read / create / update / delete / export
|
||||
-- * 表示模块默认范围,仅 b_scope_level = 'default' 时允许使用
|
||||
-- 值域与 action.<模块编码>.<操作> 的 capability 一致,用于把「操作」和「该操作的行范围」串起来
|
||||
|
||||
b_scope_level varchar(10) not null default 'default',
|
||||
-- default / override;default 使用 b_operation='*',override 为操作级覆盖
|
||||
|
||||
b_scope_no int not null default 1,
|
||||
b_scope_type varchar(30) not null,
|
||||
-- own / department / department_tree / all / custom
|
||||
|
||||
b_scope_field varchar(50) null,
|
||||
b_scope_value varchar(100) null,
|
||||
|
||||
b_updatedatetime datetime2 null,
|
||||
primary key (b_user_id, b_module_id, b_operation, b_scope_level, b_scope_no)
|
||||
);
|
||||
|
||||
create index IX_s_user_data_scope_module
|
||||
on dbo.s_user_data_scope (b_user_id, b_module_id, b_operation, b_scope_level, b_scope_type);
|
||||
```
|
||||
定义见《FMS新系统核心表结构设计.md》「8. 权限」。
|
||||
|
||||
数据范围计算规则:
|
||||
|
||||
@@ -276,39 +169,11 @@ create index IX_s_user_data_scope_module
|
||||
|
||||
### 1.6 s_user_field_pref(非权限:用户列表布局偏好表)
|
||||
|
||||
```sql
|
||||
create table dbo.s_user_field_pref (
|
||||
b_user_id varchar(50) not null,
|
||||
b_module_id varchar(50) not null,
|
||||
b_field varchar(50) not null,
|
||||
b_mode varchar(10) not null, -- view / edit
|
||||
b_visible tinyint not null default 1,
|
||||
b_xh int not null default 0,
|
||||
b_width int null,
|
||||
b_updatedatetime datetime2 null,
|
||||
primary key (b_user_id, b_module_id, b_field, b_mode)
|
||||
);
|
||||
|
||||
create index IX_s_user_field_pref_order
|
||||
on dbo.s_user_field_pref (b_user_id, b_module_id, b_mode, b_xh, b_field);
|
||||
```
|
||||
定义见《FMS新系统核心表结构设计.md》「4. 用户个性化」。
|
||||
|
||||
### 1.7 s_user_query_field_pref(非权限:用户查询布局偏好表)
|
||||
|
||||
```sql
|
||||
create table dbo.s_user_query_field_pref (
|
||||
b_user_id varchar(50) not null,
|
||||
b_module_id varchar(50) not null,
|
||||
b_field varchar(50) not null,
|
||||
b_quick_visible tinyint not null default 1,
|
||||
b_xh int not null default 0,
|
||||
b_updatedatetime datetime2 null,
|
||||
primary key (b_user_id, b_module_id, b_field)
|
||||
);
|
||||
|
||||
create index IX_s_user_query_field_pref_order
|
||||
on dbo.s_user_query_field_pref (b_user_id, b_module_id, b_xh, b_field);
|
||||
```
|
||||
定义见《FMS新系统核心表结构设计.md》「4. 用户个性化」。
|
||||
|
||||
用户个性化规则:
|
||||
|
||||
|
||||
Reference in new issue
Block a user