吉安感知网项目-后端
linwei
3 days ago 51a551a7f8eae7654f973d45cd2fa2952774673d
drone-service/drone-fw/src/main/java/org/sxkj/fw/area/mapper/FwAreaDivideMapper.xml
@@ -6,11 +6,6 @@
    <resultMap id="fwAreaDivideResultMap" type="org.sxkj.fw.area.vo.FwAreaDivideVO">
        <result column="id" property="id"/>
        <result column="area_name" property="areaName"/>
        <result column="longitude" property="longitude"/>
        <result column="latitude" property="latitude"/>
        <result column="area_size" property="areaSize"/>
        <result column="geom" property="geom"/>
        <result column="area_type" property="areaType"/>
        <result column="trigger_condition" property="triggerCondition"/>
        <result column="response_mechanism" property="responseMechanism"/>
        <result column="control_level" property="controlLevel"/>
@@ -19,22 +14,16 @@
        <result column="fly_date_start" property="flyDateStart"/>
        <result column="fly_date_end" property="flyDateEnd"/>
        <result column="area_code" property="areaCode"/>
        <result column="area_type_keys" property="areaTypeKeys"/>
        <result column="police_station_name" property="policeStationName"/>
        <result column="police_station_contact_person" property="policeStationContactPerson"/>
        <result column="police_station_contact_phone" property="policeStationContactPhone"/>
        <result column="create_user" property="createUser"/>
        <result column="create_dept" property="createDept"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
    </resultMap>
    <resultMap id="fwAreaDivideStatisticsResultMap" type="org.sxkj.fw.area.vo.FwAreaDivideStatisticsVO">
        <result column="id" property="id"/>
        <result column="area_name" property="areaName"/>
        <result column="area_type" property="areaType"/>
        <result column="area_type_keys" property="areaTypeKeys"/>
        <result column="scene_name" property="sceneName"/>
        <result column="scene_type" property="sceneType"/>
        <result column="device_count" property="deviceCount"/>
