<?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.bonus.boot.manager.basic.dao.HospitalDao">
    <insert id="addInfo">
        insert into pm_base_hospital(hospital,address,responsible,tel_phone,
                                     business_start,business_end,on_line,is_active)
        values (#{name}, #{address}, #{responsible},#{telPhone},
                #{businessStart}, #{businessEnd}, #{onLine}, '1');
    </insert>
    <update id="updateInfo">
        update pm_base_hospital set
            hospital = #{name},
            address = #{address},
            responsible=#{responsible},
            tel_phone = #{telPhone},
            business_start = #{businessStart},
            business_end = #{businessEnd},
            on_line = #{onLine}
        where id = #{id}
    </update>
    <update id="delById">
        update pm_base_hospital set is_active = '0' where id = #{id}
    </update>
    <delete id="delPBCache">
        update pm_base_combination set is_active = '0' where hospital_id = #{id}
    </delete>

    <select id="getList" resultType="com.bonus.boot.manager.basic.entity.HospitalBean">
        SELECT
            id,
            hospital as name,
            address,
            responsible ,
            tel_phone as telPhone,
            business_start as businessStart,
            business_end as businessEnd,
            CONCAT(business_start,"-",business_end) as businessHours,
            on_line as onLine
        FROM pm_base_hospital
        where is_active = '1'
        <if test="name != null and name != ''">
            AND hospital LIKE concat ('%',#{name},'%')
        </if>
        <if test="address != null and address != ''">
            AND address LIKE concat ('%',#{address},'%')
        </if>
        <if test="responsible != null and responsible != ''">
            AND responsible LIKE concat ('%',#{responsible},'%')
        </if>
    </select>
    <select id="getListById" resultType="com.bonus.boot.manager.basic.entity.HospitalBean">
        SELECT
            id,
            hospital as name,
            address,
            responsible ,
            tel_phone as telPhone,
            business_start as businessStart,
            business_end as businessEnd,
            CONCAT(business_start,"-",business_end) as businessHours,
            on_line as onLine
        FROM pm_base_hospital
        where is_active = '1' and id = #{id}
    </select>
    <select id="selectPBCById" resultType="java.lang.Integer">
        select count(1) from pm_base_combination where hospital_id = #{id} and is_active = '1'
    </select>
</mapper>

