首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >flowable实现节点超时自动跳过(二)-------工作日节点超时跳过

flowable实现节点超时自动跳过(二)-------工作日节点超时跳过

作者头像
星痕
发布2019-11-13 21:35:42
4K0
发布2019-11-13 21:35:42
举报
文章被收录于专栏:JAVA后端开发JAVA后端开发

之前写过一个文章flowable实现节点超时自动跳过实现了流程超时自动跳过的功能.

但后面有朋友问我,能不能实现一个工作日自动跳过的功能,当前跳过,是非节假日的.

后面翻了一下flowable的源码,发现其实实现也是不难的.

  1. 首先要有一个节假日的接口,这个需要第三方提供, 该接口传入一个当前时间,及超时天数,计算需要超时跳过的时间.
  2. 重写日历时钟的配置,示例代码如下:
@Bean
    public EngineConfigurationConfigurer<SpringProcessEngineConfiguration> customIdGeneratorConfigurer() {
        return engineConfiguration -> {
            engineConfiguration.setIdGenerator(customIdGenerator());
            engineConfiguration.setActivityBehaviorFactory(activityBehaviorFactory());
            engineConfiguration.setTransactionManager(transactionManager);
            //设置全局事件监听
            engineConfiguration.setTypedEventListeners(this.getGlobalFlowableEventListener());
            //需要先初始化时钟
            engineConfiguration.setClock(new DefaultClockImpl());
            //自定义工作日历
            engineConfiguration.setBusinessCalendarManager(this.getBusinessCalendarManager(engineConfiguration.getClock()));
        };
    }


    /**
     * 初始化日历
     * @param clock 时钟
     * @return 日历实现
     */
    private  MapBusinessCalendarManager getBusinessCalendarManager(Clock clock) {

            MapBusinessCalendarManager mapBusinessCalendarManager = new MapBusinessCalendarManager();
            mapBusinessCalendarManager.addBusinessCalendar(DurationBusinessCalendar.NAME, new DurationBusinessCalendar(clock));
            mapBusinessCalendarManager.addBusinessCalendar(DueDateBusinessCalendar.NAME, new AcDueDateBusinessCalendar(clock));
            mapBusinessCalendarManager.addBusinessCalendar(CycleBusinessCalendar.NAME, new CycleBusinessCalendar(clock));

            return mapBusinessCalendarManager;

    }

注意,上述代码中,AcDueDateBusinessCalendar是我重写日历超时的类

  1. 重写日历超时的类,示例如下:
public class AcDueDateBusinessCalendar extends DueDateBusinessCalendar {
    public AcDueDateBusinessCalendar(ClockReader clockReader) {
        super(clockReader);
    }

    @Override
    public Date resolveDuedate(String duedate, int maxIterations) {
        try {
            // 这里可以调用工作日接口,返回计算后的工作日时间
            if (duedate.startsWith("P")) {
                return new DateTime(clockReader.getCurrentTime()).plus(Period.parse(duedate)).toDate();
            }

            return DateTime.parse(duedate).toDate();

        } catch (Exception e) {
            throw new FlowableException("couldn't resolve duedate: " + e.getMessage(), e);
        }
    }
}

看代码上的注释,因为我手头上没有工作日的接口,先不实现,大家就按自己的需求实现即可.

至此,工作日节点超时跳过已完成.

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档