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);
|
noteFormScripts(form, result);
|
||||||
|
|
||||||
|
// WS-D D.2:附件字段(input-file)增配查看态只读下载列表(按业务 id 拉 sys_doc)
|
||||||
|
enrichAttachmentFields(formItems, table, result);
|
||||||
|
|
||||||
// F2-13:标题只留 page 层(form.title + wrapWithPanel 会再渲一个同名面板头,
|
// F2-13:标题只留 page 层(form.title + wrapWithPanel 会再渲一个同名面板头,
|
||||||
// 弹窗里叠上 dialog 标题就是三层重复——F2-17 UI 截图实锤,不再输出 form.title)
|
// 弹窗里叠上 dialog 标题就是三层重复——F2-17 UI 截图实锤,不再输出 form.title)
|
||||||
String formTitle = templateName != null ? templateName : "";
|
String formTitle = templateName != null ? templateName : "";
|
||||||
@@ -894,6 +897,8 @@ public class TemplateToAmisConverter {
|
|||||||
if (entityId == null || entityId.isBlank()) {
|
if (entityId == null || entityId.isBlank()) {
|
||||||
result.degrade("view_page 缺 <page entityid> → 字段渲染但无实体列元数据(字典/枚举源可能缺失)");
|
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() + " 字段");
|
result.note("view_page(独立编辑表单迁移)→ 解析取得 " + formItems.size() + " 字段");
|
||||||
|
|
||||||
String formTitle = templateName != null ? templateName : "";
|
String formTitle = templateName != null ? templateName : "";
|
||||||
@@ -955,16 +960,81 @@ public class TemplateToAmisConverter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断 amis 表单项是否为宽控件(独占整行,不与窄字段并排)。
|
* 判断 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) {
|
private static boolean isWideField(Map<String, Object> item) {
|
||||||
String type = String.valueOf(item.get("type"));
|
String type = String.valueOf(item.get("type"));
|
||||||
return switch (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;
|
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}
|
* 表单 body 构建:有 view_page {@code <layout>} 多 {@code <tab>} 时 → amis {@code tabs}
|
||||||
* (字段按各 tab 内 {@code <div location="X">} 文档序归位);无 layout/tab → 退回
|
* (字段按各 tab 内 {@code <div location="X">} 文档序归位);无 layout/tab → 退回
|
||||||
|
|||||||
@@ -615,6 +615,8 @@ class TemplateToAmisConverterTest {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void form_附件字段MultiFileUploadField转inputFile() {
|
void form_附件字段MultiFileUploadField转inputFile() {
|
||||||
// F2-8 实证:MultiFileUploadField / FileUploadField → input-file(receiver + downloadUrl)
|
// F2-8 实证:MultiFileUploadField / FileUploadField → input-file(receiver + downloadUrl)
|
||||||
|
// WS-D D.2:附件字段进而被包进 service 容器(已有附件下载列表 + 上传控件),
|
||||||
|
// 内层 input-file 契约不变(receiver/downloadUrl/multiple)。
|
||||||
String pageXml = "<page entityid='e9'><fields>"
|
String pageXml = "<page entityid='e9'><fields>"
|
||||||
+ "<field name='TITLE' label='主题' uitype='TextField' required='true'/>"
|
+ "<field name='TITLE' label='主题' uitype='TextField' required='true'/>"
|
||||||
+ "<field name='DOCUMENT' label='附件' uitype='MultiFileUploadField'/>"
|
+ "<field name='DOCUMENT' label='附件' uitype='MultiFileUploadField'/>"
|
||||||
@@ -629,23 +631,76 @@ class TemplateToAmisConverterTest {
|
|||||||
List<Map<String, Object>> items = flattenFormBody(form);
|
List<Map<String, Object>> items = flattenFormBody(form);
|
||||||
assertEquals(3, items.size());
|
assertEquals(3, items.size());
|
||||||
|
|
||||||
// MultiFileUploadField → input-file, multiple=true
|
// MultiFileUploadField → service 容器;内层 input-file multiple=true
|
||||||
Map<String, Object> docField = items.get(1);
|
Map<String, Object> docField = items.get(1);
|
||||||
assertEquals("input-file", docField.get("type"));
|
Map<String, Object> docUpload = attachmentUploadOf(docField);
|
||||||
assertEquals("/api/file/upload", docField.get("receiver"));
|
assertEquals("input-file", docUpload.get("type"));
|
||||||
assertEquals("/api/file/${id}", docField.get("downloadUrl"));
|
assertEquals("/api/file/upload", docUpload.get("receiver"));
|
||||||
assertEquals(true, docField.get("multiple"));
|
assertEquals("/api/file/${id}", docUpload.get("downloadUrl"));
|
||||||
|
assertEquals(true, docUpload.get("multiple"));
|
||||||
|
|
||||||
// FileUploadField → input-file, no multiple
|
// FileUploadField → service 容器;内层 input-file 无 multiple
|
||||||
Map<String, Object> singleField = items.get(2);
|
Map<String, Object> singleField = items.get(2);
|
||||||
assertEquals("input-file", singleField.get("type"));
|
Map<String, Object> singleUpload = attachmentUploadOf(singleField);
|
||||||
assertEquals("/api/file/upload", singleField.get("receiver"));
|
assertEquals("input-file", singleUpload.get("type"));
|
||||||
assertNull(singleField.get("multiple"));
|
assertEquals("/api/file/upload", singleUpload.get("receiver"));
|
||||||
|
assertNull(singleUpload.get("multiple"));
|
||||||
|
|
||||||
// 映射台账中有 input-file 记录
|
// 映射台账中有 input-file 记录
|
||||||
assertTrue(notes.stream().anyMatch(n -> n.contains("input-file")));
|
assertTrue(notes.stream().anyMatch(n -> n.contains("input-file")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void form_附件字段_查看态只读下载列表() {
|
||||||
|
// WS-D D.2:附件字段(input-file) → service 容器(api 按业务 id 拉 /api/file/list,
|
||||||
|
// each 渲染已有附件下载链接 + 保留上传控件),对齐老系统查看页附件可下载列表。
|
||||||
|
String pageXml = "<page entityid='e9'><fields>"
|
||||||
|
+ "<field name='DOCUMENT' label='附件' uitype='MultiFileUploadField'/>"
|
||||||
|
+ "</fields></page>";
|
||||||
|
Function<String, String> resolver = id -> pageXml;
|
||||||
|
// resolveTableName mock 默认返 PM_DEMO → 主键 PM_DEMO_ID
|
||||||
|
String xml = "<form entityid='e1' pageid='p1'/>";
|
||||||
|
ConversionResult r = converter.convertGraded(xml, "附件查看表单", new ArrayList<>(), resolver);
|
||||||
|
|
||||||
|
Map<String, Object> form = body(r.getSchema());
|
||||||
|
List<Map<String, Object>> items = flattenFormBody(form);
|
||||||
|
Map<String, Object> doc = items.get(0);
|
||||||
|
|
||||||
|
// 附件容器:service,按业务 id 拉已有附件,name=DOCUMENT(保布局归位),label=附件
|
||||||
|
assertEquals("service", doc.get("type"));
|
||||||
|
assertEquals("DOCUMENT", doc.get("name"));
|
||||||
|
assertEquals("附件", doc.get("label"));
|
||||||
|
assertEquals("get:/api/file/list?tableName=PM_DEMO&businessKey=${PM_DEMO_ID}", doc.get("api"));
|
||||||
|
|
||||||
|
List<Map<String, Object>> svcBody = (List<Map<String, Object>>) doc.get("body");
|
||||||
|
assertEquals(2, svcBody.size());
|
||||||
|
// (1) each 渲染已有附件下载列表
|
||||||
|
Map<String, Object> each = svcBody.get(0);
|
||||||
|
assertEquals("each", each.get("type"));
|
||||||
|
assertEquals("items", each.get("name"));
|
||||||
|
Map<String, Object> link = (Map<String, Object>) each.get("items");
|
||||||
|
assertEquals("tpl", link.get("type"));
|
||||||
|
assertTrue(String.valueOf(link.get("tpl")).contains("/api/file/${id}"), "下载链接指向 FileController.download");
|
||||||
|
assertTrue(String.valueOf(link.get("tpl")).contains("${name}"), "显示文件名");
|
||||||
|
assertTrue(String.valueOf(link.get("tpl")).contains("${sizeKb}"), "显示大小KB");
|
||||||
|
// (2) 保留上传控件
|
||||||
|
assertEquals("input-file", svcBody.get(1).get("type"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 从 WS-D 附件 service 容器里取内层上传控件(input-file)。 */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static Map<String, Object> attachmentUploadOf(Map<String, Object> attachmentField) {
|
||||||
|
assertEquals("service", attachmentField.get("type"), "附件字段应被包进 service 容器");
|
||||||
|
List<Map<String, Object>> svcBody = (List<Map<String, Object>>) attachmentField.get("body");
|
||||||
|
for (Map<String, Object> b : svcBody) {
|
||||||
|
if ("input-file".equals(b.get("type"))) {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new AssertionError("附件 service 容器内未找到 input-file 上传控件");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void form_默认控件补全_密码_单附件_日期() {
|
void form_默认控件补全_密码_单附件_日期() {
|
||||||
@@ -668,12 +723,12 @@ class TemplateToAmisConverterTest {
|
|||||||
|
|
||||||
// PasswordField → input-password(不再明文 input-text)
|
// PasswordField → input-password(不再明文 input-text)
|
||||||
assertEquals("input-password", items.get(1).get("type"));
|
assertEquals("input-password", items.get(1).get("type"));
|
||||||
// SingleFileUploadField → input-file 单文件(无 multiple),复用上传 case
|
// SingleFileUploadField → input-file 单文件(无 multiple);WS-D 包进 service 容器,内层 input-file
|
||||||
Map<String, Object> cert = items.get(2);
|
Map<String, Object> certUpload = attachmentUploadOf(items.get(2));
|
||||||
assertEquals("input-file", cert.get("type"));
|
assertEquals("input-file", certUpload.get("type"));
|
||||||
assertEquals("/api/file/upload", cert.get("receiver"));
|
assertEquals("/api/file/upload", certUpload.get("receiver"));
|
||||||
assertEquals("/api/file/${id}", cert.get("downloadUrl"));
|
assertEquals("/api/file/${id}", certUpload.get("downloadUrl"));
|
||||||
assertNull(cert.get("multiple"));
|
assertNull(certUpload.get("multiple"));
|
||||||
// DateField → input-date(复用 PopupDateField 无时分支)
|
// DateField → input-date(复用 PopupDateField 无时分支)
|
||||||
assertEquals("input-date", items.get(3).get("type"));
|
assertEquals("input-date", items.get(3).get("type"));
|
||||||
|
|
||||||
@@ -2081,7 +2136,10 @@ class TemplateToAmisConverterTest {
|
|||||||
assertEquals("group", row2.get("type"), "落单窄字段也包 group(保持行结构一致)");
|
assertEquals("group", row2.get("type"), "落单窄字段也包 group(保持行结构一致)");
|
||||||
assertEquals(1, ((List<?>) row2.get("body")).size());
|
assertEquals(1, ((List<?>) row2.get("body")).size());
|
||||||
|
|
||||||
assertEquals("input-file", rows.get(3).get("type"));
|
// 附件字段(WS-D)包进 service 容器,仍作宽控件独占整行;内层含 input-file 上传控件
|
||||||
|
assertEquals("service", rows.get(3).get("type"), "附件 service 容器独占整行(宽控件)");
|
||||||
|
assertEquals("DOC", rows.get(3).get("name"), "附件容器保留字段 name 以归位布局");
|
||||||
|
assertTrue(rows.get(3).toString().contains("input-file"), "附件容器内保留上传控件");
|
||||||
assertEquals("textarea", rows.get(4).get("type"));
|
assertEquals("textarea", rows.get(4).get("type"));
|
||||||
|
|
||||||
// actions 仍为空(单按钮契约不变)
|
// actions 仍为空(单按钮契约不变)
|
||||||
|
|||||||
Binary file not shown.
@@ -207,8 +207,78 @@ public class FileController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按业务实体(tableName + businessKey)列出已有附件(WS-D D.2)。
|
||||||
|
*
|
||||||
|
* <p>查看(只读)态新闻/通知等查看页的附件字段(DOCUMENT,老 MultiFileUploadField)数据源:
|
||||||
|
* 附件按 {@code sys_doc.tablename + businesskey} 关联业务记录(非物理列),查看态须列出已有附件供下载,
|
||||||
|
* 而非空上传按钮。amis {@code service} 组件按本端点拉取,{@code each} 渲染「文件名 (大小KB) + 下载」列表。
|
||||||
|
*
|
||||||
|
* @param tableName 业务表名(大小写不敏感,入库前已大写存储)
|
||||||
|
* @param businessKey 业务记录主键(空 → 返回空列表,防全表扫)
|
||||||
|
* @return amis 约定 {@code {status:0, data:{items:[{id,name,size,sizeKb,url}]}}}
|
||||||
|
*/
|
||||||
|
@Operation(summary = "按业务 id 列已有附件",
|
||||||
|
description = "按 sys_doc.tablename+businesskey 列附件,供查看态只读下载列表;返回 {status,data:{items}}")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public ResponseEntity<Map<String, Object>> list(
|
||||||
|
@RequestParam("tableName") String tableName,
|
||||||
|
@RequestParam("businessKey") String businessKey) {
|
||||||
|
|
||||||
|
List<Map<String, Object>> items = new java.util.ArrayList<>();
|
||||||
|
// 业务键缺失 → 空列表(不查库,防 businesskey 为空时全表附件扫出)
|
||||||
|
if (tableName != null && !tableName.isBlank() && businessKey != null && !businessKey.isBlank()) {
|
||||||
|
List<Map<String, Object>> rows = jdbcTemplate.queryForList(
|
||||||
|
"SELECT sys_doc_id, filename, filesize FROM sys_doc "
|
||||||
|
+ "WHERE UPPER(tablename) = ? AND TRIM(businesskey) = ? AND isactive = 1 "
|
||||||
|
+ "ORDER BY createtime",
|
||||||
|
tableName.trim().toUpperCase(), businessKey.trim());
|
||||||
|
for (Map<String, Object> r : rows) {
|
||||||
|
String docId = String.valueOf(r.get("sys_doc_id")).trim();
|
||||||
|
long size = toLong(r.get("filesize"));
|
||||||
|
Map<String, Object> item = new LinkedHashMap<>();
|
||||||
|
item.put("id", docId);
|
||||||
|
item.put("name", r.get("filename"));
|
||||||
|
item.put("size", size);
|
||||||
|
item.put("sizeKb", sizeToKb(size));
|
||||||
|
item.put("url", "/api/file/" + docId);
|
||||||
|
items.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> data = new LinkedHashMap<>();
|
||||||
|
data.put("items", items);
|
||||||
|
Map<String, Object> resp = new LinkedHashMap<>();
|
||||||
|
resp.put("status", 0);
|
||||||
|
resp.put("msg", "");
|
||||||
|
resp.put("data", data);
|
||||||
|
return ResponseEntity.ok(resp);
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------- 内部工具
|
// ---------------------------------------------------------------- 内部工具
|
||||||
|
|
||||||
|
/** 字节 → KB(向上取整,非空文件至少显 1KB,避免「0KB」误导)。 */
|
||||||
|
private static long sizeToKb(long bytes) {
|
||||||
|
if (bytes <= 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return Math.max(1, (bytes + 1023) / 1024);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long toLong(Object v) {
|
||||||
|
if (v instanceof Number n) {
|
||||||
|
return n.longValue();
|
||||||
|
}
|
||||||
|
if (v == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return Long.parseLong(String.valueOf(v).trim());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static String extractExt(String filename) {
|
private static String extractExt(String filename) {
|
||||||
if (filename == null || !filename.contains(".")) {
|
if (filename == null || !filename.contains(".")) {
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@@ -271,10 +271,12 @@ public class FlowController {
|
|||||||
yield ok(output, null);
|
yield ok(output, null);
|
||||||
}
|
}
|
||||||
case NAMED_READ -> {
|
case NAMED_READ -> {
|
||||||
// 命名读流:GET/POST 皆可。非合成路径无法稳妥推断实体表,故不做用户列解析(table=null)。
|
// 命名读流:GET/POST 皆可。WS-D D.3:命名读流(如查看新闻查询 OA_NEWSMANAGE_SEARCH_LOOK)按其
|
||||||
|
// sys_serviceflow.entityid → sys_entity.tablename 解析数据源实体表,使引用列 id→姓名解析生效
|
||||||
|
// (发布人 USERSEND_ID 等显「-」根因);解析不到 → null,跳过解析(现状行为不变)。
|
||||||
Properties ctx = UserSession.getAdmin();
|
Properties ctx = UserSession.getAdmin();
|
||||||
Object output = flowExcuteService.excute(map, ctx, id);
|
Object output = flowExcuteService.excute(map, ctx, id);
|
||||||
yield ok(output, null);
|
yield ok(output, flowNameResolver.entityTableForNamedFlow(id));
|
||||||
}
|
}
|
||||||
case NAMED_WRITE -> {
|
case NAMED_WRITE -> {
|
||||||
// 命名写流:GET 拒绝(防 URL 触发写);POST 用真实 JWT 用户上下文执行
|
// 命名写流:GET 拒绝(防 URL 触发写);POST 用真实 JWT 用户上下文执行
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
package com.eip4.platform.metadata.web;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.jdbc.core.JdbcOperations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WS-D D.2 FileController.list(按业务 id 列已有附件)单测(mock JdbcTemplate,不连库)。
|
||||||
|
*
|
||||||
|
* <p>覆盖:按 tableName+businessKey 列附件 → amis 约定 {status:0, data:{items:[{id,name,size,sizeKb,url}]}};
|
||||||
|
* 空业务键参数防御;KB 折算;空列表返回。下载列表是查看页只读附件下载列表的数据源(DOCUMENT 字段)。
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
class FileControllerTest {
|
||||||
|
|
||||||
|
private JdbcOperations jdbc;
|
||||||
|
private FileController controller;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
jdbc = mock(JdbcOperations.class);
|
||||||
|
controller = new FileController(jdbc, "./data/files");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> docRow(String id, String name, long size) {
|
||||||
|
Map<String, Object> m = new LinkedHashMap<>();
|
||||||
|
m.put("sys_doc_id", id);
|
||||||
|
m.put("filename", name);
|
||||||
|
m.put("filesize", size);
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("1. 按 tableName+businessKey 列附件 → status=0, items 含 id/name/size/sizeKb/url")
|
||||||
|
void listByBusinessKey() {
|
||||||
|
List<Map<String, Object>> rows = List.of(
|
||||||
|
docRow("doc-1", "奖杯.JPG", 6857687L),
|
||||||
|
docRow("doc-2", "苏州五建.zip", 11985224L));
|
||||||
|
// tableName 入库前大写,businessKey 原样
|
||||||
|
when(jdbc.queryForList(anyString(), eq("OA_NEWSMANAGE"), eq("biz-123"))).thenReturn(rows);
|
||||||
|
|
||||||
|
ResponseEntity<Map<String, Object>> resp = controller.list("oa_newsmanage", "biz-123");
|
||||||
|
|
||||||
|
Map<String, Object> body = resp.getBody();
|
||||||
|
assertNotNull(body);
|
||||||
|
assertEquals(0, body.get("status"));
|
||||||
|
Map<String, Object> data = (Map<String, Object>) body.get("data");
|
||||||
|
List<Map<String, Object>> items = (List<Map<String, Object>>) data.get("items");
|
||||||
|
assertEquals(2, items.size());
|
||||||
|
|
||||||
|
Map<String, Object> first = items.get(0);
|
||||||
|
assertEquals("doc-1", first.get("id"));
|
||||||
|
assertEquals("奖杯.JPG", first.get("name"));
|
||||||
|
assertEquals(6857687L, first.get("size"));
|
||||||
|
// 6857687 / 1024 = 6697 KB(向上取整,至少 1KB)
|
||||||
|
assertEquals(6697L, first.get("sizeKb"));
|
||||||
|
assertEquals("/api/file/doc-1", first.get("url"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("2. 空 businessKey → status=0, items 空(不查库,防全表扫)")
|
||||||
|
void listBlankBusinessKey() {
|
||||||
|
ResponseEntity<Map<String, Object>> resp = controller.list("OA_NEWSMANAGE", " ");
|
||||||
|
Map<String, Object> body = resp.getBody();
|
||||||
|
assertNotNull(body);
|
||||||
|
assertEquals(0, body.get("status"));
|
||||||
|
Map<String, Object> data = (Map<String, Object>) body.get("data");
|
||||||
|
assertTrue(((List<?>) data.get("items")).isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("3. 无匹配附件 → status=0, items 空列表(不报错)")
|
||||||
|
void listEmpty() {
|
||||||
|
when(jdbc.queryForList(anyString(), eq("OA_NEWSMANAGE"), eq("biz-none"))).thenReturn(List.of());
|
||||||
|
ResponseEntity<Map<String, Object>> resp = controller.list("OA_NEWSMANAGE", "biz-none");
|
||||||
|
Map<String, Object> data = (Map<String, Object>) resp.getBody().get("data");
|
||||||
|
assertTrue(((List<?>) data.get("items")).isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("4. 小文件 (<1KB) → sizeKb 至少 1(不显 0KB)")
|
||||||
|
void listSmallFileSizeKbAtLeastOne() {
|
||||||
|
when(jdbc.queryForList(anyString(), eq("OA_NEWSMANAGE"), eq("biz-1")))
|
||||||
|
.thenReturn(List.of(docRow("doc-s", "tiny.txt", 200L)));
|
||||||
|
ResponseEntity<Map<String, Object>> resp = controller.list("OA_NEWSMANAGE", "biz-1");
|
||||||
|
Map<String, Object> data = (Map<String, Object>) resp.getBody().get("data");
|
||||||
|
List<Map<String, Object>> items = (List<Map<String, Object>>) data.get("items");
|
||||||
|
assertEquals(1L, items.get(0).get("sizeKb"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -418,13 +418,16 @@ class FlowControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("16. UUID/命名路径: 不调用用户列解析器(无法稳妥推断实体表,table=null)")
|
@DisplayName("16. UUID/命名路径: 实体表解析不到(entityTableForNamedFlow=null)→ 不调用用户列解析器")
|
||||||
void nonSynthesizedDoesNotInvokeResolver() {
|
void nonSynthesizedDoesNotInvokeResolver() {
|
||||||
String flowId = "COMMON_REPORT";
|
String flowId = "COMMON_REPORT";
|
||||||
FlowExcuteService engine = mock(FlowExcuteService.class);
|
FlowExcuteService engine = mock(FlowExcuteService.class);
|
||||||
when(engine.excute(any(), any(), any())).thenReturn(new HashMap<>());
|
when(engine.excute(any(), any(), any())).thenReturn(new HashMap<>());
|
||||||
UserColumnResolver userResolver = mock(UserColumnResolver.class);
|
UserColumnResolver userResolver = mock(UserColumnResolver.class);
|
||||||
FlowController controller = new FlowController(engine, resolverReturning(flowId, namedHit()), userResolver);
|
FlowNameResolver resolver = resolverReturning(flowId, namedHit());
|
||||||
|
// 命名读流解析不到实体表(报表类无 entityid)→ null → 跳过解析(现状行为不变)
|
||||||
|
when(resolver.entityTableForNamedFlow(flowId)).thenReturn(null);
|
||||||
|
FlowController controller = new FlowController(engine, resolver, userResolver);
|
||||||
|
|
||||||
controller.executeGet(flowId, new HashMap<>());
|
controller.executeGet(flowId, new HashMap<>());
|
||||||
|
|
||||||
@@ -432,6 +435,56 @@ class FlowControllerTest {
|
|||||||
.resolveRows(org.mockito.ArgumentMatchers.anyString(), any(List.class));
|
.resolveRows(org.mockito.ArgumentMatchers.anyString(), any(List.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("16b. 命名读流(查看新闻查询)可解析实体表 → 用户引用列解析器以该表 + items 行被调用(发布人显「-」修复,WS-D D.3)")
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void namedReadWithResolvableTableInvokesUserColumnResolver() {
|
||||||
|
String flowId = "OA_NEWSMANAGE_SEARCH_LOOK"; // 命名读流「查看新闻查询」
|
||||||
|
|
||||||
|
// 引擎返回搜索流默认输出形态 {result:{listresult:[POJO], pagecount:1}}
|
||||||
|
Map<String, Object> listResult = new LinkedHashMap<>();
|
||||||
|
Map<String, Object> cols = new LinkedHashMap<>();
|
||||||
|
cols.put("USERSEND_ID", "user-42");
|
||||||
|
cols.put("TITLE", "公司新闻");
|
||||||
|
List<GeneralPOJO> pojos = new ArrayList<>();
|
||||||
|
pojos.add(fakeRow("row-1", cols));
|
||||||
|
listResult.put(POJOCRUDService.LIST_RESULT, pojos);
|
||||||
|
listResult.put(POJOCRUDService.PAGE_COUNT, 1);
|
||||||
|
Map<String, Object> output = new LinkedHashMap<>();
|
||||||
|
output.put("result", listResult);
|
||||||
|
|
||||||
|
FlowExcuteService engine = mock(FlowExcuteService.class);
|
||||||
|
when(engine.excute(any(), any(), eq(flowId))).thenReturn(output);
|
||||||
|
|
||||||
|
// 命名读流经 sys_serviceflow.entityid → sys_entity.tablename 解析到 OA_NEWSMANAGE
|
||||||
|
FlowNameResolver resolver = resolverReturning(flowId, namedHit());
|
||||||
|
when(resolver.entityTableForNamedFlow(flowId)).thenReturn("OA_NEWSMANAGE");
|
||||||
|
|
||||||
|
// 解析器桩:把 USERSEND_ID 补出 _DISPLAY__ 平行字段(验证就地改写反映到响应)
|
||||||
|
UserColumnResolver userResolver = mock(UserColumnResolver.class);
|
||||||
|
org.mockito.Mockito.doAnswer(inv -> {
|
||||||
|
List<Map<String, Object>> rows = inv.getArgument(1);
|
||||||
|
for (Map<String, Object> r : rows) {
|
||||||
|
if ("user-42".equals(r.get("USERSEND_ID"))) {
|
||||||
|
r.put("USERSEND_ID_DISPLAY__", "罗来伟[130218]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}).when(userResolver).resolveRows(eq("OA_NEWSMANAGE"), any(List.class));
|
||||||
|
|
||||||
|
FlowController controller = new FlowController(engine, resolver, userResolver);
|
||||||
|
|
||||||
|
ResponseEntity<Map<String, Object>> resp = controller.executeGet(flowId, new HashMap<>());
|
||||||
|
|
||||||
|
// 解析器被以「命名读流解析出的实体表」调用
|
||||||
|
org.mockito.Mockito.verify(userResolver).resolveRows(eq("OA_NEWSMANAGE"), any(List.class));
|
||||||
|
// 发布人显示名补出,原始 id 保留
|
||||||
|
Map<String, Object> data = (Map<String, Object>) resp.getBody().get("data");
|
||||||
|
List<Map<String, Object>> items = (List<Map<String, Object>>) data.get("items");
|
||||||
|
assertEquals("罗来伟[130218]", items.get(0).get("USERSEND_ID_DISPLAY__"), "发布人引用列 id → 姓名(显示列)");
|
||||||
|
assertEquals("user-42", items.get(0).get("USERSEND_ID"), "原始 id 列保留不动");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("14. 无分页参数: 不注入分页键(命名/报表流无分页语义时不凭空加键)")
|
@DisplayName("14. 无分页参数: 不注入分页键(命名/报表流无分页语义时不凭空加键)")
|
||||||
void noPagingKeysWhenAbsent() {
|
void noPagingKeysWhenAbsent() {
|
||||||
|
|||||||
Reference in New Issue
Block a user