diff --git a/platform-metadata/src/main/java/com/eip4/platform/metadata/flow/FlowInputCoercer.java b/platform-metadata/src/main/java/com/eip4/platform/metadata/flow/FlowInputCoercer.java
index 207cf46..d2992fa 100644
--- a/platform-metadata/src/main/java/com/eip4/platform/metadata/flow/FlowInputCoercer.java
+++ b/platform-metadata/src/main/java/com/eip4/platform/metadata/flow/FlowInputCoercer.java
@@ -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 主键对齐)。
+ *
+ *
背景:master-detail 右编辑表单经 {@code form initApi} 把引用字段载为对象(picker 自带 label
+ * 即显名,spike 实证只此可靠显名);「载入后不改直接保存」时 amis 不触发 valueField 提取 → 整个对象
+ * 进 payload。本扁平化是后端唯一收口点(零前端改动),保证引擎收到的引用列恒为裸 id。fail-safe:
+ * 任何异常都不抛、不阻断写。
+ */
+ static void flattenPickerObjects(Map map) {
+ for (Map.Entry 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 map, Map colTypes) {
for (Map.Entry entry : map.entrySet()) {
diff --git a/platform-metadata/src/main/java/com/eip4/platform/metadata/web/EntityController.java b/platform-metadata/src/main/java/com/eip4/platform/metadata/web/EntityController.java
index 9476632..a6945c9 100644
--- a/platform-metadata/src/main/java/com/eip4/platform/metadata/web/EntityController.java
+++ b/platform-metadata/src/main/java/com/eip4/platform/metadata/web/EntityController.java
@@ -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=]
+ *
+ * {@code pageId} 引用字段对象解析(picker 加载即显名):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 load(@PathVariable String table, @PathVariable String id) {
+ public Map 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 row = toRow(p);
+ if (pageId != null && !pageId.isBlank()) {
+ resolveReferenceFields(row, pageId.trim());
+ }
+ data = row;
+ } else {
+ data = pojo;
+ }
Map 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;
}
@@ -210,4 +241,139 @@ public class EntityController {
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 row, String pageId) {
+ List 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