<?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.xinda.itsm.mapper.DutyMapper">
    
    <resultMap type="Duty" id="DutyResult">
        <result property="dutyId"    column="duty_id"    />
        <result property="dutyDate"    column="duty_date"    />
        <result property="onDuty"    column="on_duty"    />
        <result property="dutyPeriod"    column="duty_period"    />
        <result property="type"    column="type"    />
        <result property="status"    column="status"    />
        <result property="relief"    column="relief"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectDutyVo">
        select duty_id, duty_date, on_duty, duty_period, type, status, relief, remark, create_by, create_time, update_by, update_time from duty
    </sql>

    <select id="selectDutyList" parameterType="Duty" resultMap="DutyResult">
        <include refid="selectDutyVo"/>
        <where>  
            <if test="dutyDate != null  and dutyDate != ''"> and duty_date = #{dutyDate}</if>
            <if test="onDuty != null  and onDuty != ''"> and on_duty = #{onDuty}</if>
            <if test="dutyPeriod != null  and dutyPeriod != ''"> and duty_period = #{dutyPeriod}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="relief != null  and relief != ''"> and relief = #{relief}</if>
        </where>
    </select>
    
    <select id="selectDutyByDutyId" parameterType="Long" resultMap="DutyResult">
        <include refid="selectDutyVo"/>
        where duty_id = #{dutyId}
    </select>
        
    <insert id="insertDuty" parameterType="Duty">
        insert into duty
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dutyId != null">duty_id,</if>
            <if test="dutyDate != null">duty_date,</if>
            <if test="onDuty != null">on_duty,</if>
            <if test="dutyPeriod != null">duty_period,</if>
            <if test="type != null">type,</if>
            <if test="status != null">status,</if>
            <if test="relief != null">relief,</if>
            <if test="remark != null">remark,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dutyId != null">#{dutyId},</if>
            <if test="dutyDate != null">#{dutyDate},</if>
            <if test="onDuty != null">#{onDuty},</if>
            <if test="dutyPeriod != null">#{dutyPeriod},</if>
            <if test="type != null">#{type},</if>
            <if test="status != null">#{status},</if>
            <if test="relief != null">#{relief},</if>
            <if test="remark != null">#{remark},</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>
         </trim>
    </insert>

    <update id="updateDuty" parameterType="Duty">
        update duty
        <trim prefix="SET" suffixOverrides=",">
            <if test="dutyDate != null">duty_date = #{dutyDate},</if>
            <if test="onDuty != null">on_duty = #{onDuty},</if>
            <if test="dutyPeriod != null">duty_period = #{dutyPeriod},</if>
            <if test="type != null">type = #{type},</if>
            <if test="status != null">status = #{status},</if>
            <if test="relief != null">relief = #{relief},</if>
            <if test="remark != null">remark = #{remark},</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>
        </trim>
        where duty_id = #{dutyId}
    </update>

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

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