<?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="net.chenlin.dp.modules.sys.dao.QuartzJobMapper">
	
	<select id="listForPage" resultType="net.chenlin.dp.modules.sys.entity.QuartzJobEntity">
		SELECT
			job_id,
			bean_name,
			method_name,
			params,
			cron_expression,
			status,
			remark,
			gmt_create
		FROM
			quartz_job
		<where>
			<if test="name != null and name.trim() != ''">
				AND bean_name LIKE concat('%',#{name},'%')
			</if>
		</where>
		ORDER BY
			gmt_create DESC
	</select>
	
	<select id="list" resultType="net.chenlin.dp.modules.sys.entity.QuartzJobEntity">
		SELECT
			job_id,
			bean_name,
			method_name,
			params,
			cron_expression,
			status
		FROM
			quartz_job
	</select>
	
	<insert id="save" parameterType="net.chenlin.dp.modules.sys.entity.QuartzJobEntity" useGeneratedKeys="true" keyProperty="jobId">
		INSERT INTO quartz_job (
			bean_name,
			method_name,
			params,
			cron_expression,
			status,
			remark,
			gmt_create
		)
		VALUES (
			#{beanName}, 
			#{methodName},
			#{params},
			#{cronExpression}, 
			#{status}, 
			#{remark},
			NOW()
		)
	</insert>
	
	<select id="getObjectById" resultType="net.chenlin.dp.modules.sys.entity.QuartzJobEntity">
		SELECT
			job_id,
			bean_name,
			method_name,
			params,
			cron_expression,
			status,
			remark,
			gmt_create
		FROM
			quartz_job
		WHERE
			job_id = #{value}
	</select>
	
	<update id="update">
		UPDATE quartz_job
		<set>
			<if test="beanName != null">bean_name = #{beanName}, </if>
			<if test="methodName != null">method_name = #{methodName}, </if>
			<if test="params != null">params = #{params}, </if>
			<if test="cronExpression != null">cron_expression = #{cronExpression}, </if>
			<if test="status != null">status = #{status}, </if>
			<if test="remark != null">remark = #{remark}, </if>
			gmt_modified = NOW()
		</set>
		WHERE
			job_id = #{jobId}
	</update>
	
	<update id="batchUpdate">
		UPDATE quartz_job 
		SET status = #{status} 
		WHERE
			job_id in
		<foreach item="jobId" collection="jobIdList"  open="(" separator="," close=")">
			#{jobId}
		</foreach> 
	</update>
	
	<delete id="batchRemove">
		DELETE
		FROM
			quartz_job
		WHERE
			job_id IN
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>	

</mapper>