<?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.lframework.xingyun.template.inner.mappers.QrtzMapper">
  <resultMap id="QrtzDto" type="com.lframework.xingyun.template.inner.dto.qrtz.QrtzDto">
    <result column="name" property="name"/>
    <result column="group" property="group"/>
    <result column="description" property="description"/>
    <result column="cron" property="cron"/>
    <result column="state" property="state"/>
  </resultMap>

  <sql id="QrtzDto_sql">
    SELECT
      job.JOB_NAME AS `name`,
      job.JOB_GROUP AS `group`,
      job.DESCRIPTION AS description,
      cron.CRON_EXPRESSION AS cron,
      tri.TRIGGER_STATE AS state
    FROM qrtz_job_details AS job
    LEFT JOIN qrtz_triggers AS tri ON job.JOB_NAME = tri.JOB_NAME  AND job.JOB_GROUP = tri.JOB_GROUP
    LEFT JOIN qrtz_cron_triggers AS cron ON cron.TRIGGER_NAME = tri.TRIGGER_NAME AND cron.TRIGGER_GROUP= tri.JOB_GROUP
  </sql>

  <select id="query" resultMap="QrtzDto">
    <include refid="QrtzDto_sql"/>
    WHERE tri.TRIGGER_TYPE = 'CRON'
    <if test="vo.name != null and vo.name != ''">
      AND job.JOB_NAME LIKE CONCAT('%', #{vo.name}, '%')
    </if>
    <if test="vo.group != null and vo.group != ''">
      AND job.JOB_GROUP = CONCAT('%', #{vo.group}, '%')
    </if>
    <if test="vo.state != null and vo.state != ''">
      AND tri.TRIGGER_STATE = #{vo.state}
    </if>
    AND job.JOB_CLASS_NAME IN <foreach collection="vo.jobClasses" open="(" separator="," close=")" item="item">#{item}</foreach>
  </select>
  <select id="findById" resultMap="QrtzDto">
    <include refid="QrtzDto_sql"/>
    WHERE job.JOB_NAME = #{name}
    AND job.JOB_GROUP = #{group}
  </select>
</mapper>