Browse Source

修正定时错误

master
xyiege 4 years ago
parent
commit
9b1a432440
  1. 4
      src/main/java/cn/chjyj/szwh/configure/QuartzConfig.java
  2. 2
      src/main/java/cn/chjyj/szwh/controller/QuartzController.java
  3. 4
      src/main/java/cn/chjyj/szwh/mapper/CronTriggerMapper.java
  4. 7
      src/main/java/cn/chjyj/szwh/mapper/TriggerMapper.java
  5. 8
      src/main/resources/application.properties
  6. 16
      src/main/resources/mapper/szwh/CronTriggerMapper.xml
  7. 40
      src/main/resources/mapper/szwh/JobDetailMapper.xml
  8. 20
      src/main/resources/mapper/szwh/TriggerMapper.xml
  9. 17
      src/main/resources/quartz.properties

4
src/main/java/cn/chjyj/szwh/configure/QuartzConfig.java

@ -54,6 +54,8 @@ public class QuartzConfig implements SchedulerFactoryBeanCustomizer {
@Override
public void customize(SchedulerFactoryBean schedulerFactoryBean) {
schedulerFactoryBean.setStartupDelay(2);
schedulerFactoryBean.setAutoStartup(true);
schedulerFactoryBean.setOverwriteExistingJobs(true);
}
}

2
src/main/java/cn/chjyj/szwh/controller/QuartzController.java

