<?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="XxlJobLogGlueMapper">
	
	<resultMap id="XxlJobLogGlue" type="com.xxl.job.admin.core.model.XxlJobLogGlue" >
		<result column="id" property="id" />
	    <result column="job_group" property="jobGroup" />
	    <result column="job_name" property="jobName" />
	    <result column="glue_source" property="glueSource" />
	    <result column="glue_remark" property="glueRemark" />
	    <result column="add_time" property="addTime" />
	    <result column="update_time" property="updateTime" />
	</resultMap>

	<sql id="Base_Column_List">
		t.id,
		t.job_group,
		t.job_name,
		t.glue_source,
		t.glue_remark,
		t.add_time,
		t.update_time
	</sql>
	
	<insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobLogGlue" useGeneratedKeys="true" keyProperty="id" >
		INSERT INTO `xxl_job_qrtz_trigger_logglue` (
			`job_group`,
			`job_name`,
			`glue_source`, 
			`glue_remark`,
			`add_time`, 
			`update_time`
		) VALUES (
			#{jobGroup}, 
			#{jobName},
			#{glueSource},
			#{glueRemark},
			now(),
			now()
		);
		<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id"> 
			SELECT LAST_INSERT_ID() 
		</selectKey> 
	</insert>
	
	<select id="selectList" parameterType="java.util.HashMap" resultMap="XxlJobLogGlue">
		SELECT <include refid="Base_Column_List" />
		FROM XXL_JOB_QRTZ_TRIGGER_LOGGLUE 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 = #{jobName}
			</if>
		</trim>
		ORDER BY id DESC
	</select>
	
	<delete id="removeOld" parameterType="java.util.HashMap" >
		DELETE FROM XXL_JOB_QRTZ_TRIGGER_LOGGLUE
		WHERE id NOT in(
			SELECT id FROM(
				SELECT id FROM XXL_JOB_QRTZ_TRIGGER_LOGGLUE
				WHERE `job_group` = #{jobGroup} and `job_name` = #{jobName}
				ORDER BY update_time desc
				LIMIT 0, #{limit}
			) t1
		)
	</delete>
	
	<delete id="delete" parameterType="java.util.HashMap" >
		DELETE FROM XXL_JOB_QRTZ_TRIGGER_LOGGLUE
		WHERE job_group = #{jobGroup} and job_name = #{jobName}
	</delete>
	
</mapper>