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);
|
||||
|
||||
Reference in New Issue
Block a user