fix(converter): NumberField 整型列优先于 mdec(整数输入不显小数)
字段 type=java.lang.Integer/Long/Short/BigInteger 时即便 XML 误定义 mdec 小数位(如排序号 TYPESORT type=Integer 却 mdec=2,旧版显「2.00」),也应整数输入 precision=0+step=1;非整型(Double/BigDecimal)才按 mdec 取小数精度。live 验证:新闻收藏分类 默认类别 排序号显「1」非「1.00」。118 测试绿(+整型/Double 对照单测)。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -104,7 +104,17 @@ final class UiTypeMapper {
|
|||||||
case "NumberField" -> {
|
case "NumberField" -> {
|
||||||
item.put("type", "input-number");
|
item.put("type", "input-number");
|
||||||
String mdec = f.attributeValue("mdec");
|
String mdec = f.attributeValue("mdec");
|
||||||
if (mdec != null && !mdec.isBlank()) {
|
// 列类型优先于 mdec:整型列(java.lang.Integer/Long/Short/BigInteger 等)即便 XML 误定义
|
||||||
|
// mdec 小数位(如排序号 TYPESORT type=java.lang.Integer 却 mdec=2 → 旧版显「2.00」),也应整数输入
|
||||||
|
// (precision=0 + step=1),不显小数。非整型(Double/BigDecimal)才按 mdec 取小数精度。
|
||||||
|
String numType = f.attributeValue("type");
|
||||||
|
boolean isInteger = numType != null && (numType.endsWith(".Integer") || numType.endsWith(".Long")
|
||||||
|
|| numType.endsWith(".Short") || numType.endsWith(".BigInteger")
|
||||||
|
|| "int".equals(numType) || "long".equals(numType) || "short".equals(numType));
|
||||||
|
if (isInteger) {
|
||||||
|
item.put("precision", 0);
|
||||||
|
item.put("step", 1);
|
||||||
|
} else if (mdec != null && !mdec.isBlank()) {
|
||||||
try {
|
try {
|
||||||
item.put("precision", Integer.parseInt(mdec));
|
item.put("precision", Integer.parseInt(mdec));
|
||||||
} catch (NumberFormatException ignore) {
|
} catch (NumberFormatException ignore) {
|
||||||
@@ -115,7 +125,8 @@ final class UiTypeMapper {
|
|||||||
// 如采购明细 AMOUNT vmin=1 / PRICE vmax=9999999.99)。非数值则跳过(容错口径同 mdec)。
|
// 如采购明细 AMOUNT vmin=1 / PRICE vmax=9999999.99)。非数值则跳过(容错口径同 mdec)。
|
||||||
applyNumberBound(item, "min", f.attributeValue("vmin"));
|
applyNumberBound(item, "min", f.attributeValue("vmin"));
|
||||||
applyNumberBound(item, "max", f.attributeValue("vmax"));
|
applyNumberBound(item, "max", f.attributeValue("vmax"));
|
||||||
result.note(origin + "@field " + name + " uitype=NumberField → input-number(precision=" + mdec
|
result.note(origin + "@field " + name + " uitype=NumberField → input-number(type=" + numType
|
||||||
|
+ (isInteger ? ", 整型 precision=0" : ", precision=" + mdec)
|
||||||
+ ", min=" + f.attributeValue("vmin") + ", max=" + f.attributeValue("vmax") + ")");
|
+ ", min=" + f.attributeValue("vmin") + ", max=" + f.attributeValue("vmax") + ")");
|
||||||
}
|
}
|
||||||
case "CheckBox" -> {
|
case "CheckBox" -> {
|
||||||
|
|||||||
@@ -111,6 +111,24 @@ class TemplateToAmisConverterTest {
|
|||||||
assertEquals(9999999.99, items.get(4).get("max"));
|
assertEquals(9999999.99, items.get(4).get("max"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void numberField_整型列优先_忽略mdec小数位() {
|
||||||
|
// 列类型 java.lang.Integer 即便 XML 误定义 mdec=2(如排序号 TYPESORT),也应整数输入(precision=0+step=1),不显「2.00」
|
||||||
|
String xml = "<crud entityid='e1'><display/><search>"
|
||||||
|
+ "<field name='SORT' label='排序号' uitype='NumberField' type='java.lang.Integer' mdec='2'/>"
|
||||||
|
+ "<field name='MONEY' label='金额' uitype='NumberField' type='java.lang.Double' mdec='2'/>"
|
||||||
|
+ "</search></crud>";
|
||||||
|
ConversionResult r = converter.convertGraded(xml, new ArrayList<>(), noPage);
|
||||||
|
Map<String, Object> crud = body(r.getSchema());
|
||||||
|
List<Map<String, Object>> items = (List<Map<String, Object>>) ((Map<String, Object>) crud.get("filter")).get("body");
|
||||||
|
// 整型:precision=0 + step=1(覆盖 mdec=2)
|
||||||
|
assertEquals(0, items.get(0).get("precision"), "整型列应 precision=0 覆盖 mdec");
|
||||||
|
assertEquals(1, items.get(0).get("step"));
|
||||||
|
// 非整型(Double):仍按 mdec=2
|
||||||
|
assertEquals(2, items.get(1).get("precision"), "Double 列按 mdec 取小数精度");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修复(dogfooding):ComboBox 的 comboboxitemservice(查表的列表服务,非静态枚举)应指向
|
* 修复(dogfooding):ComboBox 的 comboboxitemservice(查表的列表服务,非静态枚举)应指向
|
||||||
* picker 选项端点而非 /api/poc/dict(后者仅认 SYS_ENUMERATE → 选项恒空)。合成搜索流 <TABLE>_SEARCH
|
* picker 选项端点而非 /api/poc/dict(后者仅认 SYS_ENUMERATE → 选项恒空)。合成搜索流 <TABLE>_SEARCH
|
||||||
|
|||||||
Reference in New Issue
Block a user