feat(WS-D): 查看页附件只读下载列表 + 用户引用列(发布人)显示名
D.2 附件查看下载列表(对齐老系统):
- 附件按 sys_doc.tablename+businesskey 关联业务记录(非物理列),老
MultiFileUploadField→input-file 在只读查看态渲染空上传按钮、不显已有附件。
- FileController 新增 GET /api/file/list(按 tableName+businessKey 列 sys_doc),
返回 {status,data:{items:[{id,name,size,sizeKb,url}]}};空业务键不查库防全表扫。
- 转换器 enrichAttachmentFields:把附件字段(input-file)就地包成 service 容器——
api 按业务主键 ${<TABLE>_ID} 拉 /api/file/list,each 渲染已有附件下载链接
(文件名(大小KB)+/api/file/${id}),并保留上传控件(编辑态加附件)。
service 纳入 isWideField(独占整行)。convertViewPage/convertForm 均接入。
D.3 用户引用列(发布人)显示名:
- 根因:查看新闻列表走命名读流 OA_NEWSMANAGE_SEARCH_LOOK,FlowController
NAMED_READ 分支此前 table=null 跳过 UserColumnResolver→USERSEND_ID_DISPLAY__
不填→发布人显「-」。USERSEND_ID 本就是 SYS_USER 引用,解析器口径无误。
- FlowNameResolver 新增 entityTableForNamedFlow(经 sys_serviceflow.entityid→
sys_entity.tablename 解析命名读流数据源实体表,缓存+失败哨兵);FlowController
NAMED_READ 分支据此传 table 给 ok(...),解析器补出 _DISPLAY__ 显示名。
测试:
- TemplateToAmisConverterTest 92 绿(改 3 既有附件断言+新增查看态下载列表断言)。
- FlowControllerTest 29 绿(#16 改命名读流解析不到表跳过,#16b 新增命名读流
解析出表→发布人 id→姓名)。FileControllerTest 4 绿(list/空键/空集/小文件KB)。
实证(8093 live + 5173 playwright):查看新闻列表发布人显 顾竟蓝[000031]/
李文娟[000010]/沈波恩[000008](非「-」);查看含附件新闻→附件下载列表显
文件名+KB+下载链(3 项),真实文件下载 200+attachment;console 0 错。
全量重转(保 onEvent 501)+SchemaImportCli upsert 1163,JDK21。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -848,6 +848,9 @@ public class TemplateToAmisConverter {
|
||||
}
|
||||
noteFormScripts(form, result);
|
||||
|
||||
// WS-D D.2:附件字段(input-file)增配查看态只读下载列表(按业务 id 拉 sys_doc)
|
||||
enrichAttachmentFields(formItems, table, result);
|
||||
|
||||
// F2-13:标题只留 page 层(form.title + wrapWithPanel 会再渲一个同名面板头,
|
||||
// 弹窗里叠上 dialog 标题就是三层重复——F2-17 UI 截图实锤,不再输出 form.title)
|
||||
String formTitle = templateName != null ? templateName : "";
|
||||
@@ -894,6 +897,8 @@ public class TemplateToAmisConverter {
|
||||
if (entityId == null || entityId.isBlank()) {
|
||||
result.degrade("view_page 缺 <page entityid> → 字段渲染但无实体列元数据(字典/枚举源可能缺失)");
|
||||
}
|
||||
// WS-D D.2:附件字段(input-file)增配查看态只读下载列表(按业务 id 拉 sys_doc)
|
||||
enrichAttachmentFields(formItems, resolveTableName(entityId, result), result);
|
||||
result.note("view_page(独立编辑表单迁移)→ 解析取得 " + formItems.size() + " 字段");
|
||||
|
||||
String formTitle = templateName != null ? templateName : "";
|
||||
@@ -955,16 +960,81 @@ public class TemplateToAmisConverter {
|
||||
|
||||
/**
|
||||
* 判断 amis 表单项是否为宽控件(独占整行,不与窄字段并排)。
|
||||
* 宽控件:富文本(input-rich-text)、附件(input-file)、多行文本(textarea)、子表(input-table)。
|
||||
* 宽控件:富文本(input-rich-text)、附件(input-file)、多行文本(textarea)、子表(input-table)、
|
||||
* 附件容器(WS-D D.2 的 service 包:已有附件下载列表 + 上传控件)。
|
||||
*
|
||||
* <p>表单项里只有 WS-D 附件字段会被映射为 {@code type=service}(其余皆 input-*),故 service 即附件容器
|
||||
* → 独占整行(与富文本/附件历来宽控件口径一致)。
|
||||
*/
|
||||
private static boolean isWideField(Map<String, Object> item) {
|
||||
String type = String.valueOf(item.get("type"));
|
||||
return switch (type) {
|
||||
case "input-rich-text", "input-file", "textarea", "input-table" -> true;
|
||||
case "input-rich-text", "input-file", "textarea", "input-table", "service" -> true;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* WS-D D.2:把附件字段(input-file)就地替换为「已有附件只读下载列表 + 上传控件」容器。
|
||||
*
|
||||
* <p><b>根因</b>:老 MultiFileUploadField 的附件按 {@code sys_doc.tablename+businesskey} 关联业务记录
|
||||
* (非物理列),转换器原把它映射为空 {@code input-file} 上传控件——查看(只读 static)态渲染成空上传按钮,
|
||||
* 不拉取/显示已有附件。对齐老系统:查看态须列出已有附件(文件名+大小KB)可下载。
|
||||
*
|
||||
* <p><b>方案</b>:用 amis {@code service} 容器(api=按业务 id 拉 {@code /api/file/list})包:
|
||||
* (1) {@code each} 渲染已有附件下载链接列表(查看/编辑态都显示,与老系统编辑页也列已有一致);
|
||||
* (2) 保留原 {@code input-file} 上传控件(编辑态可加附件;查看 static 态 amis 自禁用)。
|
||||
* 业务键绑表单数据里的主键 {@code ${<TABLE>_ID}}(查看 dialog 经 {@code ${selectedItems[0]}} 注入整行含主键)。
|
||||
*
|
||||
* @param formItems 表单项列表(就地修改)
|
||||
* @param table 实体表名(用于附件 list api 的 tableName + 主键列 {@code <TABLE>_ID})
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void enrichAttachmentFields(List<Map<String, Object>> formItems, String table, ConversionResult result) {
|
||||
if (formItems == null || table == null || table.isBlank()
|
||||
|| table.startsWith("UNKNOWN_") || table.startsWith("ORPHAN_")) {
|
||||
return; // 表名不可靠 → 不增配(诚实降级,保留原上传控件)
|
||||
}
|
||||
String upper = table.toUpperCase();
|
||||
String pkCol = upper + "_ID";
|
||||
for (int i = 0; i < formItems.size(); i++) {
|
||||
Map<String, Object> item = formItems.get(i);
|
||||
if (!"input-file".equals(String.valueOf(item.get("type")))) {
|
||||
continue;
|
||||
}
|
||||
formItems.set(i, buildAttachmentField(item, upper, pkCol));
|
||||
result.note("WS-D 附件字段 " + item.get("name") + " → service 容器(已有附件只读下载列表 "
|
||||
+ "/api/file/list?tableName=" + upper + "&businessKey=${" + pkCol + "} + 保留上传控件)");
|
||||
}
|
||||
}
|
||||
|
||||
/** 构造附件 service 容器:已有附件下载列表(each) + 原上传控件(input-file)。 */
|
||||
private static Map<String, Object> buildAttachmentField(Map<String, Object> uploadItem,
|
||||
String upperTable, String pkCol) {
|
||||
// 已有附件下载链接(文件名(大小KB)),下载走 FileController.download(Content-Disposition: attachment)
|
||||
Map<String, Object> link = new LinkedHashMap<>();
|
||||
link.put("type", "tpl");
|
||||
link.put("tpl", "<a href=\"/api/file/${id}\" target=\"_blank\" download>${name}(${sizeKb}KB)</a>");
|
||||
|
||||
Map<String, Object> each = new LinkedHashMap<>();
|
||||
each.put("type", "each");
|
||||
each.put("name", "items"); // service api data.items
|
||||
each.put("placeholder", "无附件");
|
||||
each.put("items", link);
|
||||
|
||||
Map<String, Object> service = new LinkedHashMap<>();
|
||||
service.put("type", "service");
|
||||
// 业务键绑表单主键;空主键(新增态)时 list 端点返空,不误列
|
||||
service.put("api", "get:/api/file/list?tableName=" + upperTable + "&businessKey=${" + pkCol + "}");
|
||||
service.put("name", uploadItem.get("name")); // 保 <div location="DOCUMENT"> 归位
|
||||
service.put("label", uploadItem.get("label"));
|
||||
List<Map<String, Object>> body = new ArrayList<>();
|
||||
body.add(each);
|
||||
body.add(uploadItem); // 保留上传控件(编辑态加附件;static 态自禁用)
|
||||
service.put("body", body);
|
||||
return service; // type=service → isWideField 判宽控件独占整行
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单 body 构建:有 view_page {@code <layout>} 多 {@code <tab>} 时 → amis {@code tabs}
|
||||
* (字段按各 tab 内 {@code <div location="X">} 文档序归位);无 layout/tab → 退回
|
||||
|
||||
Reference in New Issue
Block a user