fix framework treegrid search and formeditgrid editors

This commit is contained in:
2026-06-18 16:35:51 +08:00
parent b6e6964913
commit d218c2ba6f
6 changed files with 493 additions and 28 deletions

View File

@@ -106,21 +106,24 @@ public class FlowInputCoercer {
applyCoerce(map, colTypes);
}
/**
* 读流(SEARCH)日期 coerce:<b>仅</b>把 DATE/TIME 列的 String 值转 {@code DateTime}/{@code DateTime[]}。
*
* <p>amis {@code input-date(time)-range} 把时间段提交为 "起,止" 逗号串,但引擎 GeneralPO 的搜索 where
* 构建只对 {@code DateTime[]} 值生成区间条件 {@code (col>=起 AND col<=止)}——收到 String 则识别不了,
* 整条时间段过滤被忽略(操作日志等"时间段查不动"根因)。本方法把日期列值转成引擎期望形态。
*
* <p><b>只碰 DATE/TIME 列</b>,其它过滤参(文本/枚举/picker)一概不动 → 对已工作的搜索零回归。fail-safe:
* 无表名/查元数据失败/parse 失败 → 原值保留。供 {@code FlowController} 命名读流(NAMED_READ)路径调用。
*/
/** 兼容旧调用名;实际已扩展为搜索值类型 coerce(日期 + BOOLEAN/ENUMERATE/数字等)。 */
public void coerceSearchDatesByFlowId(String flowId, Map<String, Object> map) {
coerceSearchValuesByFlowId(flowId, map);
}
/**
* 读流(SEARCH)值 coerce:把查询表单提交的 String 转成引擎按元数据期望的 Java 类型。
*
* <p>覆盖两类已验证问题:DATE/TIME 区间字符串须转 {@code DateTime[]},BOOLEAN 的 "0/1/false/true"
* 须转 {@code Boolean}。否则引擎 {@code GeneralPO} 搜索 where 构建会忽略条件,表现为“选择了也查不动”。
*
* <p>不同于写路径,本方法不做空串转 null,也不扁平化 picker 对象;只处理已有 String 标量,失败保留原值。
*/
public void coerceSearchValuesByFlowId(String flowId, Map<String, Object> map) {
if (flowId == null || flowId.isBlank() || map == null || map.isEmpty()) {
return;
}
coerceDatesOnly(map, flowTableCache.get(flowId, this::resolveTableNameByFlowId));
coerceSearchValues(map, flowTableCache.get(flowId, this::resolveTableNameByFlowId));
}
/**
@@ -128,14 +131,19 @@ public class FlowInputCoercer {
* 表名由 key 剥后缀推得({@code FlowController} SYNTHESIZED 路径用)。
*/
public void coerceSearchDatesByTable(String tableName, Map<String, Object> map) {
coerceSearchValuesByTable(tableName, map);
}
/** 同 {@link #coerceSearchValuesByFlowId},但表名直接给定。 */
public void coerceSearchValuesByTable(String tableName, Map<String, Object> map) {
if (map == null || map.isEmpty()) {
return;
}
coerceDatesOnly(map, tableName);
coerceSearchValues(map, tableName);
}
/** 就地:只对 {@code tableName} 里 DATE/TIME 列的 String 值做日期/区间 coerce,其余键不动。 */
private void coerceDatesOnly(Map<String, Object> map, String tableName) {
/** 就地:按 {@code tableName} 的列元数据对 String 查询值做 fail-safe coerce。 */
private void coerceSearchValues(Map<String, Object> map, String tableName) {
if (tableName == null || tableName.isEmpty()) {
return;
}
@@ -148,7 +156,7 @@ public class FlowInputCoercer {
continue;
}
String refId = colTypes.get(entry.getKey().toUpperCase());
if ("DATE".equals(refId) || "TIME".equals(refId)) {
if (refId != null) {
Object coerced = coerceValue(s, refId, entry.getKey());
if (coerced != entry.getValue()) {
entry.setValue(coerced);

View File

@@ -273,6 +273,28 @@ class FlowInputCoercerTest {
assertEquals(Boolean.TRUE, map.get("ISACTIVE"), "BOOLEAN String→Boolean");
}
@Test
@DisplayName("coerceSearchValuesByTable: 搜索条件按列元数据转换 BOOLEAN,文本保持原值")
void coerceSearchValuesByTableBoolean() {
when(jdbc.queryForList(anyString(), eq("SYS_SERVICEFLOW")))
.thenReturn(List.of(
Map.of("col", "ISCONTROL", "ref", "BOOLEAN"),
Map.of("col", "ISUPDATEABLE", "ref", "BOOLEAN"),
Map.of("col", "DISPLAYNAME", "ref", "NVARCHAR")
));
Map<String, Object> map = new HashMap<>();
map.put("ISCONTROL", "0");
map.put("ISUPDATEABLE", "1");
map.put("DISPLAYNAME", "项目");
coercer.coerceSearchValuesByTable("SYS_SERVICEFLOW", map);
assertEquals(Boolean.FALSE, map.get("ISCONTROL"));
assertEquals(Boolean.TRUE, map.get("ISUPDATEABLE"));
assertEquals("项目", map.get("DISPLAYNAME"));
}
@Test
@DisplayName("coerce: 值已是 Integer(非 String),幂等不重复转换")
void coerceIdempotent() {