feat(face-b): 数据中心五族 + 数据同步(面 B 批次 14,+29 端点)
基准数据类型/控件映射/数据库/字段类型映射/常用字段的增删改查 + getKeyList + 数据同步四条 + 接口变量下拉;新表 base_data_type_mapping / base_data_base / base_data_type_relation / base_data_interface_variate(官方 DDL 逐字)⇒ tables 57。 影响:dataCenter 五个页面能真跑;数据同步四条明确拒绝(本仓内嵌单库,无驱动层), 不再假装成功。回归测试 tests/batch14_it.rs 7 条。 五族形状一致 ⇒ 抽了声明式 Flat(一份声明 + 五个薄壳),不再逐族手抄。 过程中修掉扫描器两个同源缺陷:check-contract-scan / fe-gap 都只认每条 .route() 的**第一个**方法 ⇒ 链式 get().post() 的后半段静默消失(契约写 implemented、 代码被判「没有这条路由」)。现在按 .route( 切块取全部方法。 写路径的两处语义也一并钉住:判重是「每列各自唯一」不是「联合唯一」; 列表把 typeId 覆盖成名称而详情必须返回真 id。
This commit is contained in:
1 parent
3bf7f91461
commit
e961904252
9 files changed
+2146
-92
No files matched your search
@@ -50,7 +50,7 @@ pub const SCHEMA_SQL: &str = include_str!("../../../src/backend/db/schema.sql");
|
||||
/// (闸门查「孤儿 DDL」会红 ⇒ 两处都改才算登记完成)⇒ 数量写死是**有意的护栏**;
|
||||
/// - 业务表 = **业务包**的责任 ⇒ 住 `packs/<app>/schema/*.sql`
|
||||
/// ⇒ 加包**不该**改内核 ⇒ 数量写死是**错误的耦合**。
|
||||
pub const BASE_TABLE_COUNT: usize = 50;
|
||||
pub const BASE_TABLE_COUNT: usize = 54;
|
||||
|
||||
/// 🔴 **面 A 内嵌业务表**(留在内核 `schema.sql` 里的那几张)。
|
||||
///
|
||||
|
||||
+60
-1
@@ -1528,6 +1528,36 @@ B GET /api/system/Variate/sysfunccategory 登录 platform
|
||||
B GET /api/system/Variate/{id} 登录 platform
|
||||
B PUT /api/system/Variate/{id} 登录 platform
|
||||
B DELETE /api/system/Variate/{id} 登录 platform
|
||||
# ---- 数据中心(批次 14):基准类型 / 控件映射 / 数据库 / 字段类型映射 / 常用字段 / 数据同步 ----
|
||||
B GET /api/system/BasicDataType/{id} dataCenter.basicDataType platform
|
||||
B POST /api/system/BasicDataType dataCenter.basicDataType platform
|
||||
B PUT /api/system/BasicDataType/{id} dataCenter.basicDataType platform
|
||||
B DELETE /api/system/BasicDataType/{id} dataCenter.basicDataType platform
|
||||
B GET /api/system/DataTypeMapping dataCenter.dataTypeMapping platform
|
||||
B GET /api/system/DataTypeMapping/getKeyList dataCenter.dataTypeMapping|onlineDev.formDesign platform
|
||||
B GET /api/system/DataTypeMapping/{id} dataCenter.dataTypeMapping platform
|
||||
B POST /api/system/DataTypeMapping dataCenter.dataTypeMapping platform
|
||||
B PUT /api/system/DataTypeMapping/{id} dataCenter.dataTypeMapping platform
|
||||
B DELETE /api/system/DataTypeMapping/{id} dataCenter.dataTypeMapping platform
|
||||
B GET /api/system/DataBase 登录 platform
|
||||
B GET /api/system/DataBase/{id} dataCenter.database platform
|
||||
B POST /api/system/DataBase dataCenter.database platform
|
||||
B PUT /api/system/DataBase/{id} dataCenter.database platform
|
||||
B DELETE /api/system/DataBase/{id} dataCenter.database platform
|
||||
B GET /api/system/DataTypeRelation dataCenter.database platform
|
||||
B GET /api/system/DataTypeRelation/{id} dataCenter.database platform
|
||||
B POST /api/system/DataTypeRelation dataCenter.database platform
|
||||
B PUT /api/system/DataTypeRelation/{id} dataCenter.database platform
|
||||
B DELETE /api/system/DataTypeRelation/{id} dataCenter.database platform
|
||||
B GET /api/system/CommonFields/{id} dataCenter.basicField platform
|
||||
B POST /api/system/CommonFields dataCenter.basicField platform
|
||||
B PUT /api/system/CommonFields/{id} dataCenter.basicField platform
|
||||
B DELETE /api/system/CommonFields/{id} dataCenter.basicField platform
|
||||
B POST /api/system/DataSync systemData.dataSync platform
|
||||
B POST /api/system/DataSync/Actions/checkDbLink systemData.dataSync platform
|
||||
B POST /api/system/DataSync/Actions/Execute systemData.dataSync platform
|
||||
B POST /api/system/DataSync/Actions/batchExecute systemData.dataSync platform
|
||||
B GET /api/system/DataInterfaceVariate/Selector dataCenter.dataset|dataCenter.dataService platform
|
||||
|
||||
<!-- PACK:BEGIN -->
|
||||
# 🔴 以下由 `scripts/pack-sync.py` 从 `packs/*` 生成 —— **不许手改**
|
||||
@@ -1552,7 +1582,7 @@ B DELETE /api/asset/DataResource/{id} permission.asset.dataResource asset
|
||||
[FACE]
|
||||
# face 条数 说明
|
||||
A 28 面 A 专属(+ 2 条共用 ⇒ 面 A 合计 30 条)
|
||||
B 363 面 B 专属(官方 JNPF 形状;批次 13 新增 Area 7 + Variate 7)
|
||||
B 392 面 B 专属(官方 JNPF 形状;批次 13 新增 Area 7 + Variate 7;批次 14 新增数据中心 29)
|
||||
AB 2 两面共用(CurrentUser / Authority Data —— 按判别头分流)
|
||||
|
||||
[OFFICIAL]
|
||||
@@ -1964,6 +1994,35 @@ PUT /api/system/Variate/{id} implemented CommonVariateController.java:94 面 B
|
||||
DELETE /api/system/Variate/{id} implemented CommonVariateController.java:105 面 B 已落地:软删,幂等
|
||||
GET /api/system/Variate/selector implemented CommonVariateController.java:159 面 B 已落地:全量 ListVO(不分页);keyword 大小写不敏感(upper LIKE,同官方 toUpperCase.contains)
|
||||
GET /api/system/Variate/sysfunccategory implemented CommonVariateController.java:134 面 B 已落地:11 个固定分类(官方 FunctionCategory 枚举逐条抄)⇒ 不依赖表达式引擎
|
||||
GET /api/system/BasicDataType/{id} implemented DataTypeController.java:118 面 B 已落地:DataTypeVo 的 5 个字段
|
||||
POST /api/system/BasicDataType implemented DataTypeController.java:58 面 B 已落地:enCode 与 fullName **双判重**;新建恒为自定义(type=2),内置不可造
|
||||
PUT /api/system/BasicDataType/{id} implemented DataTypeController.java:79 面 B 已落地:只 SET 出现的键;**type 不进白名单**(否则可把自定义改成内置逃过删除保护)
|
||||
DELETE /api/system/BasicDataType/{id} implemented DataTypeController.java:99 面 B 已落地:内置(type=1)拒绝;被控件映射/字段类型映射/常用字段引用 ⇒ 拒绝
|
||||
GET /api/system/DataTypeMapping implemented DataTypeMappingController.java:55 面 B 已落地:ListVO 不分页(前端 `pagination:false`);`typeId` 被**覆盖成名称**(官方 :60-68)
|
||||
GET /api/system/DataTypeMapping/getKeyList implemented DataTypeMappingController.java:127 面 B 已落地:`[{dataType, jnpfKeyList}]`;权限是 **OR**(dataTypeMapping / formDesign)
|
||||
GET /api/system/DataTypeMapping/{id} implemented DataTypeMappingController.java:115 面 B 已落地:这里返回**真 typeId**(列表返回的是名称)⇒ 编辑表单靠这条
|
||||
POST /api/system/DataTypeMapping implemented DataTypeMappingController.java:76 面 B 已落地:白名单 jnpfKey/typeId/sortCode
|
||||
PUT /api/system/DataTypeMapping/{id} implemented DataTypeMappingController.java:90 面 B 已落地:只 SET 出现的键
|
||||
DELETE /api/system/DataTypeMapping/{id} implemented DataTypeMappingController.java:103 面 B 已落地:软删
|
||||
GET /api/system/DataBase implemented DataBaseController.java:44 面 B 已落地:ListVO;**登录即可**(官方 list 无权限注解,只有增删改有)
|
||||
GET /api/system/DataBase/{id} implemented DataBaseController.java:101 面 B 已落地:DataBaseVo 的 7 个字段
|
||||
POST /api/system/DataBase implemented DataBaseController.java:56 面 B 已落地:按 `dbType` **单列判重**(官方 existByDbType)
|
||||
PUT /api/system/DataBase/{id} implemented DataBaseController.java:73 面 B 已落地:只 SET 出现的键;dbType 判重排除自己
|
||||
DELETE /api/system/DataBase/{id} implemented DataBaseController.java:89 面 B 已落地:软删
|
||||
GET /api/system/DataTypeRelation implemented DataTypeRelationController.java:53 面 B 已落地:PageListVO 分页;支持 baseId 过滤;`typeId` 同样覆盖成名称
|
||||
GET /api/system/DataTypeRelation/{id} implemented DataTypeRelationController.java:120 面 B 已落地:真 typeId + 6 个长度/精度上限
|
||||
POST /api/system/DataTypeRelation implemented DataTypeRelationController.java:73 面 B 已落地:判重是**二元组 enCode+baseId**(同 enCode 在不同库下可各一条)
|
||||
PUT /api/system/DataTypeRelation/{id} implemented DataTypeRelationController.java:91 面 B 已落地:只 SET 出现的键
|
||||
DELETE /api/system/DataTypeRelation/{id} implemented DataTypeRelationController.java:108 面 B 已落地:软删
|
||||
GET /api/system/CommonFields/{id} implemented ComFieldsController.java:86 面 B 已落地:常用字段详情(含 dataTypeName)
|
||||
POST /api/system/CommonFields implemented ComFieldsController.java:102 面 B 已落地:**先挡 SQL/Java 保留字**再判重(列名要拿去建表);判重是 field+category
|
||||
PUT /api/system/CommonFields/{id} implemented ComFieldsController.java:129 面 B 已落地:同样挡保留字;只 SET 出现的键
|
||||
DELETE /api/system/CommonFields/{id} implemented ComFieldsController.java:158 面 B 已落地:软删
|
||||
POST /api/system/DataSync partial DbSyncController.java:166 **本仓无跨库能力**:官方走 JDBC 真连两个库;本仓是进程内嵌 PG(pglite/WASM,无驱动层)⇒ 四条 DataSync 一律返回明确业务失败(不假装成功,同 `DataSource/Actions/Test`)
|
||||
POST /api/system/DataSync/Actions/checkDbLink partial DbSyncController.java:118 同上:能力不存在,端点存在且明确拒绝
|
||||
POST /api/system/DataSync/Actions/Execute partial DbSyncController.java:191 同上:能力不存在,端点存在且明确拒绝
|
||||
POST /api/system/DataSync/Actions/batchExecute partial DbSyncController.java:212 同上:能力不存在,端点存在且明确拒绝
|
||||
GET /api/system/DataInterfaceVariate/Selector implemented DataInterfaceVariateController.java:107 面 B 已落地:两级树(数据集 type=0 → 变量 type=1);变量 fullName = `数据集enCode.变量名`;只出启用的数据集;权限 OR(dataset / dataService)
|
||||
|
||||
[RULER]
|
||||
# name 期望断言数(尺子**自己**断言的条数;跑出来的条数对不上 ⇒ 失败)
|
||||
|
||||
@@ -211,6 +211,26 @@ def _find_fn_body_uncached(masked, fname):
|
||||
return brace_span(masked, i)
|
||||
|
||||
|
||||
def paren_span(masked, start):
|
||||
"""从 `start`(`(` 的位置)开始做括号配对 ⇒ 返回 `)` 的下标(失败返回末位)。
|
||||
|
||||
🔴 在 `masked` 上跑:字符串字面量已被挖空 ⇒ 参数里的 `(` / `)` 不会干扰配对。
|
||||
"""
|
||||
depth = 0
|
||||
i = start
|
||||
n = len(masked)
|
||||
while i < n:
|
||||
c = masked[i]
|
||||
if c == "(":
|
||||
depth += 1
|
||||
elif c == ")":
|
||||
depth -= 1
|
||||
if depth == 0:
|
||||
return i
|
||||
i += 1
|
||||
return n - 1
|
||||
|
||||
|
||||
def scan_routes(path, owner):
|
||||
"""扫一个源文件里的 `.route(...)` ⇒ [{path, method, handler_mod, handler_fn, closure}]。"""
|
||||
orig = read(path)
|
||||
@@ -237,34 +257,52 @@ def scan_routes(path, owner):
|
||||
p += 1
|
||||
while p < len(orig) and orig[p] in " \t\r\n":
|
||||
p += 1
|
||||
mm = re.match(r"(get|post|put|delete)\s*\(", orig[p:])
|
||||
if not mm:
|
||||
continue
|
||||
if masked[p:p + len(mm.group(1))] != mm.group(1):
|
||||
continue # 方法名其实落在字符串里(误报)
|
||||
method = mm.group(1).upper()
|
||||
after = p + mm.end()
|
||||
if route.startswith(TEST_PATH_PREFIX):
|
||||
continue # 仅测试构建存在的端点 ⇒ 不在契约端点表里
|
||||
rest = orig[after:after + 240]
|
||||
hm = HANDLER_RE.match(rest)
|
||||
mod, fn, closure = None, None, True
|
||||
if hm and hm.group(2):
|
||||
mod, fn = hm.group(1), hm.group(2)
|
||||
closure = False
|
||||
out.append({
|
||||
"path": route,
|
||||
"method": method,
|
||||
"mod": mod,
|
||||
"fn": fn,
|
||||
"closure": closure,
|
||||
"owner": owner,
|
||||
# 🔴 `source` 区分「路由住在哪」:平台层 / 业务模块(面 A)/ 业务包(面 B)。
|
||||
# owner 会撞(包与模块同 app_code)⇒ 守卫推导与台账范围**必须**看这个。
|
||||
"source": "platform" if owner == "platform" else "module",
|
||||
"const": None,
|
||||
"file": path,
|
||||
})
|
||||
# 🔴 一条 `.route(path, …)` 里可能有**多个**方法:`.route(p, get(a).post(b))`
|
||||
# —— axum 对同一 path **只准 `.route()` 一次**(重复会 panic
|
||||
# `Overlapping method route`),所以「列表 GET + 新建 POST」必然链在一起。
|
||||
# 老实现只取**第一个**方法 ⇒ 后面的方法**静默消失**:契约里写 implemented,
|
||||
# 却报「代码里没有这条路由」(批次 14 踩到)。
|
||||
cursor = p
|
||||
while True:
|
||||
mm = re.match(r"(get|post|put|delete)\s*\(", orig[cursor:])
|
||||
if not mm:
|
||||
break
|
||||
if masked[cursor:cursor + len(mm.group(1))] != mm.group(1):
|
||||
break # 方法名其实落在字符串里(误报)
|
||||
method = mm.group(1).upper()
|
||||
name_start = cursor + mm.end()
|
||||
close = paren_span(masked, cursor + mm.end() - 1)
|
||||
rest = orig[name_start:name_start + 240]
|
||||
hm = HANDLER_RE.match(rest)
|
||||
mod, fn, closure = None, None, True
|
||||
if hm and hm.group(2):
|
||||
mod, fn = hm.group(1), hm.group(2)
|
||||
closure = False
|
||||
out.append({
|
||||
"path": route,
|
||||
"method": method,
|
||||
"mod": mod,
|
||||
"fn": fn,
|
||||
"closure": closure,
|
||||
"owner": owner,
|
||||
# 🔴 `source` 区分「路由住在哪」:平台层 / 业务模块(面 A)/ 业务包(面 B)。
|
||||
# owner 会撞(包与模块同 app_code)⇒ 守卫推导与台账范围**必须**看这个。
|
||||
"source": "platform" if owner == "platform" else "module",
|
||||
"const": None,
|
||||
"file": path,
|
||||
})
|
||||
# 顺着 `.` 走到下一个方法;遇到 `,` / `)` / 文件尾就停。
|
||||
cursor = close + 1
|
||||
while cursor < len(orig) and orig[cursor] in " \t\r\n":
|
||||
cursor += 1
|
||||
if cursor < len(orig) and orig[cursor] == ".":
|
||||
cursor += 1
|
||||
while cursor < len(orig) and orig[cursor] in " \t\r\n":
|
||||
cursor += 1
|
||||
continue
|
||||
break
|
||||
return out, orig, masked
|
||||
|
||||
|
||||
|
||||
+13
-10
@@ -71,20 +71,23 @@ def read_backend() -> tuple[set[tuple[str, str]], list[str]]:
|
||||
# `.route(\n "/api/x",\n get(h),\n)` 这种折行写法)。
|
||||
# 🔴 不能见 `"/api/..."` 就收 —— `routes.rs` 里还有大量「期望路径」字符串
|
||||
# 数组(自检用),照收会把未实现的路由误判成已实现。
|
||||
lines = text.splitlines()
|
||||
for i, line in enumerate(lines):
|
||||
if "route(" not in line:
|
||||
continue
|
||||
window = "\n".join(lines[i : i + 4])
|
||||
m = ROUTE_LIT.search(window)
|
||||
# 🔴 按 `.route(` **切块**再逐块取路径与方法:一条 `.route()` 里可以链多个方法
|
||||
# (`.route(p, get(a).post(b))` —— axum 同一个 path 只准注册一次,所以
|
||||
# 「列表 GET + 新建 POST」必然链在一起)。
|
||||
# 旧实现只看 4 行窗口里的**第一个**方法 ⇒ 后半段方法被漏掉,
|
||||
# 已实现的端点仍被报成缺口。
|
||||
for chunk in text.split(".route(")[1:]:
|
||||
m = ROUTE_LIT.search(chunk)
|
||||
if not m:
|
||||
continue
|
||||
path = m.group(1)
|
||||
mm = METHOD_CALL.search(window[m.end() :])
|
||||
if not mm:
|
||||
warns.append(f"{f.relative_to(ROOT)}:{i + 1} 路径 {path} 找不到方法")
|
||||
rest = chunk[m.end() :]
|
||||
methods = {mm.group(1).upper() for mm in METHOD_CALL.finditer(rest)}
|
||||
if not methods:
|
||||
warns.append(f"{f.relative_to(ROOT)} 路径 {path} 找不到方法")
|
||||
continue
|
||||
found.add((mm.group(1).upper(), norm(path)))
|
||||
for meth in methods:
|
||||
found.add((meth, norm(path)))
|
||||
return found, warns
|
||||
|
||||
|
||||
|
||||
@@ -1410,3 +1410,97 @@ CREATE TABLE base_common_variate (
|
||||
f_tenant_id VARCHAR(50) DEFAULT '0' NOT NULL,
|
||||
PRIMARY KEY (f_id, f_tenant_id)
|
||||
);
|
||||
|
||||
-- 基准数据类型 ↔ 控件映射 —— 列与官方 JNPF 7.0 逐字一致
|
||||
-- (官方 database/PostgreSQL/JNPF-PostgreSQL.sql 第 1520 行,`base_data_type_mapping`)
|
||||
-- 🔴 一条映射 = 「某个 jnpfKey 控件支持某种基准数据类型」;
|
||||
-- 官方 `DataTypeMappingController:131` 的 getKeyList 是**按 typeId 反查** jnpfKey 列表。
|
||||
CREATE TABLE base_data_type_mapping (
|
||||
f_id VARCHAR(50) NOT NULL,
|
||||
f_jnpf_key VARCHAR(50),
|
||||
f_type_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)
|
||||
);
|
||||
|
||||
-- 数据库管理(数据中心的「目标库类型」登记表)—— 列与官方逐字一致
|
||||
-- (官方第 1480 行附近,`base_data_base`)
|
||||
-- 🔴 `f_db_type` 是**驱动类型编码**(官方按它判重,`DataBaseController:59`),
|
||||
-- 不是显示名;`f_db_url` 只是模板串(如 `jdbc:mysql://...`),不存真实凭据。
|
||||
CREATE TABLE base_data_base (
|
||||
f_id VARCHAR(50) NOT NULL,
|
||||
f_full_name VARCHAR(50),
|
||||
f_icon VARCHAR(255),
|
||||
f_db_type VARCHAR(50) DEFAULT '0',
|
||||
f_db_drive VARCHAR(255),
|
||||
f_db_url VARCHAR(255),
|
||||
f_type 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)
|
||||
);
|
||||
|
||||
-- 数据库字段类型映射(某库下「本平台类型 → 目标库类型」)—— 列与官方逐字一致
|
||||
-- (官方第 1549 行,`base_data_type_relation`)
|
||||
-- 🔴 判重是**三元组**:`enCode + baseId`(官方 `existByEncode(id, enCode, baseId)`),
|
||||
-- 同一个 enCode 在不同库下可以各有一条。
|
||||
CREATE TABLE base_data_type_relation (
|
||||
f_id VARCHAR(50) NOT NULL,
|
||||
f_base_id VARCHAR(50),
|
||||
f_en_code VARCHAR(50),
|
||||
f_type_id VARCHAR(50),
|
||||
f_type INTEGER,
|
||||
f_length_default INTEGER,
|
||||
f_length_max INTEGER,
|
||||
f_length_min INTEGER,
|
||||
f_precision_default INTEGER,
|
||||
f_precision_max INTEGER,
|
||||
f_precision_min 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)
|
||||
);
|
||||
|
||||
-- 数据接口变量(接口的可变参数)—— 列与官方 JNPF 7.0 逐字一致
|
||||
-- (官方第 1362 行,`base_data_interface_variate`)
|
||||
-- 🔴 `f_interface_id` 是**必填**(官方 NOT NULL)⇒ 没有「游离变量」。
|
||||
CREATE TABLE base_data_interface_variate (
|
||||
f_id VARCHAR(50) NOT NULL,
|
||||
f_interface_id VARCHAR(50) NOT NULL,
|
||||
f_full_name VARCHAR(200),
|
||||
f_expression VARCHAR(500),
|
||||
f_value 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_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_field VARCHAR(50),
|
||||
PRIMARY KEY (f_id, f_tenant_id)
|
||||
);
|
||||
@@ -55,7 +55,9 @@ use ssw_platform::routes;
|
||||
/// `base_advanced_query_scheme`;**数据权限三件套**(2026-11-01 批次 11)
|
||||
/// `base_module_authorize` / `base_module_scheme` / `base_module_link`,故清单现在是 **48 张**。
|
||||
/// 系统数据批次(2026-11-02 批次 13)新增 `base_province` / `base_common_variate` ⇒ **50 张**。
|
||||
const BASE_TABLES: [&str; 50] = [
|
||||
/// 数据中心批次(2026-11-02 批次 14)新增 `base_data_type_mapping` / `base_data_base` /
|
||||
/// `base_data_type_relation` / `base_data_interface_variate` ⇒ **54 张**。
|
||||
const BASE_TABLES: [&str; 54] = [
|
||||
"base_group",
|
||||
"base_user",
|
||||
"base_role",
|
||||
@@ -124,6 +126,12 @@ const BASE_TABLES: [&str; 50] = [
|
||||
// 都是官方 DDL 逐字;`base_province` 是**树**(`f_parent_id`,根固定 `-1`)。
|
||||
"base_province",
|
||||
"base_common_variate",
|
||||
// 🔴 数据中心批次(2026-11-02 批次 14):基准类型映射 / 目标库登记 /
|
||||
// 字段类型映射 / 接口变量,都是官方 DDL 逐字(`base_data_type` 早在批次 5 已登记)。
|
||||
"base_data_type_mapping",
|
||||
"base_data_base",
|
||||
"base_data_type_relation",
|
||||
"base_data_interface_variate",
|
||||
];
|
||||
|
||||
/// 命令行解析的结果(**纯数据**,便于单测)。
|
||||
|
||||
+1199
-51
File diff suppressed because it is too large.
Load diff
@@ -385,8 +385,85 @@ pub fn build_router(state: AppState) -> axum::Router<AppState> {
|
||||
// ---- 数据建模的查询面(官方 `DbTableController`,路由前缀 `DataModel`)----
|
||||
// 🔴 `{linkId}` 一律**忽略**(本仓只有一个内置库);保留段位是为了让
|
||||
// 官方前端的 URL 形状原样命中。
|
||||
.route("/api/system/BasicDataType", get(face_b::basic_data_type_list))
|
||||
.route("/api/system/CommonFields", get(face_b::common_fields_list))
|
||||
// ---- 数据中心(批次 14):基准类型 / 控件映射 / 数据库 / 字段类型映射 / 常用字段 ----
|
||||
// 🔴 这两族的**列表**在批次 5(数据模型)就接上了,本轮补齐 info/增删改;
|
||||
// 列表与新建合并进同一行(同一个 `MethodRouter`)。
|
||||
// ⚠️ 同一 path 只能 `.route()` **一次** —— axum 对重复注册会 panic
|
||||
// (`Overlapping method route`)⇒ create 不能另起一行。
|
||||
.route(
|
||||
"/api/system/BasicDataType",
|
||||
get(face_b::basic_data_type_list).post(face_b::basic_data_type_create),
|
||||
)
|
||||
.route(
|
||||
"/api/system/BasicDataType/{id}",
|
||||
get(face_b::basic_data_type_info)
|
||||
.put(face_b::basic_data_type_update)
|
||||
.delete(face_b::basic_data_type_delete),
|
||||
)
|
||||
.route(
|
||||
"/api/system/DataTypeMapping",
|
||||
get(face_b::data_type_mapping_list).post(face_b::data_type_mapping_create),
|
||||
)
|
||||
// 🔴 静态段 `getKeyList` 必须**先于**参数段 `/{id}` 注册的直觉仍然成立
|
||||
// (axum/matchit 本身是静态优先,这里按可读性排)。
|
||||
.route(
|
||||
"/api/system/DataTypeMapping/getKeyList",
|
||||
get(face_b::data_type_mapping_key_list),
|
||||
)
|
||||
.route(
|
||||
"/api/system/DataTypeMapping/{id}",
|
||||
get(face_b::data_type_mapping_info)
|
||||
.put(face_b::data_type_mapping_update)
|
||||
.delete(face_b::data_type_mapping_delete),
|
||||
)
|
||||
.route(
|
||||
"/api/system/DataBase",
|
||||
get(face_b::data_base_list).post(face_b::data_base_create),
|
||||
)
|
||||
.route(
|
||||
"/api/system/DataBase/{id}",
|
||||
get(face_b::data_base_info)
|
||||
.put(face_b::data_base_update)
|
||||
.delete(face_b::data_base_delete),
|
||||
)
|
||||
.route(
|
||||
"/api/system/DataTypeRelation",
|
||||
get(face_b::data_type_relation_list).post(face_b::data_type_relation_create),
|
||||
)
|
||||
.route(
|
||||
"/api/system/DataTypeRelation/{id}",
|
||||
get(face_b::data_type_relation_info)
|
||||
.put(face_b::data_type_relation_update)
|
||||
.delete(face_b::data_type_relation_delete),
|
||||
)
|
||||
.route(
|
||||
"/api/system/CommonFields",
|
||||
get(face_b::common_fields_list).post(face_b::common_fields_create),
|
||||
)
|
||||
.route(
|
||||
"/api/system/CommonFields/{id}",
|
||||
get(face_b::common_fields_info)
|
||||
.put(face_b::common_fields_update)
|
||||
.delete(face_b::common_fields_delete),
|
||||
)
|
||||
// ---- 数据同步(四条一律明确拒绝:本仓无跨库能力,见 `face_b` 的注释)----
|
||||
.route("/api/system/DataSync", post(face_b::data_sync_check))
|
||||
.route(
|
||||
"/api/system/DataSync/Actions/checkDbLink",
|
||||
post(face_b::data_sync_check_db_link),
|
||||
)
|
||||
.route(
|
||||
"/api/system/DataSync/Actions/Execute",
|
||||
post(face_b::data_sync_execute),
|
||||
)
|
||||
.route(
|
||||
"/api/system/DataSync/Actions/batchExecute",
|
||||
post(face_b::data_sync_batch_execute),
|
||||
)
|
||||
.route(
|
||||
"/api/system/DataInterfaceVariate/Selector",
|
||||
get(face_b::data_interface_variate_selector),
|
||||
)
|
||||
.route(
|
||||
"/api/system/DataModel/{linkId}/Tables",
|
||||
get(face_b::data_model_tables),
|
||||
|
||||
@@ -0,0 +1,627 @@
|
||||
//! 批次 14(**数据中心五族 + 数据同步**)集成测试:
|
||||
//! `BasicDataType`(4) + `DataTypeMapping`(6) + `DataBase`(5) + `DataTypeRelation`(5)
|
||||
//! + `CommonFields`(4) + `DataSync`(4) + `DataInterfaceVariate`(1) = 29 端点,
|
||||
//! 4 张表(`base_data_type_mapping` / `base_data_base` / `base_data_type_relation` /
|
||||
//! `base_data_interface_variate`)。
|
||||
//!
|
||||
//! 🔴 **钉住的契约点**(每条都是「照抄官方会翻车 / 不照抄也会翻车」的地方):
|
||||
//! ① `BasicDataType` 是 **`enCode` 与 `fullName` 双判重** —— 只判一个就能造出
|
||||
//! 「同码不同名」的影子类型,前端下拉按 enCode 反查会拿到两行。
|
||||
//! ② `type` **不进写白名单**:官方 `DataTypeForm` 里没有这个字段。允许 PUT 改它
|
||||
//! = 允许把自定义类型伪装成内置(`type=1`),而内置是**删不掉**的。
|
||||
//! ③ 删除保护两层:内置(`type=1`)拒;被控件映射 / 字段类型映射 / 常用字段引用拒。
|
||||
//! ④ 🔴 **控件映射与字段类型映射的列表把 `typeId` 覆盖成「名字」**,而
|
||||
//! `GET /{id}` 返回**真 id**(官方 `DataTypeMappingController:60-68`)——
|
||||
//! 这是官方最反直觉的一处:同一字段,列表里是 `字符串名称`,详情里是 `id`。
|
||||
//! ⑤ `DataTypeRelation` 的判重是**二元组 `enCode + baseId`**:同一个 enCode
|
||||
//! 在不同目标库下可以各有一条(只按 enCode 判重会让第二个库配不了)。
|
||||
//! ⑥ 常用字段先挡 **SQL/Java 保留字**(列名要拿去建表),再判 `field + category`。
|
||||
//! ⑦ 数据同步四条**一律明确业务失败**(`code=400`)—— 本仓是内嵌单实例 PG,
|
||||
//! 没有驱动层。**不能返回成功**:那会让用户以为数据搬过去了。
|
||||
//! ⑧ 接口变量下拉是**两级树**:数据集 `type=0` / 变量 `type=1`,
|
||||
//! 变量的 `fullName` 是 `数据集enCode.变量名`(前端拿它当表达式引用)。
|
||||
//!
|
||||
//! 🔴 pglite-rs 是**进程级全局标志** ⇒ 全文件共用一个临时库 + 一把互斥锁。
|
||||
//! 断言一律按 id 定位,不数「列表里有几条」—— 同一个库里还有别的用例造的行。
|
||||
|
||||
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 临时库失败");
|
||||
ssw_platform::bootstrap::ensure_schema_all(&db)
|
||||
.await
|
||||
.expect("ensure_schema_all 失败");
|
||||
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-batch14-it"))),
|
||||
db: Arc::new(db.clone()),
|
||||
sessions: Arc::new(SessionStore::default()),
|
||||
}
|
||||
}
|
||||
|
||||
/// 按表 + 列取值(`create` 返 `null` ⇒ 拿不到 id,只能查库)。
|
||||
async fn id_of(table: &str, column: &str, value: &str) -> String {
|
||||
let v = value.to_string();
|
||||
let sql = format!("SELECT f_id AS \"id\" FROM {table} WHERE {column} = $1::text LIMIT 1");
|
||||
let rows = Db::query_json_params(db().await, &sql, &[&v])
|
||||
.await
|
||||
.expect("查 id 失败");
|
||||
assert_eq!(rows.len(), 1, "库里应恰有一行 {table}.{column}={value}");
|
||||
rows[0]["id"].as_str().expect("必须有 id").to_string()
|
||||
}
|
||||
|
||||
/// 起服务 + 登录,返回 (port, token)。
|
||||
async fn boot() -> (u16, String) {
|
||||
let state = new_state(db().await);
|
||||
let port = serve(state).await;
|
||||
let token = login(port).await;
|
||||
(port, token)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 基准数据类型
|
||||
|
||||
/// ① 双判重 + ② `type` 不可改 + ③ 删除保护。
|
||||
#[tokio::test]
|
||||
async fn basic_data_type_double_unique_and_type_is_immutable() {
|
||||
let _guard = LOCK.lock().await;
|
||||
let (port, token) = boot().await;
|
||||
|
||||
// 建一条自定义类型。
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/BasicDataType",
|
||||
&token,
|
||||
Some(r#"{"fullName":"B14类型甲","enCode":"b14_type_a","jnpfKey":"input"}"#),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 200, "新建应成功: {res}");
|
||||
let id = id_of("base_data_type", "f_en_code", "b14_type_a").await;
|
||||
|
||||
// ① 同 enCode 不同名 ⇒ 拒(报编码)。
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/BasicDataType",
|
||||
&token,
|
||||
Some(r#"{"fullName":"B14类型乙","enCode":"b14_type_a","jnpfKey":"input"}"#),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 400, "同 enCode 必须拒: {res}");
|
||||
assert!(
|
||||
res["msg"].as_str().unwrap_or_default().contains("编码"),
|
||||
"应报「编码已存在」: {res}"
|
||||
);
|
||||
|
||||
// ① 同名不同 enCode ⇒ 也拒(报名称)。
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/BasicDataType",
|
||||
&token,
|
||||
Some(r#"{"fullName":"B14类型甲","enCode":"b14_type_b","jnpfKey":"input"}"#),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 400, "同名必须拒: {res}");
|
||||
assert!(
|
||||
res["msg"].as_str().unwrap_or_default().contains("名称"),
|
||||
"应报「名称已存在」: {res}"
|
||||
);
|
||||
|
||||
// 新建恒为自定义(type=2)。
|
||||
let (_, info) = call(port, "GET", &format!("/api/system/BasicDataType/{id}"), &token, None).await;
|
||||
assert_eq!(info["code"], 200, "详情应成功: {info}");
|
||||
assert_eq!(info["data"]["type"], 2, "新建必须落成自定义(2): {info}");
|
||||
|
||||
// ② PUT 带 type=1 也不生效(type 不在写白名单里)。
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"PUT",
|
||||
&format!("/api/system/BasicDataType/{id}"),
|
||||
&token,
|
||||
Some(r#"{"fullName":"B14类型甲改","enCode":"b14_type_a","jnpfKey":"input","type":1}"#),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 200, "更新应成功: {res}");
|
||||
let rows = Db::query_json_params(
|
||||
db().await,
|
||||
"SELECT COALESCE(f_type, 0)::bigint AS \"type\" FROM base_data_type WHERE f_id = $1::text",
|
||||
&[&id],
|
||||
)
|
||||
.await
|
||||
.expect("查 type 失败");
|
||||
assert_eq!(rows[0]["type"], 2, "type 必须仍是 2(白名单挡住)");
|
||||
|
||||
// ③ 被控件映射引用 ⇒ 拒删。
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/DataTypeMapping",
|
||||
&token,
|
||||
Some(&format!(
|
||||
r#"{{"jnpfKey":"b14_key_x","typeId":"{id}","sortCode":1}}"#
|
||||
)),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 200, "建映射应成功: {res}");
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"DELETE",
|
||||
&format!("/api/system/BasicDataType/{id}"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 400, "被引用必须拒删: {res}");
|
||||
assert!(
|
||||
res["msg"].as_str().unwrap_or_default().contains("已被使用"),
|
||||
"应报「已被使用」: {res}"
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 控件映射
|
||||
|
||||
/// ④ 列表 `typeId` 是**名称**、详情 `typeId` 是**真 id**;⑤ getKeyList 分组。
|
||||
#[tokio::test]
|
||||
async fn data_type_mapping_list_shows_name_but_info_returns_id() {
|
||||
let _guard = LOCK.lock().await;
|
||||
let (port, token) = boot().await;
|
||||
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/BasicDataType",
|
||||
&token,
|
||||
Some(r#"{"fullName":"B14映射类型","enCode":"b14_map_type","jnpfKey":"input"}"#),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 200, "建基准类型失败: {res}");
|
||||
let type_id = id_of("base_data_type", "f_en_code", "b14_map_type").await;
|
||||
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/DataTypeMapping",
|
||||
&token,
|
||||
Some(&format!(
|
||||
r#"{{"jnpfKey":"b14_widget","typeId":"{type_id}","sortCode":7}}"#
|
||||
)),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 200, "建映射失败: {res}");
|
||||
let mapping_id = id_of("base_data_type_mapping", "f_type_id", &type_id).await;
|
||||
|
||||
// ④ 列表:typeId 被覆盖成「名称」。
|
||||
let (_, list) = call(port, "GET", "/api/system/DataTypeMapping", &token, None).await;
|
||||
assert_eq!(list["code"], 200, "列表失败: {list}");
|
||||
let row = list["data"]["list"]
|
||||
.as_array()
|
||||
.expect("必须是 ListVO")
|
||||
.iter()
|
||||
.find(|r| r["id"] == json!(mapping_id))
|
||||
.expect("列表里应有刚建的那条");
|
||||
assert_eq!(
|
||||
row["typeId"], "B14映射类型",
|
||||
"列表里的 typeId 必须是**名称**(官方 :60-68 覆盖): {row}"
|
||||
);
|
||||
|
||||
// ④ 详情:typeId 是**真 id**(编辑表单靠这条)。
|
||||
let (_, info) = call(
|
||||
port,
|
||||
"GET",
|
||||
&format!("/api/system/DataTypeMapping/{mapping_id}"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(info["code"], 200, "详情失败: {info}");
|
||||
assert_eq!(
|
||||
info["data"]["typeId"], type_id,
|
||||
"详情里的 typeId 必须是**真 id**: {info}"
|
||||
);
|
||||
|
||||
// ⑤ getKeyList:按基准类型聚合,jnpfKey 在数组里。
|
||||
let (_, keys) = call(
|
||||
port,
|
||||
"GET",
|
||||
"/api/system/DataTypeMapping/getKeyList",
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(keys["code"], 200, "getKeyList 失败: {keys}");
|
||||
let group = keys["data"]
|
||||
.as_array()
|
||||
.expect("必须是数组")
|
||||
.iter()
|
||||
.find(|g| g["dataType"] == "b14_map_type")
|
||||
.expect("应有刚建类型的分组");
|
||||
assert!(
|
||||
group["jnpfKeyList"]
|
||||
.as_array()
|
||||
.expect("jnpfKeyList 必须是数组")
|
||||
.contains(&json!("b14_widget")),
|
||||
"分组里应含 b14_widget: {group}"
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 数据库管理
|
||||
|
||||
/// ⑥ `dbType` 单列判重;列表**登录即可**(官方 list 无权限注解)。
|
||||
#[tokio::test]
|
||||
async fn data_base_unique_by_db_type() {
|
||||
let _guard = LOCK.lock().await;
|
||||
let (port, token) = boot().await;
|
||||
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/DataBase",
|
||||
&token,
|
||||
Some(
|
||||
r#"{"fullName":"B14库甲","icon":"icon-a","dbType":"b14_dbtype","dbDrive":"org.postgresql.Driver","dbUrl":"jdbc:postgresql://h/db"}"#,
|
||||
),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 200, "建库失败: {res}");
|
||||
|
||||
// 同 dbType、改名也不行(判重只看 dbType)。
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/DataBase",
|
||||
&token,
|
||||
Some(
|
||||
r#"{"fullName":"B14库乙","icon":"icon-b","dbType":"b14_dbtype","dbDrive":"x","dbUrl":"y"}"#,
|
||||
),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 400, "同 dbType 必须拒: {res}");
|
||||
assert!(
|
||||
res["msg"].as_str().unwrap_or_default().contains("数据库类型"),
|
||||
"应报「数据库类型已存在」: {res}"
|
||||
);
|
||||
|
||||
// 列表能查到(登录即可,返回 ListVO)。
|
||||
let (_, list) = call(port, "GET", "/api/system/DataBase", &token, None).await;
|
||||
assert_eq!(list["code"], 200, "列表失败: {list}");
|
||||
assert!(
|
||||
list["data"]["list"]
|
||||
.as_array()
|
||||
.expect("必须是 ListVO")
|
||||
.iter()
|
||||
.any(|r| r["dbType"] == "b14_dbtype"),
|
||||
"列表里应有刚建的库: {list}"
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 字段类型映射
|
||||
|
||||
/// ⑦ 判重是**二元组 enCode+baseId**(同 enCode 换库 ⇒ 允许);列表分页。
|
||||
#[tokio::test]
|
||||
async fn data_type_relation_unique_is_pair_en_code_and_base_id() {
|
||||
let _guard = LOCK.lock().await;
|
||||
let (port, token) = boot().await;
|
||||
|
||||
for (db_type, name) in [("b14_rel_db1", "B14关系库一"), ("b14_rel_db2", "B14关系库二")] {
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/DataBase",
|
||||
&token,
|
||||
Some(&format!(
|
||||
r#"{{"fullName":"{name}","icon":"i","dbType":"{db_type}","dbDrive":"d","dbUrl":"u"}}"#
|
||||
)),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 200, "建库失败: {res}");
|
||||
}
|
||||
let base1 = id_of("base_data_base", "f_db_type", "b14_rel_db1").await;
|
||||
let base2 = id_of("base_data_base", "f_db_type", "b14_rel_db2").await;
|
||||
|
||||
// 库 1 建一条 enCode=b14_col。
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/DataTypeRelation",
|
||||
&token,
|
||||
Some(&format!(
|
||||
r#"{{"baseId":"{base1}","enCode":"b14_col","type":1,"lengthDefault":64,"lengthMax":255,"lengthMin":1}}"#
|
||||
)),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 200, "库1建映射失败: {res}");
|
||||
|
||||
// 库 1 再建同 enCode ⇒ 拒。
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/DataTypeRelation",
|
||||
&token,
|
||||
Some(&format!(
|
||||
r#"{{"baseId":"{base1}","enCode":"b14_col","type":2}}"#
|
||||
)),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 400, "同库同 enCode 必须拒: {res}");
|
||||
|
||||
// 库 2 建同 enCode ⇒ **允许**(二元组判重)。
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/DataTypeRelation",
|
||||
&token,
|
||||
Some(&format!(
|
||||
r#"{{"baseId":"{base2}","enCode":"b14_col","type":3}}"#
|
||||
)),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 200, "换库同 enCode 必须放行: {res}");
|
||||
|
||||
// 列表是 PageListVO(有 pagination)。
|
||||
let (_, page) = call(
|
||||
port,
|
||||
"GET",
|
||||
&format!("/api/system/DataTypeRelation?baseId={base1}¤tPage=1&pageSize=10"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(page["code"], 200, "列表失败: {page}");
|
||||
assert!(
|
||||
page["data"]["pagination"].is_object(),
|
||||
"必须是 PageListVO(带 pagination): {page}"
|
||||
);
|
||||
assert_eq!(
|
||||
page["data"]["pagination"]["total"], 1,
|
||||
"库1应有 1 条: {page}"
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 常用字段
|
||||
|
||||
/// ⑧ 保留字先挡(列名要建表);判重是 field+category。
|
||||
#[tokio::test]
|
||||
async fn common_fields_rejects_reserved_words() {
|
||||
let _guard = LOCK.lock().await;
|
||||
let (port, token) = boot().await;
|
||||
|
||||
// 保留字 ⇒ 拒(大小写不敏感)。
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/CommonFields",
|
||||
&token,
|
||||
Some(r#"{"fieldName":"生僻","field":" select ","dataType":"varchar","dataLength":"50","category":"b14_cat","type":2}"#),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 400, "保留字必须拒: {res}");
|
||||
assert!(
|
||||
res["msg"].as_str().unwrap_or_default().contains("保留字"),
|
||||
"应报保留字: {res}"
|
||||
);
|
||||
|
||||
// 正常列名 ⇒ 成功。
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/CommonFields",
|
||||
&token,
|
||||
Some(r#"{"fieldName":"B14列","field":"b14_col","dataType":"varchar","dataLength":"50","category":"b14_cat","type":2}"#),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 200, "正常列名应成功: {res}");
|
||||
let id = id_of("base_common_fields", "f_field", "b14_col").await;
|
||||
|
||||
// 同 category 同 field ⇒ 拒。
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/CommonFields",
|
||||
&token,
|
||||
Some(r#"{"fieldName":"B14列2","field":"b14_col","dataType":"varchar","dataLength":"50","category":"b14_cat","type":2}"#),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 400, "同分组同列名必须拒: {res}");
|
||||
|
||||
// 换分组 ⇒ 允许。
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"POST",
|
||||
"/api/system/CommonFields",
|
||||
&token,
|
||||
Some(r#"{"fieldName":"B14列3","field":"b14_col","dataType":"varchar","dataLength":"50","category":"b14_cat2","type":2}"#),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 200, "换分组应放行: {res}");
|
||||
|
||||
// 详情带 dataTypeName(联合基准类型取名称)。
|
||||
let (_, info) = call(
|
||||
port,
|
||||
"GET",
|
||||
&format!("/api/system/CommonFields/{id}"),
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(info["code"], 200, "详情失败: {info}");
|
||||
assert_eq!(info["data"]["field"], "b14_col", "详情字段不对: {info}");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 数据同步
|
||||
|
||||
/// ⑦ 四条一律**明确失败**(不能返回 200 假装同步成功)。
|
||||
#[tokio::test]
|
||||
async fn data_sync_endpoints_refuse_explicitly() {
|
||||
let _guard = LOCK.lock().await;
|
||||
let (port, token) = boot().await;
|
||||
|
||||
for path in [
|
||||
"/api/system/DataSync",
|
||||
"/api/system/DataSync/Actions/checkDbLink",
|
||||
"/api/system/DataSync/Actions/Execute",
|
||||
"/api/system/DataSync/Actions/batchExecute",
|
||||
] {
|
||||
let (status, res) = call(port, "POST", path, &token, Some("{}")).await;
|
||||
assert!(
|
||||
status.contains("200"),
|
||||
"{path} 的业务失败必须是 HTTP 200(信封决定成败): {status}"
|
||||
);
|
||||
assert_eq!(
|
||||
res["code"], 400,
|
||||
"{path} 必须明确失败(否则用户以为数据搬过去了): {res}"
|
||||
);
|
||||
assert!(
|
||||
res["msg"].as_str().unwrap_or_default().contains("跨库"),
|
||||
"{path} 的错误文案要说明是「跨库不支持」: {res}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 接口变量下拉
|
||||
|
||||
/// ⑧ 两级树:数据集 type=0 / 变量 type=1,变量 fullName = `enCode.变量名`。
|
||||
#[tokio::test]
|
||||
async fn data_interface_variate_selector_is_two_level_tree() {
|
||||
let _guard = LOCK.lock().await;
|
||||
let (port, token) = boot().await;
|
||||
|
||||
// 直接写库造一条数据集 + 两条变量(本批次不补 DataSet 的增删改,它早就有)。
|
||||
let set_id = "b14-set-0001";
|
||||
let sql = format!(
|
||||
"INSERT INTO base_data_set (f_id, f_full_name, f_en_code, f_enabled_mark, f_delete_mark, f_tenant_id) \
|
||||
VALUES ('{set_id}', 'B14数据集', 'b14Dataset', 1, 0, '0')"
|
||||
);
|
||||
Db::exec_params(db().await, &sql, &[]).await.expect("造数据集失败");
|
||||
for (vid, name) in [("b14-var-0001", "变量甲"), ("b14-var-0002", "变量乙")] {
|
||||
let sql = format!(
|
||||
"INSERT INTO base_data_interface_variate \
|
||||
(f_id, f_interface_id, f_full_name, f_field, f_delete_mark, f_sort_code, f_tenant_id) \
|
||||
VALUES ('{vid}', '{set_id}', '{name}', 'f_{vid}', 0, 1, '0')"
|
||||
);
|
||||
Db::exec_params(db().await, &sql, &[]).await.expect("造变量失败");
|
||||
}
|
||||
|
||||
let (_, res) = call(
|
||||
port,
|
||||
"GET",
|
||||
"/api/system/DataInterfaceVariate/Selector",
|
||||
&token,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(res["code"], 200, "下拉失败: {res}");
|
||||
let node = res["data"]
|
||||
.as_array()
|
||||
.expect("必须是数组")
|
||||
.iter()
|
||||
.find(|n| n["id"] == json!(set_id))
|
||||
.expect("应有刚造的数据集节点");
|
||||
assert_eq!(node["type"], 0, "数据集节点 type=0: {node}");
|
||||
assert_eq!(node["parentId"], "-1", "数据集 parentId=-1: {node}");
|
||||
let kids = node["children"].as_array().expect("必须有 children");
|
||||
assert_eq!(kids.len(), 2, "应有 2 个变量: {node}");
|
||||
let first = &kids[0];
|
||||
assert_eq!(first["type"], 1, "变量 type=1: {first}");
|
||||
assert_eq!(first["parentId"], set_id, "变量 parentId=数据集 id: {first}");
|
||||
assert_eq!(
|
||||
first["fullName"], "b14Dataset.变量甲",
|
||||
"变量 fullName 必须是 `enCode.变量名`: {first}"
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user