feat(workflow): 添加任务节点类型检查功能
- 在 IWfTaskService 接口中添加了 checkTaskNodeType 方法 - 在 WfTaskServiceImpl 类中实现了 checkTaskNodeType 方法 - 优化了 WfProcessServiceImpl 类中的 assignNextUsers 方法注释
This commit is contained in:
@@ -117,4 +117,11 @@ public interface IWfTaskService {
|
||||
void startFirstTask(ProcessInstance processInstance, Map<String, Object> variables);
|
||||
|
||||
public List<FlowRecord> getApprovedRecords(Long userId, String category);
|
||||
|
||||
/**
|
||||
* 检查任务节点类型
|
||||
* @param taskId 任务ID
|
||||
* @return Map包含isStartNode和isEndNode信息
|
||||
*/
|
||||
Map<String, Boolean> checkTaskNodeType(String taskId);
|
||||
}
|
||||
|
||||
@@ -888,7 +888,7 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
|
||||
*
|
||||
* @param bpmnModel 流程模型
|
||||
* @param processInstanceId 流程实例ID
|
||||
* @param candidateUsers 审批人字符串
|
||||
* @param candidateUsers 审批人ID(单个用户)
|
||||
*/
|
||||
private void assignNextUsers(BpmnModel bpmnModel, String processInstanceId, String candidateUsers) {
|
||||
if (StringUtils.isBlank(candidateUsers)) {
|
||||
@@ -905,25 +905,9 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
|
||||
return;
|
||||
}
|
||||
|
||||
// 解析审批人字符串,格式可能是:userId1,userId2,userId3
|
||||
String[] userIds = candidateUsers.split(",");
|
||||
|
||||
// 为每个任务直接指定实际办理人
|
||||
// 为每个任务直接指定实际办理人(现在只支持单个用户)
|
||||
for (Task task : tasks) {
|
||||
// 如果只有一个审批人,直接设置为实际办理人
|
||||
if (userIds.length == 1 && StringUtils.isNotBlank(userIds[0])) {
|
||||
taskService.setAssignee(task.getId(), userIds[0].trim());
|
||||
} else if (userIds.length > 1) {
|
||||
// 如果有多个审批人,设置第一个为实际办理人,其他为候选人
|
||||
// 或者根据业务需求,可以只设置候选人让用户自己认领
|
||||
taskService.setAssignee(task.getId(), userIds[0].trim());
|
||||
// 如果需要其他人也能看到任务,可以添加候选人
|
||||
for (int i = 1; i < userIds.length; i++) {
|
||||
if (StringUtils.isNotBlank(userIds[i])) {
|
||||
taskService.addCandidateUser(task.getId(), userIds[i].trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
taskService.setAssignee(task.getId(), candidateUsers.trim());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -729,4 +729,63 @@ public class WfTaskServiceImpl extends FlowServiceFactory implements IWfTaskServ
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查任务节点类型
|
||||
* @param taskId 任务ID
|
||||
* @return Map包含isStartNode和isEndNode信息
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Boolean> checkTaskNodeType(String taskId) {
|
||||
Map<String, Boolean> result = new HashMap<>();
|
||||
result.put("isStartNode", false);
|
||||
result.put("isEndNode", false);
|
||||
|
||||
try {
|
||||
// 获取任务信息
|
||||
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
|
||||
if (task == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 获取流程定义
|
||||
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
|
||||
.processDefinitionId(task.getProcessDefinitionId())
|
||||
.singleResult();
|
||||
|
||||
// 获取BPMN模型
|
||||
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
|
||||
Process process = bpmnModel.getMainProcess();
|
||||
|
||||
// 获取当前任务节点
|
||||
FlowElement currentElement = process.getFlowElement(task.getTaskDefinitionKey());
|
||||
if (currentElement instanceof UserTask) {
|
||||
UserTask userTask = (UserTask) currentElement;
|
||||
|
||||
// 检查是否为开始节点的下一个节点
|
||||
List<SequenceFlow> incomingFlows = userTask.getIncomingFlows();
|
||||
for (SequenceFlow flow : incomingFlows) {
|
||||
FlowElement sourceElement = process.getFlowElement(flow.getSourceRef());
|
||||
if (sourceElement instanceof StartEvent) {
|
||||
result.put("isStartNode", true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否为结束节点的上一个节点
|
||||
List<SequenceFlow> outgoingFlows = userTask.getOutgoingFlows();
|
||||
for (SequenceFlow flow : outgoingFlows) {
|
||||
FlowElement targetElement = process.getFlowElement(flow.getTargetRef());
|
||||
if (targetElement instanceof EndEvent) {
|
||||
result.put("isEndNode", true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user