spring中使用quartz排程

 <?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);
}
//注意:必须有接口,否则报错

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值