前记:如果配置多个任务不能触发的请仔细检查配置文件!!!!!!

不存在多个同时间任务不能触发的现象!!!!

这个东西记得不要设置成false。如果写了就是true。不写的话默认true。

下面开始贴配置:

1.首先配置web.xml 注入spring的xml文件。(记得把quartz的xml也注入了,我这边都是spring开头的。)

2.Java类:

package com.apexedu.biz.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.apexedu.biz.entity.TJhrz;
import com.apexedu.biz.entity.TRyxx;
import com.apexedu.framework.util.DBUtil;
import com.apexedu.sys.util.DateUtil;
import com.apexedu.sys.util.StringUtil;

/**
 * 每天发送微信提醒
 * @author Hpp 2017-3-28
 *
 */
public class JhrzInitUtil {

    /**
     * 前一天下午发送提醒消息
     */
    public void preDay(){
        System.out.println("preDay");
        Calendar c = Calendar.getInstance();
        int year=c.get(Calendar.YEAR);//获取当前年份
        String years=String.valueOf(year)+"年";//拼接字符串
        SimpleDateFormat df = new SimpleDateFormat("M/d");//设置日期格式
        Date nextDay = DateUtil.getNextDay(new Date());//明天的日期
        String nextDays=df.format(nextDay);// new Date()为获取当前系统时间
        List<TJhrz> list = DBUtil.queryAllBeanList("select * from t_jhrz where xq=? and day=? and state not in('2','5')", TJhrz.class, years,nextDays);
        for (TJhrz tJhrz : list) {
             SendTip.sendMsg(new String[]{tJhrz.getRyid()},"您明天有"+tJhrz.getJhnr()+"工作需要处理,请您提前做好准备。", tJhrz.getRyid());
        }
    }
    /**
     * 当天9点发送提醒消息
     */
    public void currDay09(){
        System.out.println("currDay09");
        Calendar c = Calendar.getInstance();
        int year=c.get(Calendar.YEAR);//获取当前年份
        String years=String.valueOf(year)+"年";//拼接字符串
        SimpleDateFormat df = new SimpleDateFormat("M/d");//设置日期格式
        String currDays=df.format(new Date());// new Date()为获取当前系统时间
        List<TJhrz> list = DBUtil.queryAllBeanList("select * from t_jhrz where xq=? and day=? and state not in('2','5')", TJhrz.class,years,currDays);
        for (TJhrz tJhrz : list) {
             SendTip.sendMsg(new String[]{tJhrz.getRyid()},"您今天有"+tJhrz.getJhnr()+"工作需要处理,请您及时处理。", tJhrz.getRyid());
        }
    }
    /**
     * 当天下午16点发送提醒消息
     */
    public void currDay16(){
        System.out.println("currDay16");
        Calendar c = Calendar.getInstance();
        int year=c.get(Calendar.YEAR);//获取当前年份
        String years=String.valueOf(year)+"年";//拼接字符串
        SimpleDateFormat df = new SimpleDateFormat("M/d");//设置日期格式
        String currDays=df.format(new Date());// new Date()为获取当前系统时间
        List<TJhrz> list = DBUtil.queryAllBeanList("select * from t_jhrz where xq=? and day=? and state=0", TJhrz.class, years,currDays);
        for (TJhrz tJhrz : list) {
             SendTip.sendMsg(new String[]{tJhrz.getRyid()},"您今天有"+tJhrz.getJhnr()+"工作系统显示未完成,请您及时处理。", tJhrz.getRyid());
        }
    }
    /**
     * 计划延期后及时提醒09
     * @throws ParseException
     */
    public void nextSDay09() throws ParseException{
        System.out.println("nextSDay09");
        Calendar c = Calendar.getInstance();
        int year=c.get(Calendar.YEAR);//获取当前年份
        String years=String.valueOf(year)+"年";//拼接字符串
        SimpleDateFormat df = new SimpleDateFormat("yyyy/M/d");//设置日期格式
        String currWeek=DateUtil.getCurrentWeek(new Date());
        List<TJhrz> list = DBUtil.queryAllBeanList("select * from t_jhrz where state=0 and jhsj=? and xq=?", TJhrz.class, currWeek,years);
        for (TJhrz tJhrz : list) {
            int day = DateUtil.datePDate(df.parse(year+"/"+tJhrz.getDay()), new Date());
            if(day>0){
                 SendTip.sendMsg(new String[]{tJhrz.getRyid()},"您计划"+tJhrz.getDay()+"的"+tJhrz.getJhnr()+"工作系统显示已延误"+day+"天,请您及时处理。", tJhrz.getRyid());
            }
        }
    }
    /**
     * 计划延期后及时提醒16
     * @throws ParseException
     */
    public void nextSDay16() throws ParseException{
        System.out.println("nextSDay16()");
        Calendar c = Calendar.getInstance();
        int year=c.get(Calendar.YEAR);//获取当前年份
        String years=String.valueOf(year)+"年";//拼接字符串
        SimpleDateFormat df = new SimpleDateFormat("yyyy/M/d");//设置日期格式
        String currWeek=DateUtil.getCurrentWeek(new Date());
        List<TJhrz> list = DBUtil.queryAllBeanList("select * from t_jhrz where state=0 and jhsj=? and xq=?", TJhrz.class, currWeek,years);
        for (TJhrz tJhrz : list) {
            int day = DateUtil.datePDate(df.parse(year+"/"+tJhrz.getDay()), new Date());
            if(day>0){
                 SendTip.sendMsg(new String[]{tJhrz.getRyid()},"您计划"+tJhrz.getDay()+"的"+tJhrz.getJhnr()+"工作系统显示已延误"+day+"天,请您及时处理。", tJhrz.getRyid());
            }
        }
    }
    /**
     * 每周五4点给科室负责人推送
     */
    public void firDay16(){
        System.out.println("firDay16");
        String currWeek=DateUtil.getCurrentWeek(new Date());
        Calendar c = Calendar.getInstance();
        int year=c.get(Calendar.YEAR);//获取当前年份
        String years=String.valueOf(year)+"年";//拼接字符串
        List<TJhrz> list =DBUtil.queryAllBeanList("select t.*,(select name from t_ryxx where gh=t.ryid) ryid_str,(select bmfzr from t_bmxx where wid=(select bmid from t_ryxx b where b.gh=t.ryid )) ksfzr from t_jhrz t where jhsj=? and xq=? and state=0", TJhrz.class, currWeek,years);
        for (TJhrz tJhrz : list) {
             SendTip.sendMsg(new String[]{tJhrz.getKsfzr()},"您科室的"+tJhrz.getRyid_str()+"有"+tJhrz.getJhnr()+"工作系统显示未完成,请您督促处理。", tJhrz.getKsfzr());
        }
    }
    /**
     * 针对上周所分管的科室工作人员“未完成”的工作
     */
    public void Mon1(){
        System.out.println("Mon1");
        Calendar c = Calendar.getInstance();
        int year=c.get(Calendar.YEAR);//获取当前年份
        String years=String.valueOf(year)+"年";//拼接字符串
           c.setTime(new Date());
        c.add(Calendar.DATE,-7);
        Date monday = c.getTime();
        String prevWeek=DateUtil.getCurrentWeek(monday);//上一周的日期
        List<TRyxx> clds = DBUtil.queryAllBeanList("select * from t_ryxx where bmid=(select wid from t_bmxx  where bmmc like ?)", TRyxx.class, "%处领导%");
        for (TRyxx tRyxx : clds) {
            String[] kss = tRyxx.getFgks().split(",");
            for (String string : kss) {
                if(StringUtil.isNotBlank(string)){
                    List<TJhrz> list = DBUtil.queryAllBeanList("select t.*,(select name from t_ryxx where gh=t.ryid) ryid_str,(select bmmc from t_bmxx where wid=?) bmmc from t_jhrz t where ryid in(select gh from t_ryxx where bmid=?) and xq=? and jhsj=? and state=0", TJhrz.class, string,string,years,prevWeek);
                    for (TJhrz tJhrz : list) {
                         SendTip.sendMsg(new String[]{tRyxx.getGh()},"您分管的科室的"+tJhrz.getRyid_str()+"上周有"+tJhrz.getJhnr()+"工作系统显示未完成,请您督促处理。", tRyxx.getGh());
                    }
                }
            }
        }
    }
}

