fix(platform): restore approval history drawer

This commit is contained in:
2026-06-18 02:12:27 +08:00
parent 278b0da422
commit 21e3865dcf
6 changed files with 220 additions and 73 deletions

View File

@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.dsasp.server.common.core.service.FlowExcuteService;
@@ -141,24 +142,61 @@ public class ApprovalController {
wfTemplateService.parse(ctx.formKey), ctx.startFormKey);
String table = businessSummaryService.summarize(ctx.businessKey).tableName();
Map<String, Object> record = businessRecordLoader.load(formMeta.loadScript(), table, ctx.businessKey);
// 引用列 id→名(全站统一口径):主表 + 子表行补 <COL>_DISPLAY__,前端引用列显名不显 id
if (table != null && record != null && !record.isEmpty()) {
try {
userColumnResolver.resolveFormRecord(table, record);
} catch (RuntimeException e) {
log.debug("[审批表单] 引用列解析降级 table={}: {}", table, e.toString());
}
// 多选人员列(值为 id 列表,如接收人 NOTICEDRAFTPEOPLES,元数据未登记为引用列单值解析漏掉)→ 解析为姓名串
try {
for (Map.Entry<String, Object> e : new java.util.ArrayList<>(record.entrySet())) {
if (e.getValue() instanceof List<?> list && !list.isEmpty() && list.get(0) instanceof String) {
record.put(e.getKey() + "_DISPLAY__", userColumnResolver.joinUserDisplayNames(list));
}
}
} catch (RuntimeException e) {
log.debug("[审批表单] 多选人员列解析降级 table={}: {}", table, e.toString());
}
}
resolveDisplayColumns(table, record);
envelope.put("data", record);
return ResponseEntity.ok(envelope);
}
@Operation(summary = "历史审批元数据(按业务主键或流程实例,只读)",
description = "用于转换页通用「查看审批」按钮。支持 businessKey/processInstanceId 双路解析,"
+ "返回可复用 ApprovalDrawer 的只读业务表单模板、业务表与流程实例信息。")
@GetMapping("/api/approval/history/meta")
public ResponseEntity<Map<String, Object>> historyMeta(
@RequestParam(required = false) String businessKey,
@RequestParam(required = false) String processInstanceId,
@RequestParam(required = false) String businessTable) {
String processId = trimToNull(processInstanceId);
ProcessInstanceDto pi = tryProcessInstance(processId);
String bk = firstNonBlank(businessKey, pi == null ? null : pi.businessKey);
String table = resolveTable(businessTable, bk);
Map<String, Object> resp = new LinkedHashMap<>();
resp.put("found", bk != null || processId != null);
resp.put("taskId", "");
resp.put("taskName", "审批详情");
resp.put("formKey", null);
resp.put("buttons", List.of());
resp.put("buttonsSource", "default");
resp.put("loadScript", null);
resp.put("showsend", false);
resp.put("businessKey", bk);
resp.put("businessTable", table);
resp.put("businessTableName", wfTemplateService.entityDisplayName(table));
resp.put("processInstanceId", processId);
resp.put("ended", pi != null && pi.ended);
resp.put("suspended", pi != null && pi.suspended);
resp.put("formTemplateId", wfTemplateService.resolveBusinessFormTemplateId(null, table));
return ResponseEntity.ok(resp);
}
@Operation(summary = "历史审批业务单据数据(只读)",
description = "用于无 taskId 的审批历史查看。优先按 businessKey+业务表载入;若只给 processInstanceId,"
+ "先查流程实例取 businessKey,再走表单加载服务。返回 amis 单记录契约 {status:0,data:{...record}}。")
@GetMapping("/api/approval/history/business-data")
public ResponseEntity<Map<String, Object>> historyBusinessData(
@RequestParam(required = false) String businessKey,
@RequestParam(required = false) String processInstanceId,
@RequestParam(required = false) String businessTable) {
String processId = trimToNull(processInstanceId);
ProcessInstanceDto pi = tryProcessInstance(processId);
String bk = firstNonBlank(businessKey, pi == null ? null : pi.businessKey);
String table = resolveTable(businessTable, bk);
Map<String, Object> envelope = new LinkedHashMap<>();
envelope.put("status", 0);
envelope.put("msg", "");
Map<String, Object> record = businessRecordLoader.load(null, table, bk);
resolveDisplayColumns(table, record);
envelope.put("data", record);
return ResponseEntity.ok(envelope);
}
@@ -357,6 +395,53 @@ public class ApprovalController {
return pi == null || pi.ended;
}
private ProcessInstanceDto tryProcessInstance(String processInstanceId) {
if (processInstanceId == null || processInstanceId.isBlank()) {
return null;
}
try {
return flowableClient.processInstance(processInstanceId);
} catch (RuntimeException e) {
log.debug("[审批历史] 流程实例解析降级 processInstanceId={}: {}", processInstanceId, e.toString());
return null;
}
}
/** 引用列 id→名(全站统一口径):主表 + 子表行补 <COL>_DISPLAY__,前端引用列显名不显 id。 */
private void resolveDisplayColumns(String table, Map<String, Object> record) {
if (table == null || record == null || record.isEmpty()) {
return;
}
try {
userColumnResolver.resolveFormRecord(table, record);
} catch (RuntimeException e) {
log.debug("[审批表单] 引用列解析降级 table={}: {}", table, e.toString());
}
// 多选人员列(值为 id 列表,如接收人 NOTICEDRAFTPEOPLES,元数据未登记为引用列单值解析漏掉)→ 解析为姓名串
try {
for (Map.Entry<String, Object> e : new java.util.ArrayList<>(record.entrySet())) {
if (e.getValue() instanceof List<?> list && !list.isEmpty() && list.get(0) instanceof String) {
record.put(e.getKey() + "_DISPLAY__", userColumnResolver.joinUserDisplayNames(list));
}
}
} catch (RuntimeException e) {
log.debug("[审批表单] 多选人员列解析降级 table={}: {}", table, e.toString());
}
}
private static String trimToNull(String value) {
if (value == null) {
return null;
}
String s = value.trim();
return s.isEmpty() ? null : s;
}
private static String firstNonBlank(String a, String b) {
String aa = trimToNull(a);
return aa != null ? aa : trimToNull(b);
}
private static List<Map<String, Object>> buttonsToMaps(WfTemplateMeta meta) {
List<Map<String, Object>> list = new ArrayList<>();
for (WfTemplateService.Button b : meta.buttons()) {

View File

@@ -0,0 +1,84 @@
package com.eip4.platform.flowgateway;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.springframework.http.ResponseEntity;
import com.dsasp.server.common.core.service.FlowExcuteService;
import com.eip4.platform.flowgateway.aggregate.BusinessRecordLoader;
import com.eip4.platform.flowgateway.aggregate.BusinessSummaryService;
import com.eip4.platform.flowgateway.aggregate.WfTemplateService;
import com.eip4.platform.flowgateway.client.FlowableClient;
import com.eip4.platform.flowgateway.client.ProcessInstanceDto;
import com.eip4.platform.flowgateway.web.ApprovalController;
import com.eip4.platform.flowgateway.writeback.StatusWriteback;
import com.eip4.platform.metadata.flow.UserColumnResolver;
class ApprovalControllerHistoryTest {
private final FlowableClient flowableClient = mock(FlowableClient.class);
private final WfTemplateService wfTemplateService = mock(WfTemplateService.class);
private final BusinessSummaryService businessSummaryService = mock(BusinessSummaryService.class);
private final StatusWriteback statusWriteback = mock(StatusWriteback.class);
private final FlowExcuteService flowExcuteService = mock(FlowExcuteService.class);
private final BusinessRecordLoader businessRecordLoader = mock(BusinessRecordLoader.class);
private final UserColumnResolver userColumnResolver = mock(UserColumnResolver.class);
private final ApprovalController controller = new ApprovalController(flowableClient, wfTemplateService,
businessSummaryService, statusWriteback, flowExcuteService, businessRecordLoader, userColumnResolver);
@Test
@SuppressWarnings("unchecked")
void historyMeta_byBusinessKey_resolvesTableAndReadonlyFormTemplate() {
when(businessSummaryService.summarize("BK-1"))
.thenReturn(new BusinessSummaryService.Summary("OA_NOTICE", Map.of("TITLE", "会议通知")));
when(wfTemplateService.entityDisplayName("OA_NOTICE")).thenReturn("通知管理");
when(wfTemplateService.resolveBusinessFormTemplateId(null, "OA_NOTICE")).thenReturn("edit-tpl");
ResponseEntity<Map<String, Object>> response = controller.historyMeta("BK-1", null, null);
Map<String, Object> body = response.getBody();
assertThat(body).isNotNull();
assertThat(body).containsEntry("found", true)
.containsEntry("businessKey", "BK-1")
.containsEntry("businessTable", "OA_NOTICE")
.containsEntry("businessTableName", "通知管理")
.containsEntry("formTemplateId", "edit-tpl")
.containsEntry("taskId", "")
.containsEntry("taskName", "审批详情");
assertThat((java.util.List<Map<String, Object>>) body.get("buttons")).isEmpty();
verifyNoInteractions(flowableClient);
}
@Test
void historyBusinessData_byProcessInstance_usesProcessBusinessKeyAndResolvesDisplayColumns() {
ProcessInstanceDto pi = new ProcessInstanceDto();
pi.id = "pi-1";
pi.businessKey = "BK-1";
when(flowableClient.processInstance("pi-1")).thenReturn(pi);
when(businessSummaryService.summarize("BK-1"))
.thenReturn(new BusinessSummaryService.Summary("OA_NOTICE", Map.of()));
Map<String, Object> record = new LinkedHashMap<>();
record.put("OA_NOTICE_ID", "BK-1");
record.put("TITLE", "会议通知");
when(businessRecordLoader.load(null, "OA_NOTICE", "BK-1")).thenReturn(record);
ResponseEntity<Map<String, Object>> response = controller.historyBusinessData(null, "pi-1", null);
Map<String, Object> body = response.getBody();
assertThat(body).isNotNull();
assertThat(body).containsEntry("status", 0).containsEntry("msg", "");
assertThat(body.get("data")).isSameAs(record);
verify(businessRecordLoader).load(null, "OA_NOTICE", "BK-1");
verify(userColumnResolver).resolveFormRecord(eq("OA_NOTICE"), any());
}
}