feat(editgrid): 主子表编辑页可用——默认值/编号+子表选品picker+数值校验+行内脚本引擎+日期coerce+保存端到端
以「办公用品采购申请编辑页」为镜补齐主子表(EditGrid)功能模板转换缺口,子表 editgrid 从「不可用」到可加行/选品/算金额/保存落库。
D 数值校验: UiTypeMapper NumberField 读 vmin/vmax → amis min/max(applyNumberBound)。
B 默认值/编号: FormDefaultsController(/api/form/{table}/defaults)服务端解析 initvalue 宏
(复用 GetDefaultValueFunction) + {AUTOGENERATECODE}→CodeRuleService.getCode + _DISPLAY__回填;
LegacyXmlWiring 注册 codeRuleService bean(零改 com.dsasp);转换器添加 dialog 接 defaults + 补 {CURRENTDEPART}。
A 子表行内交互: EditGridScriptRunner(faithful 跑原 Groovy,类型保真,绑定 event/group/group.parent/loadPOJO)
+ EditGridScriptController(/api/script/execute-editgrid-row);转换器 buildEditGridColumns 挂 quickEdit.onEvent.change
(outputVar/row=${__rendererData}/componentId+index)+子表内只读 SelectDialog→picker 列+addable;input-table/form 加 id。
picker 400 修复: PickerController.resolveByViewTemplate 支持 <tree><treetemplate><gridtemplate> 树+网格选择窗
(取 gridtemplate 网格实体作数据源),修「子表选用品 400 非法实体」。
日期写流缺口(引擎级通用): FlowInputCoercer 补 DATE/TIME → joda DateTime(毫秒/ISO/yyyy-MM-dd[ HH:mm:ss]),
修一切含日期列表单写流 ClassCastException(String→DateTime)崩。
compute-on-save: EditGridDerivedFieldComputer(两遍:行内派生→父聚合)+FlowController ?__egtpl= 入口,
落库前补算 editgrid 派生字段(对 display-only 非列键 no-op,对有派生列模板通用生效)。
验证: 主子表 _ADD 端到端实证落库(master+2子行,FK PURCHASE_ID 自动回填,APPLYDATE coerce 落库);
picker/默认值浏览器实证;converter 108 + metadata 相关 67 测试绿。
注: 本提交亦携带工作区既有未提交改动(FlowController normalize 深度上限保护等)。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,8 @@ import com.dsasp.server.core.service.FlowServiceImpl;
|
|||||||
import com.dsasp.server.file.service.FileServiceImpl;
|
import com.dsasp.server.file.service.FileServiceImpl;
|
||||||
import com.dsasp.server.log.service.DataLogRecorderImpl;
|
import com.dsasp.server.log.service.DataLogRecorderImpl;
|
||||||
import com.dsasp.server.log.service.SystemLogManagerImpl;
|
import com.dsasp.server.log.service.SystemLogManagerImpl;
|
||||||
|
import com.dsasp.server.common.dataDic.service.CodeRuleService;
|
||||||
|
import com.dsasp.server.dataDic.service.CodeRuleServiceImpl;
|
||||||
import com.dsasp.server.dataDic.service.POJOCRUDServiceImpl;
|
import com.dsasp.server.dataDic.service.POJOCRUDServiceImpl;
|
||||||
import com.dsasp.server.dataDic.service.POJOServiceImpl;
|
import com.dsasp.server.dataDic.service.POJOServiceImpl;
|
||||||
import com.dsasp.server.organize.service.AssignmentHandlerImpl;
|
import com.dsasp.server.organize.service.AssignmentHandlerImpl;
|
||||||
@@ -120,4 +122,18 @@ public class LegacyXmlWiring implements SmartInitializingSingleton {
|
|||||||
public JodaModule jodaModule() {
|
public JodaModule jodaModule() {
|
||||||
return new JodaModule();
|
return new JodaModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* B:编号规则服务({@code CodeRuleServiceImpl})。原框架经 XML <property> setter 注入
|
||||||
|
* jdbcTemplate/pojoCRUDService,无 {@code @Service} 注解(非 component-scan bean)。这里等价
|
||||||
|
* 显式装配(旧类零修改,守「零改 com.dsasp」),供 {@code FormDefaultsController} 解析
|
||||||
|
* {@code {AUTOGENERATECODE}} 流水号(按 SYS_CODERULE 规则)。setter 填充的字段即 @Autowired 同字段。
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public CodeRuleService codeRuleService() {
|
||||||
|
CodeRuleServiceImpl impl = new CodeRuleServiceImpl();
|
||||||
|
impl.setJdbcTemplate(jdbcTemplate);
|
||||||
|
impl.setPojoCRUDService(pojoCRUDService);
|
||||||
|
return impl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -311,9 +311,11 @@ public final class BatchConvertCli {
|
|||||||
System.out.println("[WS-B][对齐告警] " + id + " 转换器算 keyed-script 数=" + keptByConverter
|
System.out.println("[WS-B][对齐告警] " + id + " 转换器算 keyed-script 数=" + keptByConverter
|
||||||
+ " ≠ 盘上文件数=" + seqsOnDisk.size() + "(seq 枚举可能与改写器偏差,请核对 //script 范围/长度阈值)");
|
+ " ≠ 盘上文件数=" + seqsOnDisk.size() + "(seq 枚举可能与改写器偏差,请核对 //script 范围/长度阈值)");
|
||||||
}
|
}
|
||||||
|
// keyToSeq 提到 bindings 判定之外:post-pass attachDialogOnloadScripts 需对「有按钮
|
||||||
|
// onloadscript 但 body 无事件绑定」的页也能解析弹窗 service marker 的 scriptKey→seq。
|
||||||
|
Map<String, Integer> keyToSeq = parseKeyToSeq(xml);
|
||||||
List<TemplateToAmisConverter.EventBinding> bindings = parseEventBindings(xml);
|
List<TemplateToAmisConverter.EventBinding> bindings = parseEventBindings(xml);
|
||||||
if (!bindings.isEmpty()) {
|
if (!bindings.isEmpty()) {
|
||||||
Map<String, Integer> keyToSeq = parseKeyToSeq(xml);
|
|
||||||
// 小修#1:解析 onselected 绑定脚本(盘上 rewritten/<id>/<seq>.*.groovy)正文里的
|
// 小修#1:解析 onselected 绑定脚本(盘上 rewritten/<id>/<seq>.*.groovy)正文里的
|
||||||
// enableButton 目标按钮名集合 —— 据此对「脚本永不引用」的业务按钮 per-button 降级
|
// enableButton 目标按钮名集合 —— 据此对「脚本永不引用」的业务按钮 per-button 降级
|
||||||
// disabledOn(如新闻「提交审批」从无 enableButton(提交审批) → 选中即可点,免永久灰)。
|
// disabledOn(如新闻「提交审批」从无 enableButton(提交审批) → 选中即可点,免永久灰)。
|
||||||
@@ -328,6 +330,14 @@ public final class BatchConvertCli {
|
|||||||
summary.onEventCount++;
|
summary.onEventCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// read/update 弹窗按钮的 onloadscript:buildFormDialog 给弹窗 service 打了
|
||||||
|
// x-onload-script-key marker,此处据 keyToSeq 解析 seq 并挂到 service.onEvent.inited
|
||||||
|
// (弹窗打开时完整执行脚本,与 service.static 只读基线共存);fail-closed:盘上无脚本删 marker 跳过。
|
||||||
|
converter.attachDialogOnloadScripts(result.getSchema(), id, keyToSeq, seqsOnDisk::contains);
|
||||||
|
} else {
|
||||||
|
// 无 rewriterDir(attachOnEvent 关闭):弹窗 service 仍可能带 onloadscript marker
|
||||||
|
// (buildFormDialog 转换期就打)。无落盘脚本可挂 → fail-closed 全删 marker,不残留到产物。
|
||||||
|
converter.attachDialogOnloadScripts(result.getSchema(), id, Map.of(), seq -> false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// C2:无 onselectedscript(脚本控启停)的 crud 页——含完全无绑定的页(attachScriptOnEvent
|
// C2:无 onselectedscript(脚本控启停)的 crud 页——含完全无绑定的页(attachScriptOnEvent
|
||||||
@@ -376,7 +386,9 @@ public final class BatchConvertCli {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
List<String> notes = new ArrayList<>();
|
List<String> notes = new ArrayList<>();
|
||||||
ConversionResult result = converter.convertGraded(xml, name, notes, pageResolver);
|
// A1:传 view_page_id 作 templateId,使 editgrid 行内脚本 onEvent 能带 templateId 调
|
||||||
|
// /api/script/execute-editgrid-row(运行时按 templateId 解析 editgridtemplate 脚本)。
|
||||||
|
ConversionResult result = converter.convertGraded(xml, id, name, notes, pageResolver);
|
||||||
boolean gate1 = false;
|
boolean gate1 = false;
|
||||||
if (result.getSchema() != null) {
|
if (result.getSchema() != null) {
|
||||||
List<String> errors = gate.validate(result.getSchema());
|
List<String> errors = gate.validate(result.getSchema());
|
||||||
|
|||||||
@@ -409,7 +409,9 @@ public class TemplateToAmisConverter {
|
|||||||
+ " 识别为主键列(designName/label=主键 或 _ID 结尾长名) → 跳过查询区(F3-1)");
|
+ " 识别为主键列(designName/label=主键 或 _ID 结尾长名) → 跳过查询区(F3-1)");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
items.add(UiTypeMapper.mapField(f, result, "search", colMeta));
|
Map<String, Object> searchItem = UiTypeMapper.mapField(f, result, "search", colMeta);
|
||||||
|
enrichFieldRefs(searchItem, f, result);
|
||||||
|
items.add(searchItem);
|
||||||
}
|
}
|
||||||
if (items.isEmpty()) {
|
if (items.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
@@ -473,8 +475,9 @@ public class TemplateToAmisConverter {
|
|||||||
btn.put("level", "primary");
|
btn.put("level", "primary");
|
||||||
btn.put("actionType", "dialog");
|
btn.put("actionType", "dialog");
|
||||||
List<Element> insertMethods = b.elements("method");
|
List<Element> insertMethods = b.elements("method");
|
||||||
|
// B:传 table 使「添加」dialog 能接默认值端点 /api/form/{table}/defaults(新建预填)。
|
||||||
Map<String, Object> dlg = buildFormDialog(btnName, editFormTemplateId, null, false,
|
Map<String, Object> dlg = buildFormDialog(btnName, editFormTemplateId, null, false,
|
||||||
null, insertMethods, result);
|
table, insertMethods, null, null, result);
|
||||||
btn.put("dialog", dlg);
|
btn.put("dialog", dlg);
|
||||||
result.note("button[insert] " + btnName + " → dialog 加载 /api/page/schema/" + editFormTemplateId
|
result.note("button[insert] " + btnName + " → dialog 加载 /api/page/schema/" + editFormTemplateId
|
||||||
+ "(pageid=" + pageId + ",methods=" + insertMethods.size() + ")");
|
+ "(pageid=" + pageId + ",methods=" + insertMethods.size() + ")");
|
||||||
@@ -548,7 +551,8 @@ public class TemplateToAmisConverter {
|
|||||||
btn.put("disabledOn", "${!selectedItems || selectedItems.length === 0}");
|
btn.put("disabledOn", "${!selectedItems || selectedItems.length === 0}");
|
||||||
List<Element> updateMethods = b.elements("method");
|
List<Element> updateMethods = b.elements("method");
|
||||||
Map<String, Object> dlg = buildFormDialog(btnName, editFormTemplateId,
|
Map<String, Object> dlg = buildFormDialog(btnName, editFormTemplateId,
|
||||||
table + "_ID", false, table, updateMethods, result);
|
table + "_ID", false, table, updateMethods, loadServiceOf(b),
|
||||||
|
onloadScriptKeyOf(b), result);
|
||||||
btn.put("dialog", dlg);
|
btn.put("dialog", dlg);
|
||||||
result.note("button[update] " + btnName + " → dialog 加载 /api/page/schema/" + editFormTemplateId
|
result.note("button[update] " + btnName + " → dialog 加载 /api/page/schema/" + editFormTemplateId
|
||||||
+ ",传选中行主键(pageid=" + pageId + ",methods=" + updateMethods.size() + ")");
|
+ ",传选中行主键(pageid=" + pageId + ",methods=" + updateMethods.size() + ")");
|
||||||
@@ -559,7 +563,8 @@ public class TemplateToAmisConverter {
|
|||||||
btn.put("actionType", "dialog");
|
btn.put("actionType", "dialog");
|
||||||
btn.put("disabledOn", "${!selectedItems || selectedItems.length === 0}");
|
btn.put("disabledOn", "${!selectedItems || selectedItems.length === 0}");
|
||||||
Map<String, Object> dlg = buildFormDialog(btnName, editFormTemplateId,
|
Map<String, Object> dlg = buildFormDialog(btnName, editFormTemplateId,
|
||||||
table + "_ID", true, table, result);
|
table + "_ID", true, table, null, loadServiceOf(b),
|
||||||
|
onloadScriptKeyOf(b), result);
|
||||||
btn.put("dialog", dlg);
|
btn.put("dialog", dlg);
|
||||||
result.note("button[read] " + btnName + " → dialog 加载 /api/page/schema/" + editFormTemplateId
|
result.note("button[read] " + btnName + " → dialog 加载 /api/page/schema/" + editFormTemplateId
|
||||||
+ "(查看态 static=true,pageid=" + pageId + ")");
|
+ "(查看态 static=true,pageid=" + pageId + ")");
|
||||||
@@ -589,11 +594,15 @@ public class TemplateToAmisConverter {
|
|||||||
* @param readOnly 查看态,service 加 static=true
|
* @param readOnly 查看态,service 加 static=true
|
||||||
* @param tableName 实体表名(保留参数,当前用于台账记录)
|
* @param tableName 实体表名(保留参数,当前用于台账记录)
|
||||||
* @param methods 按钮的 <method> 子元素(服务流提交按钮来源);null/空 → 保留默认确认/取消
|
* @param methods 按钮的 <method> 子元素(服务流提交按钮来源);null/空 → 保留默认确认/取消
|
||||||
|
* @param onloadScriptKey 按钮 {@code onloadscript} 脚本 key(弹窗打开时跑的联动脚本);非空时给 service
|
||||||
|
* body 打 {@link #DIALOG_ONLOAD_SCRIPT_KEY} marker,由 {@link #attachDialogOnloadScripts}
|
||||||
|
* post-pass 解析 seq 后挂到 service.onEvent.inited。null/空 → 不打 marker。
|
||||||
* @param result 转换结果台账
|
* @param result 转换结果台账
|
||||||
*/
|
*/
|
||||||
private Map<String, Object> buildFormDialog(String title, String templateId,
|
private Map<String, Object> buildFormDialog(String title, String templateId,
|
||||||
String primaryKey, boolean readOnly,
|
String primaryKey, boolean readOnly,
|
||||||
String tableName, List<Element> methods,
|
String tableName, List<Element> methods,
|
||||||
|
String loadService, String onloadScriptKey,
|
||||||
ConversionResult result) {
|
ConversionResult result) {
|
||||||
Map<String, Object> dlg = new LinkedHashMap<>();
|
Map<String, Object> dlg = new LinkedHashMap<>();
|
||||||
dlg.put("type", "dialog");
|
dlg.put("type", "dialog");
|
||||||
@@ -623,6 +632,42 @@ public class TemplateToAmisConverter {
|
|||||||
if (readOnly) {
|
if (readOnly) {
|
||||||
service.put("static", true);
|
service.put("static", true);
|
||||||
}
|
}
|
||||||
|
// 接按钮 <load> 服务:service 用 api 跑读流按主键加载「本体」数据。跨实体查看/修改的关键——
|
||||||
|
// 列表行是收件/收藏记录,不含本体的 主题/内容(同实体如查看新闻碰巧行里就有,故旧实现也显;
|
||||||
|
// 跨实体如查看通知/各收藏页则空)。result 拍平到顶层供表单字段按 name 绑定。
|
||||||
|
// static(只读)与 api 并存有效(浏览器实证):查看(readOnly)保留 static → 内容以只读文本显示(等价老系统
|
||||||
|
// setViewWithoutEditor,不再需要绕道执行 onloadscript);修改(非 readOnly)无 static → 可编辑 + 预填。
|
||||||
|
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("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 只读)");
|
||||||
|
} else if ((primaryKey == null || primaryKey.isBlank())
|
||||||
|
&& tableName != null && !tableName.isBlank()) {
|
||||||
|
// B:新建(添加)dialog——无选中行/无 load 服务。接默认值端点服务端解析 initvalue 宏
|
||||||
|
// ({CURRENTUSER}/{CURRENTDEPART}/{CURRENTTIME} 等)+ {AUTOGENERATECODE} 流水号,
|
||||||
|
// 预填表单号/申请人/申请部门/申请日期。GET,data 直接拍平进 service 作用域(端点已返 {data:{...}})。
|
||||||
|
Map<String, Object> api = new LinkedHashMap<>();
|
||||||
|
api.put("method", "get");
|
||||||
|
api.put("url", "/api/form/" + tableName + "/defaults?templateId=" + templateId);
|
||||||
|
service.put("api", api);
|
||||||
|
result.note("dialog[" + title + "] 新建 → service.api GET /api/form/" + tableName
|
||||||
|
+ "/defaults(服务端解析 initvalue 宏 + AUTOGENERATECODE 编号预填)");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按钮 onloadscript:转换器此时无 seq/rewriterDir 解析能力,仅给 service 打 marker 记录 scriptKey,
|
||||||
|
// 由 BatchConvertCli post-pass attachDialogOnloadScripts 据盘上脚本解析 seq 后挂到 service.onEvent.inited
|
||||||
|
// (fail-closed:无对应落盘脚本则删 marker 跳过)。与 static(只读基线)共存:static=只读,脚本=额外联动。
|
||||||
|
if (onloadScriptKey != null && !onloadScriptKey.isBlank()) {
|
||||||
|
service.put(DIALOG_ONLOAD_SCRIPT_KEY, onloadScriptKey.trim());
|
||||||
|
result.note("dialog[" + title + "] 按钮 onloadscript=" + onloadScriptKey.trim()
|
||||||
|
+ " → service 打 " + DIALOG_ONLOAD_SCRIPT_KEY + " marker(post-pass 挂 inited 脚本链)");
|
||||||
|
}
|
||||||
|
|
||||||
dlg.put("body", service);
|
dlg.put("body", service);
|
||||||
|
|
||||||
// 服务流提交按钮:有 <method servicename> 时生成显式 dialog.actions,
|
// 服务流提交按钮:有 <method servicename> 时生成显式 dialog.actions,
|
||||||
@@ -646,7 +691,11 @@ public class TemplateToAmisConverter {
|
|||||||
submitBtn.put("label", mname.isBlank() ? "提交" : mname);
|
submitBtn.put("label", mname.isBlank() ? "提交" : mname);
|
||||||
submitBtn.put("level", "primary");
|
submitBtn.put("level", "primary");
|
||||||
submitBtn.put("actionType", "submit"); // 下钻内层 form,采集字段值
|
submitBtn.put("actionType", "submit"); // 下钻内层 form,采集字段值
|
||||||
submitBtn.put("api", "POST:/api/flow/" + svc);
|
// 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("close", true); // 成功后关闭 dialog
|
submitBtn.put("close", true); // 成功后关闭 dialog
|
||||||
dlgActions.add(submitBtn);
|
dlgActions.add(submitBtn);
|
||||||
result.note("dialog[" + title + "] method " + mname
|
result.note("dialog[" + title + "] method " + mname
|
||||||
@@ -670,7 +719,31 @@ public class TemplateToAmisConverter {
|
|||||||
private Map<String, Object> buildFormDialog(String title, String templateId,
|
private Map<String, Object> buildFormDialog(String title, String templateId,
|
||||||
String primaryKey, boolean readOnly,
|
String primaryKey, boolean readOnly,
|
||||||
String tableName, ConversionResult result) {
|
String tableName, ConversionResult result) {
|
||||||
return buildFormDialog(title, templateId, primaryKey, readOnly, tableName, null, result);
|
return buildFormDialog(title, templateId, primaryKey, readOnly, tableName, null, null, null, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提取按钮 {@code <load><method servicename="...">} 的加载服务名 —— 查看/修改弹窗据此跑读流按主键
|
||||||
|
* 加载「本体」数据(跨实体查看的关键,见 {@link #buildFormDialog})。无 load 节点/服务名 → null。
|
||||||
|
*/
|
||||||
|
private static String loadServiceOf(Element b) {
|
||||||
|
Element load = b != null ? b.element("load") : null;
|
||||||
|
Element m = load != null ? load.element("method") : null;
|
||||||
|
if (m == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String svc = m.attributeValue("servicename", "");
|
||||||
|
return svc.isBlank() ? null : svc.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提取按钮 {@code onloadscript="<scriptKey>"} 属性值 —— 查看/修改弹窗打开时要执行的脚本 key
|
||||||
|
* (setFieldValue/setFieldVisible/addButton 等弹窗联动逻辑;只读基线已由 service.static 覆盖)。
|
||||||
|
* 无 onloadscript / 空值 → null(弹窗不打 marker,不挂 inited 脚本链)。
|
||||||
|
*/
|
||||||
|
private static String onloadScriptKeyOf(Element b) {
|
||||||
|
String key = b != null ? b.attributeValue(ATTR_ON_LOAD) : null;
|
||||||
|
return (key == null || key.isBlank()) ? null : key.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -715,7 +788,22 @@ public class TemplateToAmisConverter {
|
|||||||
result.degrade("button pageid 为空 → 跳过精确匹配,尝试实体级回退");
|
result.degrade("button pageid 为空 → 跳过精确匹配,尝试实体级回退");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 第二级:实体级回退(同 entityId 的可写 type=7 editform)────────────────
|
// ── 第二级:A3 直接命中已迁移 view_page(按钮显式 pageid 优先于实体级猜测)────────────
|
||||||
|
// 无 type=7 包壳时,按钮 pageid 直指 view_page(全库≈1241,BatchConvertCli 第二循环已迁入
|
||||||
|
// sys_page_schema,key=view_page_id,与 view_template_id 实测零冲突)。命中即返 pageId →
|
||||||
|
// dialog 加载 /api/page/schema/{pageId} 取该编辑表单本体。
|
||||||
|
// 必须排在实体级回退【之前】:按钮的 pageid 是「这个按钮该开哪个表单」的权威声明;当 pageid 指向
|
||||||
|
// 的表单实体≠宿主页实体时(如「查看新闻」的「收藏」按钮 pageid 指 OA_NEWSCOLLECTION 收藏表单,
|
||||||
|
// 而宿主页实体是 OA_NEWSMANAGE 新闻),实体级回退会按宿主实体误选新闻编辑表单(dogfooding 实测:
|
||||||
|
// 收藏弹出新闻富文本编辑器而非选分类)。先尊重 pageid,回退仅兜「pageid 空/非真实 view_page」。
|
||||||
|
if (pageId != null && !pageId.isBlank() && viewPageExists(pageId)) {
|
||||||
|
result.note("button pageid=" + pageId
|
||||||
|
+ " → 直接指向已迁移 view_page(标准层 key=view_page_id),无 type=7 包壳,优先于实体级回退");
|
||||||
|
return pageId.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 第三级:实体级回退(同 entityId 的可写 type=7 editform)────────────────
|
||||||
|
// 仅当 pageid 空、或 pageid 非真实 view_page 时兜底(如纯实体动作按钮无 pageid 的场景)。
|
||||||
if (entityId != null && !entityId.isBlank()) {
|
if (entityId != null && !entityId.isBlank()) {
|
||||||
try {
|
try {
|
||||||
String fallbackId = jdbcTemplate.queryForObject(
|
String fallbackId = jdbcTemplate.queryForObject(
|
||||||
@@ -736,16 +824,6 @@ public class TemplateToAmisConverter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 第三级:A3 直接命中已迁移 view_page ───────────────────────────────────
|
|
||||||
// 无 type=7 包壳时,按钮 pageid 直指 view_page(全库≈1241,BatchConvertCli 第二循环已迁入
|
|
||||||
// sys_page_schema,key=view_page_id,与 view_template_id 实测零冲突)。命中即返 pageId →
|
|
||||||
// dialog 加载 /api/page/schema/{pageId} 取该编辑表单本体(告别旧 type=7 LIKE 序首猜测/只读归档误选)。
|
|
||||||
if (pageId != null && !pageId.isBlank() && viewPageExists(pageId)) {
|
|
||||||
result.note("button pageid=" + pageId
|
|
||||||
+ " → 直接指向已迁移 view_page(标准层 key=view_page_id),无 type=7 包壳");
|
|
||||||
return pageId.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── 第四级:MISSING 诚实降级 ─────────────────────────────────────────────
|
// ── 第四级:MISSING 诚实降级 ─────────────────────────────────────────────
|
||||||
result.degrade("button pageid=" + pageId
|
result.degrade("button pageid=" + pageId
|
||||||
+ " 无 type=7 包壳、无同实体 editform、view_page 也不存在 → 诚实降级");
|
+ " 无 type=7 包壳、无同实体 editform、view_page 也不存在 → 诚实降级");
|
||||||
@@ -764,6 +842,104 @@ public class TemplateToAmisConverter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mapField 之后的「引用字段」富化(需查元数据,故在转换器侧而非纯静态 {@link UiTypeMapper}):
|
||||||
|
* <ul>
|
||||||
|
* <li><b>#1 只读引用</b>(readonly SelectDialog/MultiSelectDialog 已渲为 static):把「被引用实体的显示列」
|
||||||
|
* 补进 tpl 回退链。修自引用列(如新闻收藏「主题」=OA_NEWSMANAGE_ID,行数据无 {@code _DISPLAY__}、
|
||||||
|
* 但带被引用实体显示列 TITLE)显 id 的问题。</li>
|
||||||
|
* <li><b>② 非 _SEARCH 列表服务</b>(comboboxitemservice 推不出表、UiTypeMapper 保底指了空字典 /api/poc/dict):
|
||||||
|
* 经 {@code sys_serviceflow.entityid} 解析数据源实体 → 改指 {@code /api/picker/{实体}/list}(返真实选项)。</li>
|
||||||
|
* </ul>
|
||||||
|
* 仅在 search/editform 字段循环调用(持有源 {@code <field>}),EditGrid 子列递归不富化(影响小)。
|
||||||
|
*/
|
||||||
|
private void enrichFieldRefs(Map<String, Object> item, Element f, ConversionResult result) {
|
||||||
|
if (item == null || f == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String uitype = f.attributeValue("uitype", "");
|
||||||
|
// #1:只读引用 static → 补被引用实体显示列到 tpl 回退链
|
||||||
|
if ("static".equals(item.get("type"))
|
||||||
|
&& ("SelectDialog".equals(uitype) || "MultiSelectDialog".equals(uitype))
|
||||||
|
&& "true".equals(f.attributeValue("readonly"))) {
|
||||||
|
String dialogId = f.attributeValue("dialogid", "");
|
||||||
|
if (!dialogId.isBlank()) {
|
||||||
|
String refCol = referencedEntityDisplayColumn(dialogId);
|
||||||
|
if (refCol != null && !refCol.isBlank()) {
|
||||||
|
String name = f.attributeValue("name", "");
|
||||||
|
item.put("tpl", "${" + name + "_DISPLAY__ ? " + name + "_DISPLAY__ : ("
|
||||||
|
+ refCol + " ? " + refCol + " : " + name + ")}");
|
||||||
|
result.note("只读引用 " + name + " → tpl 补被引用实体显示列 " + refCol + "(自引用列也显名)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ②:ComboBox 非 _SEARCH 列表服务保底指了空字典 → 经 sys_serviceflow 解析实体 → picker
|
||||||
|
if ("select".equals(item.get("type")) && item.get("source") instanceof String src
|
||||||
|
&& "ComboBox".equals(uitype)) {
|
||||||
|
String svc = f.attributeValue("comboboxitemservice", "").trim();
|
||||||
|
if (!svc.isBlank() && src.equals("/api/poc/dict/" + svc)) {
|
||||||
|
String table = serviceEntityTableByMeta(svc);
|
||||||
|
if (table != null && !table.isBlank()) {
|
||||||
|
item.put("source", "/api/picker/" + table + "/list?perPage=500");
|
||||||
|
result.note("ComboBox 列表服务 " + svc + " → sys_serviceflow 解析实体 " + table
|
||||||
|
+ " → /api/picker(非 _SEARCH 命名亦解析)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** dialogid(=view_template_id) → 根 {@code @entityid} → 该实体 {@code isentitydisplay=1} 显示列名(大写)。解析失败 → null。 */
|
||||||
|
private String referencedEntityDisplayColumn(String dialogId) {
|
||||||
|
if (dialogId == null || dialogId.isBlank()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
String xml = jdbcTemplate.queryForObject(
|
||||||
|
"SELECT xml::text FROM view_template WHERE view_template_id = ? AND xml IS NOT NULL",
|
||||||
|
String.class, dialogId);
|
||||||
|
if (xml == null || xml.isBlank()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
org.dom4j.Element root = org.dom4j.DocumentHelper.parseText(xml.trim()).getRootElement();
|
||||||
|
String entityId = root.attributeValue("entityid");
|
||||||
|
if ((entityId == null || entityId.isBlank()) && "tree".equals(root.getName())) {
|
||||||
|
for (org.dom4j.Element node : root.elements("node")) {
|
||||||
|
entityId = node.attributeValue("entityid");
|
||||||
|
if (entityId != null && !entityId.isBlank()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (entityId == null || entityId.isBlank()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String col = jdbcTemplate.queryForObject(
|
||||||
|
"SELECT a.columnname FROM sys_entityattribute a "
|
||||||
|
+ "WHERE UPPER(TRIM(a.entityid)) = UPPER(TRIM(?)) AND a.isentitydisplay=1 LIMIT 1",
|
||||||
|
String.class, entityId);
|
||||||
|
return col != null ? col.trim().toUpperCase() : null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null; // 解析/查询失败 → 不补(tpl 保留 UiTypeMapper 基线回退)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** comboboxitemservice(=sys_serviceflow_id) → 数据源实体表名(经 entityid 关联 sys_entity,大写)。解析失败 → null。 */
|
||||||
|
private String serviceEntityTableByMeta(String service) {
|
||||||
|
if (service == null || service.isBlank()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
String table = jdbcTemplate.queryForObject(
|
||||||
|
"SELECT e.tablename FROM sys_serviceflow s "
|
||||||
|
+ "JOIN sys_entity e ON UPPER(TRIM(e.sys_entity_id)) = UPPER(TRIM(s.entityid)) "
|
||||||
|
+ "WHERE UPPER(TRIM(s.sys_serviceflow_id)) = UPPER(TRIM(?))",
|
||||||
|
String.class, service);
|
||||||
|
return table != null ? table.trim().toUpperCase() : null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* F2-17:crud api 改为裸路径,不带 query 参数模板。
|
* F2-17:crud api 改为裸路径,不带 query 参数模板。
|
||||||
*
|
*
|
||||||
@@ -802,7 +978,9 @@ public class TemplateToAmisConverter {
|
|||||||
// 列元数据(含 enumeratetype):供 ComboBox 缺省 comboboxid 但 itemisenumerate=true 取枚举字典源
|
// 列元数据(含 enumeratetype):供 ComboBox 缺省 comboboxid 但 itemisenumerate=true 取枚举字典源
|
||||||
Map<String, String[]> colMeta = loadColumnMeta(entityId, result);
|
Map<String, String[]> colMeta = loadColumnMeta(entityId, result);
|
||||||
for (Element f : fields.elements("field")) {
|
for (Element f : fields.elements("field")) {
|
||||||
formItems.add(UiTypeMapper.mapField(f, result, "editform", colMeta));
|
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() + " 字段");
|
result.note("form@pageid=" + pageId + " → 解析 view_page 取得 " + formItems.size() + " 字段");
|
||||||
}
|
}
|
||||||
@@ -891,7 +1069,9 @@ public class TemplateToAmisConverter {
|
|||||||
Element fields = pageRoot.element("fields");
|
Element fields = pageRoot.element("fields");
|
||||||
if (fields != null) {
|
if (fields != null) {
|
||||||
for (Element f : fields.elements("field")) {
|
for (Element f : fields.elements("field")) {
|
||||||
formItems.add(UiTypeMapper.mapField(f, result, "editform", colMeta));
|
Map<String, Object> formItem = UiTypeMapper.mapField(f, result, "editform", colMeta);
|
||||||
|
enrichFieldRefs(formItem, f, result);
|
||||||
|
formItems.add(formItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (entityId == null || entityId.isBlank()) {
|
if (entityId == null || entityId.isBlank()) {
|
||||||
@@ -904,6 +1084,7 @@ public class TemplateToAmisConverter {
|
|||||||
String formTitle = templateName != null ? templateName : "";
|
String formTitle = templateName != null ? templateName : "";
|
||||||
Map<String, Object> formSchema = new LinkedHashMap<>();
|
Map<String, Object> formSchema = new LinkedHashMap<>();
|
||||||
formSchema.put("type", "form");
|
formSchema.put("type", "form");
|
||||||
|
formSchema.put("id", UiTypeMapper.EDIT_FORM_ID); // A1:供 editgrid 行内脚本 setValue 主表字段经 componentId 定位
|
||||||
formSchema.put("title", "");
|
formSchema.put("title", "");
|
||||||
formSchema.put("mode", "horizontal");
|
formSchema.put("mode", "horizontal");
|
||||||
Map<String, Object> labelAlign = new LinkedHashMap<>();
|
Map<String, Object> labelAlign = new LinkedHashMap<>();
|
||||||
@@ -912,7 +1093,32 @@ public class TemplateToAmisConverter {
|
|||||||
formSchema.put("body", buildFormBody(pageRoot, formItems, result));
|
formSchema.put("body", buildFormBody(pageRoot, formItems, result));
|
||||||
// 提交动作由调用方 dialog 的 _ADD/_SUBMIT 按钮(view_template 按钮 <method servicename>)提供,表单本体不带
|
// 提交动作由调用方 dialog 的 _ADD/_SUBMIT 按钮(view_template 按钮 <method servicename>)提供,表单本体不带
|
||||||
formSchema.put("actions", new ArrayList<>());
|
formSchema.put("actions", new ArrayList<>());
|
||||||
return page(formTitle, formSchema);
|
Map<String, Object> pageSchema = page(formTitle, formSchema);
|
||||||
|
// A1:把 editgrid 行内脚本 onEvent 里的 templateId 占位符替换为真实 view_page_id(currentTemplateId)。
|
||||||
|
injectEditGridTemplateId(pageSchema, currentTemplateId);
|
||||||
|
return pageSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A1:递归把 schema 里的 {@link UiTypeMapper#EDITGRID_TPL_PLACEHOLDER} 替换成真实 templateId。 */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static void injectEditGridTemplateId(Object node, String templateId) {
|
||||||
|
if (templateId == null || templateId.isBlank()) {
|
||||||
|
return; // 单测/旧入口无 templateId → 保留占位符(运行时该 onEvent 不生效,不影响渲染)
|
||||||
|
}
|
||||||
|
if (node instanceof Map<?, ?> m) {
|
||||||
|
for (Map.Entry<String, Object> e : ((Map<String, Object>) m).entrySet()) {
|
||||||
|
Object v = e.getValue();
|
||||||
|
if (v instanceof String s && UiTypeMapper.EDITGRID_TPL_PLACEHOLDER.equals(s)) {
|
||||||
|
e.setValue(templateId);
|
||||||
|
} else {
|
||||||
|
injectEditGridTemplateId(v, templateId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (node instanceof List<?> l) {
|
||||||
|
for (Object it : l) {
|
||||||
|
injectEditGridTemplateId(it, templateId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1483,6 +1689,16 @@ public class TemplateToAmisConverter {
|
|||||||
gridSchema.put("headerToolbar", toolbar);
|
gridSchema.put("headerToolbar", toolbar);
|
||||||
gridSchema.put("primaryField", gridTableUpper + "_ID");
|
gridSchema.put("primaryField", gridTableUpper + "_ID");
|
||||||
}
|
}
|
||||||
|
// 查询条件:gridtemplate 的 <search> → 右表 filter(此前 treegrid 右表无查询区,老系统有)。
|
||||||
|
// 过滤字段值由 amis crud 作 query 透传给 /api/template/treegrid,端点再转发给合成搜索流(IDENT 白名单)。
|
||||||
|
Element gridSearch = gridRoot.element("search");
|
||||||
|
if (gridSearch != null) {
|
||||||
|
Map<String, Object> filter = buildSearchFilter(gridSearch, result, false, gridEntityId);
|
||||||
|
if (filter != null) {
|
||||||
|
gridSchema.put("filter", filter);
|
||||||
|
result.note("tree+grid: gridtemplate <search> → 右表查询过滤表单");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gridSchema.put("columns", gridCols);
|
gridSchema.put("columns", gridCols);
|
||||||
@@ -1854,6 +2070,14 @@ public class TemplateToAmisConverter {
|
|||||||
/** 老模板事件绑定属性:行选中(按钮联动) / 加载(字段只读·显隐联动)。 */
|
/** 老模板事件绑定属性:行选中(按钮联动) / 加载(字段只读·显隐联动)。 */
|
||||||
static final String ATTR_ON_SELECTED = "onselectedscript";
|
static final String ATTR_ON_SELECTED = "onselectedscript";
|
||||||
static final String ATTR_ON_LOAD = "onloadscript";
|
static final String ATTR_ON_LOAD = "onloadscript";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 弹窗 onloadscript marker 字段:{@link #buildFormDialog} 给 read/update 弹窗的 service body 打上
|
||||||
|
* 此标记记录按钮 onloadscript 的 scriptKey(转换器此时无 seq/rewriterDir 解析能力)。
|
||||||
|
* 后续 {@link #attachDialogOnloadScripts}(BatchConvertCli post-pass)据此把脚本链挂到 service 的
|
||||||
|
* inited 事件并删除本 marker;若 scriptKey 无对应落盘脚本则删除 marker 跳过(fail-closed)。
|
||||||
|
*/
|
||||||
|
static final String DIALOG_ONLOAD_SCRIPT_KEY = "x-onload-script-key";
|
||||||
private static final List<String> EVENT_ATTRS = List.of(ATTR_ON_SELECTED, ATTR_ON_LOAD);
|
private static final List<String> EVENT_ATTRS = List.of(ATTR_ON_SELECTED, ATTR_ON_LOAD);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2112,6 +2336,105 @@ public class TemplateToAmisConverter {
|
|||||||
return pageSchema;
|
return pageSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BatchConvertCli post-pass:把 read/update 弹窗按钮的 {@code onloadscript} 脚本挂到弹窗表单
|
||||||
|
* {@code service.onEvent.inited}(弹窗打开时完整执行脚本——setFieldValue/setFieldVisible/addButton
|
||||||
|
* 等联动;只读基线已由 {@code service.static} 覆盖,二者共存)。
|
||||||
|
*
|
||||||
|
* <p>{@link #buildFormDialog} 给弹窗 service 打了 {@link #DIALOG_ONLOAD_SCRIPT_KEY} marker(仅记 scriptKey,
|
||||||
|
* 转换器此时无 seq/rewriterDir)。本方法递归遍历整张 schema 找所有带该 marker 的 service 节点,对每个:
|
||||||
|
* <ol>
|
||||||
|
* <li>{@code seq = keyToSeq.get(key)};</li>
|
||||||
|
* <li>seq==null 或 {@code !seqExists.test(seq)} → 删 marker 跳过(fail-closed,与 attachScriptOnEvent
|
||||||
|
* C1-a 一致:盘上无 {@code rewritten/<id>/<seq>.*.groovy} 不挂,免运行时「ajax 动作执行失败」);</li>
|
||||||
|
* <li>否则用 {@link #scriptActionChain}(templateId, seq, "${&}") 建动作链,append 到该 service 的
|
||||||
|
* {@code onEvent.inited.actions}(已有 inited 则合并、不覆盖),最后删 marker。</li>
|
||||||
|
* </ol>
|
||||||
|
*
|
||||||
|
* @param pageSchema 已转换且已过 attachScriptOnEvent/demote 的页面 schema(递归遍历查 service marker)
|
||||||
|
* @param templateId 弹窗对应编辑表单模板 ID(即 service 的页面来源;脚本落盘目录名)
|
||||||
|
* @param keyToSeq scriptKey→1-based 文档序({@link #scriptKeyToSeq},由源模板 XML 解析)
|
||||||
|
* @param seqExists seq→是否存在对应落盘脚本文件的判定(BatchConvertCli 由 {@code rewriterDir} 注入)
|
||||||
|
* @return 同一 pageSchema 引用(已就地挂上弹窗 inited 脚本链 + 删除 marker)
|
||||||
|
*/
|
||||||
|
public Map<String, Object> attachDialogOnloadScripts(Map<String, Object> pageSchema, String templateId,
|
||||||
|
Map<String, Integer> keyToSeq,
|
||||||
|
Predicate<Integer> seqExists) {
|
||||||
|
if (pageSchema == null || templateId == null || templateId.isBlank()) {
|
||||||
|
return pageSchema;
|
||||||
|
}
|
||||||
|
Predicate<Integer> exists = (seqExists != null) ? seqExists : (seq -> true);
|
||||||
|
Map<String, Integer> keys = (keyToSeq != null) ? keyToSeq : Map.of();
|
||||||
|
attachDialogOnloadScriptsWalk(pageSchema, templateId, keys, exists);
|
||||||
|
return pageSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 递归遍历 schema 任意 Map/List 节点,对带 {@link #DIALOG_ONLOAD_SCRIPT_KEY} marker 的 service 挂 inited 脚本链。 */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private void attachDialogOnloadScriptsWalk(Object node, String templateId,
|
||||||
|
Map<String, Integer> keyToSeq, Predicate<Integer> exists) {
|
||||||
|
if (node instanceof Map) {
|
||||||
|
Map<String, Object> map = (Map<String, Object>) node;
|
||||||
|
Object marker = map.get(DIALOG_ONLOAD_SCRIPT_KEY);
|
||||||
|
if (marker instanceof String && !((String) marker).isBlank()) {
|
||||||
|
attachInitedScriptToService(map, ((String) marker).trim(), templateId, keyToSeq, exists);
|
||||||
|
}
|
||||||
|
// 继续下钻子节点(含 dialog/body/columns/tabs 等任意嵌套;service 本身亦可能再含子 service)
|
||||||
|
for (Object v : map.values()) {
|
||||||
|
attachDialogOnloadScriptsWalk(v, templateId, keyToSeq, exists);
|
||||||
|
}
|
||||||
|
} else if (node instanceof List) {
|
||||||
|
for (Object v : (List<Object>) node) {
|
||||||
|
attachDialogOnloadScriptsWalk(v, templateId, keyToSeq, exists);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对单个带 marker 的 service 节点解析 seq 并挂 inited 脚本链;无论成败一律删除 marker。
|
||||||
|
* fail-closed:seq==null(marker key 不在文档)或盘上无落盘脚本 → 不挂、只删 marker。
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private void attachInitedScriptToService(Map<String, Object> service, String scriptKey, String templateId,
|
||||||
|
Map<String, Integer> keyToSeq, Predicate<Integer> exists) {
|
||||||
|
// 一律删 marker(不残留到产物)——成功挂链/失败跳过都删
|
||||||
|
service.remove(DIALOG_ONLOAD_SCRIPT_KEY);
|
||||||
|
Integer seq = keyToSeq.get(scriptKey);
|
||||||
|
if (seq == null || !exists.test(seq)) {
|
||||||
|
return; // fail-closed:缺 seq / 盘上无 rewritten/<id>/<seq>.*.groovy → 不挂(免运行时「未找到」)
|
||||||
|
}
|
||||||
|
List<Object> chain = scriptActionChain(templateId, seq, "${&}");
|
||||||
|
|
||||||
|
Object onEventObj = service.get("onEvent");
|
||||||
|
Map<String, Object> onEvent;
|
||||||
|
if (onEventObj instanceof Map) {
|
||||||
|
onEvent = (Map<String, Object>) onEventObj;
|
||||||
|
} else {
|
||||||
|
onEvent = new LinkedHashMap<>();
|
||||||
|
service.put("onEvent", onEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object initedObj = onEvent.get(EVENT_INITED);
|
||||||
|
if (initedObj instanceof Map) {
|
||||||
|
// 已有 inited:把脚本链 append 进现有 actions(合并不覆盖)
|
||||||
|
Map<String, Object> inited = (Map<String, Object>) initedObj;
|
||||||
|
Object actionsObj = inited.get("actions");
|
||||||
|
List<Object> actions;
|
||||||
|
if (actionsObj instanceof List) {
|
||||||
|
actions = (List<Object>) actionsObj;
|
||||||
|
} else {
|
||||||
|
actions = new ArrayList<>();
|
||||||
|
inited.put("actions", actions);
|
||||||
|
}
|
||||||
|
actions.addAll(chain);
|
||||||
|
} else {
|
||||||
|
// 无 inited:新建(actions 用可变 List,便于后续合并)
|
||||||
|
Map<String, Object> inited = new LinkedHashMap<>();
|
||||||
|
inited.put("actions", new ArrayList<>(chain));
|
||||||
|
onEvent.put(EVENT_INITED, inited);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小修#1:对有 onselected 脚本的页,把<b>脚本 enableButton 目标集未引用</b>的 baseline 禁用业务按钮
|
* 小修#1:对有 onselected 脚本的页,把<b>脚本 enableButton 目标集未引用</b>的 baseline 禁用业务按钮
|
||||||
* 降级为 {@code disabledOn}(选中即可点)。在集合内的按钮(脚本据 STATUS 点亮)保持 {@code disabled:true}。
|
* 降级为 {@code disabledOn}(选中即可点)。在集合内的按钮(脚本据 STATUS 点亮)保持 {@code disabled:true}。
|
||||||
@@ -2206,13 +2529,19 @@ public class TemplateToAmisConverter {
|
|||||||
if (!(bodyObj instanceof Map)) {
|
if (!(bodyObj instanceof Map)) {
|
||||||
return pageSchema;
|
return pageSchema;
|
||||||
}
|
}
|
||||||
Map<String, Object> body = (Map<String, Object>) bodyObj;
|
// type=4 树+grid 页 body 是 grid,crud(连同 headerToolbar 业务按钮)嵌在某 column 的 body 里;
|
||||||
|
// 普通列表页 body 即 crud。两种结构都要找到那个 crud,否则收藏页等树+grid 的业务按钮(如「取消收藏」)
|
||||||
|
// 永远 no-op、永久置灰、点不动(dogfooding 实测新闻/通知收藏页根因)。
|
||||||
|
Map<String, Object> crud = findCrudWithToolbar((Map<String, Object>) bodyObj);
|
||||||
|
if (crud == null) {
|
||||||
|
return pageSchema;
|
||||||
|
}
|
||||||
// 有脚本控启停(selectedChange)→ no-op:业务按钮由脚本据 STATUS 点亮,保持 disabled:true。
|
// 有脚本控启停(selectedChange)→ no-op:业务按钮由脚本据 STATUS 点亮,保持 disabled:true。
|
||||||
Object onEvent = body.get("onEvent");
|
Object onEvent = crud.get("onEvent");
|
||||||
if (onEvent instanceof Map && ((Map<String, Object>) onEvent).containsKey(EVENT_SELECTED_CHANGE)) {
|
if (onEvent instanceof Map && ((Map<String, Object>) onEvent).containsKey(EVENT_SELECTED_CHANGE)) {
|
||||||
return pageSchema;
|
return pageSchema;
|
||||||
}
|
}
|
||||||
Object tbObj = body.get("headerToolbar");
|
Object tbObj = crud.get("headerToolbar");
|
||||||
if (!(tbObj instanceof List)) {
|
if (!(tbObj instanceof List)) {
|
||||||
return pageSchema;
|
return pageSchema;
|
||||||
}
|
}
|
||||||
@@ -2230,6 +2559,38 @@ public class TemplateToAmisConverter {
|
|||||||
return pageSchema;
|
return pageSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定位含 {@code headerToolbar} 的 crud 节点:
|
||||||
|
* <ul>
|
||||||
|
* <li>顶层 {@code body} 自身即 crud(普通列表页)→ 直接返回;</li>
|
||||||
|
* <li>type=4 树+grid 页 {@code body} 是 grid,crud 嵌在某 {@code columns[].body} 里
|
||||||
|
* → 遍历 columns 取首个含 {@code headerToolbar} 的 body。</li>
|
||||||
|
* </ul>
|
||||||
|
* 都找不到 → {@code null}(如纯表单页/纯树页,无工具栏可降级)。
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static Map<String, Object> findCrudWithToolbar(Map<String, Object> body) {
|
||||||
|
if (body == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (body.get("headerToolbar") instanceof List) {
|
||||||
|
return body; // 顶层即 crud
|
||||||
|
}
|
||||||
|
Object columns = body.get("columns");
|
||||||
|
if (columns instanceof List) {
|
||||||
|
for (Object col : (List<Object>) columns) {
|
||||||
|
if (col instanceof Map) {
|
||||||
|
Object colBody = ((Map<String, Object>) col).get("body");
|
||||||
|
if (colBody instanceof Map
|
||||||
|
&& ((Map<String, Object>) colBody).get("headerToolbar") instanceof List) {
|
||||||
|
return (Map<String, Object>) colBody;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/** disabledOn 表达式:无选中行则禁用(贴老 bulkActions 选中态语义)。 */
|
/** disabledOn 表达式:无选中行则禁用(贴老 bulkActions 选中态语义)。 */
|
||||||
static final String DISABLED_ON_NO_SELECTION = "${!selectedItems || selectedItems.length === 0}";
|
static final String DISABLED_ON_NO_SELECTION = "${!selectedItems || selectedItems.length === 0}";
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,12 @@ final class UiTypeMapper {
|
|||||||
// mdec 非数值 → 忽略精度,控件本身已成立
|
// mdec 非数值 → 忽略精度,控件本身已成立
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.note(origin + "@field " + name + " uitype=NumberField → input-number(precision=" + mdec + ")");
|
// D:数值范围校验 vmin/vmax → amis input-number 的 min/max(老引擎前端拦截越界,
|
||||||
|
// 如采购明细 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
|
||||||
|
+ ", min=" + f.attributeValue("vmin") + ", max=" + f.attributeValue("vmax") + ")");
|
||||||
}
|
}
|
||||||
case "CheckBox" -> {
|
case "CheckBox" -> {
|
||||||
item.put("type", "checkbox");
|
item.put("type", "checkbox");
|
||||||
@@ -110,30 +115,56 @@ final class UiTypeMapper {
|
|||||||
// 表单内嵌可编辑子表(主子表的子表侧)→ amis input-table;
|
// 表单内嵌可编辑子表(主子表的子表侧)→ amis input-table;
|
||||||
// 子列取自 <editgridtemplate> CDATA 内 <component><editgrid><field>。
|
// 子列取自 <editgridtemplate> CDATA 内 <component><editgrid><field>。
|
||||||
item.put("type", "input-table");
|
item.put("type", "input-table");
|
||||||
item.put("addable", !"false".equals(f.attributeValue("showaddbutton")));
|
item.put("id", editGridId(name)); // A1:供行内脚本 setValue 当前行经 componentId 定位
|
||||||
|
// A4:老模板 showaddbutton=false 常因「靠批量选择器(MultiSelectDialog)加行」(A3 本轮未接)。
|
||||||
|
// 为保证子表有加行入口,强制 addable=true(grid 顶部「+」),配合 A2 picker 列可点选引用对象。
|
||||||
|
item.put("addable", true);
|
||||||
item.put("removable", !"false".equals(f.attributeValue("showdeletebutton")));
|
item.put("removable", !"false".equals(f.attributeValue("showdeletebutton")));
|
||||||
item.put("columns", buildEditGridColumns(f, result, name));
|
item.put("columns", buildEditGridColumns(f, result, name));
|
||||||
|
item.put("needConfirm", false); // 单元格改即生效,免每行「确认」拦住 onEvent.change 联动
|
||||||
result.degrade(origin + "@field " + name + " uitype=" + uitype
|
result.degrade(origin + "@field " + name + " uitype=" + uitype
|
||||||
+ " → input-table 子表(主子表子表侧,列取自 editgridtemplate;保存联动 updateSubTable 待后端)");
|
+ " → input-table 子表(主子表子表侧,列取自 editgridtemplate;保存联动 updateSubTable 待后端)");
|
||||||
}
|
}
|
||||||
case "ComboBox" -> {
|
case "ComboBox" -> {
|
||||||
item.put("type", "select");
|
item.put("type", "select");
|
||||||
item.put("clearable", true);
|
item.put("clearable", true);
|
||||||
String dict = firstNonBlank(f.attributeValue("comboboxid"),
|
// 老引擎 ComboBox 选项有两个来源,语义不同,不可混为一谈:
|
||||||
f.attributeValue("comboboxitemservice"), "");
|
// ① comboboxid = 静态枚举类型(SYS_ENUMERATE)——由 /api/poc/dict 端点
|
||||||
// comboboxid 缺省但 itemisenumerate=true → 选项取该列的 enumeratetype 枚举字典
|
// (DataDicService.getEnumerateItems)解析;
|
||||||
// (与显式 comboboxid=枚举类型 的字段同口径,如 OVERTIMESTATE comboboxid=HR_HOLIDAYSTATUS)。
|
// ② comboboxitemservice = 「运行某服务取选项」(查表的列表服务,非枚举)——老引擎跑该服务返行集。
|
||||||
// enumeratetype 来自 SYS_ENTITYATTRIBUTE(colMeta[列名][1])。修复 51 模板「枚举下拉空数据」。
|
// 历史实现用 firstNonBlank(comboboxid, comboboxitemservice) 把二者都喂给 /api/poc/dict,
|
||||||
if (dict.isBlank() && "true".equals(f.attributeValue("itemisenumerate"))) {
|
// 致 ② 类(如收藏「移动分类」的 OA_NEWSCOLLECTIONTYPE_SEARCH)在枚举表查不到 → 选项恒空、选不了分类。
|
||||||
|
String comboboxId = f.attributeValue("comboboxid", "").trim();
|
||||||
|
String itemService = f.attributeValue("comboboxitemservice", "").trim();
|
||||||
|
// 枚举字典:显式 comboboxid,或 comboboxid 缺省但 itemisenumerate=true → 取该列 enumeratetype 枚举字典
|
||||||
|
// (colMeta[列名][1],来自 SYS_ENTITYATTRIBUTE,同口径如 OVERTIMESTATE comboboxid=HR_HOLIDAYSTATUS)。
|
||||||
|
// 修复 51 模板「枚举下拉空数据」。
|
||||||
|
String enumDict = comboboxId;
|
||||||
|
if (enumDict.isBlank() && "true".equals(f.attributeValue("itemisenumerate"))) {
|
||||||
String[] meta = colMeta.get(name.toUpperCase());
|
String[] meta = colMeta.get(name.toUpperCase());
|
||||||
if (meta != null && meta.length > 1 && meta[1] != null && !meta[1].isBlank()) {
|
if (meta != null && meta.length > 1 && meta[1] != null && !meta[1].isBlank()) {
|
||||||
dict = meta[1].trim();
|
enumDict = meta[1].trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!dict.isBlank()) {
|
if (!enumDict.isBlank()) {
|
||||||
item.put("source", "/api/poc/dict/" + dict);
|
// ① 静态枚举 → 字典端点(仅认 SYS_ENUMERATE)
|
||||||
result.note(origin + "@field " + name + " uitype=ComboBox(dict=" + dict
|
item.put("source", "/api/poc/dict/" + enumDict);
|
||||||
|
result.note(origin + "@field " + name + " uitype=ComboBox(枚举字典=" + enumDict
|
||||||
+ ") → select + source 字典接口 /api/poc/dict");
|
+ ") → select + source 字典接口 /api/poc/dict");
|
||||||
|
} else if (!itemService.isBlank()) {
|
||||||
|
// ② 列表服务 → 数据源实体的 picker 选项端点。合成搜索流命名约定 <TABLE>_SEARCH,剥后缀即实体表,
|
||||||
|
// PickerController 已返回 {data.options:[{label:显示列,value:主键}]},amis select 直接消费。
|
||||||
|
String table = serviceEntityTable(itemService);
|
||||||
|
if (table != null) {
|
||||||
|
item.put("source", "/api/picker/" + table + "/list?perPage=500");
|
||||||
|
result.note(origin + "@field " + name + " uitype=ComboBox(列表服务=" + itemService
|
||||||
|
+ ") → select + source /api/picker/" + table + "/list(查表选项,非枚举)");
|
||||||
|
} else {
|
||||||
|
// 非 <TABLE>_SEARCH 命名的列表服务:暂无从推数据源实体,保底仍指字典端点(注明降级,选项可能空)。
|
||||||
|
item.put("source", "/api/poc/dict/" + itemService);
|
||||||
|
result.degrade(origin + "@field " + name + " uitype=ComboBox(列表服务=" + itemService
|
||||||
|
+ " 非 _SEARCH 命名,无法推实体) → 保底 /api/poc/dict(选项可能为空,待补服务→实体映射)");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// 年/月查询下拉:老引擎对 YEAR/MONTH 整数列(itemisenumerate 但无枚举字典)按约定
|
// 年/月查询下拉:老引擎对 YEAR/MONTH 整数列(itemisenumerate 但无枚举字典)按约定
|
||||||
// 内建年/月选项。转换器据列名语义生成静态选项(月 1-12 永久稳定;年取覆盖系统生命期的范围)。
|
// 内建年/月选项。转换器据列名语义生成静态选项(月 1-12 永久稳定;年取覆盖系统生命期的范围)。
|
||||||
@@ -165,6 +196,16 @@ final class UiTypeMapper {
|
|||||||
+ (hasTime ? "input-datetime-range" : "input-date-range") + "(区间)");
|
+ (hasTime ? "input-datetime-range" : "input-date-range") + "(区间)");
|
||||||
}
|
}
|
||||||
case "SelectDialog" -> {
|
case "SelectDialog" -> {
|
||||||
|
if ("true".equals(f.attributeValue("readonly"))) {
|
||||||
|
// 只读引用字段:老系统显示的是引用对象的【名称】而非裸 id。新系统行/加载数据带
|
||||||
|
// {NAME}_DISPLAY__(REST 读层 UserColumnResolver 填充显示名),故渲染为 static 显示
|
||||||
|
// ${NAME_DISPLAY__}(无则回退裸值);原 id 仍在 form.data 里随 ${&} 提交(static 不改值)。
|
||||||
|
// 修「移动分类/收藏弹窗 主题显示 id」。
|
||||||
|
applyReadonlyReferenceDisplay(item, name);
|
||||||
|
result.note(origin + "@field " + name
|
||||||
|
+ " uitype=SelectDialog(readonly) → static 显示名(" + name + "_DISPLAY__,非裸 id)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
// 旧引擎弹窗选择器 → amis picker(弹窗多列表格 + 搜索 + 分页),恢复老系统「弹窗对照选择」语义。
|
// 旧引擎弹窗选择器 → amis picker(弹窗多列表格 + 搜索 + 分页),恢复老系统「弹窗对照选择」语义。
|
||||||
// 历史降级注释「6.13 schema 未纳入 picker」已核实失实:amis-schema-6.13.0.json 的 SchemaObject
|
// 历史降级注释「6.13 schema 未纳入 picker」已核实失实:amis-schema-6.13.0.json 的 SchemaObject
|
||||||
// allOf 含 {if type==picker then PickerControlSchema},picker 表单项过得了闸一(见
|
// allOf 含 {if type==picker then PickerControlSchema},picker 表单项过得了闸一(见
|
||||||
@@ -182,6 +223,12 @@ final class UiTypeMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "MultiSelectDialog" -> {
|
case "MultiSelectDialog" -> {
|
||||||
|
if ("true".equals(f.attributeValue("readonly"))) {
|
||||||
|
applyReadonlyReferenceDisplay(item, name);
|
||||||
|
result.note(origin + "@field " + name
|
||||||
|
+ " uitype=MultiSelectDialog(readonly) → static 显示名(" + name + "_DISPLAY__,非裸 id)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
String dialogId = f.attributeValue("dialogid", "");
|
String dialogId = f.attributeValue("dialogid", "");
|
||||||
if (dialogId.isBlank()) {
|
if (dialogId.isBlank()) {
|
||||||
applySelectDialogFallback(item, "", true);
|
applySelectDialogFallback(item, "", true);
|
||||||
@@ -247,6 +294,8 @@ final class UiTypeMapper {
|
|||||||
String token = v.substring(1, v.length() - 1).trim().toUpperCase();
|
String token = v.substring(1, v.length() - 1).trim().toUpperCase();
|
||||||
String expr = switch (token) {
|
String expr = switch (token) {
|
||||||
case "CURRENTUSER" -> "${currentUser}";
|
case "CURRENTUSER" -> "${currentUser}";
|
||||||
|
case "CURRENTDEPART" -> "${currentDepart}"; // B1:原漏映射;权威值由「添加」dialog 的
|
||||||
|
// /api/form/{table}/defaults 服务端解析,此表达式作回退
|
||||||
case "CURRENTORG" -> "${orgId}"; // 复用 AmisRenderer 已注入的 orgId
|
case "CURRENTORG" -> "${orgId}"; // 复用 AmisRenderer 已注入的 orgId
|
||||||
case "CURRENTTIME" -> "${now}";
|
case "CURRENTTIME" -> "${now}";
|
||||||
case "CURRENTPROJECT" -> "${currentProject}";
|
case "CURRENTPROJECT" -> "${currentProject}";
|
||||||
@@ -356,6 +405,78 @@ final class UiTypeMapper {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A1:editgrid 行内脚本 onEvent 里 templateId 的占位符;由 {@code convertViewPage} 后置注入真实 view_page_id。 */
|
||||||
|
public static final String EDITGRID_TPL_PLACEHOLDER = "__EDITGRID_TPL__";
|
||||||
|
|
||||||
|
/** A1:编辑表单 amis 组件 id——editgrid 行内脚本把主表字段(如 applyTotalMoney)setValue 经 componentId 定位它。 */
|
||||||
|
public static final String EDIT_FORM_ID = "eip4-edit-form";
|
||||||
|
|
||||||
|
/** A1:editgrid input-table 的 amis 组件 id(行内脚本 setValue 当前行经此 componentId + index 定位)。 */
|
||||||
|
static String editGridId(String editgridField) {
|
||||||
|
return "eg-" + editgridField;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A1:构造 editgrid 子列 {@code quickEdit.onEvent.change} 动作链——
|
||||||
|
* ① ajax 调 {@code /api/script/execute-editgrid-row}(传 templateId/editgridField/scriptKey/
|
||||||
|
* changedField + 当前行 ${&} + 父域里的子表数组),outputVar=egRow;
|
||||||
|
* ② setValue 把 {@code rowSetValues} 合并回当前行(如金额);
|
||||||
|
* ③ 自定义动作 {@code applyEditGridParent} 把 {@code parentSetValues} 写主表(如申请总金额)。
|
||||||
|
* templateId 此处填占位符,convertViewPage 后置注入。
|
||||||
|
*/
|
||||||
|
private static Map<String, Object> editGridChangeOnEvent(String editgridField, String scriptKey, String changedField) {
|
||||||
|
Map<String, Object> data = new LinkedHashMap<>();
|
||||||
|
data.put("templateId", EDITGRID_TPL_PLACEHOLDER);
|
||||||
|
data.put("editgridField", editgridField);
|
||||||
|
data.put("scriptKey", scriptKey);
|
||||||
|
data.put("changedField", changedField);
|
||||||
|
// 当前行全量数据:表单项 change 事件里整行数据在 ${__rendererData}(renderer.props.data),
|
||||||
|
// ${&} 只含「变更字段+value」会丢其它列(致脚本 getFieldValue 取不到 → 计算错)。
|
||||||
|
data.put("row", "${__rendererData}");
|
||||||
|
// 父域只需子表数组(聚合脚本读 group.parent.getField(editgridField).getValue() 求和)。
|
||||||
|
Map<String, Object> parent = new LinkedHashMap<>();
|
||||||
|
parent.put(editgridField, "${__rendererData." + editgridField + " || " + editgridField + "}");
|
||||||
|
data.put("parent", parent);
|
||||||
|
|
||||||
|
Map<String, Object> api = new LinkedHashMap<>();
|
||||||
|
api.put("method", "post");
|
||||||
|
api.put("url", "/api/script/execute-editgrid-row");
|
||||||
|
api.put("data", data);
|
||||||
|
|
||||||
|
// outputVar 是 amis 动作的顶层字段(非 args 内);放 args 里不会被识别 → egRow 取不到响应。
|
||||||
|
Map<String, Object> ajax = new LinkedHashMap<>();
|
||||||
|
ajax.put("actionType", "ajax");
|
||||||
|
ajax.put("outputVar", "egRow");
|
||||||
|
ajax.put("args", new LinkedHashMap<>(Map.of("api", api)));
|
||||||
|
|
||||||
|
// 行内字段(如 MONEY):setValue 经 input-table 组件 id + 当前行 index 合并回该行。
|
||||||
|
// amis AjaxAction 把响应 data 直接展开进 outputVar(egRow={rowSetValues,parentSetValues,...}),
|
||||||
|
// 故取 ${egRow.rowSetValues}(非 .data.rowSetValues)。
|
||||||
|
Map<String, Object> setRow = new LinkedHashMap<>();
|
||||||
|
setRow.put("actionType", "setValue");
|
||||||
|
setRow.put("componentId", editGridId(editgridField));
|
||||||
|
Map<String, Object> setRowArgs = new LinkedHashMap<>();
|
||||||
|
setRowArgs.put("index", "${index}");
|
||||||
|
setRowArgs.put("value", "${egRow.rowSetValues}");
|
||||||
|
setRow.put("args", setRowArgs);
|
||||||
|
|
||||||
|
// 主表字段(如 applyTotalMoney):标准 setValue 经 componentId 定位根表单写入(纯 amis 原生,免自定义动作)。
|
||||||
|
Map<String, Object> setParent = new LinkedHashMap<>();
|
||||||
|
setParent.put("actionType", "setValue");
|
||||||
|
setParent.put("componentId", EDIT_FORM_ID);
|
||||||
|
setParent.put("args", new LinkedHashMap<>(Map.of("value", "${egRow.parentSetValues}")));
|
||||||
|
|
||||||
|
List<Object> actions = new ArrayList<>();
|
||||||
|
actions.add(ajax);
|
||||||
|
actions.add(setRow);
|
||||||
|
actions.add(setParent);
|
||||||
|
Map<String, Object> change = new LinkedHashMap<>();
|
||||||
|
change.put("actions", actions);
|
||||||
|
Map<String, Object> onEvent = new LinkedHashMap<>();
|
||||||
|
onEvent.put("change", change);
|
||||||
|
return onEvent;
|
||||||
|
}
|
||||||
|
|
||||||
/** 解析 EditGrid 的 {@code <editgridtemplate>} CDATA,把内嵌 editgrid 字段转成 input-table 列。 */
|
/** 解析 EditGrid 的 {@code <editgridtemplate>} CDATA,把内嵌 editgrid 字段转成 input-table 列。 */
|
||||||
private static List<Map<String, Object>> buildEditGridColumns(Element f, ConversionResult result, String name) {
|
private static List<Map<String, Object>> buildEditGridColumns(Element f, ConversionResult result, String name) {
|
||||||
List<Map<String, Object>> columns = new ArrayList<>();
|
List<Map<String, Object>> columns = new ArrayList<>();
|
||||||
@@ -381,10 +502,34 @@ final class UiTypeMapper {
|
|||||||
// 显式 comboboxid/dialogid 的控件正常,依赖列枚举元数据的无源 ComboBox 仍走原降级(与列表页同口径)。
|
// 显式 comboboxid/dialogid 的控件正常,依赖列枚举元数据的无源 ComboBox 仍走原降级(与列表页同口径)。
|
||||||
Map<String, Object> control = mapField(sub, result, "editgrid:" + name, java.util.Map.of());
|
Map<String, Object> control = mapField(sub, result, "editgrid:" + name, java.util.Map.of());
|
||||||
Map<String, Object> col = new LinkedHashMap<>();
|
Map<String, Object> col = new LinkedHashMap<>();
|
||||||
|
String subName = String.valueOf(control.get("name"));
|
||||||
col.put("name", control.get("name"));
|
col.put("name", control.get("name"));
|
||||||
col.put("label", control.get("label"));
|
col.put("label", control.get("label"));
|
||||||
Map<String, Object> quickEdit = new LinkedHashMap<>(control);
|
Map<String, Object> quickEdit = new LinkedHashMap<>(control);
|
||||||
quickEdit.remove("label"); // label 归列头,避免编辑器内重复显示
|
quickEdit.remove("label"); // label 归列头,避免编辑器内重复显示
|
||||||
|
|
||||||
|
// A2:子表内只读 SelectDialog/MultiSelectDialog(带 dialogid)不该降成 static——子表是录入态,
|
||||||
|
// 新行需点选引用对象(如选用品 GOODS_ID)。把 static 升回 picker(可弹窗选择)。
|
||||||
|
String subUitype = sub.attributeValue("uitype", "");
|
||||||
|
String dialogId = sub.attributeValue("dialogid", "");
|
||||||
|
if (("SelectDialog".equals(subUitype) || "MultiSelectDialog".equals(subUitype))
|
||||||
|
&& !dialogId.isBlank() && "static".equals(quickEdit.get("type"))) {
|
||||||
|
quickEdit.keySet().removeIf(k -> !"name".equals(k)); // 清掉 static 残留(tpl/value)
|
||||||
|
applyPicker(quickEdit, dialogId, "MultiSelectDialog".equals(subUitype));
|
||||||
|
result.note("editgrid " + name + " 子列 " + subName
|
||||||
|
+ " 只读 SelectDialog → picker(子表录入可点选,dialogid=" + dialogId + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
// A1:子字段 script(单元格 onchange 行内联动,如数量×单价→金额、金额→汇总主表)→
|
||||||
|
// quickEdit.onEvent.change 调 /api/script/execute-editgrid-row(运行时 faithful 跑原 Groovy)。
|
||||||
|
// templateId 由 convertViewPage 后置注入(此处静态期不知 templateId)。
|
||||||
|
String subScript = sub.attributeValue("script", "");
|
||||||
|
if (!subScript.isBlank()) {
|
||||||
|
quickEdit.put("onEvent", editGridChangeOnEvent(name, subScript.trim(), subName));
|
||||||
|
result.note("editgrid " + name + " 子列 " + subName
|
||||||
|
+ " script=" + subScript.trim() + " → onEvent.change 行内联动端点");
|
||||||
|
}
|
||||||
|
|
||||||
col.put("quickEdit", quickEdit);
|
col.put("quickEdit", quickEdit);
|
||||||
columns.add(col);
|
columns.add(col);
|
||||||
}
|
}
|
||||||
@@ -415,6 +560,26 @@ final class UiTypeMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* D:把老 NumberField 的 {@code vmin/vmax} 写成 amis input-number 的 {@code min/max}。
|
||||||
|
* 整数无小数 → Long(避免 1 显示成 1.0),否则 Double;非数值/空 → 跳过(控件本身已成立)。
|
||||||
|
*/
|
||||||
|
private static void applyNumberBound(Map<String, Object> item, String key, String raw) {
|
||||||
|
if (raw == null || raw.isBlank()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
String t = raw.trim();
|
||||||
|
if (t.indexOf('.') < 0) {
|
||||||
|
item.put(key, Long.parseLong(t));
|
||||||
|
} else {
|
||||||
|
item.put(key, Double.parseDouble(t));
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException ignore) {
|
||||||
|
// vmin/vmax 非数值 → 忽略范围约束,控件本身已成立
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static String firstNonBlank(String... candidates) {
|
static String firstNonBlank(String... candidates) {
|
||||||
for (String c : candidates) {
|
for (String c : candidates) {
|
||||||
if (c != null && !c.isBlank()) {
|
if (c != null && !c.isBlank()) {
|
||||||
@@ -423,4 +588,37 @@ final class UiTypeMapper {
|
|||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ComboBox 列表服务名 → 数据源实体表名(大写)。合成搜索流命名约定 {@code <TABLE>_SEARCH}
|
||||||
|
* (与运行时 FlowNameResolver / PickerController 同口径),剥 {@code _SEARCH} 后缀即实体表,
|
||||||
|
* 用于把 {@code comboboxitemservice} 指向 {@code /api/picker/{TABLE}/list} 取真实选项。
|
||||||
|
* 非该命名(如自定义命名服务流)→ {@code null},调用方走字典端点保底。
|
||||||
|
*/
|
||||||
|
static String serviceEntityTable(String service) {
|
||||||
|
if (service == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String up = service.trim().toUpperCase();
|
||||||
|
if (up.endsWith("_SEARCH") && up.length() > "_SEARCH".length()) {
|
||||||
|
return up.substring(0, up.length() - "_SEARCH".length());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 只读引用字段(readonly SelectDialog/MultiSelectDialog)→ 只读「显示名」展示:
|
||||||
|
* {@code type=static} + tpl {@code ${NAME_DISPLAY__ ? NAME_DISPLAY__ : NAME}}。行/加载数据带
|
||||||
|
* {@code {NAME}_DISPLAY__}(REST 读层填充显示名)时显名,否则回退裸值(不比现状更差)。原 id 仍留
|
||||||
|
* {@code form.data},随 {@code ${&}} 整体提交(static 纯展示、不改值),故无需额外隐藏域。
|
||||||
|
* 去掉输入态属性(disabled/clearable/required 校验)——对纯展示无意义且避免 static 被必填校验。
|
||||||
|
*/
|
||||||
|
static void applyReadonlyReferenceDisplay(Map<String, Object> item, String name) {
|
||||||
|
item.remove("disabled");
|
||||||
|
item.remove("clearable");
|
||||||
|
item.remove("required");
|
||||||
|
item.remove("validationErrors");
|
||||||
|
item.put("type", "static");
|
||||||
|
item.put("tpl", "${" + name + "_DISPLAY__ ? " + name + "_DISPLAY__ : " + name + "}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ class TemplateToAmisConverterTest {
|
|||||||
+ "<field name='B' label='字典' uitype='ComboBox' comboboxid='WFSTATUS'/>"
|
+ "<field name='B' label='字典' uitype='ComboBox' comboboxid='WFSTATUS'/>"
|
||||||
+ "<field name='C' label='日期' uitype='PopupDateField' format='yyyy-MM-dd'/>"
|
+ "<field name='C' label='日期' uitype='PopupDateField' format='yyyy-MM-dd'/>"
|
||||||
+ "<field name='D' label='区间' uitype='DoublePopupDateField' format='yyyy-MM-dd HH:mm'/>"
|
+ "<field name='D' label='区间' uitype='DoublePopupDateField' format='yyyy-MM-dd HH:mm'/>"
|
||||||
+ "<field name='E' label='数值' uitype='NumberField' mdec='2'/>"
|
+ "<field name='E' label='数值' uitype='NumberField' mdec='2' vmin='1' vmax='9999999.99'/>"
|
||||||
+ "</search></crud>";
|
+ "</search></crud>";
|
||||||
ConversionResult r = converter.convertGraded(xml, new ArrayList<>(), noPage);
|
ConversionResult r = converter.convertGraded(xml, new ArrayList<>(), noPage);
|
||||||
Map<String, Object> crud = body(r.getSchema());
|
Map<String, Object> crud = body(r.getSchema());
|
||||||
@@ -106,6 +106,110 @@ class TemplateToAmisConverterTest {
|
|||||||
assertEquals("input-datetime-range", items.get(3).get("type")); // 含时分 → datetime-range
|
assertEquals("input-datetime-range", items.get(3).get("type")); // 含时分 → datetime-range
|
||||||
assertEquals("input-number", items.get(4).get("type"));
|
assertEquals("input-number", items.get(4).get("type"));
|
||||||
assertEquals(2, items.get(4).get("precision"));
|
assertEquals(2, items.get(4).get("precision"));
|
||||||
|
// D:vmin 整数 → Long min;vmax 含小数 → Double max
|
||||||
|
assertEquals(1L, items.get(4).get("min"));
|
||||||
|
assertEquals(9999999.99, items.get(4).get("max"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修复(dogfooding):ComboBox 的 comboboxitemservice(查表的列表服务,非静态枚举)应指向
|
||||||
|
* picker 选项端点而非 /api/poc/dict(后者仅认 SYS_ENUMERATE → 选项恒空)。合成搜索流 <TABLE>_SEARCH
|
||||||
|
* 剥后缀得实体表 → /api/picker/{TABLE}/list(PickerController 返 {data.options:[{label,value}]})。
|
||||||
|
* 收藏「移动分类」分类下拉空、选不了分类的根因。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void crud_ComboBox列表服务SEARCH指向picker而非空字典() {
|
||||||
|
String xml = "<crud entityid='e1'><display/>"
|
||||||
|
+ "<search>"
|
||||||
|
+ "<field name='COLLECTTYPE_ID' label='收藏类别' uitype='ComboBox'"
|
||||||
|
+ " comboboxid='' comboboxitemservice='OA_NEWSCOLLECTIONTYPE_SEARCH' itemisenumerate='false'/>"
|
||||||
|
+ "<field name='STATE' label='枚举' uitype='ComboBox' comboboxid='WFSTATUS'/>"
|
||||||
|
+ "</search></crud>";
|
||||||
|
ConversionResult r = converter.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");
|
||||||
|
// 列表服务 → picker 选项端点(剥 _SEARCH 得实体表 OA_NEWSCOLLECTIONTYPE)
|
||||||
|
assertEquals("select", items.get(0).get("type"));
|
||||||
|
assertEquals("/api/picker/OA_NEWSCOLLECTIONTYPE/list?perPage=500", items.get(0).get("source"));
|
||||||
|
// 静态枚举 comboboxid 仍走字典端点(不回归)
|
||||||
|
assertEquals("/api/poc/dict/WFSTATUS", items.get(1).get("source"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修复(dogfooding):只读引用字段(readonly SelectDialog)应显示引用对象的【名称】而非裸 id。
|
||||||
|
* 渲染为 static + tpl ${NAME_DISPLAY__ ? NAME_DISPLAY__ : NAME},原 id 仍留 form.data 随 ${&} 提交。
|
||||||
|
* 收藏/移动分类弹窗「主题」显示 id 的根因。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void mapField_只读SelectDialog渲染为显示名而非id() {
|
||||||
|
String xml = "<crud entityid='e1'><display/>"
|
||||||
|
+ "<search>"
|
||||||
|
+ "<field name='NEWS_ID' label='主题' uitype='SelectDialog' readonly='true' dialogid='d1'/>"
|
||||||
|
+ "<field name='OTHER_ID' label='可编辑引用' uitype='SelectDialog' readonly='false' dialogid='d2'/>"
|
||||||
|
+ "</search></crud>";
|
||||||
|
ConversionResult r = converter.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");
|
||||||
|
// 只读引用 → static 显示名(非裸 id),去 disabled
|
||||||
|
Map<String, Object> ro = items.get(0);
|
||||||
|
assertEquals("static", ro.get("type"));
|
||||||
|
assertEquals("${NEWS_ID_DISPLAY__ ? NEWS_ID_DISPLAY__ : NEWS_ID}", ro.get("tpl"));
|
||||||
|
assertNull(ro.get("disabled"));
|
||||||
|
// 可编辑引用仍是 picker(不回归)
|
||||||
|
assertEquals("picker", items.get(1).get("type"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修复:ComboBox 非 _SEARCH 命名的列表服务(推不出实体表)→ 经 sys_serviceflow.entityid 解析数据源实体
|
||||||
|
* → /api/picker/{实体}/list(而非保底空字典)。mock jdbc 返 PM_DEMO 作实体表。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void crud_ComboBox非SEARCH列表服务_经元数据解析实体指picker() {
|
||||||
|
String xml = "<crud entityid='e1'><display/>"
|
||||||
|
+ "<search>"
|
||||||
|
+ "<field name='X' label='自定义服务下拉' uitype='ComboBox'"
|
||||||
|
+ " comboboxid='' comboboxitemservice='HR_FOO_SEARCHBYUSER' itemisenumerate='false'/>"
|
||||||
|
+ "</search></crud>";
|
||||||
|
ConversionResult r = converter.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");
|
||||||
|
// 非 _SEARCH → UiTypeMapper 保底 dict → enrichFieldRefs 经 sys_serviceflow(mock 返 PM_DEMO) 改指 picker
|
||||||
|
assertEquals("/api/picker/PM_DEMO/list?perPage=500", items.get(0).get("source"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修复(dogfooding):查看(read)按钮的 <load> 服务 → dialog service.api(POST 跑读流按主键加载本体)。
|
||||||
|
* 跨实体查看(查看通知/各收藏页:列表行是收件/收藏记录,不含本体 主题/内容)显空的根因。
|
||||||
|
* result 拍平到顶层供表单字段绑定;接 api 后去 static。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void read按钮接load服务_dialog用api加载本体数据() {
|
||||||
|
String xml = "<crud entityid='e1'><display><field name='A' text='A'/></display>"
|
||||||
|
+ "<button type='read' name='查看' isshow='true' pageid='p1'>"
|
||||||
|
+ "<load><method servicename='OA_X_SHOW'/></load>"
|
||||||
|
+ "</button></crud>";
|
||||||
|
Map<String, Object> schema = converter.convertGraded(xml, new ArrayList<>(), noPage).getSchema();
|
||||||
|
List<Object> tb = (List<Object>) body(schema).get("headerToolbar");
|
||||||
|
Map<String, Object> viewBtn = (Map<String, Object>) tb.stream()
|
||||||
|
.filter(x -> x instanceof Map && "查看".equals(((Map<String, Object>) x).get("label")))
|
||||||
|
.findFirst().orElseThrow();
|
||||||
|
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("post", api.get("method"));
|
||||||
|
assertEquals(Boolean.TRUE, service.get("static"), "查看(read)保留 static → 只读显示(与 api 并存,浏览器实证)");
|
||||||
|
// 主键 = 实体表(mock=PM_DEMO)_ID,data 传 ${主键},result 拍平
|
||||||
|
Map<String, Object> data = (Map<String, Object>) api.get("data");
|
||||||
|
assertEquals("${PM_DEMO_ID}", data.get("PM_DEMO_ID"));
|
||||||
|
assertEquals("${result}", ((Map<String, Object>) api.get("responseData")).get("&"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1336,6 +1440,137 @@ class TemplateToAmisConverterTest {
|
|||||||
assertFalse(onEvent.containsKey("selectedChange"));
|
assertFalse(onEvent.containsKey("selectedChange"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── 弹窗 onloadscript 挂回 service.inited(read/update 弹窗打开时完整执行脚本)──────────
|
||||||
|
|
||||||
|
/** 构造一个含 read 弹窗的 pageSchema:headerToolbar 里的 read 按钮 dialog.body.service 带 onloadscript marker。 */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static Map<String, Object> readDialogSchema(String scriptKey, boolean readOnly) {
|
||||||
|
Map<String, Object> service = new java.util.LinkedHashMap<>();
|
||||||
|
service.put("type", "service");
|
||||||
|
service.put("schemaApi", "get:/api/page/schema/EDITFORM1?format=amis");
|
||||||
|
if (readOnly) {
|
||||||
|
service.put("static", true); // Part A 只读基线,须与脚本共存
|
||||||
|
}
|
||||||
|
service.put(TemplateToAmisConverter.DIALOG_ONLOAD_SCRIPT_KEY, scriptKey);
|
||||||
|
Map<String, Object> dialog = new java.util.LinkedHashMap<>();
|
||||||
|
dialog.put("type", "dialog");
|
||||||
|
dialog.put("title", "查看");
|
||||||
|
dialog.put("body", service);
|
||||||
|
Map<String, Object> readBtn = new java.util.LinkedHashMap<>();
|
||||||
|
readBtn.put("type", "button");
|
||||||
|
readBtn.put("label", "查看");
|
||||||
|
readBtn.put("actionType", "dialog");
|
||||||
|
readBtn.put("dialog", dialog);
|
||||||
|
Map<String, Object> crud = new java.util.LinkedHashMap<>();
|
||||||
|
crud.put("type", "crud");
|
||||||
|
crud.put("headerToolbar", new ArrayList<>(List.of(readBtn)));
|
||||||
|
Map<String, Object> page = new java.util.LinkedHashMap<>();
|
||||||
|
page.put("type", "page");
|
||||||
|
page.put("body", crud);
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 取 read 弹窗的 dialog.body.service(沿 page.body.headerToolbar[0].dialog.body 下钻)。 */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static Map<String, Object> dialogService(Map<String, Object> page) {
|
||||||
|
Map<String, Object> crud = body(page);
|
||||||
|
Map<String, Object> readBtn = (Map<String, Object>) ((List<Object>) crud.get("headerToolbar")).get(0);
|
||||||
|
Map<String, Object> dialog = (Map<String, Object>) readBtn.get("dialog");
|
||||||
|
return (Map<String, Object>) dialog.get("body");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 弹窗 onloadscript:service 带 x-onload-script-key marker → attachDialogOnloadScripts 把 scriptActionChain
|
||||||
|
* 挂到该 service 的 onEvent.inited(ajax 指向 /api/script/execute-template + replayScriptCommands),
|
||||||
|
* 且删除 marker;service.static 只读基线保留(共存)。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void attachDialogOnloadScripts_挂inited脚本链并删marker() {
|
||||||
|
Map<String, Object> schema = readDialogSchema("K1", true);
|
||||||
|
converter.attachDialogOnloadScripts(schema, "tid", Map.of("K1", 5), seq -> true);
|
||||||
|
|
||||||
|
Map<String, Object> service = dialogService(schema);
|
||||||
|
// marker 已删除
|
||||||
|
assertNull(service.get(TemplateToAmisConverter.DIALOG_ONLOAD_SCRIPT_KEY), "x-onload-script-key marker 应被删除");
|
||||||
|
// Part A 只读基线保留
|
||||||
|
assertEquals(Boolean.TRUE, service.get("static"), "static 只读基线须与脚本共存(不被动)");
|
||||||
|
// onEvent.inited 出现脚本链
|
||||||
|
Map<String, Object> onEvent = (Map<String, Object>) service.get("onEvent");
|
||||||
|
assertNotNull(onEvent, "service 应挂上 onEvent");
|
||||||
|
Map<String, Object> inited = (Map<String, Object>) onEvent.get("inited");
|
||||||
|
assertNotNull(inited, "应挂到 inited 事件");
|
||||||
|
List<Object> actions = (List<Object>) inited.get("actions");
|
||||||
|
assertEquals(2, actions.size(), "scriptActionChain = ajax + replayScriptCommands");
|
||||||
|
// 动作 0:ajax → /api/script/execute-template,data 含 templateId/seq/item=${&}
|
||||||
|
Map<String, Object> ajax = (Map<String, Object>) actions.get(0);
|
||||||
|
assertEquals("ajax", ajax.get("actionType"));
|
||||||
|
Map<String, Object> api = (Map<String, Object>) ajax.get("api");
|
||||||
|
assertEquals("/api/script/execute-template", api.get("url"));
|
||||||
|
Map<String, Object> data = (Map<String, Object>) api.get("data");
|
||||||
|
assertEquals("tid", data.get("templateId"));
|
||||||
|
assertEquals(5, data.get("seq"));
|
||||||
|
assertEquals("${&}", data.get("item"), "弹窗 inited item 取全量数据域 ${&}");
|
||||||
|
// 动作 1:replayScriptCommands
|
||||||
|
Map<String, Object> replay = (Map<String, Object>) actions.get(1);
|
||||||
|
assertEquals("replayScriptCommands", replay.get("actionType"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 弹窗 onloadscript fail-closed:seqExists 返 false(盘上无 rewritten/<id>/<seq>.*.groovy)→
|
||||||
|
* 不挂脚本链(无 onEvent),但 marker 仍被删除(不残留到产物)。与 attachScriptOnEvent C1-a 一致。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void attachDialogOnloadScripts_failClosed_盘上无脚本不挂但删marker() {
|
||||||
|
Map<String, Object> schema = readDialogSchema("K1", true);
|
||||||
|
converter.attachDialogOnloadScripts(schema, "tid", Map.of("K1", 5), seq -> false);
|
||||||
|
|
||||||
|
Map<String, Object> service = dialogService(schema);
|
||||||
|
assertNull(service.get(TemplateToAmisConverter.DIALOG_ONLOAD_SCRIPT_KEY), "marker 一律删除(fail-closed 也删)");
|
||||||
|
assertNull(service.get("onEvent"), "盘上无脚本 → 不挂 onEvent(fail-closed)");
|
||||||
|
assertEquals(Boolean.TRUE, service.get("static"), "static 不受影响");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 弹窗 onloadscript fail-closed:scriptKey 不在 keyToSeq(seq==null)→ 同样不挂、删 marker。 */
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void attachDialogOnloadScripts_failClosed_缺seq不挂但删marker() {
|
||||||
|
Map<String, Object> schema = readDialogSchema("K_MISSING", true);
|
||||||
|
converter.attachDialogOnloadScripts(schema, "tid", Map.of("K1", 5), seq -> true);
|
||||||
|
|
||||||
|
Map<String, Object> service = dialogService(schema);
|
||||||
|
assertNull(service.get(TemplateToAmisConverter.DIALOG_ONLOAD_SCRIPT_KEY));
|
||||||
|
assertNull(service.get("onEvent"), "scriptKey 无对应 seq → 不挂");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 弹窗 service 已有 onEvent.inited 动作时,脚本链 append 进现有 actions(合并不覆盖)。 */
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void attachDialogOnloadScripts_已有inited则append合并() {
|
||||||
|
Map<String, Object> schema = readDialogSchema("K1", false);
|
||||||
|
// 预置一个 inited 动作(模拟已有联动)
|
||||||
|
Map<String, Object> service = dialogService(schema);
|
||||||
|
Map<String, Object> existing = new java.util.LinkedHashMap<>();
|
||||||
|
existing.put("actionType", "custom");
|
||||||
|
Map<String, Object> existingInited = new java.util.LinkedHashMap<>();
|
||||||
|
existingInited.put("actions", new ArrayList<>(List.of(existing)));
|
||||||
|
Map<String, Object> onEvent = new java.util.LinkedHashMap<>();
|
||||||
|
onEvent.put("inited", existingInited);
|
||||||
|
service.put("onEvent", onEvent);
|
||||||
|
|
||||||
|
converter.attachDialogOnloadScripts(schema, "tid", Map.of("K1", 3), seq -> true);
|
||||||
|
|
||||||
|
Map<String, Object> svc = dialogService(schema);
|
||||||
|
List<Object> actions = (List<Object>) ((Map<String, Object>)
|
||||||
|
((Map<String, Object>) svc.get("onEvent")).get("inited")).get("actions");
|
||||||
|
assertEquals(3, actions.size(), "已有 1 个 + 脚本链 2 个 = 3(append 合并,不覆盖)");
|
||||||
|
assertEquals("custom", ((Map<String, Object>) actions.get(0)).get("actionType"), "原有动作保留在前");
|
||||||
|
assertEquals("ajax", ((Map<String, Object>) actions.get(1)).get("actionType"));
|
||||||
|
assertEquals("replayScriptCommands", ((Map<String, Object>) actions.get(2)).get("actionType"));
|
||||||
|
assertNull(svc.get(TemplateToAmisConverter.DIALOG_ONLOAD_SCRIPT_KEY));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* C2:页面无任何脚本绑定(55 模板的典型)→ demoteUnscriptedBusinessButtons 把永久灰的业务按钮
|
* C2:页面无任何脚本绑定(55 模板的典型)→ demoteUnscriptedBusinessButtons 把永久灰的业务按钮
|
||||||
* 降级为 disabledOn(选中即可用)。这是 BatchConvertCli 对 bindings.isEmpty() 页的兜底。
|
* 降级为 disabledOn(选中即可用)。这是 BatchConvertCli 对 bindings.isEmpty() 页的兜底。
|
||||||
@@ -1382,6 +1617,43 @@ class TemplateToAmisConverterTest {
|
|||||||
assertNull(btn.get("disabledOn"));
|
assertNull(btn.get("disabledOn"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修复(dogfooding):type=4 树+grid 页(body=grid,crud 嵌在 columns[].body)的业务按钮也要降级。
|
||||||
|
* 此前 demote 只看顶层 body.headerToolbar → 树+grid 页恒 no-op → 「取消收藏」永久置灰、点不动
|
||||||
|
* (新闻/通知收藏页根因)。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void demoteUnscriptedBusinessButtons_树Grid页嵌套crud业务按钮也降级() {
|
||||||
|
Map<String, Object> cancelBtn = new java.util.LinkedHashMap<>();
|
||||||
|
cancelBtn.put("type", "button");
|
||||||
|
cancelBtn.put("id", "取消收藏");
|
||||||
|
cancelBtn.put("label", "取消收藏");
|
||||||
|
cancelBtn.put("actionType", "ajax");
|
||||||
|
cancelBtn.put("disabled", true); // baseline 永久灰
|
||||||
|
cancelBtn.put("api", Map.of("method", "post", "url", "/api/flow/OA_NEWSCOLLECTION_DELETE"));
|
||||||
|
Map<String, Object> crud = new java.util.LinkedHashMap<>();
|
||||||
|
crud.put("type", "crud");
|
||||||
|
crud.put("headerToolbar", new ArrayList<>(List.of(cancelBtn)));
|
||||||
|
// body=grid:左 column 树(无工具栏),右 column 嵌 crud(含 headerToolbar 业务按钮)
|
||||||
|
Map<String, Object> leftCol = Map.of("md", 3, "body", Map.of("type", "input-tree"));
|
||||||
|
Map<String, Object> rightCol = new java.util.LinkedHashMap<>();
|
||||||
|
rightCol.put("md", 9);
|
||||||
|
rightCol.put("body", crud);
|
||||||
|
Map<String, Object> grid = new java.util.LinkedHashMap<>();
|
||||||
|
grid.put("type", "grid");
|
||||||
|
grid.put("columns", new ArrayList<>(List.of(leftCol, rightCol)));
|
||||||
|
Map<String, Object> page = new java.util.LinkedHashMap<>();
|
||||||
|
page.put("type", "page");
|
||||||
|
page.put("body", grid);
|
||||||
|
|
||||||
|
converter.demoteUnscriptedBusinessButtons(page);
|
||||||
|
|
||||||
|
assertNull(cancelBtn.get("disabled"), "树+grid 嵌套 crud 的业务按钮去 baseline disabled:true");
|
||||||
|
assertEquals("${!selectedItems || selectedItems.length === 0}", cancelBtn.get("disabledOn"),
|
||||||
|
"树+grid 收藏页「取消收藏」选中即可点(修永久灰)");
|
||||||
|
}
|
||||||
|
|
||||||
// ── 小修#1:per-button 降级(脚本 enableButton 目标集未引用的业务按钮 → disabledOn)──────────
|
// ── 小修#1:per-button 降级(脚本 enableButton 目标集未引用的业务按钮 → disabledOn)──────────
|
||||||
|
|
||||||
/** 小修#1:从脚本文本提取 enableButton 目标按钮名(容忍空白、单/双引号、第二参点亮/置灰)。 */
|
/** 小修#1:从脚本文本提取 enableButton 目标按钮名(容忍空白、单/双引号、第二参点亮/置灰)。 */
|
||||||
@@ -2558,14 +2830,15 @@ class TemplateToAmisConverterTest {
|
|||||||
Map<String, Object> save = (Map<String, Object>) actions.get(0);
|
Map<String, Object> save = (Map<String, Object>) actions.get(0);
|
||||||
assertEquals("保存", save.get("label"));
|
assertEquals("保存", save.get("label"));
|
||||||
assertEquals("submit", save.get("actionType"));
|
assertEquals("submit", save.get("actionType"));
|
||||||
assertEquals("POST:/api/flow/OA_NOTICEMANAGE_ADD", save.get("api"));
|
// A1 compute-on-save:submit api 带 ?__egtpl=<editFormTemplateId> 透传给 FlowController 补算 editgrid 派生字段
|
||||||
|
assertEquals("POST:/api/flow/OA_NOTICEMANAGE_ADD?__egtpl=tmpl-editform-001", save.get("api"));
|
||||||
assertNull(save.get("data"), "submit 须由内层 form 采集字段值,不能用 dialog 空作用域 data 覆盖");
|
assertNull(save.get("data"), "submit 须由内层 form 采集字段值,不能用 dialog 空作用域 data 覆盖");
|
||||||
assertEquals(true, save.get("close"), "成功后关闭 dialog");
|
assertEquals(true, save.get("close"), "成功后关闭 dialog");
|
||||||
|
|
||||||
Map<String, Object> submit = (Map<String, Object>) actions.get(1);
|
Map<String, Object> submit = (Map<String, Object>) actions.get(1);
|
||||||
assertEquals("保存并提交审批", submit.get("label"));
|
assertEquals("保存并提交审批", submit.get("label"));
|
||||||
assertEquals("submit", submit.get("actionType"));
|
assertEquals("submit", submit.get("actionType"));
|
||||||
assertEquals("POST:/api/flow/OA_NOTICEMANAGE_ADD_AND_SUBMIT", submit.get("api"));
|
assertEquals("POST:/api/flow/OA_NOTICEMANAGE_ADD_AND_SUBMIT?__egtpl=tmpl-editform-001", submit.get("api"));
|
||||||
assertNull(submit.get("data"));
|
assertNull(submit.get("data"));
|
||||||
|
|
||||||
Map<String, Object> cancel = (Map<String, Object>) actions.get(2);
|
Map<String, Object> cancel = (Map<String, Object>) actions.get(2);
|
||||||
|
|||||||
@@ -0,0 +1,188 @@
|
|||||||
|
package com.eip4.platform.metadata.flow;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.dom4j.Document;
|
||||||
|
import org.dom4j.DocumentHelper;
|
||||||
|
import org.dom4j.Element;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.eip4.platform.metadata.script.EditGridScriptRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A1 compute-on-save:写流持久化前,服务端用 editgrid 行内脚本补算派生字段(如 金额=数量×单价、
|
||||||
|
* 申请总金额=明细金额之和),绕开 amis input-table 单元格提交与异步 onEvent 的前端竞态,保证落库数据正确。
|
||||||
|
*
|
||||||
|
* <p>背景:editgrid 派生字段(MONEY/applyTotalMoney)老引擎靠行内脚本算;新端 onEvent.change 在 amis
|
||||||
|
* input-table 里与单元格自身提交存在 React setState 竞态,致前端不可靠。本组件在 {@code _ADD/_UPDATE/
|
||||||
|
* _SAVE_AND_SUBMIT} 写流执行前,对提交 map 里的 editgrid 子表数组逐行 faithful 跑原 Groovy 补派生字段:
|
||||||
|
* <ol>
|
||||||
|
* <li><b>Pass 1 行内</b>:逐行跑每段脚本,取 {@code rowSetValues} 合并回该行(如 16b5ead3 算 MONEY);</li>
|
||||||
|
* <li><b>Pass 2 聚合</b>:用已补全的子表数组跑每段脚本,取 {@code parentSetValues} 合并回主 map
|
||||||
|
* (如 f0bbf4ce 汇总 applyTotalMoney)。</li>
|
||||||
|
* </ol>
|
||||||
|
*
|
||||||
|
* <p>templateId 由转换器在写流 submit api 上以 {@code ?__egtpl=} 透传;无 editgrid 的模板自然无操作。
|
||||||
|
* 任意异常吞掉不阻断保存(派生字段缺失好过保存失败)。纪律:零改 {@code com.dsasp}。
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class EditGridDerivedFieldComputer {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(EditGridDerivedFieldComputer.class);
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
public EditGridDerivedFieldComputer(JdbcTemplate jdbcTemplate) {
|
||||||
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 就地为提交 map 补算 editgrid 派生字段。templateId 空或无 editgrid → 无操作。 */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void enrich(Map<String, Object> map, String templateId) {
|
||||||
|
if (map == null || templateId == null || templateId.isBlank()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
List<EditGridSpec> specs = loadSpecs(templateId.trim());
|
||||||
|
for (EditGridSpec spec : specs) {
|
||||||
|
Object listObj = caseInsensitiveGet(map, spec.editgridField);
|
||||||
|
if (!(listObj instanceof List<?> rawRows) || rawRows.isEmpty() || spec.scriptsByKey.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
List<Map<String, Object>> rows = new ArrayList<>();
|
||||||
|
for (Object r : rawRows) {
|
||||||
|
if (r instanceof Map) {
|
||||||
|
rows.add((Map<String, Object>) r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (rows.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pass 1:逐行算行内派生字段(如 MONEY)。
|
||||||
|
for (Map<String, Object> row : rows) {
|
||||||
|
for (String key : spec.scriptsByKey.keySet()) {
|
||||||
|
EditGridScriptRunner runner = new EditGridScriptRunner(
|
||||||
|
row, map, spec.fieldTypes, spec.changedFieldFor(key));
|
||||||
|
runner.run("save:" + templateId + ":" + key, spec.scriptsByKey.get(key));
|
||||||
|
row.putAll(runner.getRowSetValues());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pass 2:用已补全子表数组算父级聚合(如 applyTotalMoney)。取末行作触发上下文。
|
||||||
|
Map<String, Object> repRow = rows.get(rows.size() - 1);
|
||||||
|
for (String key : spec.scriptsByKey.keySet()) {
|
||||||
|
EditGridScriptRunner runner = new EditGridScriptRunner(
|
||||||
|
repRow, map, spec.fieldTypes, spec.changedFieldFor(key));
|
||||||
|
runner.run("save:" + templateId + ":" + key, spec.scriptsByKey.get(key));
|
||||||
|
map.putAll(runner.getParentSetValues());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 派生字段补算失败不阻断保存(保存比派生字段更关键)。
|
||||||
|
log.warn("[EditGridDerived] compute-on-save 跳过 templateId={}: {}", templateId, e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ────────────────────────────────────────────── 解析 view_page editgrid 规格
|
||||||
|
|
||||||
|
private static final class EditGridSpec {
|
||||||
|
final String editgridField;
|
||||||
|
final Map<String, String> fieldTypes = new LinkedHashMap<>(); // 子字段 name → java 类型
|
||||||
|
final Map<String, String> fieldScript = new LinkedHashMap<>(); // 子字段 name → scriptKey(仅有脚本的)
|
||||||
|
final Map<String, String> scriptsByKey = new LinkedHashMap<>(); // scriptKey → 脚本正文
|
||||||
|
|
||||||
|
EditGridSpec(String editgridField) {
|
||||||
|
this.editgridField = editgridField;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 某 scriptKey 的代表「变更字段」:取首个绑定该脚本的子字段(脚本 event/getFieldValue 据此取值)。 */
|
||||||
|
String changedFieldFor(String scriptKey) {
|
||||||
|
for (Map.Entry<String, String> e : fieldScript.entrySet()) {
|
||||||
|
if (scriptKey.equals(e.getValue())) {
|
||||||
|
return e.getKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<EditGridSpec> loadSpecs(String templateId) throws Exception {
|
||||||
|
List<EditGridSpec> specs = new ArrayList<>();
|
||||||
|
List<Map<String, Object>> rows = jdbcTemplate.queryForList(
|
||||||
|
"SELECT xml::text AS xml FROM view_page WHERE view_page_id = ?", templateId);
|
||||||
|
if (rows.isEmpty() || rows.get(0).get("xml") == null) {
|
||||||
|
return specs;
|
||||||
|
}
|
||||||
|
Document page = DocumentHelper.parseText(rows.get(0).get("xml").toString().trim());
|
||||||
|
Element fields = page.getRootElement().element("fields");
|
||||||
|
if (fields == null) {
|
||||||
|
return specs;
|
||||||
|
}
|
||||||
|
for (Element f : fields.elements("field")) {
|
||||||
|
Element tpl = f.element("editgridtemplate");
|
||||||
|
String name = f.attributeValue("name");
|
||||||
|
if (tpl == null || name == null || name.isBlank()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String tplXml = tpl.getText();
|
||||||
|
if (tplXml == null || tplXml.isBlank()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Element editgrid = DocumentHelper.parseText(tplXml.trim()).getRootElement().element("editgrid");
|
||||||
|
if (editgrid == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
EditGridSpec spec = new EditGridSpec(name);
|
||||||
|
Set<String> usedKeys = new LinkedHashSet<>();
|
||||||
|
for (Element sub : editgrid.elements("field")) {
|
||||||
|
String sn = sub.attributeValue("name");
|
||||||
|
String type = sub.attributeValue("type");
|
||||||
|
String script = sub.attributeValue("script", "");
|
||||||
|
if (sn == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (type != null) {
|
||||||
|
spec.fieldTypes.put(sn, type);
|
||||||
|
}
|
||||||
|
if (!script.isBlank()) {
|
||||||
|
spec.fieldScript.put(sn, script.trim());
|
||||||
|
usedKeys.add(script.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Element scripts = editgrid.element("scripts");
|
||||||
|
if (scripts != null) {
|
||||||
|
for (Element s : scripts.elements("script")) {
|
||||||
|
String key = s.attributeValue("key");
|
||||||
|
if (key != null && usedKeys.contains(key.trim())) {
|
||||||
|
spec.scriptsByKey.put(key.trim(), s.getText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!spec.scriptsByKey.isEmpty()) {
|
||||||
|
specs.add(spec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return specs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object caseInsensitiveGet(Map<String, Object> map, String key) {
|
||||||
|
if (map.containsKey(key)) {
|
||||||
|
return map.get(key);
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, Object> e : map.entrySet()) {
|
||||||
|
if (key.equalsIgnoreCase(e.getKey())) {
|
||||||
|
return e.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,9 @@ import java.util.Map;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
import org.joda.time.format.DateTimeFormat;
|
||||||
|
import org.joda.time.format.ISODateTimeFormat;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
@@ -338,13 +341,47 @@ public class FlowInputCoercer {
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case "DATE", "TIME" -> {
|
||||||
|
// DATE/TIME 列:引擎 GeneralPO 期望 joda DateTime,amis input-date/datetime 提交字符串
|
||||||
|
// (ISO/时间戳/yyyy-MM-dd[ HH:mm:ss])。原默认不转 → 引擎直接 cast String→DateTime 抛
|
||||||
|
// ClassCastException,致一切含日期列的表单写流崩。此处 String→joda DateTime(parse 失败保留原值)。
|
||||||
|
return coerceDate(val.trim(), colName);
|
||||||
|
}
|
||||||
default -> {
|
default -> {
|
||||||
// NVARCHAR/CHAR/TIME/DATE/LIST/BLOB/CODE/UUID-ref 等 → 不动
|
// NVARCHAR/CHAR/LIST/BLOB/CODE/UUID-ref 等 → 不动
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** DATE/TIME 字符串 → joda {@link DateTime}:依次试 毫秒时间戳 → ISO → {@code yyyy-MM-dd HH:mm:ss} → {@code yyyy-MM-dd};都失败保留原值。 */
|
||||||
|
private Object coerceDate(String v, String colName) {
|
||||||
|
if (v.isEmpty()) {
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
if (v.matches("-?\\d{12,}")) { // 13 位左右毫秒时间戳
|
||||||
|
try {
|
||||||
|
return new DateTime(Long.parseLong(v));
|
||||||
|
} catch (RuntimeException ignore) {
|
||||||
|
// 非时间戳 → 继续试格式
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return ISODateTimeFormat.dateTimeParser().withOffsetParsed().parseDateTime(v); // 含 2026-06-15 / ...T...Z / 带偏移
|
||||||
|
} catch (RuntimeException ignore) {
|
||||||
|
// 非 ISO → 试本地格式
|
||||||
|
}
|
||||||
|
for (String p : new String[] {"yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd"}) {
|
||||||
|
try {
|
||||||
|
return DateTimeFormat.forPattern(p).parseDateTime(v);
|
||||||
|
} catch (RuntimeException ignore) {
|
||||||
|
// 试下一格式
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.debug("[FLOW-COERCE] col={} DATE/TIME val='{}' 无法解析为日期, keeping String", colName, v);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
/** 失效单表缓存(元数据变更时,与 /api/meta/evict 钩子对齐)。 */
|
/** 失效单表缓存(元数据变更时,与 /api/meta/evict 钩子对齐)。 */
|
||||||
public void evict(String table) {
|
public void evict(String table) {
|
||||||
if (table != null && !table.isBlank()) {
|
if (table != null && !table.isBlank()) {
|
||||||
|
|||||||
@@ -0,0 +1,246 @@
|
|||||||
|
package com.eip4.platform.metadata.script;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.script.Bindings;
|
||||||
|
import javax.script.SimpleBindings;
|
||||||
|
|
||||||
|
import com.dsasp.server.common.function.GetServicesFunction;
|
||||||
|
import com.dsasp.server.dataDic.binding.ScriptingEnginesManager;
|
||||||
|
|
||||||
|
import groovy.lang.Closure;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A1 — EditGrid 行内联动脚本的服务端 faithful 执行器(引擎级原语)。
|
||||||
|
*
|
||||||
|
* <p>老引擎子表(EditGrid)字段的 {@code script} 属性是「单元格值变化触发的行内联动脚本」
|
||||||
|
* (如采购明细:数量×单价→金额、选用品→loadPOJO 带出规格单位、金额→汇总主表总额)。这些 Groovy
|
||||||
|
* 脚本引用 {@code getFieldValue/bindField/event/group/group.parent/GetServicesFunction.loadPOJO}
|
||||||
|
* 等行/父上下文 API。本执行器零改写地跑原脚本:把 amis 提交的当前行 + 父表单数据域包成 Groovy 绑定,
|
||||||
|
* 捕获脚本对当前行/父字段的 setValue,返回 {@code rowSetValues}(当前行)+ {@code parentSetValues}
|
||||||
|
* (主表,如 applyTotalMoney),前端按行/表单作用域回写。
|
||||||
|
*
|
||||||
|
* <p>类型保真:amis JSON 数值经 Jackson 落成 Integer/Double,而脚本按老引擎字段声明类型运算
|
||||||
|
* ({@code new BigDecimal(getFieldValue("AMOUNT"))} 需 Integer、{@code amount.multiply(price)} 需
|
||||||
|
* BigDecimal)。{@link #coerce} 据 editgrid 子字段 {@code type} 把值强转回声明类型,复刻老引擎
|
||||||
|
* {@code getFieldValue} 返回类型化值的语义。
|
||||||
|
*
|
||||||
|
* <p>纪律:零改 {@code com.dsasp};脚本执行复用引擎 {@link ScriptingEnginesManager},DB 取值
|
||||||
|
* 复用 {@code GetServicesFunction.loadPOJO}(其内部走 pojoCRUDService + 当前会话)。
|
||||||
|
*/
|
||||||
|
public final class EditGridScriptRunner {
|
||||||
|
|
||||||
|
private final Map<String, Object> row;
|
||||||
|
private final Map<String, Object> parent;
|
||||||
|
private final Map<String, String> fieldTypes;
|
||||||
|
private final Object changedValue;
|
||||||
|
|
||||||
|
private final Map<String, Object> rowSetValues = new LinkedHashMap<>();
|
||||||
|
private final Map<String, Object> parentSetValues = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
public EditGridScriptRunner(Map<String, Object> row, Map<String, Object> parent,
|
||||||
|
Map<String, String> fieldTypes, String changedField) {
|
||||||
|
this.row = row != null ? row : new LinkedHashMap<>();
|
||||||
|
this.parent = parent != null ? parent : new LinkedHashMap<>();
|
||||||
|
this.fieldTypes = fieldTypes != null ? fieldTypes : Map.of();
|
||||||
|
this.changedValue = coerce(changedField, this.row.get(changedField));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getRowSetValues() {
|
||||||
|
return rowSetValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getParentSetValues() {
|
||||||
|
return parentSetValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 跑一段 editgrid Groovy 脚本,捕获行/父字段 setValue。 */
|
||||||
|
public void run(String key, String script) {
|
||||||
|
if (script == null || script.isBlank()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bindings b = new SimpleBindings();
|
||||||
|
// 行级动词(复刻老引擎 group 域内函数)—— 用 Groovy Closure 绑定,脚本方能以 getFieldValue("X") 调用。
|
||||||
|
bind(b, "getFieldValue", a -> { String f = str(arg(a, 0)); return coerce(f, row.get(f)); });
|
||||||
|
bind(b, "bindField", a -> { rowSetValues.put(str(arg(a, 0)), arg(a, 1)); row.put(str(arg(a, 0)), arg(a, 1)); return null; });
|
||||||
|
// 行/父代理对象(group.getField / group.parent.getField)
|
||||||
|
FieldScope rowScope = new FieldScope(row, rowSetValues);
|
||||||
|
FieldScope parentScope = new FieldScope(parent, parentSetValues);
|
||||||
|
b.put("group", new GroupHandle(rowScope, parentScope));
|
||||||
|
b.put("event", new EventHandle(changedValue));
|
||||||
|
// DB 取值:GetServicesFunction.loadPOJO(静态委托 pojoCRUDService + UserSession,脚本原样调用)
|
||||||
|
b.put("GetServicesFunction", new GetServicesFunction());
|
||||||
|
ScriptingEnginesManager.getScriptingEnginesManager().evaluateGroovy(key, script, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ────────────────────────────────────────────── 类型保真
|
||||||
|
|
||||||
|
private Object coerce(String field, Object v) {
|
||||||
|
if (v == null || field == null) {
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
String type = fieldTypes.get(field);
|
||||||
|
if (type == null) {
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return switch (type) {
|
||||||
|
case "java.math.BigDecimal" -> v instanceof BigDecimal ? v : new BigDecimal(v.toString().trim());
|
||||||
|
case "java.lang.Integer" -> v instanceof Integer ? v : Integer.valueOf(new BigDecimal(v.toString().trim()).intValue());
|
||||||
|
case "java.lang.Long" -> v instanceof Long ? v : Long.valueOf(new BigDecimal(v.toString().trim()).longValue());
|
||||||
|
case "java.lang.Double" -> v instanceof Double ? v : Double.valueOf(v.toString().trim());
|
||||||
|
default -> v;
|
||||||
|
};
|
||||||
|
} catch (NumberFormatException ignore) {
|
||||||
|
return v; // 非数值(空串等)→ 原值,脚本自行判 null/""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String str(Object o) {
|
||||||
|
return o == null ? null : o.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ────────────────────────────────────────────── Groovy 闭包绑定(同 ScriptFacade 口径)
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
private interface VerbFn {
|
||||||
|
Object call(Object[] args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void bind(Bindings b, String name, VerbFn fn) {
|
||||||
|
b.put(name, new Closure<Object>(EditGridScriptRunner.class) {
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public Object doCall(Object... args) {
|
||||||
|
return fn.call(args);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object arg(Object[] a, int i) {
|
||||||
|
return a != null && i < a.length ? a[i] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ────────────────────────────────────────────── Groovy 绑定代理
|
||||||
|
|
||||||
|
/** group / group.parent 的字段域:getField(name) → FieldHandle,setValue 收集进对应 *SetValues。 */
|
||||||
|
private final class FieldScope {
|
||||||
|
final Map<String, Object> data;
|
||||||
|
final Map<String, Object> sink;
|
||||||
|
|
||||||
|
FieldScope(Map<String, Object> data, Map<String, Object> sink) {
|
||||||
|
this.data = data;
|
||||||
|
this.sink = sink;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldHandle getField(String name) {
|
||||||
|
return new FieldHandle(this, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** group 句柄:getField + parent。 */
|
||||||
|
public final class GroupHandle {
|
||||||
|
private final FieldScope rowScope;
|
||||||
|
private final FieldScope parentScope;
|
||||||
|
|
||||||
|
GroupHandle(FieldScope rowScope, FieldScope parentScope) {
|
||||||
|
this.rowScope = rowScope;
|
||||||
|
this.parentScope = parentScope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldHandle getField(String name) {
|
||||||
|
return rowScope.getField(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** group.parent → 父表单域(含 applyTotalMoney / GOODSDETAIL 列表)。Groovy {@code group.parent} 经此 getter 解析。 */
|
||||||
|
public ParentHandle getParent() {
|
||||||
|
return new ParentHandle(parentScope);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** group.parent 句柄:getField(name) → 父字段(applyTotalMoney 等)。 */
|
||||||
|
public final class ParentHandle {
|
||||||
|
private final FieldScope scope;
|
||||||
|
|
||||||
|
ParentHandle(FieldScope scope) {
|
||||||
|
this.scope = scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldHandle getField(String name) {
|
||||||
|
return scope.getField(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 字段句柄:getValue/setValue/setConvertedValue/setReadOnly + getPropertyDataSource(只读切换为 no-op)。 */
|
||||||
|
public final class FieldHandle {
|
||||||
|
private final FieldScope scope;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
FieldHandle(FieldScope scope, String name) {
|
||||||
|
this.scope = scope;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getValue() {
|
||||||
|
return scope.data.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object setValue(Object v) {
|
||||||
|
scope.sink.put(name, v);
|
||||||
|
scope.data.put(name, v); // 同步本地域,供后续脚本读到
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object setConvertedValue(Object v) {
|
||||||
|
return setValue(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 老引擎临时解锁只读以编程赋值;amis 侧由 schema 控只读,此处记录但赋值照常生效 → no-op。 */
|
||||||
|
public Object setReadOnly(Object readOnly) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PropertyDataSourceHandle getPropertyDataSource() {
|
||||||
|
return new PropertyDataSourceHandle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** field.getPropertyDataSource().setReadOnly(...) 占位(只读切换在 amis 由 schema 控)。 */
|
||||||
|
public static final class PropertyDataSourceHandle {
|
||||||
|
public Object setReadOnly(Object readOnly) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** event.getProperty().getValue() → 变更字段的新值(已类型保真)。 */
|
||||||
|
public static final class EventHandle {
|
||||||
|
private final Object value;
|
||||||
|
|
||||||
|
EventHandle(Object value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PropertyHandle getProperty() {
|
||||||
|
return new PropertyHandle(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class PropertyHandle {
|
||||||
|
private final Object value;
|
||||||
|
|
||||||
|
PropertyHandle(Object value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static List<Map<String, Object>> asList(Object o) {
|
||||||
|
return o instanceof List<?> l ? (List<Map<String, Object>>) l : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
package com.eip4.platform.metadata.web;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.dom4j.Document;
|
||||||
|
import org.dom4j.DocumentHelper;
|
||||||
|
import org.dom4j.Element;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.eip4.platform.metadata.script.EditGridScriptRunner;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A1 — EditGrid 行内联动脚本执行端点(引擎级原语)。
|
||||||
|
*
|
||||||
|
* <p>转换器把子表列的老 {@code script}(单元格 onchange 联动)挂成 amis input-table 列的
|
||||||
|
* {@code quickEdit.onEvent.change} 动作链:ajax 调本端点,传 {@code templateId/editgridField/
|
||||||
|
* scriptKey/changedField + 当前行 + 父表单域}。本端点据 {@code (templateId, editgridField, scriptKey)}
|
||||||
|
* 从 {@code view_page} 的 {@code <editgridtemplate>} 解析脚本正文与子字段类型,经
|
||||||
|
* {@link EditGridScriptRunner} faithful 跑原 Groovy,返回 {@code rowSetValues}(当前行)+
|
||||||
|
* {@code parentSetValues}(主表,如 applyTotalMoney)供前端按作用域回写。
|
||||||
|
*
|
||||||
|
* <p>契约:{@code POST /api/script/execute-editgrid-row},请求体
|
||||||
|
* {@code {templateId, editgridField, scriptKey, changedField, row:{...}, parent:{...}}} →
|
||||||
|
* {@code {status:0, data:{rowSetValues:{...}, parentSetValues:{...}}}}。脚本/字段缺失或执行异常 →
|
||||||
|
* 返回空 setValues(前端无联动,no-op),不阻断录入。
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@Tag(name = "子表行内脚本", description = "A1 EditGrid 行内联动脚本服务端 faithful 执行")
|
||||||
|
public class EditGridScriptController {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(EditGridScriptController.class);
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
public EditGridScriptController(JdbcTemplate jdbcTemplate) {
|
||||||
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "执行 EditGrid 行内联动脚本(返回 rowSetValues/parentSetValues)")
|
||||||
|
@PostMapping("/api/script/execute-editgrid-row")
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Map<String, Object> execute(@RequestBody Map<String, Object> body) {
|
||||||
|
Map<String, Object> data = new LinkedHashMap<>();
|
||||||
|
data.put("rowSetValues", new LinkedHashMap<>());
|
||||||
|
data.put("parentSetValues", new LinkedHashMap<>());
|
||||||
|
Map<String, Object> resp = new LinkedHashMap<>();
|
||||||
|
resp.put("status", 0);
|
||||||
|
resp.put("msg", "");
|
||||||
|
resp.put("data", data);
|
||||||
|
|
||||||
|
String templateId = str(body.get("templateId"));
|
||||||
|
String editgridField = str(body.get("editgridField"));
|
||||||
|
String scriptKey = str(body.get("scriptKey"));
|
||||||
|
String changedField = str(body.get("changedField"));
|
||||||
|
Map<String, Object> row = body.get("row") instanceof Map ? (Map<String, Object>) body.get("row") : new LinkedHashMap<>();
|
||||||
|
Map<String, Object> parent = body.get("parent") instanceof Map ? (Map<String, Object>) body.get("parent") : new LinkedHashMap<>();
|
||||||
|
|
||||||
|
if (templateId == null || editgridField == null || scriptKey == null) {
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
EditGridSpec spec = loadEditGridSpec(templateId.trim(), editgridField.trim(), scriptKey.trim());
|
||||||
|
if (spec == null || spec.script == null || spec.script.isBlank()) {
|
||||||
|
return resp; // 脚本缺失 → no-op
|
||||||
|
}
|
||||||
|
EditGridScriptRunner runner = new EditGridScriptRunner(row, parent, spec.fieldTypes, changedField);
|
||||||
|
runner.run("editgrid:" + templateId + ":" + scriptKey, spec.script);
|
||||||
|
data.put("rowSetValues", runner.getRowSetValues());
|
||||||
|
data.put("parentSetValues", runner.getParentSetValues());
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 脚本执行异常不阻断录入:返回空 setValues + 记录(不外泄给前端)。
|
||||||
|
log.warn("[EditGridScript] 执行失败 templateId={} field={} key={}: {}",
|
||||||
|
templateId, editgridField, scriptKey, e.toString());
|
||||||
|
}
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ────────────────────────────────────────────── 脚本/字段类型解析
|
||||||
|
|
||||||
|
private record EditGridSpec(String script, Map<String, String> fieldTypes) {}
|
||||||
|
|
||||||
|
/** 从 view_page 的 editgridtemplate 解析 (脚本正文, 子字段 name→java类型)。 */
|
||||||
|
private EditGridSpec loadEditGridSpec(String templateId, String editgridField, String scriptKey) throws Exception {
|
||||||
|
List<Map<String, Object>> rows = jdbcTemplate.queryForList(
|
||||||
|
"SELECT xml::text AS xml FROM view_page WHERE view_page_id = ?", templateId);
|
||||||
|
if (rows.isEmpty() || rows.get(0).get("xml") == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Document page = DocumentHelper.parseText(rows.get(0).get("xml").toString().trim());
|
||||||
|
Element fields = page.getRootElement().element("fields");
|
||||||
|
if (fields == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (Element f : fields.elements("field")) {
|
||||||
|
if (!editgridField.equalsIgnoreCase(f.attributeValue("name"))
|
||||||
|
|| f.element("editgridtemplate") == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String tplXml = f.element("editgridtemplate").getText();
|
||||||
|
if (tplXml == null || tplXml.isBlank()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Element editgrid = DocumentHelper.parseText(tplXml.trim()).getRootElement().element("editgrid");
|
||||||
|
if (editgrid == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Map<String, String> fieldTypes = new LinkedHashMap<>();
|
||||||
|
for (Element sub : editgrid.elements("field")) {
|
||||||
|
String name = sub.attributeValue("name");
|
||||||
|
String type = sub.attributeValue("type");
|
||||||
|
if (name != null && type != null) {
|
||||||
|
fieldTypes.put(name, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Element scripts = editgrid.element("scripts");
|
||||||
|
String script = null;
|
||||||
|
if (scripts != null) {
|
||||||
|
for (Element s : scripts.elements("script")) {
|
||||||
|
if (scriptKey.equals(s.attributeValue("key"))) {
|
||||||
|
script = s.getText();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new EditGridSpec(script, fieldTypes);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String str(Object o) {
|
||||||
|
return o == null ? null : o.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,6 +25,7 @@ import com.dsasp.server.common.core.service.FlowExcuteService;
|
|||||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||||
import com.dsasp.server.common.util.UserSession;
|
import com.dsasp.server.common.util.UserSession;
|
||||||
|
import com.eip4.platform.metadata.flow.EditGridDerivedFieldComputer;
|
||||||
import com.eip4.platform.metadata.flow.FlowInputCoercer;
|
import com.eip4.platform.metadata.flow.FlowInputCoercer;
|
||||||
import com.eip4.platform.metadata.flow.FlowNameResolver;
|
import com.eip4.platform.metadata.flow.FlowNameResolver;
|
||||||
import com.eip4.platform.metadata.flow.FlowNameResolver.ResolvedFlow;
|
import com.eip4.platform.metadata.flow.FlowNameResolver.ResolvedFlow;
|
||||||
@@ -71,35 +72,45 @@ public class FlowController {
|
|||||||
private final UserColumnResolver userColumnResolver;
|
private final UserColumnResolver userColumnResolver;
|
||||||
private final FlowReadWriteClassifier classifier;
|
private final FlowReadWriteClassifier classifier;
|
||||||
private final FlowInputCoercer inputCoercer;
|
private final FlowInputCoercer inputCoercer;
|
||||||
|
/** A1 compute-on-save:写流执行前为 editgrid 子表补算派生字段(金额/总额)。可空(老单测构造)。 */
|
||||||
|
private final EditGridDerivedFieldComputer editGridComputer;
|
||||||
|
|
||||||
/** Spring 注入入口(5 参:读写分类器 + 类型强制器)。
|
/** Spring 注入入口(6 参:读写分类器 + 类型强制器 + editgrid 派生字段补算器)。
|
||||||
* 多构造器场景须显式 @Autowired 指明注入构造,否则 Spring 回退无参构造致启动失败。 */
|
* 多构造器场景须显式 @Autowired 指明注入构造,否则 Spring 回退无参构造致启动失败。 */
|
||||||
@org.springframework.beans.factory.annotation.Autowired
|
@org.springframework.beans.factory.annotation.Autowired
|
||||||
public FlowController(FlowExcuteService flowExcuteService, FlowNameResolver flowNameResolver,
|
public FlowController(FlowExcuteService flowExcuteService, FlowNameResolver flowNameResolver,
|
||||||
UserColumnResolver userColumnResolver, FlowReadWriteClassifier classifier,
|
UserColumnResolver userColumnResolver, FlowReadWriteClassifier classifier,
|
||||||
FlowInputCoercer inputCoercer) {
|
FlowInputCoercer inputCoercer, EditGridDerivedFieldComputer editGridComputer) {
|
||||||
this.flowExcuteService = flowExcuteService;
|
this.flowExcuteService = flowExcuteService;
|
||||||
this.flowNameResolver = flowNameResolver;
|
this.flowNameResolver = flowNameResolver;
|
||||||
this.userColumnResolver = userColumnResolver;
|
this.userColumnResolver = userColumnResolver;
|
||||||
this.classifier = classifier;
|
this.classifier = classifier;
|
||||||
this.inputCoercer = inputCoercer;
|
this.inputCoercer = inputCoercer;
|
||||||
|
this.editGridComputer = editGridComputer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 兼容老单测的四参构造(无类型强制器:写流跳过 coerce)。生产由 Spring 走五参构造。 */
|
/** 兼容老单测的五参构造(无 editgrid 补算器)。生产由 Spring 走六参构造。 */
|
||||||
|
public FlowController(FlowExcuteService flowExcuteService, FlowNameResolver flowNameResolver,
|
||||||
|
UserColumnResolver userColumnResolver, FlowReadWriteClassifier classifier,
|
||||||
|
FlowInputCoercer inputCoercer) {
|
||||||
|
this(flowExcuteService, flowNameResolver, userColumnResolver, classifier, inputCoercer, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 兼容老单测的四参构造(无类型强制器:写流跳过 coerce)。生产由 Spring 走六参构造。 */
|
||||||
public FlowController(FlowExcuteService flowExcuteService, FlowNameResolver flowNameResolver,
|
public FlowController(FlowExcuteService flowExcuteService, FlowNameResolver flowNameResolver,
|
||||||
UserColumnResolver userColumnResolver, FlowReadWriteClassifier classifier) {
|
UserColumnResolver userColumnResolver, FlowReadWriteClassifier classifier) {
|
||||||
this(flowExcuteService, flowNameResolver, userColumnResolver, classifier, null);
|
this(flowExcuteService, flowNameResolver, userColumnResolver, classifier, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 兼容老单测的三参构造(无分类器、无类型强制器)。生产由 Spring 走五参构造。 */
|
/** 兼容老单测的三参构造(无分类器、无类型强制器)。生产由 Spring 走六参构造。 */
|
||||||
public FlowController(FlowExcuteService flowExcuteService, FlowNameResolver flowNameResolver,
|
public FlowController(FlowExcuteService flowExcuteService, FlowNameResolver flowNameResolver,
|
||||||
UserColumnResolver userColumnResolver) {
|
UserColumnResolver userColumnResolver) {
|
||||||
this(flowExcuteService, flowNameResolver, userColumnResolver, null, null);
|
this(flowExcuteService, flowNameResolver, userColumnResolver, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 兼容老单测的两参构造(无用户列解析、无分类器、无类型强制器)。生产由 Spring 走五参构造。 */
|
/** 兼容老单测的两参构造(无用户列解析、无分类器、无类型强制器)。生产由 Spring 走六参构造。 */
|
||||||
public FlowController(FlowExcuteService flowExcuteService, FlowNameResolver flowNameResolver) {
|
public FlowController(FlowExcuteService flowExcuteService, FlowNameResolver flowNameResolver) {
|
||||||
this(flowExcuteService, flowNameResolver, null, null, null);
|
this(flowExcuteService, flowNameResolver, null, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** amis crud 默认每页条数(与前端 amis 默认 perPage 一致)。 */
|
/** amis crud 默认每页条数(与前端 amis 默认 perPage 一致)。 */
|
||||||
@@ -123,9 +134,15 @@ public class FlowController {
|
|||||||
@PostMapping("/{id}")
|
@PostMapping("/{id}")
|
||||||
@Operation(summary = "执行服务流(POST):JSON body 作为入参 map,返回流输出 JSON")
|
@Operation(summary = "执行服务流(POST):JSON body 作为入参 map,返回流输出 JSON")
|
||||||
public ResponseEntity<Map<String, Object>> executePost(@PathVariable String id,
|
public ResponseEntity<Map<String, Object>> executePost(@PathVariable String id,
|
||||||
|
@RequestParam(value = "__egtpl", required = false) String egTpl,
|
||||||
@RequestBody(required = false) Map<String, Object> body) {
|
@RequestBody(required = false) Map<String, Object> body) {
|
||||||
Map<String, Object> map = body == null ? new HashMap<>() : new HashMap<>(body);
|
Map<String, Object> map = body == null ? new HashMap<>() : new HashMap<>(body);
|
||||||
applyPaging(map);
|
applyPaging(map);
|
||||||
|
// A1 compute-on-save:写流 submit 带 ?__egtpl=<view_page_id> 时,落库前补算 editgrid 派生字段
|
||||||
|
// (金额=数量×单价、申请总金额=明细之和),绕开 amis input-table 前端竞态。无 editgrid 自然无操作。
|
||||||
|
if (egTpl != null && !egTpl.isBlank() && editGridComputer != null) {
|
||||||
|
editGridComputer.enrich(map, egTpl);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return run(id, map, true);
|
return run(id, map, true);
|
||||||
} catch (RuntimeException ex) {
|
} catch (RuntimeException ex) {
|
||||||
@@ -425,11 +442,25 @@ public class FlowController {
|
|||||||
return id.replaceAll("[^A-Za-z0-9_\\-]", "?");
|
return id.replaceAll("[^A-Za-z0-9_\\-]", "?");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 归一化递归深度上限:防嵌套 GeneralPOJO 互引成环时无限递归(正常对象图远浅于此)。 */
|
||||||
|
private static final int MAX_NORMALIZE_DEPTH = 16;
|
||||||
|
|
||||||
/** 递归归一化引擎返回值,使之可被 Jackson 序列化(GeneralPOJO 非 bean,需手工展平)。 */
|
/** 递归归一化引擎返回值,使之可被 Jackson 序列化(GeneralPOJO 非 bean,需手工展平)。 */
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private Object normalize(Object value) {
|
private Object normalize(Object value) {
|
||||||
|
return normalize(value, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 深度受限的递归归一化。{@code depth} 超限 → 对 GeneralPOJO/容器返 null(截断),标量原样返
|
||||||
|
* (防互引成环;正常单据对象图浅于 16 层)。
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private Object normalize(Object value, int depth) {
|
||||||
|
if (depth > MAX_NORMALIZE_DEPTH) {
|
||||||
|
return (value instanceof GeneralPOJO || value instanceof Map || value instanceof List) ? null : value;
|
||||||
|
}
|
||||||
if (value instanceof GeneralPOJO p) {
|
if (value instanceof GeneralPOJO p) {
|
||||||
return toRow(p);
|
return toRow(p, depth);
|
||||||
}
|
}
|
||||||
if (value instanceof Map<?, ?> m) {
|
if (value instanceof Map<?, ?> m) {
|
||||||
// listSelect 结果:{listresult:[...], pagecount:N} → amis {items, total}。
|
// listSelect 结果:{listresult:[...], pagecount:N} → amis {items, total}。
|
||||||
@@ -439,20 +470,20 @@ public class FlowController {
|
|||||||
if (m.containsKey(POJOCRUDService.LIST_RESULT) || m.containsKey(POJOCRUDService.PAGE_COUNT)) {
|
if (m.containsKey(POJOCRUDService.LIST_RESULT) || m.containsKey(POJOCRUDService.PAGE_COUNT)) {
|
||||||
Map<String, Object> data = new LinkedHashMap<>();
|
Map<String, Object> data = new LinkedHashMap<>();
|
||||||
Object list = m.get(POJOCRUDService.LIST_RESULT);
|
Object list = m.get(POJOCRUDService.LIST_RESULT);
|
||||||
data.put("items", list != null ? normalize(list) : new ArrayList<>());
|
data.put("items", list != null ? normalize(list, depth + 1) : new ArrayList<>());
|
||||||
data.put("total", m.containsKey(POJOCRUDService.PAGE_COUNT) ? m.get(POJOCRUDService.PAGE_COUNT) : 0);
|
data.put("total", m.containsKey(POJOCRUDService.PAGE_COUNT) ? m.get(POJOCRUDService.PAGE_COUNT) : 0);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
Map<String, Object> out = new LinkedHashMap<>();
|
Map<String, Object> out = new LinkedHashMap<>();
|
||||||
for (Map.Entry<?, ?> e : m.entrySet()) {
|
for (Map.Entry<?, ?> e : m.entrySet()) {
|
||||||
out.put(String.valueOf(e.getKey()), normalize(e.getValue()));
|
out.put(String.valueOf(e.getKey()), normalize(e.getValue(), depth + 1));
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
if (value instanceof List<?> list) {
|
if (value instanceof List<?> list) {
|
||||||
List<Object> out = new ArrayList<>(list.size());
|
List<Object> out = new ArrayList<>(list.size());
|
||||||
for (Object o : list) {
|
for (Object o : list) {
|
||||||
out.add(normalize(o));
|
out.add(normalize(o, depth + 1));
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@@ -461,10 +492,20 @@ public class FlowController {
|
|||||||
|
|
||||||
/** GeneralPOJO 值存于内部数组(非 bean getter),展开为平面 map 供 JSON 序列化。 */
|
/** GeneralPOJO 值存于内部数组(非 bean getter),展开为平面 map 供 JSON 序列化。 */
|
||||||
private Map<String, Object> toRow(GeneralPOJO p) {
|
private Map<String, Object> toRow(GeneralPOJO p) {
|
||||||
|
return toRow(p, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GeneralPOJO → 平面 map(仅 {@code _id} + 实体列)。<b>列值递归 {@link #normalize}</b>:嵌套 GeneralPOJO
|
||||||
|
* /列表(如 NOTICERECEIVE_LIST)也经 toRow 干净展平,而非被 Jackson 反射序列化原始 GeneralPOJO——后者
|
||||||
|
* 既泄露内部字段({@code selectBuild}=原始SQL、{@code ctx}=ROLES、{@code mainPO}/{@code _poInfo}),
|
||||||
|
* 又因内部 typed 字段触 {@code String→Integer} 序列化崩(裸 500,逃 graceful 兜底)。
|
||||||
|
*/
|
||||||
|
private Map<String, Object> toRow(GeneralPOJO p, int depth) {
|
||||||
Map<String, Object> row = new LinkedHashMap<>();
|
Map<String, Object> row = new LinkedHashMap<>();
|
||||||
row.put("_id", p.get_ID());
|
row.put("_id", p.get_ID());
|
||||||
for (int i = 0; i < p.get_ColumnCount(); i++) {
|
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), normalize(p.get_Value(i), depth + 1));
|
||||||
}
|
}
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,173 @@
|
|||||||
|
package com.eip4.platform.metadata.web;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.dom4j.Document;
|
||||||
|
import org.dom4j.DocumentHelper;
|
||||||
|
import org.dom4j.Element;
|
||||||
|
import org.joda.time.format.DateTimeFormat;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
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.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.dsasp.server.common.dataDic.service.CodeRuleService;
|
||||||
|
import com.dsasp.server.common.function.GetDefaultValueFunction;
|
||||||
|
import com.eip4.platform.metadata.flow.UserColumnResolver;
|
||||||
|
import com.eip4.platform.metadata.security.IdentifierWhitelist;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* B — 新建表单默认值/编号服务端解析端点。
|
||||||
|
*
|
||||||
|
* <p>老引擎字段 {@code initvalue} 携带宏({@code {CURRENTUSER}/{CURRENTDEPART}/{CURRENTORG}/
|
||||||
|
* {CURRENTPROJECT}/{CURRENTTIME}/{AUTOGENERATECODE}})。转换器对动态宏只能产出前端表达式
|
||||||
|
* (且 {@code {CURRENTDEPART}} 漏映射、{@code AUTOGENERATECODE} 诚实降级不塞值),致采购申请等
|
||||||
|
* 新建时表单号/申请人/申请部门/申请日期全空。本端点在「添加」时服务端 faithful 解析这些宏,
|
||||||
|
* 复用引擎现成能力:{@link GetDefaultValueFunction}(从 {@code UserSession} 取当前用户/部门/组织/工程/时间)
|
||||||
|
* + {@link CodeRuleService#getCode}(按 {@code SYS_CODERULE} 规则生成流水号,如 {@code CGSQ-202604-000003})。
|
||||||
|
* 对用户/部门等引用列同时回填 {@code <COL>_DISPLAY__}(复用 {@link UserColumnResolver}),
|
||||||
|
* 让只读 SelectDialog(static)显示姓名/名称而非裸 id。
|
||||||
|
*
|
||||||
|
* <p>契约:{@code GET /api/form/{table}/defaults?templateId={viewPageId}} →
|
||||||
|
* {@code {status:0, msg:"", data:{FORMNO:"...", APPLYNAME:"<uid>", APPLYNAME_DISPLAY__:"姓名[工号]", ...}}}。
|
||||||
|
* 转换器把「添加」dialog 的 service.api 指向本端点(仅新建,不影响「修改」的 {@code _LOAD})。
|
||||||
|
*
|
||||||
|
* <p>纪律:零改 {@code com.dsasp};默认值/编号全走引擎能力,不裸 SQL 生成编号。
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@Tag(name = "表单默认值", description = "B 新建表单 initvalue 宏服务端解析 + AUTOGENERATECODE 流水号")
|
||||||
|
public class FormDefaultsController {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(FormDefaultsController.class);
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
private final CodeRuleService codeRuleService;
|
||||||
|
private final UserColumnResolver userColumnResolver;
|
||||||
|
private final IdentifierWhitelist identifierWhitelist;
|
||||||
|
|
||||||
|
public FormDefaultsController(JdbcTemplate jdbcTemplate,
|
||||||
|
CodeRuleService codeRuleService,
|
||||||
|
UserColumnResolver userColumnResolver,
|
||||||
|
IdentifierWhitelist identifierWhitelist) {
|
||||||
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
this.codeRuleService = codeRuleService;
|
||||||
|
this.userColumnResolver = userColumnResolver;
|
||||||
|
this.identifierWhitelist = identifierWhitelist;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "新建表单默认值(initvalue 宏服务端解析 + 编号生成 + 引用列显示名)",
|
||||||
|
description = "GET /api/form/{table}/defaults?templateId={viewPageId};返回 {status,msg,data:{字段:默认值, 字段_DISPLAY__:显示名}}")
|
||||||
|
@GetMapping("/api/form/{table}/defaults")
|
||||||
|
public ResponseEntity<Map<String, Object>> defaults(
|
||||||
|
@PathVariable String table,
|
||||||
|
@RequestParam(value = "templateId", required = false) String templateId) {
|
||||||
|
|
||||||
|
String t = table.toUpperCase();
|
||||||
|
identifierWhitelist.requireLegalTable(t);
|
||||||
|
|
||||||
|
Map<String, Object> data = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
String xml = (templateId == null || templateId.isBlank()) ? null : queryViewPageXml(templateId.trim());
|
||||||
|
if (xml != null && !xml.isBlank()) {
|
||||||
|
try {
|
||||||
|
Document doc = DocumentHelper.parseText(xml.trim());
|
||||||
|
Element fields = doc.getRootElement().element("fields");
|
||||||
|
if (fields != null) {
|
||||||
|
for (Element f : fields.elements("field")) {
|
||||||
|
String name = f.attributeValue("name");
|
||||||
|
String iv = f.attributeValue("initvalue");
|
||||||
|
if (name == null || name.isBlank() || iv == null || iv.isBlank()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Object resolved = resolveInitValue(t, name, iv, f.attributeValue("format"));
|
||||||
|
if (resolved != null) {
|
||||||
|
data.put(name.toUpperCase(), resolved);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("[FormDefaults] 解析 view_page xml 失败 templateId={}: {}", templateId, e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 引用列(申请人/部门等)补显示值 <COL>_DISPLAY__,让只读 SelectDialog(static) 显示名而非裸 id。
|
||||||
|
if (!data.isEmpty()) {
|
||||||
|
try {
|
||||||
|
List<Map<String, Object>> rows = new ArrayList<>();
|
||||||
|
rows.add(data);
|
||||||
|
userColumnResolver.resolveRows(t, rows);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.debug("[FormDefaults] 引用列显示名解析跳过 table={}: {}", t, e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> resp = new LinkedHashMap<>();
|
||||||
|
resp.put("status", 0);
|
||||||
|
resp.put("msg", "");
|
||||||
|
resp.put("data", data);
|
||||||
|
return ResponseEntity.ok(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析单字段 initvalue:动态宏 {@code {TOKEN}} 走引擎 faithful 求值;静态字面量原样返回;
|
||||||
|
* 未识别 token / 求值失败 → {@code null}(不塞默认值,避免把 token 字面量当初值误显)。
|
||||||
|
*/
|
||||||
|
private Object resolveInitValue(String table, String column, String initvalue, String format) {
|
||||||
|
String v = initvalue.trim();
|
||||||
|
if (!(v.startsWith("{") && v.endsWith("}"))) {
|
||||||
|
return v; // 静态字面默认值
|
||||||
|
}
|
||||||
|
String token = v.substring(1, v.length() - 1).trim().toUpperCase();
|
||||||
|
try {
|
||||||
|
switch (token) {
|
||||||
|
case "CURRENTUSER":
|
||||||
|
return GetDefaultValueFunction.getCurrentUserId();
|
||||||
|
case "CURRENTDEPART":
|
||||||
|
return GetDefaultValueFunction.getCurrentUserDepartId();
|
||||||
|
case "CURRENTORG":
|
||||||
|
return GetDefaultValueFunction.getCurrentUserOrgId();
|
||||||
|
case "CURRENTPROJECT":
|
||||||
|
return GetDefaultValueFunction.getCurrentProjectId();
|
||||||
|
case "CURRENTTIME": {
|
||||||
|
boolean hasTime = format != null && (format.contains("H") || format.contains("m"));
|
||||||
|
String pat = hasTime ? "yyyy-MM-dd HH:mm:ss" : "yyyy-MM-dd";
|
||||||
|
return GetDefaultValueFunction.currentDateTime().toString(DateTimeFormat.forPattern(pat));
|
||||||
|
}
|
||||||
|
case "AUTOGENERATECODE":
|
||||||
|
return codeRuleService.getCode(table, column, new HashMap<>());
|
||||||
|
default:
|
||||||
|
log.debug("[FormDefaults] 未识别 initvalue token {}.{}={} → 跳过", table, column, v);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// CURRENTUSER 等依赖会话;AUTOGENERATECODE 依赖 SYS_CODERULE 规则。任一缺失/异常 → 降级不塞值。
|
||||||
|
log.warn("[FormDefaults] {}.{} 宏 {} 解析失败: {}", table, column, v, e.toString());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String queryViewPageXml(String templateId) {
|
||||||
|
try {
|
||||||
|
List<Map<String, Object>> rows = jdbcTemplate.queryForList(
|
||||||
|
"SELECT xml::text AS xml FROM view_page WHERE view_page_id = ?", templateId);
|
||||||
|
if (!rows.isEmpty()) {
|
||||||
|
Object xml = rows.get(0).get("xml");
|
||||||
|
return xml == null ? null : xml.toString();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.debug("[FormDefaults] 查 view_page xml 失败 templateId={}: {}", templateId, e.toString());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -295,6 +295,15 @@ public class PickerController {
|
|||||||
entityId = root.elements("node").get(0).attributeValue("entityid");
|
entityId = root.elements("node").get(0).attributeValue("entityid");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// tree+grid 选择窗(<tree><treetemplate entityid><gridtemplate entityid>,如用品档案选择):
|
||||||
|
// 可选数据是「网格」(gridtemplate 实体,如 OA_OFFICE_GOODS),非左侧分类树。优先 gridtemplate.entityid,
|
||||||
|
// 回退 treetemplate.entityid。用 //descendant 搜索,容忍嵌套。修「子表选用品 picker 400(非法实体)」。
|
||||||
|
if (entityId == null || entityId.isBlank()) {
|
||||||
|
entityId = firstDescendantEntityId(root, "gridtemplate");
|
||||||
|
}
|
||||||
|
if (entityId == null || entityId.isBlank()) {
|
||||||
|
entityId = firstDescendantEntityId(root, "treetemplate");
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -309,6 +318,19 @@ public class PickerController {
|
|||||||
return tableName != null ? tableName.toString() : null;
|
return tableName != null ? tableName.toString() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 取模板 XML 里第一个 {@code <tag entityid="...">} 的 entityid(descendant 搜索,含嵌套);无则 null。 */
|
||||||
|
private static String firstDescendantEntityId(org.dom4j.Element root, String tag) {
|
||||||
|
for (Object n : root.selectNodes(".//" + tag + "[@entityid]")) {
|
||||||
|
if (n instanceof org.dom4j.Element el) {
|
||||||
|
String eid = el.attributeValue("entityid");
|
||||||
|
if (eid != null && !eid.isBlank()) {
|
||||||
|
return eid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 选用作 label 的「可读标识列」:优先实体声明的显示列({@code isentitydisplay=1},
|
* 选用作 label 的「可读标识列」:优先实体声明的显示列({@code isentitydisplay=1},
|
||||||
* 经 {@link POJOInfo#getDisplayIndex}),回退实体的标识列({@code isidentifier=true}),
|
* 经 {@link POJOInfo#getDisplayIndex}),回退实体的标识列({@code isidentifier=true}),
|
||||||
|
|||||||
@@ -106,7 +106,8 @@ public class TemplateTreeController {
|
|||||||
@RequestParam String rcol,
|
@RequestParam String rcol,
|
||||||
@RequestParam(required = false) String node,
|
@RequestParam(required = false) String node,
|
||||||
@RequestParam(required = false) String page,
|
@RequestParam(required = false) String page,
|
||||||
@RequestParam(required = false) String perPage) {
|
@RequestParam(required = false) String perPage,
|
||||||
|
@RequestParam Map<String, String> allParams) {
|
||||||
if (!IDENT.matcher(gridTable).matches() || !IDENT.matcher(rcol).matches()) {
|
if (!IDENT.matcher(gridTable).matches() || !IDENT.matcher(rcol).matches()) {
|
||||||
Map<String, Object> err = new LinkedHashMap<>();
|
Map<String, Object> err = new LinkedHashMap<>();
|
||||||
err.put("status", 1);
|
err.put("status", 1);
|
||||||
@@ -115,6 +116,19 @@ public class TemplateTreeController {
|
|||||||
return ResponseEntity.badRequest().body(err);
|
return ResponseEntity.badRequest().body(err);
|
||||||
}
|
}
|
||||||
Map<String, Object> body = new HashMap<>();
|
Map<String, Object> body = new HashMap<>();
|
||||||
|
// 查询过滤:转发非保留 query 参数(gridtemplate <search> 字段值,如 NEWTYPE/TITLE)给合成搜索流。
|
||||||
|
// 仅放行列名合法(IDENT 白名单)且非空者,防注入;保留参数不转发;不覆盖 rcol 的子树 IN 过滤。
|
||||||
|
Set<String> reserved = Set.of("treeRef", "gridTable", "rcol", "node", "page", "perPage");
|
||||||
|
for (Map.Entry<String, String> e : allParams.entrySet()) {
|
||||||
|
String k = e.getKey();
|
||||||
|
String v = e.getValue();
|
||||||
|
if (reserved.contains(k) || k.equalsIgnoreCase(rcol) || v == null || v.isBlank()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (IDENT.matcher(k).matches()) {
|
||||||
|
body.put(k, v); // 列名合法 → 作搜索流过滤条件(引擎 get_SearchWhereClause 已转义)
|
||||||
|
}
|
||||||
|
}
|
||||||
if (node != null && !node.isBlank()) {
|
if (node != null && !node.isBlank()) {
|
||||||
List<String> ids;
|
List<String> ids;
|
||||||
try {
|
try {
|
||||||
@@ -133,7 +147,7 @@ public class TemplateTreeController {
|
|||||||
if (perPage != null) {
|
if (perPage != null) {
|
||||||
body.put("perPage", perPage);
|
body.put("perPage", perPage);
|
||||||
}
|
}
|
||||||
return flowController.executePost(gridTable.toUpperCase() + "_SEARCH", body);
|
return flowController.executePost(gridTable.toUpperCase() + "_SEARCH", null, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 解析「点中节点 + 全部后代」的原始 id 列表(供右表 IN 过滤)。节点不在树中(陈旧)→ 退化为仅自身。 */
|
/** 解析「点中节点 + 全部后代」的原始 id 列表(供右表 IN 过滤)。节点不在树中(陈旧)→ 退化为仅自身。 */
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package com.eip4.platform.metadata.script;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A1 单测:用采购申请编辑页真实 editgrid 脚本,端到端验证 {@link EditGridScriptRunner}
|
||||||
|
* 的 Groovy 绑定(getFieldValue/bindField/event/group/group.parent)与类型保真
|
||||||
|
* (AMOUNT=Integer / PRICE=BigDecimal)。脚本零改写经保真层引擎跑通。
|
||||||
|
*/
|
||||||
|
class EditGridScriptRunnerTest {
|
||||||
|
|
||||||
|
// 真实脚本 16b5ead3「根据数量和单价变化计算金额」
|
||||||
|
private static final String SCRIPT_MONEY =
|
||||||
|
"if(getFieldValue(\"AMOUNT\") !=null && getFieldValue(\"PRICE\") !=null){\n"
|
||||||
|
+ " def amout = new BigDecimal(getFieldValue(\"AMOUNT\"));\n"
|
||||||
|
+ " def price = getFieldValue(\"PRICE\");\n"
|
||||||
|
+ " bindField(\"MONEY\",amout.multiply(price));\n"
|
||||||
|
+ "}\n"
|
||||||
|
+ "if(getFieldValue(\"AMOUNT\") ==null || getFieldValue(\"PRICE\") ==null){\n"
|
||||||
|
+ " bindField(\"MONEY\",null);\n"
|
||||||
|
+ "}\n";
|
||||||
|
|
||||||
|
// 真实脚本 f0bbf4ce「计算申请总金额」(金额变 → 汇总主表 applyTotalMoney)
|
||||||
|
private static final String SCRIPT_TOTAL =
|
||||||
|
"def value = event.getProperty().getValue();\n"
|
||||||
|
+ "if(value !=null && value !=\"\"){\n"
|
||||||
|
+ " def total = group.parent.getField(\"applyTotalMoney\");\n"
|
||||||
|
+ " def goodsDetails = group.parent.getField(\"GOODSDETAIL\");\n"
|
||||||
|
+ " def listMap = goodsDetails?.getValue();\n"
|
||||||
|
+ " def totalMoney = new BigDecimal(\"0\");\n"
|
||||||
|
+ " if(listMap != null && listMap.size()>0){\n"
|
||||||
|
+ " listMap?.each{\n"
|
||||||
|
+ " if(it.get('MONEY') !=null && it.get('MONEY') !=\"\"){\n"
|
||||||
|
+ " totalMoney = totalMoney.add(new BigDecimal(it.get('MONEY')))\n"
|
||||||
|
+ " }\n"
|
||||||
|
+ " }\n"
|
||||||
|
+ " }\n"
|
||||||
|
+ " total?.getPropertyDataSource().setReadOnly(false);\n"
|
||||||
|
+ " total?.setReadOnly(false);\n"
|
||||||
|
+ " total?.setValue(totalMoney.toString());\n"
|
||||||
|
+ " total?.getPropertyDataSource().setReadOnly(true);\n"
|
||||||
|
+ " total?.setReadOnly(true);\n"
|
||||||
|
+ "}\n";
|
||||||
|
|
||||||
|
private static final Map<String, String> TYPES = Map.of(
|
||||||
|
"AMOUNT", "java.lang.Integer",
|
||||||
|
"PRICE", "java.math.BigDecimal",
|
||||||
|
"MONEY", "java.math.BigDecimal");
|
||||||
|
|
||||||
|
private static Map<String, Object> map(Object... kv) {
|
||||||
|
Map<String, Object> m = new LinkedHashMap<>();
|
||||||
|
for (int i = 0; i + 1 < kv.length; i += 2) {
|
||||||
|
m.put(String.valueOf(kv[i]), kv[i + 1]);
|
||||||
|
}
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 数量乘单价算金额_类型保真() {
|
||||||
|
// amis 提交:AMOUNT 整数、PRICE 字符串小数(Jackson 落 Integer/String)
|
||||||
|
Map<String, Object> row = map("AMOUNT", 3, "PRICE", "10.5", "MONEY", null);
|
||||||
|
EditGridScriptRunner runner = new EditGridScriptRunner(row, map(), TYPES, "AMOUNT");
|
||||||
|
runner.run("test:money", SCRIPT_MONEY);
|
||||||
|
|
||||||
|
Object money = runner.getRowSetValues().get("MONEY");
|
||||||
|
assertTrue(money instanceof BigDecimal, "MONEY 应为 BigDecimal,实际=" + (money == null ? "null" : money.getClass()));
|
||||||
|
assertEquals(0, new BigDecimal("31.5").compareTo((BigDecimal) money));
|
||||||
|
assertTrue(runner.getParentSetValues().isEmpty(), "行内计算不应改父字段");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 数量为空时金额置空() {
|
||||||
|
Map<String, Object> row = map("AMOUNT", null, "PRICE", "10.5", "MONEY", "99");
|
||||||
|
EditGridScriptRunner runner = new EditGridScriptRunner(row, map(), TYPES, "AMOUNT");
|
||||||
|
runner.run("test:money", SCRIPT_MONEY);
|
||||||
|
assertTrue(runner.getRowSetValues().containsKey("MONEY"));
|
||||||
|
assertNull(runner.getRowSetValues().get("MONEY"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 金额变汇总到主表总金额_跨行聚合() {
|
||||||
|
Map<String, Object> row = map("MONEY", "21.5");
|
||||||
|
Map<String, Object> parent = map(
|
||||||
|
"applyTotalMoney", null,
|
||||||
|
"GOODSDETAIL", List.of(map("MONEY", "10"), map("MONEY", "21.5")));
|
||||||
|
EditGridScriptRunner runner = new EditGridScriptRunner(row, parent, TYPES, "MONEY");
|
||||||
|
runner.run("test:total", SCRIPT_TOTAL);
|
||||||
|
|
||||||
|
// 父字段 applyTotalMoney = 10 + 21.5 = 31.5(脚本以 toString 写)
|
||||||
|
assertEquals("31.5", runner.getParentSetValues().get("applyTotalMoney"));
|
||||||
|
assertTrue(runner.getRowSetValues().isEmpty(), "汇总只改父字段,不改当前行");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -118,7 +118,7 @@ class FlowControllerTest {
|
|||||||
|
|
||||||
Map<String, Object> body = new HashMap<>();
|
Map<String, Object> body = new HashMap<>();
|
||||||
body.put("sql", "select 1");
|
body.put("sql", "select 1");
|
||||||
controller.executePost(flowId, body);
|
controller.executePost(flowId, null, body);
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
ArgumentCaptor<Map<String, Object>> mapCap = ArgumentCaptor.forClass(Map.class);
|
ArgumentCaptor<Map<String, Object>> mapCap = ArgumentCaptor.forClass(Map.class);
|
||||||
@@ -134,7 +134,7 @@ class FlowControllerTest {
|
|||||||
when(engine.excute(any(), any(), any())).thenReturn(null);
|
when(engine.excute(any(), any(), any())).thenReturn(null);
|
||||||
FlowController controller = new FlowController(engine, resolverReturning(flowId, uuidPassthrough()));
|
FlowController controller = new FlowController(engine, resolverReturning(flowId, uuidPassthrough()));
|
||||||
|
|
||||||
ResponseEntity<Map<String, Object>> resp = controller.executePost(flowId, null);
|
ResponseEntity<Map<String, Object>> resp = controller.executePost(flowId, null, null);
|
||||||
assertEquals(HttpStatus.OK, resp.getStatusCode());
|
assertEquals(HttpStatus.OK, resp.getStatusCode());
|
||||||
assertEquals(0, resp.getBody().get("status"));
|
assertEquals(0, resp.getBody().get("status"));
|
||||||
}
|
}
|
||||||
@@ -524,7 +524,7 @@ class FlowControllerTest {
|
|||||||
|
|
||||||
Map<String, Object> body = new HashMap<>();
|
Map<String, Object> body = new HashMap<>();
|
||||||
body.put("TITLE", "新通知");
|
body.put("TITLE", "新通知");
|
||||||
ResponseEntity<Map<String, Object>> resp = controller.executePost(flowId, body);
|
ResponseEntity<Map<String, Object>> resp = controller.executePost(flowId, null, body);
|
||||||
|
|
||||||
assertEquals(HttpStatus.OK, resp.getStatusCode());
|
assertEquals(HttpStatus.OK, resp.getStatusCode());
|
||||||
assertEquals(0, resp.getBody().get("status"));
|
assertEquals(0, resp.getBody().get("status"));
|
||||||
@@ -556,7 +556,7 @@ class FlowControllerTest {
|
|||||||
|
|
||||||
Map<String, Object> body = new HashMap<>();
|
Map<String, Object> body = new HashMap<>();
|
||||||
body.put("ids", "id-a,id-b"); // amis bulkActions 契约:选中行主键逗号串
|
body.put("ids", "id-a,id-b"); // amis bulkActions 契约:选中行主键逗号串
|
||||||
ResponseEntity<Map<String, Object>> resp = controller.executePost(flowId, body);
|
ResponseEntity<Map<String, Object>> resp = controller.executePost(flowId, null, body);
|
||||||
|
|
||||||
assertEquals(HttpStatus.OK, resp.getStatusCode());
|
assertEquals(HttpStatus.OK, resp.getStatusCode());
|
||||||
assertEquals(0, resp.getBody().get("status"));
|
assertEquals(0, resp.getBody().get("status"));
|
||||||
@@ -597,7 +597,7 @@ class FlowControllerTest {
|
|||||||
|
|
||||||
Map<String, Object> body = new HashMap<>();
|
Map<String, Object> body = new HashMap<>();
|
||||||
body.put("ids", "id-a,id-b,id-c"); // 多选 3 行主键逗号串(C1 修正后删除按钮只送此键)
|
body.put("ids", "id-a,id-b,id-c"); // 多选 3 行主键逗号串(C1 修正后删除按钮只送此键)
|
||||||
ResponseEntity<Map<String, Object>> resp = controller.executePost(flowId, body);
|
ResponseEntity<Map<String, Object>> resp = controller.executePost(flowId, null, body);
|
||||||
|
|
||||||
assertEquals(HttpStatus.OK, resp.getStatusCode());
|
assertEquals(HttpStatus.OK, resp.getStatusCode());
|
||||||
assertEquals(0, resp.getBody().get("status"));
|
assertEquals(0, resp.getBody().get("status"));
|
||||||
@@ -635,7 +635,7 @@ class FlowControllerTest {
|
|||||||
|
|
||||||
Map<String, Object> body = new HashMap<>();
|
Map<String, Object> body = new HashMap<>();
|
||||||
body.put("ids", "id-a,id-b");
|
body.put("ids", "id-a,id-b");
|
||||||
controller.executePost(flowId, body);
|
controller.executePost(flowId, null, body);
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
ArgumentCaptor<Map<String, Object>> mapCap = ArgumentCaptor.forClass(Map.class);
|
ArgumentCaptor<Map<String, Object>> mapCap = ArgumentCaptor.forClass(Map.class);
|
||||||
@@ -657,7 +657,7 @@ class FlowControllerTest {
|
|||||||
us.when(UserSession::get).thenReturn(null);
|
us.when(UserSession::get).thenReturn(null);
|
||||||
us.when(UserSession::getAdmin).thenReturn(adminCtx());
|
us.when(UserSession::getAdmin).thenReturn(adminCtx());
|
||||||
|
|
||||||
ResponseEntity<Map<String, Object>> resp = controller.executePost(flowId, new HashMap<>());
|
ResponseEntity<Map<String, Object>> resp = controller.executePost(flowId, null, new HashMap<String, Object>());
|
||||||
assertEquals(HttpStatus.OK, resp.getStatusCode());
|
assertEquals(HttpStatus.OK, resp.getStatusCode());
|
||||||
org.mockito.Mockito.verify(engine).excute(any(), any(Properties.class), eq(flowId));
|
org.mockito.Mockito.verify(engine).excute(any(), any(Properties.class), eq(flowId));
|
||||||
}
|
}
|
||||||
@@ -723,7 +723,7 @@ class FlowControllerTest {
|
|||||||
FlowController controller = new FlowController(engine,
|
FlowController controller = new FlowController(engine,
|
||||||
resolverReturning(flowId, uuidPassthrough()), null, classifier);
|
resolverReturning(flowId, uuidPassthrough()), null, classifier);
|
||||||
|
|
||||||
ResponseEntity<Map<String, Object>> resp = controller.executePost(flowId, new HashMap<>());
|
ResponseEntity<Map<String, Object>> resp = controller.executePost(flowId, null, new HashMap<String, Object>());
|
||||||
assertEquals(HttpStatus.OK, resp.getStatusCode());
|
assertEquals(HttpStatus.OK, resp.getStatusCode());
|
||||||
org.mockito.Mockito.verify(engine).excute(any(), any(), eq(flowId));
|
org.mockito.Mockito.verify(engine).excute(any(), any(), eq(flowId));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,30 +123,51 @@ class TemplateTreeControllerTest {
|
|||||||
@DisplayName("treegrid 端点:点父级 → 以 List(子树 id) 委托 _SEARCH(引擎构 IN)+ 透传分页")
|
@DisplayName("treegrid 端点:点父级 → 以 List(子树 id) 委托 _SEARCH(引擎构 IN)+ 透传分页")
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void treeGrid_子树IN委托() {
|
void treeGrid_子树IN委托() {
|
||||||
when(flow.executePost(eq("OA_KNOWLEDGE_FILE_SEARCH"), any()))
|
when(flow.executePost(eq("OA_KNOWLEDGE_FILE_SEARCH"), any(), any()))
|
||||||
.thenReturn(ResponseEntity.ok(Map.of("status", 0)));
|
.thenReturn(ResponseEntity.ok(Map.of("status", 0)));
|
||||||
|
|
||||||
controller.treeGrid(TREE_REF, "OA_KNOWLEDGE_FILE", "FOLDERID", "P1", "2", "10");
|
controller.treeGrid(TREE_REF, "OA_KNOWLEDGE_FILE", "FOLDERID", "P1", "2", "10", Map.of());
|
||||||
|
|
||||||
ArgumentCaptor<Map<String, Object>> cap = ArgumentCaptor.forClass(Map.class);
|
ArgumentCaptor<Map<String, Object>> cap = ArgumentCaptor.forClass(Map.class);
|
||||||
verify(flow).executePost(eq("OA_KNOWLEDGE_FILE_SEARCH"), cap.capture());
|
verify(flow).executePost(eq("OA_KNOWLEDGE_FILE_SEARCH"), any(), cap.capture());
|
||||||
Map<String, Object> body = cap.getValue();
|
Map<String, Object> body = cap.getValue();
|
||||||
assertEquals(List.of("P1", "C1", "C2"), body.get("FOLDERID"), "rcol 须为子树 id 列表(List→引擎 IN)");
|
assertEquals(List.of("P1", "C1", "C2"), body.get("FOLDERID"), "rcol 须为子树 id 列表(List→引擎 IN)");
|
||||||
assertEquals("2", body.get("page"));
|
assertEquals("2", body.get("page"));
|
||||||
assertEquals("10", body.get("perPage"));
|
assertEquals("10", body.get("perPage"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("treegrid 端点:查询过滤参数透传给搜索流(IDENT 白名单),非法列名跳过")
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void treeGrid_过滤参数透传() {
|
||||||
|
when(flow.executePost(eq("OA_KNOWLEDGE_FILE_SEARCH"), any(), any()))
|
||||||
|
.thenReturn(ResponseEntity.ok(Map.of("status", 0)));
|
||||||
|
java.util.Map<String, String> params = new java.util.HashMap<>();
|
||||||
|
params.put("treeRef", TREE_REF); // 保留参数 → 不转发
|
||||||
|
params.put("gridTable", "OA_KNOWLEDGE_FILE");
|
||||||
|
params.put("TITLE", "年度"); // 合法过滤列 → 转发
|
||||||
|
params.put("BAD COL;", "x"); // 非法列名 → 跳过(防注入)
|
||||||
|
controller.treeGrid(TREE_REF, "OA_KNOWLEDGE_FILE", "FOLDERID", "", "1", "10", params);
|
||||||
|
|
||||||
|
ArgumentCaptor<Map<String, Object>> cap = ArgumentCaptor.forClass(Map.class);
|
||||||
|
verify(flow).executePost(eq("OA_KNOWLEDGE_FILE_SEARCH"), any(), cap.capture());
|
||||||
|
Map<String, Object> body = cap.getValue();
|
||||||
|
assertEquals("年度", body.get("TITLE"), "合法过滤列须透传给搜索流");
|
||||||
|
assertFalse(body.containsKey("BAD COL;"), "非法列名不进引擎拼接(防注入)");
|
||||||
|
assertFalse(body.containsKey("treeRef"), "保留参数不作过滤条件");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("treegrid 端点:空 node(未选中) → 不带 rcol 过滤(返回全部) + 仍透传分页")
|
@DisplayName("treegrid 端点:空 node(未选中) → 不带 rcol 过滤(返回全部) + 仍透传分页")
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void treeGrid_空node返全部() {
|
void treeGrid_空node返全部() {
|
||||||
when(flow.executePost(eq("OA_KNOWLEDGE_FILE_SEARCH"), any()))
|
when(flow.executePost(eq("OA_KNOWLEDGE_FILE_SEARCH"), any(), any()))
|
||||||
.thenReturn(ResponseEntity.ok(Map.of("status", 0)));
|
.thenReturn(ResponseEntity.ok(Map.of("status", 0)));
|
||||||
|
|
||||||
controller.treeGrid(TREE_REF, "OA_KNOWLEDGE_FILE", "FOLDERID", "", "1", "10");
|
controller.treeGrid(TREE_REF, "OA_KNOWLEDGE_FILE", "FOLDERID", "", "1", "10", Map.of());
|
||||||
|
|
||||||
ArgumentCaptor<Map<String, Object>> cap = ArgumentCaptor.forClass(Map.class);
|
ArgumentCaptor<Map<String, Object>> cap = ArgumentCaptor.forClass(Map.class);
|
||||||
verify(flow).executePost(eq("OA_KNOWLEDGE_FILE_SEARCH"), cap.capture());
|
verify(flow).executePost(eq("OA_KNOWLEDGE_FILE_SEARCH"), any(), cap.capture());
|
||||||
Map<String, Object> body = cap.getValue();
|
Map<String, Object> body = cap.getValue();
|
||||||
assertFalse(body.containsKey("FOLDERID"), "未选中不应带 rcol 过滤");
|
assertFalse(body.containsKey("FOLDERID"), "未选中不应带 rcol 过滤");
|
||||||
assertEquals("1", body.get("page"));
|
assertEquals("1", body.get("page"));
|
||||||
@@ -156,13 +177,13 @@ class TemplateTreeControllerTest {
|
|||||||
@DisplayName("treegrid 端点:非法表名/列名 → 400,不触达引擎")
|
@DisplayName("treegrid 端点:非法表名/列名 → 400,不触达引擎")
|
||||||
void treeGrid_IDENT守卫() {
|
void treeGrid_IDENT守卫() {
|
||||||
ResponseEntity<Map<String, Object>> resp =
|
ResponseEntity<Map<String, Object>> resp =
|
||||||
controller.treeGrid(TREE_REF, "BAD TABLE;DROP", "FOLDERID", "P1", "1", "10");
|
controller.treeGrid(TREE_REF, "BAD TABLE;DROP", "FOLDERID", "P1", "1", "10", Map.of());
|
||||||
assertTrue(resp.getStatusCode().is4xxClientError());
|
assertTrue(resp.getStatusCode().is4xxClientError());
|
||||||
verify(flow, never()).executePost(anyString(), any());
|
verify(flow, never()).executePost(anyString(), any(), any());
|
||||||
|
|
||||||
ResponseEntity<Map<String, Object>> resp2 =
|
ResponseEntity<Map<String, Object>> resp2 =
|
||||||
controller.treeGrid(TREE_REF, "OA_KNOWLEDGE_FILE", "FOLDER ID--", "P1", "1", "10");
|
controller.treeGrid(TREE_REF, "OA_KNOWLEDGE_FILE", "FOLDER ID--", "P1", "1", "10", Map.of());
|
||||||
assertTrue(resp2.getStatusCode().is4xxClientError());
|
assertTrue(resp2.getStatusCode().is4xxClientError());
|
||||||
verify(flow, never()).executePost(anyString(), any());
|
verify(flow, never()).executePost(anyString(), any(), any());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user