<?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.zzyl.nursing.mapper.NursingLevelMapper">
    
    <resultMap type="NursingLevel" id="NursingLevelResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="lplanId"    column="lplan_id"    />
        <result property="fee"    column="fee"    />
        <result property="status"    column="status"    />
        <result property="description"    column="description"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectNursingLevelVo">
        select id, name, lplan_id, fee, status, description, remark, create_time, update_time, create_by, update_by from nursing_level
    </sql>

    <select id="selectNursingLevelList" parameterType="NursingLevel" resultMap="NursingLevelResult">
        <include refid="selectNursingLevelVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="lplanId != null "> and lplan_id = #{lplanId}</if>
            <if test="fee != null "> and fee = #{fee}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
        </where>
    </select>
    
    <select id="selectNursingLevelById" parameterType="Long" resultMap="NursingLevelResult">
        <include refid="selectNursingLevelVo"/>
        where id = #{id}
    </select>

    <select id="selectNursingLevelVoList" resultType="com.zzyl.nursing.vo.NursingLevelVo">
        select nl.id, name, lplan_id, fee, nl.status, description, nl.create_time, nl.create_by, nl.update_by, nl.update_time, np.plan_name planName
        from nursing_level nl
        join nursing_plan np on nl.lplan_id = np.id
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
        </where>
    </select>

    <insert id="insertNursingLevel" parameterType="NursingLevel" useGeneratedKeys="true" keyProperty="id">
        insert into nursing_level
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="lplanId != null">lplan_id,</if>
            <if test="fee != null">fee,</if>
            <if test="status != null">status,</if>
            <if test="description != null">description,</if>
            <if test="remark != null">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="lplanId != null">#{lplanId},</if>
            <if test="fee != null">#{fee},</if>
            <if test="status != null">#{status},</if>
            <if test="description != null">#{description},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateNursingLevel" parameterType="NursingLevel">
        update nursing_level
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="lplanId != null">lplan_id = #{lplanId},</if>
            <if test="fee != null">fee = #{fee},</if>
            <if test="status != null">status = #{status},</if>
            <if test="description != null">description = #{description},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNursingLevelById" parameterType="Long">
        delete from nursing_level where id = #{id}
    </delete>

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