<?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.CareRecordsMapper">
    
    <resultMap type="CareRecords" id="CareRecordsResult">
        <result property="recordId"    column="record_id"    />
        <result property="nodeTitle"    column="node_title"    />
        <result property="operate"    column="operate"    />
        <result property="remark"    column="remark"    />
        <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="state"    column="state"    />
        <result property="applyId" column="apply_id"/>
        <result property="operateName" column="operate_name"/>
        <result property="parentId" column="parent_id"/>
        <result property="code" column="code"/>
        <result property="isAgree" column="is_agree"/>
    </resultMap>

    <sql id="selectCareRecordsVo">
        SELECT
            o.record_id,
            o.node_title,
            o.operate,
            o.remark,
            o.del_flag,
            o.create_by,
            o.create_time,
            o.update_by,
            o.update_time,
            o.state,
            o.apply_id,
            o.code,
            o.parent_id,
            o.is_agree,
            u.nick_name 'operate_name'
        FROM
            care_records o
            left join sys_user u on u.user_id=o.operate
    </sql>

    <select id="selectCareRecordsList" parameterType="CareRecords" resultMap="CareRecordsResult">
        <include refid="selectCareRecordsVo"/>
        <where>  
            <if test="nodeTitle != null  and nodeTitle != ''"> and o.node_title = #{nodeTitle}</if>
            <if test="applyId != null  and applyId != ''"> and o.apply_id = #{applyId}</if>
            <if test="operate != null  and operate != ''"> and o.operate = #{operate}</if>
            <if test="state != null  and state != ''"> and o.state = #{state}</if>
            <if test="isAgree != null and isAgree != ''">o.is_agree = #{isAgree},</if>
        </where>
    </select>
    
    <select id="selectCareRecordsByRecordId" parameterType="Long" resultMap="CareRecordsResult">
        <include refid="selectCareRecordsVo"/>
        where record_id = #{recordId}
    </select>

    <insert id="insertCareRecords" parameterType="CareRecords">
        insert into care_records
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="recordId != null">record_id,</if>
            <if test="nodeTitle != null">node_title,</if>
            <if test="operate != null">operate,</if>
            <if test="remark != null">remark,</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="applyId != null">apply_id,</if>
            <if test="state != null">state,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="code != null">code,</if>
            <if test="isAgree != null">is_agree,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="recordId != null">#{recordId},</if>
            <if test="nodeTitle != null">#{nodeTitle},</if>
            <if test="operate != null">#{operate},</if>
            <if test="remark != null">#{remark},</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="applyId != null">#{applyId},</if>
            <if test="state != null">#{state},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="code != null">#{code},</if>
            <if test="isAgree != null">#{isAgree},</if>
         </trim>
    </insert>

    <update id="updateCareRecords" parameterType="CareRecords">
        update care_records
        <trim prefix="SET" suffixOverrides=",">
            <if test="nodeTitle != null">node_title = #{nodeTitle},</if>
            <if test="operate != null">operate = #{operate},</if>
            <if test="remark != null">remark = #{remark},</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="applyId != null">apply_id = #{applyId},</if>
            <if test="state != null">state = #{state},</if>
            <if test="parentId != null">parent_id=#{parentId},</if>
            <if test="code != null">code=#{code},</if>
            <if test="isAgree != null">is_agree=#{isAgree},</if>
        </trim>
        where record_id = #{recordId}
    </update>

    <delete id="deleteCareRecordsByRecordId" parameterType="Long">
        delete from care_records where record_id = #{recordId}
    </delete>

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