<?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.zcloud.personnel.positioning.persistence.mapper.AreaMapper">
    <select id="selectBiPersonPositionAreas"
            resultType="com.zcloud.personnel.positioning.persistence.dataobject.AreaDO">
        SELECT
            id,
            area_code,
            area_name,
            area_type,
            parent_id,
            parent_code,
            org_code,
            org_name,
            CAST(corpinfo_id AS CHAR) AS corpinfo_id,
            corpinfo_name,
            area_level,
            sort_no,
            center_lon,
            center_lat,
            polygon_json,
            status,
            bind_fence_id,
            finds_fence_id,
            delete_enum,
            remarks,
            create_name,
            update_name,
            tenant_id,
            org_id,
            env,
            version,
            create_time,
            update_time,
            create_id,
            update_id
        FROM area
        WHERE (delete_enum IS NULL OR delete_enum = 'FALSE')
          AND (status IS NULL OR status = 'ENABLED')
          AND polygon_json IS NOT NULL
          AND TRIM(polygon_json) != ''
          AND CAST(corpinfo_id AS CHAR) = CAST(#{corpinfoId} AS CHAR)
        ORDER BY sort_no ASC, area_name ASC, create_time DESC
    </select>
</mapper>
