<?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="org.jeecg.modules.hotelshop.mapper.HotelShopMapper">


    <select id="getDistance" resultType="org.jeecg.modules.hotelshop.entity.HotelShop">
        SELECT a.id,
               (6371 * acos(
                               cos(radians(${lat})) * cos(radians(a.latitude)) * cos(radians(a.longitude) - radians(${lng})) +
                               sin(radians(${lat})) * sin(radians(a.latitude))
                   )) AS distance
        FROM hotel_shop a WHERE a.del_flag = 0 AND a.status = 1 AND a.user_num != (select count(1) from han_hai_member where shop_id = a.id) ORDER BY distance ASC LIMIT 1;
    </select>

</mapper>