F2-7: 审批办理 UI 后端——trace/delegate 端点增补

- flowable-service:新增 GET /api/flow/process/{id}/trace(历史任务节点+
  审批意见+结果,biz 库不可达时用户名 1s 超时降级),TraceNodeDto;
  biz 数据源加 connectionTimeout/socketTimeout 快速失败
- platform-flow-gateway:FlowableClient 增加 trace/delegate 方法;
  TodoController 增加 /api/flow/process/{id}/trace 和 /api/task/{id}/delegate
  网关透传端点;GatewayRequests.DelegateRequest;TraceNodeDto 镜像
- 单测:TraceAndDelegateTest 3 个(MockRestServiceServer),全套 34/34 通过
- application-dev.yml:eip4.flow.read-timeout-ms=60000 适配慢查询

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 23:09:11 +08:00
parent b0657a7765
commit 6dbb205e94
9 changed files with 279 additions and 2 deletions

View File

@@ -104,6 +104,26 @@ public class FlowableClient {
return post("发起", "/api/flow/process/start", startRequest, ProcessInstanceDto.class);
}
/**
* 查流程轨迹(历史任务节点列表,含办理人姓名/意见/结果)。
* 对应 flowable-service {@code GET /api/flow/process/{processInstanceId}/trace}。
*/
public List<TraceNodeDto> trace(String processInstanceId) {
return execute("轨迹", () -> restClient.get()
.uri("/api/flow/process/{id}/trace", processInstanceId)
.retrieve()
.body(new ParameterizedTypeReference<List<TraceNodeDto>>() {}));
}
/**
* 委托(delegate)任务给指定用户。
* 对应 flowable-service {@code POST /api/flow/tasks/{taskId}/delegate}。
*/
public void delegate(String taskId, String delegateUserId) {
post("委托", "/api/flow/tasks/" + taskId + "/delegate",
Map.of("delegateUserId", delegateUserId), Void.class);
}
/**
* 查流程实例(供办理后判定是否结束以回写业务状态)。
* 实例不存在(404)返回 null;运行中 {@code ended=false},已结束 {@code ended=true}。

View File

@@ -0,0 +1,16 @@
package com.eip4.platform.flowgateway.client;
/**
* 流程轨迹节点 DTO(镜像 flowable-service TraceNodeDto 出参,经网关透传给前端)。
*/
public class TraceNodeDto {
public String taskId;
public String taskName;
public String assignee;
public String assigneeName;
public String comment;
public String result;
public Long startTime;
public Long endTime;
public boolean current;
}

View File

@@ -30,4 +30,9 @@ public final class GatewayRequests {
public String businessKey;
public Map<String, Object> variables;
}
/** 委托(delegate)请求。 */
public static class DelegateRequest {
public String delegateUserId;
}
}

View File

