feat: wire my started workflow tasks
This commit is contained in:
@@ -42,6 +42,9 @@ public class FlowableClient {
|
||||
private static final ParameterizedTypeReference<List<FlowTaskDto>> TASK_LIST =
|
||||
new ParameterizedTypeReference<>() {
|
||||
};
|
||||
private static final ParameterizedTypeReference<List<ProcessInstanceDto>> PROCESS_LIST =
|
||||
new ParameterizedTypeReference<>() {
|
||||
};
|
||||
|
||||
private final RestClient restClient;
|
||||
private final FlowGatewayProperties props;
|
||||
@@ -181,6 +184,28 @@ public class FlowableClient {
|
||||
.body(ProcessInstanceDto.class));
|
||||
}
|
||||
|
||||
/** 按发起人查询历史流程实例。对应 flowable-service {@code GET /api/flow/process/started}。 */
|
||||
public List<ProcessInstanceDto> started(String startedBy, int firstResult, int maxResults) {
|
||||
return execute("发起流程列表", () -> restClient.get()
|
||||
.uri(uri -> uri.path("/api/flow/process/started")
|
||||
.queryParam("startedBy", startedBy == null ? "" : startedBy)
|
||||
.queryParam("firstResult", firstResult)
|
||||
.queryParam("maxResults", maxResults)
|
||||
.build())
|
||||
.retrieve()
|
||||
.body(PROCESS_LIST));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起人撤回。对应 flowable-service {@code POST /api/flow/process/{processInstanceId}/withdraw}。
|
||||
* 返回体含 businessKey/targetKey,供 gateway 回写 SYS_DATASTATUS=5。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> withdraw(String processInstanceId, String comment) {
|
||||
return post("撤回", "/api/flow/process/" + processInstanceId + "/withdraw",
|
||||
comment == null ? Map.of() : Map.of("comment", comment), Map.class);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 内部:重试 + 异常分类
|
||||
|
||||
private List<FlowTaskDto> get(String op, java.util.function.Function<UriBuilder, java.net.URI> uriFn) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.eip4.platform.flowgateway.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* flowable-service 发起流程返回的实例 DTO(贴 {@code flowable-service} 的 {@code ProcessInstanceDto})。
|
||||
*
|
||||
@@ -10,7 +12,13 @@ public class ProcessInstanceDto {
|
||||
public String id;
|
||||
public String processDefinitionId;
|
||||
public String processDefinitionKey;
|
||||
public String processDefinitionName;
|
||||
public String businessKey;
|
||||
public String startUserId;
|
||||
public Long startTimeMillis;
|
||||
public Long endTimeMillis;
|
||||
public List<String> activeTaskNames = List.of();
|
||||
public List<String> activeTaskAssignees = List.of();
|
||||
public boolean ended;
|
||||
public boolean suspended;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ public final class GatewayRequests {
|
||||
public String processDefinitionKey;
|
||||
public String processDefinitionId;
|
||||
public String businessKey;
|
||||
/** 兼容无登录态调用;正常页面请求由网关用 AuthPrincipal.userId() 覆盖。 */
|
||||
public String startUserId;
|
||||
public Map<String, Object> variables;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,12 +27,14 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.eip4.platform.auth.security.AuthPrincipal;
|
||||
import com.eip4.platform.flowgateway.aggregate.BusinessSummaryService;
|
||||
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 com.dsasp.server.common.workflow.service.ProcessCoreService;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -66,13 +68,16 @@ public class TodoController {
|
||||
private final TodoAggregator todoAggregator;
|
||||
private final FlowableClient flowableClient;
|
||||
private final StatusWriteback statusWriteback;
|
||||
private final BusinessSummaryService businessSummaryService;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public TodoController(TodoAggregator todoAggregator, FlowableClient flowableClient,
|
||||
StatusWriteback statusWriteback, JdbcTemplate jdbcTemplate) {
|
||||
StatusWriteback statusWriteback, BusinessSummaryService businessSummaryService,
|
||||
JdbcTemplate jdbcTemplate) {
|
||||
this.todoAggregator = todoAggregator;
|
||||
this.flowableClient = flowableClient;
|
||||
this.statusWriteback = statusWriteback;
|
||||
this.businessSummaryService = businessSummaryService;
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@@ -117,6 +122,22 @@ public class TodoController {
|
||||
return amisCrud(rows, params);
|
||||
}
|
||||
|
||||
/** 转换页「流程管理/我的发起任务」兼容端点;列名对齐 VIEW_ACT_PROCESS_SEARCH。 */
|
||||
@Operation(summary = "转换页我的发起任务数据(amis)", description = "返回老 VIEW_ACT_PROCESS 字段形态,底层走 Flowable startedBy 流程实例口径")
|
||||
@GetMapping("/api/workflow/process/started-amis")
|
||||
public Map<String, Object> startedAmis(@AuthenticationPrincipal AuthPrincipal principal,
|
||||
@RequestParam Map<String, String> params) {
|
||||
String userId = principal == null ? trim(params.get("INITUSERID")) : principal.userId();
|
||||
List<ProcessInstanceDto> raw = flowableClient.started(userId, 0, LEGACY_TASK_FETCH_LIMIT);
|
||||
List<Map<String, Object>> rows = raw.stream()
|
||||
.map(this::startedProcessRow)
|
||||
.filter(row -> matchesStartedFilters(row, params))
|
||||
.toList();
|
||||
resolveInitiatorDisplayNames(rows);
|
||||
resolveAssigneeDisplayNames(rows);
|
||||
return amisCrud(rows, params);
|
||||
}
|
||||
|
||||
/** 转换页「流程管理/已办任务」兼容端点;列名对齐 VIEW_ACT_TASK_COMPLETE_SEARCH/VIEW_ACT_FTASK_COMPLETE_SEARCH。 */
|
||||
@Operation(summary = "转换页已办任务数据(amis)", description = "返回老 VIEW_ACT_TASK 字段形态,底层走 /api/done 聚合口径")
|
||||
@GetMapping("/api/workflow/tasks/done-amis")
|
||||
@@ -155,15 +176,43 @@ public class TodoController {
|
||||
|
||||
@Operation(summary = "发起流程", description = "透传 flowable-service /process/start;按 processDefinitionKey 或 id 发起,可带 businessKey 与变量")
|
||||
@PostMapping("/api/process/start")
|
||||
public ResponseEntity<ProcessInstanceDto> start(@RequestBody GatewayRequests.StartRequest req) {
|
||||
public ResponseEntity<ProcessInstanceDto> start(@AuthenticationPrincipal AuthPrincipal principal,
|
||||
@RequestBody GatewayRequests.StartRequest req) {
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
body.put("processDefinitionKey", req.processDefinitionKey);
|
||||
body.put("processDefinitionId", req.processDefinitionId);
|
||||
body.put("businessKey", req.businessKey);
|
||||
body.put("startUserId", principal == null ? req.startUserId : principal.userId());
|
||||
body.put("variables", req.variables);
|
||||
return ResponseEntity.ok(flowableClient.start(body));
|
||||
}
|
||||
|
||||
@Operation(summary = "发起人撤回流程",
|
||||
description = "透传 flowable-service /process/{processInstanceId}/withdraw;成功后回写 SYS_DATASTATUS=5(重新提交)。")
|
||||
@PostMapping("/api/workflow/process/{processInstanceId}/withdraw")
|
||||
public ResponseEntity<Map<String, Object>> withdraw(@PathVariable String processInstanceId,
|
||||
@RequestBody(required = false) GatewayRequests.ApprovalActionRequest req) {
|
||||
Map<String, Object> engine = flowableClient.withdraw(processInstanceId, req == null ? null : req.comment);
|
||||
String businessKey = req != null && notBlank(req.businessKey)
|
||||
? req.businessKey
|
||||
: rowString(engine, "businessKey", "BUSINESSKEY");
|
||||
String table = req == null ? null : req.tableName;
|
||||
boolean written = false;
|
||||
if (notBlank(businessKey)) {
|
||||
statusWriteback.updateStatus(businessKey, table, ProcessCoreService.STATUS_RESUBMIT);
|
||||
written = true;
|
||||
}
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
resp.put("status", 0);
|
||||
resp.put("msg", "撤回成功");
|
||||
resp.put("withdrawn", true);
|
||||
resp.put("targetKey", rowString(engine, "targetKey", "TARGETKEY"));
|
||||
resp.put("businessKey", businessKey);
|
||||
resp.put("processInstanceId", processInstanceId);
|
||||
resp.put("statusWritten", written);
|
||||
return ResponseEntity.ok(resp);
|
||||
}
|
||||
|
||||
@Operation(summary = "流程轨迹", description = "返回流程实例的历史任务节点(含当前活动节点),按开始时间升序;包含办理人姓名/审批意见/办理结果")
|
||||
@GetMapping("/api/flow/process/{processInstanceId}/trace")
|
||||
public ResponseEntity<List<TraceNodeDto>> trace(@PathVariable String processInstanceId) {
|
||||
@@ -249,6 +298,36 @@ public class TodoController {
|
||||
return row;
|
||||
}
|
||||
|
||||
private Map<String, Object> startedProcessRow(ProcessInstanceDto pi) {
|
||||
Map<String, Object> row = new LinkedHashMap<>();
|
||||
String processId = trim(pi.id);
|
||||
BusinessSummaryService.Summary summary = businessSummaryService.summarize(pi.businessKey);
|
||||
Map<String, Object> fields = summary.fields() == null ? Map.of() : summary.fields();
|
||||
row.put("VIEW_ACT_PROCESS_ID", processId);
|
||||
row.put("TITLE", titleOf(pi, fields));
|
||||
row.put("PROCESSNAME", firstNonBlank(pi.processDefinitionName, processName(pi.processDefinitionId),
|
||||
pi.processDefinitionKey));
|
||||
row.put("INITUSERID", trim(pi.startUserId));
|
||||
row.put("INITUSERID_DISPLAY__", trim(pi.startUserId));
|
||||
int status = statusOf(pi);
|
||||
row.put("WFSTATUS", status);
|
||||
row.put("STARTTIME", formatMillis(pi.startTimeMillis));
|
||||
row.put("ENDTIME", formatMillis(pi.endTimeMillis));
|
||||
String assigneeIds = pi.activeTaskAssignees == null ? "" : pi.activeTaskAssignees.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(String::trim)
|
||||
.filter(s -> !s.isBlank())
|
||||
.distinct()
|
||||
.collect(java.util.stream.Collectors.joining(","));
|
||||
row.put("ASSIGNEEIDS", assigneeIds);
|
||||
row.put("ASSIGNEENAME", assigneeIds);
|
||||
row.put("processInstanceId", processId);
|
||||
row.put("businessKey", pi.businessKey);
|
||||
row.put("businessTable", summary.tableName());
|
||||
row.put("businessSummary", fields);
|
||||
return row;
|
||||
}
|
||||
|
||||
private void resolveInitiatorDisplayNames(List<Map<String, Object>> rows) {
|
||||
Set<String> userIds = new LinkedHashSet<>();
|
||||
for (Map<String, Object> row : rows) {
|
||||
@@ -295,6 +374,65 @@ public class TodoController {
|
||||
}
|
||||
}
|
||||
|
||||
private void resolveAssigneeDisplayNames(List<Map<String, Object>> rows) {
|
||||
Set<String> userIds = new LinkedHashSet<>();
|
||||
for (Map<String, Object> row : rows) {
|
||||
String raw = trim(Objects.toString(row.get("ASSIGNEEIDS"), ""));
|
||||
if (raw == null || raw.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
for (String part : raw.split(",")) {
|
||||
String id = trim(part);
|
||||
if (id != null && !id.isBlank()) {
|
||||
userIds.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (userIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, String> displayById = new HashMap<>();
|
||||
List<String> ids = new ArrayList<>(userIds);
|
||||
for (int from = 0; from < ids.size(); from += 200) {
|
||||
List<String> batch = ids.subList(from, Math.min(from + 200, ids.size()));
|
||||
String placeholders = String.join(",", Collections.nCopies(batch.size(), "?"));
|
||||
try {
|
||||
List<Map<String, Object>> matches = jdbcTemplate.queryForList(
|
||||
"SELECT TRIM(VIEW_SYS_USER_ID) AS USER_ID, DISPLAYNAME AS DISPLAY_NAME "
|
||||
+ "FROM VIEW_SYS_USER WHERE TRIM(VIEW_SYS_USER_ID) IN (" + placeholders + ")",
|
||||
batch.toArray());
|
||||
if (matches == null) {
|
||||
continue;
|
||||
}
|
||||
for (Map<String, Object> match : matches) {
|
||||
String userId = rowString(match, "USER_ID", "user_id", "ID", "id");
|
||||
String displayName = rowString(match, "DISPLAY_NAME", "display_name", "DISPLAYNAME", "displayname");
|
||||
if (userId != null && !userId.isBlank() && displayName != null && !displayName.isBlank()) {
|
||||
displayById.put(userId, displayName);
|
||||
}
|
||||
}
|
||||
} catch (DataAccessException ignored) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (Map<String, Object> row : rows) {
|
||||
String raw = trim(Objects.toString(row.get("ASSIGNEEIDS"), ""));
|
||||
if (raw == null || raw.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
List<String> names = new ArrayList<>();
|
||||
for (String part : raw.split(",")) {
|
||||
String id = trim(part);
|
||||
if (id != null && !id.isBlank()) {
|
||||
names.add(displayById.getOrDefault(id, id));
|
||||
}
|
||||
}
|
||||
row.put("ASSIGNEENAME", String.join(",", names));
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean matchesLegacyFilters(Map<String, Object> row, Map<String, String> params, boolean done) {
|
||||
return contains(row, params, "TITLE")
|
||||
&& contains(row, params, "PROCESSNAME")
|
||||
@@ -306,6 +444,16 @@ public class TodoController {
|
||||
&& (!done || equalsIfPresent(row, params, "WFSTATUS"));
|
||||
}
|
||||
|
||||
private static boolean matchesStartedFilters(Map<String, Object> row, Map<String, String> params) {
|
||||
return contains(row, params, "TITLE")
|
||||
&& contains(row, params, "PROCESSNAME")
|
||||
&& equalsIfPresent(row, params, "INITUSERID")
|
||||
&& equalsIfPresent(row, params, "WFSTATUS")
|
||||
&& contains(row, params, "ASSIGNEENAME")
|
||||
&& inDateRange(row.get("STARTTIME"), params.get("STARTTIME"))
|
||||
&& inDateRange(row.get("ENDTIME"), params.get("ENDTIME"));
|
||||
}
|
||||
|
||||
private static boolean contains(Map<String, Object> row, Map<String, String> params, String key) {
|
||||
String needle = trim(params.get(key));
|
||||
if (needle == null || needle.isBlank()) {
|
||||
@@ -394,6 +542,39 @@ public class TodoController {
|
||||
return item.taskName;
|
||||
}
|
||||
|
||||
private static String titleOf(ProcessInstanceDto pi, Map<String, Object> summary) {
|
||||
if (summary != null) {
|
||||
for (String key : List.of("TITLE", "NAME", "SUBJECT", "NO", "SERIALNO", "FORMNO")) {
|
||||
Object value = summary.get(key);
|
||||
if (value == null) {
|
||||
value = summary.get(key.toLowerCase());
|
||||
}
|
||||
String s = trim(Objects.toString(value, ""));
|
||||
if (s != null && !s.isBlank()) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pi.businessKey != null && !pi.businessKey.isBlank()) {
|
||||
return pi.businessKey;
|
||||
}
|
||||
return firstNonBlank(pi.processDefinitionName, pi.processDefinitionKey, pi.id);
|
||||
}
|
||||
|
||||
private int statusOf(ProcessInstanceDto pi) {
|
||||
if (pi.businessKey != null && !pi.businessKey.isBlank()) {
|
||||
try {
|
||||
Integer status = statusWriteback.getStatus(pi.businessKey);
|
||||
if (status != null) {
|
||||
return status;
|
||||
}
|
||||
} catch (RuntimeException ignored) {
|
||||
// 状态表不可读时按流程是否结束降级。
|
||||
}
|
||||
}
|
||||
return pi.ended ? ProcessCoreService.STATUS_PASS : ProcessCoreService.STATUS_PROCESSING;
|
||||
}
|
||||
|
||||
private static String summaryString(TodoItem item, String... keys) {
|
||||
if (item.businessSummary == null || item.businessSummary.isEmpty()) {
|
||||
return null;
|
||||
@@ -422,6 +603,16 @@ public class TodoController {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String firstNonBlank(String... values) {
|
||||
for (String value : values) {
|
||||
String s = trim(value);
|
||||
if (s != null && !s.isBlank()) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String processName(String processDefinitionId) {
|
||||
String s = trim(processDefinitionId);
|
||||
if (s == null || s.isBlank()) {
|
||||
|
||||
@@ -91,6 +91,7 @@ public class ProcessCoreServiceBridge {
|
||||
Map<String, Object> startRequest = new LinkedHashMap<>();
|
||||
startRequest.put("processDefinitionKey", processName);
|
||||
startRequest.put("businessKey", businessKey);
|
||||
startRequest.put("startUserId", currentUser);
|
||||
startRequest.put("variables", vars);
|
||||
|
||||
ProcessInstanceDto inst = flowableClient.start(startRequest);
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.eip4.platform.flowgateway.client.FlowServiceUnavailableException;
|
||||
import com.eip4.platform.flowgateway.client.FlowTaskDto;
|
||||
import com.eip4.platform.flowgateway.client.FlowGatewayProperties;
|
||||
import com.eip4.platform.flowgateway.client.FlowableClient;
|
||||
import com.eip4.platform.flowgateway.client.ProcessInstanceDto;
|
||||
|
||||
/**
|
||||
* Flowable REST 客户端单测:连接失败重试→降级 503 语义、业务错(409)透传不重试、404→null、正常待办解析。
|
||||
@@ -125,4 +126,42 @@ class FlowableClientTest {
|
||||
assertThat(client.processInstance("P-MISSING")).isNull();
|
||||
server.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
void 发起流程列表_按startedBy下发参数() {
|
||||
FlowGatewayProperties p = props();
|
||||
RestClient.Builder builder = RestClient.builder().baseUrl(p.getBaseUrl());
|
||||
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
|
||||
String body = "[{\"id\":\"P1\",\"processDefinitionKey\":\"NOTICE\",\"businessKey\":\"BK-1\","
|
||||
+ "\"startUserId\":\"U1\",\"startTimeMillis\":1700000000000,\"ended\":false}]";
|
||||
server.expect(requestTo("http://localhost:8089/api/flow/process/started?startedBy=U1&firstResult=0&maxResults=1000"))
|
||||
.andExpect(method(HttpMethod.GET))
|
||||
.andRespond(withSuccess(body, MediaType.APPLICATION_JSON));
|
||||
FlowableClient client = new FlowableClient(builder.build(), p);
|
||||
|
||||
List<ProcessInstanceDto> list = client.started("U1", 0, 1000);
|
||||
|
||||
assertThat(list).hasSize(1);
|
||||
assertThat(list.get(0).id).isEqualTo("P1");
|
||||
assertThat(list.get(0).businessKey).isEqualTo("BK-1");
|
||||
server.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
void 撤回流程_POST实例撤回端点并传评论() {
|
||||
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/P1/withdraw"))
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andExpect(jsonPath("$.comment").value("主动召回"))
|
||||
.andRespond(withSuccess("{\"withdrawn\":true,\"businessKey\":\"BK-1\"}", MediaType.APPLICATION_JSON));
|
||||
FlowableClient client = new FlowableClient(builder.build(), p);
|
||||
|
||||
Map<String, Object> result = client.withdraw("P1", "主动召回");
|
||||
|
||||
assertThat(result).containsEntry("withdrawn", true);
|
||||
assertThat(result).containsEntry("businessKey", "BK-1");
|
||||
server.verify();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ class ProcessCoreServiceBridgeTest {
|
||||
Map<String, Object> req = reqCap.getValue();
|
||||
assertThat(req.get("processDefinitionKey")).isEqualTo("收房变更申请");
|
||||
assertThat(req.get("businessKey")).isEqualTo("BK-1");
|
||||
assertThat(req.get("startUserId")).isEqualTo("U-007");
|
||||
|
||||
Object varsObj = req.get("variables");
|
||||
assertThat(varsObj).isInstanceOf(Map.class);
|
||||
|
||||
@@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -11,13 +12,17 @@ import java.time.ZoneId;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import com.eip4.platform.auth.security.AuthPrincipal;
|
||||
import com.eip4.platform.flowgateway.aggregate.BusinessSummaryService;
|
||||
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.web.GatewayRequests;
|
||||
import com.eip4.platform.flowgateway.web.TodoController;
|
||||
import com.eip4.platform.flowgateway.writeback.StatusWriteback;
|
||||
|
||||
@@ -25,9 +30,12 @@ import com.eip4.platform.flowgateway.writeback.StatusWriteback;
|
||||
class TodoControllerAmisTest {
|
||||
|
||||
private final TodoAggregator aggregator = mock(TodoAggregator.class);
|
||||
private final FlowableClient flowableClient = mock(FlowableClient.class);
|
||||
private final StatusWriteback statusWriteback = mock(StatusWriteback.class);
|
||||
private final BusinessSummaryService businessSummaryService = mock(BusinessSummaryService.class);
|
||||
private final JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
|
||||
private final TodoController controller = new TodoController(
|
||||
aggregator, mock(FlowableClient.class), mock(StatusWriteback.class), jdbcTemplate);
|
||||
aggregator, flowableClient, statusWriteback, businessSummaryService, jdbcTemplate);
|
||||
|
||||
private static AuthPrincipal principal() {
|
||||
return new AuthPrincipal("U1", "u1", "张三", "D1", "O1", List.of("R1"));
|
||||
@@ -129,4 +137,72 @@ class TodoControllerAmisTest {
|
||||
assertThat(items).hasSize(1);
|
||||
assertThat(items.get(0)).containsEntry("TITLE", "区间内");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void startedAmis_映射我的发起任务并支持状态过滤() {
|
||||
ProcessInstanceDto p1 = process("PI-1", "BK-1", false, epochMillis(2026, 6, 14, 11, 23));
|
||||
ProcessInstanceDto p2 = process("PI-2", "BK-2", true, epochMillis(2026, 6, 13, 10, 0));
|
||||
when(flowableClient.started("U1", 0, 1_000)).thenReturn(List.of(p1, p2));
|
||||
when(businessSummaryService.summarize("BK-1"))
|
||||
.thenReturn(new BusinessSummaryService.Summary("OA_NOTICE", Map.of("TITLE", "会议通知")));
|
||||
when(businessSummaryService.summarize("BK-2"))
|
||||
.thenReturn(new BusinessSummaryService.Summary("OA_NOTICE", Map.of("TITLE", "结束流程")));
|
||||
when(statusWriteback.getStatus("BK-1")).thenReturn(2);
|
||||
when(statusWriteback.getStatus("BK-2")).thenReturn(3);
|
||||
when(jdbcTemplate.queryForList(anyString(), any(Object[].class)))
|
||||
.thenReturn(List.of(Map.of("USER_ID", "U1", "DISPLAY_NAME", "张三"),
|
||||
Map.of("USER_ID", "U2", "DISPLAY_NAME", "李四")));
|
||||
|
||||
Map<String, Object> resp = controller.startedAmis(principal(),
|
||||
Map.of("WFSTATUS", "2", "page", "1", "perPage", "10"));
|
||||
|
||||
Map<String, Object> data = (Map<String, Object>) resp.get("data");
|
||||
List<Map<String, Object>> items = (List<Map<String, Object>>) data.get("items");
|
||||
assertThat(data).containsEntry("total", 1);
|
||||
Map<String, Object> row = items.get(0);
|
||||
assertThat(row).containsEntry("VIEW_ACT_PROCESS_ID", "PI-1");
|
||||
assertThat(row).containsEntry("TITLE", "会议通知");
|
||||
assertThat(row).containsEntry("PROCESSNAME", "通知审批");
|
||||
assertThat(row).containsEntry("INITUSERID", "U1");
|
||||
assertThat(row).containsEntry("INITUSERID_DISPLAY__", "张三");
|
||||
assertThat(row).containsEntry("ASSIGNEENAME", "李四");
|
||||
assertThat(row).containsEntry("WFSTATUS", 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void start_透传登录用户为流程发起人() {
|
||||
GatewayRequests.StartRequest req = new GatewayRequests.StartRequest();
|
||||
req.processDefinitionKey = "NOTICE_APPROVAL";
|
||||
req.businessKey = "BK-1";
|
||||
req.startUserId = "BODY-USER";
|
||||
req.variables = Map.of("title", "会议通知");
|
||||
ProcessInstanceDto dto = new ProcessInstanceDto();
|
||||
dto.id = "PI-1";
|
||||
when(flowableClient.start(any())).thenReturn(dto);
|
||||
|
||||
controller.start(principal(), req);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<Map<String, Object>> body = ArgumentCaptor.forClass(Map.class);
|
||||
verify(flowableClient).start(body.capture());
|
||||
assertThat(body.getValue()).containsEntry("processDefinitionKey", "NOTICE_APPROVAL");
|
||||
assertThat(body.getValue()).containsEntry("businessKey", "BK-1");
|
||||
assertThat(body.getValue()).containsEntry("startUserId", "U1");
|
||||
assertThat(body.getValue().get("variables")).isEqualTo(Map.of("title", "会议通知"));
|
||||
}
|
||||
|
||||
private static ProcessInstanceDto process(String id, String businessKey, boolean ended, long startMillis) {
|
||||
ProcessInstanceDto dto = new ProcessInstanceDto();
|
||||
dto.id = id;
|
||||
dto.processDefinitionId = "通知审批:1:100";
|
||||
dto.processDefinitionKey = "NOTICE_APPROVAL";
|
||||
dto.businessKey = businessKey;
|
||||
dto.startUserId = "U1";
|
||||
dto.startTimeMillis = startMillis;
|
||||
dto.endTimeMillis = ended ? startMillis + 60_000 : null;
|
||||
dto.activeTaskAssignees = ended ? List.of() : List.of("U2");
|
||||
dto.ended = ended;
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user