fix(platform): restore approval history drawer
This commit is contained in:
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user