feat: wire process monitor actions
This commit is contained in:
@@ -382,6 +382,50 @@ public class FlowController {
|
||||
return ResponseEntity.ok(resp);
|
||||
}
|
||||
|
||||
@PostMapping("/process/{processInstanceId}/terminate")
|
||||
@Operation(summary = "结束运行中流程实例",
|
||||
description = "对齐老 ProcessMonitorComponentNew:流程监控页按实例结束活动流程。仅运行中且有活动任务的流程可结束;"
|
||||
+ "操作会记录流程评论、设置 approveResult=invalid,并 deleteProcessInstance。")
|
||||
public ResponseEntity<Map<String, Object>> terminateProcessInstance(@PathVariable String processInstanceId,
|
||||
@RequestBody(required = false) Requests.ActionRequest req) {
|
||||
String pid = trimToNull(processInstanceId);
|
||||
if (pid == null) {
|
||||
return ResponseEntity.badRequest().body(errorBody("processInstanceId 不能为空"));
|
||||
}
|
||||
ProcessInstance pi = runtimeService.createProcessInstanceQuery()
|
||||
.processInstanceId(pid).singleResult();
|
||||
if (pi == null) {
|
||||
return ResponseEntity.status(org.springframework.http.HttpStatus.CONFLICT)
|
||||
.body(errorBody("该流程已结束"));
|
||||
}
|
||||
List<org.flowable.task.api.Task> activeTasks = taskService.createTaskQuery()
|
||||
.processInstanceId(pid).active().list();
|
||||
if (activeTasks == null || activeTasks.isEmpty()) {
|
||||
return ResponseEntity.status(org.springframework.http.HttpStatus.CONFLICT)
|
||||
.body(errorBody("该流程已结束"));
|
||||
}
|
||||
String comment = firstNonBlank(req == null ? null : req.comment, "流程有误作废处理");
|
||||
for (org.flowable.task.api.Task task : activeTasks) {
|
||||
if (task.getId() != null) {
|
||||
taskService.addComment(task.getId(), pid, comment);
|
||||
}
|
||||
}
|
||||
try {
|
||||
runtimeService.setVariable(pid, "approveResult", "invalid");
|
||||
} catch (RuntimeException ignore) {
|
||||
/* 变量写入失败不阻断终止 */
|
||||
}
|
||||
String businessKey = pi.getBusinessKey();
|
||||
runtimeService.deleteProcessInstance(pid, comment);
|
||||
Map<String, Object> resp = new java.util.LinkedHashMap<>();
|
||||
resp.put("terminated", true);
|
||||
resp.put("processEnded", true);
|
||||
resp.put("processInstanceId", pid);
|
||||
resp.put("businessKey", businessKey);
|
||||
resp.put("activeTaskCount", activeTasks.size());
|
||||
return ResponseEntity.ok(resp);
|
||||
}
|
||||
|
||||
@PostMapping("/tasks/{taskId}/delegate")
|
||||
@Operation(summary = "委托任务", description = "委托给指定用户:assignee 变为受托人,owner 记原办理人")
|
||||
public ResponseEntity<TaskDto> delegate(@PathVariable String taskId, @RequestBody Requests.DelegateRequest req) {
|
||||
|
||||
@@ -156,6 +156,49 @@ class FlowControllerTest {
|
||||
verify(historyService, never()).deleteHistoricProcessInstance(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 结束运行中流程实例_记录评论并删除实例() throws Exception {
|
||||
ProcessInstance pi = org.mockito.Mockito.mock(ProcessInstance.class);
|
||||
when(pi.getBusinessKey()).thenReturn("BK-END");
|
||||
when(runtimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery);
|
||||
when(processInstanceQuery.processInstanceId("PI-END")).thenReturn(processInstanceQuery);
|
||||
when(processInstanceQuery.singleResult()).thenReturn(pi);
|
||||
|
||||
Task task = org.mockito.Mockito.mock(Task.class);
|
||||
when(task.getId()).thenReturn("T-END");
|
||||
when(taskService.createTaskQuery()).thenReturn(taskQuery);
|
||||
when(taskQuery.processInstanceId("PI-END")).thenReturn(taskQuery);
|
||||
when(taskQuery.active()).thenReturn(taskQuery);
|
||||
when(taskQuery.list()).thenReturn(java.util.List.of(task));
|
||||
|
||||
mvc.perform(post("/api/flow/process/PI-END/terminate")
|
||||
.contentType("application/json")
|
||||
.content("{}"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.terminated").value(true))
|
||||
.andExpect(jsonPath("$.businessKey").value("BK-END"))
|
||||
.andExpect(jsonPath("$.activeTaskCount").value(1));
|
||||
|
||||
verify(taskService).addComment("T-END", "PI-END", "流程有误作废处理");
|
||||
verify(runtimeService).setVariable("PI-END", "approveResult", "invalid");
|
||||
verify(runtimeService).deleteProcessInstance("PI-END", "流程有误作废处理");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 结束已结束流程实例_返回409且不删除() throws Exception {
|
||||
when(runtimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery);
|
||||
when(processInstanceQuery.processInstanceId("PI-DONE")).thenReturn(processInstanceQuery);
|
||||
when(processInstanceQuery.singleResult()).thenReturn(null);
|
||||
|
||||
mvc.perform(post("/api/flow/process/PI-DONE/terminate")
|
||||
.contentType("application/json")
|
||||
.content("{}"))
|
||||
.andExpect(status().isConflict())
|
||||
.andExpect(jsonPath("$.msg").value("该流程已结束"));
|
||||
|
||||
verify(runtimeService, never()).deleteProcessInstance(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 撤回流程_移动回起始节点并挂起实例() throws Exception {
|
||||
Task task = org.mockito.Mockito.mock(Task.class);
|
||||
|
||||
@@ -94,6 +94,14 @@ public final class EngineclassDelta {
|
||||
registerMutator("com.dsasp.client.wf.ui.process.monitor.ProcessFormRemoveComponent",
|
||||
EngineclassDelta::processFormRemoveCrudAnchor);
|
||||
|
||||
// 流程监控:ProcessMonitorComponentNew 原有「处理 / 高级处理 / 结束流程」。
|
||||
// EIP4 当前只注入真实可用的「处理」明细查看与「结束流程」;高级处理(Groovy)需权限/审计另案。
|
||||
register("com.dsasp.client.wf.ui.process.monitor.ProcessMonitorComponentNew",
|
||||
EngineclassDelta::processMonitorDetailButton,
|
||||
EngineclassDelta::processMonitorTerminateButton);
|
||||
registerMutator("com.dsasp.client.wf.ui.process.monitor.ProcessMonitorComponentNew",
|
||||
EngineclassDelta::processMonitorCrudAnchor);
|
||||
|
||||
// 消息查看:MessageReceiveView/MessageSendView 在默认 GridTemplateComponent 之上加「查看」按钮。
|
||||
// 收到消息按 SYS_MESSAGEUSER_ID 打开并置已读;已发送消息按 SYS_MESSAGE_ID 打开只读详情。
|
||||
register("com.dsasp.client.tools.message.MessageReceiveView",
|
||||
@@ -415,6 +423,63 @@ public final class EngineclassDelta {
|
||||
}
|
||||
}
|
||||
|
||||
/** 流程监控「处理」:当前 EIP4 复用只读审批详情,承载流程监控明细查看。 */
|
||||
private static Map<String, Object> processMonitorDetailButton(String pkField) {
|
||||
Map<String, Object> args = mapOf(
|
||||
"taskName", "${selectedItems[0].TITLE || '流程监控明细'}",
|
||||
"processInstanceId", selectedSingleFieldExpr(pkField),
|
||||
"businessKey", "${selectedItems[0].businessKey || selectedItems[0].BUSINESSKEY || ''}",
|
||||
"businessTable", "${selectedItems[0].businessTable || selectedItems[0].BUSINESSTABLE || ''}",
|
||||
"businessSummary", "${selectedItems[0].businessSummary || {}}",
|
||||
"readOnly", true,
|
||||
"mode", "read");
|
||||
Map<String, Object> action = mapOf(
|
||||
"actionType", "openApprovalDrawer",
|
||||
"args", args);
|
||||
Map<String, Object> btn = new LinkedHashMap<>();
|
||||
btn.put("type", "button");
|
||||
btn.put("id", "处理");
|
||||
btn.put("label", "处理");
|
||||
btn.put("icon", "fa fa-edit");
|
||||
btn.put("disabledOn", "${!selectedItems || selectedItems.length !== 1}");
|
||||
btn.put("onEvent", mapOf("click", mapOf("actions", List.of(action))));
|
||||
return btn;
|
||||
}
|
||||
|
||||
/** 流程监控「结束流程」:按流程实例作废活动流程。 */
|
||||
private static Map<String, Object> processMonitorTerminateButton(String pkField) {
|
||||
Map<String, Object> btn = new LinkedHashMap<>();
|
||||
btn.put("type", "button");
|
||||
btn.put("id", "结束流程");
|
||||
btn.put("label", "结束流程");
|
||||
btn.put("icon", "fa fa-ban");
|
||||
btn.put("level", "danger");
|
||||
btn.put("actionType", "ajax");
|
||||
btn.put("disabledOn", "${!selectedItems || selectedItems.length !== 1}");
|
||||
btn.put("confirmText", "确认结束选中的流程?");
|
||||
btn.put("api", mapOf(
|
||||
"method", "post",
|
||||
"url", "/api/workflow/process/" + selectedSingleFieldExpr(pkField) + "/terminate",
|
||||
"data", mapOf(
|
||||
"comment", "流程有误作废处理",
|
||||
"businessKey", "${selectedItems[0].businessKey || selectedItems[0].BUSINESSKEY || ''}",
|
||||
"tableName", "${selectedItems[0].businessTable || selectedItems[0].BUSINESSTABLE || ''}")));
|
||||
btn.put("reload", "process-monitor-crud");
|
||||
return btn;
|
||||
}
|
||||
|
||||
/** 流程监控 CRUD 刷新锚点,供结束流程后精准 reload。 */
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void processMonitorCrudAnchor(Map<String, Object> schema, ConversionResult result) {
|
||||
Object bodyObj = schema.get("body");
|
||||
if (bodyObj instanceof Map<?, ?> body && "crud".equals(body.get("type"))) {
|
||||
((Map<String, Object>) bodyObj).putIfAbsent("id", "process-monitor-crud");
|
||||
if (result != null) {
|
||||
result.note("engineclass[ProcessMonitorComponentNew] 设置流程监控 CRUD 刷新锚点");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, Object> approvalDrawerButton(String label, String icon, String pkField,
|
||||
boolean readOnly) {
|
||||
Map<String, Object> args = mapOf(
|
||||
|
||||
@@ -1112,6 +1112,47 @@ class TemplateToAmisConverterTest {
|
||||
assertEquals("主动召回", data.get("comment"));
|
||||
}
|
||||
|
||||
/** engineclass=ProcessMonitorComponentNew → 流程监控注入处理明细和结束流程按钮,不注入高级处理假入口。 */
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void engineclass_ProcessMonitorComponentNew_注入处理和结束流程按钮() {
|
||||
String xml = "<crud entityid='e1'><display/></crud>";
|
||||
ConversionResult r = converter.convertGraded(xml, null,
|
||||
"com.dsasp.client.wf.ui.process.monitor.ProcessMonitorComponentNew",
|
||||
"流程监控", new ArrayList<>(), noPage);
|
||||
Map<String, Object> crud = body(r.getSchema());
|
||||
List<Object> toolbar = (List<Object>) crud.get("headerToolbar");
|
||||
Map<String, Object> handle = toolbar.stream()
|
||||
.filter(o -> o instanceof Map && "处理".equals(((Map<String, Object>) o).get("label")))
|
||||
.map(o -> (Map<String, Object>) o).findFirst().orElse(null);
|
||||
Map<String, Object> terminate = toolbar.stream()
|
||||
.filter(o -> o instanceof Map && "结束流程".equals(((Map<String, Object>) o).get("label")))
|
||||
.map(o -> (Map<String, Object>) o).findFirst().orElse(null);
|
||||
boolean hasAdvanced = toolbar.stream()
|
||||
.anyMatch(o -> o instanceof Map && "高级处理".equals(((Map<String, Object>) o).get("label")));
|
||||
|
||||
assertEquals("process-monitor-crud", crud.get("id"));
|
||||
assertNotNull(handle, "流程监控应注入「处理」");
|
||||
assertNotNull(terminate, "流程监控应注入「结束流程」");
|
||||
assertFalse(hasAdvanced, "高级处理需要权限/审计端点,不能生成假入口");
|
||||
|
||||
Map<String, Object> action = (Map<String, Object>) ((List<Object>) ((Map<String, Object>)
|
||||
((Map<String, Object>) handle.get("onEvent")).get("click")).get("actions")).get(0);
|
||||
Map<String, Object> args = (Map<String, Object>) action.get("args");
|
||||
assertEquals("openApprovalDrawer", action.get("actionType"));
|
||||
assertEquals("${selectedItems[0].PM_DEMO_ID}", args.get("processInstanceId"));
|
||||
assertEquals(true, args.get("readOnly"));
|
||||
|
||||
assertEquals("ajax", terminate.get("actionType"));
|
||||
assertEquals("danger", terminate.get("level"));
|
||||
assertEquals("process-monitor-crud", terminate.get("reload"));
|
||||
Map<String, Object> api = (Map<String, Object>) terminate.get("api");
|
||||
assertEquals("post", api.get("method"));
|
||||
assertEquals("/api/workflow/process/${selectedItems[0].PM_DEMO_ID}/terminate", api.get("url"));
|
||||
Map<String, Object> data = (Map<String, Object>) api.get("data");
|
||||
assertEquals("流程有误作废处理", data.get("comment"));
|
||||
}
|
||||
|
||||
/** engineclass=ProcessFormRemoveComponent → 审批表单删除注入查看和历史删除按钮。 */
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -216,6 +216,16 @@ public class FlowableClient {
|
||||
Map.of(), Map.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束运行中流程实例。对应 flowable-service
|
||||
* {@code POST /api/flow/process/{processInstanceId}/terminate}。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> terminateProcessInstance(String processInstanceId, String comment) {
|
||||
return post("结束流程", "/api/flow/process/" + processInstanceId + "/terminate",
|
||||
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) {
|
||||
|
||||
@@ -227,6 +227,33 @@ public class TodoController {
|
||||
return ResponseEntity.ok(resp);
|
||||
}
|
||||
|
||||
@Operation(summary = "流程监控结束流程",
|
||||
description = "流程监控页专用:按流程实例结束活动流程,并按老系统语义回写 SYS_DATASTATUS=6(作废)。")
|
||||
@PostMapping("/api/workflow/process/{processInstanceId}/terminate")
|
||||
public ResponseEntity<Map<String, Object>> terminateProcess(@PathVariable String processInstanceId,
|
||||
@RequestBody(required = false) GatewayRequests.ApprovalActionRequest req) {
|
||||
String comment = firstNonBlank(req == null ? null : req.comment, "流程有误作废处理");
|
||||
Map<String, Object> engine = flowableClient.terminateProcessInstance(processInstanceId, 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_INVALID);
|
||||
written = true;
|
||||
}
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
resp.put("status", 0);
|
||||
resp.put("msg", "已结束该流程");
|
||||
resp.put("terminated", true);
|
||||
resp.put("processEnded", true);
|
||||
resp.put("processInstanceId", processInstanceId);
|
||||
resp.put("businessKey", businessKey);
|
||||
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) {
|
||||
|
||||
@@ -181,4 +181,22 @@ class FlowableClientTest {
|
||||
assertThat(result).containsEntry("businessKey", "BK-1");
|
||||
server.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
void 结束流程_POST实例terminate端点并传评论() {
|
||||
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/terminate"))
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andExpect(jsonPath("$.comment").value("流程有误作废处理"))
|
||||
.andRespond(withSuccess("{\"terminated\":true,\"businessKey\":\"BK-1\"}", MediaType.APPLICATION_JSON));
|
||||
FlowableClient client = new FlowableClient(builder.build(), p);
|
||||
|
||||
Map<String, Object> result = client.terminateProcessInstance("P1", "流程有误作废处理");
|
||||
|
||||
assertThat(result).containsEntry("terminated", true);
|
||||
assertThat(result).containsEntry("businessKey", "BK-1");
|
||||
server.verify();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import com.dsasp.server.common.workflow.service.ProcessCoreService;
|
||||
import com.eip4.platform.auth.security.AuthPrincipal;
|
||||
import com.eip4.platform.flowgateway.aggregate.BusinessSummaryService;
|
||||
import com.eip4.platform.flowgateway.aggregate.TodoAggregator;
|
||||
@@ -207,6 +208,24 @@ class TodoControllerAmisTest {
|
||||
verify(flowableClient).deleteHistoricProcessInstance("PI-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void terminateProcess_透传结束流程并回写作废状态() {
|
||||
when(flowableClient.terminateProcessInstance("PI-1", "流程有误作废处理"))
|
||||
.thenReturn(Map.of("terminated", true, "businessKey", "BK-1"));
|
||||
GatewayRequests.ApprovalActionRequest req = new GatewayRequests.ApprovalActionRequest();
|
||||
req.tableName = "OA_NOTICE";
|
||||
|
||||
Map<String, Object> resp = controller.terminateProcess("PI-1", req).getBody();
|
||||
|
||||
assertThat(resp).containsEntry("status", 0);
|
||||
assertThat(resp).containsEntry("msg", "已结束该流程");
|
||||
assertThat(resp).containsEntry("terminated", true);
|
||||
assertThat(resp).containsEntry("statusWritten", true);
|
||||
assertThat(resp).containsEntry("businessKey", "BK-1");
|
||||
verify(flowableClient).terminateProcessInstance("PI-1", "流程有误作废处理");
|
||||
verify(statusWriteback).updateStatus("BK-1", "OA_NOTICE", ProcessCoreService.STATUS_INVALID);
|
||||
}
|
||||
|
||||
private static ProcessInstanceDto process(String id, String businessKey, boolean ended, long startMillis) {
|
||||
ProcessInstanceDto dto = new ProcessInstanceDto();
|
||||
dto.id = id;
|
||||
|
||||
Reference in New Issue
Block a user