<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<!--结束未确认的任务-->
<ref local="finishNotConfirmTaskTrigger"/>
</list>
</property>
</bean>
<bean id="finishNotConfirmTaskTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="finishNotConfirmTaskJobDetail"/>
</property>
<property name="cronExpression">
<value>0 * * ? * *</value><!-- 每分钟执行一次 -->
</property>
</bean>
<bean id="finishNotConfirmTaskJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="appealManageSchedulerTarget"/>
</property>
<property name="targetMethod">
<value>finishNotConfirmTask</value>
</property>
</bean>
<!--<bean id="monitorJob" class="com.hollycrm.unicom.sheet.monitor.hibernate.HibernateMonitorSheetJob"/>-->
<bean id="appealManageSchedulerTarget" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="target">
<ref local="appealManageScheduler"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="finishNotConfirmTask">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="appealManageScheduler" class="com.hollycrm.qcweb.appeal.scheduler.AppealManageScheduler">
<property name="hibernateTemplate">
<ref bean="hibernateTemplate" />
</property>
</bean>
</beans>
package com.hollycrm.qcweb.appeal.scheduler;
import java.util.List;
import org.jbpm.taskmgmt.exe.TaskInstance;
import com.hollycrm.framework.dao.impl.HibernateUtilDAOImpl;
import com.hollycrm.qcweb.appeal.po.TblQcAppeal;
import com.hollycrm.workflow.task.business.impl.TaskOptContext;
import com.hollycrm.workflow.util.WorkflowUtil;
public class AppealManageScheduler extends HibernateUtilDAOImpl implements
AppealManageSchedulerInterface {
/**
* 清除未确认的成绩
*/
public synchronized void finishNotConfirmTask(){
System.out.println("***********************************");
System.out.println(
"appeal process -- the ScheduleJob and finish NotConfirm of TaskInstance method invoking ");
String sql = "from org.jbpm.taskmgmt.exe.TaskInstance as ti where ti.dueDate < sysdate and ti.end is null and ti.isCancelled = 0 and ti.name='TConfirm'";
System.out.println("***********************************");
List taskInstanceList = this.findAllList(sql);
TaskInstance taskInstance = null;
for(int i = 0; i < taskInstanceList.size(); i++){
taskInstance = (TaskInstance)taskInstanceList.get(i);
//新建流程处理的上下文
TaskOptContext context = new TaskOptContext();
context.setPdname("appeal");
context.setTkname("TConfirm");
context.setProcId(taskInstance.getProcessInstance().getId());
context.setTkId(taskInstance.getId());
context.setTransaction("confirm");
TblQcAppeal appeal = findAppealByProcessId(String.valueOf(taskInstance.getProcessInstance().getId()));
context.setValue("appealId", appeal.getAppealId());
WorkflowUtil.endTaskInstance(context);
}
}
/**
* 通过流程实例Id获得申诉对象
* @param processId
* @return
*/
public TblQcAppeal findAppealByProcessId(String processId) {
String sql = "from TblQcAppeal as a where a.processId='" + processId
+ "'";
List list = this.findAllList(sql);
if (list.size() > 0) {
return (TblQcAppeal) list.get(0);
} else {
return null;
}
}
}
public interface AppealManageSchedulerInterface {
public void finishNotConfirmTask();
public TblQcAppeal findAppealByProcessId(String processId);
}
//注意:必须有接口,否则报错