之前写过一个文章flowable实现节点超时自动跳过实现了流程超时自动跳过的功能.
但后面有朋友问我,能不能实现一个工作日自动跳过的功能,当前跳过,是非节假日的.
后面翻了一下flowable的源码,发现其实实现也是不难的.
@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是我重写日历超时的类
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);
}
}
}
看代码上的注释,因为我手头上没有工作日的接口,先不实现,大家就按自己的需求实现即可.
至此,工作日节点超时跳过已完成.
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有