Commit 1b08e6828fd08714ed9c3dfe46b54b177b55d647

Authored by smallNorthLee
1 parent 9dfed536

feat:新增获取下一个执行的流程节点接口

yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/BpmProcessInstanceController.java
... ... @@ -178,4 +178,15 @@ public class BpmProcessInstanceController {
178 178 public CommonResult<BpmProcessInstanceBpmnModelViewRespVO> getProcessInstanceBpmnModelView(@RequestParam(value = "id") String id) {
179 179 return success(processInstanceService.getProcessInstanceBpmnModelView(id));
180 180 }
  181 +
  182 + @GetMapping("/get-next-flow-nodes")
  183 + @Operation(summary = "获取下一个执行的流程节点")
  184 + @PreAuthorize("@ss.hasPermission('bpm:process-instance:query')")
  185 + @SuppressWarnings("unchecked")
  186 + public CommonResult<List<BpmApprovalDetailRespVO.ActivityNode>> getNextFlowNodes(@Valid BpmApprovalDetailReqVO reqVO) {
  187 + if (StrUtil.isNotEmpty(reqVO.getProcessVariablesStr())) {
  188 + reqVO.setProcessVariables(JsonUtils.parseObject(reqVO.getProcessVariablesStr(), Map.class));
  189 + }
  190 + return success(processInstanceService.getNextFlowNodes(getLoginUserId(), reqVO));
  191 + }
181 192 }
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceService.java
... ... @@ -98,6 +98,15 @@ public interface BpmProcessInstanceService {
98 98 BpmApprovalDetailRespVO getApprovalDetail(Long loginUserId, @Valid BpmApprovalDetailReqVO reqVO);
99 99  
100 100 /**
  101 + * 获取下一个执行节点信息。
  102 + *
  103 + * @param loginUserId 登录人的用户编号
  104 + * @param reqVO 请求信息
  105 + * @return 下一个执行节点信息
  106 + */
  107 + List<BpmApprovalDetailRespVO.ActivityNode> getNextFlowNodes(Long loginUserId, @Valid BpmApprovalDetailReqVO reqVO);
  108 +
  109 + /**
101 110 * 获取流程实例的 BPMN 模型视图
102 111 *
103 112 * @param id 流程实例的编号
... ... @@ -173,4 +182,5 @@ public interface BpmProcessInstanceService {
173 182 * @param instance 流程任务
174 183 */
175 184 void processProcessInstanceCompleted(ProcessInstance instance);
  185 +
176 186 }
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
... ... @@ -11,6 +11,7 @@ import cn.hutool.core.util.StrUtil;
11 11 import cn.iocoder.yudao.framework.common.pojo.PageResult;
12 12 import cn.iocoder.yudao.framework.common.util.date.DateUtils;
13 13 import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
  14 +import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
14 15 import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
15 16 import cn.iocoder.yudao.framework.common.util.object.PageUtils;
16 17 import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
... ... @@ -55,6 +56,7 @@ import org.flowable.engine.history.HistoricProcessInstanceQuery;
55 56 import org.flowable.engine.repository.ProcessDefinition;
56 57 import org.flowable.engine.runtime.ProcessInstance;
57 58 import org.flowable.engine.runtime.ProcessInstanceBuilder;
  59 +import org.flowable.task.api.Task;
58 60 import org.flowable.task.api.history.HistoricTaskInstance;
59 61 import org.springframework.context.annotation.Lazy;
60 62 import org.springframework.stereotype.Service;
... ... @@ -226,6 +228,49 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
226 228 }
227 229  
228 230 @Override
  231 + public List<ActivityNode> getNextFlowNodes(Long loginUserId, BpmApprovalDetailReqVO reqVO) {
  232 + // 1 校验任务存在
  233 + Task task = taskService.getTask(reqVO.getTaskId());
  234 + if (task == null) {
  235 + throw exception(TASK_NOT_EXISTS);
  236 + }
  237 + // 2 校验任务是否由当前用户审批
  238 + if (StrUtil.isNotBlank(task.getAssignee())
  239 + && ObjectUtil.notEqual(loginUserId, NumberUtils.parseLong(task.getAssignee()))) {
  240 + throw exception(TASK_OPERATE_FAIL_ASSIGN_NOT_SELF);
  241 + }
  242 + // 3 校验流程实例存在
  243 + ProcessInstance instance = getProcessInstance(task.getProcessInstanceId());
  244 + if (instance == null) {
  245 + throw exception(PROCESS_INSTANCE_NOT_EXISTS);
  246 + }
  247 + // 4 获取 BpmnModel
  248 + BpmnModel bpmnModel = processDefinitionService.getProcessDefinitionBpmnModel(task.getProcessDefinitionId());
  249 + if (bpmnModel == null) {
  250 + return null;
  251 + }
  252 + // 5. 获取当前任务节点的信息
  253 + FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey());
  254 + List<FlowNode> nextFlowNodes = BpmnModelUtils.getNextFlowNodes(flowElement, bpmnModel, reqVO.getProcessVariables());
  255 + return convertList(nextFlowNodes, nodes -> {
  256 + FlowElement flowNode = BpmnModelUtils.getFlowElementById(bpmnModel, nodes.getId());
  257 + ActivityNode activityNode = new ActivityNode().setId(nodes.getId()).setName(nodes.getName())
  258 + .setNodeType(START_USER_NODE_ID.equals(nodes.getId())
  259 + ? BpmSimpleModelNodeTypeEnum.START_USER_NODE.getType()
  260 + : ObjUtil.defaultIfNull(parseNodeType(flowNode), // 目的:解决“办理节点”的识别
  261 + BpmSimpleModelNodeTypeEnum.APPROVE_NODE.getType()))
  262 + .setStatus(FlowableUtils.getTaskStatus(task))
  263 + .setCandidateStrategy(BpmnModelUtils.parseCandidateStrategy(flowNode));
  264 +
  265 + // 如果是取消状态,则跳过
  266 + if (BpmTaskStatusEnum.isCancelStatus(activityNode.getStatus())) {
  267 + return null;
  268 + }
  269 + return activityNode;
  270 + });
  271 + }
  272 +
  273 + @Override
229 274 @SuppressWarnings("unchecked")
230 275 public PageResult<HistoricProcessInstance> getProcessInstancePage(Long userId,
231 276 BpmProcessInstancePageReqVO pageReqVO) {
... ...