<?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="XxlJobLogMapper">
	
	<resultMap id="XxlJobLog" type="com.xxl.job.admin.core.model.XxlJobLog" >
		<result column="id" property="id" />

		<result column="job_group" property="jobGroup" />
		<result column="job_id" property="jobId" />

	    <result column="executor_address" property="executorAddress" />
		<result column="executor_handler" property="executorHandler" />
	    <result column="executor_param" property="executorParam" />
	    
	    <result column="trigger_time" property="triggerTime" />
	    <result column="trigger_code" property="triggerCode" />
	    <result column="trigger_msg" property="triggerMsg" />
	    
	    <result column="handle_time" property="handleTime" />
	    <result column="handle_code" property="handleCode" />
	    <result column="handle_msg" property="handleMsg" />
	    
	</resultMap>

	<sql id="Base_Column_List">
		t.id,
		t.job_group,
		t.job_id,
		t.executor_address,
		t.executor_handler,
		t.executor_param,
		t.trigger_time,
		t.trigger_code,
		t.trigger_msg,
		t.handle_time,
		t.handle_code,
		t.handle_msg
	</sql>
	
	<select id="pageList" parameterType="java.util.HashMap" resultMap="XxlJobLog">
		SELECT <include refid="Base_Column_List" />
		FROM XXL_JOB_QRTZ_TRIGGER_LOG AS t
		<trim prefix="WHERE" prefixOverrides="AND | OR" >
			<if test="jobGroup != null and jobGroup != ''">
				AND t.job_group = #{jobGroup}
			</if>
			<if test="jobId gt 0">
				AND t.job_id = #{jobId}
			</if>
			<if test="triggerTimeStart != null">
				AND t.trigger_time <![CDATA[ >= ]]> #{triggerTimeStart}
			</if>
			<if test="triggerTimeEnd != null">
				AND t.trigger_time <![CDATA[ <= ]]> #{triggerTimeEnd}
			</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_LOG AS t
		<trim prefix="WHERE" prefixOverrides="AND | OR" >
			<if test="jobGroup != null and jobGroup != ''">
				AND t.job_group = #{jobGroup}
			</if>
			<if test="jobId gt 0">
				AND t.job_id = #{jobId}
			</if>
			<if test="triggerTimeStart != null">
				AND t.trigger_time <![CDATA[ >= ]]> #{triggerTimeStart}
			</if>
			<if test="triggerTimeEnd != null">
				AND t.trigger_time <![CDATA[ <= ]]> #{triggerTimeEnd}
			</if>
		</trim>
	</select>
	
	<select id="load" parameterType="java.lang.Integer" resultMap="XxlJobLog">
		SELECT <include refid="Base_Column_List" />
		FROM XXL_JOB_QRTZ_TRIGGER_LOG AS t
		WHERE t.id = #{id}
	</select>

	
	<insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobLog" useGeneratedKeys="true" keyProperty="id" >
		INSERT INTO XXL_JOB_QRTZ_TRIGGER_LOG (
			`job_group`,
			`job_id`
		) VALUES (
			#{jobGroup},
			#{jobId}
		);
		<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id"> 
			SELECT LAST_INSERT_ID() 
		</selectKey> 
	</insert>

	<update id="updateTriggerInfo">
		UPDATE XXL_JOB_QRTZ_TRIGGER_LOG
		SET
			`trigger_time`= #{triggerTime},
			`trigger_code`= #{triggerCode},
			`trigger_msg`= #{triggerMsg},
			`executor_address`= #{executorAddress},
			`executor_handler`=#{executorHandler},
			`executor_param`= #{executorParam}
		WHERE `id`= #{id}
	</update>

	<update id="updateHandleInfo">
		UPDATE XXL_JOB_QRTZ_TRIGGER_LOG
		SET 
			`handle_time`= #{handleTime}, 
			`handle_code`= #{handleCode},
			`handle_msg`= #{handleMsg} 
		WHERE `id`= #{id}
	</update>
	
	<delete id="delete">
		delete from XXL_JOB_QRTZ_TRIGGER_LOG
		WHERE job_id = #{jobId}
	</delete>
	
</mapper>