工作流

flowable实现节点超时自动跳过

2019-04-18  本文已影响0人  爱余星痕

不论是flowable还是activiti,都可以快速的实现节点超时自动跳过,主要是使用边缘事件

  1. 启动定时任务
    在初始化时,启动定时job,写在配置文件如下

flowable:
  #启动定时任务JOB
    async-executor-activate: true
    check-process-definitions: false
    rest-api-enabled: false
    database-schema-update: true
    idm:
     enabled: false

注意: async-executor-activate就是开关

  1. 使用边缘事件
    生成流程定义如下:
<userTask id="N5" name="审批" flowable:async="true" flowable:assignee="1,2,3">
      <multiInstanceLoopCharacteristics isSequential="false" flowable:collection="{starmark_emptycollection}" flowable:elementVariable="starmark_atuser"></multiInstanceLoopCharacteristics>
    </userTask>
    <boundaryEvent id="BoundaryEvent_N5" name="审批" attachedToRef="N5" cancelActivity="true">
      <extensionElements>
        <flowable:executionListener event="end" class="com.starmark.oa.workflow.activiti.listener.ProcessDueTimeListener"></flowable:executionListener>
      </extensionElements>
      <timerEventDefinition>
        <timeDate>PT1H</timeDate>
      </timerEventDefinition>
    </boundaryEvent>

上述就配置了1个小时自动跳过

  1. 实现监听器
    从上述定义,可以看到,我配置了一个监听器.
    为什么配一个监听器呢,主要是为了让自动跳过时,生成一条日记记录,不然自动跳过了,啥都不知道了.
    当然,如果不考虑加日志,上面的配置已经可以定时跳过了
/**
 * 流程节点超时自动跳过
 */
public class ProcessDueTimeListener implements ExecutionListener {

    private IActHiCommentService actHiCommentService=null;

    private IActHiCommentService getActHiCommentService(){
        if(actHiCommentService==null){
            actHiCommentService=SpringContextUtils.getBean(IActHiCommentService.class);
        }
        return actHiCommentService;
    }

    @Override
    public void notify(DelegateExecution execution) {
        CommentEntity comment = new CommentEntityImpl();
        comment.setId(IdWorker.getIdStr());
        comment.setProcessInstanceId(execution.getProcessInstanceId());
        comment.setType("comment");
        comment.setAction(execution.getCurrentFlowElement().getName()+"超时自动跳过");
        comment.setTime(new Date());
        comment.setUserId("system");
        comment.setMessage("");
       System.out.println(execution.getProcessInstanceId());
        System.out.println( execution.getCurrentActivityId());
        getActHiCommentService().insert(comment);

    }
}

  1. 遗留问题:
上一篇 下一篇

猜你喜欢

热点阅读