@ -161,7 +161,7 @@ public class QuartzController {
JSONObject jsonObject = new JSONObject();
PageInfo<JobAndTriggerDto> pageInfo = quartzService.getJobAndTriggerDetails(pageNum, pageSize);
Map<String, Object> map = new HashMap<>();
if (!StringUtils.isEmpty(pageInfo.getTotal())) {
if (pageInfo!=null) {
map.put("JobAndTrigger", pageInfo);
map.put("number", pageInfo.getTotal());
jsonObject.put("code",200);

4
src/main/java/cn/chjyj/szwh/mapper/CronTriggerMapper.java

@ -1,7 +1,7 @@
package cn.chjyj.szwh.mapper;
import org.example.pojo.CronTrigger;
import org.example.pojo.CronTriggerKey;
import cn.chjyj.szwh.bean.CronTrigger;
import cn.chjyj.szwh.bean.CronTriggerKey;
public interface CronTriggerMapper {
int deleteByPrimaryKey(CronTriggerKey key);

7
src/main/java/cn/chjyj/szwh/mapper/TriggerMapper.java

@ -1,8 +1,11 @@
package cn.chjyj.szwh.mapper;
import org.example.pojo.Trigger;
import org.example.pojo.TriggerKey;
import cn.chjyj.szwh.bean.Trigger;
import cn.chjyj.szwh.bean.TriggerKey;
import org.springframework.stereotype.Component;
@Component
public interface TriggerMapper {
int deleteByPrimaryKey(TriggerKey key);

8
src/main/resources/application.properties

@ -20,10 +20,8 @@ spring.redis.jedis.pool.max-active=8
spring.redis.jedis.pool.max-wait=-1
# 存放在数据库
spring.quartz.job-store-type=jdbc
#spring.quartz.job-store-type=jdbc
# 是否等待任务执行完毕后,容器才会关闭
spring.quartz.wait-for-jobs-to-complete-on-shutdown=true
#spring.quartz.wait-for-jobs-to-complete-on-shutdown=true
# 容器名称
spring.quartz.scheduler-name=SzwhScheduler
spring.quartz.properties=classpath:quatz.properties
spring.quartz
#spring.quartz.scheduler-name=SzwhScheduler

16
src/main/resources/mapper/szwh/CronTriggerMapper.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.example.mapper.CronTriggerMapper">
<resultMap id="BaseResultMap" type="org.example.pojo.CronTrigger">
<mapper namespace="cn.chjyj.szwh.mapper.CronTriggerMapper">
<resultMap id="BaseResultMap" type="cn.chjyj.szwh.bean.CronTrigger">
<id column="SCHED_NAME" jdbcType="VARCHAR" property="schedName"/>
<id column="TRIGGER_NAME" jdbcType="VARCHAR" property="triggerName"/>
<id column="TRIGGER_GROUP" jdbcType="VARCHAR" property="triggerGroup"/>
@ -11,7 +11,7 @@
<sql id="Base_Column_List">
SCHED_NAME, TRIGGER_NAME, TRIGGER_GROUP, CRON_EXPRESSION, TIME_ZONE_ID
</sql>
<select id="selectByPrimaryKey" parameterType="org.example.pojo.CronTriggerKey" resultMap="BaseResultMap">
<select id="selectByPrimaryKey" parameterType="cn.chjyj.szwh.bean.CronTriggerKey" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from qrtz_cron_triggers
@ -19,19 +19,19 @@
and TRIGGER_NAME = #{triggerName,jdbcType=VARCHAR}
and TRIGGER_GROUP = #{triggerGroup,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="org.example.pojo.CronTriggerKey">
<delete id="deleteByPrimaryKey" parameterType="cn.chjyj.szwh.bean.CronTriggerKey">
delete from qrtz_cron_triggers
where SCHED_NAME = #{schedName,jdbcType=VARCHAR}
and TRIGGER_NAME = #{triggerName,jdbcType=VARCHAR}
and TRIGGER_GROUP = #{triggerGroup,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="org.example.pojo.CronTrigger">
<insert id="insert" parameterType="cn.chjyj.szwh.bean.CronTrigger">
insert into qrtz_cron_triggers (SCHED_NAME, TRIGGER_NAME, TRIGGER_GROUP,
CRON_EXPRESSION, TIME_ZONE_ID)
values (#{schedName,jdbcType=VARCHAR}, #{triggerName,jdbcType=VARCHAR}, #{triggerGroup,jdbcType=VARCHAR},
#{cronExpression,jdbcType=VARCHAR}, #{timeZoneId,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="org.example.pojo.CronTrigger">
<insert id="insertSelective" parameterType="cn.chjyj.szwh.bean.CronTrigger">
insert into qrtz_cron_triggers
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="schedName != null">
@ -68,7 +68,7 @@
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="org.example.pojo.CronTrigger">
<update id="updateByPrimaryKeySelective" parameterType="cn.chjyj.szwh.bean.CronTrigger">
update qrtz_cron_triggers
<set>
<if test="cronExpression != null">
@ -82,7 +82,7 @@
and TRIGGER_NAME = #{triggerName,jdbcType=VARCHAR}
and TRIGGER_GROUP = #{triggerGroup,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="org.example.pojo.CronTrigger">
<update id="updateByPrimaryKey" parameterType="cn.chjyj.szwh.bean.CronTrigger">
update qrtz_cron_triggers
set CRON_EXPRESSION = #{cronExpression,jdbcType=VARCHAR},
TIME_ZONE_ID = #{timeZoneId,jdbcType=VARCHAR}

40
src/main/resources/mapper/szwh/JobDetailMapper.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.example.mapper.JobDetailMapper">
<resultMap id="BaseResultMap" type="org.example.pojo.JobDetail">
<mapper namespace="cn.chjyj.szwh.mapper.JobDetailMapper">
<resultMap id="BaseResultMap" type="cn.chjyj.szwh.bean.JobDetail">
<id column="SCHED_NAME" jdbcType="VARCHAR" property="schedName"/>
<id column="JOB_NAME" jdbcType="VARCHAR" property="jobName"/>
<id column="JOB_GROUP" jdbcType="VARCHAR" property="jobGroup"/>
@ -12,7 +12,7 @@
<result column="IS_UPDATE_DATA" jdbcType="VARCHAR" property="isUpdateData"/>
<result column="REQUESTS_RECOVERY" jdbcType="VARCHAR" property="requestsRecovery"/>
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="org.example.pojo.JobDetail">
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="cn.chjyj.szwh.bean.JobDetail">
<result column="JOB_DATA" jdbcType="LONGVARBINARY" property="jobData"/>
</resultMap>
<sql id="Base_Column_List">
@ -24,7 +24,7 @@
JOB_DATA
</sql>
<select id="getJobAndTriggerDetails" resultType="org.example.dto.JobAndTriggerDto">
<select id="getJobAndTriggerDetails" resultType="cn.chjyj.szwh.bean.JobDetail">
SELECT DISTINCT
qrtz_job_details.JOB_NAME,
qrtz_job_details.JOB_GROUP,
@ -42,7 +42,7 @@
AND qrtz_triggers.TRIGGER_GROUP = qrtz_cron_triggers.TRIGGER_GROUP
</select>
<select id="selectByPrimaryKey" parameterType="org.example.pojo.JobDetailKey" resultMap="ResultMapWithBLOBs">
<select id="selectByPrimaryKey" parameterType="cn.chjyj.szwh.bean.JobDetailKey" resultMap="ResultMapWithBLOBs">
select
<include refid="Base_Column_List"/>
,
@ -52,25 +52,33 @@
and JOB_NAME = #{jobName,jdbcType=VARCHAR}
and JOB_GROUP = #{jobGroup,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="org.example.pojo.JobDetailKey">
<delete id="deleteByPrimaryKey" parameterType="cn.chjyj.szwh.bean.JobDetailKey">
delete
from qrtz_job_details
where SCHED_NAME = #{schedName,jdbcType=VARCHAR}
and JOB_NAME = #{jobName,jdbcType=VARCHAR}
and JOB_GROUP = #{jobGroup,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="org.example.pojo.JobDetail">
<insert id="insert" parameterType="cn.chjyj.szwh.bean.JobDetail">
insert into qrtz_job_details (SCHED_NAME, JOB_NAME, JOB_GROUP,
DESCRIPTION, JOB_CLASS_NAME, IS_DURABLE,
IS_NONCONCURRENT, IS_UPDATE_DATA, REQUESTS_RECOVERY,
IS_NONCONCURRENT,
IS_UPDATE_DATA,
REQUESTS_RECOVERY,
JOB_DATA)
values (#{schedName,jdbcType=VARCHAR}, #{jobName,jdbcType=VARCHAR}, #{jobGroup,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR}, #{jobClassName,jdbcType=VARCHAR}, #{isDurable,jdbcType=VARCHAR},
#{isNonconcurrent,jdbcType=VARCHAR}, #{isUpdateData,jdbcType=VARCHAR},
values (#{schedName,jdbcType=VARCHAR}, #{jobName,jdbcType=VARCHAR},
#{jobGroup,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR}, #{jobClassName,jdbcType=VARCHAR},
#{isDurable,jdbcType=VARCHAR},
#{isNonconcurrent,jdbcType=VARCHAR},
#{isUpdateData,jdbcType=VARCHAR},
#{requestsRecovery,jdbcType=VARCHAR},
#{jobData,jdbcType=LONGVARBINARY})
</insert>
<insert id="insertSelective" parameterType="org.example.pojo.JobDetail">
<insert id="insertSelective" parameterType="cn.chjyj.szwh.bean.JobDetail">
insert into qrtz_job_details
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="schedName != null">
@ -137,7 +145,7 @@
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="org.example.pojo.JobDetail">
<update id="updateByPrimaryKeySelective" parameterType="cn.chjyj.szwh.bean.JobDetail">
update qrtz_job_details
<set>
<if test="description != null">
@ -166,7 +174,8 @@
and JOB_NAME = #{jobName,jdbcType=VARCHAR}
and JOB_GROUP = #{jobGroup,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="org.example.pojo.JobDetail">
<update id="updateByPrimaryKeyWithBLOBs" parameterType="cn.chjyj.szwh.bean.JobDetail">
update qrtz_job_details
set DESCRIPTION = #{description,jdbcType=VARCHAR},
JOB_CLASS_NAME = #{jobClassName,jdbcType=VARCHAR},
@ -179,7 +188,8 @@
and JOB_NAME = #{jobName,jdbcType=VARCHAR}
and JOB_GROUP = #{jobGroup,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="org.example.pojo.JobDetail">
<update id="updateByPrimaryKey" parameterType="cn.chjyj.szwh.bean.JobDetail">
update qrtz_job_details
set DESCRIPTION = #{description,jdbcType=VARCHAR},
JOB_CLASS_NAME = #{jobClassName,jdbcType=VARCHAR},

20
src/main/resources/mapper/szwh/TriggerMapper.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.example.mapper.TriggerMapper">
<resultMap id="BaseResultMap" type="org.example.pojo.Trigger">
<mapper namespace="cn.chjyj.szwh.mapper.TriggerMapper">
<resultMap id="BaseResultMap" type="cn.chjyj.szwh.bean.Trigger">
<id column="SCHED_NAME" jdbcType="VARCHAR" property="schedName"/>
<id column="TRIGGER_NAME" jdbcType="VARCHAR" property="triggerName"/>
<id column="TRIGGER_GROUP" jdbcType="VARCHAR" property="triggerGroup"/>
@ -18,7 +18,7 @@
<result column="CALENDAR_NAME" jdbcType="VARCHAR" property="calendarName"/>
<result column="MISFIRE_INSTR" jdbcType="SMALLINT" property="misfireInstr"/>
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="org.example.pojo.Trigger">
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="cn.chjyj.szwh.bean.Trigger">
<result column="JOB_DATA" jdbcType="LONGVARBINARY" property="jobData"/>
</resultMap>
<sql id="Base_Column_List">
@ -29,7 +29,7 @@
<sql id="Blob_Column_List">
JOB_DATA
</sql>
<select id="selectByPrimaryKey" parameterType="org.example.pojo.TriggerKey" resultMap="ResultMapWithBLOBs">
<select id="selectByPrimaryKey" parameterType="cn.chjyj.szwh.bean.TriggerKey" resultMap="ResultMapWithBLOBs">
select
<include refid="Base_Column_List"/>
,
@ -39,13 +39,13 @@
and TRIGGER_NAME = #{triggerName,jdbcType=VARCHAR}
and TRIGGER_GROUP = #{triggerGroup,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="org.example.pojo.TriggerKey">
<delete id="deleteByPrimaryKey" parameterType="cn.chjyj.szwh.bean.TriggerKey">
delete from qrtz_triggers
where SCHED_NAME = #{schedName,jdbcType=VARCHAR}
and TRIGGER_NAME = #{triggerName,jdbcType=VARCHAR}
and TRIGGER_GROUP = #{triggerGroup,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="org.example.pojo.Trigger">
<insert id="insert" parameterType="cn.chjyj.szwh.bean.Trigger">
insert into qrtz_triggers (SCHED_NAME, TRIGGER_NAME, TRIGGER_GROUP,
JOB_NAME, JOB_GROUP, DESCRIPTION,
NEXT_FIRE_TIME, PREV_FIRE_TIME, PRIORITY,
@ -59,7 +59,7 @@
#{endTime,jdbcType=BIGINT}, #{calendarName,jdbcType=VARCHAR}, #{misfireInstr,jdbcType=SMALLINT},
#{jobData,jdbcType=LONGVARBINARY})
</insert>
<insert id="insertSelective" parameterType="org.example.pojo.Trigger">
<insert id="insertSelective" parameterType="cn.chjyj.szwh.bean.Trigger">
insert into qrtz_triggers
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="schedName != null">
@ -162,7 +162,7 @@
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="org.example.pojo.Trigger">
<update id="updateByPrimaryKeySelective" parameterType="cn.chjyj.szwh.bean.Trigger">
update qrtz_triggers
<set>
<if test="jobName != null">
@ -209,7 +209,7 @@
and TRIGGER_NAME = #{triggerName,jdbcType=VARCHAR}
and TRIGGER_GROUP = #{triggerGroup,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="org.example.pojo.Trigger">
<update id="updateByPrimaryKeyWithBLOBs" parameterType="cn.chjyj.szwh.bean.Trigger">
update qrtz_triggers
set JOB_NAME = #{jobName,jdbcType=VARCHAR},
JOB_GROUP = #{jobGroup,jdbcType=VARCHAR},
@ -228,7 +228,7 @@
and TRIGGER_NAME = #{triggerName,jdbcType=VARCHAR}
and TRIGGER_GROUP = #{triggerGroup,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="org.example.pojo.Trigger">
<update id="updateByPrimaryKey" parameterType="cn.chjyj.szwh.bean.Trigger">
update qrtz_triggers
set JOB_NAME = #{jobName,jdbcType=VARCHAR},
JOB_GROUP = #{jobGroup,jdbcType=VARCHAR},

17
src/main/resources/quartz.properties

@ -2,7 +2,7 @@
org.quartz.scheduler.instanceId=AUTO
org.quartz.scheduler.instanceName=DefaultQuartzScheduler
org.quartz.scheduler.instanceName=SzwhScheduler
#如果您希望Quartz Scheduler通过RMI作为服务器导出本身,则将“rmi.export”标志设置为true
#在同一个配置文件中为'org.quartz.scheduler.rmi.export'和'org.quartz.scheduler.rmi.proxy'指定一个'true'值是没有意义的,如果你这样做'export'选项将被忽略
org.quartz.scheduler.rmi.export=false
@ -39,15 +39,16 @@ org.quartz.jobStore.useProperties=true
#表前缀
org.quartz.jobStore.tablePrefix=QRTZ_
#数据源别名,自定义
org.quartz.jobStore.dataSource=qzDS
org.quartz.jobStore.dataSource=datasoure
#org.quartz.jobStore.dataSource=qzDS
#使用阿里的druid作为数据库连接池
org.quartz.dataSource.qzDS.connectionProvider.class=org.example.config.DruidPoolingconnectionProvider
org.quartz.dataSource.qzDS.URL=jdbc:mysql://127.0.0.1:3306/test_quartz?characterEncoding=utf8&useSSL=false&autoReconnect=true&serverTimezone=UTC
org.quartz.dataSource.qzDS.user=root
org.quartz.dataSource.qzDS.password=123456
org.quartz.dataSource.qzDS.driver=com.mysql.jdbc.Driver
org.quartz.dataSource.qzDS.maxConnections=10
#org.quartz.dataSource.qzDS.connectionProvider.class=org.example.config.DruidPoolingconnectionProvider
#org.quartz.dataSource.qzDS.URL=jdbc:mysql://127.0.0.1:3306/test_quartz?characterEncoding=utf8&useSSL=false&autoReconnect=true&serverTimezone=UTC
#org.quartz.dataSource.qzDS.user=root
#org.quartz.dataSource.qzDS.password=123456
#org.quartz.dataSource.qzDS.driver=com.mysql.jdbc.Driver
#org.quartz.dataSource.qzDS.maxConnections=10
#设置为“true”以打开群集功能。如果您有多个Quartz实例使用同一组数据库表,则此属性必须设置为“true”,否则您将遇到破坏
#org.quartz.jobStore.isClustered=false

Loading…
Cancel
Save