下面看看quartz的xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <bean id="JhrzInitUtil"
       class="com.apexedu.biz.util.JhrzInitUtil">
   </bean>
    <bean id="JhrzInitUtil2"
       class="com.apexedu.biz.util.JhrzInitUtil">
   </bean>
   <bean id="JhrzInitUtil3"
       class="com.apexedu.biz.util.JhrzInitUtil">
   </bean>
    <bean id="JhrzInitUtil4"
       class="com.apexedu.biz.util.JhrzInitUtil">
   </bean>
   <bean id="JhrzInitUtil5"
       class="com.apexedu.biz.util.JhrzInitUtil">
   </bean>
   <bean id="JhrzInitUtil6"
       class="com.apexedu.biz.util.JhrzInitUtil">
   </bean>
   <bean id="JhrzInitUtil7"
       class="com.apexedu.biz.util.JhrzInitUtil">
   </bean>
   <!-- 计划任务 -->
    <bean id="preDay"
       class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
       <property name="targetObject">
           <ref bean="JhrzInitUtil" />
       </property>
       <property name="targetMethod">
           <value>preDay</value>
       </property>
       <property name="concurrent" value="true"/>
   </bean>   

   <bean id="preDayInit"
       class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
       <property name="jobDetail">
           <ref bean="preDay"/>
       </property>
       <property name="cronExpression">
            <value>0 0 16 * * ? *</value>
       </property>
   </bean>
   <!-- 计划任务 -->

   <bean id="currDay09"
       class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
       <property name="targetObject">
           <ref bean="JhrzInitUtil2" />
       </property>
       <property name="targetMethod">
           <value>currDay09</value>
       </property>
       <property name="concurrent" value="true"/>
   </bean>   

   <bean id="currDay09Init"
       class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
       <property name="jobDetail">
           <ref bean="currDay09"/>
       </property>
       <property name="cronExpression">
            <value>0 0 9 * * ? *</value>
       </property>
   </bean>

    <bean id="currDay16"
       class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
       <property name="targetObject">
           <ref bean="JhrzInitUtil3" />
       </property>
       <property name="targetMethod">
           <value>currDay16</value>
       </property>
       <property name="concurrent" value="true"/>
   </bean>   

   <bean id="currDay16Init"
       class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
       <property name="jobDetail">
           <ref bean="currDay16"/>
       </property>
       <property name="cronExpression">
            <value>0 0 16 * * ? *</value>
       </property>
   </bean>

   <bean id="nextSDay09"
       class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
       <property name="targetObject">
           <ref bean="JhrzInitUtil4" />
       </property>
       <property name="targetMethod">
           <value>nextSDay09</value>
       </property>
       <property name="concurrent" value="true"/>
   </bean>   

   <bean id="nextSDay09Init"
       class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
       <property name="jobDetail">
           <ref bean="nextSDay09"/>
       </property>
       <property name="cronExpression">
            <value>0 0 9 * * ? *</value>
       </property>
   </bean>

   <bean id="nextSDay16"
       class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
       <property name="targetObject">
           <ref bean="JhrzInitUtil5" />
       </property>
       <property name="targetMethod">
           <value>nextSDay16</value>
       </property>
       <property name="concurrent" value="true"/>
   </bean>   

   <bean id="nextSDay16Init"
       class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
       <property name="jobDetail">
           <ref bean="nextSDay16"/>
       </property>
       <property name="cronExpression">
            <value>0 0 16 * * ? *</value>
       </property>
   </bean>

    <bean id="firDay16"
       class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
       <property name="targetObject">
           <ref bean="JhrzInitUtil6" />
       </property>
       <property name="targetMethod">
           <value>firDay16</value>
       </property>
       <property name="concurrent" value="true"/>
   </bean>   

   <bean id="firDay16Init"
       class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
       <property name="jobDetail">
           <ref bean="firDay16"/>
       </property>
       <property name="cronExpression">
            <value>0 0 16 ? * FRI</value>
       </property>
   </bean>

    <bean id="Mon1"
       class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
       <property name="targetObject">
           <ref bean="JhrzInitUtil7" />
       </property>
       <property name="targetMethod">
           <value>Mon1</value>
       </property>
       <property name="concurrent" value="true"/>
   </bean>   

   <bean id="Mon1Init"
       class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
       <property name="jobDetail">
           <ref bean="Mon1"/>
       </property>
       <property name="cronExpression">
            <value>0 30 13 ? * MON</value>
       </property>
   </bean>

   <bean
       class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
       <property name="triggers">
           <list>
           <ref local="Mon1Init"/>
            <ref local="firDay16Init"/>
           <ref local="nextSDay16Init"/>
                 <ref local="nextSDay09Init"/>
                <ref local="currDay16Init"/>
               <ref local="currDay09Init"/>
               <ref local="preDayInit"/>
           </list>
       </property>
   </bean>
