<?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.DutyScheduleMapper">
    
    <resultMap type="DutySchedule" id="DutyScheduleResult">
        <result property="dutyId"    column="duty_id"    />
        <result property="startWorkTime"    column="start_work_time"    />
        <result property="endWorkTime"    column="end_work_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectDutyScheduleVo">
        select duty_id, start_work_time, end_work_time, create_by, create_time, update_by, update_time, remark from duty_schedule
    </sql>

    <select id="selectDutyScheduleList" parameterType="DutySchedule" resultMap="DutyScheduleResult">
        <include refid="selectDutyScheduleVo"/>
        <where>  
            <if test="startWorkTime != null  and startWorkTime != ''"> and start_work_time = #{startWorkTime}</if>
            <if test="endWorkTime != null  and endWorkTime != ''"> and end_work_time = #{endWorkTime}</if>
        </where>
    </select>
    
    <select id="selectDutyScheduleByDutyId" parameterType="Long" resultMap="DutyScheduleResult">
        <include refid="selectDutyScheduleVo"/>
        where duty_id = #{dutyId}
    </select>
        
    <insert id="insertDutySchedule" parameterType="DutySchedule" useGeneratedKeys="true" keyProperty="dutyId">
        insert into duty_schedule
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="startWorkTime != null">start_work_time,</if>
            <if test="endWorkTime != null">end_work_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="startWorkTime != null">#{startWorkTime},</if>
            <if test="endWorkTime != null">#{endWorkTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateDutySchedule" parameterType="DutySchedule">
        update duty_schedule
        <trim prefix="SET" suffixOverrides=",">
            <if test="startWorkTime != null">start_work_time = #{startWorkTime},</if>
            <if test="endWorkTime != null">end_work_time = #{endWorkTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where duty_id = #{dutyId}
    </update>

    <delete id="deleteDutyScheduleByDutyId" parameterType="Long">
        delete from duty_schedule where duty_id = #{dutyId}
    </delete>

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