<?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.ruoyi.care.mapper.CareNurseRecordsMapper">
    
    <resultMap type="CareNurseRecords" id="CareNurseRecordsResult">
        <result property="nursingRecordId"    column="nursing_record_id"    />
        <result property="applyId"    column="apply_id"    />
        <result property="nursingTime"    column="nursing_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCareNurseRecordsVo">
        select nursing_record_id, apply_id, nursing_time, del_flag, create_by, create_time, update_by, update_time, remark from care_nurse_records
    </sql>

    <select id="selectCareNurseRecordsList" parameterType="CareNurseRecords" resultMap="CareNurseRecordsResult">
        <include refid="selectCareNurseRecordsVo"/>
        <where>  
            <if test="applyId != null "> and apply_id = #{applyId}</if>
            <if test="nursingTime != null  and nursingTime != ''"> and nursing_time = #{nursingTime}</if>
        </where>
    </select>
    
    <select id="selectCareNurseRecordsByNursingRecordId" parameterType="Long" resultMap="CareNurseRecordsResult">
        <include refid="selectCareNurseRecordsVo"/>
        where nursing_record_id = #{nursingRecordId}
    </select>

    <insert id="insertCareNurseRecords" parameterType="CareNurseRecords" useGeneratedKeys="true" keyProperty="nursingRecordId">
        insert into care_nurse_records
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="applyId != null">apply_id,</if>
            <if test="nursingTime != null and nursingTime != ''">nursing_time,</if>
            <if test="delFlag != null">del_flag,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="applyId != null">#{applyId},</if>
            <if test="nursingTime != null and nursingTime != ''">#{nursingTime},</if>
            <if test="delFlag != null">#{delFlag},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCareNurseRecords" parameterType="CareNurseRecords">
        update care_nurse_records
        <trim prefix="SET" suffixOverrides=",">
            <if test="applyId != null">apply_id = #{applyId},</if>
            <if test="nursingTime != null and nursingTime != ''">nursing_time = #{nursingTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where nursing_record_id = #{nursingRecordId}
    </update>

    <delete id="deleteCareNurseRecordsByNursingRecordId" parameterType="Long">
        delete from care_nurse_records where nursing_record_id = #{nursingRecordId}
    </delete>

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