JBPM 3.2.2动态修改duedate

花了2个多星期,终于将JBPM的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可以将你变量放进来。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章