Compare commits
10 Commits
bf5659590f
...
bad7e66b73
| Author | SHA1 | Date | |
|---|---|---|---|
| bad7e66b73 | |||
| 5e0845e2c2 | |||
| dc2aa31df8 | |||
| e2ddf157d5 | |||
| 7c15bc55f8 | |||
| a19bcdbf67 | |||
| 4468616e88 | |||
| 76ad354605 | |||
| 9d05894e9d | |||
| 84a64624ff |
@@ -0,0 +1,36 @@
|
||||
package com.eip4.platform.app.config;
|
||||
|
||||
import org.apache.catalina.connector.Connector;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 放宽 Tomcat 查询串允许字符,接纳未编码的方括号 {@code [ ]}(及 {@code { } |})。
|
||||
*
|
||||
* <p><b>动机(amis picker 多选加载已存值显名)</b>:amis 用 {@code qs(arrayFormat='indices',
|
||||
* encodeValuesOnly=true)} 序列化数组查询参数——只编码值、不编码键,故多选 picker 加载已存值时
|
||||
* 原生发出的 loadOptions 请求形如 {@code /api/picker/{id}/list?value[0]=v1&value[1]=v2&op=loadOptions},
|
||||
* query 串里带<b>未编码</b>的 {@code [ ]}。Tomcat 默认按 RFC 3986 严格校验 query 字符,遇未编码
|
||||
* {@code [ ]} 直接回 400(在进 Spring MVC 之前,控制器无从处理)——表现为多选 picker 显裸 id、
|
||||
* 控制台「ajax 动作执行失败」。放宽这几个字符后,{@code MultiValueMap} 即可绑定 {@code value[n]},
|
||||
* {@link com.eip4.platform.metadata.web.PickerController} 的 {@code op=loadOptions} 分支正常解析显示名。
|
||||
*
|
||||
* <p>这是 amis + Spring Boot 的标准兼容设置:amis 各类 CRUD 的数组型过滤/排序参数普遍走 indices
|
||||
* 方括号形态,本放宽对全站 amis 数组查询通用生效(非仅 picker)。{@code [ ]} 仅出现在 query 串、
|
||||
* 经引擎参数化/白名单消费,放宽字符集不削弱既有注入防护。
|
||||
*/
|
||||
@Configuration
|
||||
public class TomcatRelaxedQueryConfig {
|
||||
|
||||
@Bean
|
||||
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> relaxedQueryCharsCustomizer() {
|
||||
return factory -> factory.addConnectorCustomizers(this::relaxConnector);
|
||||
}
|
||||
|
||||
private void relaxConnector(Connector connector) {
|
||||
// amis qs indices 数组键用 [ ];{ } | 一并放宽以覆盖 amis 其它查询编码场景。
|
||||
connector.setProperty("relaxedQueryChars", "[]{}|");
|
||||
}
|
||||
}
|
||||
@@ -137,7 +137,7 @@ public class TemplateToAmisConverter {
|
||||
switch (root) {
|
||||
case "crud" -> result.setSchema(convertCrud(rootEl, result, effectiveName));
|
||||
case "form" -> result.setSchema(convertForm(rootEl, result, pageResolver, effectiveName));
|
||||
case "tree" -> result.setSchema(convertTree(rootEl, result, effectiveName));
|
||||
case "tree" -> result.setSchema(convertTree(rootEl, result, pageResolver, effectiveName));
|
||||
case "report" -> result.setSchema(convertReport(rootEl, result, effectiveName));
|
||||
case "group" -> result.setSchema(convertGroup(rootEl, result, effectiveName));
|
||||
case "page" -> result.setSchema(convertViewPage(rootEl, result, effectiveName));
|
||||
@@ -1050,16 +1050,202 @@ public class TemplateToAmisConverter {
|
||||
item.put("type", "tree-select");
|
||||
item.put("source", "/api/template/" + dialogId + "/tree");
|
||||
item.put("clearable", true);
|
||||
item.put("searchable", true); // 大树下拉带搜索框,过滤层级节点
|
||||
if (multiple) {
|
||||
item.put("multiple", true);
|
||||
}
|
||||
result.note("树选择 " + name + " → dialogid=" + dialogId
|
||||
+ " 是 type=3 树模板 → tree-select(source=/api/template/.../tree),非扁平 picker"
|
||||
+ "(修上级菜单等层级引用显列表选择框)");
|
||||
} else if (!dialogId.isBlank() && isType4Dialog(dialogId)) {
|
||||
// ④:树+grid 选择框——dialogid 指向 type=4「树+grid」模板(<treetemplate ref/> + <gridtemplate
|
||||
// ref/ rcolumnname/>,如「功能管理」)→ 把扁平 picker 改写为「弹窗内 = 左分类树过滤 + 右 CRUD 表格」
|
||||
// (降级规则:通用 6 + 自定义 3 全走此路,不看 engineclass)。机制与 type=4 浏览页(convertTreeGrid)
|
||||
// 同源、与 spike 实证一致:picker.source=右表子树聚合端点 /api/template/treegrid?...&node=${rcol},
|
||||
// pickerSchema.filter=分类 tree-select(name=rcol, source=左树端点),选分类→${rcol}→node 过滤右表,
|
||||
// 选行回填 picker(valueField=_id 提交裸 id 不变)。列取自 gridtemplate <display>(转换器侧解析)。
|
||||
applyTreeGridPicker(item, f, dialogId, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* type=4 树+grid 选择框(弹窗内 = 左分类树过滤 + 右 CRUD 表格)的 picker 改写。
|
||||
*
|
||||
* <p>读 dialog(type=4 view_template)XML 的 {@code <treetemplate ref/>}(左分类树)+
|
||||
* {@code <gridtemplate ref/ entityid/ rcolumnname/>}(右数据表 + 分类过滤列),按 spike 确认的机制重写
|
||||
* 入参 {@code item}(原 UiTypeMapper 产的扁平 picker):
|
||||
* <ul>
|
||||
* <li>{@code source}=右表子树聚合端点 {@code /api/template/treegrid?treeRef=&gridTable=&rcol=&node=${rcol}}
|
||||
* (与 {@link #convertTreeGrid} 浏览页右表同源;node 取分类 tree-select 的当前值 {@code ${rcol}});</li>
|
||||
* <li>{@code labelField}=右表显示列(gridtemplate display 首个可见列,回落实体显示列)——treegrid 端点返
|
||||
* 业务行(无统一 {@code _label}),故 chip/选中显示绑真实显示列,显名而非裸 id;</li>
|
||||
* <li>{@code valueField=_id}(保持表单提交值=裸主键不变);</li>
|
||||
* <li>{@code pickerSchema}={@code crud(mode=table)} + {@code filter:[tree-select name=rcol source=左树端点]}
|
||||
* + {@code columns}(gridtemplate {@code <display>} 解析,转换器侧——与 convertTreeGrid 右表列同源)。</li>
|
||||
* </ul>
|
||||
* 解析失败(dialog XML 缺 treetemplate/gridtemplate、实体/rcol 解析不出)→ 保留扁平 picker 基线(零回归)。
|
||||
*/
|
||||
private void applyTreeGridPicker(Map<String, Object> item, Element f, String dialogId, ConversionResult result) {
|
||||
Element dialogRoot = loadRefRoot(dialogId, result);
|
||||
if (dialogRoot == null) {
|
||||
return; // dialog XML 取不到 → 保留扁平 picker 基线
|
||||
}
|
||||
Element treeTemplate = dialogRoot.element("treetemplate");
|
||||
Element gridTemplate = dialogRoot.element("gridtemplate");
|
||||
if (treeTemplate == null || gridTemplate == null) {
|
||||
return; // 非标准 tree+grid 结构 → 保留扁平 picker 基线
|
||||
}
|
||||
String treeRef = treeTemplate.attributeValue("ref", "");
|
||||
String gridRef = gridTemplate.attributeValue("ref", "");
|
||||
String gridEntityId = gridTemplate.attributeValue("entityid", "");
|
||||
String rcol = gridTemplate.attributeValue("rcolumnname", "");
|
||||
String gridTable = resolveTableName(gridEntityId, result);
|
||||
String gridTableUpper = gridTable != null ? gridTable.toUpperCase() : null;
|
||||
if (treeRef.isBlank() || rcol.isBlank() || gridTableUpper == null
|
||||
|| gridTableUpper.isBlank() || gridTableUpper.startsWith("UNKNOWN_")
|
||||
|| gridTableUpper.startsWith("ORPHAN_")) {
|
||||
result.degrade("树+grid选择框 dialogid=" + dialogId + " treetemplate/gridtemplate 解析失败"
|
||||
+ "(treeRef=" + treeRef + ",rcol=" + rcol + ",gridTable=" + gridTableUpper
|
||||
+ ") → 保留扁平 picker 基线");
|
||||
return;
|
||||
}
|
||||
String rcolUpper = rcol.toUpperCase();
|
||||
boolean multiple = Boolean.TRUE.equals(item.get("multiple"));
|
||||
String name = f.attributeValue("name", "");
|
||||
|
||||
// 右表列:取自 gridtemplate 引用模板的 <display>(与 convertTreeGrid 右表列同源)。
|
||||
// 丢主键列(iskeycolumn=true,如 VIEW_TEMPLATE_ID)——它是 picker 的 value(valueField=_id),
|
||||
// 在选择网格里再显一遍裸 id 是噪声(用户反馈「列表还有 ID 显示」),故剔除。
|
||||
List<Map<String, Object>> gridCols = new ArrayList<>();
|
||||
Element gridRoot = loadRefRoot(gridRef, result);
|
||||
if (gridRoot != null) {
|
||||
Element display = gridRoot.element("display");
|
||||
if (display != null) {
|
||||
Set<String> keyColNames = new LinkedHashSet<>();
|
||||
for (Element fld : display.elements("field")) {
|
||||
if ("true".equalsIgnoreCase(fld.attributeValue("iskeycolumn"))) {
|
||||
String kn = fld.attributeValue("name", "");
|
||||
if (!kn.isBlank()) keyColNames.add(kn.toUpperCase());
|
||||
}
|
||||
}
|
||||
List<Map<String, Object>> refCols = buildColumns(display, gridEntityId, result);
|
||||
if (refCols != null) {
|
||||
for (Map<String, Object> c : refCols) {
|
||||
Object cn = c.get("name");
|
||||
if (cn != null && keyColNames.contains(String.valueOf(cn).toUpperCase())) {
|
||||
continue; // 主键列 = picker 的 value,不在网格里重复显裸 id
|
||||
}
|
||||
gridCols.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// labelField=_label:treegrid 端点已为每行补统一显示值 _label(= 网格实体显示列),与「加载已存值经
|
||||
// EntityController 解析出的 {_id,_label}」同口径——chip/选中/加载三处显人可读名而非裸 id(与 PickerController
|
||||
// 扁平 picker 的 _label 约定一致)。
|
||||
String labelField = "_label";
|
||||
|
||||
// 右表数据源:子树聚合端点(点分类含整棵子树,对齐老系统),node 取分类 tree-select 当前值。
|
||||
String source = "/api/template/treegrid?treeRef=" + treeRef + "&gridTable=" + gridTableUpper
|
||||
+ "&rcol=" + rcolUpper + "&node=${" + rcolUpper + "}&page=${page}&perPage=${perPage}";
|
||||
|
||||
// 过滤器:分类树过滤器仅当 rcol 是 gridTable 的真实列时才渲染。否则(如功能管理:右表 VIEW_TEMPLATE
|
||||
// 无 ENTITYTYPE 列,分类靠「功能→实体→实体分类」join,属老自定义组件 UserFunDesignComponent 逻辑/153)
|
||||
// 过滤器点了也不缩窄,渲染只会误导用户,故省略死过滤器,降级为「可搜索表格」(始终补名称搜索框)。
|
||||
List<Object> filterBody = new ArrayList<>();
|
||||
if (isRealColumn(gridTableUpper, rcolUpper)) {
|
||||
Map<String, Object> treeFilter = new LinkedHashMap<>();
|
||||
treeFilter.put("type", "tree-select");
|
||||
treeFilter.put("name", rcolUpper);
|
||||
treeFilter.put("label", "分类");
|
||||
treeFilter.put("source", "/api/template/" + treeRef + "/tree");
|
||||
treeFilter.put("searchable", true);
|
||||
treeFilter.put("clearable", true);
|
||||
filterBody.add(treeFilter);
|
||||
} else {
|
||||
result.degrade("树+grid选择框 dialogid=" + dialogId + " rcol=" + rcolUpper + " 非 "
|
||||
+ gridTableUpper + " 真实列(分类过滤需实体→分类 join,属自定义组件/153)"
|
||||
+ " → 省略死分类过滤器,降级为可搜索表格");
|
||||
}
|
||||
// 名称搜索框(始终):按首个显示列名搜索(treegrid 端点把非保留参转发给搜索流过滤)。大表可搜,覆盖查找诉求。
|
||||
String searchCol = !gridCols.isEmpty() ? String.valueOf(gridCols.get(0).get("name")) : "NAME";
|
||||
Map<String, Object> nameSearch = new LinkedHashMap<>();
|
||||
nameSearch.put("type", "input-text");
|
||||
nameSearch.put("name", searchCol);
|
||||
nameSearch.put("label", "名称");
|
||||
nameSearch.put("clearable", true);
|
||||
filterBody.add(nameSearch);
|
||||
|
||||
Map<String, Object> filter = new LinkedHashMap<>();
|
||||
filter.put("title", "");
|
||||
filter.put("body", filterBody);
|
||||
|
||||
Map<String, Object> pickerSchema = new LinkedHashMap<>();
|
||||
pickerSchema.put("mode", "table");
|
||||
pickerSchema.put("filter", filter);
|
||||
if (!gridCols.isEmpty()) {
|
||||
pickerSchema.put("columns", gridCols);
|
||||
}
|
||||
pickerSchema.put("footerToolbar", List.of("pagination"));
|
||||
|
||||
// 重写 item:保持 type=picker,换数据源/字段/弹窗内容为 tree+grid。
|
||||
item.put("type", "picker");
|
||||
item.put("clearable", true);
|
||||
if (multiple) {
|
||||
item.put("multiple", true);
|
||||
}
|
||||
item.put("source", source);
|
||||
item.put("labelField", labelField);
|
||||
item.put("valueField", "_id");
|
||||
item.put("modalMode", "dialog");
|
||||
item.put("modalSize", "lg");
|
||||
item.put("pickerSchema", pickerSchema);
|
||||
|
||||
result.note("树+grid选择框 " + name + " → dialogid=" + dialogId + " 是 type=4 树+grid 模板"
|
||||
+ " → picker(弹窗内=左分类树[" + rcolUpper + "]过滤 + 右表 " + gridTableUpper
|
||||
+ " CRUD,labelField=" + labelField + "),提交值仍 _id");
|
||||
}
|
||||
|
||||
/**
|
||||
* dialogid(=view_template_id) 指向的模板是否 type=4(树+grid,浏览/选择两用)。
|
||||
* 用于把 type=4 选择框(SelectDialog/MultiSelectDialog)的扁平 picker 改写为「树过滤 + grid」picker。
|
||||
* 查询失败/非 type=4 → false(保持扁平 picker 基线,零回归)。
|
||||
*/
|
||||
private boolean isType4Dialog(String dialogId) {
|
||||
if (dialogId == null || dialogId.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Integer type = jdbcTemplate.queryForObject(
|
||||
"SELECT type FROM view_template WHERE view_template_id = ?",
|
||||
Integer.class, dialogId);
|
||||
return type != null && type == 4;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code table} 是否真实存在 {@code col} 列(information_schema 查)。用于 type=4 树+grid 选择框:
|
||||
* 仅当 rcolumnname 是右表真实列时才渲染分类树过滤器;否则(如功能管理右表 VIEW_TEMPLATE 无 ENTITYTYPE
|
||||
* 列,分类靠跨实体 join)过滤器无效,省略以免误导。查询失败 → false(保守省略过滤器)。
|
||||
*/
|
||||
private boolean isRealColumn(String table, String col) {
|
||||
if (table == null || table.isBlank() || col == null || col.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Integer cnt = jdbcTemplate.queryForObject(
|
||||
"SELECT count(*) FROM information_schema.columns "
|
||||
+ "WHERE upper(table_name) = ? AND upper(column_name) = ?",
|
||||
Integer.class, table.toUpperCase(), col.toUpperCase());
|
||||
return cnt != null && cnt > 0;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* dialogid(=view_template_id) 指向的模板是否 type=3(树形对话框,绑自引用层级实体)。
|
||||
* 用于把「上级菜单/父分类」等层级引用的 SelectDialog 从扁平 picker 改写为 tree-select。
|
||||
@@ -1170,6 +1356,49 @@ public class TemplateToAmisConverter {
|
||||
// form(EDITFORM 表单页)—— 字段取自 pageid 指向的 view_page
|
||||
// ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* 解析 pageid 指向的 view_page → 经 {@link UiTypeMapper#mapField} + {@link #enrichFieldRefs} 生成表单字段项。
|
||||
* 由 EDITFORM 表单页({@link #convertForm})与可编辑 type=3 树 master-detail({@link #buildEditableTreeMasterDetail})
|
||||
* 共用——字段忠实保真(SelectDialog+dialogid→picker、ComboBox→select、TextField→input-text…)的唯一来源。
|
||||
*
|
||||
* @param pageResolver pageid → view_page.xml 解析器;null/解析失败 → 空字段壳(降级标注)
|
||||
*/
|
||||
private List<Map<String, Object>> buildFormItemsFromPage(String pageId, String entityId,
|
||||
Function<String, String> pageResolver,
|
||||
ConversionResult result) throws Exception {
|
||||
String pageXml = (pageResolver != null && pageId != null && !pageId.isBlank())
|
||||
? pageResolver.apply(pageId) : null;
|
||||
if (pageXml == null || pageXml.isBlank()) {
|
||||
result.degrade("form@pageid=" + pageId + " 无法解析 view_page(缺解析器/页面不存在)→ 空表单壳");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Element pageRoot = DocumentHelper.parseText(pageXml).getRootElement();
|
||||
return buildFormItemsFromPage(pageId, entityId, pageRoot, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析已就绪的 view_page 根元素的 {@code <fields>} → 表单字段项(共用核心,见上述 resolver 重载)。
|
||||
*/
|
||||
private List<Map<String, Object>> buildFormItemsFromPage(String pageId, String entityId,
|
||||
Element pageRoot, ConversionResult result) {
|
||||
List<Map<String, Object>> formItems = new ArrayList<>();
|
||||
if (pageRoot == null) {
|
||||
return formItems;
|
||||
}
|
||||
Element fields = pageRoot.element("fields");
|
||||
if (fields != null) {
|
||||
// 列元数据(含 enumeratetype):供 ComboBox 缺省 comboboxid 但 itemisenumerate=true 取枚举字典源
|
||||
Map<String, String[]> colMeta = loadColumnMeta(entityId, result);
|
||||
for (Element f : fields.elements("field")) {
|
||||
Map<String, Object> formItem = UiTypeMapper.mapField(f, result, "editform", colMeta);
|
||||
enrichFieldRefs(formItem, f, result);
|
||||
formItems.add(formItem);
|
||||
}
|
||||
result.note("form@pageid=" + pageId + " → 解析 view_page 取得 " + formItems.size() + " 字段");
|
||||
}
|
||||
return formItems;
|
||||
}
|
||||
|
||||
private Map<String, Object> convertForm(Element form, ConversionResult result,
|
||||
Function<String, String> pageResolver,
|
||||
String templateName) throws Exception {
|
||||
@@ -1182,17 +1411,7 @@ public class TemplateToAmisConverter {
|
||||
String pageXml = (pageResolver != null && !pageId.isBlank()) ? pageResolver.apply(pageId) : null;
|
||||
if (pageXml != null && !pageXml.isBlank()) {
|
||||
pageRoot = DocumentHelper.parseText(pageXml).getRootElement();
|
||||
Element fields = pageRoot.element("fields");
|
||||
if (fields != null) {
|
||||
// 列元数据(含 enumeratetype):供 ComboBox 缺省 comboboxid 但 itemisenumerate=true 取枚举字典源
|
||||
Map<String, String[]> colMeta = loadColumnMeta(entityId, result);
|
||||
for (Element f : fields.elements("field")) {
|
||||
Map<String, Object> formItem = UiTypeMapper.mapField(f, result, "editform", colMeta);
|
||||
enrichFieldRefs(formItem, f, result);
|
||||
formItems.add(formItem);
|
||||
}
|
||||
result.note("form@pageid=" + pageId + " → 解析 view_page 取得 " + formItems.size() + " 字段");
|
||||
}
|
||||
formItems = buildFormItemsFromPage(pageId, entityId, pageRoot, result);
|
||||
// <layout> 多 <tab> 由 buildFormBody 解析为 amis tabs(见该方法);无 layout 退两栏排版
|
||||
} else {
|
||||
result.degrade("form@pageid=" + pageId + " 无法解析 view_page(缺解析器/页面不存在)→ 空表单壳");
|
||||
@@ -1983,7 +2202,8 @@ public class TemplateToAmisConverter {
|
||||
// tree(树 / 树+grid)
|
||||
// ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
private Map<String, Object> convertTree(Element tree, ConversionResult result, String templateName) {
|
||||
private Map<String, Object> convertTree(Element tree, ConversionResult result,
|
||||
Function<String, String> pageResolver, String templateName) {
|
||||
// type=4:树+grid 引用式(<treetemplate ref/> + <gridtemplate ref/>)
|
||||
Element treeTemplate = tree.element("treetemplate");
|
||||
Element gridTemplate = tree.element("gridtemplate");
|
||||
@@ -1992,7 +2212,9 @@ public class TemplateToAmisConverter {
|
||||
}
|
||||
|
||||
// type=3:声明式树(含 <node entityid selectservice><buttons>)—— 管理页,本应可编辑(增/改/删分类节点)。
|
||||
Element node = tree.element("node");
|
||||
// 一棵 tree 可能多个 <node>:优先选含 edit=true+pageid 的可编辑数据节点(菜单维护根 node 在前但第一个即可编辑,
|
||||
// 新闻收藏分类仅一个 node;稳妥起见多 node 时选可编辑节点),否则回退第一个 <node>。
|
||||
Element node = selectEditableNode(tree);
|
||||
Map<String, Object> treeSchema = new LinkedHashMap<>();
|
||||
treeSchema.put("type", "input-tree");
|
||||
treeSchema.put("name", "tree");
|
||||
@@ -2024,6 +2246,20 @@ public class TemplateToAmisConverter {
|
||||
if (node.element("nextnodes") != null && !node.element("nextnodes").elements().isEmpty()) {
|
||||
result.note("tree@node 含 nextnodes 多级 → amis input-tree 懒加载(deferApi 待补)");
|
||||
}
|
||||
// 可编辑 type=3 树 master-detail(左树 + 右「选中节点载入的编辑表单」),取代旧「工具栏 + 弹窗」。
|
||||
// 判定:node@pageid 非空 + buttons 有 save 服务名(addSvc) + (hasInsert||hasUpdate)(不强制 edit='true',
|
||||
// 真实可编辑分类树节点既有 edit=true 也有靠 buttons 表达;isroot 且 edit=false 的纯根 selectservice
|
||||
// 节点无 pageid,自然不走)。表名解析失败(UNKNOWN_/ORPHAN_/空) → 回退现有逻辑(降级)。
|
||||
NodeButtons nb = parseNodeButtons(node);
|
||||
String pageId = node.attributeValue("pageid", "");
|
||||
String mdTable = resolveTableName(entityId, result);
|
||||
boolean tableOk = mdTable != null && !mdTable.isBlank()
|
||||
&& !mdTable.startsWith("UNKNOWN_") && !mdTable.startsWith("ORPHAN_");
|
||||
if (pageId != null && !pageId.isBlank() && !nb.addSvc().isBlank()
|
||||
&& (nb.hasInsert() || nb.hasUpdate()) && tableOk) {
|
||||
return buildEditableTreeMasterDetail(node, pageId, mdTable.toUpperCase(), nb,
|
||||
treeSchema, treeCompId, pageResolver, templateName, tree, result);
|
||||
}
|
||||
// 节点 buttons(增删改保存)→ input-tree 原生 editable/removable + 弹窗新增(管理页可编辑)。
|
||||
// 实体来自 <node entityid>(type=4 来自 treetemplate);source/reload 同源(currentTemplateId)。
|
||||
treeCrud = applyTreeNodeCrudFromNode(treeSchema, node, entityId,
|
||||
@@ -2162,6 +2398,212 @@ public class TemplateToAmisConverter {
|
||||
return page(treeGridTitle, hbox);
|
||||
}
|
||||
|
||||
/** type=3 声明式树节点的 buttons 解析结果:增/改/删能力 + 新增/删除服务流名。 */
|
||||
private record NodeButtons(boolean hasInsert, boolean hasUpdate, boolean hasDelete,
|
||||
String addSvc, String deleteSvc) {}
|
||||
|
||||
/**
|
||||
* 解析 {@code <node><buttons>} 的增删改保存按钮 → {@link NodeButtons}(增/改/删能力 + save/delete 服务流名)。
|
||||
* 与 master-detail 判定({@link #convertTree})和内联/工具栏 CRUD({@link #applyTreeNodeCrudFromNode})共用,
|
||||
* 避免按钮语义解析重复。{@code isshow='false'} 的按钮跳过;save 按钮携新增/更新服务名(addSvc)。
|
||||
*/
|
||||
private NodeButtons parseNodeButtons(Element node) {
|
||||
Element buttonsEl = node != null ? node.element("buttons") : null;
|
||||
boolean hasInsert = false, hasUpdate = false, hasDelete = false;
|
||||
String addSvc = "", deleteSvc = "";
|
||||
if (buttonsEl != null) {
|
||||
for (Element b : buttonsEl.elements("button")) {
|
||||
if ("false".equals(b.attributeValue("isshow"))) {
|
||||
continue;
|
||||
}
|
||||
String svc = b.elements("method").stream()
|
||||
.map(m -> m.attributeValue("servicename", ""))
|
||||
.filter(s -> !s.isBlank()).findFirst().orElse("");
|
||||
switch (b.attributeValue("type", "")) {
|
||||
case "insert" -> hasInsert = true;
|
||||
case "update" -> hasUpdate = true;
|
||||
case "delete" -> { hasDelete = true; if (!svc.isBlank()) deleteSvc = svc; }
|
||||
case "save" -> { if (!svc.isBlank()) addSvc = svc; } // 保存按钮携带新增/更新服务名
|
||||
default -> { }
|
||||
}
|
||||
}
|
||||
}
|
||||
return new NodeButtons(hasInsert, hasUpdate, hasDelete, addSvc, deleteSvc);
|
||||
}
|
||||
|
||||
/**
|
||||
* 一棵 type=3 树可能含多个 {@code <node>}:优先选含 {@code edit='true'} 且 {@code pageid} 的可编辑数据节点
|
||||
* (菜单维护根 node 在前但第一个即可编辑,新闻收藏分类仅一个 node;多 node 时稳妥选可编辑节点)。
|
||||
* 无可编辑节点 → 回退第一个 {@code <node>}(保持现有「取第一个」语义)。
|
||||
*/
|
||||
private Element selectEditableNode(Element tree) {
|
||||
Element first = tree.element("node");
|
||||
for (Element n : tree.elements("node")) {
|
||||
String pid = n.attributeValue("pageid", "");
|
||||
if ("true".equals(n.attributeValue("edit")) && pid != null && !pid.isBlank()) {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
/**
|
||||
* 可编辑 type=3 树 → master-detail:左树(选中节点驱动 {@code selId})+ 右「按 selId 载入的编辑表单」,
|
||||
* 取代旧「工具栏 + 弹窗」。右表单字段由 {@code pageId} 的 view_page 经 {@link #buildFormItemsFromPage}
|
||||
* (内部 {@link UiTypeMapper#mapField})忠实生成,与编辑表单页同源——不手写控件。
|
||||
*
|
||||
* <p>amis 形态(对齐 menu v5 bespoke):page → body=grid[左树 md=4, 右编辑 md=8];右列
|
||||
* = button-toolbar(添加/删除) + service(api=/api/entity/{TABLE}/${selId}, sendOn=${selId})
|
||||
* → body=form(api=post:/api/flow/{addSvc}, actions submit「保存」reload=树)。
|
||||
*
|
||||
* @param node 可编辑数据节点
|
||||
* @param pageId node@pageid(右编辑表单字段来源)
|
||||
* @param table 实体表名(大写,已校验非 UNKNOWN_/ORPHAN_)
|
||||
* @param nb 节点按钮解析结果(增/改/删 + addSvc/deleteSvc)
|
||||
* @param treeSchema 已构建的 input-tree 基底(含 source/virtualThreshold/id)
|
||||
* @param treeCompId 树组件 id(保存成功后 reload 它)
|
||||
* @param pageResolver pageid → view_page.xml 解析器(缺失则右表单退化空字段壳)
|
||||
* @param templateName page 标题
|
||||
* @param tree tree 根元素(标题回退用 rootname)
|
||||
*/
|
||||
private Map<String, Object> buildEditableTreeMasterDetail(Element node, String pageId, String table,
|
||||
NodeButtons nb, Map<String, Object> treeSchema,
|
||||
String treeCompId,
|
||||
Function<String, String> pageResolver,
|
||||
String templateName, Element tree,
|
||||
ConversionResult result) {
|
||||
String pk = table + "_ID";
|
||||
String entityId = node.attributeValue("entityid", "");
|
||||
|
||||
// ── 左树:复用 treeSchema,置 selId/label:false/可搜索展开 ──
|
||||
treeSchema.put("name", "selId");
|
||||
treeSchema.put("label", false);
|
||||
treeSchema.put("id", treeCompId);
|
||||
treeSchema.put("searchable", true);
|
||||
treeSchema.put("initiallyOpen", true);
|
||||
treeSchema.put("showOutline", true);
|
||||
treeSchema.put("heightAuto", true);
|
||||
|
||||
// ── 右表单字段(pageid → view_page,UiTypeMapper 忠实映射)──
|
||||
List<Map<String, Object>> formItems;
|
||||
try {
|
||||
formItems = buildFormItemsFromPage(pageId, entityId, pageResolver, result);
|
||||
} catch (Exception e) {
|
||||
result.degrade("tree(type=3) master-detail: 右表单 pageid=" + pageId
|
||||
+ " 解析失败(" + e.getClass().getSimpleName() + ") → 空字段壳");
|
||||
formItems = new ArrayList<>();
|
||||
}
|
||||
|
||||
String formId = table.toLowerCase() + "_editform";
|
||||
String formTitle = templateName != null ? templateName : "";
|
||||
|
||||
// 保存动作:submit → post /api/flow/{addSvc},成功 reload 左树
|
||||
Map<String, Object> submit = new LinkedHashMap<>();
|
||||
submit.put("type", "submit");
|
||||
submit.put("label", "保存");
|
||||
submit.put("level", "primary");
|
||||
submit.put("icon", "fa fa-save");
|
||||
submit.put("reload", treeCompId);
|
||||
|
||||
// form initApi:按选中节点主键 ${selId} 动态载入编辑表单数据,带 pageId 让后端把引用字段
|
||||
// (SelectDialog/MultiSelectDialog)解析为 {_id,_label} 对象——picker 自带 label 即显名,
|
||||
// 不依赖 source 补拉(spike 实证:service 包裹 picker 加载已存值只显裸 id;form initApi+对象值 → 显名)。
|
||||
// pageId 必须放 api.data(GET 时 amis 拼成 query 发出)——url 内联 ?pageId= amis 不可靠发出(spike 实证:
|
||||
// url-query 丢失致后端收不到 pageId、退化返裸 id)。sendOn=${selId} 使空选中(添加态)不触发坏请求。
|
||||
Map<String, Object> initApi = new LinkedHashMap<>();
|
||||
initApi.put("method", "get");
|
||||
initApi.put("url", "/api/entity/" + table + "/${selId}");
|
||||
Map<String, Object> initData = new LinkedHashMap<>();
|
||||
initData.put("pageId", pageId);
|
||||
initApi.put("data", initData);
|
||||
initApi.put("sendOn", "${selId}");
|
||||
|
||||
Map<String, Object> form = new LinkedHashMap<>();
|
||||
form.put("type", "form");
|
||||
form.put("id", formId);
|
||||
form.put("title", formTitle);
|
||||
form.put("mode", "horizontal");
|
||||
form.put("horizontal", new LinkedHashMap<>(Map.of("left", 3, "right", 8)));
|
||||
form.put("initApi", initApi);
|
||||
form.put("api", "post:/api/flow/" + nb.addSvc());
|
||||
form.put("body", formItems);
|
||||
form.put("actions", List.of(submit));
|
||||
|
||||
// ── 工具栏:添加(清空选中+清空表单)+ 删除(删选中节点) ──
|
||||
List<Map<String, Object>> toolbarBtns = new ArrayList<>();
|
||||
if (nb.hasInsert()) {
|
||||
// 添加:清空树选中(selId="") + 清空表单各字段值(开新增态)
|
||||
Map<String, Object> clearTree = new LinkedHashMap<>();
|
||||
clearTree.put("actionType", "setValue");
|
||||
clearTree.put("componentId", treeCompId);
|
||||
clearTree.put("args", new LinkedHashMap<>(Map.of("value", "")));
|
||||
Map<String, Object> emptyForm = new LinkedHashMap<>();
|
||||
for (Map<String, Object> fi : formItems) {
|
||||
Object fname = fi.get("name");
|
||||
if (fname != null && !String.valueOf(fname).isBlank()) {
|
||||
emptyForm.put(String.valueOf(fname), "");
|
||||
}
|
||||
}
|
||||
emptyForm.put(pk, ""); // 主键清空 → save 服务流按空主键走新增
|
||||
Map<String, Object> clearForm = new LinkedHashMap<>();
|
||||
clearForm.put("actionType", "setValue");
|
||||
clearForm.put("componentId", formId);
|
||||
clearForm.put("args", new LinkedHashMap<>(Map.of("value", emptyForm)));
|
||||
Map<String, Object> onClick = new LinkedHashMap<>(Map.of(
|
||||
"actions", List.of(clearTree, clearForm)));
|
||||
Map<String, Object> addBtn = new LinkedHashMap<>();
|
||||
addBtn.put("type", "button");
|
||||
addBtn.put("label", "添加");
|
||||
addBtn.put("level", "primary");
|
||||
addBtn.put("icon", "fa fa-plus");
|
||||
addBtn.put("onEvent", new LinkedHashMap<>(Map.of("click", onClick)));
|
||||
toolbarBtns.add(addBtn);
|
||||
}
|
||||
if (nb.hasDelete() && !nb.deleteSvc().isBlank()) {
|
||||
Map<String, Object> delApi = new LinkedHashMap<>();
|
||||
delApi.put("method", "post");
|
||||
delApi.put("url", "/api/flow/" + nb.deleteSvc());
|
||||
delApi.put("data", mapOf(pk, "${selId}"));
|
||||
Map<String, Object> delBtn = new LinkedHashMap<>();
|
||||
delBtn.put("type", "button");
|
||||
delBtn.put("label", "删除");
|
||||
delBtn.put("level", "danger");
|
||||
delBtn.put("icon", "fa fa-trash");
|
||||
delBtn.put("disabledOn", "${!selId}");
|
||||
delBtn.put("actionType", "ajax");
|
||||
delBtn.put("confirmText", "确认删除选中项?");
|
||||
delBtn.put("api", delApi);
|
||||
delBtn.put("reload", treeCompId);
|
||||
toolbarBtns.add(delBtn);
|
||||
}
|
||||
Map<String, Object> toolbar = new LinkedHashMap<>();
|
||||
toolbar.put("type", "button-toolbar");
|
||||
toolbar.put("className", "m-b-sm");
|
||||
toolbar.put("buttons", toolbarBtns);
|
||||
|
||||
// ── 两栏 grid:左树 md=4,右编辑区 md=8 ──
|
||||
Map<String, Object> leftCol = new LinkedHashMap<>();
|
||||
leftCol.put("md", 4);
|
||||
leftCol.put("columnClassName", "b-r pr-md");
|
||||
leftCol.put("body", List.of(treeSchema));
|
||||
|
||||
Map<String, Object> rightCol = new LinkedHashMap<>();
|
||||
rightCol.put("md", 8);
|
||||
rightCol.put("columnClassName", "pl-md");
|
||||
rightCol.put("body", List.of(toolbar, form));
|
||||
|
||||
Map<String, Object> grid = new LinkedHashMap<>();
|
||||
grid.put("type", "grid");
|
||||
grid.put("columns", List.of(leftCol, rightCol));
|
||||
|
||||
String title = templateName != null ? templateName
|
||||
: (tree.attributeValue("rootname") != null ? tree.attributeValue("rootname") : "树");
|
||||
result.note("tree(type=3) master-detail:左树(selId) + 右编辑表单(pageid=" + pageId + " 表=" + table
|
||||
+ " add=" + nb.addSvc() + " del=" + nb.deleteSvc() + " 字段=" + formItems.size()
|
||||
+ ") 取代工具栏+弹窗");
|
||||
return page(title, grid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 声明式树(type=3 管理页)节点增删改:{@code <node entityid><buttons>} 的增/改/删 → amis InputTree 原生
|
||||
* {@code editable}/{@code removable} + {@code editApi}/{@code deleteApi},新增走弹窗表单按钮。
|
||||
@@ -2186,23 +2628,9 @@ public class TemplateToAmisConverter {
|
||||
if (buttonsEl == null || buttonsEl.elements("button").isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
boolean hasInsert = false, hasUpdate = false, hasDelete = false;
|
||||
String addSvc = "", deleteSvc = "";
|
||||
for (Element b : buttonsEl.elements("button")) {
|
||||
if ("false".equals(b.attributeValue("isshow"))) {
|
||||
continue;
|
||||
}
|
||||
String svc = b.elements("method").stream()
|
||||
.map(m -> m.attributeValue("servicename", ""))
|
||||
.filter(s -> !s.isBlank()).findFirst().orElse("");
|
||||
switch (b.attributeValue("type", "")) {
|
||||
case "insert" -> hasInsert = true;
|
||||
case "update" -> hasUpdate = true;
|
||||
case "delete" -> { hasDelete = true; if (!svc.isBlank()) deleteSvc = svc; }
|
||||
case "save" -> { if (!svc.isBlank()) addSvc = svc; } // 保存按钮携带新增/更新服务名
|
||||
default -> { }
|
||||
}
|
||||
}
|
||||
NodeButtons nb = parseNodeButtons(node);
|
||||
boolean hasInsert = nb.hasInsert(), hasUpdate = nb.hasUpdate(), hasDelete = nb.hasDelete();
|
||||
String addSvc = nb.addSvc(), deleteSvc = nb.deleteSvc();
|
||||
String treeTable = resolveTableName(entityId, result);
|
||||
if (treeTable == null || treeTable.isBlank()
|
||||
|| treeTable.startsWith("UNKNOWN_") || treeTable.startsWith("ORPHAN_")) {
|
||||
@@ -2401,6 +2829,7 @@ public class TemplateToAmisConverter {
|
||||
parentField.put("label", "上级分类");
|
||||
parentField.put("source", "/api/template/" + treeRef + "/tree");
|
||||
parentField.put("clearable", true);
|
||||
parentField.put("searchable", true); // 大树下拉带搜索框,过滤层级节点
|
||||
parentField.put("placeholder", "留空 = 顶级分类");
|
||||
fields.add(parentField);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,17 @@ final class UiTypeMapper {
|
||||
case "NumberField" -> {
|
||||
item.put("type", "input-number");
|
||||
String mdec = f.attributeValue("mdec");
|
||||
if (mdec != null && !mdec.isBlank()) {
|
||||
// 列类型优先于 mdec:整型列(java.lang.Integer/Long/Short/BigInteger 等)即便 XML 误定义
|
||||
// mdec 小数位(如排序号 TYPESORT type=java.lang.Integer 却 mdec=2 → 旧版显「2.00」),也应整数输入
|
||||
// (precision=0 + step=1),不显小数。非整型(Double/BigDecimal)才按 mdec 取小数精度。
|
||||
String numType = f.attributeValue("type");
|
||||
boolean isInteger = numType != null && (numType.endsWith(".Integer") || numType.endsWith(".Long")
|
||||
|| numType.endsWith(".Short") || numType.endsWith(".BigInteger")
|
||||
|| "int".equals(numType) || "long".equals(numType) || "short".equals(numType));
|
||||
if (isInteger) {
|
||||
item.put("precision", 0);
|
||||
item.put("step", 1);
|
||||
} else if (mdec != null && !mdec.isBlank()) {
|
||||
try {
|
||||
item.put("precision", Integer.parseInt(mdec));
|
||||
} catch (NumberFormatException ignore) {
|
||||
@@ -115,7 +125,8 @@ final class UiTypeMapper {
|
||||
// 如采购明细 AMOUNT vmin=1 / PRICE vmax=9999999.99)。非数值则跳过(容错口径同 mdec)。
|
||||
applyNumberBound(item, "min", f.attributeValue("vmin"));
|
||||
applyNumberBound(item, "max", f.attributeValue("vmax"));
|
||||
result.note(origin + "@field " + name + " uitype=NumberField → input-number(precision=" + mdec
|
||||
result.note(origin + "@field " + name + " uitype=NumberField → input-number(type=" + numType
|
||||
+ (isInteger ? ", 整型 precision=0" : ", precision=" + mdec)
|
||||
+ ", min=" + f.attributeValue("vmin") + ", max=" + f.attributeValue("vmax") + ")");
|
||||
}
|
||||
case "CheckBox" -> {
|
||||
|
||||
@@ -111,6 +111,24 @@ class TemplateToAmisConverterTest {
|
||||
assertEquals(9999999.99, items.get(4).get("max"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void numberField_整型列优先_忽略mdec小数位() {
|
||||
// 列类型 java.lang.Integer 即便 XML 误定义 mdec=2(如排序号 TYPESORT),也应整数输入(precision=0+step=1),不显「2.00」
|
||||
String xml = "<crud entityid='e1'><display/><search>"
|
||||
+ "<field name='SORT' label='排序号' uitype='NumberField' type='java.lang.Integer' mdec='2'/>"
|
||||
+ "<field name='MONEY' label='金额' uitype='NumberField' type='java.lang.Double' mdec='2'/>"
|
||||
+ "</search></crud>";
|
||||
ConversionResult r = converter.convertGraded(xml, new ArrayList<>(), noPage);
|
||||
Map<String, Object> crud = body(r.getSchema());
|
||||
List<Map<String, Object>> items = (List<Map<String, Object>>) ((Map<String, Object>) crud.get("filter")).get("body");
|
||||
// 整型:precision=0 + step=1(覆盖 mdec=2)
|
||||
assertEquals(0, items.get(0).get("precision"), "整型列应 precision=0 覆盖 mdec");
|
||||
assertEquals(1, items.get(0).get("step"));
|
||||
// 非整型(Double):仍按 mdec=2
|
||||
assertEquals(2, items.get(1).get("precision"), "Double 列按 mdec 取小数精度");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修复(dogfooding):ComboBox 的 comboboxitemservice(查表的列表服务,非静态枚举)应指向
|
||||
* picker 选项端点而非 /api/poc/dict(后者仅认 SYS_ENUMERATE → 选项恒空)。合成搜索流 <TABLE>_SEARCH
|
||||
@@ -189,9 +207,36 @@ class TemplateToAmisConverterTest {
|
||||
Map<String, Object> parent = items.get(0);
|
||||
assertEquals("tree-select", parent.get("type"));
|
||||
assertEquals("/api/template/TREE1/tree", parent.get("source"));
|
||||
assertEquals(true, parent.get("searchable"), "大树 tree-select 应带搜索框(searchable)");
|
||||
assertNull(parent.get("pickerSchema")); // picker 专属键已清除
|
||||
}
|
||||
|
||||
/**
|
||||
* 大树过滤:type=3 树模板 → tree-select 须含 {@code searchable:true}(下拉带搜索框,过滤层级节点)。
|
||||
* 单独固化 searchable,避免后续改写丢失搜索能力。
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void selectDialog_树模板_treeSelect含searchable() {
|
||||
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||
lenient().when(jdbc.queryForObject(any(String.class), eq(String.class), any(Object[].class)))
|
||||
.thenReturn("PM_DEMO");
|
||||
lenient().when(jdbc.queryForObject(any(String.class), eq(Integer.class), any(Object[].class)))
|
||||
.thenReturn(3); // dialogid=TREE1 → type=3 树模板
|
||||
TemplateToAmisConverter c = new TemplateToAmisConverter(jdbc);
|
||||
|
||||
String xml = "<crud entityid='e1'><display/>"
|
||||
+ "<search><field name='PARENTID' label='上级菜单' uitype='SelectDialog' dialogid='TREE1'/></search>"
|
||||
+ "</crud>";
|
||||
ConversionResult r = c.convertGraded(xml, new ArrayList<>(), noPage);
|
||||
Map<String, Object> crud = body(r.getSchema());
|
||||
Map<String, Object> filter = (Map<String, Object>) crud.get("filter");
|
||||
List<Map<String, Object>> items = (List<Map<String, Object>>) filter.get("body");
|
||||
Map<String, Object> parent = items.get(0);
|
||||
assertEquals("tree-select", parent.get("type"));
|
||||
assertEquals(true, parent.get("searchable"), "type=3 SelectDialog → tree-select 应含 searchable:true");
|
||||
}
|
||||
|
||||
/** 不回归:dialogid 指向非树模板(type≠3)的 SelectDialog 仍转扁平 picker。 */
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -214,6 +259,113 @@ class TemplateToAmisConverterTest {
|
||||
assertEquals("/api/picker/LIST1/list", items.get(0).get("source"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 树+grid 选择框:可编辑 SelectDialog 的 dialogid 指向 type=4「树+grid」模板({@code <treetemplate ref/>}
|
||||
* + {@code <gridtemplate ref/ entityid/ rcolumnname/>},如「功能管理」)→ 改写为 picker,弹窗内 =
|
||||
* 左分类树过滤(tree-select name=rcol source=左树端点)+ 右 CRUD 表格(source=treegrid 子树聚合端点,
|
||||
* node=${rcol}),列取自 gridtemplate display,labelField=_label,valueField=_id(提交仍裸 id)。
|
||||
* 降级规则:通用 + 自定义 type=4 全走此路(不看 engineclass)。
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void selectDialog_dialogid指向type4树grid模板_转tree加grid的picker() {
|
||||
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||
// queryForObject(Integer) → dialog 模板 type=4
|
||||
lenient().when(jdbc.queryForObject(any(String.class), eq(Integer.class), any(Object[].class)))
|
||||
.thenReturn(4);
|
||||
// queryForObject(String) → resolveTableName(gridEntityId='ge') 取实体表名
|
||||
lenient().when(jdbc.queryForObject(any(String.class), eq(String.class), any(Object[].class)))
|
||||
.thenReturn("VIEW_TEMPLATE");
|
||||
// queryForList(xml::text) by ref:dialogid=TG4 → 树+grid 结构;gridRef=GREF → 右表 display
|
||||
lenient().when(jdbc.queryForList(any(String.class), eq(String.class), any(Object[].class)))
|
||||
.thenAnswer(inv -> {
|
||||
// 末位参数=绑定值(varargs):可能被 Mockito 摊为单值或数组,统一摊平找 ref。
|
||||
Object[] all = inv.getArguments();
|
||||
Object last = all[all.length - 1];
|
||||
String ref = last instanceof Object[] arr && arr.length > 0
|
||||
? String.valueOf(arr[0]) : String.valueOf(last);
|
||||
if ("TG4".equals(ref)) {
|
||||
return List.of("<tree>"
|
||||
+ "<treetemplate ref='TREF' entityid='te'/>"
|
||||
+ "<gridtemplate ref='GREF' entityid='ge' rcolumnname='ENTITYTYPE'/>"
|
||||
+ "</tree>");
|
||||
}
|
||||
if ("GREF".equals(ref)) {
|
||||
return List.of("<crud entityid='ge'><display>"
|
||||
+ "<field name='NAME' text='功能名称'/>"
|
||||
+ "<field name='TYPE' text='类型'/>"
|
||||
+ "</display></crud>");
|
||||
}
|
||||
return List.of();
|
||||
});
|
||||
TemplateToAmisConverter c = new TemplateToAmisConverter(jdbc);
|
||||
|
||||
String xml = "<crud entityid='e1'><display/>"
|
||||
+ "<search><field name='VIEW_TEMPLATEID' label='功能' uitype='SelectDialog' dialogid='TG4'/></search>"
|
||||
+ "</crud>";
|
||||
ConversionResult r = c.convertGraded(xml, new ArrayList<>(), noPage);
|
||||
Map<String, Object> crud = body(r.getSchema());
|
||||
Map<String, Object> filter = (Map<String, Object>) crud.get("filter");
|
||||
List<Map<String, Object>> items = (List<Map<String, Object>>) filter.get("body");
|
||||
Map<String, Object> picker = items.get(0);
|
||||
|
||||
// 仍是 picker(非 tree-select、非扁平 /api/picker),数据源为 treegrid 子树聚合端点
|
||||
assertEquals("picker", picker.get("type"), "type=4 选择框应为 tree+grid picker");
|
||||
assertEquals("_id", picker.get("valueField"), "提交值仍裸主键 _id");
|
||||
assertEquals("_label", picker.get("labelField"), "选中显示绑统一显示值 _label");
|
||||
String source = String.valueOf(picker.get("source"));
|
||||
assertTrue(source.startsWith("/api/template/treegrid?"), "右表走 treegrid 子树聚合端点: " + source);
|
||||
assertTrue(source.contains("gridTable=VIEW_TEMPLATE"), "右表实体来自 gridtemplate: " + source);
|
||||
assertTrue(source.contains("rcol=ENTITYTYPE"), "过滤列来自 rcolumnname: " + source);
|
||||
assertTrue(source.contains("node=${ENTITYTYPE}"), "node 取分类 tree-select 当前值: " + source);
|
||||
assertTrue(source.contains("treeRef=TREF"), "treeRef 来自 treetemplate: " + source);
|
||||
|
||||
// pickerSchema:左分类树过滤 + 右表列
|
||||
Map<String, Object> ps = (Map<String, Object>) picker.get("pickerSchema");
|
||||
assertNotNull(ps, "应有 pickerSchema");
|
||||
assertEquals("table", ps.get("mode"));
|
||||
Map<String, Object> psFilter = (Map<String, Object>) ps.get("filter");
|
||||
assertNotNull(psFilter, "弹窗内应有分类树过滤器");
|
||||
List<Map<String, Object>> filterBody = (List<Map<String, Object>>) psFilter.get("body");
|
||||
Map<String, Object> treeSel = filterBody.get(0);
|
||||
assertEquals("tree-select", treeSel.get("type"), "过滤器是分类 tree-select");
|
||||
assertEquals("ENTITYTYPE", treeSel.get("name"), "tree-select 绑过滤列 rcol");
|
||||
assertEquals("/api/template/TREF/tree", treeSel.get("source"), "分类树 source 指 treetemplate 树端点");
|
||||
List<Map<String, Object>> cols = (List<Map<String, Object>>) ps.get("columns");
|
||||
assertNotNull(cols, "右表列取自 gridtemplate display");
|
||||
assertEquals("NAME", cols.get(0).get("name"));
|
||||
assertEquals("功能名称", cols.get(0).get("label"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 不回归:type=4 树+grid 结构缺失(dialog XML 无 treetemplate/gridtemplate)→ 保留扁平 picker 基线,
|
||||
* 不误改写、不抛错。
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void selectDialog_type4但结构缺失_保留扁平picker基线() {
|
||||
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||
lenient().when(jdbc.queryForObject(any(String.class), eq(Integer.class), any(Object[].class)))
|
||||
.thenReturn(4);
|
||||
lenient().when(jdbc.queryForObject(any(String.class), eq(String.class), any(Object[].class)))
|
||||
.thenReturn("PM_DEMO");
|
||||
// dialog XML 不是标准 tree+grid(无 treetemplate/gridtemplate)
|
||||
lenient().when(jdbc.queryForList(any(String.class), eq(String.class), any(Object[].class)))
|
||||
.thenReturn(List.of("<tree><node entityid='ne'/></tree>"));
|
||||
TemplateToAmisConverter c = new TemplateToAmisConverter(jdbc);
|
||||
|
||||
String xml = "<crud entityid='e1'><display/>"
|
||||
+ "<search><field name='REF' label='引用' uitype='SelectDialog' dialogid='TG4'/></search>"
|
||||
+ "</crud>";
|
||||
ConversionResult r = c.convertGraded(xml, new ArrayList<>(), noPage);
|
||||
Map<String, Object> crud = body(r.getSchema());
|
||||
Map<String, Object> filter = (Map<String, Object>) crud.get("filter");
|
||||
List<Map<String, Object>> items = (List<Map<String, Object>>) filter.get("body");
|
||||
Map<String, Object> picker = items.get(0);
|
||||
assertEquals("picker", picker.get("type"));
|
||||
assertEquals("/api/picker/TG4/list", picker.get("source"), "结构缺失应保留 UiTypeMapper 扁平 picker 基线");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修复:ComboBox 非 _SEARCH 命名的列表服务(推不出实体表)→ 经 sys_serviceflow.entityid 解析数据源实体
|
||||
* → /api/picker/{实体}/list(而非保底空字典)。mock jdbc 返 PM_DEMO 作实体表。
|
||||
@@ -972,6 +1124,15 @@ class TemplateToAmisConverterTest {
|
||||
assertEquals("button", addBtn.get("type"));
|
||||
assertEquals("新增分类", addBtn.get("label"));
|
||||
assertEquals("dialog", addBtn.get("actionType"));
|
||||
// 弹窗内「上级分类」选择器 = tree-select 且带搜索框(大树过滤)
|
||||
Map<String, Object> dialog = (Map<String, Object>) addBtn.get("dialog");
|
||||
Map<String, Object> addForm = (Map<String, Object>) dialog.get("body");
|
||||
List<Map<String, Object>> addFields = (List<Map<String, Object>>) addForm.get("body");
|
||||
Map<String, Object> parentSel = addFields.stream()
|
||||
.filter(it -> "tree-select".equals(it.get("type")))
|
||||
.findFirst().orElse(null);
|
||||
assertNotNull(parentSel, "新增弹窗应含上级分类 tree-select");
|
||||
assertEquals(true, parentSel.get("searchable"), "上级分类 tree-select 应带搜索框(searchable)");
|
||||
// 树本体:可编辑/可删 + source 走 TemplateTreeController(修 undefined)
|
||||
assertEquals("input-tree", tree.get("type"));
|
||||
assertEquals("/api/template/a763d48d-tmpl/tree", tree.get("source"),
|
||||
@@ -986,13 +1147,182 @@ class TemplateToAmisConverterTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单维护 dogfooding:type=3 管理树的节点 <node pageid> 指向真实编辑页时,节点 CRUD 应升级为
|
||||
* 老系统式「工具栏(新增/修改/删除) + 树」——选中节点后修改/删除作用其上,修改打开全字段表单(initApi 载入
|
||||
* 选中节点数据)。树包进无面板 form 使选中值 ${tree} 可被工具栏按钮引用;不再用内联 editable/removable。
|
||||
* 可编辑 type=3 树(pageid + buttons 有 save 服务名)→ master-detail(左树 + 右「选中节点载入的编辑表单」),
|
||||
* 取代「工具栏 + 弹窗」。右表单字段由 pageid 的 view_page 经 UiTypeMapper.mapField 忠实生成
|
||||
* (SelectDialog+dialogid → picker,TextField → input-text)。
|
||||
*
|
||||
* <p>判定条件:{@code pageId 非空 且 addSvc 非空 且 (hasInsert||hasUpdate)}(不强制 edit='true',
|
||||
* 真实可编辑分类树节点既有 edit=true 也有靠 buttons 表达;isroot 且 edit=false 的纯根 selectservice
|
||||
* 节点无 pageid,自然不走)。
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void tree_type3带pageid_工具栏增改删全表单() throws Exception {
|
||||
void tree_type3_edit可编辑树_pageid_生成masterDetail() throws Exception {
|
||||
TemplateToAmisConverter c = converterWithMeta(new String[0][], new String[0][]); // resolveTableName→PM_DEMO
|
||||
String xml = "<tree rootname='新闻收藏分类'>"
|
||||
+ "<node entityid='e1' selectservice='OA_X_SEARCH' isroot='true' edit='true' pageid='PAGE1'>"
|
||||
+ "<buttons>"
|
||||
+ "<button name='添加' type='insert'/>"
|
||||
+ "<button name='修改' type='update'/>"
|
||||
+ "<button name='删除' type='delete'><method servicename='OA_X_DELETE'/></button>"
|
||||
+ "<button name='保存' type='save'><method servicename='OA_X_ADD'/></button>"
|
||||
+ "</buttons></node></tree>";
|
||||
Function<String, String> resolver = pid -> "PAGE1".equals(pid)
|
||||
? "<page entityid='e1'><fields>"
|
||||
+ "<field name='TYPENAME' label='类别名称' uitype='TextField'/>"
|
||||
+ "<field name='MENUROOT' label='根级菜单' uitype='SelectDialog' dialogid='D1'/>"
|
||||
+ "</fields></page>"
|
||||
: null;
|
||||
ConversionResult r = c.convertGraded(xml, "TID", "新闻收藏分类", new ArrayList<>(), resolver);
|
||||
assertEquals("tree", r.getRootElement());
|
||||
|
||||
// 顶层 = page → body = grid(2 列:左树 md=4,右编辑区 md=8)
|
||||
Map<String, Object> grid = body(r.getSchema());
|
||||
assertEquals("grid", grid.get("type"), "可编辑树 master-detail:body 应是 grid 两栏");
|
||||
List<Map<String, Object>> cols = (List<Map<String, Object>>) grid.get("columns");
|
||||
assertEquals(2, cols.size(), "应有左树/右编辑两列");
|
||||
|
||||
// 左列:input-tree(source=/api/template/TID/tree, name=selId)
|
||||
List<Map<String, Object>> leftBody = (List<Map<String, Object>>) cols.get(0).get("body");
|
||||
Map<String, Object> leftTree = null;
|
||||
for (Map<String, Object> it : leftBody) {
|
||||
if ("input-tree".equals(it.get("type"))) {
|
||||
leftTree = it;
|
||||
}
|
||||
}
|
||||
assertNotNull(leftTree, "左列应含 input-tree");
|
||||
assertEquals("/api/template/TID/tree", leftTree.get("source"));
|
||||
assertEquals("selId", leftTree.get("name"), "树绑 selId(选中节点主键驱动右表)");
|
||||
assertEquals(false, leftTree.get("label"));
|
||||
assertEquals(100000, leftTree.get("virtualThreshold"));
|
||||
|
||||
// 右列:button-toolbar(含 删除)+ form(initApi 动态载入选中节点 + UiTypeMapper 字段)
|
||||
List<Map<String, Object>> rightBody = (List<Map<String, Object>>) cols.get(1).get("body");
|
||||
Map<String, Object> toolbar = null;
|
||||
Map<String, Object> form = null;
|
||||
for (Map<String, Object> it : rightBody) {
|
||||
if ("button-toolbar".equals(it.get("type"))) {
|
||||
toolbar = it;
|
||||
}
|
||||
if ("form".equals(it.get("type"))) {
|
||||
form = it;
|
||||
}
|
||||
}
|
||||
assertNotNull(toolbar, "右列应含 button-toolbar");
|
||||
assertNotNull(form, "右列应直接含 form(initApi 动态载入,不再 service 包裹)");
|
||||
|
||||
// 工具栏:删除按钮 → ajax /api/flow/OA_X_DELETE,data 含 PK=${selId}
|
||||
List<Map<String, Object>> tbBtns = (List<Map<String, Object>>) toolbar.get("buttons");
|
||||
Map<String, Object> delBtn = null;
|
||||
Map<String, Object> addBtn = null;
|
||||
for (Map<String, Object> b : tbBtns) {
|
||||
if ("删除".equals(b.get("label"))) {
|
||||
delBtn = b;
|
||||
}
|
||||
if ("添加".equals(b.get("label"))) {
|
||||
addBtn = b;
|
||||
}
|
||||
}
|
||||
assertNotNull(addBtn, "工具栏含 添加(清空表单开新增)");
|
||||
assertNotNull(delBtn, "工具栏含 删除");
|
||||
assertEquals("ajax", delBtn.get("actionType"));
|
||||
Map<String, Object> delApi = (Map<String, Object>) delBtn.get("api");
|
||||
assertEquals("/api/flow/OA_X_DELETE", delApi.get("url"));
|
||||
assertEquals("${selId}", ((Map<String, Object>) delApi.get("data")).get("PM_DEMO_ID"));
|
||||
|
||||
// form.initApi:按选中节点主键动态载入 /api/entity/PM_DEMO/${selId}, data.pageId=PAGE1, sendOn=${selId}
|
||||
// (pageId 放 data——GET 时 amis 拼成 query 发出;url 内联 ?pageId= amis 不可靠发出。让后端把引用字段
|
||||
// 解析为 {_id,_label} 对象,picker 自带 label 即显名)
|
||||
assertEquals("form", form.get("type"));
|
||||
Map<String, Object> initApi = (Map<String, Object>) form.get("initApi");
|
||||
assertNotNull(initApi, "form 应有 initApi(替代旧 service 包裹)");
|
||||
assertEquals("/api/entity/PM_DEMO/${selId}", initApi.get("url"));
|
||||
Map<String, Object> initData = (Map<String, Object>) initApi.get("data");
|
||||
assertNotNull(initData, "initApi 应把 pageId 放 data(GET 拼 query),而非 url 内联");
|
||||
assertEquals("PAGE1", initData.get("pageId"));
|
||||
assertEquals("${selId}", initApi.get("sendOn"));
|
||||
assertEquals("get", initApi.get("method"));
|
||||
|
||||
// form:api=post:/api/flow/OA_X_ADD(保存),actions submit label 保存
|
||||
assertEquals("post:/api/flow/OA_X_ADD", form.get("api"));
|
||||
List<Map<String, Object>> actions = (List<Map<String, Object>>) form.get("actions");
|
||||
Map<String, Object> submit = actions.get(0);
|
||||
assertEquals("submit", submit.get("type"));
|
||||
assertEquals("保存", submit.get("label"));
|
||||
|
||||
// form.body:UiTypeMapper 忠实字段——TYPENAME=input-text,MENUROOT(SelectDialog+dialogid)=picker
|
||||
List<Map<String, Object>> formItems = (List<Map<String, Object>>) form.get("body");
|
||||
Map<String, Object> byName = new java.util.HashMap<>();
|
||||
for (Map<String, Object> it : formItems) {
|
||||
byName.put(String.valueOf(it.get("name")), it.get("type"));
|
||||
}
|
||||
assertEquals("input-text", byName.get("TYPENAME"), "TextField → input-text");
|
||||
assertEquals("picker", byName.get("MENUROOT"), "SelectDialog+dialogid → picker(弹出框)");
|
||||
// 注:grid 列 body 用数组(多子节点)= 严格对齐 menu v5 bespoke(sys_page_schema 直存形态,
|
||||
// amis 运行时支持),与闸一(amis 6.13 schema 把 column.body 类型为单 SchemaObject)的严格度不一致——
|
||||
// bespoke 本身亦不过严格闸一,故此处不挂 SchemaGate 断言(保持与 live 一致)。
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单维护:一棵 tree 含多个 <node>——可编辑数据节点(edit=true + pageid)+ 纯根节点
|
||||
* (isroot=true edit=false selectservice,无 pageid)。须选可编辑节点作 master-detail 数据节点,
|
||||
* 根节点不被误当可编辑(其无 pageid,单独时不会走 master-detail)。
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void tree_type3多node_选可编辑节点作masterDetail() throws Exception {
|
||||
TemplateToAmisConverter c = converterWithMeta(new String[0][], new String[0][]);
|
||||
// 真实菜单维护形态:第一个 node 即可编辑(edit=true pageid),根 node(edit=false 无 pageid)在后
|
||||
String xml = "<tree rootname='菜单维护'>"
|
||||
+ "<node entityid='e1' edit='true' pageid='PAGE1'>"
|
||||
+ "<buttons>"
|
||||
+ "<button name='添加' type='insert'/>"
|
||||
+ "<button name='修改' type='update'/>"
|
||||
+ "<button name='删除' type='delete'><method servicename='SYS_MENU_DELETE'/></button>"
|
||||
+ "<button name='保存' type='save'><method servicename='SYS_MENU_ADD'/></button>"
|
||||
+ "</buttons></node>"
|
||||
+ "<node entityid='e1' isroot='true' edit='false' selectservice='SYS_MENU_ROOT_SEARCH'/>"
|
||||
+ "</tree>";
|
||||
ConversionResult r = c.convertGraded(xml, "menu-tmpl", "菜单维护", new ArrayList<>(), noPage);
|
||||
Map<String, Object> grid = body(r.getSchema());
|
||||
assertEquals("grid", grid.get("type"), "多 node 时选可编辑节点(edit=true+pageid)走 master-detail");
|
||||
List<Map<String, Object>> cols = (List<Map<String, Object>>) grid.get("columns");
|
||||
List<Map<String, Object>> rightBody = (List<Map<String, Object>>) cols.get(1).get("body");
|
||||
Map<String, Object> form = null;
|
||||
for (Map<String, Object> it : rightBody) {
|
||||
if ("form".equals(it.get("type"))) {
|
||||
form = it;
|
||||
}
|
||||
}
|
||||
assertNotNull(form);
|
||||
assertEquals("post:/api/flow/SYS_MENU_ADD", form.get("api"),
|
||||
"右表单保存到可编辑节点的 save 服务流");
|
||||
}
|
||||
|
||||
/**
|
||||
* 纯根节点树(isroot=true edit=false selectservice,无 pageid、无 buttons save)不被误判为可编辑——
|
||||
* 不走 master-detail,保持只读树壳。
|
||||
*/
|
||||
@Test
|
||||
void tree_type3纯根节点_不走masterDetail() throws Exception {
|
||||
TemplateToAmisConverter c = converterWithMeta(new String[0][], new String[0][]);
|
||||
String xml = "<tree rootname='菜单根'>"
|
||||
+ "<node entityid='e1' isroot='true' edit='false' selectservice='SYS_MENU_ROOT_SEARCH'/>"
|
||||
+ "</tree>";
|
||||
ConversionResult r = c.convertGraded(xml, "menu-tmpl", "菜单维护", new ArrayList<>(), noPage);
|
||||
Map<String, Object> b = body(r.getSchema());
|
||||
assertFalse("grid".equals(b.get("type")), "纯根节点(无 pageid/save)不应走 master-detail");
|
||||
assertEquals("input-tree", b.get("type"), "纯根节点保持只读树壳");
|
||||
}
|
||||
|
||||
/**
|
||||
* type=3 树的节点含 pageid + buttons(有 save 服务名) + insert/update → 走 master-detail(左树 + 右编辑表单),
|
||||
* 取代旧「工具栏 + 弹窗」。判定不强制 edit='true':pageId 非空 + addSvc 非空 + (hasInsert||hasUpdate) 即成立。
|
||||
* resolver 缺失(noPage)时右表单退化为空字段壳,但 master-detail 骨架(grid 两栏 + service + 删除按钮)仍成立。
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void tree_type3带pageid_生成masterDetail() throws Exception {
|
||||
TemplateToAmisConverter c = converterWithMeta(new String[0][], new String[0][]);
|
||||
String xml = "<tree rootname='菜单'>"
|
||||
+ "<node entityid='e1' pageid='PAGE1' isroot='true'>"
|
||||
@@ -1004,40 +1334,56 @@ class TemplateToAmisConverterTest {
|
||||
+ "</buttons><nextnodes/></node></tree>";
|
||||
ConversionResult r = c.convertGraded(xml, "menu-tmpl", "菜单维护", new ArrayList<>(), noPage);
|
||||
assertEquals("tree", r.getRootElement());
|
||||
Map<String, Object> form = body(r.getSchema());
|
||||
assertEquals("form", form.get("type"), "工具栏+树须包进 form(选中值 ${tree} 供工具栏引用)");
|
||||
List<Map<String, Object>> fb = (List<Map<String, Object>>) form.get("body");
|
||||
// 末项=树本体,去内联编辑
|
||||
Map<String, Object> tree = fb.get(fb.size() - 1);
|
||||
assertEquals("input-tree", tree.get("type"));
|
||||
assertEquals("/api/template/menu-tmpl/tree", tree.get("source"));
|
||||
assertNull(tree.get("editable"), "工具栏模式不再内联改名");
|
||||
assertNull(tree.get("removable"), "工具栏模式不再内联删除");
|
||||
// 工具栏按钮:按 label 收集
|
||||
Map<String, Map<String, Object>> byLabel = new java.util.HashMap<>();
|
||||
for (Map<String, Object> it : fb) {
|
||||
if ("button".equals(it.get("type"))) {
|
||||
byLabel.put(String.valueOf(it.get("label")), it);
|
||||
Map<String, Object> grid = body(r.getSchema());
|
||||
assertEquals("grid", grid.get("type"), "pageid+save → master-detail(grid 两栏),不再工具栏+弹窗");
|
||||
List<Map<String, Object>> cols = (List<Map<String, Object>>) grid.get("columns");
|
||||
assertEquals(2, cols.size());
|
||||
|
||||
// 左树 source/selId
|
||||
List<Map<String, Object>> leftBody = (List<Map<String, Object>>) cols.get(0).get("body");
|
||||
Map<String, Object> leftTree = null;
|
||||
for (Map<String, Object> it : leftBody) {
|
||||
if ("input-tree".equals(it.get("type"))) {
|
||||
leftTree = it;
|
||||
}
|
||||
}
|
||||
assertTrue(byLabel.containsKey("新增"), "工具栏含 新增");
|
||||
assertTrue(byLabel.containsKey("修改"), "工具栏含 修改");
|
||||
assertTrue(byLabel.containsKey("删除"), "工具栏含 删除");
|
||||
// 修改:无选中禁用 + 弹窗 service.api 载入选中节点 /api/entity/PM_DEMO/${tree}
|
||||
Map<String, Object> edit = byLabel.get("修改");
|
||||
assertEquals("${!tree}", edit.get("disabledOn"));
|
||||
Map<String, Object> editDialog = (Map<String, Object>) edit.get("dialog");
|
||||
Map<String, Object> editService = (Map<String, Object>) editDialog.get("body");
|
||||
assertEquals("get:/api/page/schema/PAGE1?format=amis", editService.get("schemaApi"));
|
||||
Map<String, Object> editApi = (Map<String, Object>) editService.get("api");
|
||||
assertEquals("/api/entity/PM_DEMO/${tree}", editApi.get("url"));
|
||||
// 删除:无选中禁用 + ajax 删除服务流,pk=${tree}
|
||||
Map<String, Object> del = byLabel.get("删除");
|
||||
assertEquals("${!tree}", del.get("disabledOn"));
|
||||
assertEquals("ajax", del.get("actionType"));
|
||||
assertNotNull(leftTree);
|
||||
assertEquals("/api/template/menu-tmpl/tree", leftTree.get("source"));
|
||||
assertEquals("selId", leftTree.get("name"));
|
||||
|
||||
// 右列 form.initApi:动态载入选中节点 /api/entity/PM_DEMO/${selId}?pageId=PAGE1;form 保存到 SYS_MENU_ADD
|
||||
List<Map<String, Object>> rightBody = (List<Map<String, Object>>) cols.get(1).get("body");
|
||||
Map<String, Object> form = null;
|
||||
Map<String, Object> toolbar = null;
|
||||
for (Map<String, Object> it : rightBody) {
|
||||
if ("form".equals(it.get("type"))) {
|
||||
form = it;
|
||||
}
|
||||
if ("button-toolbar".equals(it.get("type"))) {
|
||||
toolbar = it;
|
||||
}
|
||||
}
|
||||
assertNotNull(form);
|
||||
Map<String, Object> initApi = (Map<String, Object>) form.get("initApi");
|
||||
assertNotNull(initApi);
|
||||
assertEquals("/api/entity/PM_DEMO/${selId}", initApi.get("url"));
|
||||
assertEquals("PAGE1", ((Map<String, Object>) initApi.get("data")).get("pageId"));
|
||||
assertEquals("${selId}", initApi.get("sendOn"));
|
||||
assertEquals("post:/api/flow/SYS_MENU_ADD", form.get("api"));
|
||||
|
||||
// 删除按钮 → SYS_MENU_DELETE,PK=${selId}
|
||||
assertNotNull(toolbar);
|
||||
List<Map<String, Object>> tbBtns = (List<Map<String, Object>>) toolbar.get("buttons");
|
||||
Map<String, Object> del = null;
|
||||
for (Map<String, Object> b : tbBtns) {
|
||||
if ("删除".equals(b.get("label"))) {
|
||||
del = b;
|
||||
}
|
||||
}
|
||||
assertNotNull(del);
|
||||
Map<String, Object> delApi = (Map<String, Object>) del.get("api");
|
||||
assertEquals("/api/flow/SYS_MENU_DELETE", delApi.get("url"));
|
||||
assertEquals("${tree}", ((Map<String, Object>) delApi.get("data")).get("PM_DEMO_ID"));
|
||||
assertEquals("${selId}", ((Map<String, Object>) delApi.get("data")).get("PM_DEMO_ID"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -89,6 +89,11 @@ public class FlowInputCoercer {
|
||||
if (flowId == null || flowId.isBlank() || map == null || map.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// 引用 picker 对象值扁平化:master-detail/编辑表单经 form initApi 把引用字段载为 {_id,_label}
|
||||
// 对象(picker 自带 label 即显名)。amis picker 仅在用户「重新选值」时按 valueField=_id 提取裸 id;
|
||||
// 「载入后不动直接保存」时整个对象原样进 payload → 引擎收到 Map 而非裸 id 必坏。故写流前统一把
|
||||
// {_id,...} 形态对象就地降为其 _id 裸值(与 valueField=_id 提交语义一致),与表名解析无关先行。
|
||||
flattenPickerObjects(map);
|
||||
// 先从缓存取 tableName;缓存未命中则查 contentxml
|
||||
String tableName = flowTableCache.get(flowId, this::resolveTableNameByFlowId);
|
||||
if (tableName.isEmpty()) {
|
||||
@@ -114,6 +119,8 @@ public class FlowInputCoercer {
|
||||
if (contentXml == null || contentXml.isBlank() || map == null || map.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// 引用 picker {_id,_label} 对象 → 裸 _id(见 coerceByFlowId 注释;与表名解析无关先行)
|
||||
flattenPickerObjects(map);
|
||||
String tableName = extractTableName(contentXml);
|
||||
if (tableName == null) {
|
||||
return; // 无固定 tableName(如跨表流),不做 coerce
|
||||
@@ -125,6 +132,26 @@ public class FlowInputCoercer {
|
||||
applyCoerce(map, colTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 引用 picker 对象值就地扁平化:把 {@code {_id,_label}} 形态的 Map 值降为其 {@code _id} 裸值
|
||||
* (与 amis picker {@code valueField=_id} 提交语义一致)。仅处理「含 {@code _id} 键的 Map」,
|
||||
* 其它结构化值(数组/普通 Map)不动;{@code _id} 为 String 时去尾补白(CHAR 主键对齐)。
|
||||
*
|
||||
* <p>背景:master-detail 右编辑表单经 {@code form initApi} 把引用字段载为对象(picker 自带 label
|
||||
* 即显名,spike 实证只此可靠显名);「载入后不改直接保存」时 amis 不触发 valueField 提取 → 整个对象
|
||||
* 进 payload。本扁平化是后端唯一收口点(零前端改动),保证引擎收到的引用列恒为裸 id。fail-safe:
|
||||
* 任何异常都不抛、不阻断写。
|
||||
*/
|
||||
static void flattenPickerObjects(Map<String, Object> map) {
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
Object val = entry.getValue();
|
||||
if (val instanceof Map<?, ?> obj && obj.containsKey("_id")) {
|
||||
Object id = obj.get("_id");
|
||||
entry.setValue(id instanceof String s ? s.stripTrailing() : id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 遍历 map,按 colTypes 就地强制转换 String 值为目标 Java 类型。 */
|
||||
private void applyCoerce(Map<String, Object> map, Map<String, String> colTypes) {
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
@@ -137,6 +164,17 @@ public class FlowInputCoercer {
|
||||
if (refId == null) {
|
||||
continue; // 元数据无此列,不动
|
||||
}
|
||||
// 空串 → null(写路径通用修复,列类型感知,见 emptyToNull):amis 表单里未选的
|
||||
// select/picker/tree-select、未赋默认值的隐藏框提交 "" 空串而非 null。FK/PK/数字/日期列
|
||||
// 吃空串 → 保存失败(FK 「功能引用的对象被删除」、PK "" 致 isSave 误判走 update、数字列
|
||||
// (Integer)"" cast 崩)。对齐老语义(老前端未选字段直接省略键 = null,引擎 INSERT 跳过该列
|
||||
// 走 DB 默认/可空、PK null 则自动生成 UUID)。先判空串再 coerce:空串决定 null 后无需再 parse。
|
||||
if (((String) val).trim().isEmpty()) {
|
||||
if (emptyToNull(refId, colUpper)) {
|
||||
entry.setValue(null);
|
||||
}
|
||||
continue; // 空串列处理完毕(不论是否 nullify,都无需走类型 coerce)
|
||||
}
|
||||
Object coerced = coerceValue((String) val, refId, colUpper);
|
||||
if (coerced != val) { // 引用变了才更新
|
||||
entry.setValue(coerced);
|
||||
@@ -144,6 +182,49 @@ public class FlowInputCoercer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 已知非 id 文本 DisplayType(自由文本列),其空串<b>不</b>转 null(保留老语义:老引擎把空文本
|
||||
* 存为 {@code ''},且部分 NOT NULL 文本列以空串为合法默认)。其余一律 ""→null。
|
||||
*/
|
||||
private static final java.util.Set<String> TEXT_DISPLAY_TYPES = java.util.Set.of("NVARCHAR", "CODE");
|
||||
|
||||
/**
|
||||
* 列类型感知的「空串 → null」判定:决定某列的 {@code ""} 是否应转 null。
|
||||
*
|
||||
* <p><b>转 null(true)</b>——本次修复核心:
|
||||
* <ul>
|
||||
* <li>非文本类型列:{@code INTEGER/ENUMERATE/STATUS}(数字)、{@code DECIMAL/MONEY}(小数)、
|
||||
* {@code BOOLEAN}、{@code DATE/TIME}(日期)——空串无法 cast/parse,老引擎 {@code (Integer)""}
|
||||
* 直接 ClassCastException 崩。</li>
|
||||
* <li>FK/引用列:referenceid 是 36 位实体 UUID(指向另一实体),空串 → FK 约束违反
|
||||
* (「功能引用的对象被删除」根因)。</li>
|
||||
* <li>PK / id 列:列名以 {@code _ID} 结尾({@code CHAR} 主键/外键 id),空串主键致 isSave 误判
|
||||
* 走 update、或写入空 FK。转 null 后引擎 INSERT 自动生成 UUID 主键、可空 FK 跳过。</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p><b>保留空串(false)</b>:自由文本列({@code NVARCHAR/CODE} 且列名非 {@code _ID} 结尾)——
|
||||
* 对齐老引擎语义(空文本存 {@code ''}),不破坏以空串为合法默认的 NOT NULL 文本列。
|
||||
*
|
||||
* @param refId referenceid(DisplayType 字符串或 36 位实体 UUID,已大写)
|
||||
* @param colUpper 列名(大写)
|
||||
*/
|
||||
static boolean emptyToNull(String refId, String colUpper) {
|
||||
// id 列(PK/FK,名以 _ID 结尾):恒转 null(本问题核心:空 PK/FK 必坏)
|
||||
if (colUpper.endsWith("_ID")) {
|
||||
return true;
|
||||
}
|
||||
// FK/引用列:referenceid 是 36 位实体 UUID(非已知 DisplayType 关键字)→ 转 null
|
||||
if (refId.length() == 36) {
|
||||
return true;
|
||||
}
|
||||
// 自由文本列(NVARCHAR/CODE):保留空串(对齐老语义,护 NOT NULL 合法空文本)
|
||||
if (TEXT_DISPLAY_TYPES.contains(refId)) {
|
||||
return false;
|
||||
}
|
||||
// 其余已知类型(数字/小数/布尔/日期/CHAR-id/LIST/BLOB 等非文本)→ 转 null
|
||||
return true;
|
||||
}
|
||||
|
||||
/** flowId → 流 {@code <input>} 声明的必填 *_ID 入参名缓存({@code ""} = 无/歧义)。 */
|
||||
private final Cache<String, String> requiredIdInputCache = Caffeine.newBuilder()
|
||||
.maximumSize(5_000)
|
||||
|
||||
@@ -8,6 +8,11 @@ import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -37,11 +42,17 @@ public class EntityController {
|
||||
|
||||
private final POJOCRUDService pojoCRUDService;
|
||||
private final IdentifierWhitelist identifierWhitelist;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PickerController pickerController;
|
||||
|
||||
public EntityController(POJOCRUDService pojoCRUDService,
|
||||
IdentifierWhitelist identifierWhitelist) {
|
||||
IdentifierWhitelist identifierWhitelist,
|
||||
JdbcTemplate jdbcTemplate,
|
||||
PickerController pickerController) {
|
||||
this.pojoCRUDService = pojoCRUDService;
|
||||
this.identifierWhitelist = identifierWhitelist;
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
this.pickerController = pickerController;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,15 +108,35 @@ public class EntityController {
|
||||
return resp;
|
||||
}
|
||||
|
||||
/** 单条加载:GET /api/entity/{table}/{id} */
|
||||
/**
|
||||
* 单条加载:GET /api/entity/{table}/{id}[?pageId=]
|
||||
*
|
||||
* <p><b>{@code pageId} 引用字段对象解析(picker 加载即显名)</b>:amis picker(可编辑引用字段)
|
||||
* 在「form initApi 动态载入已存值」时只显裸 id(不自动补拉 source 解析 label)。给定 {@code pageId}
|
||||
* 时读其 {@code view_page} XML 收集 {@code SelectDialog/MultiSelectDialog}(带 {@code dialogid})字段,
|
||||
* 把载入记录里这些字段的裸 id 值就地解析为 {@code {_id,_label}} 对象(多选→对象数组),自带 label,
|
||||
* picker 经 valueField=_id 仍提交 _id 不变。{@code pageId} 空 → 行为不变(仅 CHAR trim)。
|
||||
*/
|
||||
@GetMapping("/{table}/{id}")
|
||||
public Map<String, Object> load(@PathVariable String table, @PathVariable String id) {
|
||||
public Map<String, Object> load(@PathVariable String table, @PathVariable String id,
|
||||
@RequestParam(required = false) String pageId) {
|
||||
Properties ctx = UserSession.getAdmin();
|
||||
Object pojo = pojoCRUDService.loadPOJO(id, table.toUpperCase(), ctx, false);
|
||||
String t = table.toUpperCase();
|
||||
Object pojo = pojoCRUDService.loadPOJO(id, t, ctx, false);
|
||||
Object data;
|
||||
if (pojo instanceof GeneralPOJO p) {
|
||||
Map<String, Object> row = toRow(p);
|
||||
if (pageId != null && !pageId.isBlank()) {
|
||||
resolveReferenceFields(row, pageId.trim());
|
||||
}
|
||||
data = row;
|
||||
} else {
|
||||
data = pojo;
|
||||
}
|
||||
Map<String, Object> resp = new HashMap<>();
|
||||
resp.put("status", 0);
|
||||
resp.put("msg", "");
|
||||
resp.put("data", pojo instanceof GeneralPOJO p ? toRow(p) : pojo);
|
||||
resp.put("data", data);
|
||||
return resp;
|
||||
}
|
||||
|
||||
@@ -193,10 +224,156 @@ public class EntityController {
|
||||
|
||||
private Map<String, Object> toRow(GeneralPOJO p) {
|
||||
Map<String, Object> row = new LinkedHashMap<>();
|
||||
row.put("_id", p.get_ID());
|
||||
row.put("_id", trimChar(p.get_ID()));
|
||||
for (int i = 0; i < p.get_ColumnCount(); i++) {
|
||||
row.put(p.get_ColumnName(i), p.get_Value(i));
|
||||
row.put(p.get_ColumnName(i), trimChar(p.get_Value(i)));
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* 去 CHAR 列尾部补白:DB CHAR(n) 主键/引用值带尾空格(如 {@code "MESSAGE "}),而
|
||||
* picker 选项 {@code _id}(PickerController 已 .trim())与表单提交值均为无补白形态。表单加载
|
||||
* (master-detail/编辑页)经本端点回填引用字段时若带补白,picker valueField=_id 永不匹配选项
|
||||
* → 加载只显裸 id 而非名称(如根级菜单显 MESSAGE)。故按值统一去尾补白对齐。仅 String 生效、
|
||||
* 只去尾(stripTrailing)不动头,非 String(数字/日期/布尔)原样返回。
|
||||
*/
|
||||
private static Object trimChar(Object v) {
|
||||
return v instanceof String s ? s.stripTrailing() : v;
|
||||
}
|
||||
|
||||
/** view_page 里的可编辑引用字段:列名(大写) + dialogid(picker 数据源) + 是否多选。 */
|
||||
private record RefField(String name, String dialogid, boolean multi) {}
|
||||
|
||||
/**
|
||||
* dialogid(=view_template_id) 指向的模板是否 type=3(树形对话框,层级引用)。与转换器
|
||||
* {@code TemplateToAmisConverter.isTreeDialog} 同口径:type=3 的 SelectDialog 被转换器改写为
|
||||
* {@code tree-select}(吃裸 id 标量、自 source 拉树标签),而非 {@code picker}(吃 {_id,_label} 对象)。
|
||||
* 故 tree-select 引用字段不可转对象(否则 amis 显「undefined」),本端点据此跳过。查询失败/非树 → false。
|
||||
*/
|
||||
private boolean isTreeDialog(String dialogId) {
|
||||
if (dialogId == null || dialogId.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Integer type = jdbcTemplate.queryForObject(
|
||||
"SELECT type FROM view_template WHERE view_template_id = ?",
|
||||
Integer.class, dialogId);
|
||||
return type != null && type == 3;
|
||||
} catch (DataAccessException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 把载入记录里的引用字段裸 id 就地替换为 {@code {_id,_label}} 对象(picker 自带 label 即显名):
|
||||
* 读 {@code pageId} 的 view_page XML 收集 {@code SelectDialog/MultiSelectDialog}(带 {@code dialogid})
|
||||
* 字段,对 row 里这些非空字段值经 {@link PickerController#resolveValuesToOptions}(口径同 /resolve)
|
||||
* 解析为对象(多选→逗号拆分为对象数组),解析不到的回退 {@code {_id:value,_label:value}}(不丢值)。
|
||||
* 引用字段对象的 {@code _id} 同样去尾补白对齐选项 value。XML 缺失/解析异常 → 原样返回(降级)。
|
||||
*/
|
||||
private void resolveReferenceFields(Map<String, Object> row, String pageId) {
|
||||
List<RefField> refs = referenceFields(pageId);
|
||||
if (refs.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (RefField rf : refs) {
|
||||
Object raw = row.get(rf.name());
|
||||
if (raw == null) {
|
||||
continue;
|
||||
}
|
||||
String v = String.valueOf(raw).trim();
|
||||
if (v.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
if (rf.multi()) {
|
||||
List<Map<String, Object>> objs = new ArrayList<>();
|
||||
for (String part : v.split(",")) {
|
||||
String single = part.trim();
|
||||
if (!single.isBlank()) {
|
||||
objs.add(resolveRefValue(rf.dialogid(), single));
|
||||
}
|
||||
}
|
||||
row.put(rf.name(), objs);
|
||||
} else {
|
||||
row.put(rf.name(), resolveRefValue(rf.dialogid(), v));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个引用值 → {@code {_id,_label}} 对象(复用 PickerController 的 dialog→显示名口径)。
|
||||
* 解析不到(dialog 异常/查无)→ 回退 {@code {_id:value,_label:value}}(不丢值)。{@code _id} 去尾补白。
|
||||
*/
|
||||
private Map<String, Object> resolveRefValue(String dialogid, String value) {
|
||||
try {
|
||||
List<Map<String, Object>> resolved = pickerController.resolveValuesToOptions(
|
||||
dialogid, value, null, null, null, null, "_label", "_id");
|
||||
if (!resolved.isEmpty()) {
|
||||
Map<String, Object> opt = resolved.get(0);
|
||||
Object idVal = opt.get("_id");
|
||||
Map<String, Object> obj = new LinkedHashMap<>();
|
||||
obj.put("_id", idVal instanceof String s ? s.stripTrailing() : idVal);
|
||||
obj.put("_label", opt.get("_label"));
|
||||
return obj;
|
||||
}
|
||||
} catch (RuntimeException ex) {
|
||||
// dialog 解析/查询异常 → 不丢值,回退裸 id(picker 至少显裸 id)
|
||||
}
|
||||
Map<String, Object> obj = new LinkedHashMap<>();
|
||||
obj.put("_id", value);
|
||||
obj.put("_label", value);
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读 {@code pageId} 的 view_page XML,收集可编辑引用字段({@code uitype} ∈
|
||||
* {@code {SelectDialog, MultiSelectDialog}} 且有 {@code dialogid})。XML 缺失/无 fields/异常 → 空列表。
|
||||
*/
|
||||
private List<RefField> referenceFields(String pageId) {
|
||||
List<RefField> refs = new ArrayList<>();
|
||||
String xml = queryViewPageXml(pageId);
|
||||
if (xml == null || xml.isBlank()) {
|
||||
return refs;
|
||||
}
|
||||
try {
|
||||
Document doc = DocumentHelper.parseText(xml.trim());
|
||||
Element fields = doc.getRootElement().element("fields");
|
||||
if (fields == null) {
|
||||
return refs;
|
||||
}
|
||||
for (Element f : fields.elements("field")) {
|
||||
String name = f.attributeValue("name");
|
||||
String uitype = f.attributeValue("uitype");
|
||||
String dialogid = f.attributeValue("dialogid");
|
||||
if (name == null || name.isBlank() || dialogid == null || dialogid.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
boolean multi = "MultiSelectDialog".equals(uitype);
|
||||
if (!multi && !"SelectDialog".equals(uitype)) {
|
||||
continue;
|
||||
}
|
||||
// type=3 树对话框 → 转换器渲为 tree-select(吃裸 id),不可转 {_id,_label} 对象,跳过。
|
||||
if (isTreeDialog(dialogid)) {
|
||||
continue;
|
||||
}
|
||||
refs.add(new RefField(name.toUpperCase(), dialogid, multi));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return refs;
|
||||
}
|
||||
|
||||
/** 取 view_page XML(PG xml 物理类型须 {@code xml::text} 取出);缺失/异常 → null。 */
|
||||
private String queryViewPageXml(String pageId) {
|
||||
try {
|
||||
List<String> xmls = jdbcTemplate.queryForList(
|
||||
"SELECT xml::text FROM view_page WHERE view_page_id = ? AND xml IS NOT NULL",
|
||||
String.class, pageId);
|
||||
return xmls.isEmpty() ? null : xmls.get(0);
|
||||
} catch (DataAccessException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -89,10 +90,23 @@ public class PickerController {
|
||||
* {@code /list} 后缀以与全部存量 source 对齐;同时接受 {@code q/page/perPage} 三参(amis select
|
||||
* 的 searchable/分页透传)。
|
||||
*
|
||||
* <p><b>amis picker 加载已存值自动显名({@code op=loadOptions})</b>:amis 的 OptionsControl picker
|
||||
* 在「加载一个已存值」时(mount / value 变化)会原生用本 {@code source} 发一次请求,query 带
|
||||
* {@code op=loadOptions&value=<v>&_id=<v>}(amis-core formItem.fetchOptions/loadOptions 约定),
|
||||
* 期望响应只回该值对应的选项,再经 {@code setOptions} 合并 → 选中项显示人可读名而非裸 id(picker
|
||||
* 不像 select 那样自动拉 source 解析 label,全靠这一原生回环)。本端点据此在 {@code op=loadOptions}
|
||||
* 时短路到 {@link #resolveValuesToOptions}(与独立 {@code /resolve} 端点同源口径),返回
|
||||
* {@code {status,data:{options:[{label,value}]}}}——这就是「全站可编辑引用 picker 加载即显名」的落点,
|
||||
* 无需重转换、无需改前端 source,存量 883 页 picker 即时生效。普通弹窗 CRUD 不带 {@code op},列表/
|
||||
* 搜索/分页路径不受影响(对齐老系统 DialogDisplayUtil「dialog 自己按 dialogid 解析显示名」)。
|
||||
*
|
||||
* @param entityOrRef SYS_REFERENCE_ID 或实体表名
|
||||
* @param q 模糊搜索关键字(按引用实体的标识列做 LIKE,已转义)
|
||||
* @param page 页码(1 起)
|
||||
* @param perPage 每页条数
|
||||
* @param op amis 操作标记:{@code loadOptions} 时短路为「按值解析显示名」(picker 加载已存值)
|
||||
* @param value amis loadOptions 透传的已存值(与 {@code idValue} 同义,取其一),支持逗号分隔多值
|
||||
* @param idValue amis loadOptions 透传的 {@code _id}(valueField=_id);与 {@code value} 互为兜底
|
||||
* @param asUser 行级权限测试通道:显式当前用户(非 ADMIN 视角,触发行级过滤)
|
||||
* @param roles 行级权限测试通道:逗号分隔角色
|
||||
* @param asDepart 多维测试通道:当前部门
|
||||
@@ -103,10 +117,37 @@ public class PickerController {
|
||||
@RequestParam(required = false) String q,
|
||||
@RequestParam(defaultValue = "1") int page,
|
||||
@RequestParam(defaultValue = "20") int perPage,
|
||||
@RequestParam(required = false) String op,
|
||||
@RequestParam(required = false) String value,
|
||||
@RequestParam(name = "_id", required = false) String idValue,
|
||||
@RequestParam(required = false) String asUser,
|
||||
@RequestParam(required = false) String roles,
|
||||
@RequestParam(required = false) String asDepart,
|
||||
@RequestParam(required = false) String asOrg) {
|
||||
@RequestParam(required = false) String asOrg,
|
||||
@RequestParam(required = false) MultiValueMap<String, String> allParams) {
|
||||
// amis picker 加载已存值:op=loadOptions 短路到「按值解析显示名」,返回 options,
|
||||
// 让 picker 选中项原生显名而非裸 id(与 /resolve 同源口径)。
|
||||
if ("loadOptions".equalsIgnoreCase(op)) {
|
||||
// 取值口径兼容 amis 单选/多选两种序列化:
|
||||
// - 单选:value=<v> / _id=<v>(scalar);
|
||||
// - 多选:amis qs(arrayFormat=indices) 产 value[0]=v1&value[1]=v2 / _id[0]=...(indexed)。
|
||||
// 合并成逗号串交 resolveValuesToOptions(其内部按逗号拆分+保序去重+CHAR trim)。
|
||||
String wanted = collectLoadOptionsValues(value, idValue, allParams);
|
||||
List<Map<String, Object>> resolved = resolveValuesToOptions(
|
||||
entityOrRef, wanted, asUser, roles, asDepart, asOrg, "_label", "_id");
|
||||
// 每个选项同时带 _id/_label(转换器 picker 的 valueField=_id/labelField=_label)与 value/label
|
||||
// (amis 默认 field)两套键——使 picker 无论 field 配置如何,loadOptions 回来的选项都能按值匹配
|
||||
// 并显名(转换器产物用 _id/_label;缺省/历史 schema 用 value/label)。这是「全站任意 picker 通用」
|
||||
// 的关键:amis 按各自 valueField 匹配选中值,两套键全覆盖。
|
||||
for (Map<String, Object> o : resolved) {
|
||||
o.put("value", o.get("_id"));
|
||||
o.put("label", o.get("_label"));
|
||||
}
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("options", resolved);
|
||||
return ok(data);
|
||||
}
|
||||
|
||||
String table = resolveTable(entityOrRef);
|
||||
// 安全第 1 层:解析出的表名必须存在于 SYS_ENTITY,否则 400(非法表名不进引擎拼接)
|
||||
identifierWhitelist.requireLegalTable(table);
|
||||
@@ -156,16 +197,16 @@ public class PickerController {
|
||||
List<Map<String, Object>> rows = toRows(result.get(POJOCRUDService.LIST_RESULT));
|
||||
List<Map<String, Object>> options = new ArrayList<>();
|
||||
for (Map<String, Object> row : rows) {
|
||||
Object value = row.get("_id");
|
||||
Object rowId = row.get("_id");
|
||||
Object label = labelColumn != null ? row.get(labelColumn) : null;
|
||||
String labelStr = label != null ? String.valueOf(label).trim() : "";
|
||||
String display = !labelStr.isBlank() ? labelStr : String.valueOf(value).trim();
|
||||
String display = !labelStr.isBlank() ? labelStr : String.valueOf(rowId).trim();
|
||||
// _label:统一显示值字段。picker 用 labelField="_label" 显示选中项人可读名(与 select 的
|
||||
// option.label 同口径),避免依赖各 dialog 实体显示列名(转换器无从得知)。
|
||||
row.put("_label", display);
|
||||
Map<String, Object> opt = new LinkedHashMap<>();
|
||||
opt.put("label", display);
|
||||
opt.put("value", value);
|
||||
opt.put("value", rowId);
|
||||
options.add(opt);
|
||||
}
|
||||
|
||||
@@ -187,6 +228,182 @@ public class PickerController {
|
||||
return resp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择窗回显解析:{@code GET /api/picker/{entityOrRef}/resolve?value=}。
|
||||
*
|
||||
* <p>对齐老系统 {@code DialogDisplayUtil.parseDisplay}——「dialog 按自己的 dialogid 配置把已存
|
||||
* 裸 id 解析成显示名」。amis {@code picker} 加载一个已存值时只显裸 id(不像 {@code select} 那样
|
||||
* 自动拉 source 解析 label),故前端宿主在 picker 加载有值时调本端点,按 dialog 同源口径拿
|
||||
* {@code _label} 回填选中项显示名(提交值仍为 {@code _id}=裸 id,不变)。
|
||||
*
|
||||
* <p><b>口径与 {@link #list} 完全一致</b>:复用同一 {@link #resolveTable}(dialogid→实体表)、
|
||||
* 同一 {@link #displayColumn}(显示列优先于标识列)、同一 {@link #isUserDirectoryTable} 上下文策略、
|
||||
* 同一 {@link #trimId} CHAR 主键去补白——保证 resolve 出的 {@code _label} 与弹窗 {@code /list}
|
||||
* 里同一行的 {@code _label} 字字相同(同 dialog 同显示名)。
|
||||
*
|
||||
* <p>语义细节:
|
||||
* <ul>
|
||||
* <li>{@code value} 支持逗号分隔多值(多选 picker),按 keyColumn {@code IN (...)} 一次查回;</li>
|
||||
* <li>返回顺序尽量对齐入参顺序(按 value 在入参里的位置重排查询结果);</li>
|
||||
* <li>查不到的 value 兜底返回 {@code {_id:value,_label:value}}(不丢值、不报错,picker 至少显裸 id);</li>
|
||||
* <li>CHAR(36) 主键库内尾空格补白:入参 trim 后比对、返回 {@code _id} 经 {@link #trimId} 去补白。</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param entityOrRef dialogid(= view_template_id)/ SYS_REFERENCE_ID / 实体表名(同 {@link #list})
|
||||
* @param value 已存裸 id,支持逗号分隔多值
|
||||
* @param asUser 行级权限测试通道(同 {@link #list})
|
||||
* @param roles 行级权限测试通道
|
||||
* @param asDepart 行级权限测试通道
|
||||
* @param asOrg 行级权限测试通道
|
||||
*/
|
||||
@GetMapping("/{entityOrRef}/resolve")
|
||||
public Map<String, Object> resolve(@PathVariable String entityOrRef,
|
||||
@RequestParam(required = false) String value,
|
||||
@RequestParam(required = false) String asUser,
|
||||
@RequestParam(required = false) String roles,
|
||||
@RequestParam(required = false) String asDepart,
|
||||
@RequestParam(required = false) String asOrg) {
|
||||
// 独立端点:返回 [{_id,_label}](valueField=_id/labelField=_label 口径,picker chip 直接消费)
|
||||
List<Map<String, Object>> data = resolveValuesToOptions(
|
||||
entityOrRef, value, asUser, roles, asDepart, asOrg, "_label", "_id");
|
||||
return ok(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集 amis loadOptions 透传的待解析值,兼容单选/多选两种序列化,合并为逗号串:
|
||||
* <ul>
|
||||
* <li>单选:scalar {@code value=<v>} / {@code _id=<v>}({@code value}/{@code idValue} 形参已绑);</li>
|
||||
* <li>多选:amis 用 {@code qs(arrayFormat=indices)} 序列化数组 → {@code value[0]=v1&value[1]=v2}
|
||||
* /{@code _id[0]=...}(indexed),Spring 标量形参绑不到,从 {@code allParams} 里捞 {@code value[*]}
|
||||
* /{@code _id[*]} 全部键。</li>
|
||||
* </ul>
|
||||
* 优先 {@code value} 族(amis ctx 主键),无则回退 {@code _id} 族(valueField=_id 透传)。下游
|
||||
* {@link #resolveValuesToOptions} 再做逗号拆分 + 保序去重 + CHAR trim,故此处只需把多值拼成逗号串。
|
||||
*/
|
||||
private static String collectLoadOptionsValues(String value, String idValue,
|
||||
MultiValueMap<String, String> allParams) {
|
||||
List<String> vals = collectIndexed(value, "value", allParams);
|
||||
if (vals.isEmpty()) {
|
||||
vals = collectIndexed(idValue, "_id", allParams); // value 族空 → 回退 _id 族
|
||||
}
|
||||
return String.join(",", vals);
|
||||
}
|
||||
|
||||
/** 收集某基名的 scalar({@code base})与 indexed({@code base[n]})全部值(amis qs indices 数组形态)。 */
|
||||
private static List<String> collectIndexed(String scalar, String base,
|
||||
MultiValueMap<String, String> allParams) {
|
||||
List<String> vals = new ArrayList<>();
|
||||
if (scalar != null && !scalar.isBlank()) {
|
||||
vals.add(scalar);
|
||||
}
|
||||
if (allParams != null) {
|
||||
String prefix = base + "[";
|
||||
for (Map.Entry<String, List<String>> e : allParams.entrySet()) {
|
||||
String k = e.getKey();
|
||||
if (k != null && k.startsWith(prefix) && k.endsWith("]")) {
|
||||
for (String v : e.getValue()) {
|
||||
if (v != null && !v.isBlank()) {
|
||||
vals.add(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return vals;
|
||||
}
|
||||
|
||||
/**
|
||||
* 「按值解析显示名」核心:把已存裸 id(逗号分隔多值)按 dialog 同源口径解析为 {@code [{label,value}]}
|
||||
* (字段名由 {@code labelKey}/{@code valueKey} 定,供 {@code /resolve}=「_label/_id」与
|
||||
* {@code list?op=loadOptions}=「label/value」两路复用,保证 {@code _label} 与 {@link #list} 弹窗行
|
||||
* 同显示名)。复用 {@link #resolveTable}/{@link #displayColumn}/{@link #isUserDirectoryTable}/
|
||||
* {@link #buildCtx}/{@link #trimId}——与 {@link #list} 完全同源。
|
||||
*
|
||||
* <p>语义:① 入参 trim(CHAR 主键去补白后比对)+ 保序去重;② keyColumn {@code IN (...)} 一次查回;
|
||||
* ③ 返回按入参顺序回填;④ 查不到的 value 兜底 {@code {label:value,value:value}}(不丢值、显裸 id);
|
||||
* ⑤ 数据权限拒绝(PrivilegeException)→ 全部兜底,不 500(与 {@link #list} 友好降级一致)。
|
||||
*/
|
||||
List<Map<String, Object>> resolveValuesToOptions(String entityOrRef, String value,
|
||||
String asUser, String roles,
|
||||
String asDepart, String asOrg,
|
||||
String labelKey, String valueKey) {
|
||||
// 入参拆分 + trim(CHAR 主键去补白后比对)+ 保序去重(重复值只查一次,回填时按原序复用)
|
||||
List<String> wanted = new ArrayList<>();
|
||||
if (value != null) {
|
||||
for (String v : value.split(",")) {
|
||||
String t = v.trim();
|
||||
if (!t.isBlank() && !wanted.contains(t)) {
|
||||
wanted.add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (wanted.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
String table = resolveTable(entityOrRef);
|
||||
// 安全第 1 层:解析出的表名必须存在于 SYS_ENTITY(与 list 同口径),否则 400
|
||||
identifierWhitelist.requireLegalTable(table);
|
||||
|
||||
POJOInfo info = POInfo.getPOInfo(table);
|
||||
if (info == null || !info.hasKeyColumn()) {
|
||||
throw new IllegalIdentifierException("引用实体不可作选择窗数据源(无主键): "
|
||||
+ table.replaceAll("[^A-Z0-9_]", "?"));
|
||||
}
|
||||
String keyColumn = info.getKeyColumnName();
|
||||
String labelColumn = displayColumn(info, keyColumn);
|
||||
|
||||
// 上下文策略与 list 同源:用户目录类强制 ADMIN,其余走 per-user 行级权限
|
||||
Properties ctx = isUserDirectoryTable(table)
|
||||
? UserSession.getAdmin()
|
||||
: buildCtx(asUser, roles, asDepart, asOrg);
|
||||
|
||||
// keyColumn IN (values):引擎对 String 列的 List 条件走 processListIn → col IN ('v1','v2')(值经
|
||||
// StringUtil.TO_STRING 引号转义,杜绝注入)。perPage 取「不少于入参数」的安全上限,一次查回。
|
||||
Map<String, Object> cond = new HashMap<>();
|
||||
cond.put(POJOCRUDService.PAGE_START, 0);
|
||||
cond.put(POJOCRUDService.PAGE_SIZE, Math.max(wanted.size(), 1));
|
||||
cond.put(keyColumn, new ArrayList<>(wanted));
|
||||
|
||||
// value→显示名 命中表(id 已 trim);查不到的 value 走兜底
|
||||
Map<String, String> resolved = new HashMap<>();
|
||||
try {
|
||||
Map<String, Object> result = pojoCRUDService.listSelect(cond, table, ctx);
|
||||
for (Map<String, Object> row : toRows(result.get(POJOCRUDService.LIST_RESULT))) {
|
||||
Object idVal = row.get("_id"); // toRow 已 trimId
|
||||
String id = idVal != null ? String.valueOf(idVal).trim() : "";
|
||||
if (id.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
Object label = labelColumn != null ? row.get(labelColumn) : null;
|
||||
String labelStr = label != null ? String.valueOf(label).trim() : "";
|
||||
resolved.put(id, !labelStr.isBlank() ? labelStr : id);
|
||||
}
|
||||
} catch (PrivilegeException ex) {
|
||||
// 数据权限拒绝 → 不报错、不丢值,全部走兜底(picker 至少显裸 id),与 list 的友好降级一致
|
||||
resolved = new HashMap<>();
|
||||
}
|
||||
|
||||
// 按入参顺序回填;查不到的 value 兜底 {label:value,value:value}
|
||||
List<Map<String, Object>> data = new ArrayList<>();
|
||||
for (String v : wanted) {
|
||||
String label = resolved.getOrDefault(v, v);
|
||||
Map<String, Object> item = new LinkedHashMap<>();
|
||||
item.put(valueKey, v);
|
||||
item.put(labelKey, label);
|
||||
data.add(item);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private static Map<String, Object> ok(Object data) {
|
||||
Map<String, Object> resp = new HashMap<>();
|
||||
resp.put("status", 0);
|
||||
resp.put("msg", "");
|
||||
resp.put("data", data);
|
||||
return resp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析 path 变量为实体表名(优先级见类注释):
|
||||
* <ol>
|
||||
|
||||
@@ -152,7 +152,45 @@ public class TemplateTreeController {
|
||||
if (perPage != null) {
|
||||
body.put("perPage", perPage);
|
||||
}
|
||||
return flowController.executePost(gridTable.toUpperCase() + "_SEARCH", null, body);
|
||||
ResponseEntity<Map<String, Object>> resp =
|
||||
flowController.executePost(gridTable.toUpperCase() + "_SEARCH", null, body);
|
||||
// type=4 选择框 picker:每行补 _label(统一显示值=网格显示列),使 picker(labelField=_label)选中/
|
||||
// chip 显人可读名而非裸 id,且与「加载已存值经 EntityController 解析出的 {_id,_label}」labelField 同口径。
|
||||
// 浏览页 type=4 右表不读 _label(按 columns 渲染),故无副作用。
|
||||
attachLabel(resp, gridTable.toUpperCase());
|
||||
return resp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给 treegrid 右表响应每行补 {@code _label}(= 网格实体显示列值),供 type=4 选择框 picker
|
||||
* ({@code labelField=_label})显选中项人可读名。显示列复用 {@link #displayColumn}(与左树节点 label 同源);
|
||||
* 列是虚拟表达式(物理不存在)时退回主键值。响应非预期结构/无 items → 原样不动(零副作用)。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void attachLabel(ResponseEntity<Map<String, Object>> resp, String table) {
|
||||
if (resp == null || resp.getBody() == null) {
|
||||
return;
|
||||
}
|
||||
Object dataObj = resp.getBody().get("data");
|
||||
if (!(dataObj instanceof Map<?, ?> data) || !(data.get("items") instanceof List<?> items)) {
|
||||
return;
|
||||
}
|
||||
String keyCol = table + "_ID";
|
||||
String dispCol = displayColumn(table, keyCol);
|
||||
boolean dispIsExpr = com.eip4.platform.metadata.flow.EntityDisplayColumns.isExpression(dispCol);
|
||||
for (Object o : items) {
|
||||
if (!(o instanceof Map)) {
|
||||
continue;
|
||||
}
|
||||
Map<String, Object> row = (Map<String, Object>) o;
|
||||
Object id = row.get("_id");
|
||||
// 虚拟表达式显示列无法按列名取行值(行键是物理列)→ 退回主键;物理列直接取该列值。
|
||||
Object lbl = dispIsExpr ? null : row.get(dispCol);
|
||||
String label = lbl != null && !String.valueOf(lbl).isBlank()
|
||||
? String.valueOf(lbl).trim()
|
||||
: (id != null ? String.valueOf(id).trim() : "");
|
||||
row.put("_label", label);
|
||||
}
|
||||
}
|
||||
|
||||
/** 解析「点中节点 + 全部后代」的原始 id 列表(供右表 IN 过滤)。节点不在树中(陈旧)→ 退化为仅自身。 */
|
||||
|
||||
@@ -336,4 +336,165 @@ class FlowInputCoercerTest {
|
||||
|
||||
verify(jdbc, times(2)).queryForObject(anyString(), eq(String.class), eq(flowId));
|
||||
}
|
||||
|
||||
// ── flattenPickerObjects(master-detail 引用 picker {_id,_label} 对象 → 裸 _id)────────
|
||||
|
||||
@Test
|
||||
@DisplayName("flattenPickerObjects: {_id,_label} 对象 → 裸 _id(CHAR 主键去尾补白)")
|
||||
void flattenPickerObjectToId() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("VIEW_TEMPLATEID", new HashMap<>(Map.of("_id", "a5996b8a", "_label", "文件阅读")));
|
||||
map.put("MENUROOT", new HashMap<>(Map.of("_id", "MESSAGE ", "_label", "信息站"))); // 尾补白
|
||||
map.put("NAME", "公文收发"); // 普通 String 不动
|
||||
map.put("SEQ", 40); // 普通数值不动
|
||||
|
||||
FlowInputCoercer.flattenPickerObjects(map);
|
||||
|
||||
assertEquals("a5996b8a", map.get("VIEW_TEMPLATEID"), "对象降为裸 _id");
|
||||
assertEquals("MESSAGE", map.get("MENUROOT"), "_id String 去尾补白");
|
||||
assertEquals("公文收发", map.get("NAME"), "普通 String 原样");
|
||||
assertEquals(40, map.get("SEQ"), "数值原样");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("flattenPickerObjects: 无 _id 键的 Map / 数组 不动(不误伤结构化输入)")
|
||||
void flattenPickerObjectsLeavesNonRefStructuresAlone() {
|
||||
Map<String, Object> nested = new HashMap<>(Map.of("foo", "bar")); // 无 _id
|
||||
List<String> arr = List.of("a", "b");
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("CONFIG", nested);
|
||||
map.put("TAGS", arr);
|
||||
|
||||
FlowInputCoercer.flattenPickerObjects(map);
|
||||
|
||||
assertSame(nested, map.get("CONFIG"), "无 _id 键的 Map 不动");
|
||||
assertSame(arr, map.get("TAGS"), "数组不动");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("coerceByFlowId: 引用对象先扁平为 _id 再按列类型 coerce(端到端 master-detail 保存)")
|
||||
void coerceByFlowIdFlattensRefObjectThenCoerces() {
|
||||
String flowId = "SYS_MENU_ADD";
|
||||
String xml = "<flow><input><field name=\"tableName\" initValue=\"SYS_MENU\"/></input></flow>";
|
||||
when(jdbc.queryForObject(anyString(), eq(String.class), eq(flowId))).thenReturn(xml);
|
||||
when(jdbc.queryForList(anyString(), eq("SYS_MENU")))
|
||||
.thenReturn(List.of(Map.of("col", "SEQ", "ref", "INTEGER")));
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("VIEW_TEMPLATEID", new HashMap<>(Map.of("_id", "a5996b8a", "_label", "文件阅读")));
|
||||
map.put("SEQ", "40"); // String → coerce 为 Integer
|
||||
|
||||
coercer.coerceByFlowId(flowId, map);
|
||||
|
||||
assertEquals("a5996b8a", map.get("VIEW_TEMPLATEID"), "引用对象降为裸 _id(提交值是 id)");
|
||||
assertEquals(40, map.get("SEQ"), "数值列仍按元数据 coerce 为 Integer");
|
||||
}
|
||||
|
||||
// ── emptyToNull(列类型感知的 空串→null 规则)──────────────────────────────────
|
||||
|
||||
@Test
|
||||
@DisplayName("emptyToNull: id 列(名以 _ID 结尾,PK/FK)恒转 null")
|
||||
void emptyToNullIdColumns() {
|
||||
// PK(CHAR)
|
||||
org.junit.jupiter.api.Assertions.assertTrue(
|
||||
FlowInputCoercer.emptyToNull("CHAR", "SYS_MENU_ID"), "CHAR PK _ID → null");
|
||||
// FK(refId 是 36 位 UUID 且名以 _ID 结尾)
|
||||
org.junit.jupiter.api.Assertions.assertTrue(
|
||||
FlowInputCoercer.emptyToNull("0236DBDC-435C-4F6A-B0E8-8FD6D215EC45", "USER_ID"), "FK _ID → null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("emptyToNull: FK/引用列(refId=36 位实体 UUID)转 null(即便列名不以 _ID 结尾,如 MENUROOT)")
|
||||
void emptyToNullReferenceColumns() {
|
||||
org.junit.jupiter.api.Assertions.assertTrue(
|
||||
FlowInputCoercer.emptyToNull("C931BA3B-4CAC-44AB-9836-B120E9FDCF36", "MENUROOT"),
|
||||
"MENUROOT FK(36 位 refId)→ null");
|
||||
org.junit.jupiter.api.Assertions.assertTrue(
|
||||
FlowInputCoercer.emptyToNull("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", "VIEW_TEMPLATEID"),
|
||||
"VIEW_TEMPLATEID FK(36 字符 refId)→ null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("emptyToNull: 非文本类型列(数字/小数/布尔/日期)转 null")
|
||||
void emptyToNullNonTextTypes() {
|
||||
org.junit.jupiter.api.Assertions.assertTrue(FlowInputCoercer.emptyToNull("INTEGER", "SEQ"));
|
||||
org.junit.jupiter.api.Assertions.assertTrue(FlowInputCoercer.emptyToNull("ENUMERATE", "IMPORTANT"));
|
||||
org.junit.jupiter.api.Assertions.assertTrue(FlowInputCoercer.emptyToNull("STATUS", "STATUS"));
|
||||
org.junit.jupiter.api.Assertions.assertTrue(FlowInputCoercer.emptyToNull("DECIMAL", "AMOUNT"));
|
||||
org.junit.jupiter.api.Assertions.assertTrue(FlowInputCoercer.emptyToNull("MONEY", "PRICE"));
|
||||
org.junit.jupiter.api.Assertions.assertTrue(FlowInputCoercer.emptyToNull("BOOLEAN", "ISACTIVE"));
|
||||
org.junit.jupiter.api.Assertions.assertTrue(FlowInputCoercer.emptyToNull("DATE", "PUBLISHDATE"));
|
||||
org.junit.jupiter.api.Assertions.assertTrue(FlowInputCoercer.emptyToNull("TIME", "CREATETIME"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("emptyToNull: 自由文本列(NVARCHAR/CODE,名非 _ID)保留空串 → false(护 NOT NULL 合法空文本)")
|
||||
void emptyToNullTextColumnsPreserved() {
|
||||
org.junit.jupiter.api.Assertions.assertFalse(
|
||||
FlowInputCoercer.emptyToNull("NVARCHAR", "TITLE"), "NVARCHAR 自由文本保留空串");
|
||||
org.junit.jupiter.api.Assertions.assertFalse(
|
||||
FlowInputCoercer.emptyToNull("CODE", "DOCCODE"), "CODE 保留空串");
|
||||
org.junit.jupiter.api.Assertions.assertFalse(
|
||||
FlowInputCoercer.emptyToNull("NVARCHAR", "DEPARTID"), "NVARCHAR DEPARTID(老库存裸 id 文本)保留空串");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("coerce: 端到端 空串→null(FK/PK/数字 转 null,自由文本保留,合法值不动)")
|
||||
void coerceEmptyToNullEndToEnd() {
|
||||
String xml = "<flow><input><field name=\"tableName\" initValue=\"SYS_MENU\"/></input></flow>";
|
||||
when(jdbc.queryForList(anyString(), eq("SYS_MENU")))
|
||||
.thenReturn(List.of(
|
||||
Map.of("col", "SYS_MENU_ID", "ref", "CHAR"), // PK
|
||||
Map.of("col", "MENUROOT", "ref", "C931BA3B-4CAC-44AB-9836-B120E9FDCF36"), // FK 36 位
|
||||
Map.of("col", "VIEW_TEMPLATEID", "ref", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"), // FK 36 字符
|
||||
Map.of("col", "SEQ", "ref", "INTEGER"), // 数字
|
||||
Map.of("col", "NAME", "ref", "NVARCHAR") // 自由文本
|
||||
));
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("SYS_MENU_ID", ""); // PK 空串 → null(引擎自动生成 UUID)
|
||||
map.put("MENUROOT", ""); // FK 空串 → null(INSERT 跳过,避免 FK 违反)
|
||||
map.put("VIEW_TEMPLATEID", ""); // FK 空串 → null
|
||||
map.put("SEQ", ""); // 数字空串 → null(避免 (Integer)"" 崩)
|
||||
map.put("NAME", "测试空串"); // 合法文本 → 不动
|
||||
|
||||
coercer.coerce(xml, map);
|
||||
|
||||
assertNull(map.get("SYS_MENU_ID"), "PK 空串 → null");
|
||||
assertNull(map.get("MENUROOT"), "FK 空串 → null");
|
||||
assertNull(map.get("VIEW_TEMPLATEID"), "FK 空串 → null");
|
||||
assertNull(map.get("SEQ"), "数字空串 → null");
|
||||
assertEquals("测试空串", map.get("NAME"), "合法文本不被误伤");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("coerce: 数字列合法非空值仍正常 coerce 为 Integer(空串修复不破坏合法值)")
|
||||
void coerceNonEmptyNumericStillCoerces() {
|
||||
String xml = "<flow><input><field name=\"tableName\" initValue=\"SYS_MENU\"/></input></flow>";
|
||||
when(jdbc.queryForList(anyString(), eq("SYS_MENU")))
|
||||
.thenReturn(List.of(Map.of("col", "SEQ", "ref", "INTEGER")));
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("SEQ", "99");
|
||||
coercer.coerce(xml, map);
|
||||
assertEquals(Integer.valueOf(99), map.get("SEQ"), "非空数字仍 coerce 为 Integer");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("coerceByFlowId: 引用 picker 对象 _id 为空串 → 扁平后转 null(与 flattenPickerObjects 协同)")
|
||||
void coerceByFlowIdFlattenedEmptyRefToNull() {
|
||||
String flowId = "SYS_MENU_ADD";
|
||||
String xml = "<flow><input><field name=\"tableName\" initValue=\"SYS_MENU\"/></input></flow>";
|
||||
when(jdbc.queryForObject(anyString(), eq(String.class), eq(flowId))).thenReturn(xml);
|
||||
when(jdbc.queryForList(anyString(), eq("SYS_MENU")))
|
||||
.thenReturn(List.of(Map.of("col", "MENUROOT", "ref", "C931BA3B-4CAC-44AB-9836-B120E9FDCF36")));
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
// picker 载入未改、其 _id 为空串(未选)→ flatten 为 "",再按 FK 列类型 → null
|
||||
map.put("MENUROOT", new HashMap<>(Map.of("_id", "", "_label", "")));
|
||||
|
||||
coercer.coerceByFlowId(flowId, map);
|
||||
|
||||
assertNull(map.get("MENUROOT"), "空 _id 引用对象 → null(避免 FK 违反)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,20 +3,26 @@ package com.eip4.platform.metadata.web;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||
import com.eip4.platform.metadata.security.IdentifierWhitelist;
|
||||
import com.eip4.platform.metadata.security.IdentifierWhitelistExceptionHandler;
|
||||
@@ -40,7 +46,8 @@ class EntityControllerWhitelistTest {
|
||||
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||
doThrow(new IllegalIdentifierException("非法实体或元数据不存在: NOPE"))
|
||||
.when(wl).requireLegalTable(eq("NOPE"));
|
||||
EntityController c = new EntityController(engine, wl);
|
||||
EntityController c = new EntityController(engine, wl,
|
||||
mock(org.springframework.jdbc.core.JdbcTemplate.class), mock(PickerController.class));
|
||||
|
||||
assertThrows(IllegalIdentifierException.class,
|
||||
() -> c.list("NOPE", 1, 10, null, null, null, null, null, null, new HashMap<>()));
|
||||
@@ -52,7 +59,8 @@ class EntityControllerWhitelistTest {
|
||||
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||
doThrow(new IllegalIdentifierException("查询条件含非法列标识符,已拒绝"))
|
||||
.when(wl).requireLegalColumn(eq(TABLE), any(), eq("查询条件"));
|
||||
EntityController c = new EntityController(engine, wl);
|
||||
EntityController c = new EntityController(engine, wl,
|
||||
mock(org.springframework.jdbc.core.JdbcTemplate.class), mock(PickerController.class));
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("XX' OR 1=1--", "x");
|
||||
@@ -64,7 +72,8 @@ class EntityControllerWhitelistTest {
|
||||
void 非法排序方向拒绝() {
|
||||
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||
EntityController c = new EntityController(engine, wl);
|
||||
EntityController c = new EntityController(engine, wl,
|
||||
mock(org.springframework.jdbc.core.JdbcTemplate.class), mock(PickerController.class));
|
||||
|
||||
// orderBy 列合法(白名单不抛),但 orderDir=drop 非 asc/desc → Controller 抛
|
||||
IllegalIdentifierException ex = assertThrows(IllegalIdentifierException.class,
|
||||
@@ -81,7 +90,8 @@ class EntityControllerWhitelistTest {
|
||||
engineResult.put(POJOCRUDService.LIST_RESULT, java.util.List.of());
|
||||
engineResult.put(POJOCRUDService.PAGE_COUNT, 0L);
|
||||
when(engine.listSelect(any(), eq(TABLE), any(Properties.class))).thenReturn(engineResult);
|
||||
EntityController c = new EntityController(engine, wl);
|
||||
EntityController c = new EntityController(engine, wl,
|
||||
mock(org.springframework.jdbc.core.JdbcTemplate.class), mock(PickerController.class));
|
||||
|
||||
Map<String, Object> resp = c.list(TABLE, 1, 10, null, null, null, null, "ORDERNO", "asc", new HashMap<>());
|
||||
assertEquals(0, resp.get("status"));
|
||||
@@ -100,7 +110,8 @@ class EntityControllerWhitelistTest {
|
||||
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||
when(engine.listSelect(any(), eq(TABLE), any(Properties.class))).thenReturn(new HashMap<>());
|
||||
EntityController c = new EntityController(engine, wl);
|
||||
EntityController c = new EntityController(engine, wl,
|
||||
mock(org.springframework.jdbc.core.JdbcTemplate.class), mock(PickerController.class));
|
||||
|
||||
// page/perPage/asUser/roles 是保留键(经方法签名绑定),allParams 里只放保留键不应触发列校验
|
||||
Map<String, String> params = new HashMap<>();
|
||||
@@ -123,4 +134,103 @@ class EntityControllerWhitelistTest {
|
||||
assertEquals(1, resp.getBody().get("status"));
|
||||
assertFalse(String.valueOf(resp.getBody().get("msg")).contains("'"));
|
||||
}
|
||||
|
||||
/** 单字段 GeneralPOJO 桩:主键 + 一个引用列 MENUROOT=值。 */
|
||||
private static GeneralPOJO refRow(String id, String menuRoot) {
|
||||
GeneralPOJO p = mock(GeneralPOJO.class);
|
||||
when(p.get_ID()).thenReturn(id);
|
||||
when(p.get_ColumnCount()).thenReturn(1);
|
||||
when(p.get_ColumnName(0)).thenReturn("MENUROOT");
|
||||
when(p.get_Value(0)).thenReturn(menuRoot);
|
||||
return p;
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void load带pageId_SelectDialog字段返对象() {
|
||||
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||
PickerController picker = mock(PickerController.class);
|
||||
|
||||
// 先构造 row(其内部 stubbing)再 stub engine,避免「stubbing 内嵌 stubbing」破坏 Mockito 状态
|
||||
GeneralPOJO row = refRow("n1", "MESSAGE");
|
||||
when(engine.loadPOJO(eq("n1"), eq(TABLE), any(Properties.class), anyBoolean()))
|
||||
.thenReturn(row);
|
||||
// view_page XML:MENUROOT 是 SelectDialog + dialogid=D1
|
||||
when(jdbc.queryForList(any(String.class), eq(String.class), eq("PAGE1")))
|
||||
.thenReturn(List.of("<page><fields>"
|
||||
+ "<field name='MENUROOT' uitype='SelectDialog' dialogid='D1'/>"
|
||||
+ "</fields></page>"));
|
||||
// dialog 解析 MESSAGE → 显示名「信息站」
|
||||
Map<String, Object> opt = new HashMap<>();
|
||||
opt.put("_id", "MESSAGE");
|
||||
opt.put("_label", "信息站");
|
||||
when(picker.resolveValuesToOptions(eq("D1"), eq("MESSAGE"),
|
||||
any(), any(), any(), any(), eq("_label"), eq("_id")))
|
||||
.thenReturn(List.of(opt));
|
||||
|
||||
EntityController c = new EntityController(engine, wl, jdbc, picker);
|
||||
Map<String, Object> resp = c.load(TABLE, "n1", "PAGE1");
|
||||
assertEquals(0, resp.get("status"));
|
||||
Map<String, Object> data = (Map<String, Object>) resp.get("data");
|
||||
Object menuRoot = data.get("MENUROOT");
|
||||
assertInstanceOf(Map.class, menuRoot, "SelectDialog 引用字段应解析为 {_id,_label} 对象");
|
||||
Map<String, Object> obj = (Map<String, Object>) menuRoot;
|
||||
assertEquals("MESSAGE", obj.get("_id"), "提交值仍是裸 id(picker valueField=_id)");
|
||||
assertEquals("信息站", obj.get("_label"), "自带 label 即显名");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void load带pageId_树对话框字段不转对象() {
|
||||
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||
PickerController picker = mock(PickerController.class);
|
||||
|
||||
// 行:PARENTID 是层级引用(tree-select),值是裸 id
|
||||
GeneralPOJO p = mock(GeneralPOJO.class);
|
||||
when(p.get_ID()).thenReturn("n1");
|
||||
when(p.get_ColumnCount()).thenReturn(1);
|
||||
when(p.get_ColumnName(0)).thenReturn("PARENTID");
|
||||
when(p.get_Value(0)).thenReturn("parent-1");
|
||||
when(engine.loadPOJO(eq("n1"), eq(TABLE), any(Properties.class), anyBoolean())).thenReturn(p);
|
||||
|
||||
when(jdbc.queryForList(any(String.class), eq(String.class), eq("PAGE1")))
|
||||
.thenReturn(List.of("<page><fields>"
|
||||
+ "<field name='PARENTID' uitype='SelectDialog' dialogid='TREE1'/>"
|
||||
+ "</fields></page>"));
|
||||
// TREE1 是 type=3 树对话框 → isTreeDialog=true → 不转对象
|
||||
when(jdbc.queryForObject(any(String.class), eq(Integer.class), eq("TREE1"))).thenReturn(3);
|
||||
|
||||
EntityController c = new EntityController(engine, wl, jdbc, picker);
|
||||
Map<String, Object> resp = c.load(TABLE, "n1", "PAGE1");
|
||||
Map<String, Object> data = (Map<String, Object>) resp.get("data");
|
||||
assertEquals("parent-1", data.get("PARENTID"), "tree-select 引用字段保持裸 id(不转对象,避免 amis 显 undefined)");
|
||||
// 树对话框不调 picker 解析
|
||||
verify(picker, never()).resolveValuesToOptions(any(), any(), any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void load无pageId_返原样不解析引用() {
|
||||
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||
PickerController picker = mock(PickerController.class);
|
||||
|
||||
GeneralPOJO row = refRow("n1", "MESSAGE");
|
||||
when(engine.loadPOJO(eq("n1"), eq(TABLE), any(Properties.class), anyBoolean()))
|
||||
.thenReturn(row);
|
||||
|
||||
EntityController c = new EntityController(engine, wl, jdbc, picker);
|
||||
Map<String, Object> resp = c.load(TABLE, "n1", null);
|
||||
assertEquals(0, resp.get("status"));
|
||||
Map<String, Object> data = (Map<String, Object>) resp.get("data");
|
||||
assertEquals("MESSAGE", data.get("MENUROOT"), "无 pageId 引用字段原样返回(CHAR trim 后裸值)");
|
||||
// 无 pageId 不读 view_page、不解析 dialog
|
||||
verify(jdbc, never()).queryForList(any(String.class), eq(String.class), any());
|
||||
verify(picker, never()).resolveValuesToOptions(any(), any(), any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ class PickerControllerTest {
|
||||
seedPoInfoCache(TABLE, fakeInfo());
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
Map<String, Object> resp = c.list(REF_ID, null, 1, 20, null, null, null, null);
|
||||
Map<String, Object> resp = c.list(REF_ID, null, 1, 20, null, null, null, null, null, null, null, null);
|
||||
assertEquals(0, resp.get("status"));
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> data = (Map<String, Object>) resp.get("data");
|
||||
@@ -165,7 +165,7 @@ class PickerControllerTest {
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
// path 用实体表名(小写也可,内部 toUpperCase)
|
||||
Map<String, Object> resp = c.list("sys_usergroup", null, 1, 20, null, null, null, null);
|
||||
Map<String, Object> resp = c.list("sys_usergroup", null, 1, 20, null, null, null, null, null, null, null, null);
|
||||
assertEquals(0, resp.get("status"));
|
||||
verify(wl).requireLegalTable(TABLE);
|
||||
}
|
||||
@@ -181,7 +181,7 @@ class PickerControllerTest {
|
||||
seedPoInfoCache(TABLE, fakeInfo());
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
c.list(REF_ID, "管理'员%组", 1, 20, null, null, null, null);
|
||||
c.list(REF_ID, "管理'员%组", 1, 20, null, null, null, null, null, null, null, null);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<Map<String, Object>> condCap = ArgumentCaptor.forClass(Map.class);
|
||||
@@ -202,7 +202,7 @@ class PickerControllerTest {
|
||||
seedPoInfoCache(TABLE, fakeInfo());
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
c.list(REF_ID, null, 3, 15, null, null, null, null);
|
||||
c.list(REF_ID, null, 3, 15, null, null, null, null, null, null, null, null);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<Map<String, Object>> condCap = ArgumentCaptor.forClass(Map.class);
|
||||
@@ -223,7 +223,7 @@ class PickerControllerTest {
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
IllegalIdentifierException ex = assertThrows(IllegalIdentifierException.class,
|
||||
() -> c.list("nope", null, 1, 20, null, null, null, null));
|
||||
() -> c.list("nope", null, 1, 20, null, null, null, null, null, null, null, null));
|
||||
assertFalse(ex.getMessage().contains("'")); // 不回显注入载荷
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ class PickerControllerTest {
|
||||
seedPoInfoCache(TABLE, fakeInfo());
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
c.list(REF_ID, null, 1, 20, "alice", "role-a,role-b", null, null);
|
||||
c.list(REF_ID, null, 1, 20, null, null, null, "alice", "role-a,role-b", null, null, null);
|
||||
|
||||
ArgumentCaptor<Properties> ctxCap = ArgumentCaptor.forClass(Properties.class);
|
||||
verify(engine).listSelect(any(), eq(TABLE), ctxCap.capture());
|
||||
@@ -262,7 +262,7 @@ class PickerControllerTest {
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
assertThrows(IllegalIdentifierException.class,
|
||||
() -> c.list(REF_ID, null, 1, 20, null, null, null, null));
|
||||
() -> c.list(REF_ID, null, 1, 20, null, null, null, null, null, null, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -296,7 +296,7 @@ class PickerControllerTest {
|
||||
seedPoInfoCache("PM_PROJECT", fakeInfo());
|
||||
PickerController c = new PickerController(engine, dic, wl, jdbc);
|
||||
|
||||
Map<String, Object> resp = c.list(dialogId, null, 1, 20, null, null, null, null);
|
||||
Map<String, Object> resp = c.list(dialogId, null, 1, 20, null, null, null, null, null, null, null, null);
|
||||
assertEquals(0, resp.get("status"));
|
||||
verify(wl).requireLegalTable("PM_PROJECT"); // 解析出 PM_PROJECT 并过白名单
|
||||
verify(engine).listSelect(any(), eq("PM_PROJECT"), any(Properties.class));
|
||||
@@ -328,7 +328,7 @@ class PickerControllerTest {
|
||||
seedPoInfoCache("VIEW_SYS_USER", fakeInfo());
|
||||
PickerController c = new PickerController(engine, dic, wl, jdbc);
|
||||
|
||||
Map<String, Object> resp = c.list(dialogId, null, 1, 20, null, null, null, null);
|
||||
Map<String, Object> resp = c.list(dialogId, null, 1, 20, null, null, null, null, null, null, null, null);
|
||||
|
||||
assertEquals(0, resp.get("status"));
|
||||
verify(wl).requireLegalTable("VIEW_SYS_USER"); // 路由到 VIEW_SYS_USER 并过白名单
|
||||
@@ -380,7 +380,7 @@ class PickerControllerTest {
|
||||
when(engine.listSelect(any(), eq("VIEW_SYS_USER"), any(Properties.class))).thenReturn(result);
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
Map<String, Object> resp = c.list(REF_ID, null, 1, 20, null, null, null, null);
|
||||
Map<String, Object> resp = c.list(REF_ID, null, 1, 20, null, null, null, null, null, null, null, null);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> data = (Map<String, Object>) resp.get("data");
|
||||
@@ -413,7 +413,7 @@ class PickerControllerTest {
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
// 以非 admin 用户身份调用(asUser=ceshi,模拟真实登录用户)
|
||||
Map<String, Object> resp = c.list(REF_ID, null, 1, 20, null, null, null, null);
|
||||
Map<String, Object> resp = c.list(REF_ID, null, 1, 20, null, null, null, null, null, null, null, null);
|
||||
|
||||
assertEquals(0, resp.get("status"));
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -452,7 +452,7 @@ class PickerControllerTest {
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
// 不应抛异常,不应 500
|
||||
Map<String, Object> resp = c.list(REF_ID, null, 1, 20, null, null, null, null);
|
||||
Map<String, Object> resp = c.list(REF_ID, null, 1, 20, null, null, null, null, null, null, null, null);
|
||||
|
||||
assertEquals(0, resp.get("status"));
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -468,4 +468,326 @@ class PickerControllerTest {
|
||||
assertTrue(resp.get("msg").toString().contains("权限"),
|
||||
"msg 应包含权限相关提示,实际: " + resp.get("msg"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, Object>> resolveData(Map<String, Object> resp) {
|
||||
return (List<Map<String, Object>>) resp.get("data");
|
||||
}
|
||||
|
||||
/**
|
||||
* resolve 主路径:单值 → keyColumn IN 查回 → 返回 {@code [{_id,_label}]},且 {@code _label}
|
||||
* 与 {@link PickerController#list} 同源(同 displayColumn 口径)。这是「picker 加载已存 id 自动显名」
|
||||
* 的后端落点(对齐老系统 DialogDisplayUtil.parseDisplay)。
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("14. resolve:单值 → _label 与 list 同源(显示列)")
|
||||
void resolveSingleValueReturnsSameLabelAsList() {
|
||||
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||
DataDicService dic = mock(DataDicService.class);
|
||||
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||
when(dic.getReferenceEntityTableName(REF_ID)).thenReturn(TABLE);
|
||||
Map<String, Object> result = engineResult(fakeRow("g1", "管理员组"));
|
||||
when(engine.listSelect(any(), eq(TABLE), any(Properties.class))).thenReturn(result);
|
||||
seedPoInfoCache(TABLE, fakeInfo());
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
Map<String, Object> resp = c.resolve(REF_ID, "g1", null, null, null, null);
|
||||
|
||||
assertEquals(0, resp.get("status"));
|
||||
List<Map<String, Object>> data = resolveData(resp);
|
||||
assertEquals(1, data.size());
|
||||
assertEquals("g1", data.get(0).get("_id"));
|
||||
// _label 取显示列(LABEL/NAME),与 list 返回的 option.label/_label 同口径
|
||||
assertEquals("管理员组", data.get(0).get("_label"));
|
||||
verify(wl).requireLegalTable(TABLE);
|
||||
// keyColumn IN (...) 条件下推(List 值)
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<Map<String, Object>> condCap = ArgumentCaptor.forClass(Map.class);
|
||||
verify(engine).listSelect(condCap.capture(), eq(TABLE), any(Properties.class));
|
||||
Object keyCond = condCap.getValue().get(KEY);
|
||||
assertTrue(keyCond instanceof List, "keyColumn 条件应为 List(IN 查询)");
|
||||
assertTrue(((List<?>) keyCond).contains("g1"));
|
||||
}
|
||||
|
||||
/**
|
||||
* resolve 同源断言(核心契约):同一 dialog、同一行,resolve 的 {@code _label} 必须等于 list 的
|
||||
* {@code option.label}/{@code _label}(同显示名)。
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("15. resolve 的 _label 与 list 的 option.label 字字相同(同 dialog 同显示名)")
|
||||
void resolveLabelMatchesListLabelExactly() {
|
||||
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||
DataDicService dic = mock(DataDicService.class);
|
||||
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||
when(dic.getReferenceEntityTableName(REF_ID)).thenReturn(TABLE);
|
||||
// list 与 resolve 用同一行数据源(同 fakeRow),断言两端 label 相等
|
||||
// 先建结果再 stub,避免「stubbing 内嵌 fakeRow 的 stubbing」破坏 Mockito 状态
|
||||
Map<String, Object> result = engineResult(fakeRow("g1", "管理员组"));
|
||||
when(engine.listSelect(any(), eq(TABLE), any(Properties.class))).thenReturn(result);
|
||||
seedPoInfoCache(TABLE, fakeInfo());
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
Map<String, Object> listResp = c.list(REF_ID, null, 1, 20, null, null, null, null, null, null, null, null);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> listDataMap = (Map<String, Object>) listResp.get("data");
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> options = (List<Map<String, Object>>) listDataMap.get("options");
|
||||
Object listLabel = options.get(0).get("label");
|
||||
|
||||
Map<String, Object> resolveResp = c.resolve(REF_ID, "g1", null, null, null, null);
|
||||
Object resolveLabel = resolveData(resolveResp).get(0).get("_label");
|
||||
|
||||
assertEquals(listLabel, resolveLabel, "resolve 的 _label 必须与 list 的 option.label 同源");
|
||||
}
|
||||
|
||||
/**
|
||||
* resolve 多值:逗号分隔 → 一次 IN 查回,结果按入参顺序回填(多选 picker 回显场景)。
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("16. resolve:多值(逗号分隔) → 按入参顺序回填")
|
||||
void resolveMultiValuePreservesInputOrder() {
|
||||
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||
DataDicService dic = mock(DataDicService.class);
|
||||
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||
when(dic.getReferenceEntityTableName(REF_ID)).thenReturn(TABLE);
|
||||
// 引擎以任意顺序返回(g2 在前),resolve 须按入参顺序(g1,g2)回填
|
||||
Map<String, Object> result = engineResult(fakeRow("g2", "普通组"), fakeRow("g1", "管理员组"));
|
||||
when(engine.listSelect(any(), eq(TABLE), any(Properties.class))).thenReturn(result);
|
||||
seedPoInfoCache(TABLE, fakeInfo());
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
Map<String, Object> resp = c.resolve(REF_ID, "g1,g2", null, null, null, null);
|
||||
|
||||
List<Map<String, Object>> data = resolveData(resp);
|
||||
assertEquals(2, data.size());
|
||||
assertEquals("g1", data.get(0).get("_id"));
|
||||
assertEquals("管理员组", data.get(0).get("_label"));
|
||||
assertEquals("g2", data.get(1).get("_id"));
|
||||
assertEquals("普通组", data.get(1).get("_label"));
|
||||
}
|
||||
|
||||
/**
|
||||
* resolve 兜底:查不到的 value → {@code {_id:value,_label:value}}(不丢值、不报错,picker 至少显裸 id)。
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("17. resolve:查不到的 value 兜底 {_id:value,_label:value}")
|
||||
void resolveFallsBackForUnknownValue() {
|
||||
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||
DataDicService dic = mock(DataDicService.class);
|
||||
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||
when(dic.getReferenceEntityTableName(REF_ID)).thenReturn(TABLE);
|
||||
// 只查到 g1,gX 查不到 → gX 走兜底
|
||||
Map<String, Object> result = engineResult(fakeRow("g1", "管理员组"));
|
||||
when(engine.listSelect(any(), eq(TABLE), any(Properties.class))).thenReturn(result);
|
||||
seedPoInfoCache(TABLE, fakeInfo());
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
Map<String, Object> resp = c.resolve(REF_ID, "g1,gX", null, null, null, null);
|
||||
|
||||
List<Map<String, Object>> data = resolveData(resp);
|
||||
assertEquals(2, data.size());
|
||||
assertEquals("管理员组", data.get(0).get("_label"));
|
||||
// 查不到的 gX 兜底:_id 与 _label 都是原值
|
||||
assertEquals("gX", data.get(1).get("_id"));
|
||||
assertEquals("gX", data.get(1).get("_label"));
|
||||
}
|
||||
|
||||
/**
|
||||
* resolve 空值/空白:value 为空或全空白 → 返回空 data(status=0),不触引擎、不报错。
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("18. resolve:空 value → 空 data,不触引擎")
|
||||
void resolveEmptyValueReturnsEmptyData() {
|
||||
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||
DataDicService dic = mock(DataDicService.class);
|
||||
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
Map<String, Object> resp = c.resolve(REF_ID, " ", null, null, null, null);
|
||||
|
||||
assertEquals(0, resp.get("status"));
|
||||
assertTrue(resolveData(resp).isEmpty());
|
||||
org.mockito.Mockito.verifyNoInteractions(engine);
|
||||
}
|
||||
|
||||
/**
|
||||
* resolve CHAR 主键 trim:入参带补白(尾空格) → trim 后比对命中,返回 _id 去补白。
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("19. resolve:CHAR 主键入参补白 → trim 后命中,_id 去补白")
|
||||
void resolveTrimsCharPaddingOnInputAndOutput() {
|
||||
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||
DataDicService dic = mock(DataDicService.class);
|
||||
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||
when(dic.getReferenceEntityTableName(REF_ID)).thenReturn(TABLE);
|
||||
// 引擎行的 _id 带 CHAR 补白("g1 "),toRow.trimId 去补白为 "g1"
|
||||
Map<String, Object> result = engineResult(fakeRow("g1 ", "管理员组"));
|
||||
when(engine.listSelect(any(), eq(TABLE), any(Properties.class))).thenReturn(result);
|
||||
seedPoInfoCache(TABLE, fakeInfo());
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
// 入参也带补白("g1 ")
|
||||
Map<String, Object> resp = c.resolve(REF_ID, "g1 ", null, null, null, null);
|
||||
|
||||
List<Map<String, Object>> data = resolveData(resp);
|
||||
assertEquals(1, data.size());
|
||||
assertEquals("g1", data.get(0).get("_id")); // 入参 trim
|
||||
assertEquals("管理员组", data.get(0).get("_label")); // 命中显示名(非裸 id)
|
||||
}
|
||||
|
||||
/**
|
||||
* resolve 权限降级:非用户目录 picker 被 PrivilegeException 拒绝 → 全部走兜底(显裸 id),
|
||||
* 不报错、不 500(与 list 的友好降级一致)。
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("20. resolve:PrivilegeException → 全部兜底(显裸 id),不 500")
|
||||
void resolveDegradesToFallbackOnPrivilegeException() {
|
||||
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||
DataDicService dic = mock(DataDicService.class);
|
||||
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||
when(dic.getReferenceEntityTableName(REF_ID)).thenReturn("PM_PROJECT");
|
||||
when(engine.listSelect(any(), eq("PM_PROJECT"), any(Properties.class)))
|
||||
.thenThrow(new PrivilegeException("没有PM_PROJECT数据访问权限"));
|
||||
seedPoInfoCache("PM_PROJECT", fakeInfo());
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
Map<String, Object> resp = c.resolve(REF_ID, "p1", null, null, null, null);
|
||||
|
||||
assertEquals(0, resp.get("status"));
|
||||
List<Map<String, Object>> data = resolveData(resp);
|
||||
assertEquals(1, data.size());
|
||||
assertEquals("p1", data.get(0).get("_id"));
|
||||
assertEquals("p1", data.get(0).get("_label")); // 权限拒绝 → 兜底显裸 id
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, Object>> listOptions(Map<String, Object> resp) {
|
||||
Map<String, Object> data = (Map<String, Object>) resp.get("data");
|
||||
return (List<Map<String, Object>>) data.get("options");
|
||||
}
|
||||
|
||||
/**
|
||||
* amis picker 加载已存值原生回环:{@code GET /list?op=loadOptions&value=<v>&_id=<v>} → 短路到
|
||||
* 按值解析显示名,返回 {@code data.options:[{label,value}]}(amis loadOptions/setOptions 直接消费),
|
||||
* 选中项遂显人可读名而非裸 id。这是「全站 picker 加载即显名」的运行时落点(无需重转换/改前端 source)。
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("21. list?op=loadOptions:按值解析 → data.options 含 {label,value}(显名)")
|
||||
void listLoadOptionsResolvesValueToOption() {
|
||||
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||
DataDicService dic = mock(DataDicService.class);
|
||||
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||
when(dic.getReferenceEntityTableName(REF_ID)).thenReturn(TABLE);
|
||||
Map<String, Object> result = engineResult(fakeRow("g1", "管理员组"));
|
||||
when(engine.listSelect(any(), eq(TABLE), any(Properties.class))).thenReturn(result);
|
||||
seedPoInfoCache(TABLE, fakeInfo());
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
// amis 同时带 value 与 _id;op=loadOptions → 短路解析
|
||||
Map<String, Object> resp = c.list(REF_ID, null, 1, 20, "loadOptions", "g1", "g1",
|
||||
null, null, null, null, null);
|
||||
|
||||
assertEquals(0, resp.get("status"));
|
||||
List<Map<String, Object>> options = listOptions(resp);
|
||||
assertEquals(1, options.size());
|
||||
// 每个选项同带两套键:_id/_label(转换器 picker valueField=_id/labelField=_label)
|
||||
// 与 value/label(amis 默认 field)——任意 picker field 配置都能匹配显名。
|
||||
assertEquals("g1", options.get(0).get("_id"));
|
||||
assertEquals("管理员组", options.get(0).get("_label"));
|
||||
assertEquals("g1", options.get(0).get("value"));
|
||||
assertEquals("管理员组", options.get(0).get("label"));
|
||||
// keyColumn IN 条件下推(与 /resolve 同源)
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<Map<String, Object>> condCap = ArgumentCaptor.forClass(Map.class);
|
||||
verify(engine).listSelect(condCap.capture(), eq(TABLE), any(Properties.class));
|
||||
assertTrue(condCap.getValue().get(KEY) instanceof List);
|
||||
}
|
||||
|
||||
/**
|
||||
* list?op=loadOptions 用 {@code _id}(amis valueField=_id 透传)当值(value 缺省时兜底取 _id)。
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("22. list?op=loadOptions:value 缺省 → 取 _id 当值解析")
|
||||
void listLoadOptionsFallsBackToIdParam() {
|
||||
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||
DataDicService dic = mock(DataDicService.class);
|
||||
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||
when(dic.getReferenceEntityTableName(REF_ID)).thenReturn(TABLE);
|
||||
Map<String, Object> result = engineResult(fakeRow("g1", "管理员组"));
|
||||
when(engine.listSelect(any(), eq(TABLE), any(Properties.class))).thenReturn(result);
|
||||
seedPoInfoCache(TABLE, fakeInfo());
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
// value=null,_id=g1
|
||||
Map<String, Object> resp = c.list(REF_ID, null, 1, 20, "loadOptions", null, "g1",
|
||||
null, null, null, null, null);
|
||||
|
||||
List<Map<String, Object>> options = listOptions(resp);
|
||||
assertEquals(1, options.size());
|
||||
assertEquals("管理员组", options.get(0).get("label"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 多选 picker(multiple)加载已存值:amis 用 {@code qs(arrayFormat=indices)} 把数组序列化成
|
||||
* {@code value[0]=v1&value[1]=v2}(indexed),Spring 标量形参 {@code value} 绑不到,需从
|
||||
* {@code allParams} 捞 {@code value[*]}。覆盖 {@link PickerController#collectLoadOptionsValues}
|
||||
* 的多选路径——这是 live 验收揪出的 400 边界(多选 picker 显裸 id)的修复。
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("23. list?op=loadOptions:多选 indexed(value[0]/value[1]) → 全部解析显名")
|
||||
void listLoadOptionsHandlesIndexedArrayForMultiple() {
|
||||
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||
DataDicService dic = mock(DataDicService.class);
|
||||
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||
when(dic.getReferenceEntityTableName(REF_ID)).thenReturn(TABLE);
|
||||
Map<String, Object> result = engineResult(fakeRow("g1", "管理员组"), fakeRow("g2", "普通组"));
|
||||
when(engine.listSelect(any(), eq(TABLE), any(Properties.class))).thenReturn(result);
|
||||
seedPoInfoCache(TABLE, fakeInfo());
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
// amis 多选序列化:value[0]=g1&value[1]=g2&op=loadOptions(scalar value/_id 均空)
|
||||
org.springframework.util.MultiValueMap<String, String> all =
|
||||
new org.springframework.util.LinkedMultiValueMap<>();
|
||||
all.add("value[0]", "g1");
|
||||
all.add("value[1]", "g2");
|
||||
all.add("op", "loadOptions");
|
||||
Map<String, Object> resp = c.list(REF_ID, null, 1, 20, "loadOptions", null, null,
|
||||
null, null, null, null, all);
|
||||
|
||||
List<Map<String, Object>> options = listOptions(resp);
|
||||
assertEquals(2, options.size());
|
||||
// 两个值都解析为显示名(顺序对齐入参 g1,g2),两套键齐全
|
||||
assertEquals("管理员组", options.get(0).get("_label"));
|
||||
assertEquals("g1", options.get(0).get("_id"));
|
||||
assertEquals("管理员组", options.get(0).get("label"));
|
||||
assertEquals("g1", options.get(0).get("value"));
|
||||
assertEquals("普通组", options.get(1).get("_label"));
|
||||
assertEquals("g2", options.get(1).get("_id"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通 list(op 缺省)不受影响:仍返回 items/options/columns/total 全套(弹窗 CRUD 列表路径不变)。
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("24. list(op 缺省):列表/分页/列路径不受 loadOptions 短路影响")
|
||||
void listWithoutOpStillReturnsFullCrudPayload() {
|
||||
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||
DataDicService dic = mock(DataDicService.class);
|
||||
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||
when(dic.getReferenceEntityTableName(REF_ID)).thenReturn(TABLE);
|
||||
Map<String, Object> result = engineResult(fakeRow("g1", "管理员组"), fakeRow("g2", "普通组"));
|
||||
when(engine.listSelect(any(), eq(TABLE), any(Properties.class))).thenReturn(result);
|
||||
seedPoInfoCache(TABLE, fakeInfo());
|
||||
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc());
|
||||
|
||||
Map<String, Object> resp = c.list(REF_ID, null, 1, 20, null, null, null, null, null, null, null, null);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> data = (Map<String, Object>) resp.get("data");
|
||||
assertTrue(data.containsKey("items")); // 弹窗 CRUD 仍拿全套
|
||||
assertTrue(data.containsKey("options"));
|
||||
assertTrue(data.containsKey("columns"));
|
||||
assertTrue(data.containsKey("total"));
|
||||
assertEquals(2, ((List<?>) data.get("options")).size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,6 +234,39 @@ class TemplateTreeControllerTest {
|
||||
assertEquals("1", body.get("page"));
|
||||
}
|
||||
|
||||
/**
|
||||
* type=4 选择框 picker:treegrid 右表响应每行补 {@code _label}(= 网格实体显示列值),
|
||||
* 供 picker(labelField=_label)显选中项人可读名而非裸 id。显示列 NAME(mock isentitydisplay=1 → NAME)。
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("treegrid 端点:响应每行补 _label(=显示列值) 供 picker 显名")
|
||||
@SuppressWarnings("unchecked")
|
||||
void treeGrid_补_label供picker显名() {
|
||||
// 用 CAT 表(setup 已 mock 其 isentitydisplay=NAME + 物理列含 NAME),flow 返带 items 的可变响应
|
||||
List<Map<String, Object>> items = new ArrayList<>();
|
||||
Map<String, Object> r1 = new LinkedHashMap<>();
|
||||
r1.put("_id", "ROW1");
|
||||
r1.put("NAME", "功能甲");
|
||||
items.add(r1);
|
||||
Map<String, Object> r2 = new LinkedHashMap<>();
|
||||
r2.put("_id", "ROW2");
|
||||
r2.put("NAME", ""); // 空显示值 → _label 回落主键
|
||||
items.add(r2);
|
||||
Map<String, Object> data = new LinkedHashMap<>();
|
||||
data.put("items", items);
|
||||
data.put("total", 2);
|
||||
Map<String, Object> respBody = new LinkedHashMap<>();
|
||||
respBody.put("status", 0);
|
||||
respBody.put("data", data);
|
||||
when(flow.executePost(eq("CAT_SEARCH"), any(), any()))
|
||||
.thenReturn(ResponseEntity.ok(respBody));
|
||||
|
||||
controller.treeGrid(TREE_REF, "CAT", "PARENTID", "", "1", "10", Map.of());
|
||||
|
||||
assertEquals("功能甲", items.get(0).get("_label"), "显示列(NAME)非空 → _label=显示值");
|
||||
assertEquals("ROW2", items.get(1).get("_label"), "显示列空 → _label 回落主键 _id");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("treegrid 端点:非法表名/列名 → 400,不触达引擎")
|
||||
void treeGrid_IDENT守卫() {
|
||||
|
||||
Reference in New Issue
Block a user