<?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.sqx.modules.timedtask.dao.RiderLocationDao">

    <select id="selectAllRiderLocation" resultType="com.sqx.modules.timedtask.entity.RiderLocation">
        select * from rider_location r,tb_user u where r.user_id = u.user_id and u.user_type =2
        <if test="province!=null and province!=''">
            and r.province = #{province}
        </if>
        <if test="city!=null and city!=''">
            and r.city = #{city}
        </if>
        <if test="district!=null and district!=''">
            and r.district = #{district}
        </if>
        <if test="nickName!=null and nickName!=''">
            and u.nick_name like concat("%",#{nickName},"%")
        </if>
    </select>
    <select id="getUserRiderCount" resultType="java.lang.Integer">
        select count(*)
        from (SELECT *,
                     (st_distance(POINT(r.lng, r.lat),
                                  POINT(#{lng}, #{lat})) *
                      111195) AS distance
              FROM rider_location r
              WHERE (r.city = #{city} or r.province = #{city})) t1
        where t1.distance &lt;= #{kilometreCount} * 1000
    </select>
    <select id="getRiderCount" resultType="java.util.HashMap">
        SELECT *
        FROM (SELECT u.user_id     as userId,
                     u.`nick_name` as userName,
                     u.avatar,
                     u.phone,
                     r.lng,
                     r.lat,
                     r.city,
                     (select if(count(0) > 0, 1, 0) from sys_indent s where s.rider_user_id = u.user_id and s.indent_state in(1,2)) as riderStatus,
                  (st_distance(POINT(r.lng, r.lat),
                               POINT(#{lng}, #{lat})) *
                   111195) AS distance
              FROM rider_location r,
                   tb_user u
              WHERE r.`user_id` = u.`user_id`
                and u.on_line_flag = 1
                and u.status = 1
                and u.check_certification = 1
                AND (r.city = #{city} OR r.province = #{city})) t1
        where t1.distance &lt;= #{kilometreCount} * 1000
    </select>
</mapper>