feat: wire process form removal actions
This commit is contained in:
@@ -349,6 +349,39 @@ public class FlowController {
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/process/{processInstanceId}/delete-history")
|
||||
@Operation(summary = "删除已结束历史流程实例",
|
||||
description = "对齐老 ProcessCoreService.dleteCompleteProcessInstance:仅允许删除已结束的历史流程实例;"
|
||||
+ "运行中实例返回 409,避免审批表单删除页误删活动流程。")
|
||||
public ResponseEntity<Map<String, Object>> deleteHistoricProcessInstance(@PathVariable String processInstanceId) {
|
||||
String pid = trimToNull(processInstanceId);
|
||||
if (pid == null) {
|
||||
return ResponseEntity.badRequest().body(errorBody("processInstanceId 不能为空"));
|
||||
}
|
||||
ProcessInstance runtime = runtimeService.createProcessInstanceQuery()
|
||||
.processInstanceId(pid).singleResult();
|
||||
if (runtime != null) {
|
||||
return ResponseEntity.status(org.springframework.http.HttpStatus.CONFLICT)
|
||||
.body(errorBody("流程未结束,不能删除审批表单"));
|
||||
}
|
||||
var hpi = historyService.createHistoricProcessInstanceQuery()
|
||||
.processInstanceId(pid).singleResult();
|
||||
if (hpi == null) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
if (hpi.getEndTime() == null) {
|
||||
return ResponseEntity.status(org.springframework.http.HttpStatus.CONFLICT)
|
||||
.body(errorBody("流程未结束,不能删除审批表单"));
|
||||
}
|
||||
String businessKey = hpi.getBusinessKey();
|
||||
historyService.deleteHistoricProcessInstance(pid);
|
||||
Map<String, Object> resp = new java.util.LinkedHashMap<>();
|
||||
resp.put("deleted", true);
|
||||
resp.put("processInstanceId", pid);
|
||||
resp.put("businessKey", businessKey);
|
||||
return ResponseEntity.ok(resp);
|
||||
}
|
||||
|
||||
@PostMapping("/tasks/{taskId}/delegate")
|
||||
@Operation(summary = "委托任务", description = "委托给指定用户:assignee 变为受托人,owner 记原办理人")
|
||||
public ResponseEntity<TaskDto> delegate(@PathVariable String taskId, @RequestBody Requests.DelegateRequest req) {
|
||||
|
||||
@@ -11,6 +11,8 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.flowable.engine.HistoryService;
|
||||
import org.flowable.engine.IdentityService;
|
||||
import org.flowable.engine.RepositoryService;
|
||||
@@ -119,6 +121,41 @@ class FlowControllerTest {
|
||||
verify(runtimeService).activateProcessInstanceById("pi-3");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 删除已结束历史流程实例_转调historyDelete() throws Exception {
|
||||
when(runtimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery);
|
||||
when(processInstanceQuery.processInstanceId("PI-DONE")).thenReturn(processInstanceQuery);
|
||||
when(processInstanceQuery.singleResult()).thenReturn(null);
|
||||
|
||||
HistoricProcessInstance hpi = org.mockito.Mockito.mock(HistoricProcessInstance.class);
|
||||
when(hpi.getBusinessKey()).thenReturn("BK-DONE");
|
||||
when(hpi.getEndTime()).thenReturn(new Date());
|
||||
when(historyService.createHistoricProcessInstanceQuery()).thenReturn(historicProcessInstanceQuery);
|
||||
when(historicProcessInstanceQuery.processInstanceId("PI-DONE")).thenReturn(historicProcessInstanceQuery);
|
||||
when(historicProcessInstanceQuery.singleResult()).thenReturn(hpi);
|
||||
|
||||
mvc.perform(post("/api/flow/process/PI-DONE/delete-history"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.deleted").value(true))
|
||||
.andExpect(jsonPath("$.businessKey").value("BK-DONE"));
|
||||
|
||||
verify(historyService).deleteHistoricProcessInstance("PI-DONE");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 删除运行中流程实例_拒绝且不删历史() throws Exception {
|
||||
ProcessInstance pi = org.mockito.Mockito.mock(ProcessInstance.class);
|
||||
when(runtimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery);
|
||||
when(processInstanceQuery.processInstanceId("PI-RUN")).thenReturn(processInstanceQuery);
|
||||
when(processInstanceQuery.singleResult()).thenReturn(pi);
|
||||
|
||||
mvc.perform(post("/api/flow/process/PI-RUN/delete-history"))
|
||||
.andExpect(status().isConflict())
|
||||
.andExpect(jsonPath("$.msg").value("流程未结束,不能删除审批表单"));
|
||||
|
||||
verify(historyService, never()).deleteHistoricProcessInstance(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 撤回流程_移动回起始节点并挂起实例() throws Exception {
|
||||
Task task = org.mockito.Mockito.mock(Task.class);
|
||||
|
||||
@@ -86,6 +86,14 @@ public final class EngineclassDelta {
|
||||
registerMutator("com.dsasp.client.wf.ui.process.monitor.MySendTaskComponent",
|
||||
EngineclassDelta::startedProcessDataSource);
|
||||
|
||||
// 审批表单删除:ProcessFormRemoveComponent 在默认流程实例列表之上加「查看」「删除」。
|
||||
// 查看复用只读 ApprovalDrawer;删除仅删除已结束的历史流程实例,后端守卫运行中流程 409。
|
||||
register("com.dsasp.client.wf.ui.process.monitor.ProcessFormRemoveComponent",
|
||||
EngineclassDelta::processFormRemoveDetailButton,
|
||||
EngineclassDelta::processFormRemoveDeleteButton);
|
||||
registerMutator("com.dsasp.client.wf.ui.process.monitor.ProcessFormRemoveComponent",
|
||||
EngineclassDelta::processFormRemoveCrudAnchor);
|
||||
|
||||
// 消息查看:MessageReceiveView/MessageSendView 在默认 GridTemplateComponent 之上加「查看」按钮。
|
||||
// 收到消息按 SYS_MESSAGEUSER_ID 打开并置已读;已发送消息按 SYS_MESSAGE_ID 打开只读详情。
|
||||
register("com.dsasp.client.tools.message.MessageReceiveView",
|
||||
@@ -354,6 +362,59 @@ public final class EngineclassDelta {
|
||||
return btn;
|
||||
}
|
||||
|
||||
/** 审批表单删除「查看」:按历史流程实例打开只读审批详情。 */
|
||||
private static Map<String, Object> processFormRemoveDetailButton(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-search");
|
||||
btn.put("disabledOn", "${!selectedItems || selectedItems.length !== 1}");
|
||||
btn.put("onEvent", mapOf("click", mapOf("actions", List.of(action))));
|
||||
return btn;
|
||||
}
|
||||
|
||||
/** 审批表单删除「删除」:按历史流程实例物理删除流程历史。 */
|
||||
private static Map<String, Object> processFormRemoveDeleteButton(String pkField) {
|
||||
Map<String, Object> btn = new LinkedHashMap<>();
|
||||
btn.put("type", "button");
|
||||
btn.put("id", "删除");
|
||||
btn.put("label", "删除");
|
||||
btn.put("icon", "fa fa-trash");
|
||||
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) + "/delete-history"));
|
||||
btn.put("reload", "process-form-remove-crud");
|
||||
return btn;
|
||||
}
|
||||
|
||||
/** 审批表单删除 CRUD 刷新锚点,供删除后精准 reload。 */
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void processFormRemoveCrudAnchor(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-form-remove-crud");
|
||||
if (result != null) {
|
||||
result.note("engineclass[ProcessFormRemoveComponent] 设置审批表单删除 CRUD 刷新锚点");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, Object> approvalDrawerButton(String label, String icon, String pkField,
|
||||
boolean readOnly) {
|
||||
Map<String, Object> args = mapOf(
|
||||
|
||||
@@ -1112,6 +1112,44 @@ class TemplateToAmisConverterTest {
|
||||
assertEquals("主动召回", data.get("comment"));
|
||||
}
|
||||
|
||||
/** engineclass=ProcessFormRemoveComponent → 审批表单删除注入查看和历史删除按钮。 */
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void engineclass_ProcessFormRemoveComponent_注入查看和删除历史流程按钮() {
|
||||
String xml = "<crud entityid='e1'><display/></crud>";
|
||||
ConversionResult r = converter.convertGraded(xml, null,
|
||||
"com.dsasp.client.wf.ui.process.monitor.ProcessFormRemoveComponent",
|
||||
"审批表单删除", new ArrayList<>(), noPage);
|
||||
Map<String, Object> crud = body(r.getSchema());
|
||||
List<Object> toolbar = (List<Object>) crud.get("headerToolbar");
|
||||
Map<String, Object> detail = 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> delete = toolbar.stream()
|
||||
.filter(o -> o instanceof Map && "删除".equals(((Map<String, Object>) o).get("label")))
|
||||
.map(o -> (Map<String, Object>) o).findFirst().orElse(null);
|
||||
|
||||
assertEquals("process-form-remove-crud", crud.get("id"));
|
||||
assertNotNull(detail, "审批表单删除应注入「查看」");
|
||||
assertNotNull(delete, "审批表单删除应注入「删除」");
|
||||
assertTrue(toolbar.indexOf(detail) < toolbar.indexOf("pagination"));
|
||||
assertTrue(toolbar.indexOf(delete) < toolbar.indexOf("pagination"));
|
||||
|
||||
Map<String, Object> action = (Map<String, Object>) ((List<Object>) ((Map<String, Object>)
|
||||
((Map<String, Object>) detail.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", delete.get("actionType"));
|
||||
assertEquals("danger", delete.get("level"));
|
||||
assertEquals("process-form-remove-crud", delete.get("reload"));
|
||||
Map<String, Object> api = (Map<String, Object>) delete.get("api");
|
||||
assertEquals("post", api.get("method"));
|
||||
assertEquals("/api/workflow/process/${selectedItems[0].PM_DEMO_ID}/delete-history", api.get("url"));
|
||||
}
|
||||
|
||||
/** engineclass=MessageReceiveView → 注入「查看」,按 SYS_MESSAGEUSER 主键打开详情并置已读。 */
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -206,6 +206,16 @@ public class FlowableClient {
|
||||
comment == null ? Map.of() : Map.of("comment", comment), Map.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除已结束历史流程实例。对应 flowable-service
|
||||
* {@code POST /api/flow/process/{processInstanceId}/delete-history}。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> deleteHistoricProcessInstance(String processInstanceId) {
|
||||
return post("删除历史流程", "/api/flow/process/" + processInstanceId + "/delete-history",
|
||||
Map.of(), Map.class);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 内部:重试 + 异常分类
|
||||
|
||||
private List<FlowTaskDto> get(String op, java.util.function.Function<UriBuilder, java.net.URI> uriFn) {
|
||||
|
||||
@@ -213,6 +213,20 @@ public class TodoController {
|
||||
return ResponseEntity.ok(resp);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除已结束历史流程实例",
|
||||
description = "审批表单删除页专用:透传 flowable-service delete-history。仅已结束流程允许删除,运行中流程由引擎返回 409。")
|
||||
@PostMapping("/api/workflow/process/{processInstanceId}/delete-history")
|
||||
public ResponseEntity<Map<String, Object>> deleteHistoricProcess(@PathVariable String processInstanceId) {
|
||||
Map<String, Object> engine = flowableClient.deleteHistoricProcessInstance(processInstanceId);
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
resp.put("status", 0);
|
||||
resp.put("msg", "删除成功");
|
||||
resp.put("deleted", true);
|
||||
resp.put("processInstanceId", processInstanceId);
|
||||
resp.put("businessKey", rowString(engine, "businessKey", "BUSINESSKEY"));
|
||||
return ResponseEntity.ok(resp);
|
||||
}
|
||||
|
||||
@Operation(summary = "流程轨迹", description = "返回流程实例的历史任务节点(含当前活动节点),按开始时间升序;包含办理人姓名/审批意见/办理结果")
|
||||
@GetMapping("/api/flow/process/{processInstanceId}/trace")
|
||||
public ResponseEntity<List<TraceNodeDto>> trace(@PathVariable String processInstanceId) {
|
||||
|
||||
@@ -164,4 +164,21 @@ class FlowableClientTest {
|
||||
assertThat(result).containsEntry("businessKey", "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/delete-history"))
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andRespond(withSuccess("{\"deleted\":true,\"businessKey\":\"BK-1\"}", MediaType.APPLICATION_JSON));
|
||||
FlowableClient client = new FlowableClient(builder.build(), p);
|
||||
|
||||
Map<String, Object> result = client.deleteHistoricProcessInstance("P1");
|
||||
|
||||
assertThat(result).containsEntry("deleted", true);
|
||||
assertThat(result).containsEntry("businessKey", "BK-1");
|
||||
server.verify();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,6 +192,21 @@ class TodoControllerAmisTest {
|
||||
assertThat(body.getValue().get("variables")).isEqualTo(Map.of("title", "会议通知"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteHistoricProcess_透传删除历史流程并返回amis成功契约() {
|
||||
when(flowableClient.deleteHistoricProcessInstance("PI-1"))
|
||||
.thenReturn(Map.of("deleted", true, "businessKey", "BK-1"));
|
||||
|
||||
Map<String, Object> resp = controller.deleteHistoricProcess("PI-1").getBody();
|
||||
|
||||
assertThat(resp).containsEntry("status", 0);
|
||||
assertThat(resp).containsEntry("msg", "删除成功");
|
||||
assertThat(resp).containsEntry("deleted", true);
|
||||
assertThat(resp).containsEntry("processInstanceId", "PI-1");
|
||||
assertThat(resp).containsEntry("businessKey", "BK-1");
|
||||
verify(flowableClient).deleteHistoricProcessInstance("PI-1");
|
||||
}
|
||||
|
||||
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