</beans>
    

Spring + qyartz+多任务实现任务调度功能。的更多相关文章

  1. spring boot实现ssm(2)功能

    spring 和 mybatis 整合的那篇: ssm(2) . 配置文件比ssm(1) 更多, 在做项目的时候, 配置文件是一个让人头大的事情. 那么在spring boot中, 实现相同功能, 需 ...

  2. Spring框架的IOC核心功能快速入门

    2. 步骤一:下载Spring框架的开发包 * 官网:http://spring.io/ * 下载地址:http://repo.springsource.org/libs-release-local/ ...

  3. Spring常用jar包的功能

    jar名称 描述 spring-framework.jar spring框架比较完整的功能,core+aop+ioc+transaction spring-core.jar 基本上的核心工具类,一些u ...

  4. Spring Security 3.1 中功能强大的加密工具 PasswordEncoder

    Spring Security 3.1 中功能强大的加密工具 PasswordEncoder 博客分类: security spring springsecurity  好吧,这种加密机制很复杂,还是 ...

  5. Spring是什么,Spring容器提供了那些功能,Spring的工作机制

    spring是什么 spring 是一个轻型的容器,是J2EE规范的轻量级实现,可以一站式开发,其中提供了,bean工厂,用以构造我们需要的Model ,spring 是非侵入式的,spring应用中 ...

  6. 关于MVC WebAPI 中加入任务调度功能的问题 (MVC WebAPI 任务调度)

    在MVC WebAPI中加入任务调度功能.即在MVC WebAPI启动时,启用任务调度程序. 但是这里有一个问题点,就是部署好IIS站点后,发现任务调度并没有启用.原因为何? 原因是部署好IIS站点后 ...

  7. Spring注解方式实现任务调度

    原文:http://docs.spring.io/spring/docs/4.0.1.BUILD-SNAPSHOT/javadoc-api/ 注解类型:EnableScheduling @Target ...

  8. Spring注解方式实现任务调度【官方文档翻译】

    原文:http://docs.spring.io/spring/docs/4.0.1.BUILD-SNAPSHOT/javadoc-api/ 注解类型:EnableScheduling @Target ...

  9. 采用dom4j和反射模拟Spring框架的依赖注入功能

    Spring的依赖注入是指将对象的创建权交给Spring框架,将对象所依赖的属性注入进来的行为.在学习了dom4j后,其实也可以利用dom4j和反射做一个小Demo模拟Spring框架的这种功能.下面 ...