@@ -47,54 +36,21 @@
    <select id="selectFwAreaDividePage" resultMap="fwAreaDivideResultMap">
        select
        ad.id,
        ad.area_name,
        ad.longitude,
        ad.latitude,
        ad.area_size,
        case
            when ad.geom is null then null
            when ST_SRID(ad.geom) is null or ST_SRID(ad.geom) = 0 then ST_AsText(ad.geom)
            else concat(ST_AsText(ST_SwapXY(ad.geom)), ' | ', ST_SRID(ad.geom))
        end as geom,
        ad.area_type,
        ad.trigger_condition,
        ad.response_mechanism,
        ad.control_level,
        ad.police_station_id,
        ad.device_ids,
        ad.fly_date_start,
        ad.fly_date_end,
        ad.area_code,
        ps.station_name as police_station_name,
        ad.create_user,
        ad.create_dept,
        ad.create_time,
        ad.update_user,
        ad.update_time,
        ad.status,
        ad.is_deleted
        from ja_fw_area_divide ad
        left join ja_fw_police_station ps on ps.id = ad.police_station_id and ps.is_deleted = 0
            ad.*,
            ps.station_name as police_station_name,
            ps.contact_person as police_station_contact_person,
            ps.contact_phone as police_station_contact_phone
        from
            ja_fw_area_divide ad
        left join
            ja_fw_police_station ps on ps.id::VARCHAR = ad.police_station_id::VARCHAR and ps.is_deleted = 0
        <where>
            ad.is_deleted = 0
                ad.is_deleted = 0
            <if test="param2.id != null and param2.id != ''">
                and ad.id = #{param2.id}
            </if>
            <if test="param2.areaName != null and param2.areaName != ''">
                and ad.area_name like concat('%', #{param2.areaName}, '%')
            </if>
            <if test="param2.longitude != null and param2.longitude != ''">
                and ad.longitude = #{param2.longitude}
            </if>
            <if test="param2.latitude != null and param2.latitude != ''">
                and ad.latitude = #{param2.latitude}
            </if>
            <if test="param2.areaSize != null and param2.areaSize != ''">
                and ad.area_size = #{param2.areaSize}
            </if>
            <if test="param2.areaType != null and param2.areaType != ''">
                and ad.area_type = #{param2.areaType}
            </if>
            <if test="param2.triggerCondition != null and param2.triggerCondition != ''">
                and ad.trigger_condition = #{param2.triggerCondition}
@@ -120,101 +76,165 @@
            <if test="param2.areaCode != null and param2.areaCode != ''">
                and ad.area_code = #{param2.areaCode}
            </if>
            <if test="param2.areaTypeKeyList != null and param2.areaTypeKeyList.size > 0">
                and (
                    <foreach collection="param2.areaTypeKeyList" item="key" separator=" or ">
                        ARRAY_POSITION(string_to_array(ad.area_type_keys, ','), #{key}::text) IS NOT NULL
                    </foreach>
                )
            </if>
            <if test="param2.deptList != null and param2.deptList.size > 0">
                and ad.create_dept in
                <foreach collection="param2.deptList" item="deptId" open="(" separator="," close=")">
                    #{deptId}
                </foreach>
            </if>
        </where>
    </select>
    <select id="selectFwAreaDivideList" resultMap="fwAreaDivideResultMap">
        select
            ad.*,
            ps.station_name as police_station_name,
            ps.contact_person as police_station_contact_person,
            ps.contact_phone as police_station_contact_phone
        from ja_fw_area_divide ad
        left join ja_fw_police_station ps on ps.id::VARCHAR = ad.police_station_id::VARCHAR and ps.is_deleted = 0
        <where>
                ad.is_deleted = 0
            <if test="deptList != null and deptList.size > 0">
                and ad.create_dept in
                <foreach collection="deptList" item="deptId" open="(" separator="," close=")">
                    #{deptId}
                </foreach>
            </if>
            <if test="isSetSceneManage != null and isSetSceneManage == 1">
                and exists (
                    select 1
                    from ja_fw_defense_scene ds
                    join ja_fw_defense_scene_manage dsm on dsm.defense_scene_id::VARCHAR = ds.id::VARCHAR and dsm.is_deleted = 0
                    where ds.is_deleted = 0
                      and ds.area_divide_ids is not null
                      and ds.area_divide_ids != ''
                      and ad.id = ANY(string_to_array(replace(ds.area_divide_ids, ' ', ''), ',')::bigint[])
                )
            </if>
            <if test="isSetSceneManage != null and isSetSceneManage == 1 and flyTime != null">
                and exists (
                    select 1
                    from ja_fw_defense_scene ds
                    join ja_fw_defense_scene_manage dsm on dsm.defense_scene_id::VARCHAR = ds.id::VARCHAR and dsm.is_deleted = 0
                    where ds.is_deleted = 0
                      and ds.area_divide_ids is not null
                      and ds.area_divide_ids != ''
                      and ad.id = ANY(string_to_array(replace(ds.area_divide_ids, ' ', ''), ',')::bigint[])
                      and (dsm.effective_date_start is null or dsm.effective_date_start &lt;= #{flyTime})
                      and (dsm.effective_date_end is null or dsm.effective_date_end &gt;= #{flyTime})
                )
            </if>
            <if test="filterSelected != null and filterSelected == 1">
                and (
                    not exists (
                        select 1
                        from ja_fw_defense_scene ds
                        where ds.is_deleted = 0
                          and ds.area_divide_ids is not null
                          and ds.area_divide_ids != ''
                          and ad.id = ANY(string_to_array(replace(ds.area_divide_ids, ' ', ''), ',')::bigint[])
                    )
                    <if test="sceneId != null">
                        or exists (
                            select 1
                            from ja_fw_defense_scene ds
                            where ds.is_deleted = 0
                              and ds.id = #{sceneId}
                              and ds.area_divide_ids is not null
                              and ds.area_divide_ids != ''
                              and ad.id = ANY(string_to_array(replace(ds.area_divide_ids, ' ', ''), ',')::bigint[])
                        )
                    </if>
                )
            </if>
            <if test="sceneId != null and (filterSelected == null or filterSelected != 1)">
                and exists (
                    select 1
                    from ja_fw_defense_scene ds
                    where ds.is_deleted = 0
                      and ds.id = #{sceneId}
                      and ds.area_divide_ids is not null
                      and ds.area_divide_ids != ''
                      and ad.id = ANY(string_to_array(replace(ds.area_divide_ids, ' ', ''), ',')::bigint[])
                )
            </if>
            <if test="areaTypeKeyList != null and areaTypeKeyList.size > 0">
                and (
                    <foreach collection="areaTypeKeyList" item="key" separator=" or ">
                        ARRAY_POSITION(string_to_array(ad.area_type_keys, ','), #{key}::text) IS NOT NULL
                    </foreach>
                )
            </if>
        </where>
    </select>
    <select id="selectFwAreaDivideListByDeviceIds" resultMap="fwAreaDivideResultMap">
        select
        ad.id,
        ad.area_name,
        ad.longitude,
        ad.latitude,
        ad.area_size,
        case
            when ad.geom is null then null
            when ST_SRID(ad.geom) is null or ST_SRID(ad.geom) = 0 then ST_AsText(ad.geom)
            else concat(ST_AsText(ST_SwapXY(ad.geom)), ' | ', ST_SRID(ad.geom))
        end as geom,
        ad.area_type,
        ad.trigger_condition,
        ad.response_mechanism,
        ad.control_level,
        ad.police_station_id,
        ad.device_ids,
        ad.fly_date_start,
        ad.fly_date_end,
        ad.area_code,
        ps.station_name as police_station_name,
        ad.create_user,
        ad.create_dept,
        ad.create_time,
        ad.update_user,
        ad.update_time,
        ad.status,
        ad.is_deleted
        ad.device_ids
        from ja_fw_area_divide ad
        left join ja_fw_police_station ps on ps.id = ad.police_station_id and ps.is_deleted = 0
        <where>
            ad.is_deleted = 0
            <choose>
                <when test="sceneId != null">
                    and exists (
                        select 1
                        from ja_fw_defense_scene ds
                        where ds.is_deleted = 0
                          and ds.id = #{sceneId}
                          and ds.area_divide_ids is not null
                          and ds.area_divide_ids != ''
                          and find_in_set(ad.id, replace(ds.area_divide_ids, ' ', ''))
                    )
                </when>
                <when test="filterSelected != null and filterSelected == 1">
                    and not exists (
                        select 1
                        from ja_fw_defense_scene ds
                        where ds.is_deleted = 0
                          and ds.area_divide_ids is not null
                          and ds.area_divide_ids != ''
                          and find_in_set(ad.id, ds.area_divide_ids)
                    )
                </when>
            </choose>
            and ad.device_ids is not null
            and ad.device_ids != ''
            <if test="deviceIds != null and deviceIds.size > 0">
                and (
                    <foreach collection="deviceIds" item="deviceId" separator=" or ">
                        #{deviceId} = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])
                    </foreach>
                )
            </if>
        </where>
    </select>
    <select id="selectFwDefenseSceneListByAreaIds" resultType="org.sxkj.fw.area.vo.FwDefenseSceneVO">
        select
        ds.id,
        ds.scene_name as sceneName,
        ds.area_divide_ids as areaDivideIds
        from ja_fw_defense_scene ds
        <where>
            ds.is_deleted = 0
            and ds.area_divide_ids is not null
            and ds.area_divide_ids != ''
            <if test="areaIds != null and areaIds.size > 0">
                and (
                    <foreach collection="areaIds" item="areaId" separator=" or ">
                        #{areaId} = ANY(string_to_array(replace(ds.area_divide_ids, ' ', ''), ',')::bigint[])
                    </foreach>
                )
            </if>
        </where>
    </select>
    <select id="selectAreaCountByDeviceId" resultType="java.lang.Integer">
        select count(1)
        from ja_fw_area_divide ad
        <where>
            ad.is_deleted = 0
            and ad.device_ids is not null
            and ad.device_ids != ''
            and #{deviceId} = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])
        </where>
    </select>
    <select id="selectFwAreaDivideDetail" resultMap="fwAreaDivideResultMap">
        select
        ad.id,
        ad.area_name,
        ad.longitude,
        ad.latitude,
        ad.area_size,
        case
            when ad.geom is null then null
            when ST_SRID(ad.geom) is null or ST_SRID(ad.geom) = 0 then ST_AsText(ad.geom)
            else concat(ST_AsText(ST_SwapXY(ad.geom)), ' | ', ST_SRID(ad.geom))
        end as geom,
        ad.area_type,
        ad.trigger_condition,
        ad.response_mechanism,
        ad.control_level,
        ad.police_station_id,
        ad.device_ids,
        ad.fly_date_start,
        ad.fly_date_end,
        ad.area_code,
        ps.station_name as police_station_name,
        ps.contact_person as police_station_contact_person,
        ps.contact_phone as police_station_contact_phone,
        ad.create_user,
        ad.create_dept,
        ad.create_time,
        ad.update_user,
        ad.update_time,
        ad.status,
        ad.is_deleted
            ad.*,
            ps.station_name as police_station_name,
            ps.contact_person as police_station_contact_person,
            ps.contact_phone as police_station_contact_phone
        from ja_fw_area_divide ad
        left join ja_fw_police_station ps on ps.id = ad.police_station_id and ps.is_deleted = 0
        left join ja_fw_police_station ps on ps.id::VARCHAR = ad.police_station_id::VARCHAR and ps.is_deleted = 0
        where ad.is_deleted = 0
          and ad.id = #{id}
    </select>
@@ -223,7 +243,7 @@
        select
        stats.id,
        stats.area_name,
        stats.area_type,
        stats.area_type_keys,
        stats.scene_name,
        stats.scene_type,
        stats.device_count,
@@ -231,88 +251,89 @@
        stats.counter_count,
        stats.counter_success_count,
        case
            when stats.counter_count = 0 then '/'
            when stats.counter_success_count * 100.0 / stats.counter_count &gt;= 80 then '好'
            when stats.counter_success_count * 100.0 / stats.counter_count &gt;= 60 then '一般'
            else '差'
        when stats.counter_count = 0 then '/'
        when stats.counter_success_count * 100.0 / stats.counter_count &gt;= 80 then '好'
        when stats.counter_success_count * 100.0 / stats.counter_count &gt;= 60 then '一般'
        else '差'
        end as control_effect
        from (
            select
            ad.id,
            ad.area_name,
            ad.area_type,
            (
                select group_concat(distinct ds.scene_name)
        select
        ad.id,
        ad.area_name,
        ad.area_type_keys,
        (SELECT string_agg(DISTINCT ds.scene_name, ',')
        FROM ja_fw_defense_scene ds
        JOIN ja_fw_defense_scene_manage dsm ON dsm.defense_scene_id::text = ds.id::text AND dsm.is_deleted = 0
        WHERE ds.is_deleted = 0
        AND ad.id::text = ANY(string_to_array(ds.area_divide_ids, ','))) AS scene_name,
        (SELECT string_agg(DISTINCT ds.scene_type, ',')
        FROM ja_fw_defense_scene ds
        JOIN ja_fw_defense_scene_manage dsm ON dsm.defense_scene_id::text = ds.id::text AND dsm.is_deleted = 0
        WHERE ds.is_deleted = 0
        AND ad.id::text = ANY(string_to_array(ds.area_divide_ids, ','))) AS scene_type,
        CASE WHEN ad.device_ids IS NULL OR trim(ad.device_ids) = '' THEN 0
        ELSE length(replace(ad.device_ids, ' ', '')) - length(replace(replace(ad.device_ids, ' ', ''), ',', '')) + 1 END AS device_count,
        CASE WHEN ad.device_ids IS NULL OR trim(ad.device_ids) = '' THEN 0
        ELSE (SELECT count(1) FROM ja_fw_drone_alarm_record ar
        JOIN ja_fw_device d ON d.id = ar.device_id AND d.is_deleted = 0
        WHERE ar.is_deleted = 0
        AND d.id = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])) END AS alarm_count,
        CASE WHEN ad.device_ids IS NULL OR trim(ad.device_ids) = '' THEN 0
        ELSE (SELECT count(1) FROM ja_fw_effect_eval ee
        JOIN ja_fw_device d ON d.id = ee.device_id AND d.is_deleted = 0
        WHERE ee.is_deleted = 0
        AND d.id = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])) END AS counter_count,
        CASE WHEN ad.device_ids IS NULL OR trim(ad.device_ids) = '' THEN 0
        ELSE (SELECT count(1) FROM ja_fw_effect_eval ee
        JOIN ja_fw_device d ON d.id = ee.device_id AND d.is_deleted = 0
        WHERE ee.is_deleted = 0 AND ee.counter_effect = '1'
        AND d.id = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])) END AS counter_success_count
        from ja_fw_area_divide ad
        <where>
            ad.is_deleted = 0
            and exists (
            SELECT 1 FROM ja_fw_defense_scene ds
            JOIN ja_fw_defense_scene_manage dsm ON dsm.defense_scene_id::text = ds.id::text AND dsm.is_deleted = 0
            WHERE ds.is_deleted = 0
            AND ad.id::text = ANY(string_to_array(ds.area_divide_ids, ','))
            )
            <if test="param2.id != null and param2.id != ''">
                and ad.id = #{param2.id}::bigint
            </if>
            <if test="param2.areaName != null and param2.areaName != ''">
                and ad.area_name like concat('%', #{param2.areaName}, '%')
            </if>
            <if test="param2.sceneType != null and param2.sceneType != ''">
                and exists (
                select 1
                from ja_fw_defense_scene ds
                where ds.is_deleted = 0
                  and find_in_set(ad.id, ds.area_divide_ids)
            ) as scene_name,
            (
                select group_concat(distinct ds.scene_type)
                from ja_fw_defense_scene ds
                where ds.is_deleted = 0
                  and find_in_set(ad.id, ds.area_divide_ids)
            ) as scene_type,
            case
                when ad.device_ids is null or trim(ad.device_ids) = '' then 0
                else length(replace(ad.device_ids, ' ', '')) - length(replace(replace(ad.device_ids, ' ', ''), ',', '')) + 1
            end as device_count,
            case
                when ad.device_ids is null or trim(ad.device_ids) = '' then 0
                else (
                    select count(1)
                    from ja_fw_drone_alarm_record ar
                    join ja_fw_device d on d.id = ar.device_id and d.is_deleted = 0
                    where ar.is_deleted = 0
                      and find_in_set(d.id, replace(ad.device_ids, ' ', ''))
                and ad.id::text = ANY(string_to_array(ds.area_divide_ids, ','))
                and ds.scene_type = #{param2.sceneType}
                )
            end as alarm_count,
            case
                when ad.device_ids is null or trim(ad.device_ids) = '' then 0
                else (
                    select count(1)
                    from ja_fw_effect_eval ee
                    join ja_fw_device d on d.id = ee.device_id and d.is_deleted = 0
                    where ee.is_deleted = 0
                      and find_in_set(d.id, replace(ad.device_ids, ' ', ''))
            </if>
            <if test="param2.areaCode != null and param2.areaCode != ''">
                and ad.area_code = #{param2.areaCode}
            </if>
            <if test="param2.areaTypeKeyList != null and param2.areaTypeKeyList.size > 0">
                and (
                <foreach collection="param2.areaTypeKeyList" item="key" separator=" or ">
                    array_position(string_to_array(ad.area_type_keys, ','), #{key}::text) is not null
                </foreach>
                )
            end as counter_count,
            case
                when ad.device_ids is null or trim(ad.device_ids) = '' then 0
                else (
                    select count(1)
                    from ja_fw_effect_eval ee
                    join ja_fw_device d on d.id = ee.device_id and d.is_deleted = 0
                    where ee.is_deleted = 0
                      and ee.counter_effect = 'success'
                      and find_in_set(d.id, replace(ad.device_ids, ' ', ''))
                )
            end as counter_success_count
            from ja_fw_area_divide ad
            <where>
                ad.is_deleted = 0
                <if test="param2.id != null and param2.id != ''">
                    and ad.id = #{param2.id}
                </if>
                <if test="param2.areaName != null and param2.areaName != ''">
                    and ad.area_name like concat('%', #{param2.areaName}, '%')
                </if>
                <if test="param2.areaType != null and param2.areaType != ''">
                    and ad.area_type = #{param2.areaType}
                </if>
                <if test="param2.sceneType != null and param2.sceneType != ''">
                    and exists (
                        select 1
                        from ja_fw_defense_scene ds
                        where ds.is_deleted = 0
                          and find_in_set(ad.id, ds.area_divide_ids)
                          and ds.scene_type = #{param2.sceneType}
                    )
                </if>
                <if test="param2.areaCode != null and param2.areaCode != ''">
                    and ad.area_code = #{param2.areaCode}
                </if>
            </where>
            </if>
            <if test="param2.deptList != null and param2.deptList.size > 0">
                and ad.create_dept in
                <foreach collection="param2.deptList" item="deptId" open="(" separator="," close=")">
                    #{deptId}::bigint
                </foreach>
            </if>
        </where>
        ) stats
    </select>
@@ -320,7 +341,7 @@
        select
        stats.id,
        stats.area_name,
        stats.area_type,
        stats.area_type_keys,
        stats.scene_name,
        stats.scene_type,
        stats.device_count,
@@ -334,21 +355,21 @@
            else '差'
        end as control_effect
        from (
            select
            ad.id,
            ad.area_name,
            ad.area_type,
            (
                select group_concat(distinct ds.scene_name)
                from ja_fw_defense_scene ds
        select
        ad.id,
        ad.area_name,
        ad.area_type_keys,
        (
            select string_agg(distinct ds.scene_name, ',')
            from ja_fw_defense_scene ds
                where ds.is_deleted = 0
                  and find_in_set(ad.id, ds.area_divide_ids)
                  and ad.id = ANY(string_to_array(ds.area_divide_ids, ',')::bigint[])
            ) as scene_name,
            (
                select group_concat(distinct ds.scene_type)
                select string_agg(distinct ds.scene_type, ',')
                from ja_fw_defense_scene ds
                where ds.is_deleted = 0
                  and find_in_set(ad.id, ds.area_divide_ids)
                  and ad.id = ANY(string_to_array(ds.area_divide_ids, ',')::bigint[])
            ) as scene_type,
            case
                when ad.device_ids is null or trim(ad.device_ids) = '' then 0
@@ -359,9 +380,9 @@
                else (
                    select count(1)
                    from ja_fw_drone_alarm_record ar
                    join ja_fw_device d on d.id = ar.device_id and d.is_deleted = 0
                    join ja_fw_device d on d.id = ar.device_id::VARCHAR and d.is_deleted = 0
                    where ar.is_deleted = 0
                      and find_in_set(d.id, replace(ad.device_ids, ' ', ''))
                      and d.id = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])
                )
            end as alarm_count,
            case
@@ -369,9 +390,9 @@
                else (
                    select count(1)
                    from ja_fw_effect_eval ee
                    join ja_fw_device d on d.id = ee.device_id and d.is_deleted = 0
                    join ja_fw_device d on d.id = ee.device_id::VARCHAR and d.is_deleted = 0
                    where ee.is_deleted = 0
                      and find_in_set(d.id, replace(ad.device_ids, ' ', ''))
                      and d.id = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])
                )
            end as counter_count,
            case
@@ -379,10 +400,10 @@
                else (
                    select count(1)
                    from ja_fw_effect_eval ee
                    join ja_fw_device d on d.id = ee.device_id and d.is_deleted = 0
                    join ja_fw_device d on d.id = ee.device_id::VARCHAR and d.is_deleted = 0
                    where ee.is_deleted = 0
                      and ee.counter_effect = 'success'
                      and find_in_set(d.id, replace(ad.device_ids, ' ', ''))
                      and d.id = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])
                )
            end as counter_success_count
            from ja_fw_area_divide ad
