!69 feat(bpm): 新增流程当前节点及办理人查询接口

Merge pull request !69 from wsm/feature/query_current_assignee
This commit is contained in:
wsm
2026-07-06 06:16:35 +00:00
committed by Gitee
@@ -19,6 +19,7 @@ import org.flowable.bpmn.model.*;
import org.flowable.bpmn.model.Process;
import org.flowable.common.engine.api.FlowableException;
import org.flowable.engine.*;
import org.flowable.idm.api.User;
import org.flowable.engine.history.HistoricActivityInstance;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.history.HistoricProcessInstanceQuery;
@@ -508,6 +509,87 @@ public class ActTaskController {
return result;
}
/**
* 查询流程当前节点及办理人信息(轻量接口,供列表页按钮快速查看)
*
* @param procInstId 流程实例ID
* @return finished: 是否已结束, endTime: 结束时间, currentTasks: 当前活跃任务列表(节点名+办理人+开始时间)
*/
@GetMapping(value = "/currentNodeInfo")
public Result<Map<String, Object>> getCurrentNodeInfo(@RequestParam(name = "procInstId", required = true) String procInstId) {
Result<Map<String, Object>> result = new Result<>();
Map<String, Object> map = new HashMap<>();
// 1. 判断流程是否已结束
boolean finished = false;
String endTime = null;
List<ActHiActinstDTO> startAndEndlist = activitiService.getActHiActinstStartAndEnd(procInstId);
if (startAndEndlist != null) {
for (ActHiActinstDTO m : startAndEndlist) {
if ("endEvent".equals(m.getActType())) {
finished = true;
endTime = m.getEndTime() != null
? DateUtils.formatDate(m.getEndTime(), "YYYY-MM-dd HH:mm:ss") : null;
break;
}
}
}
map.put("finished", finished);
if (finished) {
// 流程已结束:返回结束时间
map.put("endTime", endTime);
map.put("currentTasks", Collections.emptyList());
log.info("【流程-当前节点查询】流程已结束, procInstId: {}, endTime: {}", procInstId, endTime);
} else {
// 流程未结束:查询所有活跃任务(支持会签/并行分支等多任务场景)
List<Task> activeTasks = taskService.createTaskQuery()
.processInstanceId(procInstId).active().list();
List<Map<String, Object>> taskList = new ArrayList<>();
if (activeTasks != null && !activeTasks.isEmpty()) {
for (Task task : activeTasks) {
Map<String, Object> taskInfo = new HashMap<>();
taskInfo.put("taskId", task.getId());
taskInfo.put("taskName", task.getName());
taskInfo.put("taskDefinitionKey", task.getTaskDefinitionKey());
taskInfo.put("startTime", task.getCreateTime() != null
? DateUtils.formatDate(task.getCreateTime(), "YYYY-MM-dd HH:mm:ss") : null);
// 查询办理人
String assignee = task.getAssignee();
if (oConvertUtils.isNotEmpty(assignee)) {
taskInfo.put("assignee", assignee);
LoginUser user = sysBaseAPI.getUserByName(assignee);
taskInfo.put("assigneeName", user != null ? user.getRealname() : assignee);
List<String> deptNames = sysBaseAPI.getDepartNamesByUsername(assignee);
taskInfo.put("deptNames", deptNames != null ? deptNames : Collections.emptyList());
} else {
taskInfo.put("assignee", "");
taskInfo.put("assigneeName", "待签收");
taskInfo.put("deptNames", Collections.emptyList());
}
taskList.add(taskInfo);
}
} else {
// 没有活跃任务但流程未结束(极端情况,如定时器等待中)
Map<String, Object> emptyTask = new HashMap<>();
emptyTask.put("taskName", "等待中(无活跃用户任务)");
emptyTask.put("assigneeName", "系统自动处理");
taskList.add(emptyTask);
}
map.put("currentTasks", taskList);
map.put("endTime", null);
log.info("【流程-当前节点查询】查询成功, procInstId: {}, 活跃任务数: {}", procInstId, taskList.size());
}
result.setResult(map);
result.setSuccess(true);
return result;
}
/**
* 获取退回的上个节点