<?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.NursingPlanMapper">
    
    <resultMap type="NursingPlan" id="NursingPlanResult">
        <result property="id"    column="id"    />
        <result property="sortNo"    column="sort_no"    />
        <result property="planName"    column="plan_name"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectNursingPlanVo">
        select id, sort_no, plan_name, status, create_time, update_time, create_by, update_by, remark from nursing_plan
    </sql>

    <select id="selectNursingPlanList" parameterType="NursingPlan" resultMap="NursingPlanResult">
        <include refid="selectNursingPlanVo"/>
        <where>  
            <if test="sortNo != null "> and sort_no = #{sortNo}</if>
            <if test="planName != null  and planName != ''"> and plan_name like concat('%', #{planName}, '%')</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectNursingPlanById" parameterType="Long" resultMap="NursingPlanResult">
        <include refid="selectNursingPlanVo"/>
        where id = #{id}
    </select>

    <insert id="insertNursingPlan" parameterType="NursingPlan" useGeneratedKeys="true" keyProperty="id">
        insert into nursing_plan
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sortNo != null">sort_no,</if>
            <if test="planName != null and planName != ''">plan_name,</if>
            <if test="status != null">status,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sortNo != null">#{sortNo},</if>
            <if test="planName != null and planName != ''">#{planName},</if>
            <if test="status != null">#{status},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateNursingPlan" parameterType="NursingPlan">
        update nursing_plan
        <trim prefix="SET" suffixOverrides=",">
            <if test="sortNo != null">sort_no = #{sortNo},</if>
            <if test="planName != null and planName != ''">plan_name = #{planName},</if>
            <if test="status != null">status = #{status},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNursingPlanById" parameterType="Long">
        delete from nursing_plan where id = #{id}
    </delete>

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