<?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.ruoyi.ibs.custmap.mapper.CustMapFavoriteMapper">
    <select id="countFavoriteCustMap" resultType="FavoriteCountVO">
        select a.city, count(distinct a.cust_name) as count_favorite from cust_info_radar a
        left join cust_map_favorite b on a.id = b.radar_id
        where b.user_name = #{userName}
        group by a.city
    </select>

    <select id="getCityWktList" resultType="FavoriteCountVO">
        select a.city, b.grid as wkt from grid_admin_division a
        left join grid_admin_division_fence b on a.id = b.id
        where a.province = '浙江省' and a.level= 2
    </select>

    <select id="getFavoriteCustList" parameterType="CustMapFavoriteDTO" resultType="CustMapVO">
        SELECT
            a.id, cust_name, lp_name, start_date, province, city, regist_capi_show, phone_number,
            address_detail, longitude, latitude,social_credit_code,
            ST_Distance_Sphere(
                point(longitude, latitude),
                point(#{longitude}, #{latitude})
            ) AS distance
        FROM
            cust_info_radar a
        LEFT JOIN cust_map_favorite b on a.id = b.radar_id
        WHERE
            b.user_name = #{userName}
        ORDER BY a.id
        <if test="isAsc != null and isAsc">
            asc
        </if>
        <if test="isAsc != null and !isAsc">
            desc
        </if>
    </select>
</mapper>