<?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.nurseclassifyinfo.NurseClassifyInfoMapper">

    <resultMap type="NurseClassifyInfo" id="NurseClassifyInfoResult">
        <result property="id" column="id"/>
        <result property="parentId" column="parent_id"/>
        <result property="classifyCode" column="classify_code"/>
        <result property="classifyName" column="classify_name"/>
        <result property="classifyLevel" column="classify_level"/>
        <result property="classifyType" column="classify_type"/>
        <result property="classifyPictureUrl" column="classify_picture_url"/>
        <result property="classifySort" column="classify_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="selectNurseClassifyInfoVo">
        select id,
               parent_id,
               classify_code,
               classify_name,
               classify_level,
               classify_type,
               classify_picture_url,
               classify_sort,
               create_by,
               create_time,
               update_by,
               update_time
        from nurse_classify_info
    </sql>

    <select id="selectNurseClassifyInfoList" parameterType="NurseClassifyInfo" resultMap="NurseClassifyInfoResult">
        select id,
        parent_id,
        classify_code,
        classify_name,
        classify_level,
        classify_type,
        classify_picture_url,
        classify_sort,
        create_by,
        create_time,
        update_by,
        update_time
        from nurse_classify_info
        <where>
            <if test="parentId != null ">
                and parent_id = #{parentId}
            </if>
            <if test="classifyCode != null  and classifyCode != ''">
                and classify_code = #{classifyCode}
            </if>
            <if test="classifyName != null  and classifyName != ''">
                and classify_name like concat('%', #{classifyName}, '%')
            </if>
            <if test="classifyLevel != null ">
                and classify_level = #{classifyLevel}
            </if>
            <if test="classifyType != null  and classifyType != ''">
                and classify_type = #{classifyType}
            </if>
            <if test="classifyPictureUrl != null  and classifyPictureUrl != ''">
                and classify_picture_url = #{classifyPictureUrl}
            </if>
            <if test="classifySort != null ">
                and classify_sort = #{classifySort}
            </if>
        </where>
        ORDER BY classify_sort asc,id DESC
    </select>

    <select id="selectNurseClassifyInfoById" parameterType="Long"
            resultMap="NurseClassifyInfoResult">
        <include refid="selectNurseClassifyInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertNurseClassifyInfo" parameterType="NurseClassifyInfo" useGeneratedKeys="true"
            keyProperty="id">
        insert into nurse_classify_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parentId != null">parent_id,
            </if>
            <if test="classifyCode != null">classify_code,
            </if>
            <if test="classifyName != null">classify_name,
            </if>
            <if test="classifyLevel != null">classify_level,
            </if>
            <if test="classifyType != null">classify_type,
            </if>
            <if test="classifyPictureUrl != null">classify_picture_url,
            </if>
            <if test="classifySort != null">classify_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="parentId != null">#{parentId},
            </if>
            <if test="classifyCode != null">#{classifyCode},
            </if>
            <if test="classifyName != null">#{classifyName},
            </if>
            <if test="classifyLevel != null">#{classifyLevel},
            </if>
            <if test="classifyType != null">#{classifyType},
            </if>
            <if test="classifyPictureUrl != null">#{classifyPictureUrl},
            </if>
            <if test="classifySort != null">#{classifySort},
            </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="updateNurseClassifyInfo" parameterType="NurseClassifyInfo">
        update nurse_classify_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id =
                #{parentId},
            </if>
            <if test="classifyCode != null">classify_code =
                #{classifyCode},
            </if>
            <if test="classifyName != null">classify_name =
                #{classifyName},
            </if>
            <if test="classifyLevel != null">classify_level =
                #{classifyLevel},
            </if>
            <if test="classifyType != null">classify_type =
                #{classifyType},
            </if>
            <if test="classifyPictureUrl != null">classify_picture_url =
                #{classifyPictureUrl},
            </if>
            <if test="classifySort != null">classify_sort =
                #{classifySort},
            </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="deleteNurseClassifyInfoById" parameterType="Long">
        delete
        from nurse_classify_info
        where id = #{id}
    </delete>

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

    <insert id="insertNurseClassifyInfoList" parameterType="java.util.List">
        insert into nurse_classify_info(
        parent_id,
        classify_code,
        classify_name,
        classify_level,
        classify_type,
        classify_picture_url,
        classify_sort,
        create_by,
        create_time,
        update_by,
        update_time
        ) values
        <foreach item="nurseClassifyInfoList" index="index" collection="list" separator=",">
            (
            #{nurseClassifyInfoList.parentId},
            #{nurseClassifyInfoList.classifyCode},
            #{nurseClassifyInfoList.classifyName},
            #{nurseClassifyInfoList.classifyLevel},
            #{nurseClassifyInfoList.classifyType},
            #{nurseClassifyInfoList.classifyPictureUrl},
            #{nurseClassifyInfoList.classifySort},
            #{nurseClassifyInfoList.createBy},
            #{nurseClassifyInfoList.createTime},
            #{nurseClassifyInfoList.updateBy},
            #{nurseClassifyInfoList.updateTime}
            )
        </foreach>
    </insert>

    <insert id="insertNurseStationClassifyList">
        insert into nurse_classify_info(
        parent_id,
        classify_code,
        classify_name,
        classify_level,
        classify_type,
        classify_picture_url,
        classify_sort,
        create_by,
        create_time
        )
        values
        <foreach item="nurseClassifyInfoList" index="index" collection="list" separator=",">
            (
            #{nurseClassifyInfoList.parentId},
            #{nurseClassifyInfoList.classifyCode},
            #{nurseClassifyInfoList.classifyName},
            #{nurseClassifyInfoList.classifyLevel},
            #{nurseClassifyInfoList.classifyType},
            #{nurseClassifyInfoList.classifyPictureUrl},
            #{nurseClassifyInfoList.classifySort},
            #{nurseClassifyInfoList.createBy},
            #{nurseClassifyInfoList.createTime}
            )
        </foreach>
    </insert>

    <select id="selectNurseStationClassNameCount" resultType="java.lang.Integer">
        select count(1)
        from nurse_classify_info
        <where>
            <if test="classifyName != null  and classifyName != ''">
                and classify_name = #{classifyName}
            </if>
            <if test="classifyType != null  and classifyType != ''">
                and classify_type = #{classifyType}
            </if>
        </where>
    </select>

    <select id="selectNurseStationClassByIds"
            resultType="com.xinelu.manage.domain.nurseclassifyinfo.NurseClassifyInfo">
        select id,
        parent_id,
        classify_code,
        classify_name,
        classify_level,
        classify_type,
        classify_picture_url,
        classify_sort,
        create_by,
        create_time,
        update_by,
        update_time
        from nurse_classify_info
        where
        id IN
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <select id="selectNurseStationClassNameByList" resultType="java.lang.String">
        select classify_name
        from nurse_classify_info
        where
        classify_name in
        <foreach item="list" collection="list" open="(" separator="," close=")">
            #{list}
        </foreach>
        and classify_type = #{classifyType}
    </select>
</mapper>