<?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="com.younike.service.mapper.SysQuartzMapper">

    <!-- 2021-7-27 Another quartz定时任务分页 -->
    <select id="getList" parameterType="com.younike.service.params.system.QuartzParam"
            resultType="com.younike.service.dto.system.QuartzDto">
        select
               a.job_name as jobClassName, a.description
             , case a.trigger_state
                 when 'WAITING' then '等待'
                 when 'PAUSED' then '暂停'
                 when 'ACQUIRED' then '正常'
                 when 'BLOCKED' then '阻塞'
                 when 'ERROR' then '错误' end
                 as triggerStateName
             , case a.trigger_state
                 when 'PAUSED' then 0
                 when 'WAITING' then 1
                 when 'ACQUIRED' then 1
                 else 9 end
                 as triggerState
             , FROM_UNIXTIME(a.prev_fire_time/1000, '%Y-%m-%d %H:%i:%s') as prevFireTime
             , FROM_UNIXTIME(a.next_fire_time/1000, '%Y-%m-%d %H:%i:%s') as nextFireTime
             , b.cron_expression
        from qrtz_triggers a
            left join qrtz_cron_triggers b
                on a.sched_name = b.sched_name
                    and a.trigger_name = b.trigger_name
                    and a.trigger_group = b.trigger_group
        <where>
            <if test="quartz != null and quartz.jobClassName != null and quartz.jobClassName != ''">
                a.job_name like CONCAT('%', #{quartz.jobClassName}, '%')
            </if>
            <if test="quartz != null and quartz.description != null and quartz.description != ''">
                a.description like CONCAT('%', #{quartz.description}, '%')
            </if>
        </where>
    </select>

    <!-- 2021-7-27 Another 根据 文件全路径 查询 -->
    <select id="findByJobClassName" parameterType="String" resultType="com.younike.service.params.system.QuartzParam">
        select
            a.job_name as jobClassName, a.description, b.cron_expression
        from qrtz_triggers a
            left join qrtz_cron_triggers b
                on a.sched_name = b.sched_name
                    and a.trigger_name = b.trigger_name
                    and a.trigger_group = b.trigger_group
        where a.job_name = #{jobClassName}
    </select>

</mapper>