@@ -18,6 +18,7 @@ import com.eip4.platform.flowgateway.aggregate.TodoAggregator;
import com.eip4.platform.flowgateway.aggregate.TodoItem;
import com.eip4.platform.flowgateway.client.FlowableClient;
import com.eip4.platform.flowgateway.client.ProcessInstanceDto;
import com.eip4.platform.flowgateway.client.TraceNodeDto;
import com.eip4.platform.flowgateway.writeback.StatusWriteback;
import io.swagger.v3.oas.annotations.Operation;
@@ -107,6 +108,27 @@ public class TodoController {
return ResponseEntity.ok(flowableClient.start(body));
}
@Operation(summary = "流程轨迹", description = "返回流程实例的历史任务节点(含当前活动节点),按开始时间升序;包含办理人姓名/审批意见/办理结果")
@GetMapping("/api/flow/process/{processInstanceId}/trace")
public ResponseEntity<List<TraceNodeDto>> trace(@PathVariable String processInstanceId) {
List<TraceNodeDto> nodes = flowableClient.trace(processInstanceId);
return ResponseEntity.ok(nodes);
}
@Operation(summary = "委托任务", description = "将任务委托给指定用户(delegateUserId),assignee 变受托人,owner 记原办理人")
@PostMapping("/api/task/{id}/delegate")
public ResponseEntity<Map<String, Object>> delegate(@PathVariable String id,
@RequestBody GatewayRequests.DelegateRequest req) {
if (req == null || req.delegateUserId == null || req.delegateUserId.isBlank()) {
return ResponseEntity.badRequest().build();
}
flowableClient.delegate(id, req.delegateUserId);
Map<String, Object> resp = new HashMap<>();
resp.put("delegated", true);
resp.put("delegateUserId", req.delegateUserId);
return ResponseEntity.ok(resp);
}
/** 实例不存在(已被清理)按"已结束"处理(complete 后无运行实例即流程终结)。 */
private boolean isProcessEnded(String processInstanceId) {
ProcessInstanceDto pi = flowableClient.processInstance(processInstanceId);

View File

@@ -0,0 +1,82 @@
package com.eip4.platform.flowgateway;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.client.RestClient;
import com.eip4.platform.flowgateway.client.FlowGatewayProperties;
import com.eip4.platform.flowgateway.client.FlowableClient;
import com.eip4.platform.flowgateway.client.TraceNodeDto;
/**
* 流程轨迹 + 委托端点网关层单测(MockRestServiceServer 验证 URL 和出参解析)。
*/
class TraceAndDelegateTest {
private FlowGatewayProperties props() {
FlowGatewayProperties p = new FlowGatewayProperties();
p.setBaseUrl("http://localhost:8089");
p.setMaxRetries(0);
p.setRetryBackoffMs(1);
return p;
}
@Test
void trace_正常返回_节点列表解析() {
FlowGatewayProperties p = props();
RestClient.Builder builder = RestClient.builder().baseUrl(p.getBaseUrl());
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
String body = "[{\"taskId\":\"T1\",\"taskName\":\"接收交底(项目部)\",\"assignee\":\"U1\","
+ "\"assigneeName\":\"张三\",\"comment\":\"同意\",\"result\":\"agree\","
+ "\"startTime\":1700000000000,\"endTime\":1700001000000,\"current\":false}]";
server.expect(requestTo("http://localhost:8089/api/flow/process/P1/trace"))
.andRespond(withSuccess(body, MediaType.APPLICATION_JSON));
FlowableClient client = new FlowableClient(builder.build(), p);
List<TraceNodeDto> nodes = client.trace("P1");
assertThat(nodes).hasSize(1);
assertThat(nodes.get(0).taskId).isEqualTo("T1");
assertThat(nodes.get(0).assigneeName).isEqualTo("张三");
assertThat(nodes.get(0).comment).isEqualTo("同意");
assertThat(nodes.get(0).result).isEqualTo("agree");
assertThat(nodes.get(0).current).isFalse();
server.verify();
}
@Test
void trace_空列表_正常返回() {
FlowGatewayProperties p = props();
RestClient.Builder builder = RestClient.builder().baseUrl(p.getBaseUrl());
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
server.expect(requestTo("http://localhost:8089/api/flow/process/P-EMPTY/trace"))
.andRespond(withSuccess("[]", MediaType.APPLICATION_JSON));
FlowableClient client = new FlowableClient(builder.build(), p);
List<TraceNodeDto> nodes = client.trace("P-EMPTY");
assertThat(nodes).isEmpty();
server.verify();
}
@Test
void delegate_正常_发送delegateUserId() {
FlowGatewayProperties p = props();
RestClient.Builder builder = RestClient.builder().baseUrl(p.getBaseUrl());
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
server.expect(requestTo("http://localhost:8089/api/flow/tasks/T1/delegate"))
.andRespond(withSuccess("{}", MediaType.APPLICATION_JSON));
FlowableClient client = new FlowableClient(builder.build(), p);
// 不抛异常即为通过
client.delegate("T1", "U2");
server.verify();
}
}