动态修改JBPM之Timer组件的duedate值

需求是这样的,主管发起任务,任务根据实际需求要求有完成的限期,用timer可以实现
 <task name="orgTime">
<timer name="varTimer" duedate="1 business days" repeat="10 business seconds">
<!--<script>System.out.println("I reset my timer!");</script>-->
<action class="com.pujin.oa.workflow.allotTask.jbpm.handler.OverTimeActionHandler">
</action>
</timer>
</task>
这样做duedate在流程定义发布的时候就被限死了,就不能跟据实际需求而修改,如果在duedate放变量上去,会发现不可能能实现,怎么办呢?
在timer其实有这样的事件触发:timer-create,当要创建时间的时候就可以先去修改duedate,这样就能做成动态修改 符合实际需求了。
具体代码如下:
   <task-node name="timerControl">
<!-- 创建timer的时候触发修改时间事件 -->
<event type="timer-create">
<action name="timerCreated"
class="com.pujin.oa.workflow.allotTask.jbpm.handler.ChangeDueDateActionHandler">
<timerName>varTimer</timerName>
<delay>#{newDelay}</delay>
</action>
</event>
<task name="orgTime">
<timer name="varTimer" duedate="1 business days" repeat="10 business seconds">
<!--<script>System.out.println("I reset my timer!");</script>-->
<action class="com.pujin.oa.workflow.allotTask.jbpm.handler.OverTimeActionHandler">
</action>
</timer>
</task>
<transition to="audit"></transition>
</task-node>
在com.pujin.oa.workflow.allotTask.jbpm.handler.ChangeDueDateActionHandler中我们实现duedate修改:

package com.pujin.oa.workflow.allotTask.jbpm.handler;

import java.util.Date;
import org.jbpm.calendar.BusinessCalendar;
import org.jbpm.calendar.Duration;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.job.Timer;
import org.jbpm.scheduler.SchedulerService;
import org.jbpm.svc.Services;
import com.pujin.common.database.hibernate.AbstractHibernateDAO;
import com.pujin.common.util.Tools;
import com.pujin.oa.bo.OaTaskPhase;
import com.pujin.oa.workflow.allotTask.service.AllotTaskService;
public class ChangeDueDateActionHandler extends AbstractHibernateDAO implements ActionHandler {
static BusinessCalendar businessCalendar = new BusinessCalendar();
String timerName;
String delay;
public void execute(ExecutionContext executionContext) throws Exception {
// TODO Auto-generated method stub
Timer timer = executionContext.getTimer();
if (timer != null && timerName.equals(timer.getName())) {
OaTaskPhase oaTaskPhase = (OaTaskPhase)executionContext.getVariable("oaTaskPhase");
int dueDate = Tools.countDays(Tools.getToday(), Tools.date2string(oaTaskPhase.getPhaseterm()), "yyyy-MM-dd");
//Duration duration = new Duration(dueDate);
Duration duration = new Duration("2 minutes");
SchedulerService schedulerService = (SchedulerService) Services.getCurrentService(Services.SERVICENAME_SCHEDULER);
Date dueDateDate = businessCalendar.add(new Date(), duration);
timer.setDueDate(dueDateDate);
schedulerService.createTimer(timer);
}else{

}
}
public String getDelay() {
return delay;
}
public void setDelay(String delay) {
this.delay = delay;
}
public String getTimerName() {
return timerName;
}
public void setTimerName(String timerName) {
this.timerName = timerName;
}

}
其中:Duration duration = new Duration("2 minutes");这里的2 minutes可以将你变量放进来。


注:本文转载[url]http://user.qzone.qq.com/451712078/blog/1231294345[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值