<?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.CareHospitalMapper">
    
    <resultMap type="CareHospital" id="CareHospitalResult">
        <result property="hospitalId"    column="hospital_id"    />
        <result property="name"    column="name"    />
        <result property="address"    column="address"    />
        <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="selectCareHospitalVo">
        select hospital_id, name, address, del_flag, create_by, create_time, update_by, update_time, remark from care_hospital
    </sql>

    <select id="selectCareHospitalList" parameterType="CareHospital" resultMap="CareHospitalResult">
        <include refid="selectCareHospitalVo"/>
        <where>
            <if test="1==1"> and del_flag = '0'</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
        </where>
    </select>
    
    <select id="selectCareHospitalByHospitalId" parameterType="Long" resultMap="CareHospitalResult">
        <include refid="selectCareHospitalVo"/>
        where hospital_id = #{hospitalId} and del_flag = '0'
    </select>

    <insert id="insertCareHospital" parameterType="CareHospital">
        insert into care_hospital
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="hospitalId != null">hospital_id,</if>
            <if test="name != null">name,</if>
            <if test="address != null">address,</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="hospitalId != null">#{hospitalId},</if>
            <if test="name != null">#{name},</if>
            <if test="address != null">#{address},</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="updateCareHospital" parameterType="CareHospital">
        update care_hospital
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="address != null">address = #{address},</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 hospital_id = #{hospitalId}
    </update>

    <delete id="deleteCareHospitalByHospitalId" parameterType="Long">
        update care_hospital set del_flag = '2' where hospital_id = #{hospitalId}
    </delete>

    <delete id="deleteCareHospitalByHospitalIds" parameterType="String">
        update care_hospital set del_flag = '2' where hospital_id in
        <foreach item="hospitalId" collection="array" open="(" separator="," close=")">
            #{hospitalId}
        </foreach>
    </delete>

</mapper>