<?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="XxlJobInfoMapper">
	
	<resultMap id="XxlJobInfo" type="com.xxl.job.core.model.XxlJobInfo" >
		<result column="id" property="id" />
	
		<result column="job_group" property="jobGroup" />
	    <result column="job_name" property="jobName" />
	    <result column="job_cron" property="jobCron" />
	    <result column="job_desc" property="jobDesc" />
	    <result column="job_class" property="jobClass" />
	    <result column="job_data" property="jobData" />
	    
	    <result column="add_time" property="addTime" />
	    <result column="update_time" property="updateTime" />
	    
	    <result column="author" property="author" />
	    <result column="alarm_email" property="alarmEmail" />
	    <result column="alarm_threshold" property="alarmThreshold" />
	    
	    <result column="glue_switch" property="glueSwitch" />
	    <result column="glue_source" property="glueSource" />
	    <result column="glue_remark" property="glueRemark" />
	</resultMap>

	<sql id="Base_Column_List">
		t.id,
		t.job_group,
		t.job_name,
		t.job_cron,
		t.job_desc,
		t.job_class,
		t.job_data,
		t.add_time,
		t.update_time,
		t.author,
		t.alarm_email,
		t.alarm_threshold,
		t.glue_switch,
		t.glue_source,
		t.glue_remark
	</sql>
	
	<select id="pageList" parameterType="java.util.HashMap" resultMap="XxlJobInfo">
		SELECT <include refid="Base_Column_List" />
		FROM xxl_job_qrtz_trigger_info AS t
		<trim prefix="WHERE" prefixOverrides="AND | OR" >
			<if test="jobGroup != null and jobGroup != ''">
				AND t.job_group = #{jobGroup}
			</if>
			<if test="jobName != null and jobName != ''">
				AND t.job_name like CONCAT(CONCAT('%', #{jobName}), '%')
			</if>
		</trim>
		ORDER BY id DESC
		LIMIT #{offset}, #{pagesize}
	</select>
	
	<select id="pageListCount" parameterType="java.util.HashMap" resultType="int">
		SELECT count(1)
		FROM xxl_job_qrtz_trigger_info AS t
		<trim prefix="WHERE" prefixOverrides="AND | OR" >
			<if test="jobGroup != null and jobGroup != ''">
				AND t.job_group = #{jobGroup}
			</if>
			<if test="jobName != null and jobName != ''">
				AND t.job_name like CONCAT(CONCAT('%', #{jobName}), '%')
			</if>
		</trim>
	</select>
	
	<insert id="save" parameterType="com.xxl.job.core.model.XxlJobInfo" useGeneratedKeys="true" keyProperty="id" >
		INSERT INTO `xxl_job_qrtz_trigger_info` (
			job_group,
			job_name,
			job_cron,
			job_desc,
			job_class,
			job_data,
			add_time,
			update_time,
			author,
			alarm_email,
			alarm_threshold,
			glue_switch,
			glue_source,
			glue_remark
		) VALUES (
			#{jobGroup}, 
			#{jobName}, 
			#{jobCron}, 
			#{jobDesc}, 
			#{jobClass}, 
			#{jobData},
			NOW(),
			NOW(),
			#{author},
			#{alarmEmail},
			#{alarmThreshold},
			#{glueSwitch},
			#{glueSource},
			#{glueRemark}
		);
		<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id"> 
			SELECT LAST_INSERT_ID() 
		</selectKey> 
	</insert>
	
	<select id="load" parameterType="java.util.HashMap" resultMap="XxlJobInfo">
		SELECT <include refid="Base_Column_List" />
		FROM xxl_job_qrtz_trigger_info AS t
		WHERE t.job_group = #{jobGroup}
			AND t.job_name = #{jobName}
	</select>
	
	<update id="update" parameterType="com.xxl.job.core.model.XxlJobInfo" >
		UPDATE `xxl_job_qrtz_trigger_info` 
		SET 
			job_cron = #{jobCron},
			job_desc = #{jobDesc},
			job_data = #{jobData},
			update_time = NOW(),
			author = #{author},
			alarm_email = #{alarmEmail},
			alarm_threshold = #{alarmThreshold},
			glue_switch = #{glueSwitch},
			glue_source = #{glueSource},
			glue_remark = #{glueRemark}
		WHERE job_group = #{jobGroup}
			AND job_name = #{jobName}
	</update>
	
	<delete id="delete" parameterType="java.lang.String">
		DELETE
		FROM
			xxl_job_qrtz_trigger_info
		WHERE
			job_group = #{jobGroup}
		AND job_name = #{jobName}
	</delete>
	
</mapper>