<?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="com.ruoyi.system.mapper.ScheduleTaskMapper">
    
    <resultMap type="ScheduleTask" id="ScheduleTaskResult">
        <result property="id"    column="id"    />
        <result property="sn"    column="sn"    />
        <result property="taskId"    column="taskId"    />
        <result property="execMonth"    column="exec_month"    />
        <result property="execDay"    column="exec_day"    />
        <result property="execHour"    column="exec_hour"    />
        <result property="execMinute"    column="exec_minute"    />
        <result property="execSecond"    column="exec_second"    />
        <result property="createdAt"    column="created_at"    />
    </resultMap>

    <sql id="selectScheduleTaskVo">
        select id, sn, taskId, exec_month, exec_day, exec_hour, exec_minute, exec_second, created_at from schedule_task
    </sql>

    <select id="selectScheduleTaskList" parameterType="ScheduleTask" resultMap="ScheduleTaskResult">
        <include refid="selectScheduleTaskVo"/>
        <where>  
            <if test="sn != null  and sn != ''"> and sn = #{sn}</if>
            <if test="taskId != null  and taskId != ''"> and taskId = #{taskId}</if>
            <if test="execMonth != null  and execMonth != ''"> and exec_month = #{execMonth}</if>
            <if test="execDay != null  and execDay != ''"> and exec_day = #{execDay}</if>
            <if test="execHour != null  and execHour != ''"> and exec_hour = #{execHour}</if>
            <if test="execMinute != null  and execMinute != ''"> and exec_minute = #{execMinute}</if>
            <if test="execSecond != null  and execSecond != ''"> and exec_second = #{execSecond}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
        </where>
    </select>
    
    <select id="selectScheduleTaskById" parameterType="Long" resultMap="ScheduleTaskResult">
        <include refid="selectScheduleTaskVo"/>
        where id = #{id}
    </select>

    <insert id="insertScheduleTask" parameterType="ScheduleTask">
        insert into schedule_task
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="sn != null and sn != ''">sn,</if>
            <if test="taskId != null and taskId != ''">taskId,</if>
            <if test="execMonth != null and execMonth != ''">exec_month,</if>
            <if test="execDay != null and execDay != ''">exec_day,</if>
            <if test="execHour != null and execHour != ''">exec_hour,</if>
            <if test="execMinute != null and execMinute != ''">exec_minute,</if>
            <if test="execSecond != null and execSecond != ''">exec_second,</if>
            <if test="createdAt != null">created_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="sn != null and sn != ''">#{sn},</if>
            <if test="taskId != null and taskId != ''">#{taskId},</if>
            <if test="execMonth != null and execMonth != ''">#{execMonth},</if>
            <if test="execDay != null and execDay != ''">#{execDay},</if>
            <if test="execHour != null and execHour != ''">#{execHour},</if>
            <if test="execMinute != null and execMinute != ''">#{execMinute},</if>
            <if test="execSecond != null and execSecond != ''">#{execSecond},</if>
            <if test="createdAt != null">#{createdAt},</if>
         </trim>
    </insert>

    <update id="updateScheduleTask" parameterType="ScheduleTask">
        update schedule_task
        <trim prefix="SET" suffixOverrides=",">
            <if test="sn != null and sn != ''">sn = #{sn},</if>
            <if test="taskId != null and taskId != ''">taskId = #{taskId},</if>
            <if test="execMonth != null and execMonth != ''">exec_month = #{execMonth},</if>
            <if test="execDay != null and execDay != ''">exec_day = #{execDay},</if>
            <if test="execHour != null and execHour != ''">exec_hour = #{execHour},</if>
            <if test="execMinute != null and execMinute != ''">exec_minute = #{execMinute},</if>
            <if test="execSecond != null and execSecond != ''">exec_second = #{execSecond},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteScheduleTaskById" parameterType="Long">
        delete from schedule_task where id = #{id}
    </delete>

    <delete id="deleteScheduleTaskByIds" parameterType="String">
        delete from schedule_task where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>