<?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="cn.bunny.services.mapper.ScheduleExecuteLogMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.bunny.dao.entity.log.ScheduleExecuteLog">
        <id column="id" property="id"/>
        <id column="create_time" property="createTime"/>
        <id column="update_time" property="updateTime"/>
        <id column="create_user" property="createUser"/>
        <id column="update_user" property="updateUser"/>
        <id column="is_deleted" property="isDeleted"/>
        <id column="job_name" property="jobName"/>
        <id column="job_group" property="jobGroup"/>
        <id column="job_class_name" property="jobClassName"/>
        <id column="cron_expression" property="cronExpression"/>
        <id column="trigger_name" property="triggerName"/>
        <id column="execute_result" property="executeResult"/>
        <id column="duration" property="duration"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, create_time, update_time, create_user, update_user, is_deleted, job_name, job_group, job_class_name, cron_expression, trigger_name, execute_result, duration
    </sql>

    <!-- 分页查询调度任务执行日志内容 -->
    <select id="selectListByPage" resultType="cn.bunny.dao.vo.log.QuartzExecuteLogVo">
        select
        log.*,
        create_user.username as create_username,
        update_user.username as update_username
        from log_quartz_execute log
        left join sys_user create_user on create_user.id = log.create_user
        left join sys_user update_user on update_user.id = log.update_user
        <where>
            log.is_deleted = 0
            <if test="dto.jobName != null and dto.jobName != ''">
                and log.job_name like CONCAT('%',#{dto.jobName},'%')
            </if>
            <if test="dto.jobGroup != null and dto.jobGroup != ''">
                and log.job_group like CONCAT('%',#{dto.jobGroup},'%')
            </if>
            <if test="dto.jobClassName != null and dto.jobClassName != ''">
                and log.job_class_name like CONCAT('%',#{dto.jobClassName},'%')
            </if>
            <if test="dto.cronExpression != null and dto.cronExpression != ''">
                and log.cron_expression like CONCAT('%',#{dto.cronExpression},'%')
            </if>
            <if test="dto.triggerName != null and dto.triggerName != ''">
                and log.trigger_name like CONCAT('%',#{dto.triggerName},'%')
            </if>
        </where>
    </select>

    <!-- 物理删除调度任务执行日志 -->
    <delete id="deleteBatchIdsWithPhysics">
        delete
        from log_quartz_execute
        where id in
        <foreach collection="ids" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </delete>

</mapper>
