<?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.CareNurseClocksMapper">

    <resultMap type="CareNurseClocks" id="CareNurseClocksResult">
        <result property="clockId"    column="clock_id"    />
        <result property="nursingRecordId"    column="nursing_record_id"    />
        <result property="nursingTime"    column="nursing_time"    />
        <result property="imgPaths"    column="img_paths"    />
        <result property="imgNum"    column="img_num"    />
        <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"    />
        <result property="applyId" column="apply_id"/>
    </resultMap>

    <sql id="selectCareNurseClocksVo">
        select clock_id, nursing_record_id, nursing_time, img_paths, img_num, del_flag, create_by, create_time, update_by, update_time, remark,apply_id from care_nurse_clocks
    </sql>

    <select id="selectCareNurseClocksList" parameterType="CareNurseClocks" resultMap="CareNurseClocksResult">
        <include refid="selectCareNurseClocksVo"/>
        <where>
            <if test="nursingRecordId != null "> and nursing_record_id = #{nursingRecordId}</if>
            <if test="nursingTime != null  and nursingTime != ''"> and nursing_time like concat('%', #{nursingTime}, '%')</if>
            <if test="imgPaths != null  and imgPaths != ''"> and img_paths = #{imgPaths}</if>
            <if test="applyId != null  and applyId != ''"> and apply_id = #{applyId}</if>
            <if test="imgNum != null "> and img_num = #{imgNum}</if>
        </where>
        order by nursing_time
    </select>

    <select id="selectCareNurseClocksByClockId" parameterType="Long" resultMap="CareNurseClocksResult">
        <include refid="selectCareNurseClocksVo"/>
        where clock_id = #{clockId}
    </select>

    <insert id="insertCareNurseClocks" parameterType="CareNurseClocks" useGeneratedKeys="true" keyProperty="clockId">
        insert into care_nurse_clocks
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="nursingRecordId != null">nursing_record_id,</if>
            <if test="nursingTime != null and nursingTime != ''">nursing_time,</if>
            <if test="imgPaths != null and imgPaths != ''">img_paths,</if>
            <if test="imgNum != null">img_num,</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>
            <if test="applyId != null">apply_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="nursingRecordId != null">#{nursingRecordId},</if>
            <if test="nursingTime != null and nursingTime != ''">#{nursingTime},</if>
            <if test="imgPaths != null and imgPaths != ''">#{imgPaths},</if>
            <if test="imgNum != null">#{imgNum},</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>
            <if test="applyId != null">#{applyId}</if>
        </trim>
    </insert>

    <update id="updateCareNurseClocks" parameterType="CareNurseClocks">
        update care_nurse_clocks
        <trim prefix="SET" suffixOverrides=",">
            <if test="nursingRecordId != null">nursing_record_id = #{nursingRecordId},</if>
            <if test="nursingTime != null and nursingTime != ''">nursing_time = #{nursingTime},</if>
            <if test="imgPaths != null and imgPaths != ''">img_paths = #{imgPaths},</if>
            <if test="imgNum != null">img_num = #{imgNum},</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 clock_id = #{clockId}
    </update>

    <delete id="deleteCareNurseClocksByClockId" parameterType="Long">
        delete from care_nurse_clocks where clock_id = #{clockId}
    </delete>

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