<?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.xinelu.manage.mapper.nursestationlabel.NurseStationLabelMapper">

    <resultMap type="NurseStationLabel" id="NurseStationLabelResult">
        <result property="id" column="id"/>
        <result property="nurseStationId" column="nurse_station_id"/>
        <result property="userId" column="user_id"/>
        <result property="labelCode" column="label_code"/>
        <result property="labelDescription" column="label_description"/>
        <result property="sort" column="sort"/>
        <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="selectNurseStationLabelVo">
        select id,
               nurse_station_id,
               user_id,
               label_code,
               label_description,
               sort,
               create_by,
               create_time,
               update_by,
               update_time
        from nurse_station_label
    </sql>

    <select id="selectNurseStationLabelList" parameterType="NurseStationLabel" resultMap="NurseStationLabelResult">
        <include refid="selectNurseStationLabelVo"/>
        <where>
            <if test="nurseStationId != null ">
                and nurse_station_id = #{nurseStationId}
            </if>
            <if test="userId != null ">
                and user_id = #{userId}
            </if>
            <if test="labelCode != null  and labelCode != ''">
                and label_code = #{labelCode}
            </if>
            <if test="labelDescription != null  and labelDescription != ''">
                and label_description = #{labelDescription}
            </if>
            <if test="sort != null ">
                and sort = #{sort}
            </if>
            order by create_time desc
        </where>
    </select>

    <select id="selectNurseStationLabelById" parameterType="Long"
            resultMap="NurseStationLabelResult">
        <include refid="selectNurseStationLabelVo"/>
        where id = #{id}
    </select>

    <insert id="insertNurseStationLabel" parameterType="NurseStationLabel" useGeneratedKeys="true"
            keyProperty="id">
        insert into nurse_station_label
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="nurseStationId != null">nurse_station_id,
            </if>
            <if test="userId != null">user_id,
            </if>
            <if test="labelCode != null">label_code,
            </if>
            <if test="labelDescription != null">label_description,
            </if>
            <if test="sort != null">sort,
            </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="nurseStationId != null">#{nurseStationId},
            </if>
            <if test="userId != null">#{userId},
            </if>
            <if test="labelCode != null">#{labelCode},
            </if>
            <if test="labelDescription != null">#{labelDescription},
            </if>
            <if test="sort != null">#{sort},
            </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="updateNurseStationLabel" parameterType="NurseStationLabel">
        update nurse_station_label
        <trim prefix="SET" suffixOverrides=",">
            <if test="nurseStationId != null">nurse_station_id =
                #{nurseStationId},
            </if>
            <if test="userId != null">user_id =
                #{userId},
            </if>
            <if test="labelCode != null">label_code =
                #{labelCode},
            </if>
            <if test="labelDescription != null">label_description =
                #{labelDescription},
            </if>
            <if test="sort != null">sort =
                #{sort},
            </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 id = #{id}
    </update>

    <delete id="deleteNurseStationLabelById" parameterType="Long">
        delete
        from nurse_station_label
        where id = #{id}
    </delete>

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


    <select id="getNurseStationLabelStationId" parameterType="long" resultType="int">
        SELECT count(1)
        FROM nurse_station_label
        WHERE nurse_station_id = #{nurseStationId}
    </select>

    <delete id="deleteNurseStationLabelStationId" parameterType="Long">
        DELETE
        FROM nurse_station_label
        WHERE nurse_station_id = #{nurseStationId}
    </delete>

    <insert id="insertBatchNurseStationLabel" parameterType="java.util.List">
        insert into nurse_station_label(
        nurse_station_id,
        user_id,
        label_code,
        label_description,
        sort,
        create_by,
        create_time
        ) values
        <foreach item="label" index="index" collection="nurseStationLabelList" separator=",">
            (
            #{label.nurseStationId},
            #{label.userId},
            #{label.labelCode},
            #{label.labelDescription},
            #{label.labelSort},
            #{label.createBy},
            #{label.createTime}
            )
        </foreach>
    </insert>
</mapper>
