<?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.unis.basic.info.modular.grainPriceCollect.mapper.GrainPriceCollectMapper">

    <select id="getMonitorInfo" resultType="java.util.Map">
--         SELECT a.id as "id",a.name as "name",sys_org_id as "sysOrgId",b.name as "sysName"  FROM biz_price_monitor a LEFT JOIN sys_org b on a.sys_org_id = b.ID
         SELECT
            CAST(a.id AS CHAR) AS "id",
            a. NAME AS "name",
            a. location_switch AS "locationSwitch",
            a.address as "address",
            CAST(c.id AS CHAR) as "userId",
            c.name as "userName",
            c.phone as "userPhone",
            d.ID as "sysOrgId",
            d.name as "sysOrgName"
        FROM
            biz_price_monitor a
        LEFT JOIN biz_user_price b ON a.id = b.price_monitor_id
        LEFT JOIN biz_user_collect c on c.id = b.user_collect_id
        LEFT JOIN sys_org d on d.ID = a.sys_org_id
        where c.id = #{userId}

    </select>
    <select id="getMonitorInfoByPoint" resultType="java.util.Map">
        SELECT
        CAST(a.id AS CHAR) AS "id",
        a. NAME AS "name",
        a.address as "address"
        FROM
        biz_price_monitor a
        LEFT JOIN biz_user_price b ON a.id = b.price_monitor_id
        where b.user_collect_id = #{userId}
        and ST_Distance(geo_point, ST_GeomFromText(#{point}))* 1000  &lt; 100
        ORDER BY ST_Distance(geo_point, ST_GeomFromText(#{point})) LIMIT 0,1
    </select>
    <select id="selectMyMapsPage" resultType="java.util.Map">
        SELECT
        CAST(a.id AS CHAR) AS "id",
        b.name as "monitorName",
        b.address as "address",
        c.name as "orgName",
        a.user_collect_name as "userCollectName",
        DATE_FORMAT(a.user_collect_time,'%Y-%m-%d %T') as "userCollectTime",
        DATE_FORMAT(a.user_collect_date,'%Y-%m-%d') as "userCollectDate",
        a.audit_status as "status"
        FROM
        biz_grain_price_collect a
        LEFT JOIN biz_price_monitor b ON a.price_monitor_id = b.id
        LEFT JOIN sys_org c on b.sys_org_id = c.ID
        <if test="ew.sqlSegment != null and ew.sqlSegment != ''">
            where ${ew.sqlSegment}
        </if>
        order by a.user_collect_time desc
    </select>
    <select id="getOffPrice" resultType="java.util.Map">
         SELECT
        price as "offPrice"
        FROM
            biz_grain_price_collect_category a
        INNER JOIN biz_grain_price_collect b ON a.type_id = b.id
        INNER JOIN biz_price_monitor c ON b.price_monitor_id = c.id
        WHERE b.id != #{grainPriceCollectId}
                and b.price_monitor_id = #{priceMonitorId}
                and a.type = #{type}
              AND IFNULL(a.first_level, 0) = #{firstLevel}
             AND IFNULL(a.second_level, 0) = #{secondLevel}
             AND IFNULL(a.three_level, 0) = #{threeLevel}
      ORDER BY
        b.user_collect_time desc LIMIT 0,1
    </select>
</mapper>