@@ -403,11 +424,6 @@
        SELECT
        id,
        area_name,
        longitude,
        latitude,
        area_size,
        concat(ST_AsText(geom), ' | ', ST_SRID(geom)) as geom,
        area_type,
        trigger_condition,
        response_mechanism,
        control_level,
@@ -426,15 +442,124 @@
        FROM ja_fw_area_divide ${ew.customSqlSegment}
    </select>
    <select id="selectFwAreaDivideListCockpit" resultType="org.sxkj.fw.area.vo.FwAreaDivideVO">
        select
        ad.*,
        ps.station_name as police_station_name,
        ps.contact_person as police_station_contact_person,
        ps.contact_phone as police_station_contact_phone
        from ja_fw_area_divide ad
        left join ja_fw_police_station ps on ps.id::VARCHAR = ad.police_station_id::VARCHAR and ps.is_deleted = 0
        inner join (
        SELECT
        d.id
        FROM
        ja_fw_device d
        WHERE
        d.is_deleted = 0
        AND d.is_enabled = 1
        AND d.final_outbound_area IS NOT NULL
        <if test="regionCode != null and regionCode != ''">
            and ( d.final_outbound_area_code like concat(#{regionCode},'%')
            <if test="currentDeptId != null and currentDeptId != '' ">
                or d.id in (
                SELECT device_id FROM ja_fw_device_per_share
                /* 修改点1:参数强制转为 bigint 匹配数据库字段 */
                WHERE loan_to_dept_id = #{currentDeptId}::bigint
                AND is_deleted = 0
                )
            </if>
            )
        </if>
        GROUP BY
        d.id
        /* 修改点2:dd.id 是 bigint,转 VARCHAR 匹配文本数组,去掉不稳定的 ::bigint[] */
        ) dd on dd.id::VARCHAR = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ','))
        <where>
            ad.is_deleted = 0
            <if test="isSetSceneManage != null and isSetSceneManage == 1">
                and exists (
                select 1
                from ja_fw_defense_scene ds_sub
                join ja_fw_defense_scene_manage dsm_sub on dsm_sub.defense_scene_id::VARCHAR = ds_sub.id::VARCHAR and dsm_sub.is_deleted = 0
                where ds_sub.is_deleted = 0
                and ds_sub.area_divide_ids is not null
                and ds_sub.area_divide_ids != ''
                /* 修改点3:ad.id 转 VARCHAR 匹配 ANY */
                and ad.id::VARCHAR = ANY(string_to_array(replace(ds_sub.area_divide_ids, ' ', ''), ','))
                )
            </if>
            <if test="isSetSceneManage != null and isSetSceneManage == 1 and flyTime != null">
                and exists (
                select 1
                from ja_fw_defense_scene ds_sub2
                join ja_fw_defense_scene_manage dsm_sub2 on dsm_sub2.defense_scene_id::VARCHAR = ds_sub2.id::VARCHAR and dsm_sub2.is_deleted = 0
                where ds_sub2.is_deleted = 0
                and ds_sub2.area_divide_ids is not null
                and ds_sub2.area_divide_ids != ''
                and ad.id::VARCHAR = ANY(string_to_array(replace(ds_sub2.area_divide_ids, ' ', ''), ','))
                and (dsm_sub2.effective_date_start is null or dsm_sub2.effective_date_start &lt;= #{flyTime})
                and (dsm_sub2.effective_date_end is null or dsm_sub2.effective_date_end &gt;= #{flyTime})
                )
            </if>
            <if test="filterSelected != null and filterSelected == 1">
                and (
                not exists (
                select 1
                from ja_fw_defense_scene ds_sub3
                where ds_sub3.is_deleted = 0
                and ds_sub3.area_divide_ids is not null
                and ds_sub3.area_divide_ids != ''
                and ad.id::VARCHAR = ANY(string_to_array(replace(ds_sub3.area_divide_ids, ' ', ''), ','))
                )
                <if test="sceneId != null">
                    or exists (
                    select 1
                    from ja_fw_defense_scene ds_sub4
                    where ds_sub4.is_deleted = 0
                    and ds_sub4.id = #{sceneId}::bigint
                    and ds_sub4.area_divide_ids is not null
                    and ds_sub4.area_divide_ids != ''
                    and ad.id::VARCHAR = ANY(string_to_array(replace(ds_sub4.area_divide_ids, ' ', ''), ','))
                    )
                </if>
                )
            </if>
            <if test="sceneId != null and (filterSelected == null or filterSelected != 1)">
                and exists (
                select 1
                from ja_fw_defense_scene ds_sub5
                where ds_sub5.is_deleted = 0
                and ds_sub5.id = #{sceneId}::bigint
                and ds_sub5.area_divide_ids is not null
                and ds_sub5.area_divide_ids != ''
                and ad.id::VARCHAR = ANY(string_to_array(replace(ds_sub5.area_divide_ids, ' ', ''), ','))
                )
            </if>
            <if test="areaTypeKeyList != null and areaTypeKeyList.size > 0">
                and (
                <foreach collection="areaTypeKeyList" item="key" separator=" or ">
                    ARRAY_POSITION(string_to_array(ad.area_type_keys, ','), #{key}::VARCHAR) IS NOT NULL
                </foreach>
                )
            </if>
        </where>
    </select>
    <select id="checkAreaBindScene" resultType="java.lang.Boolean">
        select
        count(1)
        from ja_fw_defense_scene_manage dsm
        left join ja_fw_defense_scene ds on ds.id::VARCHAR = dsm.defense_scene_id::VARCHAR and ds.is_deleted = 0
        where ds.is_deleted = 0
        and #{areaId} = ANY(string_to_array(ds.area_divide_ids, ',')::bigint[])
        and dsm.is_deleted = 0
    </select>
    <insert id="insertWithGeom" parameterType="org.sxkj.fw.area.entity.FwAreaDivideEntity" useGeneratedKeys="true" keyProperty="id">
        insert into ja_fw_area_divide (
            id,
            area_name,
            longitude,
            latitude,
            area_size,
            geom,
            area_type,
            trigger_condition,
            response_mechanism,
            control_level,
@@ -443,6 +568,7 @@
            fly_date_start,
            fly_date_end,
            area_code,
            area_type_keys,
            create_user,
            create_dept,
            create_time,
@@ -453,22 +579,6 @@
        ) values (
            #{id},
            #{areaName},
            #{longitude},
            #{latitude},
            #{areaSize},
            <choose>
                <when test="geom != null and geom != ''">
                    case
                        when instr(#{geom}, '|') &gt; 0 then ST_GeomFromText(
                            trim(substring_index(#{geom}, '|', 1)),
                            cast(trim(substring_index(#{geom}, '|', -1)) as unsigned)
                        )
                        else ST_GeomFromText(trim(#{geom}))
                    end
                </when>
                <otherwise>null</otherwise>
            </choose>,
            #{areaType},
            #{triggerCondition},
            #{responseMechanism},
            #{controlLevel},
@@ -477,13 +587,14 @@
            #{flyDateStart},
            #{flyDateEnd},
            #{areaCode},
            #{areaTypeKeys},
            #{createUser},
            #{createDept},
            #{createTime},
            #{updateUser},
            #{updateTime},
            IFNULL(#{status}, '0'),
            IFNULL(#{isDeleted}, 0)
            COALESCE(#{status}, '0'),
            COALESCE(#{isDeleted}, 0)
        )
    </insert>
@@ -491,19 +602,6 @@
        update ja_fw_area_divide
        <set>
            <if test="areaName != null">area_name = #{areaName},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="areaSize != null">area_size = #{areaSize},</if>
            <if test="geom != null and geom != ''">
                geom = case
                    when instr(#{geom}, '|') &gt; 0 then ST_GeomFromText(
                        trim(substring_index(#{geom}, '|', 1)),
                        cast(trim(substring_index(#{geom}, '|', -1)) as unsigned)
                    )
                    else ST_GeomFromText(trim(#{geom}))
                end,
            </if>
            <if test="areaType != null">area_type = #{areaType},</if>
            <if test="triggerCondition != null">trigger_condition = #{triggerCondition},</if>
            <if test="responseMechanism != null">response_mechanism = #{responseMechanism},</if>
            <if test="controlLevel != null">control_level = #{controlLevel},</if>
@@ -512,6 +610,7 @@
            <if test="flyDateStart != null">fly_date_start = #{flyDateStart},</if>
            <if test="flyDateEnd != null">fly_date_end = #{flyDateEnd},</if>
            <if test="areaCode != null">area_code = #{areaCode},</if>
            <if test="areaTypeKeys != null">area_type_keys = #{areaTypeKeys},</if>
            <if test="createUser != null">create_user = #{createUser},</if>
            <if test="createDept != null">create_dept = #{createDept},</if>
            <if test="createTime != null">create_time = #{createTime},</if>