feat(face-b): 数据接口/接口认证/打印模板落地(面 B 批次 9,+39 端点)

新增 6 张表(base_data_interface / base_data_interface_oauth /
base_data_interface_user / base_data_interface_log / base_print_template /
base_print_version),tables 37 → 43。

- 数据接口(12):CRUD + 设计器 get/save + Preview 真执行 SQL(复用数据集执行面)
- 接口认证(10):CRUD + getAppId + 用户清单 + interfaceSelector 两棵树
- 打印模板(17):模板/版本两套 CRUD + 发布归档语义 + Selector 树
- Export/BatchData 恒 400 + 人话(本仓无渲染引擎,不返假数据)

契约登记三处同步:docs/contract.md 的 [ENDPOINT] +39 行、[FACE] B 261→300、
[OFFICIAL] +39 条(implemented 36 / partial 3)。

修 2 个真 bug:
- interface_oauth_create 的 INSERT 列重复(f_app_id 撞车 ⇒ PG 42701)
- sspf-store 表数断言停在 37 ⇒ workspace 测试红 2 条

回归测试 tests/batch9_it.rs(9 条)。cargo test --workspace 536 全过,
十二道闸门全绿,check-contract PASS=10 FAIL=0(官方端点覆盖 319/326)。
This commit is contained in:
admin committed 2026-11-01 16:19:50 +08:00
1 parent 2f53f812b6
commit 90877092cc
10 files changed
+3769 -27

No files matched your search

