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