<?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.CareAssignmentsMapper">
    
    <resultMap type="CareAssignments" id="CareAssignmentsResult">
        <result property="assignId"    column="assign_id"    />
        <result property="applyId"    column="apply_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="nurseId"    column="nurse_id"    />
        <result property="careRequirements"    column="care_requirements"    />
        <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="selectCareAssignmentsVo">
        select assign_id, apply_id, company_id, nurse_id, care_requirements, del_flag, create_by, create_time, update_by, update_time, remark from care_assignments
    </sql>

    <select id="selectCareAssignmentsList" parameterType="CareAssignments" resultMap="CareAssignmentsResult">
        <include refid="selectCareAssignmentsVo"/>
        <where>  
            <if test="applyId != null "> and apply_id = #{applyId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="nurseId != null "> and nurse_id = #{nurseId}</if>
            <if test="careRequirements != null  and careRequirements != ''"> and care_requirements = #{careRequirements}</if>
        </where>
    </select>
    
    <select id="selectCareAssignmentsByAssignId" parameterType="Long" resultMap="CareAssignmentsResult">
        <include refid="selectCareAssignmentsVo"/>
        where assign_id = #{assignId}
    </select>

    <insert id="insertCareAssignments" parameterType="CareAssignments" useGeneratedKeys="true" keyProperty="assignId">
        insert into care_assignments
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="applyId != null">apply_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="nurseId != null">nurse_id,</if>
            <if test="careRequirements != null">care_requirements,</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="companyId != null">#{companyId},</if>
            <if test="nurseId != null">#{nurseId},</if>
            <if test="careRequirements != null">#{careRequirements},</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="updateCareAssignments" parameterType="CareAssignments">
        update care_assignments
        <trim prefix="SET" suffixOverrides=",">
            <if test="applyId != null">apply_id = #{applyId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="nurseId != null">nurse_id = #{nurseId},</if>
            <if test="careRequirements != null">care_requirements = #{careRequirements},</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 assign_id = #{assignId}
    </update>

    <delete id="deleteCareAssignmentsByAssignId" parameterType="Long">
        delete from care_assignments where assign_id = #{assignId}
    </delete>

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