diff --git a/flowable-service/src/main/java/com/eip4/flowservice/api/ApprovalContextDto.java b/flowable-service/src/main/java/com/eip4/flowservice/api/ApprovalContextDto.java
new file mode 100644
index 0000000..43009ad
--- /dev/null
+++ b/flowable-service/src/main/java/com/eip4/flowservice/api/ApprovalContextDto.java
@@ -0,0 +1,29 @@
+package com.eip4.flowservice.api;
+
+/**
+ * 任务审批上下文(供 gateway 解析 WfTemplate 驱动审批界面)。
+ *
+ *
聚合一次性返回办理审批所需的引擎侧事实:formKey(= view_wftemplate_id,已经 {@code FormKeyResolver}
+ * 历史回补)、业务主键/表、实例状态。gateway 据 formKey 查 view_wftemplate 得按钮/脚本/业务表单。
+ */
+public class ApprovalContextDto {
+ /** 是否查到任务(运行中或历史)。 */
+ public boolean found;
+ /** 任务 id。 */
+ public String taskId;
+ /** 任务名(节点名)。 */
+ public String taskName;
+ /** formKey = view_wftemplate_id(已历史回补;解析不到为 null → gateway 降级默认按钮)。 */
+ public String formKey;
+ /** 开始节点 formKey(BPMN startEvent activiti:formKey)。任务节点是裸模板(无pageid)时 gateway 回退到它(对齐老 getStartFormKey)。 */
+ public String startFormKey;
+ public String processInstanceId;
+ public String processDefinitionId;
+ public String taskDefinitionKey;
+ /** 流程业务主键(= 业务记录 PK;从实例反查)。 */
+ public String businessKey;
+ /** 流程实例是否已结束。 */
+ public boolean ended;
+ /** 任务/实例是否挂起(挂起不可办理)。 */
+ public boolean suspended;
+}
diff --git a/flowable-service/src/main/java/com/eip4/flowservice/api/FlowController.java b/flowable-service/src/main/java/com/eip4/flowservice/api/FlowController.java
index 538d174..6b9d1b5 100644
--- a/flowable-service/src/main/java/com/eip4/flowservice/api/FlowController.java
+++ b/flowable-service/src/main/java/com/eip4/flowservice/api/FlowController.java
@@ -43,15 +43,30 @@ public class FlowController {
private final HistoryService historyService;
private final RepositoryService repositoryService;
private final JdbcTemplate bizJdbc;
+ private final com.eip4.flowservice.wf.FormKeyResolver formKeyResolver;
+ private final com.eip4.flowservice.wf.StartFormKeyResolver startFormKeyResolver;
+ @org.springframework.beans.factory.annotation.Autowired
public FlowController(TaskService taskService, RuntimeService runtimeService,
HistoryService historyService, RepositoryService repositoryService,
- JdbcTemplate bizJdbc) {
+ JdbcTemplate bizJdbc, com.eip4.flowservice.wf.FormKeyResolver formKeyResolver,
+ com.eip4.flowservice.wf.StartFormKeyResolver startFormKeyResolver) {
this.taskService = taskService;
this.runtimeService = runtimeService;
this.historyService = historyService;
this.repositoryService = repositoryService;
this.bizJdbc = bizJdbc;
+ this.formKeyResolver = formKeyResolver;
+ this.startFormKeyResolver = startFormKeyResolver;
+ }
+
+ /** 兼容老单测的五参构造(无解析器:就地构造)。生产由 Spring 走七参构造。 */
+ public FlowController(TaskService taskService, RuntimeService runtimeService,
+ HistoryService historyService, RepositoryService repositoryService,
+ JdbcTemplate bizJdbc) {
+ this(taskService, runtimeService, historyService, repositoryService, bizJdbc,
+ new com.eip4.flowservice.wf.FormKeyResolver(historyService),
+ new com.eip4.flowservice.wf.StartFormKeyResolver(repositoryService));
}
@PostMapping("/deploy")
@@ -227,8 +242,12 @@ public class FlowController {
}
@PostMapping("/tasks/{taskId}/complete")
- @Operation(summary = "办理任务", description = "complete 任务,可带提交变量。挂起实例的任务会被引擎拒绝(语义回归)")
+ @Operation(summary = "办理任务", description = "complete 任务,可带提交变量与审批意见(comment 经 addComment 记入流程评论供轨迹展示)。挂起实例的任务会被引擎拒绝(语义回归)")
public ResponseEntity complete(@PathVariable String taskId, @RequestBody(required = false) Requests.CompleteRequest req) {
+ // 审批意见落流程评论(对齐老 passProcess 的 addComment;complete 后任务消失,故先记)
+ if (req != null && req.comment != null && !req.comment.isBlank()) {
+ addTaskComment(taskId, req.comment);
+ }
if (req != null && req.variables != null) {
taskService.complete(taskId, req.variables);
} else {
@@ -237,6 +256,18 @@ public class FlowController {
return ResponseEntity.noContent().build();
}
+ /** 记审批意见为流程评论(轨迹经 getProcessInstanceComments 读)。任务不存在则静默跳过。 */
+ private void addTaskComment(String taskId, String comment) {
+ try {
+ var t = taskService.createTaskQuery().taskId(taskId).singleResult();
+ String pid = t != null ? t.getProcessInstanceId() : null;
+ taskService.addComment(taskId, pid, comment);
+ } catch (RuntimeException e) {
+ org.slf4j.LoggerFactory.getLogger(FlowController.class)
+ .warn("[审批意见] addComment 失败 taskId={}: {}", taskId, e.toString());
+ }
+ }
+
@GetMapping("/process/{processInstanceId}")
@Operation(summary = "查实例", description = "查流程实例:运行中返回 ended=false;已结束返回历史实例 ended=true;不存在 404。供 gateway 办理后判定流程是否结束以回写业务状态")
public ResponseEntity processInstance(@PathVariable String processInstanceId) {
@@ -285,6 +316,142 @@ public class FlowController {
return ResponseEntity.ok(t != null ? TaskDto.of(t) : null);
}
+ @GetMapping("/tasks/{taskId}/approval-context")
+ @Operation(summary = "任务审批上下文",
+ description = "聚合返回 WfTemplate 驱动审批界面所需事实:formKey(=view_wftemplate_id,经 FormKeyResolver 历史回补)、"
+ + "businessKey、processInstanceId、taskDefinitionKey、实例是否结束/挂起。任务不存在返回 found=false(前端降级)。"
+ + "运行中任务优先,查不到回退历史任务(供已办查看)。")
+ public ResponseEntity approvalContext(@PathVariable String taskId) {
+ ApprovalContextDto dto = new ApprovalContextDto();
+ dto.taskId = taskId;
+ var t = taskService.createTaskQuery().taskId(taskId).singleResult();
+ if (t != null) {
+ dto.found = true;
+ dto.taskName = t.getName();
+ dto.processInstanceId = t.getProcessInstanceId();
+ dto.processDefinitionId = t.getProcessDefinitionId();
+ dto.taskDefinitionKey = t.getTaskDefinitionKey();
+ dto.suspended = t.isSuspended();
+ dto.formKey = formKeyResolver.resolve(t.getFormKey(), t.getProcessDefinitionId(), t.getTaskDefinitionKey());
+ dto.startFormKey = startFormKeyResolver.resolve(t.getProcessDefinitionId());
+ ProcessInstance pi = runtimeService.createProcessInstanceQuery()
+ .processInstanceId(t.getProcessInstanceId()).singleResult();
+ if (pi != null) {
+ dto.businessKey = pi.getBusinessKey();
+ dto.ended = false;
+ }
+ return ResponseEntity.ok(dto);
+ }
+ // 运行库无 → 历史任务(已办查看仍要解析 WfTemplate 显业务表单/轨迹)
+ HistoricTaskInstance ht = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
+ if (ht == null) {
+ dto.found = false;
+ return ResponseEntity.ok(dto);
+ }
+ dto.found = true;
+ dto.taskName = ht.getName();
+ dto.processInstanceId = ht.getProcessInstanceId();
+ dto.processDefinitionId = ht.getProcessDefinitionId();
+ dto.taskDefinitionKey = ht.getTaskDefinitionKey();
+ dto.formKey = formKeyResolver.resolve(ht.getFormKey(), ht.getProcessDefinitionId(), ht.getTaskDefinitionKey());
+ dto.startFormKey = startFormKeyResolver.resolve(ht.getProcessDefinitionId());
+ var hpi = historyService.createHistoricProcessInstanceQuery()
+ .processInstanceId(ht.getProcessInstanceId()).singleResult();
+ if (hpi != null) {
+ dto.businessKey = hpi.getBusinessKey();
+ dto.ended = hpi.getEndTime() != null;
+ }
+ return ResponseEntity.ok(dto);
+ }
+
+ @PostMapping("/tasks/{taskId}/reject")
+ @Operation(summary = "拒绝(终止流程)",
+ description = "对齐老 ProcessCoreServiceImpl.endProcess:审批拒绝=终止整个流程实例(deleteProcessInstance),"
+ + "记审批意见为评论、置 approveResult=reject 供轨迹。返回 businessKey/processEnded 供 gateway 回写 SYS_DATASTATUS=4(驳回)。")
+ public ResponseEntity