feat(face-b): 权限配置族落地(面 B 批次 10,+31 端点)
新增 6 张表(base_signature / base_signature_user / base_module_button / base_module_column / base_module_form / base_advanced_query_scheme), tables 43 → 49。 - 电子签章 Signature(7):CRUD + Selector + 按 ids 取列表;官方无点权限, 只需登录;名称/编码两次独立判重;userIds 列表是字符串(;连接)、详情是数组 - 按钮权限 ModuleButton(7):CRUD + Selector + selectActions 批量落树 (parentId=-1 为根、任一撞码则整体失败不落库) - 列表权限 ModuleColumn(6) / 表单权限 ModuleForm(6):单条按「菜单存在」套 enCode 前缀,批量无条件套;读时剥除前缀 - 高级查询方案 AdvancedQuery(5):只看自己的方案(列表 ListVO 非 PageListVO) 权限模式:ModuleButton/Column/Form 三族官方为 OR 两码 (permission.resource | appConfig.appResource);Signature 与 AdvancedQuery 官方无 @SaCheckPermission ⇒ 只需登录。 契约登记三处同步:docs/contract.md 的 [ENDPOINT] +31 行、[FACE] B 300→331、 [OFFICIAL] +31 条(src 写真实 Java 方法行号)。 回归测试 tests/batch10_it.rs(9 条)。cargo test --workspace 545 全过, 十二道闸门全绿,check-contract PASS=10 FAIL=0(官方端点覆盖 350/357)。
This commit is contained in:
1 parent
6c6cadc950
commit
4e8ef78b20
8 files changed
+3344
-11
No files matched your search
@@ -1215,23 +1215,26 @@ mod tests {
|
||||
// + base_visual_dev / base_visual_release(P2 低代码),+ 4 张业务表)。
|
||||
// + base_data_interface / base_data_interface_oauth / base_data_interface_user
|
||||
// / base_data_interface_log(数据接口 + 接口认证批次)
|
||||
// + base_print_template / base_print_version(打印模板批次)。
|
||||
// + base_print_template / base_print_version(打印模板批次)
|
||||
// + base_signature / base_signature_user / base_module_button
|
||||
// / base_module_column / base_module_form / base_advanced_query_scheme
|
||||
// (权限配置批次)。
|
||||
//
|
||||
// 🔴 这个数字**故意写死**:加表必须同时改这里与 main.rs 的 BASE_TABLES,
|
||||
// 两处都改才算登记完成(漏一处就是「孤儿 DDL」或「白名单多一项」)。
|
||||
let count = SCHEMA_SQL.matches("CREATE TABLE ").count();
|
||||
assert_eq!(count, 43, "schema.sql 的 CREATE TABLE 数量应为 43");
|
||||
assert_eq!(count, 49, "schema.sql 的 CREATE TABLE 数量应为 49");
|
||||
}
|
||||
|
||||
/// 🔴 [`ddl_tables`] 的解析必须与上面那条计数一致(不能只数到 12 却解析出别的)。
|
||||
#[test]
|
||||
fn ddl_tables_parses_every_create_table() {
|
||||
let tables = ddl_tables();
|
||||
assert_eq!(tables.len(), 43, "ddl_tables 应解析出 43 张表");
|
||||
assert_eq!(tables.len(), 49, "ddl_tables 应解析出 49 张表");
|
||||
assert!(tables.iter().all(|t| !t.is_empty()));
|
||||
assert_eq!(
|
||||
tables.iter().collect::<std::collections::HashSet<_>>().len(),
|
||||
43,
|
||||
49,
|
||||
"表名不许重复"
|
||||
);
|
||||
// 基础 base_* 必须都在(业务表由业务层 spec 派生,不在本文件写死)。
|
||||
@@ -1258,6 +1261,18 @@ mod tests {
|
||||
"base_common_fields",
|
||||
"base_data_set",
|
||||
"base_data_set_relation",
|
||||
"base_data_interface",
|
||||
"base_data_interface_oauth",
|
||||
"base_data_interface_user",
|
||||
"base_data_interface_log",
|
||||
"base_print_template",
|
||||
"base_print_version",
|
||||
"base_signature",
|
||||
"base_signature_user",
|
||||
"base_module_button",
|
||||
"base_module_column",
|
||||
"base_module_form",
|
||||
"base_advanced_query_scheme",
|
||||
] {
|
||||
assert!(
|
||||
tables.iter().any(|t| t == base),
|
||||
|
||||
+63
-1
@@ -1455,6 +1455,37 @@ B GET /api/system/printDev/Info/{id} onlineDev.printDev platform
|
||||
B GET /api/system/printDev/Version/{id} onlineDev.printDev platform
|
||||
B POST /api/system/printDev/Info/{id} onlineDev.printDev platform
|
||||
B DELETE /api/system/printDev/Info/{id} onlineDev.printDev platform
|
||||
B GET /api/system/Signature 登录 platform
|
||||
B POST /api/system/Signature 登录 platform
|
||||
B GET /api/system/Signature/Selector 登录 platform
|
||||
B POST /api/system/Signature/ListByIds 登录 platform
|
||||
B GET /api/system/Signature/{id} 登录 platform
|
||||
B PUT /api/system/Signature/{id} 登录 platform
|
||||
B DELETE /api/system/Signature/{id} 登录 platform
|
||||
B POST /api/system/ModuleButton permission.resource|appConfig.appResource platform
|
||||
B POST /api/system/ModuleButton/selectActions/{menuId} permission.resource|appConfig.appResource platform
|
||||
B GET /api/system/ModuleButton/{menuId}/List permission.resource|appConfig.appResource platform
|
||||
B GET /api/system/ModuleButton/{menuId}/Selector permission.resource|appConfig.appResource platform
|
||||
B GET /api/system/ModuleButton/{id} permission.resource|appConfig.appResource platform
|
||||
B PUT /api/system/ModuleButton/{id} permission.resource|appConfig.appResource platform
|
||||
B DELETE /api/system/ModuleButton/{id} permission.resource|appConfig.appResource platform
|
||||
B POST /api/system/ModuleColumn permission.resource|appConfig.appResource platform
|
||||
B POST /api/system/ModuleColumn/Actions/Batch permission.resource|appConfig.appResource platform
|
||||
B GET /api/system/ModuleColumn/{moduleId}/Fields permission.resource|appConfig.appResource platform
|
||||
B GET /api/system/ModuleColumn/{id} permission.resource|appConfig.appResource platform
|
||||
B PUT /api/system/ModuleColumn/{id} permission.resource|appConfig.appResource platform
|
||||
B DELETE /api/system/ModuleColumn/{id} permission.resource|appConfig.appResource platform
|
||||
B POST /api/system/ModuleForm permission.resource|appConfig.appResource platform
|
||||
B POST /api/system/ModuleForm/Actions/Batch permission.resource|appConfig.appResource platform
|
||||
B GET /api/system/ModuleForm/{moduleId}/Fields permission.resource|appConfig.appResource platform
|
||||
B GET /api/system/ModuleForm/{id} permission.resource|appConfig.appResource platform
|
||||
B PUT /api/system/ModuleForm/{id} permission.resource|appConfig.appResource platform
|
||||
B DELETE /api/system/ModuleForm/{id} permission.resource|appConfig.appResource platform
|
||||
B POST /api/system/AdvancedQuery 登录 platform
|
||||
B GET /api/system/AdvancedQuery/{moduleId}/List 登录 platform
|
||||
B GET /api/system/AdvancedQuery/{id} 登录 platform
|
||||
B PUT /api/system/AdvancedQuery/{id} 登录 platform
|
||||
B DELETE /api/system/AdvancedQuery/{id} 登录 platform
|
||||
A GET /api/ssw/demo/DemoItem/List 登录 demo
|
||||
A POST /api/ssw/demo/DemoItem/Save 登录 demo
|
||||
A DELETE /api/ssw/demo/DemoItem/Delete 登录 demo
|
||||
@@ -1471,7 +1502,7 @@ A DELETE /api/ssw/asset/DataResource/Delete asset/DataResource asset
|
||||
[FACE]
|
||||
# face 条数 说明
|
||||
A 28 面 A 专属(+ 2 条共用 ⇒ 面 A 合计 30 条)
|
||||
B 300 面 B 专属(官方 JNPF 形状)
|
||||
B 331 面 B 专属(官方 JNPF 形状)
|
||||
AB 2 两面共用(CurrentUser / Authority Data —— 按判别头分流)
|
||||
|
||||
[OFFICIAL]
|
||||
@@ -1822,6 +1853,37 @@ GET /api/system/printDev/Info/{id} implemented PrintDevController.java:313 面 B
|
||||
GET /api/system/printDev/Version/{id} implemented PrintDevController.java:353 面 B 已落地:版本列表(裸数组,fullName=打印版本V{n})
|
||||
POST /api/system/printDev/Info/{id} implemented PrintDevController.java:322 面 B 已落地:版本复制
|
||||
DELETE /api/system/printDev/Info/{id} implemented PrintDevController.java:331 面 B 已落地:版本删除(至少留 1 个;已发布/已归档不可删)
|
||||
GET /api/system/Signature implemented SignatureController.java:55 面 B 已落地:PageListVO;userIds = 「真实名/账号」用「;」连接;支持 userId 过滤
|
||||
POST /api/system/Signature implemented SignatureController.java:112 面 B 已落地:名称/编码判重(EXIST001/EXIST002 分开报)+ 写签章 + 写授权人
|
||||
GET /api/system/Signature/Selector implemented SignatureController.java:67 面 B 已落地:ListVO
|
||||
POST /api/system/Signature/ListByIds implemented SignatureController.java:81 面 B 已落地:ListVO(按 ids 取)
|
||||
GET /api/system/Signature/{id} implemented SignatureController.java:96 面 B 已落地:SignatureInfoVO(userIds 是数组)
|
||||
PUT /api/system/Signature/{id} implemented SignatureController.java:134 面 B 已落地:只 SET body 出现的键;userIds 变化时全量重建授权人
|
||||
DELETE /api/system/Signature/{id} implemented SignatureController.java:158 面 B 已落地:软删
|
||||
POST /api/system/ModuleButton implemented ModuleButtonController.java:123 面 B 已落地:同菜单内编码判重;parentId 缺省 -1
|
||||
GET /api/system/ModuleButton/{menuId}/List implemented ModuleButtonController.java:71 面 B 已落地:PageListVO(按 menuId 过滤 + 关键词)
|
||||
GET /api/system/ModuleButton/{menuId}/Selector implemented ModuleButtonController.java:87 面 B 已落地:ListVO + **树**(parentId=-1 视为根)
|
||||
GET /api/system/ModuleButton/{id} implemented ModuleButtonController.java:107 面 B 已落地:ModuleButtonInfoVO
|
||||
PUT /api/system/ModuleButton/{id} implemented ModuleButtonController.java:144 面 B 已落地:只 SET body 出现的键
|
||||
DELETE /api/system/ModuleButton/{id} implemented ModuleButtonController.java:167 面 B 已落地:软删
|
||||
POST /api/system/ModuleButton/selectActions/{menuId} implemented ModuleButtonController.java:204 面 B 已落地:从动作管理批量选入(逐条判重;任一撞 ⇒ 整体失败不落库)
|
||||
POST /api/system/ModuleColumn implemented ModuleColumnController.java:180 面 B 已落地:enCode 前缀化(fieldRule=1 ⇒ jnpf_<bindTable>_jnpf_;=2 ⇒ <childTableKey>-)
|
||||
GET /api/system/ModuleColumn/{moduleId}/Fields implemented ModuleColumnController.java:79 面 B 已落地:PageListVO;读时剥掉 enCode 前缀
|
||||
GET /api/system/ModuleColumn/{id} implemented ModuleColumnController.java:153 面 B 已落地:ModuleColumnInfoVO(childTableKey 默认 tableField)
|
||||
PUT /api/system/ModuleColumn/{id} implemented ModuleColumnController.java:215 面 B 已落地:同 create 的前缀化规则
|
||||
DELETE /api/system/ModuleColumn/{id} implemented ModuleColumnController.java:251 面 B 已落地:软删
|
||||
POST /api/system/ModuleColumn/Actions/Batch implemented ModuleColumnController.java:294 面 B 已落地:columnJson 批量;库内撞码与**批内撞码**都判失败
|
||||
POST /api/system/ModuleForm implemented ModuleFormController.java:201 面 B 已落地:同 ModuleColumn 的前缀化规则
|
||||
GET /api/system/ModuleForm/{moduleId}/Fields implemented ModuleFormController.java:83 面 B 已落地:PageListVO;读时剥掉 enCode 前缀
|
||||
GET /api/system/ModuleForm/{id} implemented ModuleFormController.java:174 面 B 已落地:ModuleFormInfoVO(childTableKey 默认 tableField)
|
||||
PUT /api/system/ModuleForm/{id} implemented ModuleFormController.java:237 面 B 已落地:同 create 的前缀化规则
|
||||
DELETE /api/system/ModuleForm/{id} implemented ModuleFormController.java:272 面 B 已落地:软删
|
||||
POST /api/system/ModuleForm/Actions/Batch implemented ModuleFormController.java:290 面 B 已落地:formJson 批量;库内撞码与批内撞码都判失败
|
||||
POST /api/system/AdvancedQuery implemented AdvancedQueryController.java:54 面 B 已落地:必填校验(fullName/conditionJson/matchLogic/moduleId)
|
||||
GET /api/system/AdvancedQuery/{moduleId}/List implemented AdvancedQueryController.java:106 面 B 已落地:ListVO;**只返当前用户自己**的方案
|
||||
GET /api/system/AdvancedQuery/{id} implemented AdvancedQueryController.java:125 面 B 已落地:只看自己的方案(他人 ⇒ 数据不存在)
|
||||
PUT /api/system/AdvancedQuery/{id} implemented AdvancedQueryController.java:70 面 B 已落地:只 SET body 出现的键
|
||||
DELETE /api/system/AdvancedQuery/{id} implemented AdvancedQueryController.java:87 面 B 已落地:软删;只删自己的方案
|
||||
|
||||
[RULER]
|
||||
# name 期望断言数(尺子**自己**断言的条数;跑出来的条数对不上 ⇒ 失败)
|
||||
|
||||
@@ -1167,3 +1167,134 @@ CREATE TABLE base_print_version (
|
||||
f_query_list TEXT,
|
||||
PRIMARY KEY (f_id, f_tenant_id)
|
||||
);
|
||||
|
||||
-- ==== 面 B 批次 10:权限配置族(官方表名对齐)====
|
||||
-- 官方 DDL:`base_signature` / `base_signature_user` / `base_module_button` /
|
||||
-- `base_module_column` / `base_module_form` / `base_advanced_query_scheme`。
|
||||
|
||||
CREATE TABLE base_signature (
|
||||
f_id VARCHAR(50) NOT NULL,
|
||||
f_full_name VARCHAR(200),
|
||||
f_en_code VARCHAR(200),
|
||||
f_icon TEXT,
|
||||
f_enabled_mark INTEGER,
|
||||
f_sort_code BIGINT,
|
||||
f_description VARCHAR(500),
|
||||
f_creator_time TIMESTAMP(0) WITHOUT TIME ZONE,
|
||||
f_creator_user_id VARCHAR(50),
|
||||
f_last_modify_time TIMESTAMP(0) WITHOUT TIME ZONE,
|
||||
f_last_modify_user_id VARCHAR(50),
|
||||
f_delete_time TIMESTAMP(0) WITHOUT TIME ZONE,
|
||||
f_delete_user_id VARCHAR(50),
|
||||
f_delete_mark INTEGER,
|
||||
f_tenant_id VARCHAR(50) DEFAULT '0' NOT NULL,
|
||||
PRIMARY KEY (f_id, f_tenant_id)
|
||||
);
|
||||
|
||||
CREATE TABLE base_signature_user (
|
||||
f_id VARCHAR(50) NOT NULL,
|
||||
f_signature_id VARCHAR(50),
|
||||
f_user_id VARCHAR(50),
|
||||
f_enabled_mark INTEGER,
|
||||
f_sort_code BIGINT,
|
||||
f_description VARCHAR(500),
|
||||
f_creator_time TIMESTAMP(0) WITHOUT TIME ZONE,
|
||||
f_creator_user_id VARCHAR(50),
|
||||
f_last_modify_time TIMESTAMP(0) WITHOUT TIME ZONE,
|
||||
f_last_modify_user_id VARCHAR(50),
|
||||
f_delete_time TIMESTAMP(0) WITHOUT TIME ZONE,
|
||||
f_delete_user_id VARCHAR(50),
|
||||
f_delete_mark INTEGER,
|
||||
f_tenant_id VARCHAR(50) DEFAULT '0' NOT NULL,
|
||||
PRIMARY KEY (f_id, f_tenant_id)
|
||||
);
|
||||
|
||||
CREATE TABLE base_module_button (
|
||||
f_id VARCHAR(50) NOT NULL,
|
||||
f_parent_id VARCHAR(50),
|
||||
f_full_name VARCHAR(200),
|
||||
f_en_code VARCHAR(200),
|
||||
f_icon VARCHAR(500),
|
||||
f_url_address VARCHAR(500),
|
||||
f_property_json TEXT,
|
||||
f_module_id VARCHAR(50),
|
||||
f_description VARCHAR(500),
|
||||
f_enabled_mark INTEGER,
|
||||
f_sort_code BIGINT,
|
||||
f_creator_time TIMESTAMP(0) WITHOUT TIME ZONE,
|
||||
f_creator_user_id VARCHAR(50),
|
||||
f_last_modify_time TIMESTAMP(0) WITHOUT TIME ZONE,
|
||||
f_last_modify_user_id VARCHAR(50),
|
||||
f_delete_time TIMESTAMP(0) WITHOUT TIME ZONE,
|
||||
f_delete_user_id VARCHAR(50),
|
||||
f_delete_mark INTEGER,
|
||||
f_tenant_id VARCHAR(50) DEFAULT '0' NOT NULL,
|
||||
PRIMARY KEY (f_id, f_tenant_id)
|
||||
);
|
||||
|
||||
CREATE TABLE base_module_column (
|
||||
f_id VARCHAR(50) NOT NULL,
|
||||
f_parent_id VARCHAR(50),
|
||||
f_full_name VARCHAR(200),
|
||||
f_en_code VARCHAR(200),
|
||||
f_bind_table VARCHAR(50),
|
||||
f_bind_table_name VARCHAR(50),
|
||||
f_property_json TEXT,
|
||||
f_module_id VARCHAR(50),
|
||||
f_field_rule INTEGER,
|
||||
f_child_table_key VARCHAR(50),
|
||||
f_description VARCHAR(500),
|
||||
f_enabled_mark INTEGER,
|
||||
f_sort_code BIGINT,
|
||||
f_creator_time TIMESTAMP(0) WITHOUT TIME ZONE,
|
||||
f_creator_user_id VARCHAR(50),
|
||||
f_last_modify_time TIMESTAMP(0) WITHOUT TIME ZONE,
|
||||
f_last_modify_user_id VARCHAR(50),
|
||||
f_delete_time TIMESTAMP(0) WITHOUT TIME ZONE,
|
||||
f_delete_user_id VARCHAR(50),
|
||||
f_delete_mark INTEGER,
|
||||
f_tenant_id VARCHAR(50) DEFAULT '0' NOT NULL,
|
||||
PRIMARY KEY (f_id, f_tenant_id)
|
||||
);
|
||||
|
||||
CREATE TABLE base_module_form (
|
||||
f_id VARCHAR(50) NOT NULL,
|
||||
f_parent_id VARCHAR(50),
|
||||
f_full_name VARCHAR(200),
|
||||
f_en_code VARCHAR(200),
|
||||
f_property_json TEXT,
|
||||
f_module_id VARCHAR(50),
|
||||
f_field_rule INTEGER,
|
||||
f_child_table_key VARCHAR(50),
|
||||
f_bind_table VARCHAR(50),
|
||||
f_description VARCHAR(500),
|
||||
f_enabled_mark INTEGER,
|
||||
f_sort_code BIGINT,
|
||||
f_creator_time TIMESTAMP(0) WITHOUT TIME ZONE,
|
||||
f_creator_user_id VARCHAR(50),
|
||||
f_last_modify_time TIMESTAMP(0) WITHOUT TIME ZONE,
|
||||
f_last_modify_user_id VARCHAR(50),
|
||||
f_delete_time TIMESTAMP(0) WITHOUT TIME ZONE,
|
||||
f_delete_user_id VARCHAR(50),
|
||||
f_delete_mark INTEGER,
|
||||
f_tenant_id VARCHAR(50) DEFAULT '0' NOT NULL,
|
||||
PRIMARY KEY (f_id, f_tenant_id)
|
||||
);
|
||||
|
||||
CREATE TABLE base_advanced_query_scheme (
|
||||
f_id VARCHAR(50) NOT NULL,
|
||||
f_full_name VARCHAR(200),
|
||||
f_match_logic VARCHAR(20),
|
||||
f_condition_json TEXT,
|
||||
f_module_id VARCHAR(50),
|
||||
f_creator_time TIMESTAMP(0) WITHOUT TIME ZONE,
|
||||
f_creator_user_id VARCHAR(50),
|
||||
f_last_modify_time TIMESTAMP(0) WITHOUT TIME ZONE,
|
||||
f_last_modify_user_id VARCHAR(50),
|
||||
f_delete_time TIMESTAMP(0) WITHOUT TIME ZONE,
|
||||
f_delete_user_id VARCHAR(50),
|
||||
f_delete_mark INTEGER,
|
||||
f_sort_code BIGINT,
|
||||
f_tenant_id VARCHAR(50) DEFAULT '0' NOT NULL,
|
||||
PRIMARY KEY (f_id, f_tenant_id)
|
||||
);
|
||||
+13
-2
@@ -49,8 +49,11 @@ use ssw_platform::routes;
|
||||
/// `base_db_link` / `base_data_type` / `base_common_fields`;数据集批次新增
|
||||
/// `base_data_set` / `base_data_set_relation`;数据接口批次(2026-11-01)新增
|
||||
/// `base_data_interface` / `base_data_interface_oauth` / `base_data_interface_user` /
|
||||
/// `base_data_interface_log` / `base_print_template` / `base_print_version`,故清单现在是 **39 张**。
|
||||
const BASE_TABLES: [&str; 39] = [
|
||||
/// `base_data_interface_log` / `base_print_template` / `base_print_version`;
|
||||
/// 权限配置批次(2026-11-01)新增 `base_signature` / `base_signature_user` /
|
||||
/// `base_module_button` / `base_module_column` / `base_module_form` /
|
||||
/// `base_advanced_query_scheme`,故清单现在是 **45 张**。
|
||||
const BASE_TABLES: [&str; 45] = [
|
||||
"base_group",
|
||||
"base_user",
|
||||
"base_role",
|
||||
@@ -97,6 +100,14 @@ const BASE_TABLES: [&str; 39] = [
|
||||
"base_data_interface_log",
|
||||
"base_print_template",
|
||||
"base_print_version",
|
||||
// 🔴 权限配置批次(2026-11-01):电子签章 + 签章授权人 + 按钮/列表/表单权限
|
||||
// + 高级查询方案,仍是官方 DDL 逐字。
|
||||
"base_signature",
|
||||
"base_signature_user",
|
||||
"base_module_button",
|
||||
"base_module_column",
|
||||
"base_module_form",
|
||||
"base_advanced_query_scheme",
|
||||
// 🔴 低代码两张表是**平台表**不是业务表:它们存的是「功能定义」,
|
||||
// 任何业务模块都会用,属于引擎基础设施。
|
||||
"base_visual_dev",
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
+132
-2
@@ -629,6 +629,111 @@ pub fn build_router(state: AppState) -> axum::Router<AppState> {
|
||||
"/api/system/printDev/Info/{id}",
|
||||
delete(face_b::print_dev_version_delete),
|
||||
)
|
||||
// ---- 电子签章(官方 `SignatureController.java`;官方**无** `@SaCheckPermission`)----
|
||||
.route("/api/system/Signature", get(face_b::signature_list))
|
||||
.route("/api/system/Signature", post(face_b::signature_create))
|
||||
.route(
|
||||
"/api/system/Signature/Selector",
|
||||
get(face_b::signature_selector),
|
||||
)
|
||||
.route(
|
||||
"/api/system/Signature/ListByIds",
|
||||
post(face_b::signature_list_by_ids),
|
||||
)
|
||||
.route("/api/system/Signature/{id}", get(face_b::signature_info))
|
||||
.route("/api/system/Signature/{id}", put(face_b::signature_update))
|
||||
.route(
|
||||
"/api/system/Signature/{id}",
|
||||
delete(face_b::signature_delete),
|
||||
)
|
||||
// ---- 按钮权限(官方 `ModuleButtonController.java`,权限 OR 两码)----
|
||||
.route(
|
||||
"/api/system/ModuleButton",
|
||||
post(face_b::module_button_create),
|
||||
)
|
||||
.route(
|
||||
"/api/system/ModuleButton/selectActions/{menuId}",
|
||||
post(face_b::module_button_select_actions),
|
||||
)
|
||||
.route(
|
||||
"/api/system/ModuleButton/{menuId}/List",
|
||||
get(face_b::module_button_list),
|
||||
)
|
||||
.route(
|
||||
"/api/system/ModuleButton/{menuId}/Selector",
|
||||
get(face_b::module_button_selector),
|
||||
)
|
||||
.route("/api/system/ModuleButton/{id}", get(face_b::module_button_info))
|
||||
.route(
|
||||
"/api/system/ModuleButton/{id}",
|
||||
put(face_b::module_button_update),
|
||||
)
|
||||
.route(
|
||||
"/api/system/ModuleButton/{id}",
|
||||
delete(face_b::module_button_delete),
|
||||
)
|
||||
// ---- 列表权限(官方 `ModuleColumnController.java`)----
|
||||
.route(
|
||||
"/api/system/ModuleColumn",
|
||||
post(face_b::module_column_create),
|
||||
)
|
||||
.route(
|
||||
"/api/system/ModuleColumn/Actions/Batch",
|
||||
post(face_b::module_column_batch_create),
|
||||
)
|
||||
.route(
|
||||
"/api/system/ModuleColumn/{moduleId}/Fields",
|
||||
get(face_b::module_column_list),
|
||||
)
|
||||
.route("/api/system/ModuleColumn/{id}", get(face_b::module_column_info))
|
||||
.route(
|
||||
"/api/system/ModuleColumn/{id}",
|
||||
put(face_b::module_column_update),
|
||||
)
|
||||
.route(
|
||||
"/api/system/ModuleColumn/{id}",
|
||||
delete(face_b::module_column_delete),
|
||||
)
|
||||
// ---- 表单权限(官方 `ModuleFormController.java`)----
|
||||
.route("/api/system/ModuleForm", post(face_b::module_form_create))
|
||||
.route(
|
||||
"/api/system/ModuleForm/Actions/Batch",
|
||||
post(face_b::module_form_batch_create),
|
||||
)
|
||||
.route(
|
||||
"/api/system/ModuleForm/{moduleId}/Fields",
|
||||
get(face_b::module_form_list),
|
||||
)
|
||||
.route("/api/system/ModuleForm/{id}", get(face_b::module_form_info))
|
||||
.route(
|
||||
"/api/system/ModuleForm/{id}",
|
||||
put(face_b::module_form_update),
|
||||
)
|
||||
.route(
|
||||
"/api/system/ModuleForm/{id}",
|
||||
delete(face_b::module_form_delete),
|
||||
)
|
||||
// ---- 高级查询方案(官方 `AdvancedQueryController.java`;官方**无** `@SaCheckPermission`)----
|
||||
.route(
|
||||
"/api/system/AdvancedQuery",
|
||||
post(face_b::advanced_query_create),
|
||||
)
|
||||
.route(
|
||||
"/api/system/AdvancedQuery/{moduleId}/List",
|
||||
get(face_b::advanced_query_list),
|
||||
)
|
||||
.route(
|
||||
"/api/system/AdvancedQuery/{id}",
|
||||
get(face_b::advanced_query_info),
|
||||
)
|
||||
.route(
|
||||
"/api/system/AdvancedQuery/{id}",
|
||||
put(face_b::advanced_query_update),
|
||||
)
|
||||
.route(
|
||||
"/api/system/AdvancedQuery/{id}",
|
||||
delete(face_b::advanced_query_delete),
|
||||
)
|
||||
// ---- 系统配置 + 第三方同步(官方 `SysConfigController` / `SynThirdInfoController`)----
|
||||
.route("/api/system/SysConfig", get(face_b::sys_config_get))
|
||||
.route("/api/system/SysConfig", put(face_b::sys_config_update))
|
||||
@@ -1421,7 +1526,7 @@ mod tests {
|
||||
// 🔴 表数**故意写死**:它同时校验「schema.sql 建了预期的表」与
|
||||
// 「health 报的是真数」。加表要同步改这里 + main.rs 的 BASE_TABLES
|
||||
// + crates/sspf-store 的两条 DDL 断言(共四处,漏一处就红)。
|
||||
assert_eq!(body["tables"], 43);
|
||||
assert_eq!(body["tables"], 49);
|
||||
assert_eq!(body["version"], env!("CARGO_PKG_VERSION"));
|
||||
}
|
||||
|
||||
@@ -1436,7 +1541,7 @@ mod tests {
|
||||
let port = serve(new_state(db().await)).await;
|
||||
|
||||
// 🔴 按**路径**列(同一路径多个方法只算一条)—— 每条都用 PATCH 探 405。
|
||||
const FACE_B_REGISTERED: [&str; 224] = [
|
||||
const FACE_B_REGISTERED: [&str; 244] = [
|
||||
"/api/permission/Users",
|
||||
"/api/permission/Users/any-id",
|
||||
"/api/permission/Users/BatchDelete",
|
||||
@@ -1670,6 +1775,31 @@ mod tests {
|
||||
"/api/system/printDev/Save",
|
||||
"/api/system/printDev/Info/any-id",
|
||||
"/api/system/printDev/Version/any-id",
|
||||
// ---- 电子签章(批次 10)----
|
||||
"/api/system/Signature",
|
||||
"/api/system/Signature/Selector",
|
||||
"/api/system/Signature/ListByIds",
|
||||
"/api/system/Signature/any-id",
|
||||
// ---- 按钮权限(批次 10)----
|
||||
"/api/system/ModuleButton",
|
||||
"/api/system/ModuleButton/selectActions/any-id",
|
||||
"/api/system/ModuleButton/any-id/List",
|
||||
"/api/system/ModuleButton/any-id/Selector",
|
||||
"/api/system/ModuleButton/any-id",
|
||||
// ---- 列表权限(批次 10)----
|
||||
"/api/system/ModuleColumn",
|
||||
"/api/system/ModuleColumn/Actions/Batch",
|
||||
"/api/system/ModuleColumn/any-id/Fields",
|
||||
"/api/system/ModuleColumn/any-id",
|
||||
// ---- 表单权限(批次 10)----
|
||||
"/api/system/ModuleForm",
|
||||
"/api/system/ModuleForm/Actions/Batch",
|
||||
"/api/system/ModuleForm/any-id/Fields",
|
||||
"/api/system/ModuleForm/any-id",
|
||||
// ---- 高级查询方案(批次 10)----
|
||||
"/api/system/AdvancedQuery",
|
||||
"/api/system/AdvancedQuery/any-id/List",
|
||||
"/api/system/AdvancedQuery/any-id",
|
||||
];
|
||||
|
||||
for path in FACE_B_REGISTERED {
|
||||
|
||||
@@ -0,0 +1,804 @@
|
||||
//! 批次 10(**电子签章 / 按钮权限 / 列表权限 / 表单权限 / 高级查询方案**)集成测试。
|
||||
//!
|
||||
//! 🔴 **钉住的契约点**(每条都对应官方控制器 / 前端组件的一处硬要求):
|
||||
//! ① 电子签章:官方**没有** `@SaCheckPermission` ⇒ 只需登录(不判点权限)。
|
||||
//! ② 签章列表 `userIds` = 「真实名/账号」,多个用 **「;」** 连接(官方 `StringJoiner`);
|
||||
//! 但**详情**的 `userIds` 是**数组**(官方 `SignatureInfoVO` 是 `List<String>`)。
|
||||
//! ③ 签章**名称 / 编码是两次独立判重** ⇒ 撞名报「名称不能重复」、撞码报「编码不能重复」。
|
||||
//! ④ 签章更新时 `userIds` 变化 ⇒ **先删后插**全量重建授权人。
|
||||
//! ⑤ 按钮/列表/表单权限:官方 `@SaCheckPermission(mode=OR)` 两码 ⇒ 契约写 `A|B`。
|
||||
//! ⑥ 按钮 `selectActions`:**任一条撞码 ⇒ 整体失败且不落库**(官方逐条判重后 return)。
|
||||
//! ⑦ 列表/表单权限 `enCode` **前缀化**:fieldRule=1 ⇒ `jnpf_<bindTable>_jnpf_<code>`;
|
||||
//! fieldRule=2 ⇒ `<childTableKey>-<code>`;读回时**剥掉**前缀。
|
||||
//! ⑧ 批量创建:**批内撞码**也判失败(官方 `name.contains(enCode)`)。
|
||||
//! ⑨ 高级查询方案:**只看自己的**(官方 `getList/getInfo/delete` 都带 `userId` 过滤)。
|
||||
//! ⑩ 高级查询方案列表是 `ListVO`(不是 `PageListVO`)—— 官方 `ActionResult<ListVO<…>>`。
|
||||
//!
|
||||
//! 🔴 pglite-rs 0.2.7 是**进程级全局标志** ⇒ 全文件共用一个临时库 + 一把互斥锁。
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use serde_json::{json, Value};
|
||||
use ssw_platform::bootstrap::ensure_base;
|
||||
use ssw_platform::platform::config::Config;
|
||||
use ssw_platform::platform::db::Db;
|
||||
use ssw_platform::platform::seed::first_seed;
|
||||
use ssw_platform::platform::session::SessionStore;
|
||||
use ssw_platform::platform::state::AppState;
|
||||
use ssw_platform::routes::build_app;
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::sync::{Mutex, OnceCell};
|
||||
|
||||
static DB: OnceCell<Db> = OnceCell::const_new();
|
||||
static LOCK: Mutex<()> = Mutex::const_new(());
|
||||
|
||||
async fn db() -> &'static Db {
|
||||
DB.get_or_init(|| async {
|
||||
let db = Db::open_temp().await.expect("打开 pglite 临时库失败");
|
||||
db.ensure_schema().await.expect("ensure_schema 失败");
|
||||
ensure_base(&db).await.expect("ensure_base 失败");
|
||||
first_seed(&db, "123456").await.expect("first_seed 失败");
|
||||
db
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
async fn serve(state: AppState) -> u16 {
|
||||
let listener = tokio::net::TcpListener::bind("127.0.0.1:0")
|
||||
.await
|
||||
.expect("绑定失败");
|
||||
let port = listener.local_addr().expect("取本地地址失败").port();
|
||||
let server = tokio::spawn(async move {
|
||||
let _ = axum::serve(listener, build_app(state)).await;
|
||||
});
|
||||
tokio::task::yield_now().await;
|
||||
std::mem::forget(server);
|
||||
port
|
||||
}
|
||||
|
||||
async fn call(port: u16, method: &str, path: &str, token: &str, body: Option<&str>) -> (String, Value) {
|
||||
let mut stream = TcpStream::connect(("127.0.0.1", port)).await.expect("连接失败");
|
||||
let payload = body.unwrap_or("");
|
||||
let req = format!(
|
||||
"{method} {path} HTTP/1.1\r\n\
|
||||
Host: 127.0.0.1\r\n\
|
||||
Vue-Version: 3\r\n\
|
||||
App-Code: mainSystem\r\n\
|
||||
Authorization: {token}\r\n\
|
||||
Content-Type: application/json\r\n\
|
||||
Content-Length: {}\r\n\
|
||||
Connection: close\r\n\r\n{payload}",
|
||||
payload.len()
|
||||
);
|
||||
stream.write_all(req.as_bytes()).await.expect("写请求失败");
|
||||
let mut buf = Vec::new();
|
||||
tokio::time::timeout(std::time::Duration::from_secs(15), stream.read_to_end(&mut buf))
|
||||
.await
|
||||
.expect("读响应超时")
|
||||
.expect("读响应失败");
|
||||
let text = String::from_utf8_lossy(&buf).to_string();
|
||||
let (head, body) = text.split_once("\r\n\r\n").expect("响应必须有头体分隔");
|
||||
let status = head.lines().next().unwrap_or_default().to_string();
|
||||
let json: Value = serde_json::from_str(body.trim()).unwrap_or(Value::Null);
|
||||
(status, json)
|
||||
}
|
||||
|
||||
async fn login(port: u16) -> String {
|
||||
let enc = ssw_platform::platform::cipher::encrypt_password("123456");
|
||||
let payload = format!("account=admin&password={enc}");
|
||||
let mut stream = TcpStream::connect(("127.0.0.1", port)).await.expect("连接失败");
|
||||
let req = format!(
|
||||
"POST /api/oauth/Login HTTP/1.1\r\n\
|
||||
Host: 127.0.0.1\r\n\
|
||||
Vue-Version: 3\r\n\
|
||||
App-Code: mainSystem\r\n\
|
||||
Content-Type: application/x-www-form-urlencoded\r\n\
|
||||
Content-Length: {}\r\n\
|
||||
Connection: close\r\n\r\n{payload}",
|
||||
payload.len()
|
||||
);
|
||||
stream.write_all(req.as_bytes()).await.expect("写请求失败");
|
||||
let mut buf = Vec::new();
|
||||
tokio::time::timeout(std::time::Duration::from_secs(15), stream.read_to_end(&mut buf))
|
||||
.await
|
||||
.expect("读响应超时")
|
||||
.expect("读响应失败");
|
||||
let text = String::from_utf8_lossy(&buf).to_string();
|
||||
let (_, body) = text.split_once("\r\n\r\n").expect("响应必须有头体分隔");
|
||||
let json: Value = serde_json::from_str(body.trim()).expect("登录响应必须是 JSON");
|
||||
json["data"]["token"].as_str().expect("登录必须返回 token").to_string()
|
||||
}
|
||||
|
||||
fn new_state(db: &Db) -> AppState {
|
||||
AppState {
|
||||
config: Arc::new(Config::from_env(PathBuf::from("/tmp/ssw-platform-batch10-it"))),
|
||||
db: Arc::new(db.clone()),
|
||||
sessions: Arc::new(SessionStore::default()),
|
||||
}
|
||||
}
|
||||
|
||||
/// 取一个真实存在的菜单 id(官方这些端点都挂在某个菜单下)。
|
||||
///
|
||||
/// 🔴 **直接查库**而不是走端点 —— 端点返回的是菜单**树**(`children` 嵌套),
|
||||
/// 从里面挑「功能菜单(type=2)」要递归;查库直白且不受端点形状影响。
|
||||
async fn any_menu_id() -> String {
|
||||
let rows = ssw_platform::platform::db::Db::query_json_params(
|
||||
db().await,
|
||||
"SELECT f_id AS \"id\" FROM base_module \
|
||||
WHERE COALESCE(f_delete_mark, 0) = 0 AND f_type = 2 ORDER BY f_sort_code ASC LIMIT 1",
|
||||
&[],
|
||||
)
|
||||
.await
|
||||
.expect("查菜单失败");
|
||||
assert!(!rows.is_empty(), "库里必须有 type=2 的功能菜单");
|
||||
rows[0]["id"].as_str().expect("菜单必须有 id").to_string()
|
||||
}
|
||||
|
||||
/// 新建签章,返回 id。
|
||||
async fn create_signature(port: u16, token: &str, name: &str, code: &str, user_ids: Vec<&str>) -> String {
|
||||
let body = json!({
|
||||
"fullName": name,
|
||||
"enCode": code,
|
||||
"icon": "icon-1",
|
||||
"userIds": user_ids,
|
||||
});
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/Signature",
|
||||
token,
|
||||
Some(&body.to_string()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 200, "新建签章应成功:{resp}");
|
||||
resp["data"]["id"].as_str().expect("必须返回 id").to_string()
|
||||
}
|
||||
|
||||
/// ① + ② + ③:签章的双判重、列表 `userIds` 拼接、详情 `userIds` 是数组。
|
||||
#[tokio::test]
|
||||
async fn signature_dedup_and_user_ids_shape() {
|
||||
let _guard = LOCK.lock().await;
|
||||
let port = serve(new_state(db().await)).await;
|
||||
let token = login(port).await;
|
||||
|
||||
let id = create_signature(port, &token, "合同签章", "sig_contract", vec!["u_admin"]).await;
|
||||
|
||||
// ③ 撞**名称** ⇒ 「名称不能重复」(不是编码的文案)。
|
||||
let dup_name = json!({ "fullName": "合同签章", "enCode": "sig_other" });
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/Signature",
|
||||
&token,
|
||||
Some(&dup_name.to_string()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 400, "撞名必须失败:{resp}");
|
||||
assert_eq!(resp["msg"], "名称不能重复", "撞名文案:{resp}");
|
||||
|
||||
// ③ 撞**编码** ⇒ 「编码不能重复」。
|
||||
let dup_code = json!({ "fullName": "别的签章", "enCode": "sig_contract" });
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/Signature",
|
||||
&token,
|
||||
Some(&dup_code.to_string()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 400, "撞码必须失败:{resp}");
|
||||
assert_eq!(resp["msg"], "编码不能重复", "撞码文案:{resp}");
|
||||
|
||||
// ② 详情:`userIds` 是**数组**。
|
||||
let (_, resp) = call(port, "GET", &format!("/api/system/Signature/{id}"), &token, None).await;
|
||||
assert_eq!(resp["code"], 200, "签章详情应成功:{resp}");
|
||||
assert!(
|
||||
resp["data"]["userIds"].is_array(),
|
||||
"详情的 userIds 必须是数组:{resp}"
|
||||
);
|
||||
assert_eq!(resp["data"]["userIds"].as_array().unwrap().len(), 1);
|
||||
|
||||
// ② 列表:`userIds` 是**字符串**(官方 StringJoiner 形状)。
|
||||
let (_, resp) = call(port, "GET", "/api/system/Signature", &token, None).await;
|
||||
assert_eq!(resp["code"], 200, "签章列表应成功:{resp}");
|
||||
let list = resp["data"]["list"].as_array().expect("必须是 PageListVO");
|
||||
let item = list
|
||||
.iter()
|
||||
.find(|r| r["id"] == json!(id))
|
||||
.expect("列表里必须有刚建的签章");
|
||||
assert!(
|
||||
item["userIds"].is_string(),
|
||||
"列表的 userIds 必须是字符串:{item}"
|
||||
);
|
||||
// 官方 `真实名/账号`;查不到用户时官方留空 ⇒ 这里只钉「是字符串」。
|
||||
assert!(item["userIds"].as_str().unwrap().contains('/')
|
||||
|| item["userIds"].as_str().unwrap().is_empty());
|
||||
}
|
||||
|
||||
/// ④:签章更新时 `userIds` 变化 ⇒ 全量重建授权人。
|
||||
#[tokio::test]
|
||||
async fn signature_update_rebuilds_users() {
|
||||
let _guard = LOCK.lock().await;
|
||||
let port = serve(new_state(db().await)).await;
|
||||
let token = login(port).await;
|
||||
|
||||
let id = create_signature(port, &token, "重建签章", "sig_rebuild", vec!["u_a", "u_b"]).await;
|
||||
let (_, resp) = call(port, "GET", &format!("/api/system/Signature/{id}"), &token, None).await;
|
||||
assert_eq!(
|
||||
resp["data"]["userIds"].as_array().unwrap().len(),
|
||||
2,
|
||||
"初始应有 2 个授权人:{resp}"
|
||||
);
|
||||
|
||||
// 改成 1 个 ⇒ 旧的全删、只留新的。
|
||||
let body = json!({ "userIds": ["u_c"] });
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"PUT",
|
||||
&format!("/api/system/Signature/{id}"),
|
||||
&token,
|
||||
Some(&body.to_string()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 200, "更新签章应成功:{resp}");
|
||||
|
||||
let (_, resp) = call(port, "GET", &format!("/api/system/Signature/{id}"), &token, None).await;
|
||||
let users = resp["data"]["userIds"].as_array().expect("必须是数组");
|
||||
assert_eq!(users.len(), 1, "授权人必须被全量重建:{resp}");
|
||||
assert_eq!(users[0], json!("u_c"), "应只剩 u_c:{resp}");
|
||||
}
|
||||
|
||||
/// 签章下拉框 + 按 ids 取 + 软删。
|
||||
#[tokio::test]
|
||||
async fn signature_selector_list_by_ids_and_soft_delete() {
|
||||
let _guard = LOCK.lock().await;
|
||||
let port = serve(new_state(db().await)).await;
|
||||
let token = login(port).await;
|
||||
|
||||
let id = create_signature(port, &token, "下拉签章", "sig_dropdown", vec![]).await;
|
||||
|
||||
// Selector ⇒ ListVO。
|
||||
let (_, resp) = call(port, "GET", "/api/system/Signature/Selector", &token, None).await;
|
||||
assert_eq!(resp["code"], 200, "下拉框应成功:{resp}");
|
||||
assert!(resp["data"]["list"].is_array(), "必须是 ListVO:{resp}");
|
||||
|
||||
// ListByIds ⇒ 只回给定的那些。
|
||||
let body = json!({ "ids": [id] });
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/Signature/ListByIds",
|
||||
&token,
|
||||
Some(&body.to_string()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 200, "ListByIds 应成功:{resp}");
|
||||
let list = resp["data"]["list"].as_array().expect("必须是 ListVO");
|
||||
assert_eq!(list.len(), 1, "只应返 1 条:{resp}");
|
||||
assert_eq!(list[0]["id"], json!(id));
|
||||
|
||||
// 软删后再取 ⇒ 数据不存在。
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"DELETE",
|
||||
&format!("/api/system/Signature/{id}"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 200, "删除应成功:{resp}");
|
||||
let (_, resp) = call(port, "GET", &format!("/api/system/Signature/{id}"), &token, None).await;
|
||||
assert_eq!(resp["code"], 400, "删后详情应失败:{resp}");
|
||||
assert_eq!(resp["msg"], "数据不存在", "删后详情文案:{resp}");
|
||||
}
|
||||
|
||||
/// ⑤ + ⑥:按钮权限的 OR 守卫、编码判重、selectActions「任一撞 ⇒ 整体失败」。
|
||||
#[tokio::test]
|
||||
async fn module_button_dedup_and_select_actions_atomic() {
|
||||
let _guard = LOCK.lock().await;
|
||||
let port = serve(new_state(db().await)).await;
|
||||
let token = login(port).await;
|
||||
let menu_id = any_menu_id().await;
|
||||
|
||||
// 建两个按钮。
|
||||
for (name, code) in [("新增", "btn_add"), ("编辑", "btn_edit")] {
|
||||
let body = json!({ "fullName": name, "enCode": code, "moduleId": menu_id });
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/ModuleButton",
|
||||
&token,
|
||||
Some(&body.to_string()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 200, "新建按钮应成功:{resp}");
|
||||
}
|
||||
|
||||
// 同菜单内撞码 ⇒ 「编码不能重复」。
|
||||
let dup = json!({ "fullName": "另一个新增", "enCode": "btn_add", "moduleId": menu_id });
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/ModuleButton",
|
||||
&token,
|
||||
Some(&dup.to_string()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 400, "撞码必须失败:{resp}");
|
||||
assert_eq!(resp["msg"], "编码不能重复", "撞码文案:{resp}");
|
||||
|
||||
// 列表 ⇒ PageListVO。
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"GET",
|
||||
&format!("/api/system/ModuleButton/{menu_id}/List"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 200, "按钮列表应成功:{resp}");
|
||||
assert!(resp["data"]["pagination"].is_object(), "必须是 PageListVO:{resp}");
|
||||
let list = resp["data"]["list"].as_array().unwrap();
|
||||
assert!(list.len() >= 2, "应有 2 个按钮:{resp}");
|
||||
|
||||
// 下拉框 ⇒ ListVO + 树(parentId=-1 视为根)。
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"GET",
|
||||
&format!("/api/system/ModuleButton/{menu_id}/Selector"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 200, "按钮下拉应成功:{resp}");
|
||||
let tree = resp["data"]["list"].as_array().expect("必须是 ListVO");
|
||||
assert!(!tree.is_empty(), "树不应为空:{resp}");
|
||||
assert!(
|
||||
tree.iter().all(|n| n["hasChildren"].is_boolean() && n["children"].is_array()),
|
||||
"树的每个节点都要有 hasChildren + children:{resp}"
|
||||
);
|
||||
|
||||
// ⑥ selectActions:一条撞码 ⇒ 整体失败且**不落库**。
|
||||
let before = call(
|
||||
port,
|
||||
"GET",
|
||||
&format!("/api/system/ModuleButton/{menu_id}/List"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.1["data"]["list"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.len();
|
||||
let body = json!({
|
||||
"menuId": menu_id,
|
||||
"ids": [
|
||||
{ "fullName": "删除", "enCode": "btn_del", "description": "删除" },
|
||||
{ "fullName": "导入", "enCode": "btn_add", "description": "导入" }
|
||||
],
|
||||
});
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"POST",
|
||||
&format!("/api/system/ModuleButton/selectActions/{menu_id}"),
|
||||
&token,
|
||||
Some(&body.to_string()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 400, "撞码必须整体失败:{resp}");
|
||||
let after = call(
|
||||
port,
|
||||
"GET",
|
||||
&format!("/api/system/ModuleButton/{menu_id}/List"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.1["data"]["list"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.len();
|
||||
assert_eq!(after, before, "失败时一条都不许落库:{before} → {after}");
|
||||
|
||||
// 不撞码 ⇒ 全部落库,且 parentId = "-1"、enabledMark = 1。
|
||||
let body = json!({
|
||||
"menuId": menu_id,
|
||||
"ids": [
|
||||
{ "fullName": "删除", "enCode": "btn_del", "description": "删除" },
|
||||
{ "fullName": "导出", "enCode": "btn_export", "description": "导出" }
|
||||
],
|
||||
});
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"POST",
|
||||
&format!("/api/system/ModuleButton/selectActions/{menu_id}"),
|
||||
&token,
|
||||
Some(&body.to_string()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 200, "selectActions 应成功:{resp}");
|
||||
let after = call(
|
||||
port,
|
||||
"GET",
|
||||
&format!("/api/system/ModuleButton/{menu_id}/List"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.1["data"]["list"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.clone();
|
||||
assert_eq!(after.len(), before + 2, "应新增 2 个:{before} → {}", after.len());
|
||||
let added = after
|
||||
.iter()
|
||||
.find(|r| r["enCode"] == json!("btn_del"))
|
||||
.expect("应新增 btn_del");
|
||||
assert_eq!(added["parentId"], json!("-1"), "parentId 应为 -1");
|
||||
assert_eq!(added["enabledMark"], json!(1), "enabledMark 应为 1");
|
||||
}
|
||||
|
||||
/// ⑦:列表权限的 `enCode` 前缀化(写入前缀化、读回剥掉)。
|
||||
#[tokio::test]
|
||||
async fn module_column_en_code_prefix_and_strip() {
|
||||
let _guard = LOCK.lock().await;
|
||||
let port = serve(new_state(db().await)).await;
|
||||
let token = login(port).await;
|
||||
let menu_id = any_menu_id().await;
|
||||
|
||||
// fieldRule=1 + bindTable ⇒ 落库是 `jnpf_<bindTable>_jnpf_<code>`,读回是裸 code。
|
||||
let body = json!({
|
||||
"fullName": "名称字段",
|
||||
"enCode": "f_name",
|
||||
"moduleId": menu_id,
|
||||
"bindTable": "demo_item",
|
||||
"fieldRule": 1,
|
||||
});
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/ModuleColumn",
|
||||
&token,
|
||||
Some(&body.to_string()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 200, "新建列表权限应成功:{resp}");
|
||||
let id = resp["data"]["id"].as_str().expect("必须返回 id").to_string();
|
||||
|
||||
// 详情 ⇒ 已剥掉前缀。
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"GET",
|
||||
&format!("/api/system/ModuleColumn/{id}"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 200, "详情应成功:{resp}");
|
||||
assert_eq!(
|
||||
resp["data"]["enCode"], json!("f_name"),
|
||||
"详情应剥掉前缀:{resp}"
|
||||
);
|
||||
assert_eq!(
|
||||
resp["data"]["childTableKey"], json!("tableField"),
|
||||
"childTableKey 默认 tableField:{resp}"
|
||||
);
|
||||
|
||||
// 列表 ⇒ 也剥掉前缀。
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"GET",
|
||||
&format!("/api/system/ModuleColumn/{menu_id}/Fields"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 200, "列表应成功:{resp}");
|
||||
let list = resp["data"]["list"].as_array().unwrap();
|
||||
let item = list
|
||||
.iter()
|
||||
.find(|r| r["id"] == json!(id))
|
||||
.expect("列表里必须有刚建的");
|
||||
assert_eq!(item["enCode"], json!("f_name"), "列表应剥掉前缀:{item}");
|
||||
|
||||
// 🔴 **库里存的是带前缀的**(官方语义)—— 直接查库核对。
|
||||
let rows = ssw_platform::platform::db::Db::query_json_params(
|
||||
db().await,
|
||||
"SELECT f_en_code AS \"enCode\" FROM base_module_column WHERE f_id = $1::text",
|
||||
&[&id],
|
||||
)
|
||||
.await
|
||||
.expect("查库失败");
|
||||
assert_eq!(
|
||||
rows[0]["enCode"], json!("jnpf_demo_item_jnpf_f_name"),
|
||||
"库里应存带前缀的编码:{rows:?}"
|
||||
);
|
||||
|
||||
// fieldRule=2 + childTableKey ⇒ `<childTableKey>-<code>`。
|
||||
let body = json!({
|
||||
"fullName": "子表字段",
|
||||
"enCode": "f_child",
|
||||
"moduleId": menu_id,
|
||||
"childTableKey": "tableField",
|
||||
"fieldRule": 2,
|
||||
});
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/ModuleColumn",
|
||||
&token,
|
||||
Some(&body.to_string()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 200, "新建子表字段应成功:{resp}");
|
||||
let id2 = resp["data"]["id"].as_str().expect("必须返回 id").to_string();
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"GET",
|
||||
&format!("/api/system/ModuleColumn/{id2}"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(
|
||||
resp["data"]["enCode"], json!("f_child"),
|
||||
"fieldRule=2 的详情也应剥掉前缀:{resp}"
|
||||
);
|
||||
}
|
||||
|
||||
/// ⑧:批量创建 —— **批内撞码**也判失败。
|
||||
#[tokio::test]
|
||||
async fn module_column_batch_rejects_duplicate_in_batch() {
|
||||
let _guard = LOCK.lock().await;
|
||||
let port = serve(new_state(db().await)).await;
|
||||
let token = login(port).await;
|
||||
let menu_id = any_menu_id().await;
|
||||
|
||||
// 批内两条同 code ⇒ 失败,且一条都不落库。
|
||||
let body = json!({
|
||||
"moduleId": menu_id,
|
||||
"bindTable": "demo_item",
|
||||
"fieldRule": 1,
|
||||
"columnJson": [
|
||||
{ "fullName": "甲", "enCode": "f_dup" },
|
||||
{ "fullName": "乙", "enCode": "f_dup" }
|
||||
],
|
||||
});
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/ModuleColumn/Actions/Batch",
|
||||
&token,
|
||||
Some(&body.to_string()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 400, "批内撞码必须失败:{resp}");
|
||||
assert_eq!(resp["msg"], "编码不能重复", "批内撞码文案:{resp}");
|
||||
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"GET",
|
||||
&format!("/api/system/ModuleColumn/{menu_id}/Fields"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
let count = resp["data"]["list"].as_array().unwrap().len();
|
||||
assert_eq!(count, 0, "失败时一条都不许落库:{resp}");
|
||||
|
||||
// 不撞码 ⇒ 全部落库。
|
||||
let body = json!({
|
||||
"moduleId": menu_id,
|
||||
"bindTable": "demo_item",
|
||||
"fieldRule": 1,
|
||||
"columnJson": [
|
||||
{ "fullName": "甲", "enCode": "f_a" },
|
||||
{ "fullName": "乙", "enCode": "f_b" }
|
||||
],
|
||||
});
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/ModuleColumn/Actions/Batch",
|
||||
&token,
|
||||
Some(&body.to_string()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 200, "批量应成功:{resp}");
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"GET",
|
||||
&format!("/api/system/ModuleColumn/{menu_id}/Fields"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(
|
||||
resp["data"]["list"].as_array().unwrap().len(),
|
||||
2,
|
||||
"应落库 2 条:{resp}"
|
||||
);
|
||||
}
|
||||
|
||||
/// 表单权限:与列表权限同规则(前缀化 / 剥前缀 / 详情默认 childTableKey)。
|
||||
#[tokio::test]
|
||||
async fn module_form_prefix_and_defaults() {
|
||||
let _guard = LOCK.lock().await;
|
||||
let port = serve(new_state(db().await)).await;
|
||||
let token = login(port).await;
|
||||
let menu_id = any_menu_id().await;
|
||||
|
||||
let body = json!({
|
||||
"fullName": "表单字段",
|
||||
"enCode": "ff_name",
|
||||
"moduleId": menu_id,
|
||||
"bindTable": "demo_item",
|
||||
"fieldRule": 1,
|
||||
});
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/ModuleForm",
|
||||
&token,
|
||||
Some(&body.to_string()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 200, "新建表单权限应成功:{resp}");
|
||||
let id = resp["data"]["id"].as_str().expect("必须返回 id").to_string();
|
||||
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"GET",
|
||||
&format!("/api/system/ModuleForm/{id}"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 200, "详情应成功:{resp}");
|
||||
assert_eq!(
|
||||
resp["data"]["enCode"], json!("ff_name"),
|
||||
"详情应剥掉前缀:{resp}"
|
||||
);
|
||||
assert_eq!(
|
||||
resp["data"]["childTableKey"], json!("tableField"),
|
||||
"childTableKey 默认 tableField:{resp}"
|
||||
);
|
||||
|
||||
// 表单权限批量 ⇒ 撞码失败。
|
||||
let body = json!({
|
||||
"moduleId": menu_id,
|
||||
"formJson": [
|
||||
{ "fullName": "甲", "enCode": "ff_dup" },
|
||||
{ "fullName": "乙", "enCode": "ff_dup" }
|
||||
],
|
||||
});
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/ModuleForm/Actions/Batch",
|
||||
&token,
|
||||
Some(&body.to_string()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 400, "批内撞码必须失败:{resp}");
|
||||
}
|
||||
|
||||
/// ⑨ + ⑩:高级查询方案 —— 只看自己的;列表是 `ListVO` 不是 `PageListVO`。
|
||||
#[tokio::test]
|
||||
async fn advanced_query_is_owner_scoped_and_list_vo() {
|
||||
let _guard = LOCK.lock().await;
|
||||
let port = serve(new_state(db().await)).await;
|
||||
let token = login(port).await;
|
||||
let menu_id = any_menu_id().await;
|
||||
|
||||
let body = json!({
|
||||
"fullName": "我的方案",
|
||||
"matchLogic": "and",
|
||||
"conditionJson": "[{\"field\":\"name\",\"op\":\"like\",\"value\":\"a\"}]",
|
||||
"moduleId": menu_id,
|
||||
});
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/AdvancedQuery",
|
||||
&token,
|
||||
Some(&body.to_string()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 200, "新建方案应成功:{resp}");
|
||||
let id = resp["data"]["id"].as_str().expect("必须返回 id").to_string();
|
||||
|
||||
// ⑩ 列表 ⇒ `ListVO`(**没有** pagination 字段)。
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"GET",
|
||||
&format!("/api/system/AdvancedQuery/{menu_id}/List"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 200, "方案列表应成功:{resp}");
|
||||
assert!(
|
||||
resp["data"]["list"].is_array(),
|
||||
"必须是 ListVO 的 list:{resp}"
|
||||
);
|
||||
assert!(
|
||||
resp["data"].get("pagination").is_none(),
|
||||
"高级查询列表**不是** PageListVO:{resp}"
|
||||
);
|
||||
let list = resp["data"]["list"].as_array().unwrap();
|
||||
assert_eq!(list.len(), 1, "应有 1 条:{resp}");
|
||||
assert_eq!(list[0]["id"], json!(id));
|
||||
|
||||
// ⑨ 详情 ⇒ 自己的能取到。
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"GET",
|
||||
&format!("/api/system/AdvancedQuery/{id}"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 200, "自己的方案应能取到:{resp}");
|
||||
assert_eq!(resp["data"]["matchLogic"], json!("and"), "字段应对齐:{resp}");
|
||||
|
||||
// ⑨ 别人的方案(直接改库里的 creator)⇒ 看不到。
|
||||
ssw_platform::platform::db::Db::exec_params(
|
||||
db().await,
|
||||
"UPDATE base_advanced_query_scheme SET f_creator_user_id = 'u_other' WHERE f_id = $1::text",
|
||||
&[&id],
|
||||
)
|
||||
.await
|
||||
.expect("改库失败");
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"GET",
|
||||
&format!("/api/system/AdvancedQuery/{id}"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 400, "别人的方案应看不到:{resp}");
|
||||
assert_eq!(resp["msg"], "数据不存在", "别人的方案文案:{resp}");
|
||||
|
||||
// ⑨ 别人的方案也删不掉。
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"DELETE",
|
||||
&format!("/api/system/AdvancedQuery/{id}"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 400, "别人的方案应删不掉:{resp}");
|
||||
assert_eq!(resp["msg"], "删除失败,数据不存在", "别人的方案文案:{resp}");
|
||||
}
|
||||
|
||||
/// 必填校验:官方 `@NotBlank` 的四个字段缺一不可。
|
||||
#[tokio::test]
|
||||
async fn advanced_query_required_fields() {
|
||||
let _guard = LOCK.lock().await;
|
||||
let port = serve(new_state(db().await)).await;
|
||||
let token = login(port).await;
|
||||
|
||||
for (body, why) in [
|
||||
(json!({ "enCode": "x" }), "缺 fullName/conditionJson/matchLogic/moduleId"),
|
||||
(
|
||||
json!({ "fullName": "甲", "conditionJson": "[]", "matchLogic": "and" }),
|
||||
"缺 moduleId",
|
||||
),
|
||||
] {
|
||||
let (_, resp) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/AdvancedQuery",
|
||||
&token,
|
||||
Some(&body.to_string()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp["code"], 400, "必填校验必须失败({why}):{resp}");
|
||||
}
|
||||
}
|
||||
@@ -380,9 +380,10 @@ async fn data_model_tables_info_and_fields() {
|
||||
let total = tables["data"]["pagination"]["total"]
|
||||
.as_i64()
|
||||
.expect("必须有 total");
|
||||
// schema.sql 现在是 43 张表(批次 9 新增 6 张:数据接口 + 接口认证 + 打印模板/版本);
|
||||
// schema.sql 现在是 49 张表(批次 9 新增 6 张:数据接口 + 接口认证 + 打印模板/版本;
|
||||
// 批次 10 新增 6 张:签章 + 签章授权人 + 按钮/列表/表单权限 + 高级查询方案);
|
||||
// 真有变化时这条会红,提醒同步(与 DDL 计数测试同口径)。
|
||||
assert_eq!(total, 43, "表清单必须来自 information_schema: {tables}");
|
||||
assert_eq!(total, 49, "表清单必须来自 information_schema: {tables}");
|
||||
let list = tables["data"]["list"].as_array().expect("必须有 list");
|
||||
assert!(
|
||||
list.iter().any(|r| r["table"] == "base_user"),
|
||||
|
||||
Reference in new issue
Block a user