HospitalMapper.xml 4.3 KB
<?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.rejoice.hospital.mapper.HospitalMapper">


    <select id="searchHospital" parameterType="cn.brotop.hospital.controller.dto.hospital.SearchHospitalDTO" resultType="cn.brotop.hospital.controller.vo.hospital.HospitalListVO">
        select
        id,hospitalName,hospitalAvatar,hospitalDetailAddress,hospitalListDetails,hospitalLevelName,hospitalTypeName,hospitalLongitude
        ,hospitalLatitude,hospitalMobile,hospitalAdvisoryNum,hospitalPraiseRate,distance from (
        select t.id,t.hospital_name as hospitalName,t.hospital_avatar as hospitalAvatar,t.hospital_detail_address as
        hospitalDetailAddress,t.hospital_list_details as hospitalListDetails,
        (select h.name from tb_hospital_type h where h.id=t.hospital_level) as hospitalLevelName,
        (select h.name from tb_hospital_type h where h.id=t.hospital_type) as hospitalTypeName,
        t.hospital_longitude as hospitalLongitude,t.hospital_latitude as hospitalLatitude ,
        t.hospital_mobile as hospitalMobile,t.hospital_advisory_num as hospitalAdvisoryNum,
        t.hospital_praise_rate as hospitalPraiseRate
        ,(select (6371 * acos(cos(radians(#{searchHospitalDTO.latitude})) * cos(radians(t.hospital_latitude)) * cos(radians(t.hospital_longitude)
        - radians(#{searchHospitalDTO.longitude})) + sin(radians(#{searchHospitalDTO.latitude})) *
        sin(radians(t.hospital_latitude))))) as distance
        from tb_hospital t
            where t.hospital_status =1
            <if test="searchHospitalDTO.keyWords!=null and searchHospitalDTO.keyWords!=''">and t.hospital_name like
                concat('%',#{searchHospitalDTO.keyWords},'%')
            </if>
        <if test="searchHospitalDTO.provinceId!=null">
            and t.hospital_province_id=#{searchHospitalDTO.provinceId}
        </if>
        <if test="searchHospitalDTO.cityId!=null">
            and t.hospital_city_id=#{searchHospitalDTO.cityId}
        </if>

        <if test="searchHospitalDTO.type!=null and searchHospitalDTO.type==2">
            order by t.hospital_praise_rate desc
        </if>
        <if test="searchHospitalDTO.type!=null and searchHospitalDTO.type==3">
            order by t.hospital_advisory_num desc
        </if>
        <if test="searchHospitalDTO.type!=null and searchHospitalDTO.type==1">
            order by t.hospital_created desc
        </if>
    ) as temporarytable
        <if test="searchHospitalDTO.type!=null and searchHospitalDTO.type==4">
            order by distance desc
        </if>
    </select>
    <select id="getHospitalDetail" resultType="cn.brotop.hospital.controller.vo.hospital.HospitalDetailVO">
        select t.id,t.hospital_name as hospitalName,t.hospital_avatar as hospitalAvatar,t.hospital_detail_address as
                                       hospitalDetailAddress,t.hospital_list_details as hospitalListDetails,
               (select h.name from tb_hospital_type h where h.id=t.hospital_level) as hospitalLevelName,
               (select h.name from tb_hospital_type h where h.id=t.hospital_type) as hospitalTypeName,
               t.hospital_longitude as hospitalLongitude,t.hospital_latitude as hospitalLatitude ,
               t.hospital_mobile as hospitalMobile,t.hospital_advisory_num as hospitalAdvisoryNum,
               t.hospital_praise_rate as hospitalPraiseRate,t.hospital_introduction as hospitalIntroduction
            from tb_hospital t where t.id=#{hospitalId}
    </select>
    <select id="findByHospitalIds" resultType="cn.brotop.api.hospital.DTO.HospitalRpcDTO">
        select id as hospitalId,hospital_name as  hospitalName,
               (select h.name from tb_hospital_type h where h.id=hospital_level) as hospitalLevel
               from tb_hospital where id in
        <foreach collection="hospitalIds" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>

    </select>
    <select id="findByHospitalId" resultType="cn.brotop.api.hospital.DTO.HospitalRpcDTO">
        select id as hospitalId,hospital_name as  hospitalName,
               (select h.name from tb_hospital_type h where h.id=hospital_level) as hospitalLevel
        from tb_hospital where id=#{hospitalId}
    </select>
</mapper>