zoukankan      html  css  js  c++  java
  • flowable流程启动时监听器

    一、核心配置类
    
    package com.magus.project.flow.config;
    
    import com.google.common.collect.Maps;
    import com.magus.project.flow.listener.ProcessStartedListener;
    import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
    import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
    import org.flowable.spring.SpringProcessEngineConfiguration;
    import org.flowable.spring.boot.EngineConfigurationConfigurer;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;
    import java.util.Map;
    
    /**
     * @Description flowable全局监听器配置类
     * @author: lxk
     * @Date 2020年6月17日14:44:33
     */
    @Configuration
    public class FlowableListenerConfig {
    
        /**
         * 任务节点前置监听
         * flowable监听级别参照 {@link FlowableEngineEventType} org.flowable.common.engine.api.delegate.event
         */
        private static final String CUSTOMER_LISTENER_PROCESS_STARTED = "PROCESS_STARTED";
    
        /**
         * 任务节点前置监听
         * 自己建立监听类实现FlowableEventListener接口
         */
        private final ProcessStartedListener taskBeforeListener;
    
    
        @Autowired
        public FlowableListenerConfig(ProcessStartedListener taskBeforeListener) {
            this.taskBeforeListener = taskBeforeListener;
        }
    
        /**
         * 将自定义监听器纳入flowable监听
         *
         * @param
         * @return org.flowable.spring.boot.EngineConfigurationConfigurer
         */
        @Bean
        public EngineConfigurationConfigurer globalListenerConfigurer() {
            return engineConfiguration -> {
                engineConfiguration.setTypedEventListeners(this.customFlowableListeners());
            };
        }
    
        /**
         * 监听类配置 {@link FlowableEngineEventType} flowable监听器级别
         *
         * @param
         * @return java.util.Map>
         */
        private Map> customFlowableListeners() {
            Map> listenerMap = Maps.newHashMap();
            listenerMap.put(CUSTOMER_LISTENER_PROCESS_STARTED, new ArrayList<>(Collections.singletonList(taskBeforeListener)));
            return listenerMap;
        }
    
    }
    二、监听器
    
    package com.magus.project.flow.listener;
    
    import com.magus.framework.core.springbean.SpringContextUtils;
    import com.magus.project.flow.constants.Constant;
    import com.magus.project.flow.webBean.FormRelevant;
    import lombok.extern.slf4j.Slf4j;
    import org.flowable.common.engine.api.delegate.event.FlowableEvent;
    import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
    import org.flowable.engine.RuntimeService;
    import org.flowable.engine.delegate.event.impl.FlowableProcessEventImpl;
    import org.springframework.stereotype.Component;
    
    /**
     * 流程实例开始,监听处理类
     * @author: lxk
     * @create: 2020年6月17日14:47:52
     **/
    @Slf4j
    @Component
    public class ProcessStartedListener implements FlowableEventListener {
    
        @Override
        public void onEvent(FlowableEvent event) {
            log.error("----------前置监听器{},执行开始----------");
            FlowableProcessEventImpl eventImpl = (FlowableProcessEventImpl) event;
            RuntimeService runtimeService = SpringContextUtils.getBean(RuntimeService.class);
            runtimeService.setVariable(eventImpl.getExecutionId(), Constant.PROCESS_FORM_SKIP_EBABLE, true);
    
            //获取流程启动是设置的变量对象
            FormRelevant formRelevant = (FormRelevant) runtimeService.getVariable(eventImpl.getExecutionId(), Constant.PROCESS_FORM_RELEVANT_KEY);
           
            log.error("----------前置监听器{},执行结束----------");
        }
    
        @Override
        public boolean isFailOnException() {
            return false;
        }
    
        @Override
        public boolean isFireOnTransactionLifecycleEvent() {
            return false;
        }
    
        @Override
        public String getOnTransaction() {
            return null;
        }
    }
  • 相关阅读:
    个人博客08
    《新浪微博平台架构》---阅读
    《阿里游戏高可用架构设计实践》---阅读
    《京东咚咚架构演进》---阅读
    《京东话费充值系统架构演进实践》--阅读
    实时获取input框内容
    html:判断两次密码不一致以及阻止提交
    《京东到家库存系统架构设计》---阅读
    《数据蜂巢架构演进之路》---阅读
    SOA案例分析浅谈
  • 原文地址:https://www.cnblogs.com/xianz666/p/13413372.html
Copyright © 2011-2022 走看看