<?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="org.springblade.modules.quartz.mapper.JobLogMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="jobLogResultMap" type="org.springblade.modules.quartz.entity.JobLog">
        <result column="id" property="id"/>
        <result column="create_time" property="createTime"/>
        <result column="job_name" property="jobName"/>
        <result column="job_group" property="jobGroup"/>
        <result column="invoke_target" property="invokeTarget"/>
        <result column="job_message" property="jobMessage"/>
        <result column="status" property="status"/>
        <result column="exception_info" property="exceptionInfo"/>
    </resultMap>

    <resultMap type="JobLog" id="JobLogResult">
        <id     property="id"       column="id"      />
        <result property="jobName"        column="job_name"        />
        <result property="jobGroup"       column="job_group"       />
        <result property="invokeTarget"   column="invoke_target"   />
        <result property="jobMessage"     column="job_message"     />
        <result property="status"         column="status"          />
        <result property="exceptionInfo"  column="exception_info"  />
        <result property="createTime"     column="create_time"     />
    </resultMap>


    <select id="selectJobLogPage" resultMap="jobLogResultMap">
        select * from blade_job_log where is_deleted = 0
    </select>

    <sql id="selectJobLogVo">
        select id, job_name, job_group, invoke_target, job_message, status, exception_info, create_time
		from blade_job_log
    </sql>

    <select id="selectJobLogList" parameterType="JobLog" resultMap="JobLogResult">
        <include refid="selectJobLogVo"/>
        <where>
            <if test="jobName != null and jobName != ''">
                AND job_name like concat('%', #{jobName}, '%')
            </if>
            <if test="jobGroup != null and jobGroup != ''">
                AND job_group = #{jobGroup}
            </if>
            <if test="status != null and status != ''">
                AND status = #{status}
            </if>
            <if test="invokeTarget != null and invokeTarget != ''">
                AND invoke_target like concat('%', #{invokeTarget}, '%')
            </if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
        </where>
    </select>

    <select id="selectJobLogAll" resultMap="JobLogResult">
        <include refid="selectJobLogVo"/>
    </select>

    <select id="selectJobLogById" parameterType="Long" resultMap="JobLogResult">
        <include refid="selectJobLogVo"/>
        where id = #{id}
    </select>

    <delete id="deleteJobLogById" parameterType="Long">
 		delete from blade_job_log where id = #{id}
 	</delete>

    <delete id="deleteJobLogByIds" parameterType="Long">
        delete from blade_job_log where id in
        <foreach collection="array" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <update id="cleanJobLog">
        truncate table blade_job_log
    </update>

    <insert id="insertJobLog" parameterType="JobLog">
        insert into blade_job_log(
        <if test="id != null and id != 0">id,</if>
        <if test="jobName != null and jobName != ''">job_name,</if>
        <if test="jobGroup != null and jobGroup != ''">job_group,</if>
        <if test="invokeTarget != null and invokeTarget != ''">invoke_target,</if>
        <if test="jobMessage != null and jobMessage != ''">job_message,</if>
        <if test="status != null and status != ''">status,</if>
        <if test="exceptionInfo != null and exceptionInfo != ''">exception_info,</if>
        create_time
        )values(
        <if test="id != null and id != 0">#{id},</if>
        <if test="jobName != null and jobName != ''">#{jobName},</if>
        <if test="jobGroup != null and jobGroup != ''">#{jobGroup},</if>
        <if test="invokeTarget != null and invokeTarget != ''">#{invokeTarget},</if>
        <if test="jobMessage != null and jobMessage != ''">#{jobMessage},</if>
        <if test="status != null and status != ''">#{status},</if>
        <if test="exceptionInfo != null and exceptionInfo != ''">#{exceptionInfo},</if>
        sysdate()
        )
    </insert>


</mapper>