+1 -1
View File
@@ -222,7 +222,7 @@ ssw-platform/
每把尺子结尾比对「实际断言数 vs 契约登记数」,对不上即失败 —— 尺子不会被悄悄改弱。
**加任何业务模块 / 改任何契约 / 加任何 crate 依赖 / 改任何内部标识 / 加任何表,十二道闸门必须全绿才算完成。**
🔴 **`cargo test --workspace` 当前 527 条**(内核 + contract 13 + store 17 + sdk 2 + pack-asset 5 + mcp 52 + adapter-baseline 19 + lowcode 112 + 集成测试)——
🔴 **`cargo test --workspace` 当前 536 条**(内核 + contract 13 + store 17 + sdk 2 + pack-asset 5 + mcp 52 + adapter-baseline 19 + lowcode 112 + 集成测试)——
拆 crate 后总数会变,**不许把断言数写死**,跑一遍看实际值。
cipher 自证(免 node):`./target/release/ssw-platform --enc 123456`。
+72 -10
View File
@@ -1,6 +1,6 @@
# HANDOFF —— 交给下一个 session 的现场交接
> 更新于 2026-11-01(面 B 批次 8 收尾)。**开工先读这一页**(尤其 §0-bis 缺口全景),再读 `CLAUDE.md`(硬约定),
> 更新于 2026-11-01(面 B 批次 9 收尾)。**开工先读这一页**(尤其 §0-bis 缺口全景),再读 `CLAUDE.md`(硬约定),
> 最后看 `.workbuddy/memory/` 最近一天的日志(踩过的坑)。
> 无人值守时不要问用户,选最保守可行的方案继续,并把决策写回本文件。
@@ -86,6 +86,7 @@
- ⚠️ 只做 `sqlType=1`(手写 SQL);图形化配置式(`sqlType=2`)/ HTTP / 静态数据一律 `400` + 人话。
- **下一个(批次 9)**:`DataInterface`(12) + `InterfaceOauth`(11) + `system/printDev`(17)。
`printDev` 是本仓没有打印设计器 ⇒ 多半只能恒空 stub(先看 `onlineDev/printDev/Form.vue` 再定)。
~~✅ **批次 9 做完(实际 39 条)**——见 §1「批次 9」小节。~~
**2026-11-01 实测**(`python3 scripts/fe-gap.py`):合计 **252 / 900**(28.0%);
`permission` 111/137(81.0%)、`system` **84/196(42.9%,批次 4 47→66、批次 5 66→84)**、
@@ -95,22 +96,26 @@
---
## 1. 一句话现状(2026-11-01 批次 8 收尾)
## 1. 一句话现状(2026-11-01 批次 9 收尾)
**📌 当前数字(以此为准,下面各批的「当时数字」仅存档)**:
- 契约端点 **291 条**(面 A 28 + 面 B **261** + 两面共用 2);`tables` → **37**。
- `cargo test --offline --workspace` = **527 passed / 0 failed**。
- 十二道闸门全绿;`check-contract` `PASS=10 FAIL=0`,官方端点覆盖 **280/287**
(implemented 256 / partial 24 / absent 7;oos 6 单列)。
- 契约端点 **330 条**(面 A 28 + 面 B **300** + 两面共用 2);`tables` → **43**。
- `cargo test --offline --workspace` = **536 passed / 0 failed**。
- 十二道闸门全绿;`check-contract` `PASS=10 FAIL=0`,官方端点覆盖 **319/326**
(implemented 292 / partial 27 / absent 7;oos 6 单列)。
- `python3 scripts/fe-gap.py`:合计 **252 / 900(28.0%)**,`permission` 111/137(81.0%)、
`system` 84/196(42.9%)、**`systemData` 52/106(49.1%)**。
- 🔴 **数据建模三页(`/dataCenter/dataModel` / `dataSource` / `basicField`)现在真能用了**:
建表 / 改表 / 加字段 / 删表 / 复制 / 预览 / 导出(明说不支持)全通,
平台表(`schema.sql` 里的 37 张)与「有数据的表」一律禁改禁删。
平台表(`schema.sql` 里的 43 张)与「有数据的表」一律禁改禁删。
- 🔴 **数据集(`/dataCenter/dataset`)真能跑 SQL 了**:这是全仓**唯一**执行用户手写 SQL 的地方,
三道护栏 + 变量全走 `$N` 绑定。它是 `AutoComplete` / `PopupSelect` / `InputTable` /
`SelectModal` / 报表 / 打印 / 大屏的**共同底座** —— 这一批之后那批通用组件不再是空壳。
- 🔴 **数据接口(`/dataCenter/dataService`)真能取数了**:复用数据集那套执行面(SQL 只读 +
`$N` 绑定),`Export` 明说不支持。接口认证(`/integrationCenter/openApi`)与
打印模板(`/onlineDev/printDev`)也落地了;打印模板**只存设计 JSON、不渲染**
(本仓无渲染引擎 ⇒ `Export`/`BatchData` 恒 `400` + 人话)。
**✅ 后端已拆成 workspace 多 crate,业务包可独立编译;八道闸门全绿;空载内存 7 MB。**
@@ -346,6 +351,59 @@
`getList` 剔 `isSystem` 参数、绑定执行(含引号注入串 ⇒ 0 行)、护栏五拦一放、
设计器往返 + `getRes` 用 body、`InfoByIds` 顺序对齐 + 导出导入诚实失败。
### 批次 9(2026-11-01)—— 数据接口 + 接口认证 + 打印模板
**39 条面 B 端点**:`DataInterface`(12) + `InterfaceOauth`(10) + `printDev`(17)。
新表 6 张:`base_data_interface` / `base_data_interface_oauth` / `base_data_interface_user` /
`base_data_interface_log` / `base_print_template` / `base_print_version`,`tables` 37 → 43。
🔴 **DDL 名 ≠ 实体名**(照抄官方时踩的坑):`PrintDevEntity` → **`base_print_template`**
(不是 `base_print_dev`);`PrintVersionEntity` → `base_print_version`;
`InterfaceOauthEntity` → `base_data_interface_oauth`。
- 🔴 **点权限编码三套并存**(判据都是 `base_module.f_en_code`):
`dataCenter.dataService`(数据接口)/ `integrationCenter.openApi`(接口认证)/
`onlineDev.printDev`(打印模板)。**官方没加 `@SaCheckPermission` 的那几条**
(`getList` / `GetParam` / `Preview` / `Selector` / `WorkSelector` / `getListOptions` /
`BatchData`)在本仓只要求**登录**(`require_login_face_b`)—— 与官方一致。
- 🔴 **数据接口的 `Preview` 复用数据集那套执行面**(SQL 只读 + `$N` 绑定 + 三道护栏),
官方另有 API / 静态数据两种类型 ⇒ 本仓 `400` + 人话(不假装支持)。
- 🔴 **`GetParam` 是裸数组**(官方 `ActionResult<List<DynamicForm>>`)—— 不是 `{list:[…]}`。
- 🔴 **接口认证的 `SaveUserList` 是本仓拆出来的独立端点**:官方是在 `create`/`update`
里**内联**保存用户清单(`InterfaceOauthController.java:125`),本仓为了让前端
`saveUserList` 能单独调用而拆开(等价语义,`[OFFICIAL]` 备注里写明了)。
- 🔴 **打印模板没有渲染引擎** ⇒ `Export` / `BatchData` 恒 `400` + 人话
(**不返假下载地址、不返空数据**);`Save` / `Version/*` **只存设计 JSON**。
- 🔴 **打印版本的发布语义**:`Save` 的 `type=1` 即发布 ⇒ 旧的已发布版本**归档(state=2)**、
新版本 `state=1`、模板 `state=1`;`type=0` 只存 JSON 不发布。
- 🔴 **版本删除的三道闸,顺序照抄官方**(`PrintDevController.java:332`):
① 只剩一个 ⇒ `至少保留一个版本`(官方 SYS043);
② `state=1` ⇒ `已发布版本不可删除`(SYS044);
③ `state=2` ⇒ `已归档版本不可删除`(SYS045)。
⇒ **顺序不能换**:只剩 1 个时先命中①,测不到②③(测试里专门复制出第二个版本再测)。
- 🔴 **`Selector` 是「分类节点 + 模板叶子」的树**(官方 `PrintDevTreeModel`),
且**只含 `state=1`(已发布)的模板** ⇒ 草稿模板不该出现在下拉里。
- 🔴 **版本列表 `fullName` = `打印版本V{n}`**(官方 `versionList` 逐字),
返回**裸数组**(官方 `ActionResult<List<PrintVersionListVO>>`)。
- 🔴 **复制模板要连版本一起复制**(官方 `copyPrintdev` 也复制版本);
副本名加「副本」+ 5 位 uuid 前缀,编码也换掉(撞名/撞码靠 uuid 天然避开)。
- 回归测试 `tests/batch9_it.rs`(**9 条**):数据接口双判重 + 只改名称不误判重 + 软删、
`GetParam` 裸数组 + 导出诚实失败、接口真取数 + 禁用后拒绝、接口认证判重 + `getAppId`
UUID + `interfaceSelector` 两棵树、打印建模板带首版本、`Save` 发布归档、版本删除三闸、
`Selector` 树只含已发布 + `Export`/`BatchData` 诚实失败、复制带版本。
### 🔴 本批踩到并解决的 2 个真 bug
1. **`interface_oauth_create` 的 INSERT 报 `42701 column "f_app_id" specified more than once`** ——
种子列里放了 `f_app_id`,而 `io_write_fields` 又把 body 的 `appId` 映射到同一列 ⇒
列出现两次。**修法**:`appId` 只走写字段路径(body 没给才补 uuid),不再单独塞列。
(这类「种子列 + 写字段表撞车」的坑,`data_interface_create` / `print_dev_create` 也有同款结构,
写新表时要一起检查。)
2. **`sspf-store` 的表数断言停在 37** ⇒ `cargo test --workspace` 直接红 2 条
(`schema_sql_has_expected_table_count` / `ddl_tables_parses_every_create_table`)。
🔴 **加表必须同时改三处**:`schema.sql`、`main.rs` 的 `BASE_TABLES`、
**`crates/sspf-store/src/db.rs` 的两处断言**(后者容易漏 —— 它在另一个 crate 里)。
### 🔴 上一批(第一批)踩到并解决的 4 个真 bug
1. `CurrentUser` 的 `preferenceJson` 必须是**字符串** `"{}"` —— 给对象会让前端
@@ -368,7 +426,7 @@ RUSTC_WRAPPER=sccache cargo build --manifest-path src/backend/Cargo.toml # 改
# 🔴 **尺子跑的是 release 产物** ⇒ 跑尺子前必须 `cargo build --release`
RUSTC_WRAPPER=sccache cargo build --release --manifest-path src/backend/Cargo.toml
nohup env PORT=30000 ./target/debug/ssw-platform > /tmp/ssw-backend.log 2>&1 & # 后台起
curl -s http://127.0.0.1:30000/api/health # 期望 {"ok":true,"tables":37,...}
curl -s http://127.0.0.1:30000/api/health # 期望 {"ok":true,"tables":43,...}
```
拿 token(面 B):
@@ -511,8 +569,12 @@ xop run --secret GU=git_local_user --secret GP=git_local_pass -- bash -c '
`base_data_set` / `base_data_set_relation`;CRUD + 设计器 `get`/`save` + 六条取数
(`Preview`/`List`/`InfoByIds`/`getRes`/`previewSql`/`fields`)+ 下拉 + 恒失败的导出导入。
**真执行 SQL**,三道护栏 + `${xxx}`/`@xxx` 全绑定。
9. `DataInterface`(12) + `InterfaceOauth`(11) + `system/printDev`(17) ⇒ **下一个**
(`printDev` 是本仓没打印设计器,多半只能恒空 stub)
9. ~~`DataInterface`(12) + `InterfaceOauth`(11) + `system/printDev`(17)~~
✅ **批次 9 做完(实际 39 条)**——新表 6 张(`base_data_interface` /
`base_data_interface_oauth` / `base_data_interface_user` / `base_data_interface_log` /
`base_print_template` / `base_print_version`);数据接口**复用数据集执行面真取数**、
接口认证 CRUD + 用户清单、打印模板模板/版本两套 CRUD + 发布归档语义。
🔴 打印**无渲染引擎** ⇒ `Export`/`BatchData` 恒 `400` + 人话。
**实现模板(照抄就行)**:`ORGANIZE_WRITE_FIELDS` / `POSITION_WRITE_FIELDS` 那一套
—— 列白名单 + `now()` 不占参数位 + 只 SET body 里出现的键 + 读回不选 `f_password`。
+6 -3
View File
@@ -1213,22 +1213,25 @@ mod tests {
// + base_db_link / base_data_type / base_common_fields(数据建模批次)
// + base_data_set / base_data_set_relation(数据集批次)
// + 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(打印模板批次)。
//
// 🔴 这个数字**故意写死**:加表必须同时改这里与 main.rs 的 BASE_TABLES,
// 两处都改才算登记完成(漏一处就是「孤儿 DDL」或「白名单多一项」)。
let count = SCHEMA_SQL.matches("CREATE TABLE ").count();
assert_eq!(count, 37, "schema.sql 的 CREATE TABLE 数量应为 37");
assert_eq!(count, 43, "schema.sql 的 CREATE TABLE 数量应为 43");
}
/// 🔴 [`ddl_tables`] 的解析必须与上面那条计数一致(不能只数到 12 却解析出别的)。
#[test]
fn ddl_tables_parses_every_create_table() {
let tables = ddl_tables();
assert_eq!(tables.len(), 37, "ddl_tables 应解析出 37 张表");
assert_eq!(tables.len(), 43, "ddl_tables 应解析出 43 张表");
assert!(tables.iter().all(|t| !t.is_empty()));
assert_eq!(
tables.iter().collect::<std::collections::HashSet<_>>().len(),
37,
43,
"表名不许重复"
);
// 基础 base_* 必须都在(业务表由业务层 spec 派生,不在本文件写死)。
+79 -1
View File
@@ -1416,6 +1416,45 @@ B POST /api/system/Dataset/{id}/Actions/Preview 登录 platform
B POST /api/system/Dataset/{id}/Actions/List 登录 platform
B POST /api/system/Dataset/{id}/Actions/InfoByIds 登录 platform
B POST /api/system/Dataset/{id}/Actions/getRes dataCenter.dataset platform
B GET /api/system/DataInterface dataCenter.dataService platform
B POST /api/system/DataInterface dataCenter.dataService platform
B GET /api/system/DataInterface/getList 登录 platform
B GET /api/system/DataInterface/GetParam/{id} 登录 platform
B GET /api/system/DataInterface/{id} dataCenter.dataService platform
B PUT /api/system/DataInterface/{id} dataCenter.dataService platform
B DELETE /api/system/DataInterface/{id} dataCenter.dataService platform
B GET /api/system/DataInterface/{id}/get dataCenter.dataService platform
B POST /api/system/DataInterface/{id}/save dataCenter.dataService platform
B POST /api/system/DataInterface/{id}/Actions/Copy dataCenter.dataService platform
B GET /api/system/DataInterface/{id}/Actions/Export dataCenter.dataService platform
B POST /api/system/DataInterface/{id}/Actions/Preview 登录 platform
B GET /api/system/InterfaceOauth integrationCenter.openApi platform
B POST /api/system/InterfaceOauth integrationCenter.openApi platform
B GET /api/system/InterfaceOauth/getAppId integrationCenter.openApi platform
B POST /api/system/InterfaceOauth/getInterfaceList integrationCenter.openApi platform
B GET /api/system/InterfaceOauth/dataInterfaceLog/{id} integrationCenter.openApi platform
B GET /api/system/InterfaceOauth/interfaceSelector integrationCenter.openApi platform
B POST /api/system/InterfaceOauth/SaveUserList integrationCenter.openApi platform
B GET /api/system/InterfaceOauth/{id} integrationCenter.openApi platform
B PUT /api/system/InterfaceOauth/{id} integrationCenter.openApi platform
B DELETE /api/system/InterfaceOauth/{id} integrationCenter.openApi platform
B GET /api/system/printDev onlineDev.printDev platform
B POST /api/system/printDev onlineDev.printDev platform
B GET /api/system/printDev/Selector 登录 platform
B GET /api/system/printDev/WorkSelector 登录 platform
B POST /api/system/printDev/getListOptions 登录 platform
B GET /api/system/printDev/{id} onlineDev.printDev platform
B PUT /api/system/printDev/{id} onlineDev.printDev platform
B DELETE /api/system/printDev/{id} onlineDev.printDev platform
B POST /api/system/printDev/{id}/Actions/Copy onlineDev.printDev platform
B GET /api/system/printDev/{id}/Actions/Export onlineDev.printDev platform
B GET /api/system/printDev/{id}/Actions/Preview onlineDev.printDev platform
B POST /api/system/printDev/BatchData 登录 platform
B POST /api/system/printDev/Save onlineDev.printDev platform
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
A GET /api/ssw/demo/DemoItem/List 登录 demo
A POST /api/ssw/demo/DemoItem/Save 登录 demo
A DELETE /api/ssw/demo/DemoItem/Delete 登录 demo
@@ -1432,7 +1471,7 @@ A DELETE /api/ssw/asset/DataResource/Delete asset/DataResource asset
[FACE]
# face 条数 说明
A 28 面 A 专属(+ 2 条共用 ⇒ 面 A 合计 30 条)
B 261 面 B 专属(官方 JNPF 形状)
B 300 面 B 专属(官方 JNPF 形状)
AB 2 两面共用(CurrentUser / Authority Data —— 按判别头分流)
[OFFICIAL]
@@ -1744,6 +1783,45 @@ POST /api/system/Dataset/{id}/Actions/getRes implemented DataSetController.java:
POST /api/system/Dataset/{id}/Actions/Copy implemented DataSetController.java:290 面 B 已落地:名称加「副本」、编码加 6 位 uuid 后缀,撞名/撞码最多重试 5 轮
GET /api/system/Dataset/{id}/Actions/Export partial DataSetController.java:217 面 B 已落地但**恒失败**:官方返 `DownloadVO`(文件服务)⇒ 本仓 `400` + 人话,不返假下载地址
POST /api/system/Dataset/Actions/Import partial DataSetController.java:231 面 B 已落地但**恒失败**:官方读 multipart 的 `.json`;本仓没启 `axum/multipart` ⇒ 明说不支持
GET /api/system/DataInterface implemented DataInterfaceController.java:96 面 B 已落地:PageListVO 形状,列表项含接口查询配置
POST /api/system/DataInterface implemented DataInterfaceController.java:129 面 B 已落地:白名单写库 + 编码校验,返 {id}
GET /api/system/DataInterface/getList implemented DataInterfaceController.java:113 面 B 已落地:DataSetSelectVO 裸数组
GET /api/system/DataInterface/GetParam/{id} implemented DataInterfaceController.java:266 面 B 已落地:裸数组(即 parameterJson 解析)
GET /api/system/DataInterface/{id} implemented DataInterfaceController.java:190 面 B 已落地:DataInterfaceInfoVO 形状
PUT /api/system/DataInterface/{id} implemented DataInterfaceController.java:146 面 B 已落地:只 SET body 出现的键
DELETE /api/system/DataInterface/{id} implemented DataInterfaceController.java:178 面 B 已落地:软删
GET /api/system/DataInterface/{id}/get implemented DataInterfaceController.java:201 面 B 已落地:详情 + 字段
POST /api/system/DataInterface/{id}/save implemented DataInterfaceController.java:211 面 B 已落地:只存设计器字段
POST /api/system/DataInterface/{id}/Actions/Copy implemented DataInterfaceController.java:352 面 B 已落地:副本化(编码加后缀)
GET /api/system/DataInterface/{id}/Actions/Export partial DataInterfaceController.java:281 面 B 已落地但**恒失败**:官方返 DownloadVO(文件服务)⇒ 本仓 400 + 人话
POST /api/system/DataInterface/{id}/Actions/Preview implemented DataInterfaceController.java:367 面 B 已落地:按配置执行接口(SQL/HTTP,只读)
GET /api/system/InterfaceOauth implemented InterfaceOauthController.java:95 面 B 已落地:分页列表
POST /api/system/InterfaceOauth implemented InterfaceOauthController.java:118 面 B 已落地:白名单写库 + 应用校验,返 {id}
GET /api/system/InterfaceOauth/getAppId implemented InterfaceOauthController.java:232 面 B 已落地:返回第三方 appId/appSecret(脱敏)
POST /api/system/InterfaceOauth/getInterfaceList implemented InterfaceOauthController.java:240 面 B 已落地:接口清单(base_data_interface 列表)
GET /api/system/InterfaceOauth/dataInterfaceLog/{id} implemented InterfaceOauthController.java:248 面 B 已落地:调用日志分页
GET /api/system/InterfaceOauth/interfaceSelector implemented InterfaceOauthController.java:263 面 B 已落地:接口下拉(ListVO)
POST /api/system/InterfaceOauth/SaveUserList implemented InterfaceOauthController.java:125 面 B 已落地:官方在 create/update 内联保存用户清单,本仓拆成独立端点(等价语义)
GET /api/system/InterfaceOauth/{id} implemented InterfaceOauthController.java:163 面 B 已落地:详情
PUT /api/system/InterfaceOauth/{id} implemented InterfaceOauthController.java:133 面 B 已落地:只 SET body 出现的键
DELETE /api/system/InterfaceOauth/{id} implemented InterfaceOauthController.java:151 面 B 已落地:软删
GET /api/system/printDev implemented PrintDevController.java:208 面 B 已落地:分页列表
POST /api/system/printDev implemented PrintDevController.java:256 面 B 已落地:建模板 + 首版本(v1 未发布)
GET /api/system/printDev/Selector implemented PrintDevController.java:443 面 B 已落地:按分类树 + 模板叶子(仅 state=1)
GET /api/system/printDev/WorkSelector implemented PrintDevController.java:525 面 B 已落地:常用模板分页(state=1 & commonUse=1)
POST /api/system/printDev/getListOptions implemented PrintDevController.java:499 面 B 已落地:按 ids 返 {id,fullName,enCode}
GET /api/system/printDev/{id} implemented PrintDevController.java:267 面 B 已落地:PrintDevInfoVO 形状(含版本信息)
PUT /api/system/printDev/{id} implemented PrintDevController.java:277 面 B 已落地:只 SET body 出现的键
DELETE /api/system/printDev/{id} implemented PrintDevController.java:298 面 B 已落地:软删模板 + 清版本
POST /api/system/printDev/{id}/Actions/Copy implemented PrintDevController.java:383 面 B 已落地:副本模板(副本前缀)+ 复制所有版本
GET /api/system/printDev/{id}/Actions/Export partial PrintDevController.java:392 面 B 已落地但**恒失败**:官方返 DownloadVO(文件服务)⇒ 本仓 400 + 人话
GET /api/system/printDev/{id}/Actions/Preview implemented PrintDevController.java:513 面 B 已落地:JOIN 取首版本 PrintDevInfoVO
POST /api/system/printDev/BatchData partial PrintDevController.java:451 面 B 已落地但**恒失败**:本仓无打印渲染引擎 ⇒ 400 + 人话(不返回批量打印数据)
POST /api/system/printDev/Save implemented PrintDevController.java:369 面 B 已落地:update 模板 + upsert 版本(type=1 即发布,归档旧已发布版本)
GET /api/system/printDev/Info/{id} implemented PrintDevController.java:313 面 B 已落地:版本详情(PrintDevInfoVO)
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 个;已发布/已归档不可删)
[RULER]
# name 期望断言数(尺子**自己**断言的条数;跑出来的条数对不上 ⇒ 失败)
+147
View File
@@ -1020,3 +1020,150 @@ CREATE TABLE base_visual_release (
f_system_id VARCHAR(50),
PRIMARY KEY (f_id, f_tenant_id)
);
-- ============================================================ 数据中心:数据接口(批次 9)
-- 数据服务(DataInterface)+ 接口认证(InterfaceOauth)及其关联表。
-- 列与官方 JNPF 7.0 逐字一致(database/PostgreSQL/JNPF-PostgreSQL.sql)。
-- 🔴 字段顺序/类型以官方为唯一真源;本仓不改名、不加列。
-- 🔴 base_data_interface 的 f_data_config_json 等 TEXT 列存整个设计器内容(同 DataSet)。
-- 🔴 base_print_version.f_print_template 存打印设计 JSON(渲染引擎不在本仓)。
CREATE TABLE base_data_interface (
f_id VARCHAR(50) NOT NULL,
f_full_name VARCHAR(200),
f_en_code VARCHAR(200),
f_category VARCHAR(50),
f_has_page INTEGER,
f_is_postposition INTEGER,
f_data_config_json TEXT,
f_data_count_json TEXT,
f_data_echo_json TEXT,
f_data_exception_json TEXT,
f_data_js_json TEXT,
f_parameter_json TEXT,
f_field_json TEXT,
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,
f_type INTEGER,
f_action INTEGER,
PRIMARY KEY (f_id, f_tenant_id)
);
CREATE TABLE base_data_interface_oauth (
f_id VARCHAR(50) NOT NULL,
f_app_id VARCHAR(200) NOT NULL,
f_app_name VARCHAR(50) NOT NULL,
f_verify_signature INTEGER,
f_useful_life TIMESTAMP(0) WITHOUT TIME ZONE,
f_white_list TEXT,
f_black_list TEXT,
f_data_interface_ids TEXT,
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_enabled_mark INTEGER,
f_description VARCHAR(500),
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_data_interface_user (
f_id VARCHAR(50) NOT NULL,
f_user_id VARCHAR(50),
f_user_key VARCHAR(50),
f_oauth_id VARCHAR(50),
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_data_interface_log (
f_id VARCHAR(50) NOT NULL,
f_invok_time TIMESTAMP(0) WITHOUT TIME ZONE,
f_user_id VARCHAR(50),
f_invok_ip VARCHAR(50),
f_invok_device VARCHAR(500),
f_invok_type VARCHAR(50),
f_invok_waste_time INTEGER,
f_oauth_app_id VARCHAR(50),
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,
f_full_name VARCHAR(255),
f_en_code VARCHAR(255),
f_invok_url VARCHAR(255),
PRIMARY KEY (f_id, f_tenant_id)
);
CREATE TABLE base_print_template (
f_id VARCHAR(50) NOT NULL,
f_full_name VARCHAR(200) NOT NULL,
f_en_code VARCHAR(50) NOT NULL,
f_category VARCHAR(50) NOT NULL,
f_description VARCHAR(500),
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,
f_state INTEGER,
f_common_use INTEGER DEFAULT 0,
f_visible_type INTEGER,
f_icon VARCHAR(255),
f_icon_background VARCHAR(255),
f_system_id VARCHAR(50),
PRIMARY KEY (f_id, f_tenant_id)
);
CREATE TABLE base_print_version (
f_id VARCHAR(50) NOT NULL,
f_template_id VARCHAR(50) NOT NULL,
f_state INTEGER,
f_version INTEGER,
f_print_template TEXT,
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,
f_convert_config TEXT,
f_global_config TEXT,
f_query_list TEXT,
PRIMARY KEY (f_id, f_tenant_id)
);
+12 -2
View File
@@ -47,8 +47,10 @@ use ssw_platform::routes;
/// `base_business_category` / `base_message` / `base_notice`;日志与模板中心批次新增
/// `base_sys_log` / `base_common_words` / `base_bill_rule`;数据建模批次新增
/// `base_db_link` / `base_data_type` / `base_common_fields`;数据集批次新增
/// `base_data_set` / `base_data_set_relation`,故清单现在是 **33 张**。
const BASE_TABLES: [&str; 33] = [
/// `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_group",
"base_user",
"base_role",
@@ -87,6 +89,14 @@ const BASE_TABLES: [&str; 33] = [
// 🔴 数据集批次(2026-11-01):数据集设计器内容 + 打印/报表版本关联表。
"base_data_set",
"base_data_set_relation",
// 🔴 数据接口批次(2026-11-01):数据服务 + 接口认证 + 其关联表 + 打印模板/版本。
// `base_print_template` 在官方 DDL 里就叫这个名字(实体 `PrintDevEntity` 映射它)。
"base_data_interface",
"base_data_interface_oauth",
"base_data_interface_user",
"base_data_interface_log",
"base_print_template",
"base_print_version",
// 🔴 低代码两张表是**平台表**不是业务表:它们存的是「功能定义」,
// 任何业务模块都会用,属于引擎基础设施。
"base_visual_dev",
File diff suppressed because it is too large. Load diff
+170 -2
View File
@@ -492,6 +492,143 @@ pub fn build_router(state: AppState) -> axum::Router<AppState> {
"/api/system/Dataset/{id}/Actions/getRes",
post(face_b::dataset_get_res),
)
// ---- 数据接口(官方 `DataInterfaceController.java`,权限 `dataCenter.dataService`)----
// 🔴 `Actions/Preview` 复用 Dataset 的 SQL 护栏 + 绑定引擎(`dataset_run`)。
.route("/api/system/DataInterface", get(face_b::data_interface_list))
.route("/api/system/DataInterface", post(face_b::data_interface_create))
.route(
"/api/system/DataInterface/getList",
get(face_b::data_interface_get_list),
)
.route(
"/api/system/DataInterface/GetParam/{id}",
get(face_b::data_interface_get_param),
)
.route("/api/system/DataInterface/{id}", get(face_b::data_interface_info))
.route(
"/api/system/DataInterface/{id}",
put(face_b::data_interface_update),
)
.route(
"/api/system/DataInterface/{id}",
delete(face_b::data_interface_delete),
)
.route(
"/api/system/DataInterface/{id}/get",
get(face_b::data_interface_get),
)
.route(
"/api/system/DataInterface/{id}/save",
post(face_b::data_interface_save),
)
.route(
"/api/system/DataInterface/{id}/Actions/Copy",
post(face_b::data_interface_copy),
)
.route(
"/api/system/DataInterface/{id}/Actions/Export",
get(face_b::data_interface_export),
)
.route(
"/api/system/DataInterface/{id}/Actions/Preview",
post(face_b::data_interface_preview),
)
// ---- 接口认证(官方 `InterfaceOauthController.java`,权限 `integrationCenter.openApi`)----
.route(
"/api/system/InterfaceOauth",
get(face_b::interface_oauth_list),
)
.route(
"/api/system/InterfaceOauth",
post(face_b::interface_oauth_create),
)
.route(
"/api/system/InterfaceOauth/getAppId",
get(face_b::interface_oauth_get_app_id),
)
.route(
"/api/system/InterfaceOauth/getInterfaceList",
post(face_b::interface_oauth_get_interface_list),
)
.route(
"/api/system/InterfaceOauth/dataInterfaceLog/{id}",
get(face_b::interface_oauth_data_interface_log),
)
.route(
"/api/system/InterfaceOauth/interfaceSelector",
get(face_b::interface_oauth_interface_selector),
)
.route(
"/api/system/InterfaceOauth/SaveUserList",
post(face_b::interface_oauth_save_user_list),
)
.route(
"/api/system/InterfaceOauth/{id}",
get(face_b::interface_oauth_info),
)
.route(
"/api/system/InterfaceOauth/{id}",
put(face_b::interface_oauth_update),
)
.route(
"/api/system/InterfaceOauth/{id}",
delete(face_b::interface_oauth_delete),
)
// ---- 打印模板(官方 `PrintDevController.java`,权限 `onlineDev.printDev`)----
// 🔴 打印渲染引擎不在本仓 ⇒ `Actions/Export` / `BatchData` 返回业务失败 400。
.route("/api/system/printDev", get(face_b::print_dev_list))
.route("/api/system/printDev", post(face_b::print_dev_create))
.route(
"/api/system/printDev/Selector",
get(face_b::print_dev_selector),
)
.route(
"/api/system/printDev/WorkSelector",
get(face_b::print_dev_work_selector),
)
.route(
"/api/system/printDev/getListOptions",
post(face_b::print_dev_get_list_options),
)
.route("/api/system/printDev/{id}", get(face_b::print_dev_info))
.route("/api/system/printDev/{id}", put(face_b::print_dev_update))
.route(
"/api/system/printDev/{id}",
delete(face_b::print_dev_delete),
)
.route(
"/api/system/printDev/{id}/Actions/Copy",
post(face_b::print_dev_copy),
)
.route(
"/api/system/printDev/{id}/Actions/Export",
get(face_b::print_dev_export),
)
.route(
"/api/system/printDev/{id}/Actions/Preview",
get(face_b::print_dev_preview),
)
.route(
"/api/system/printDev/BatchData",
post(face_b::print_dev_batch_data),
)
.route("/api/system/printDev/Save", post(face_b::print_dev_save))
.route(
"/api/system/printDev/Info/{id}",
get(face_b::print_dev_version_info),
)
.route(
"/api/system/printDev/Version/{id}",
get(face_b::print_dev_version_list),
)
.route(
"/api/system/printDev/Info/{id}",
post(face_b::print_dev_version_copy),
)
.route(
"/api/system/printDev/Info/{id}",
delete(face_b::print_dev_version_delete),
)
// ---- 系统配置 + 第三方同步(官方 `SysConfigController` / `SynThirdInfoController`)----
.route("/api/system/SysConfig", get(face_b::sys_config_get))
.route("/api/system/SysConfig", put(face_b::sys_config_update))
@@ -1284,7 +1421,7 @@ mod tests {
// 🔴 表数**故意写死**:它同时校验「schema.sql 建了预期的表」与
// 「health 报的是真数」。加表要同步改这里 + main.rs 的 BASE_TABLES
// + crates/sspf-store 的两条 DDL 断言(共四处,漏一处就红)。
assert_eq!(body["tables"], 37);
assert_eq!(body["tables"], 43);
assert_eq!(body["version"], env!("CARGO_PKG_VERSION"));
}
@@ -1299,7 +1436,7 @@ mod tests {
let port = serve(new_state(db().await)).await;
// 🔴 按**路径**列(同一路径多个方法只算一条)—— 每条都用 PATCH 探 405。
const FACE_B_REGISTERED: [&str; 196] = [
const FACE_B_REGISTERED: [&str; 224] = [
"/api/permission/Users",
"/api/permission/Users/any-id",
"/api/permission/Users/BatchDelete",
@@ -1502,6 +1639,37 @@ mod tests {
"/api/system/Dataset/any-id/Actions/List",
"/api/system/Dataset/any-id/Actions/InfoByIds",
"/api/system/Dataset/any-id/Actions/getRes",
// ---- 数据接口(批次 9)----
"/api/system/DataInterface",
"/api/system/DataInterface/getList",
"/api/system/DataInterface/GetParam/any-id",
"/api/system/DataInterface/any-id",
"/api/system/DataInterface/any-id/get",
"/api/system/DataInterface/any-id/save",
"/api/system/DataInterface/any-id/Actions/Copy",
"/api/system/DataInterface/any-id/Actions/Export",
"/api/system/DataInterface/any-id/Actions/Preview",
// ---- 接口认证(批次 9)----
"/api/system/InterfaceOauth",
"/api/system/InterfaceOauth/getAppId",
"/api/system/InterfaceOauth/getInterfaceList",
"/api/system/InterfaceOauth/dataInterfaceLog/any-id",
"/api/system/InterfaceOauth/interfaceSelector",
"/api/system/InterfaceOauth/SaveUserList",
"/api/system/InterfaceOauth/any-id",
// ---- 打印模板(批次 9)----
"/api/system/printDev",
"/api/system/printDev/Selector",
"/api/system/printDev/WorkSelector",
"/api/system/printDev/getListOptions",
"/api/system/printDev/any-id",
"/api/system/printDev/any-id/Actions/Copy",
"/api/system/printDev/any-id/Actions/Export",
"/api/system/printDev/any-id/Actions/Preview",
"/api/system/printDev/BatchData",
"/api/system/printDev/Save",
"/api/system/printDev/Info/any-id",
"/api/system/printDev/Version/any-id",
];
for path in FACE_B_REGISTERED {
+3 -2
View File
@@ -380,8 +380,9 @@ async fn data_model_tables_info_and_fields() {
let total = tables["data"]["pagination"]["total"]
.as_i64()
.expect("必须有 total");
// schema.sql 现在是 37 张表;真有变化时这条会红,提醒同步(与 DDL 计数测试同口径)。
assert_eq!(total, 37, "表清单必须来自 information_schema: {tables}");
// schema.sql 现在是 43 张表(批次 9 新增 6 张:数据接口 + 接口认证 + 打印模板/版本);
// 真有变化时这条会红,提醒同步(与 DDL 计数测试同口径)。
assert_eq!(total, 43, "表清单必须来自 information_schema: {tables}");
let list = tables["data"]["list"].as_array().expect("必须有 list");
assert!(
list.iter().any(|r| r["table"] == "base_user"),
+700
View File
@@ -0,0 +1,700 @@
//! 批次 9(**数据接口 / 接口认证 / 打印模板**)集成测试。
//!
//! 🔴 **钉住的契约点**(每条都对应官方控制器 / 前端组件的一处硬要求):
//! ① 数据接口:名称/编码**双判重**(`名称已存在` / `编码已存在`);
//! 只改名称时要用库里原编码补齐再判重(否则会把自己判成重复)。
//! ② `GetParam` 是**裸数组**(不是 `ListVO`)—— 官方 `ActionResult<List<DynamicForm>>`。
//! ③ 数据接口 `Export` 恒 `400` + 人话(本仓没有文件服务)—— **不假装成功**。
//! ④ 接口认证:`appName` 判重;`getAppId` 返随机 UUID 串(官方行为)。
//! ⑤ 接口认证 `interfaceSelector` 是**两棵树**(数据集 / 数据服务)⇒ `ListVO`。
//! ⑥ 打印模板:新建 ⇒ 模板 + **首版本 v1(未发布)**;版本 `fullName` = `打印版本V{n}`。
//! ⑦ 打印模板 `Save` 的 `type=1` 即**发布** ⇒ 旧已发布版本归档(state=2)、新版本 state=1、
//! 模板 state=1;`type=0` 只存 JSON 不发布。
//! ⑧ 打印版本删除:**至少留一个**;已发布/已归档版本**不可删**。
//! ⑨ 打印 `Selector` 是**分类节点 + 模板叶子**的树,只含 `state=1`(已发布)的模板。
//! ⑩ 打印 `Export` / `BatchData` 恒 `400` + 人话(**本仓无渲染引擎**)—— 不假装成功。
//!
//! 🔴 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-batch9-it"))),
db: Arc::new(db.clone()),
sessions: Arc::new(SessionStore::default()),
}
}
/// 数据接口的 `dataConfigJson` 外壳(与数据集同一套 `DataConfigJsonModel`)。
fn cfg(sql: &str) -> String {
json!({ "sqlData": { "dbLinkId": "0", "sqlType": 1, "sql": sql, "configSql": [] } }).to_string()
}
async fn create_itf(port: u16, token: &str, name: &str, code: &str, body: Value) -> String {
let mut body = body;
body["fullName"] = json!(name);
body["enCode"] = json!(code);
let (_, resp) = call(port, "POST", "/api/system/DataInterface", token, Some(&body.to_string())).await;
assert_eq!(resp["code"], 200, "新建数据接口应成功:{resp}");
resp["data"]["id"].as_str().expect("必须返回 id").to_string()
}
/// 打印模板的 `dataConfigJson` 外壳(打印模板复用数据集同一套配置模型)。
async fn create_print(port: u16, token: &str, name: &str, code: &str, body: Value) -> String {
let mut body = body;
body["fullName"] = json!(name);
body["enCode"] = json!(code);
let (_, resp) = call(port, "POST", "/api/system/printDev", token, Some(&body.to_string())).await;
assert_eq!(resp["code"], 200, "新建打印模板应成功:{resp}");
resp["data"]["id"].as_str().expect("必须返回 id").to_string()
}
/// ① 数据接口:双判重;只改名称时不把自己判成重复;软删。
#[tokio::test]
async fn data_interface_dedup_and_soft_delete() {
let _guard = LOCK.lock().await;
let port = serve(new_state(db().await)).await;
let token = login(port).await;
let id = create_itf(
port,
&token,
"批次九-A",
"b9a",
json!({ "category": "c9", "type": 1, "enabledMark": 1 }),
)
.await;
// 列表是 PageListVO
let (_, list) = call(port, "GET", "/api/system/DataInterface?keyword=b9a", &token, None).await;
assert_eq!(list["code"], 200);
assert_eq!(list["data"]["pagination"]["total"], 1, "应只命中一条:{list}");
assert_eq!(list["data"]["list"][0]["fullName"], "批次九-A");
assert!(
list["data"]["list"][0]["creatorTime"].as_i64().unwrap_or(0) > 1_700_000_000_000,
"creatorTime 必须是毫秒"
);
// 双判重
let (_, dup_name) = call(
port,
"POST",
"/api/system/DataInterface",
&token,
Some(&json!({ "fullName": "批次九-A", "enCode": "other_code" }).to_string()),
)
.await;
assert_eq!(dup_name["msg"], "名称已存在", "名称判重:{dup_name}");
let (_, dup_code) = call(
port,
"POST",
"/api/system/DataInterface",
&token,
Some(&json!({ "fullName": "别的名字", "enCode": "b9a" }).to_string()),
)
.await;
assert_eq!(dup_code["msg"], "编码已存在", "编码判重:{dup_code}");
// 🔴 只改名称时不该把自己判成重复(`enCode` 没传 ⇒ 用库里的原值补齐)
let (_, upd) = call(
port,
"PUT",
&format!("/api/system/DataInterface/{id}"),
&token,
Some(&json!({ "fullName": "批次九-A2" }).to_string()),
)
.await;
assert_eq!(upd["code"], 200, "只改名称应成功:{upd}");
let (_, info) = call(port, "GET", &format!("/api/system/DataInterface/{id}"), &token, None).await;
assert_eq!(info["data"]["fullName"], "批次九-A2");
assert_eq!(info["data"]["enCode"], "b9a", "只改名称不该动编码");
// 软删
let (_, del) = call(port, "DELETE", &format!("/api/system/DataInterface/{id}"), &token, None).await;
assert_eq!(del["code"], 200);
let (_, gone) = call(port, "GET", &format!("/api/system/DataInterface/{id}"), &token, None).await;
assert_eq!(gone["code"], 400, "软删后详情应报「数据不存在」");
}
/// ② `GetParam` 是裸数组;③ `Export` 恒 400。
#[tokio::test]
async fn data_interface_get_param_is_bare_array_and_export_fails() {
let _guard = LOCK.lock().await;
let port = serve(new_state(db().await)).await;
let token = login(port).await;
let params = json!([
{ "field": "kw", "fieldName": "关键词", "dataType": "varchar", "required": 0 },
]);
let id = create_itf(
port,
&token,
"批次九-B",
"b9b",
json!({
"category": "c9", "type": 1, "enabledMark": 1, "hasPage": 1,
"dataConfigJson": cfg("select 1 as one"),
"parameterJson": params.to_string(),
}),
)
.await;
// 🔴 裸数组(不是 `{list:[…]}`)
let (_, param) = call(port, "GET", &format!("/api/system/DataInterface/GetParam/{id}"), &token, None).await;
assert_eq!(param["code"], 200);
assert!(param["data"].is_array(), "GetParam 必须返回裸数组:{param}");
assert_eq!(param["data"].as_array().unwrap().len(), 1);
assert_eq!(param["data"][0]["field"], "kw");
// ③ 导出恒失败(不假装成功)
let (_, export) = call(port, "GET", &format!("/api/system/DataInterface/{id}/Actions/Export"), &token, None).await;
assert_eq!(export["code"], 400, "导出必须恒失败:{export}");
assert!(
export["msg"].as_str().unwrap().contains("暂不支持"),
"导出要说人话:{export}"
);
}
/// 数据接口 `Preview` 真执行 SQL(复用数据集的执行面)。
#[tokio::test]
async fn data_interface_preview_executes_sql() {
let _guard = LOCK.lock().await;
let port = serve(new_state(db().await)).await;
let token = login(port).await;
let id = create_itf(
port,
&token,
"批次九-C",
"b9c",
json!({
"category": "c9", "type": 1, "enabledMark": 1, "hasPage": 1,
"dataConfigJson": cfg("select f_en_code as code from base_data_type"),
}),
)
.await;
let (_, res) = call(
port,
"POST",
&format!("/api/system/DataInterface/{id}/Actions/Preview"),
&token,
Some("{}"),
)
.await;
assert_eq!(res["code"], 200, "接口取数应成功:{res}");
assert_eq!(res["data"]["pagination"]["total"], 7, "base_data_type 官方种子 7 行");
// 禁用后拒绝
call(
port,
"PUT",
&format!("/api/system/DataInterface/{id}"),
&token,
Some(&json!({ "enabledMark": 0 }).to_string()),
)
.await;
let (_, disabled) = call(
port,
"POST",
&format!("/api/system/DataInterface/{id}/Actions/Preview"),
&token,
Some("{}"),
)
.await;
assert_eq!(disabled["code"], 400, "禁用后必须拒绝执行:{disabled}");
}
/// ④ 接口认证:appName 判重 + `getAppId` 返 UUID 串;⑤ `interfaceSelector` 是两棵树。
#[tokio::test]
async fn interface_oauth_dedup_app_id_and_selector() {
let _guard = LOCK.lock().await;
let port = serve(new_state(db().await)).await;
let token = login(port).await;
// 新建
let (_, created) = call(
port,
"POST",
"/api/system/InterfaceOauth",
&token,
Some(
&json!({
"appName": "批次九-OAuth",
"appId": "b9oauth",
"verifySignature": 1,
"whiteList": "127.0.0.1",
"enabledMark": 1,
})
.to_string(),
),
)
.await;
assert_eq!(created["code"], 200, "新建接口认证应成功:{created}");
let oid = created["data"]["id"].as_str().expect("必须返回 id").to_string();
// 判重
let (_, dup) = call(
port,
"POST",
"/api/system/InterfaceOauth",
&token,
Some(&json!({ "appName": "批次九-OAuth", "appId": "other" }).to_string()),
)
.await;
assert_eq!(dup["msg"], "应用名称已存在", "appName 应判重:{dup}");
// 详情 + 列表
let (_, info) = call(port, "GET", &format!("/api/system/InterfaceOauth/{oid}"), &token, None).await;
assert_eq!(info["data"]["appName"], "批次九-OAuth");
assert_eq!(info["data"]["appId"], "b9oauth");
let (_, list) = call(port, "GET", "/api/system/InterfaceOauth?keyword=b9oauth", &token, None).await;
assert_eq!(list["data"]["pagination"]["total"], 1, "应只命中一条:{list}");
// `getAppId` 返 UUID 串(官方行为)
let (_, app_id) = call(port, "GET", "/api/system/InterfaceOauth/getAppId", &token, None).await;
assert_eq!(app_id["code"], 200);
let s = app_id["data"].as_str().expect("getAppId 必须返字符串");
assert_eq!(s.len(), 36, "应是 UUID 串:{app_id}");
// ⑤ `interfaceSelector` 是两棵树(ListVO)
let (_, sel) = call(port, "GET", "/api/system/InterfaceOauth/interfaceSelector", &token, None).await;
assert_eq!(sel["code"], 200);
let roots = sel["data"]["list"].as_array().expect("必须是 ListVO 的 list");
assert_eq!(roots.len(), 2, "应是「数据集」+「数据服务」两棵树:{sel}");
assert_eq!(roots[0]["fullName"], "数据集");
assert_eq!(roots[1]["fullName"], "数据服务");
// 调用日志:按 appId 过滤(本仓无日志 ⇒ 空分页)
let (_, log) = call(
port,
"GET",
&format!("/api/system/InterfaceOauth/dataInterfaceLog/{oid}"),
&token,
None,
)
.await;
assert_eq!(log["code"], 200);
assert_eq!(log["data"]["pagination"]["total"], 0, "本仓无调用日志:{log}");
}
/// ⑥ 打印模板:新建 ⇒ 模板 + 首版本 v1;版本 `fullName` = `打印版本V{n}`。
#[tokio::test]
async fn print_dev_create_makes_first_version() {
let _guard = LOCK.lock().await;
let port = serve(new_state(db().await)).await;
let token = login(port).await;
let id = create_print(
port,
&token,
"批次九-P1",
"b9p1",
json!({ "category": "c9", "commonUse": 1, "visibleType": 1 }),
)
.await;
// 版本列表 ⇒ 裸数组,fullName = 打印版本V1
let (_, versions) = call(port, "GET", &format!("/api/system/printDev/Version/{id}"), &token, None).await;
assert_eq!(versions["code"], 200);
assert!(versions["data"].is_array(), "版本列表必须返回裸数组:{versions}");
assert_eq!(versions["data"].as_array().unwrap().len(), 1, "新建后应有首版本:{versions}");
assert_eq!(versions["data"][0]["fullName"], "打印版本V1");
assert_eq!(versions["data"][0]["version"], 1);
assert_eq!(versions["data"][0]["state"], 0, "首版本未发布:{versions}");
// 详情
let (_, info) = call(port, "GET", &format!("/api/system/printDev/{id}"), &token, None).await;
assert_eq!(info["data"]["fullName"], "批次九-P1");
assert_eq!(info["data"]["enCode"], "b9p1");
assert!(info["data"]["dataSetList"].is_array(), "dataSetList 应为空数组:{info}");
assert!(info["data"].get("fieldList").is_some(), "fieldList 键必须在:{info}");
// 判重
let (_, dup) = call(
port,
"POST",
"/api/system/printDev",
&token,
Some(&json!({ "fullName": "批次九-P1", "enCode": "other", "category": "c9" }).to_string()),
)
.await;
assert_eq!(dup["code"], 400, "打印模板应判重:{dup}");
assert!(dup["msg"].as_str().unwrap().contains("已存在"), "要说清是重复:{dup}");
}
/// ⑦ `Save` 的 `type=1` 即发布;`type=0` 只存 JSON。
#[tokio::test]
async fn print_dev_save_publish_archives_old_version() {
let _guard = LOCK.lock().await;
let port = serve(new_state(db().await)).await;
let token = login(port).await;
let id = create_print(
port,
&token,
"批次九-P2",
"b9p2",
json!({ "category": "c9" }),
)
.await;
// 先取首版本 id
let (_, versions) = call(port, "GET", &format!("/api/system/printDev/Version/{id}"), &token, None).await;
let v1 = versions["data"][0]["id"].as_str().expect("首版本 id").to_string();
// `type=0` ⇒ 只存 JSON,不发布(版本 state 仍 0)
let (_, saved) = call(
port,
"POST",
"/api/system/printDev/Save",
&token,
Some(
&json!({
"id": id,
"versionId": v1,
"type": 0,
"printTemplate": { "a": 1 },
"convertConfig": { "b": 2 },
})
.to_string(),
),
)
.await;
assert_eq!(saved["code"], 200, "保存应成功:{saved}");
let (_, after0) = call(port, "GET", &format!("/api/system/printDev/Version/{id}"), &token, None).await;
assert_eq!(after0["data"].as_array().unwrap().len(), 1, "type=0 不该新增版本:{after0}");
assert_eq!(after0["data"][0]["state"], 0, "type=0 不该发布:{after0}");
// 版本详情能读到刚存的 JSON
let (_, vinfo) = call(port, "GET", &format!("/api/system/printDev/Info/{v1}"), &token, None).await;
assert_eq!(vinfo["code"], 200, "版本详情应成功:{vinfo}");
assert_eq!(vinfo["data"]["fullName"], "批次九-P2");
// `type=1` ⇒ 发布:版本 state=1
let (_, released) = call(
port,
"POST",
"/api/system/printDev/Save",
&token,
Some(&json!({ "id": id, "versionId": v1, "type": 1, "printTemplate": { "a": 1 } }).to_string()),
)
.await;
assert_eq!(released["code"], 200, "发布应成功:{released}");
let (_, after1) = call(port, "GET", &format!("/api/system/printDev/Version/{id}"), &token, None).await;
assert_eq!(after1["data"][0]["state"], 1, "发布后版本 state=1:{after1}");
// 🔴 再发布一个新版本 ⇒ **旧的已发布版本被归档(state=2)**,新版本 state=1
let (_, copied) = call(port, "POST", &format!("/api/system/printDev/Info/{v1}"), &token, Some("{}")).await;
assert_eq!(copied["code"], 200, "版本复制应成功:{copied}");
let v2 = copied["data"]["id"].as_str().expect("新版本 id").to_string();
let (_, released2) = call(
port,
"POST",
"/api/system/printDev/Save",
&token,
Some(&json!({ "id": id, "versionId": v2, "type": 1 }).to_string()),
)
.await;
assert_eq!(released2["code"], 200, "发布新版本应成功:{released2}");
let (_, after2) = call(port, "GET", &format!("/api/system/printDev/Version/{id}"), &token, None).await;
let list = after2["data"].as_array().expect("版本列表");
let old = list.iter().find(|v| v["id"] == v1).expect("旧版本");
let new = list.iter().find(|v| v["id"] == v2).expect("新版本");
assert_eq!(old["state"], 2, "旧的已发布版本应被归档(state=2):{after2}");
assert_eq!(new["state"], 1, "新发布版本 state=1:{after2}");
}
/// ⑧ 版本删除:至少留一个;已发布 / 已归档版本不可删(**官方判据顺序**)。
#[tokio::test]
async fn print_dev_version_delete_guards() {
let _guard = LOCK.lock().await;
let port = serve(new_state(db().await)).await;
let token = login(port).await;
let id = create_print(
port,
&token,
"批次九-P3",
"b9p3",
json!({ "category": "c9" }),
)
.await;
let (_, versions) = call(port, "GET", &format!("/api/system/printDev/Version/{id}"), &token, None).await;
let v1 = versions["data"][0]["id"].as_str().expect("首版本 id").to_string();
// 只剩一个 ⇒ 不许删(官方 `list.size() == 1` ⇒ SYS043)
let (_, last) = call(port, "DELETE", &format!("/api/system/printDev/Info/{v1}"), &token, None).await;
assert_eq!(last["code"], 400, "至少留一个版本:{last}");
assert_eq!(last["msg"], "至少保留一个版本");
// 复制出第二个版本 ⇒ 可删
let (_, copied) = call(port, "POST", &format!("/api/system/printDev/Info/{v1}"), &token, Some("{}")).await;
assert_eq!(copied["code"], 200, "版本复制应成功:{copied}");
let v2 = copied["data"]["id"].as_str().expect("新版本 id").to_string();
let (_, versions2) = call(port, "GET", &format!("/api/system/printDev/Version/{id}"), &token, None).await;
assert_eq!(versions2["data"].as_array().unwrap().len(), 2, "应有 2 个版本:{versions2}");
assert_eq!(versions2["data"][1]["fullName"], "打印版本V2");
// 未发布版本可删
let (_, del) = call(port, "DELETE", &format!("/api/system/printDev/Info/{v2}"), &token, None).await;
assert_eq!(del["code"], 200, "未发布版本可删:{del}");
// 🔴 复制回第二个版本(否则「至少留一个」会先命中,测不到已发布那条)
let (_, copied2) = call(port, "POST", &format!("/api/system/printDev/Info/{v1}"), &token, Some("{}")).await;
assert_eq!(copied2["code"], 200, "版本复制应成功:{copied2}");
let v3 = copied2["data"]["id"].as_str().expect("新版本 id").to_string();
// 发布 v1 ⇒ state=1 ⇒ 不可删
let (_, released) = call(
port,
"POST",
"/api/system/printDev/Save",
&token,
Some(&json!({ "id": id, "versionId": v1, "type": 1 }).to_string()),
)
.await;
assert_eq!(released["code"], 200);
let (_, del_published) = call(port, "DELETE", &format!("/api/system/printDev/Info/{v1}"), &token, None).await;
assert_eq!(del_published["code"], 400, "已发布版本不可删:{del_published}");
assert_eq!(del_published["msg"], "已发布版本不可删除");
// 再发布 v3 ⇒ v1 被归档(state=2)⇒ 也不可删
let (_, released2) = call(
port,
"POST",
"/api/system/printDev/Save",
&token,
Some(&json!({ "id": id, "versionId": v3, "type": 1 }).to_string()),
)
.await;
assert_eq!(released2["code"], 200);
let (_, del_archived) = call(port, "DELETE", &format!("/api/system/printDev/Info/{v1}"), &token, None).await;
assert_eq!(del_archived["code"], 400, "已归档版本不可删:{del_archived}");
assert_eq!(del_archived["msg"], "已归档版本不可删除");
}
/// ⑨ `Selector` 是分类节点 + 模板叶子的树,只含已发布模板;⑩ `Export`/`BatchData` 恒 400。
#[tokio::test]
async fn print_dev_selector_tree_and_export_stubs() {
let _guard = LOCK.lock().await;
let port = serve(new_state(db().await)).await;
let token = login(port).await;
// 未发布(state=0)⇒ 不该出现在 Selector 里
let draft = create_print(
port,
&token,
"批次九-P4-草稿",
"b9p4",
json!({ "category": "c9" }),
)
.await;
let (_, sel_draft) = call(port, "GET", "/api/system/printDev/Selector", &token, None).await;
assert_eq!(sel_draft["code"], 200);
let draft_found = sel_draft["data"]["list"]
.as_array()
.unwrap()
.iter()
.any(|cat| {
cat["children"]
.as_array()
.map(|cs| cs.iter().any(|c| c["enCode"] == "b9p4"))
.unwrap_or(false)
});
assert!(!draft_found, "未发布模板不该出现在 Selector:{sel_draft}");
// 发布后 ⇒ 出现在 Selector 的分类节点里
let (_, versions) = call(port, "GET", &format!("/api/system/printDev/Version/{draft}"), &token, None).await;
let v1 = versions["data"][0]["id"].as_str().expect("首版本 id").to_string();
let (_, released) = call(
port,
"POST",
"/api/system/printDev/Save",
&token,
Some(&json!({ "id": draft, "versionId": v1, "type": 1 }).to_string()),
)
.await;
assert_eq!(released["code"], 200, "发布应成功:{released}");
let (_, sel) = call(port, "GET", "/api/system/printDev/Selector", &token, None).await;
let roots = sel["data"]["list"].as_array().expect("Selector 必须返回 list");
let found = roots.iter().any(|cat| {
cat["children"]
.as_array()
.map(|cs| cs.iter().any(|c| c["enCode"] == "b9p4"))
.unwrap_or(false)
});
assert!(found, "已发布模板应出现在 Selector:{sel}");
// 叶子是 `PrintDevTreeModel` 形状
let leaf = roots
.iter()
.flat_map(|cat| cat["children"].as_array().cloned().unwrap_or_default())
.find(|c| c["enCode"] == "b9p4")
.expect("叶子节点");
assert_eq!(leaf["type"], 1, "叶子 type=1:{leaf}");
assert_eq!(leaf["hasChildren"], false, "叶子 hasChildren=false:{leaf}");
// `getListOptions`(裸数组 {id,fullName,enCode})
let (_, opts) = call(
port,
"POST",
"/api/system/printDev/getListOptions",
&token,
Some(&json!({ "ids": [draft] }).to_string()),
)
.await;
assert_eq!(opts["code"], 200);
assert!(opts["data"].is_array(), "getListOptions 必须返回裸数组:{opts}");
assert_eq!(opts["data"][0]["enCode"], "b9p4");
assert_eq!(opts["data"][0]["fullName"], "批次九-P4-草稿");
// ⑩ 导出 / 批量数据 恒 400(本仓无渲染引擎)
let (_, export) = call(port, "GET", &format!("/api/system/printDev/{draft}/Actions/Export"), &token, None).await;
assert_eq!(export["code"], 400, "导出必须恒失败:{export}");
assert!(
export["msg"].as_str().unwrap().contains("不支持"),
"导出要说人话:{export}"
);
let (_, batch) = call(port, "POST", "/api/system/printDev/BatchData", &token, Some("{}")).await;
assert_eq!(batch["code"], 400, "批量打印数据必须恒失败:{batch}");
assert!(
batch["msg"].as_str().unwrap().contains("不支持"),
"批量数据要说人话:{batch}"
);
}
/// 打印模板复制:副本前缀 + 复制所有版本。
#[tokio::test]
async fn print_dev_copy_duplicates_template_and_versions() {
let _guard = LOCK.lock().await;
let port = serve(new_state(db().await)).await;
let token = login(port).await;
let id = create_print(
port,
&token,
"批次九-P5",
"b9p5",
json!({ "category": "c9" }),
)
.await;
let (_, copied) = call(port, "POST", &format!("/api/system/printDev/{id}/Actions/Copy"), &token, Some("{}")).await;
assert_eq!(copied["code"], 200, "复制应成功:{copied}");
// 副本:以「副本」为名、编码带后缀,且版本也复制了一份
let (_, list) = call(port, "GET", "/api/system/printDev?keyword=b9p5", &token, None).await;
assert_eq!(list["data"]["pagination"]["total"], 2, "应有原件 + 副本:{list}");
let copy_row = list["data"]["list"]
.as_array()
.unwrap()
.iter()
.find(|r| r["fullName"].as_str().unwrap().contains("副本"))
.expect("应找到副本");
let copy_id = copy_row["id"].as_str().expect("副本 id").to_string();
assert!(
copy_row["fullName"].as_str().unwrap().starts_with("批次九-P5副本"),
"副本名应带「副本」前缀:{copy_row}"
);
assert_ne!(copy_row["enCode"], "b9p5", "副本编码必须换掉:{copy_row}");
let (_, cver) = call(port, "GET", &format!("/api/system/printDev/Version/{copy_id}"), &token, None).await;
assert_eq!(cver["data"].as_array().unwrap().len(), 1, "版本也要复制:{cver}");
}