fix(platform): resolve picker load defaults
Some checks failed
ci / build-test-parity (push) Has been cancelled
Some checks failed
ci / build-test-parity (push) Has been cancelled
This commit is contained in:
@@ -36,7 +36,7 @@
|
||||
| 范围 | 状态 | 缺口 | 下一步 |
|
||||
|---|---|---|---|
|
||||
| 流程/审批:待办任务 `TaskComponentNew` | Needs side-effect verification | 浏览器已验 `4ebfc9ee`、`0f7531e2`:列表有数据、发起人显名、查看详细抽屉、处理抽屉、遮罩层级均正常;未点最终同意/拒绝,未验处理后刷新 | 准备专门测试流程实例,或经用户确认可消耗真实待办后,再验“同意/拒绝/退回后列表刷新” |
|
||||
| 用户选择框全家 | Implemented / Needs business verification | 最新口径:`eip4-platform 0d6fab4` 已把用户单选 `SelectDialog`、多选 `MultiSelectDialog` 统一转换为标准 amis `picker`(单选不加 `multiple`,多选仅加 `multiple: true` + `overflowConfig.maxTagCount=1`,数据源 `/api/picker/<dialogid>/list`);`eip4-web b0537f8` 兼容过滤器会把存量 `user-transfer-picker` schema 归一成同一标准 picker,本轮补丁进一步移除旧自定义 renderer 注册,只保留 schema filter。自动化:`npm run test -- registerUserTransferPicker registerMessageAction`、`npm run build`、`mvn -q -pl platform-converter -Dtest=TemplateToAmisConverterTest test`、`mvn -q -pl platform-metadata -Dtest=NoticeControllerTest test`。浏览器烟测:`54042d08` 查询单选「操作人」为标准 PickerControl;`919477da`「流程代理授权」代理人为标准单选 picker,和日期/下拉同高对齐;`5078945c`「用户组-分配用户」为标准多选 picker,默认值/label 正常,图标可打开二级 amis 表格弹窗,含搜索/分页/checkbox,多选确认后输入框仍 32px 且显示 `+ N ...`,未再撑开表单;短消息 `ae79a47b` 已覆盖多选 picker 选人并保存。 | 继续在设置定时任务、岗位设置等真实引用页验保存值、ALL 互斥、受控/全部权限差异和考勤排除挂靠 |
|
||||
| 用户选择框全家 | Implemented / Needs business verification | 最新口径:用户单选 `SelectDialog`、多选 `MultiSelectDialog` 均使用标准 amis `picker`(单选不加 `multiple`;多选 `multiple:true` + `overflowConfig.maxTagCount=1`;数据源 `/api/picker/<dialogid>/list`),`eip4-web` 兼容过滤器继续把存量 `user-transfer-picker` 归一成标准 picker。本轮补丁补齐运行时默认值契约:转换器给编辑/查看弹窗 load 服务追加 `?__egtpl=<editFormViewPageId>`,`FlowController` 按该编辑表单 XML 将 load 返回的 `SelectDialog/MultiSelectDialog` 裸 id 解析为 `{_id,_label}`(多选为对象数组),避免默认值显示 UUID 或撑开布局。部署:`BatchConvertCli` 全量重转 2757 项(view_page 编辑表单 1241 个产物),`SchemaImportCli` 扫描 2727 个产物、入库/更新 1054 个,8093 已重启。自动化:`mvn -q -pl platform-converter -Dtest=TemplateToAmisConverterTest#read按钮接load服务_dialog用api加载本体数据,TemplateToAmisConverterTest#crud_用户单选框受控转标准Picker,TemplateToAmisConverterTest#crud_用户选择框组织与考勤模式接线,TemplateToAmisConverterTest#crud_multiSelectDialog转picker多选弹窗 test`、`mvn -q -pl platform-metadata -Dtest=FlowControllerTest#postLoadWithEditTemplateResolvesPickerDefaults test`、`npm test -- --run src/amis/registerUserTransferPicker.test.ts`。浏览器烟测:`5078945c`「用户组-分配用户」为标准多选 picker,默认值显示 `施继栋002[222222]`、无裸 UUID、控件 32px、二级弹窗含搜索/分页/checkbox;`919477da`「流程代理授权」代理人为标准单选 picker,控件与 label 对齐且二级弹窗实际 input 类型为 radio;短消息 `ae79a47b` 已覆盖多选 picker 选人并保存。 | 继续在设置定时任务、岗位设置等真实引用页验保存值、ALL 互斥、受控/全部权限差异和考勤排除挂靠 |
|
||||
| 流程选择框 | Implemented / Needs business verification | `ProcessSelectController` 已提供 `/api/process-select/options|search`;转换器已把 `b3070157` 接到 amis `transfer-picker`;`919477da` 流程代理授权已重转重导并从 PARTIAL 转 SUCCESS;浏览器 smoke 可打开弹窗,显示「流程名称/已选流程」和流程名 | 继续验流程代理授权保存闭环:代理类型=指定流程时必填、保存后 `wf_agent_process` 写入/读取一致 |
|
||||
| 菜单真入口 | Needs verification | 前端已去硬编码假入口;需确认所有需要的真菜单在 `sys_menu` 中可达 | 用 `/api/menu` 和页面侧栏核对 |
|
||||
| 功能模板下载门控 | Pending | backlog 写了 `VIEW_TEMPLATEID` 非空才显示附件编辑;当前只做了去按钮/改标题 | 决定是否补门控,若补则在 `EngineclassDelta` mutator 中按行/上下文控制 |
|
||||
|
||||
@@ -877,12 +877,13 @@ public class TemplateToAmisConverter {
|
||||
if (loadService != null && !loadService.isBlank() && primaryKey != null && !primaryKey.isBlank()) {
|
||||
Map<String, Object> api = new LinkedHashMap<>();
|
||||
api.put("method", "post");
|
||||
api.put("url", "/api/flow/" + loadService);
|
||||
api.put("url", "/api/flow/" + loadService + editTemplateQuery(templateId));
|
||||
api.put("data", new LinkedHashMap<>(Map.of(primaryKey, "${" + primaryKey + "}")));
|
||||
api.put("responseData", new LinkedHashMap<>(Map.of("&", "${result}")));
|
||||
service.put("api", api);
|
||||
result.note("dialog[" + title + "] 接 load 服务 " + loadService
|
||||
+ " → service.api POST 按 " + primaryKey + " 加载本体数据(result 拍平,readOnly 保留 static 只读)");
|
||||
+ " → service.api POST 按 " + primaryKey
|
||||
+ " 加载本体数据(result 拍平,readOnly 保留 static 只读,透传编辑模板解析 picker 默认值)");
|
||||
} else if ((primaryKey == null || primaryKey.isBlank())
|
||||
&& tableName != null && !tableName.isBlank()) {
|
||||
// B:新建(添加)dialog——无选中行/无 load 服务。接默认值端点服务端解析 initvalue 宏
|
||||
@@ -930,9 +931,7 @@ public class TemplateToAmisConverter {
|
||||
submitBtn.put("actionType", "submit"); // 下钻内层 form,采集字段值
|
||||
// A1 compute-on-save:带 ?__egtpl=<editFormTemplateId> 透传给 FlowController,落库前补算
|
||||
// editgrid 派生字段(金额/总额)。无 editgrid 的表单后端自然无操作。
|
||||
String egTpl = (templateId != null && !templateId.isBlank() && !templateId.startsWith("MISSING_"))
|
||||
? "?__egtpl=" + templateId : "";
|
||||
submitBtn.put("api", "POST:/api/flow/" + svc + egTpl);
|
||||
submitBtn.put("api", "POST:/api/flow/" + svc + editTemplateQuery(templateId));
|
||||
submitBtn.put("close", true); // 成功后关闭 dialog
|
||||
dlgActions.add(submitBtn);
|
||||
result.note("dialog[" + title + "] method " + mname
|
||||
@@ -952,6 +951,11 @@ public class TemplateToAmisConverter {
|
||||
return dlg;
|
||||
}
|
||||
|
||||
private static String editTemplateQuery(String templateId) {
|
||||
return templateId != null && !templateId.isBlank() && !templateId.startsWith("MISSING_")
|
||||
? "?__egtpl=" + templateId : "";
|
||||
}
|
||||
|
||||
/** 兼容旧调用:read 按钮无 methods,使用默认确认/取消。 */
|
||||
private Map<String, Object> buildFormDialog(String title, String templateId,
|
||||
String primaryKey, boolean readOnly,
|
||||
|
||||
@@ -487,7 +487,7 @@ class TemplateToAmisConverterTest {
|
||||
Map<String, Object> service = (Map<String, Object>) ((Map<String, Object>) viewBtn.get("dialog")).get("body");
|
||||
Map<String, Object> api = (Map<String, Object>) service.get("api");
|
||||
assertNotNull(api, "查看 dialog service 应接 load api 加载本体");
|
||||
assertEquals("/api/flow/OA_X_SHOW", api.get("url"));
|
||||
assertEquals("/api/flow/OA_X_SHOW?__egtpl=PM_DEMO", api.get("url"));
|
||||
assertEquals("post", api.get("method"));
|
||||
assertEquals(Boolean.TRUE, service.get("static"), "查看(read)保留 static → 只读显示(与 api 并存,浏览器实证)");
|
||||
// 查看态注入 __readonly:service.static 传导不到 input-table 子表与「添加」按钮,
|
||||
|
||||
@@ -9,10 +9,15 @@ import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
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.PostMapping;
|
||||
@@ -75,22 +80,36 @@ public class FlowController {
|
||||
private final FlowInputCoercer inputCoercer;
|
||||
/** A1 compute-on-save:写流执行前为 editgrid 子表补算派生字段(金额/总额)。可空(老单测构造)。 */
|
||||
private final EditGridDerivedFieldComputer editGridComputer;
|
||||
/** 编辑弹窗 load:把 picker 默认值裸 id 解析成 {_id,_label}。可空(老单测构造)。 */
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PickerController pickerController;
|
||||
|
||||
/** Spring 注入入口(6 参:读写分类器 + 类型强制器 + editgrid 派生字段补算器)。
|
||||
/** Spring 注入入口(8 参:读写分类器 + 类型强制器 + editgrid 派生字段补算器 + picker 默认值解析)。
|
||||
* 多构造器场景须显式 @Autowired 指明注入构造,否则 Spring 回退无参构造致启动失败。 */
|
||||
@org.springframework.beans.factory.annotation.Autowired
|
||||
public FlowController(FlowExcuteService flowExcuteService, FlowNameResolver flowNameResolver,
|
||||
UserColumnResolver userColumnResolver, FlowReadWriteClassifier classifier,
|
||||
FlowInputCoercer inputCoercer, EditGridDerivedFieldComputer editGridComputer) {
|
||||
FlowInputCoercer inputCoercer, EditGridDerivedFieldComputer editGridComputer,
|
||||
JdbcTemplate jdbcTemplate, PickerController pickerController) {
|
||||
this.flowExcuteService = flowExcuteService;
|
||||
this.flowNameResolver = flowNameResolver;
|
||||
this.userColumnResolver = userColumnResolver;
|
||||
this.classifier = classifier;
|
||||
this.inputCoercer = inputCoercer;
|
||||
this.editGridComputer = editGridComputer;
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
this.pickerController = pickerController;
|
||||
}
|
||||
|
||||
/** 兼容老单测的五参构造(无 editgrid 补算器)。生产由 Spring 走六参构造。 */
|
||||
/** 兼容老单测的六参构造(无 picker 默认值解析)。生产由 Spring 走八参构造。 */
|
||||
public FlowController(FlowExcuteService flowExcuteService, FlowNameResolver flowNameResolver,
|
||||
UserColumnResolver userColumnResolver, FlowReadWriteClassifier classifier,
|
||||
FlowInputCoercer inputCoercer, EditGridDerivedFieldComputer editGridComputer) {
|
||||
this(flowExcuteService, flowNameResolver, userColumnResolver, classifier, inputCoercer,
|
||||
editGridComputer, null, null);
|
||||
}
|
||||
|
||||
/** 兼容老单测的五参构造(无 editgrid 补算器)。生产由 Spring 走八参构造。 */
|
||||
public FlowController(FlowExcuteService flowExcuteService, FlowNameResolver flowNameResolver,
|
||||
UserColumnResolver userColumnResolver, FlowReadWriteClassifier classifier,
|
||||
FlowInputCoercer inputCoercer) {
|
||||
@@ -121,16 +140,23 @@ public class FlowController {
|
||||
@GetMapping("/{id}")
|
||||
@Operation(summary = "执行服务流(GET):query 参数作为入参 map,返回流输出 JSON。报表 D 类查询入口")
|
||||
public ResponseEntity<Map<String, Object>> executeGet(@PathVariable String id,
|
||||
@RequestParam(value = "__egtpl", required = false) String egTpl,
|
||||
@RequestParam Map<String, String> allParams) {
|
||||
Map<String, Object> map = new HashMap<>(allParams);
|
||||
map.remove("__egtpl");
|
||||
applyPaging(map);
|
||||
try {
|
||||
return run(id, map, false);
|
||||
return run(id, map, false, egTpl);
|
||||
} catch (RuntimeException ex) {
|
||||
return gracefulFlowError(id, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/** 兼容老单测直接调用的两参入口;HTTP 入口走带 __egtpl 的三参方法。 */
|
||||
ResponseEntity<Map<String, Object>> executeGet(String id, Map<String, String> allParams) {
|
||||
return executeGet(id, null, allParams);
|
||||
}
|
||||
|
||||
/** POST 执行:JSON body 透传为服务流入参 map。body 为空时按空 map 执行。 */
|
||||
@PostMapping("/{id}")
|
||||
@Operation(summary = "执行服务流(POST):JSON body 作为入参 map,返回流输出 JSON")
|
||||
@@ -145,7 +171,7 @@ public class FlowController {
|
||||
editGridComputer.enrich(map, egTpl);
|
||||
}
|
||||
try {
|
||||
return run(id, map, true);
|
||||
return run(id, map, true, egTpl);
|
||||
} catch (RuntimeException ex) {
|
||||
return gracefulFlowError(id, ex);
|
||||
}
|
||||
@@ -274,7 +300,7 @@ public class FlowController {
|
||||
*
|
||||
* @param isPost 是否 POST 请求(GET=false)。写流仅 POST 放行,防 URL 触发写。
|
||||
*/
|
||||
private ResponseEntity<Map<String, Object>> run(String id, Map<String, Object> map, boolean isPost) {
|
||||
private ResponseEntity<Map<String, Object>> run(String id, Map<String, Object> map, boolean isPost, String egTpl) {
|
||||
ResolvedFlow resolved = flowNameResolver.resolve(id);
|
||||
|
||||
return switch (resolved.type()) {
|
||||
@@ -286,7 +312,7 @@ public class FlowController {
|
||||
}
|
||||
Properties ctx = UserSession.getAdmin();
|
||||
Object output = withEngineContext(ctx, () -> flowExcuteService.excute(map, ctx, id));
|
||||
yield ok(output, null);
|
||||
yield ok(output, null, egTpl);
|
||||
}
|
||||
case NAMED_READ -> {
|
||||
// 命名读流:GET/POST 皆可。WS-D D.3:命名读流(如查看新闻查询 OA_NEWSMANAGE_SEARCH_LOOK)按其
|
||||
@@ -299,7 +325,7 @@ public class FlowController {
|
||||
}
|
||||
Properties ctx = UserSession.getAdmin();
|
||||
Object output = withEngineContext(ctx, () -> flowExcuteService.excute(map, ctx, id));
|
||||
yield ok(output, flowNameResolver.entityTableForNamedFlow(id));
|
||||
yield ok(output, flowNameResolver.entityTableForNamedFlow(id), egTpl);
|
||||
}
|
||||
case NAMED_WRITE -> {
|
||||
// 命名写流:GET 拒绝(防 URL 触发写);POST 用真实 JWT 用户上下文执行
|
||||
@@ -334,7 +360,7 @@ public class FlowController {
|
||||
Map<String, Object> agg = new LinkedHashMap<>();
|
||||
agg.put("count", results.size());
|
||||
agg.put("results", results);
|
||||
yield ok(agg, null);
|
||||
yield ok(agg, null, egTpl);
|
||||
}
|
||||
// amis JSON body 全为 String,引擎 GeneralPO.load 按 POJOInfo 列类型直接 cast:
|
||||
// ENUMERATE/INTEGER/STATUS→Integer、BOOLEAN→Boolean、DECIMAL→BigDecimal。
|
||||
@@ -344,7 +370,7 @@ public class FlowController {
|
||||
}
|
||||
Properties ctx = currentCtx();
|
||||
Object output = withEngineContext(ctx, () -> flowExcuteService.excute(map, ctx, id));
|
||||
yield ok(output, null);
|
||||
yield ok(output, null, egTpl);
|
||||
}
|
||||
case SYNTHESIZED -> {
|
||||
// _SEARCH 合成:合成流已注册到 SynthesizedFlowRegistry,
|
||||
@@ -358,7 +384,7 @@ public class FlowController {
|
||||
}
|
||||
Object output = withEngineContext(ctx, () -> flowExcuteService.excute(map, ctx, flowKey));
|
||||
// 合成搜索流的 key = <TABLE>_SEARCH,剥后缀即数据源实体表名,用于用户引用列 id→姓名解析
|
||||
yield ok(output, tableFromSearchKey(flowKey));
|
||||
yield ok(output, tableFromSearchKey(flowKey), egTpl);
|
||||
}
|
||||
case ORPHAN -> {
|
||||
Map<String, Object> err = new LinkedHashMap<>();
|
||||
@@ -409,10 +435,11 @@ public class FlowController {
|
||||
}
|
||||
}
|
||||
|
||||
private ResponseEntity<Map<String, Object>> ok(Object output, String table) {
|
||||
private ResponseEntity<Map<String, Object>> ok(Object output, String table, String egTpl) {
|
||||
Object data = unwrapCrudResult(normalize(output));
|
||||
// read-path issue D1=603:把元数据标记为用户引用的列 id/工号 → 姓名(仅在已知数据源实体的合成搜索流上)
|
||||
resolveUserColumns(data, table);
|
||||
resolveReferenceFields(data, egTpl);
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
resp.put("status", 0);
|
||||
resp.put("msg", "");
|
||||
@@ -493,6 +520,162 @@ public class FlowController {
|
||||
}
|
||||
}
|
||||
|
||||
/** view_page 里的可编辑引用字段:列名(大写) + dialogid(picker 数据源) + 是否多选。 */
|
||||
private record RefField(String name, String dialogid, boolean multi) {}
|
||||
|
||||
/**
|
||||
* 编辑弹窗 service.api load 后,标准 picker 的默认值必须是 {@code {_id,_label}} 对象(多选为对象数组)。
|
||||
* 老服务流只回裸 id/裸 id 数组;带 {@code __egtpl=<编辑表单 view_page_id>} 时,按该模板 XML 解析
|
||||
* {@code SelectDialog/MultiSelectDialog} 字段并补显示名,避免控件展开成长串 ID。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void resolveReferenceFields(Object data, String pageId) {
|
||||
if (pageId == null || pageId.isBlank() || jdbcTemplate == null || pickerController == null) {
|
||||
return;
|
||||
}
|
||||
if (!(data instanceof Map<?, ?> m0)) {
|
||||
return;
|
||||
}
|
||||
Map<String, Object> map = (Map<String, Object>) m0;
|
||||
if (map.get("items") instanceof List<?>) {
|
||||
return;
|
||||
}
|
||||
Object resultObj = map.get("result");
|
||||
Map<String, Object> record = resultObj instanceof Map<?, ?> r ? (Map<String, Object>) r : map;
|
||||
List<RefField> refs = referenceFields(pageId);
|
||||
if (refs.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (RefField rf : refs) {
|
||||
Object raw = record.get(rf.name());
|
||||
if (raw == null) {
|
||||
continue;
|
||||
}
|
||||
if (rf.multi()) {
|
||||
if (raw instanceof List<?> rawList && rawList.stream().allMatch(Map.class::isInstance)) {
|
||||
continue;
|
||||
}
|
||||
List<Map<String, Object>> resolved = new ArrayList<>();
|
||||
for (String value : splitRefValues(raw)) {
|
||||
resolved.add(resolveRefValue(rf.dialogid(), value));
|
||||
}
|
||||
if (!resolved.isEmpty()) {
|
||||
record.put(rf.name(), resolved);
|
||||
}
|
||||
} else if (!(raw instanceof Map<?, ?>)) {
|
||||
String value = String.valueOf(raw).trim();
|
||||
if (!value.isBlank()) {
|
||||
record.put(rf.name(), resolveRefValue(rf.dialogid(), value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 多选引用字段可能来自逗号串,也可能来自 JSON 数组;统一拆为非空 id 列表。 */
|
||||
private static List<String> splitRefValues(Object raw) {
|
||||
List<String> values = new ArrayList<>();
|
||||
if (raw instanceof List<?> list) {
|
||||
for (Object item : list) {
|
||||
String v = item == null ? "" : String.valueOf(item).trim();
|
||||
if (!v.isBlank()) {
|
||||
values.add(v);
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
String s = String.valueOf(raw).trim();
|
||||
if (s.startsWith("[") && s.endsWith("]")) {
|
||||
s = s.substring(1, s.length() - 1);
|
||||
}
|
||||
for (String part : s.split(",")) {
|
||||
String v = part.trim();
|
||||
if (!v.isBlank()) {
|
||||
values.add(v);
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
/** 单个引用值 → {@code {_id,_label}};查不到则回退原值,保证不丢数据。 */
|
||||
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 解析/查询异常不应阻断 load;picker 至少保留原始 id。
|
||||
}
|
||||
Map<String, Object> obj = new LinkedHashMap<>();
|
||||
obj.put("_id", value);
|
||||
obj.put("_label", value);
|
||||
return obj;
|
||||
}
|
||||
|
||||
/** 读编辑表单 XML,收集非树形 SelectDialog/MultiSelectDialog 字段。 */
|
||||
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;
|
||||
}
|
||||
if (!isTreeDialog(dialogid)) {
|
||||
refs.add(new RefField(name.toUpperCase(), dialogid, multi));
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return refs;
|
||||
}
|
||||
|
||||
/** type=3 树形对话框由 tree-select 自己拉 source 显名,不转成 picker 对象。 */
|
||||
private boolean isTreeDialog(String dialogId) {
|
||||
try {
|
||||
Integer type = jdbcTemplate.queryForObject(
|
||||
"SELECT type FROM view_template WHERE view_template_id = ?",
|
||||
Integer.class, dialogId);
|
||||
return type != null && type == 3;
|
||||
} catch (DataAccessException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 取 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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* F2-14b:流输出变量名为 result(DefaultFlowHelper 默认搜索流口径),查询结果被包成
|
||||
* {result:{items,total}},而 amis crud 契约读 data.items/data.total——一层之差导致
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
@@ -154,6 +155,54 @@ class FlowControllerTest {
|
||||
assertNotNull(resp.getBody().get("data"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("4a. 带 __egtpl 的 load 响应: picker 单/多选默认值裸 id → {_id,_label}")
|
||||
@SuppressWarnings("unchecked")
|
||||
void postLoadWithEditTemplateResolvesPickerDefaults() {
|
||||
String flowId = "SYS_USERGROUP_LOAD";
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("USERS", List.of("u1", "u2"));
|
||||
result.put("OWNER", "u3");
|
||||
Map<String, Object> output = new LinkedHashMap<>();
|
||||
output.put("result", result);
|
||||
|
||||
FlowExcuteService engine = mock(FlowExcuteService.class);
|
||||
when(engine.excute(any(), any(), eq(flowId))).thenReturn(output);
|
||||
|
||||
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||
when(jdbc.queryForList(any(String.class), eq(String.class), eq("PAGE1")))
|
||||
.thenReturn(List.of("<page><fields>"
|
||||
+ "<field name='USERS' uitype='MultiSelectDialog' dialogid='D_USERS'/>"
|
||||
+ "<field name='OWNER' uitype='SelectDialog' dialogid='D_USER'/>"
|
||||
+ "</fields></page>"));
|
||||
when(jdbc.queryForObject(any(String.class), eq(Integer.class), any())).thenReturn(1);
|
||||
|
||||
PickerController picker = mock(PickerController.class);
|
||||
when(picker.resolveValuesToOptions(any(), any(), any(), any(), any(), any(), eq("_label"), eq("_id")))
|
||||
.thenAnswer(inv -> {
|
||||
String value = inv.getArgument(1);
|
||||
Map<String, Object> opt = new LinkedHashMap<>();
|
||||
opt.put("_id", value);
|
||||
opt.put("_label", "姓名" + value);
|
||||
return List.of(opt);
|
||||
});
|
||||
|
||||
FlowController controller = new FlowController(engine, resolverReturning(flowId, namedHit()),
|
||||
null, null, null, null, jdbc, picker);
|
||||
|
||||
ResponseEntity<Map<String, Object>> resp = controller.executePost(flowId, "PAGE1",
|
||||
new LinkedHashMap<>(Map.of("SYS_USERGROUP_ID", "g1")));
|
||||
|
||||
Map<String, Object> data = (Map<String, Object>) resp.getBody().get("data");
|
||||
Map<String, Object> loaded = (Map<String, Object>) data.get("result");
|
||||
List<Map<String, Object>> users = (List<Map<String, Object>>) loaded.get("USERS");
|
||||
assertEquals("u1", users.get(0).get("_id"));
|
||||
assertEquals("姓名u1", users.get(0).get("_label"));
|
||||
Map<String, Object> owner = (Map<String, Object>) loaded.get("OWNER");
|
||||
assertEquals("u3", owner.get("_id"));
|
||||
assertEquals("姓名u3", owner.get("_label"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("4b. 无 JWT 上下文时,读流执行期间临时绑定 ADMIN UserSession,执行后清理")
|
||||
void readFlowBindsAdminUserSessionWhenMissing() {
|
||||
|
||||
Reference in New Issue
Block a user