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:
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) {
|
||||
if (filename == null || !filename.contains(".")) {
|
||||
return "";
|
||||
|
||||
@@ -271,10 +271,12 @@ public class FlowController {
|
||||
yield ok(output, null);
|
||||
}
|
||||
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();
|
||||
Object output = flowExcuteService.excute(map, ctx, id);
|
||||
yield ok(output, null);
|
||||
yield ok(output, flowNameResolver.entityTableForNamedFlow(id));
|
||||
}
|
||||
case NAMED_WRITE -> {
|
||||
// 命名写流:GET 拒绝(防 URL 触发写);POST 用真实 JWT 用户上下文执行
|
||||
|
||||
Reference in New Issue
Block a user