因为flowable流程对于会签流转过程控制都是自动的,但要进行人为中间或后期干预,必须要用到执行监控器,在监控器中进行流程过程与监控,对满足要求进行处理。

1、首先在会签流程进行执行监控器的增加

其中类名 com.nbcio.modules.flowable.listener.MutiInstanceExecutionListener

目前先只实现多实例会签的监控处理

2、在程序里增加相应的执行监控器类

/**
 * 多实例会签审核结果全局监听器
 * @author nbacheng
 * @date 2022-09-22
*/
@Slf4j
@Component("MutiInstanceExecutionListener")
public class MutiInstanceExecutionListener implements ExecutionListener, ApplicationContextAware {

    private static final long serialVersionUID = 1L;
    private static  ApplicationContext applicationContext;

    
    @Override
    public void notify(DelegateExecution execution) {
        // TODO Auto-generated method stub
        RedisUtil redisUtil = applicationContext.getBean(RedisUtil.class);
        FlowNode flowNode = (FlowNode) execution.getCurrentFlowElement();
        if(Objects.nonNull(flowNode)) {
            if(flowNode instanceof UserTask ){
             UserTask userTask = (UserTask) flowNode;
             MultiInstanceLoopCharacteristics multiInstance = userTask.getLoopCharacteristics();
             if (Objects.nonNull(multiInstance)) {
                 if (Objects.nonNull(execution.getVariable("nrOfCompletedInstances"))) {
                     int nrOfCompletedInstances = (int) execution.getVariable("nrOfCompletedInstances");
                     int nrOfInstances = (int) execution.getVariable("nrOfInstances");
                     if(multiInstance.isSequential()) {
                         if((nrOfCompletedInstances + 1) >= nrOfInstances){//结束会签流程前一个节点提示进行用户选择
                             
                             redisUtil.set(CommonConstant.MUTIINSTANCE_NEXT_FINISH + execution.getProcessInstanceId(), execution.getProcessInstanceId());
                         }
                     }
                     else if(multiInstance.getCompletionCondition().equals("${nrOfCompletedInstances>=nrOfInstances}")) {
                         if((nrOfCompletedInstances + 1) >= nrOfInstances){//结束会签流程前一个节点提示进行用户选择
                             redisUtil.set(CommonConstant.MUTIINSTANCE_NEXT_FINISH + execution.getProcessInstanceId(), execution.getProcessInstanceId());
                         }
                     }
                     else if(multiInstance.getCompletionCondition().startsWith("${nrOfCompletedInstances/nrOfInstances>=")) {//后续根据需要实现
                         
                     }
                     /*log.info(execution.getId() + " - " + execution.getProcessInstanceId()
                        + " - " + execution.getEventName()
                        + " - " + execution.getCurrentActivityId()
                        + " - " + execution.getProcessInstanceBusinessKey());
                     log.info("UserExecutionListener会签方式:" + multiInstance.isSequential());
                     log.info("UserExecutionListener会签条件:" + multiInstance.getCompletionCondition());
                    log.info("UserExecutionListener总会签数:" + execution.getVariable("nrOfInstances"));
                    log.info("UserExecutionListener激活的会签数:" + execution.getVariable("nrOfActiveInstances"));
                    log.info("UserExecutionListener已经完成会签数:" + execution.getVariable("nrOfCompletedInstances"));*/
                 }
              }
             
          }    
        }
        
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContextNew) throws BeansException {
        // TODO Auto-generated method stub
        applicationContext = applicationContextNew;
    }
}

上面自己类没办法注入,所以采用ApplicationContextAware方式

同时对下一个任务是进行redis数据读取判断,同时前端也做一下处理

具体流程图与流程流转情况如下: