<?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.miaxis.hospital.mapper.HospitalInfoMapper">

    <resultMap type="HospitalInfo" id="HospitalInfoResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="detail"    column="detail"    />
        <result property="tel"    column="tel"    />
        <result property="address"    column="address"    />
        <result property="timeSlot"    column="time_slot"    />
        <result property="tip"    column="tip"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectHospitalInfoVo">
        select id, name, detail, tel, address, time_slot, tip, create_time, update_time from hospital_info
    </sql>

    <select id="selectHospitalInfoList" parameterType="HospitalInfo" resultMap="HospitalInfoResult">
        <include refid="selectHospitalInfoVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="detail != null  and detail != ''"> and detail = #{detail}</if>
            <if test="tel != null  and tel != ''"> and tel = #{tel}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="timeSlot != null  and timeSlot != ''"> and time_slot = #{timeSlot}</if>
            <if test="tip != null  and tip != ''"> and tip = #{tip}</if>
        </where>
    </select>

    <select id="selectHospitalInfoById" parameterType="Long" resultMap="HospitalInfoResult">
        <include refid="selectHospitalInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertHospitalInfo" parameterType="HospitalInfo" useGeneratedKeys="true" keyProperty="id">
        insert into hospital_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="detail != null">detail,</if>
            <if test="tel != null">tel,</if>
            <if test="address != null">address,</if>
            <if test="timeSlot != null">time_slot,</if>
            <if test="tip != null">tip,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="detail != null">#{detail},</if>
            <if test="tel != null">#{tel},</if>
            <if test="address != null">#{address},</if>
            <if test="timeSlot != null">#{timeSlot},</if>
            <if test="tip != null">#{tip},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateHospitalInfo" parameterType="HospitalInfo">
        update hospital_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="detail != null">detail = #{detail},</if>
            <if test="tel != null">tel = #{tel},</if>
            <if test="address != null">address = #{address},</if>
            <if test="timeSlot != null">time_slot = #{timeSlot},</if>
            <if test="tip != null">tip = #{tip},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteHospitalInfoById" parameterType="Long">
        delete from hospital_info where id = #{id}
    </delete>

    <delete id="deleteHospitalInfoByIds" parameterType="String">
        delete from hospital_info where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>
