<?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.lantone.security.mapper.HospitalMapper">
    <select id="getHospitalTreeInfo" resultType="com.lantone.security.dto.GetHospitalTreeDTO">
        SELECT
            h.id hospitalId,
            h.parent_id parentId,
            h.`name` hospitalName,
            h.type
        FROM
            sys_hospital h
        WHERE
            h.is_deleted = 'N'
        <if test="status !=null and status!=''">
            AND h.`status` = #{status}
        </if>
        AND FIND_IN_SET(h.id, getChildList(#{hospitalId}))
    </select>
    <select id="getHospitalById" resultType="com.lantone.security.dto.GetHospitalListInfoDTO">
        SELECT
            h.id hospitalId,
            h.`name` hospitalName,
            h.parent_id parentId,
            h.`status`,
            IF (
            h.`status` = 1,
            "启用",
            "禁用"
            ) statusName,
            h.type,
            (
            CASE
            WHEN h.type = 0 THEN
            "AI质控平台"
            WHEN h.type = 1 THEN
            "集团医院"
            WHEN h.type = 2 THEN
            "医共体"
            WHEN h.type = 3 THEN
            "医联体"
            WHEN h.type = 4 THEN
            "单家医院"
            ELSE
            "未知类型"
            END
            ) typeName,
            h.gmt_create gmtCreate
        FROM
        sys_hospital h
        WHERE
        h.is_deleted = 'N'
            AND h.creator = #{getHospitalListInfoVO.creator}
        <if test="getHospitalListInfoVO.hospitalName !=null and getHospitalListInfoVO.hospitalName!=''">
            AND h.`name` LIKE concat ('%',#{getHospitalListInfoVO.hospitalName},'%')
        </if>
        <if test="getHospitalListInfoVO.type !=null and getHospitalListInfoVO.type!=''">
            AND h.type = #{getHospitalListInfoVO.type}
        </if>
        <if test="getHospitalListInfoVO.status !=null and getHospitalListInfoVO.status!=''">
            AND h.`status` = #{getHospitalListInfoVO.status}
        </if>
        OR h.id = #{getHospitalListInfoVO.hospitalId}


    </select>
    <select id="getHospitals" resultType="com.lantone.security.dto.GetDataAuthHospitalDTO">
        SELECT
            h.id,
            h.`name`,
            1 detailType
        FROM
            sys_hospital h
        WHERE
            h.is_deleted = 'N'
        AND h.`status` = 1
        <if test="hospitalIds !=null and hospitalIds.size!=0">
            AND h.id IN
            <foreach collection="hospitalIds" item="id" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
    </select>
</mapper>