<?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.draw.mapper.DrawLayerMapper">


    <select id="getLayerList" resultType="com.ruoyi.ibs.draw.domain.vo.LayerRuleVO">
        select layer_id,layer_name from draw_layer
         where  delete_flag = 0
         and layer_id in
        (select layer_id from draw_shape where ops_dept = #{opsDept} and delete_flag = 0 and dept_id like concat(#{deptId},'%') group by layer_id)
    </select>


    <select id="getDrawLayerList" resultType="DrawLayerVO">
        select dl.layer_id, dl.layer_name, dl.layer_color, ifnull(sum(ds.shape_id) = 0, 1) as disabled from draw_layer dl
        left join (
        select * from draw_shape where delete_flag = '0'
             <if test="deptId != null and deptId != ''">  and left(dept_id,3) = left(#{deptId},3) </if>
            and relate_flag = '0'
        ) ds on ds.layer_id = dl.layer_id
        where dl.delete_flag = '0'   and dl.dept_id like concat(#{deptHead},'%')
        <if test="layerName != null and layerName != ''">  and dl.layer_name like concat('%', #{layerName}, '%')  </if>
        group by dl.layer_id, dl.layer_name
        order by dl.layer_id desc
    </select>



    <select id="getValidDrawLayerList" resultType="DrawLayerVO">
        select dl.layer_id, dl.layer_name, dl.layer_color, ifnull(sum(ds.audit_flag) = 0, 1) as disabled from draw_layer dl
        left join (
            select *, if(audit_status ='1', 1, 0) as audit_flag from draw_shape
            where delete_flag = '0' and ops_dept = #{opsDept} and dept_id = #{deptId} and relate_flag = '0'
        ) ds on ds.layer_id = dl.layer_id
        where dl.delete_flag = '0'
          and dl.dept_id like concat(#{deptHead},'%')
        group by dl.layer_id, dl.layer_name
        order by disabled
    </select>

    <select id="queryBusinessFreqList" resultType="MapCustCountVO">
        select  round(iaa.longitude, 4) as lng,  round(iaa.latitude, 4) as lat, count(*) as count from cust_info_business cir
          left join ibs_anchor ia on cir.cust_id = ia.cust_id
          left join ibs_anchor_address iaa on ia.address_id = iaa.id
        where iaa.longitude is not null and length(iaa.longitude) != 0 and iaa.latitude is not null and length(iaa.latitude) != 0
        group by lng, lat;
        </select>
</mapper>