修复列表页两 bug:空结果集崩溃 + ComboBox 枚举下拉空数据(用户报「加班登记」)
【bug1 空结果集列表崩溃】凡 0 行的列表页报「data.items 必须是数组」(amis CRUD)。
根因:引擎对空查询结果省略 listresult 键、仅返 {result:{pagecount:0}};FlowController.normalize
只在含 listresult 时拍平为 {items,total},空集落入通用分支 → data.items 缺失 → amis 崩。
修:normalize 触发条件加 PAGE_COUNT——含 pagecount 即视为分页查询,listresult 缺省→空 items、
pagecount→total。新增 FlowControllerTest「5b 空结果集归一化」。影响全部 0 行列表页。
【bug2 ComboBox 枚举下拉空数据】「加班类型」等下拉无选项(51 模板)。
根因:ComboBox 字段 comboboxid="" 空但 itemisenumerate="true"(选项来自列的 enumeratetype),
转换器只认 comboboxid → 生成无 source 空 select。对照:OVERTIMESTATE comboboxid=HR_HOLIDAYSTATUS
显式填了枚举类型故正常。修:UiTypeMapper.mapField 加 colMeta 入参,ComboBox 缺 comboboxid 且
itemisenumerate 时取列 enumeratetype 作 /api/poc/dict/{enumeratetype} 源;buildSearchFilter/
convertForm 经 loadColumnMeta 注入 colMeta。新增转换器测「ComboBox 缺 comboboxid 取列枚举字典」。
分级清单.csv 随重批(无枚举元数据的空 ComboBox 改记诚实降级)。
验证:converter 58 测 + FlowController 26 测 + 全模块测过;运行时 HR_OVERTIMEAPPLY_SEARCHPASS
返 {items:[],total:0};/api/poc/dict/HR_CHECKATTENDANCESTATE 返加班类型枚举;
浏览器加班登记页无报错 + 加班类型下拉出「正常/迟到/早退/旷工/年假…」。已重转+重导入 sys_page_schema 上线。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -126,7 +126,7 @@ public class TemplateToAmisConverter {
|
||||
// F2-16:传 entityId 以便 buildColumns 查列元数据注入渲染映射
|
||||
List<Map<String, Object>> columns = display != null ? buildColumns(display, entityId, result) : new ArrayList<>();
|
||||
|
||||
Map<String, Object> filter = buildSearchFilter(crud.element("search"), result);
|
||||
Map<String, Object> filter = buildSearchFilter(crud.element("search"), result, entityId);
|
||||
List<Map<String, Object>> bulkActions = new ArrayList<>();
|
||||
List<Object> toolbar = buildToolbar(collectButtons(crud), table, entityId, bulkActions, result);
|
||||
|
||||
@@ -344,8 +344,8 @@ public class TemplateToAmisConverter {
|
||||
}
|
||||
|
||||
/** search/field → filter 表单(uitype 映射经 UiTypeMapper 统一)。 */
|
||||
private Map<String, Object> buildSearchFilter(Element search, ConversionResult result) {
|
||||
return buildSearchFilter(search, result, false);
|
||||
private Map<String, Object> buildSearchFilter(Element search, ConversionResult result, String entityId) {
|
||||
return buildSearchFilter(search, result, false, entityId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -362,10 +362,12 @@ public class TemplateToAmisConverter {
|
||||
* @param skipKeyFields {@code true} 时启用过滤(report 路径),{@code false} 保持原行为(crud/form 路径)
|
||||
*/
|
||||
private Map<String, Object> buildSearchFilter(Element search, ConversionResult result,
|
||||
boolean skipKeyFields) {
|
||||
boolean skipKeyFields, String entityId) {
|
||||
if (search == null || search.elements("field").isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// 列元数据(含 enumeratetype):供 ComboBox 缺省 comboboxid 但 itemisenumerate=true 时取枚举字典源
|
||||
Map<String, String[]> colMeta = loadColumnMeta(entityId, result);
|
||||
List<Map<String, Object>> items = new ArrayList<>();
|
||||
for (Element f : search.elements("field")) {
|
||||
if (skipKeyFields && isSearchKeyField(f)) {
|
||||
@@ -373,7 +375,7 @@ public class TemplateToAmisConverter {
|
||||
+ " 识别为主键列(designName/label=主键 或 _ID 结尾长名) → 跳过查询区(F3-1)");
|
||||
continue;
|
||||
}
|
||||
items.add(UiTypeMapper.mapField(f, result, "search"));
|
||||
items.add(UiTypeMapper.mapField(f, result, "search", colMeta));
|
||||
}
|
||||
if (items.isEmpty()) {
|
||||
return null;
|
||||
@@ -725,8 +727,10 @@ public class TemplateToAmisConverter {
|
||||
Document pageDoc = DocumentHelper.parseText(pageXml);
|
||||
Element fields = pageDoc.getRootElement().element("fields");
|
||||
if (fields != null) {
|
||||
// 列元数据(含 enumeratetype):供 ComboBox 缺省 comboboxid 但 itemisenumerate=true 取枚举字典源
|
||||
Map<String, String[]> colMeta = loadColumnMeta(entityId, result);
|
||||
for (Element f : fields.elements("field")) {
|
||||
formItems.add(UiTypeMapper.mapField(f, result, "editform"));
|
||||
formItems.add(UiTypeMapper.mapField(f, result, "editform", colMeta));
|
||||
}
|
||||
result.note("form@pageid=" + pageId + " → 解析 view_page 取得 " + formItems.size() + " 字段");
|
||||
}
|
||||
@@ -967,7 +971,7 @@ public class TemplateToAmisConverter {
|
||||
|
||||
// search → filter(报表查询参数,F3-1:过滤主键列),selectservice → api
|
||||
Element search = report.element("search");
|
||||
Map<String, Object> filter = buildSearchFilter(search, result, true);
|
||||
Map<String, Object> filter = buildSearchFilter(search, result, true, entityId);
|
||||
String selectservice = attrOf(search, "selectservice");
|
||||
|
||||
Map<String, Object> crudSchema = new LinkedHashMap<>();
|
||||
|
||||
@@ -34,6 +34,16 @@ final class UiTypeMapper {
|
||||
* @return amis 表单项
|
||||
*/
|
||||
static Map<String, Object> mapField(Element f, ConversionResult result, String origin) {
|
||||
return mapField(f, result, origin, java.util.Map.of());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param colMeta 实体列元数据 {@code UPPER(列名) → [referenceid, enumeratetype]}(来自
|
||||
* SYS_ENTITYATTRIBUTE,由转换器 loadColumnMeta 提供);用于 ComboBox 缺省 comboboxid
|
||||
* 但 {@code itemisenumerate=true} 时回落取列的 enumeratetype 作字典源。空 map 时退化为旧行为。
|
||||
*/
|
||||
static Map<String, Object> mapField(Element f, ConversionResult result, String origin,
|
||||
Map<String, String[]> colMeta) {
|
||||
String name = f.attributeValue("name", "");
|
||||
String uitype = f.attributeValue("uitype", "TextField");
|
||||
// label 优先用 label 属性,回退 text(display 段用 text)、再回退 name
|
||||
@@ -98,12 +108,22 @@ final class UiTypeMapper {
|
||||
item.put("clearable", true);
|
||||
String dict = firstNonBlank(f.attributeValue("comboboxid"),
|
||||
f.attributeValue("comboboxitemservice"), "");
|
||||
// comboboxid 缺省但 itemisenumerate=true → 选项取该列的 enumeratetype 枚举字典
|
||||
// (与显式 comboboxid=枚举类型 的字段同口径,如 OVERTIMESTATE comboboxid=HR_HOLIDAYSTATUS)。
|
||||
// enumeratetype 来自 SYS_ENTITYATTRIBUTE(colMeta[列名][1])。修复 51 模板「枚举下拉空数据」。
|
||||
if (dict.isBlank() && "true".equals(f.attributeValue("itemisenumerate"))) {
|
||||
String[] meta = colMeta.get(name.toUpperCase());
|
||||
if (meta != null && meta.length > 1 && meta[1] != null && !meta[1].isBlank()) {
|
||||
dict = meta[1].trim();
|
||||
}
|
||||
}
|
||||
if (!dict.isBlank()) {
|
||||
item.put("source", "/api/poc/dict/" + dict);
|
||||
result.note(origin + "@field " + name + " uitype=ComboBox(comboboxid=" + dict
|
||||
+ ") → select + source 字典接口(接口待实现)");
|
||||
result.note(origin + "@field " + name + " uitype=ComboBox(dict=" + dict
|
||||
+ ") → select + source 字典接口 /api/poc/dict");
|
||||
} else {
|
||||
result.note(origin + "@field " + name + " uitype=ComboBox(无字典源) → 空 select");
|
||||
result.degrade(origin + "@field " + name
|
||||
+ " uitype=ComboBox(无 comboboxid 且非枚举/列元数据缺失) → 空 select(选项源无法解析)");
|
||||
}
|
||||
}
|
||||
case "PopupDateField" -> {
|
||||
|
||||
Reference in New Issue
Block a user