随机推荐

  1. Android jni 编程4(对基本类型二维整型数组的操作)

    Android jni 编程 对于整型二维数组操作: 类型一:传入二维整型数组,返回一个整型值 类型二:传入二维整型数组,返回一个二维整型数组 声明方法: private native int Sum ...

  2. vs2010 入门程序

    #include <stdio.h> int main(){ printf("hello world!\n"); getchar(); //此处避免执行完程序自动退出 ...

  3. PAT乙级 1065. 单身狗(25) by Python

    1065. 单身狗(25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue "单身狗"是中文对 ...

  4. Java初学练习答案(循环)

    /* 题目如下: 1 (for 循环)*编程找出四位整数abcd 中满足下述关系的数. (ab+cd)(ab+cd)=abcd 2 (循环)*读入一个整数n,输出如下图形 n = 3 * *** ** ...

  5. 在vim中搜索单词

    基本的搜索: /pattern    向前搜索 ?pattern   向后搜索 n               向前重复搜索 N               向后重复搜索 搜索并替换 :%s/sear ...

  6. [Selenium With C#学习笔记] Lesson-01环境搭建

    Step-1:准备所需的开发环境.浏览器驱动.Selenium-Webdriver.单元测试框架,因目前使用C#的开发神器都Visual Studio,本文也打算采用Visual Studio 201 ...

  7. Manual | BSD手册| Linux手册 | 数据库手册 | 编程开发手册 | WEB开发手册 | 软件应用手册 | 网络技术手册 | GNU手册

    豆豆手册 □ BSD手册 □ Linux手册 □ 数据库手册 □ 编程开发手册 □ WEB开发手册 □ 软件应用手册 □ 网络技术手册 □ GNU手册 在线手册 首 页 BSD手册   ·FreeBS ...

  8. 【经验】AngularJS

    1.关于ng-model <textarea id="feature_name" class="col-sm-3" placeholder="软 ...

  9. ThinkPHP模板的知识(比较全的知识)

    php框架 一.真实项目开发步骤: 多人同时开发项目,协作开发项目.分工合理.效率有提高(代码风格不一样.分工不好) 测试阶段 上线运行 对项目进行维护.修改.升级(单个人维护项目,十分困难,代码风格 ...

  10. Linux i2c子系统(四) _从i2c-s3c24xx.c看i2c控制器驱动的编写

    "./drivers/i2c/busses/i2c-s3c2410.c"是3.14.0内核中三星SoC的i2c控制器驱动程序, 本文试图通过对这个程序的分析, 剥离繁复的细节, 总 ...