<?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.CareApplicationsMapper">
    
    <resultMap type="CareApplications" id="CareApplicationsResult">
        <result property="applyId"    column="apply_id"    />
        <result property="personId"    column="person_id"    />
        <result property="personName"    column="person_name"    />
        <result property="careNeeds"    column="care_needs"    />
        <result property="nurseGender"    column="nurse_gender"    />
        <result property="hospital"    column="hospital"    />
        <result property="address"    column="address"    />
        <result property="careDays"    column="care_days"    />
        <result property="applyDate"    column="apply_date"    />
        <result property="status"    column="status"    />
        <result property="dealStatus"    column="deal_status"    />
        <result property="payStatus"    column="pay_status"    />
        <result property="auditReason"    column="audit_reason"    />
        <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="selectCareApplicationsVo">
        select apply_id, person_id, person_name, care_needs, nurse_gender, hospital, address, care_days, apply_date, status, deal_status, pay_status, audit_reason, del_flag, create_by, create_time, update_by, update_time, remark from care_applications
    </sql>

    <select id="selectCareApplicationsList" parameterType="CareApplications" resultMap="CareApplicationsResult">
        <include refid="selectCareApplicationsVo"/>
        <where>  
            <if test="personId != null "> and person_id = #{personId}</if>
            <if test="personName != null  and personName != ''"> and person_name like concat('%', #{personName}, '%')</if>
            <if test="careNeeds != null  and careNeeds != ''"> and care_needs = #{careNeeds}</if>
            <if test="nurseGender != null  and nurseGender != ''"> and nurse_gender = #{nurseGender}</if>
            <if test="hospital != null  and hospital != ''"> and hospital = #{hospital}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="careDays != null  and careDays != ''"> and care_days = #{careDays}</if>
            <if test="applyDate != null  and applyDate != ''"> and apply_date = #{applyDate}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="dealStatus != null  and dealStatus != ''"> and deal_status = #{dealStatus}</if>
            <if test="payStatus != null  and payStatus != ''"> and pay_status = #{payStatus}</if>
            <if test="auditReason != null  and auditReason != ''"> and audit_reason = #{auditReason}</if>
        </where>
    </select>
    
    <select id="selectCareApplicationsByApplyId" parameterType="Long" resultMap="CareApplicationsResult">
        <include refid="selectCareApplicationsVo"/>
        where apply_id = #{applyId}
    </select>

    <insert id="insertCareApplications" parameterType="CareApplications" useGeneratedKeys="true" keyProperty="applyId">
        insert into care_applications
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="personId != null">person_id,</if>
            <if test="personName != null and personName != ''">person_name,</if>
            <if test="careNeeds != null">care_needs,</if>
            <if test="nurseGender != null">nurse_gender,</if>
            <if test="hospital != null">hospital,</if>
            <if test="address != null">address,</if>
            <if test="careDays != null">care_days,</if>
            <if test="applyDate != null and applyDate != ''">apply_date,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="dealStatus != null">deal_status,</if>
            <if test="payStatus != null">pay_status,</if>
            <if test="auditReason != null">audit_reason,</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="personId != null">#{personId},</if>
            <if test="personName != null and personName != ''">#{personName},</if>
            <if test="careNeeds != null">#{careNeeds},</if>
            <if test="nurseGender != null">#{nurseGender},</if>
            <if test="hospital != null">#{hospital},</if>
            <if test="address != null">#{address},</if>
            <if test="careDays != null">#{careDays},</if>
            <if test="applyDate != null and applyDate != ''">#{applyDate},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="dealStatus != null">#{dealStatus},</if>
            <if test="payStatus != null">#{payStatus},</if>
            <if test="auditReason != null">#{auditReason},</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="updateCareApplications" parameterType="CareApplications">
        update care_applications
        <trim prefix="SET" suffixOverrides=",">
            <if test="personId != null">person_id = #{personId},</if>
            <if test="personName != null and personName != ''">person_name = #{personName},</if>
            <if test="careNeeds != null">care_needs = #{careNeeds},</if>
            <if test="nurseGender != null">nurse_gender = #{nurseGender},</if>
            <if test="hospital != null">hospital = #{hospital},</if>
            <if test="address != null">address = #{address},</if>
            <if test="careDays != null">care_days = #{careDays},</if>
            <if test="applyDate != null and applyDate != ''">apply_date = #{applyDate},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="dealStatus != null">deal_status = #{dealStatus},</if>
            <if test="payStatus != null">pay_status = #{payStatus},</if>
            <if test="auditReason != null">audit_reason = #{auditReason},</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 apply_id = #{applyId}
    </update>

    <delete id="deleteCareApplicationsByApplyId" parameterType="Long">
        delete from care_applications where apply_id = #{applyId}
    </delete>

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