<?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.userCode.mapper.TaskMapper">
    <!-- 通过字典code获取字典数据 -->
    <select id="tasks" parameterType="String"
            resultType="org.jeecg.modules.userCode.model.vo.TbTaskVo">
   select *
        from (

        SELECT *,ROUND(
        6378.138 * 2 * ASIN(
        SQRT(
        POW(
        SIN(
        (
        #{lat,jdbcType=VARCHAR} * PI() / 180 - SUBSTRING_INDEX(longitude,',',-1) * PI() / 180
        ) / 2
        ),
        2
        ) + COS(#{lat,jdbcType=VARCHAR} * PI() / 180) * COS(SUBSTRING_INDEX(longitude,',',-1) * PI() / 180) * POW(
        SIN(
        (
        #{lon,jdbcType=VARCHAR} * PI() / 180 - SUBSTRING_INDEX(longitude,',',1) * PI() / 180
        ) / 2
        ),
        2
        )
        )
        ) * 1000
        ) AS distances
        FROM
        tb_task
        where   del_flag =0 and audit_status =1 and role in (0,1)
        ORDER BY distances ASC)
        as a
        <where>
            del_flag =0
            <if test="search!=null and search!='' ">
                and a.name like '%${search}%'
            </if>
            <if test="distance!=null and distance!='' ">
                and a.distances <![CDATA[ <=]]> #{distance}
            </if>
        </where>
    </select>


</mapper>
