From 0565a01de2888b0fb03e0ced9f4ed9d92f3e62b7 Mon Sep 17 00:00:00 2001
From: linwei <872216696@qq.com>
Date: Tue, 07 Apr 2026 18:43:39 +0800
Subject: [PATCH] opt: 人大金仓数据库改造

---
 drone-service/drone-fw/src/main/java/org/sxkj/fw/device/mapper/FwDeviceMapper.xml |  483 +++++++++++++++++++++++++++--------------------------
 1 files changed, 245 insertions(+), 238 deletions(-)

diff --git a/drone-service/drone-fw/src/main/java/org/sxkj/fw/device/mapper/FwDeviceMapper.xml b/drone-service/drone-fw/src/main/java/org/sxkj/fw/device/mapper/FwDeviceMapper.xml
index bf6caf7..9a9946b 100644
--- a/drone-service/drone-fw/src/main/java/org/sxkj/fw/device/mapper/FwDeviceMapper.xml
+++ b/drone-service/drone-fw/src/main/java/org/sxkj/fw/device/mapper/FwDeviceMapper.xml
@@ -86,10 +86,10 @@
                 and status = #{param2.status}
             </if>
             <if test="param2.isTrack != null and param2.isTrack == 1">
-                and (SELECT COUNT(*) FROM ja_fw_device_track tmp WHERE ja_fw_device.id = tmp.device_id::VARCHAR) > 0
+                and (SELECT COUNT(*) FROM ja_fw_device_track tmp WHERE ja_fw_device.id::VARCHAR = tmp.device_id::VARCHAR) > 0
             </if>
             <if test="param2.isTrack != null and param2.isTrack == 2">
-                and (SELECT COUNT(*) FROM ja_fw_device_track tmp WHERE ja_fw_device.id = tmp.device_id::VARCHAR) = 0
+                and (SELECT COUNT(*) FROM ja_fw_device_track tmp WHERE ja_fw_device.id::VARCHAR = tmp.device_id::VARCHAR) = 0
             </if>
             <if test="param2.deptList != null and param2.deptList.size > 0">
                 and ( create_dept in
@@ -188,48 +188,51 @@
             and track_status = 1
             <if test="query.isAreaSelect != null and query.isAreaSelect == 1">
                 and (
-                    <choose>
-                        <when test="query.areaId != null">
-                            exists (
-                                select 1
-                                from ja_fw_area_divide ad
-                                where ad.is_deleted = 0
-                                  and ad.id = #{query.areaId}
-                                  and ad.device_ids is not null
-                                  and ad.device_ids != ''
-                                  and ja_fw_device.id = ANY(string_to_array(ad.device_ids, ',')::bigint[])
-                            )
-                            or not exists (
-                                select 1
-                                from ja_fw_area_divide ad
-                                where ad.is_deleted = 0
-                                  and ad.device_ids is not null
-                                  and ad.device_ids != ''
-                                  and ja_fw_device.id = ANY(string_to_array(ad.device_ids, ',')::bigint[])
-                                  and ad.id != #{query.areaId}
-                            )
-                        </when>
-                        <otherwise>
-                            not exists (
-                                select 1
-                                from ja_fw_area_divide ad
-                                where ad.is_deleted = 0
-                                  and ad.device_ids is not null
-                                  and ad.device_ids != ''
-                                  and ja_fw_device.id = ANY(string_to_array(ad.device_ids, ',')::bigint[])
-                            )
-                        </otherwise>
-                    </choose>
+                <choose>
+                    <when test="query.areaId != null">
+                        exists (
+                        select 1
+                        from ja_fw_area_divide ad
+                        where ad.is_deleted = 0
+                        /* 修改点1:参数对齐 */
+                        and ad.id::text = #{query.areaId}::text
+                        and ad.device_ids is not null
+                        and ad.device_ids != ''
+                        /* 修改点2:使用 text 匹配文本数组,去掉不稳定的 ::bigint[] */
+                        and ja_fw_device.id::text = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ','))
+                        )
+                        or not exists (
+                        select 1
+                        from ja_fw_area_divide ad
+                        where ad.is_deleted = 0
+                        and ad.device_ids is not null
+                        and ad.device_ids != ''
+                        and ja_fw_device.id::text = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ','))
+                        and ad.id::text != #{query.areaId}::text
+                        )
+                    </when>
+                    <otherwise>
+                        not exists (
+                        select 1
+                        from ja_fw_area_divide ad
+                        where ad.is_deleted = 0
+                        and ad.device_ids is not null
+                        and ad.device_ids != ''
+                        and ja_fw_device.id::text = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ','))
+                        )
+                    </otherwise>
+                </choose>
                 )
             </if>
             <if test="query.status != null">
                 and status = #{query.status}
             </if>
             <if test="query.isTrack != null and query.isTrack == 1">
-                and (SELECT COUNT(*) FROM ja_fw_device_track tmp WHERE ja_fw_device.id = tmp.device_id::VARCHAR) > 0
+                /* 修改点3:解决 Position 575 报错,双向转 text */
+                and (SELECT COUNT(*) FROM ja_fw_device_track tmp WHERE ja_fw_device.id::text = tmp.device_id::text) > 0
             </if>
             <if test="query.isTrack != null and query.isTrack == 2">
-                and (SELECT COUNT(*) FROM ja_fw_device_track tmp WHERE ja_fw_device.id = tmp.device_id::VARCHAR) = 0
+                and (SELECT COUNT(*) FROM ja_fw_device_track tmp WHERE ja_fw_device.id::text = tmp.device_id::text) = 0
             </if>
             and longitude is not null
             and longitude != ''
@@ -237,12 +240,13 @@
             and latitude != ''
             <if test="query.polygons != null and query.polygons.size > 0">
                 and (
-                    <foreach collection="query.polygons" item="polygon" separator=" OR ">
-                        ST_Contains(
-                            ST_SRID(ST_GeomFromText(#{polygon}), 4326),
-                            ST_GeomFromText(CONCAT('POINT(', latitude, ' ', longitude, ')'), 4326)
-                        )
-                    </foreach>
+                <foreach collection="query.polygons" item="polygon" separator=" OR ">
+                    public.st_contains(
+                    public.st_srid(public.st_geomfromtext(#{polygon}), 4326),
+                    /* 注意:Kingbase/PostGIS 坐标顺序通常是 (经度, 纬度) 即 (longitude, latitude) */
+                    public.st_geomfromtext(CONCAT('POINT(', longitude, ' ', latitude, ')'), 4326)
+                    )
+                </foreach>
                 )
             </if>
         </where>
@@ -279,7 +283,7 @@
         WHERE
         d.is_deleted = 0
         AND d.is_enabled = 1
-        /* 修改点2:修正 bpchar <> integer 报错,给 3 加引号 */
+        /* 修改点2:修正 bpchar  integer 报错,给 3 加引号 */
         AND d.status::VARCHAR != '3'
         <if test="regionCode != null and regionCode != ''">
             and (d.final_outbound_area_code like concat(#{regionCode}, '%')
@@ -324,7 +328,7 @@
         WHERE
         d.is_deleted = 0
         AND is_enabled = 1
-        /* 修改点5:修正 bpchar <> integer 报错 */
+        /* 修改点5:修正 bpchar  integer 报错 */
         AND d.status::VARCHAR != '3'
         AND device_type = '3'
         <if test="regionCode != null and regionCode != ''">
@@ -447,190 +451,188 @@
      <!-- 查询设备总数 + 无线电/光电/雷达设备数量 -->
     <select id="statisticalDeviceAtt" resultType="org.sxkj.fw.cockpit.vo.AlarmStatisticsVO">
         SELECT
-            -- 设备统计总数
-            (SELECT
-                 COUNT(*)
-             FROM
-                 ja_fw_device d
-            left join ja_fw_area_divide ad
-                on d.id::VARCHAR = ANY(string_to_array(ad.device_ids, ','))
-                and ad.is_deleted = 0
-             WHERE
-                 d.is_deleted = 0
-               and d.is_enabled = 1
-                <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
-                        WHERE loan_to_dept_id = #{currentDeptId}
-                        AND is_deleted = 0
-                        )
-                    </if>
-                    )
-                </if>
-                <if test="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>
-             ) AS deviceCount,
-            -- 无线电设备数量
-            (SELECT
-                 COUNT(*)
-             FROM
-                 ja_fw_device d
-            left join ja_fw_area_divide ad
-                on d.id::VARCHAR = ANY(string_to_array(ad.device_ids, ','))
-                and ad.is_deleted = 0
-             WHERE
-                 d.is_deleted = 0
-               and d.is_enabled = 1
-               AND device_att = '1'
-                <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
-                        WHERE loan_to_dept_id = #{currentDeptId}
-                        AND is_deleted = 0
-                        )
-                    </if>
-                    )
-                </if>
-                <if test="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>
-             ) AS radioCount,
-            -- 光电设备数量
-            (SELECT
-                 COUNT(*)
-             FROM
-                 ja_fw_device d
-            left join ja_fw_area_divide ad
-                on d.id::VARCHAR = ANY(string_to_array(ad.device_ids, ','))
-                and ad.is_deleted = 0
-             WHERE d.is_deleted = 0
-               and d.is_enabled = 1
-               AND device_att = '2'
-            <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
-                    WHERE loan_to_dept_id = #{currentDeptId}
-                    AND is_deleted = 0
-                    )
-                </if>
+        -- 设备统计总数
+        (SELECT
+        COUNT(*)
+        FROM
+        ja_fw_device d
+        left join ja_fw_area_divide ad
+        /* 修改点1:统一用 VARCHAR 对齐匹配 */
+        on d.id::VARCHAR = ANY(string_to_array(ad.device_ids, ','))
+        and ad.is_deleted = 0
+        WHERE
+        d.is_deleted = 0
+        and d.is_enabled = 1
+        <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
+                /* 修改点2:强制参数转为 bigint 以匹配数据库字段 */
+                WHERE loan_to_dept_id = #{currentDeptId}::bigint
+                AND is_deleted = 0
                 )
             </if>
-            <if test="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="flyTime != null">
+            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 匹配文本数组 */
+            and ad.id::VARCHAR = ANY(string_to_array(replace(ds_sub.area_divide_ids, ' ', ''), ','))
+            and (dsm_sub.effective_date_start is null or dsm_sub.effective_date_start &lt;= #{flyTime})
+            and (dsm_sub.effective_date_end is null or dsm_sub.effective_date_end &gt;= #{flyTime})
+            )
+        </if>
+        ) AS deviceCount,
+        -- 无线电设备数量
+        (SELECT
+        COUNT(*)
+        FROM
+        ja_fw_device d
+        left join ja_fw_area_divide ad
+        on d.id::VARCHAR = ANY(string_to_array(ad.device_ids, ','))
+        and ad.is_deleted = 0
+        WHERE
+        d.is_deleted = 0
+        and d.is_enabled = 1
+        AND device_att = '1'
+        <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
+                WHERE loan_to_dept_id = #{currentDeptId}::bigint
+                AND is_deleted = 0
                 )
             </if>
-             ) AS opticalCount,
-            -- 雷达设备数量
-            (SELECT
-                 COUNT(*)
-             FROM ja_fw_device d
-             left join ja_fw_area_divide ad
-                on d.id::VARCHAR = ANY(string_to_array(ad.device_ids, ','))
-                and ad.is_deleted = 0
-             WHERE d.is_deleted = 0
-               and d.is_enabled = 1
-               AND device_att = '3'
-                <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
-                        WHERE loan_to_dept_id = #{currentDeptId}
-                        AND is_deleted = 0
-                        )
-                    </if>
-                    )
-                </if>
-                <if test="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>
-             ) AS radarCount,
-            -- 设备告警
-            (SELECT
-                 COUNT(*)
-             FROM ja_fw_device d
-            left join ja_fw_area_divide ad
-                on d.id::VARCHAR = ANY(string_to_array(ad.device_ids, ','))
-                and ad.is_deleted = 0
-             WHERE d.is_deleted = 0
-               and d.is_enabled = 1
-               AND d.status in ('1', '2', '3' )
-                <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
-                        WHERE loan_to_dept_id = #{currentDeptId}
-                        AND is_deleted = 0
-                        )
-                    </if>
-                    )
-                </if>
-                <if test="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>
-             ) AS deviceAlarmCount
+            )
+        </if>
+        <if test="flyTime != null">
+            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 != ''
+            and ad.id::VARCHAR = ANY(string_to_array(replace(ds_sub.area_divide_ids, ' ', ''), ','))
+            and (dsm_sub.effective_date_start is null or dsm_sub.effective_date_start &lt;= #{flyTime})
+            and (dsm_sub.effective_date_end is null or dsm_sub.effective_date_end &gt;= #{flyTime})
+            )
+        </if>
+        ) AS radioCount,
+        -- 光电设备数量
+        (SELECT
+        COUNT(*)
+        FROM
+        ja_fw_device d
+        left join ja_fw_area_divide ad
+        on d.id::VARCHAR = ANY(string_to_array(ad.device_ids, ','))
+        and ad.is_deleted = 0
+        WHERE d.is_deleted = 0
+        and d.is_enabled = 1
+        AND device_att = '2'
+        <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
+                WHERE loan_to_dept_id = #{currentDeptId}::bigint
+                AND is_deleted = 0
+                )
+            </if>
+            )
+        </if>
+        <if test="flyTime != null">
+            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 != ''
+            and ad.id::VARCHAR = ANY(string_to_array(replace(ds_sub.area_divide_ids, ' ', ''), ','))
+            and (dsm_sub.effective_date_start is null or dsm_sub.effective_date_start &lt;= #{flyTime})
+            and (dsm_sub.effective_date_end is null or dsm_sub.effective_date_end &gt;= #{flyTime})
+            )
+        </if>
+        ) AS opticalCount,
+        -- 雷达设备数量
+        (SELECT
+        COUNT(*)
+        FROM ja_fw_device d
+        left join ja_fw_area_divide ad
+        on d.id::VARCHAR = ANY(string_to_array(ad.device_ids, ','))
+        and ad.is_deleted = 0
+        WHERE d.is_deleted = 0
+        and d.is_enabled = 1
+        AND device_att = '3'
+        <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
+                WHERE loan_to_dept_id = #{currentDeptId}::bigint
+                AND is_deleted = 0
+                )
+            </if>
+            )
+        </if>
+        <if test="flyTime != null">
+            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 != ''
+            and ad.id::VARCHAR = ANY(string_to_array(replace(ds_sub.area_divide_ids, ' ', ''), ','))
+            and (dsm_sub.effective_date_start is null or dsm_sub.effective_date_start &lt;= #{flyTime})
+            and (dsm_sub.effective_date_end is null or dsm_sub.effective_date_end &gt;= #{flyTime})
+            )
+        </if>
+        ) AS radarCount,
+        -- 设备告警
+        (SELECT
+        COUNT(*)
+        FROM ja_fw_device d
+        left join ja_fw_area_divide ad
+        on d.id::VARCHAR = ANY(string_to_array(ad.device_ids, ','))
+        and ad.is_deleted = 0
+        WHERE d.is_deleted = 0
+        and d.is_enabled = 1
+        AND d.status in ('1', '2', '3' )
+        <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
+                WHERE loan_to_dept_id = #{currentDeptId}::bigint
+                AND is_deleted = 0
+                )
+            </if>
+            )
+        </if>
+        <if test="flyTime != null">
+            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 != ''
+            and ad.id::VARCHAR = ANY(string_to_array(replace(ds_sub.area_divide_ids, ' ', ''), ','))
+            and (dsm_sub.effective_date_start is null or dsm_sub.effective_date_start &lt;= #{flyTime})
+            and (dsm_sub.effective_date_end is null or dsm_sub.effective_date_end &gt;= #{flyTime})
+            )
+        </if>
+        ) AS deviceAlarmCount
     </select>
 
     <select id="selectCockpitDevicePage" resultType="org.sxkj.fw.device.vo.CockpitFwDeviceVO">
@@ -751,7 +753,7 @@
             END AS isShared
         FROM
             ja_fw_device d
-            LEFT JOIN ja_fw_device_per_share ps ON ps.device_id = d.id::VARCHAR
+            LEFT JOIN ja_fw_device_per_share ps ON ps.device_id::VARCHAR = d.id::VARCHAR
             AND ps.loan_to_dept_id = #{currentDeptId}
             AND ps.is_deleted = 0
         WHERE
@@ -765,15 +767,16 @@
 
     <select id="getDeviceStatistics" resultType="org.sxkj.fw.cockpit.vo.DeviceStatisticsVO">
         SELECT
-            d.final_outbound_area AS type,
-            COUNT(*) AS count
+        d.final_outbound_area AS type,
+        COUNT(*) AS count
         FROM
-            ja_fw_device d
+        ja_fw_device d
         LEFT JOIN ja_fw_area_divide ad
+        /* 修改点1:d.id 是数字,匹配文本数组需转 VARCHAR */
         on d.id::VARCHAR = ANY(string_to_array(ad.device_ids, ','))
         AND ad.is_deleted = 0
         WHERE
-            d.is_deleted = 0
+        d.is_deleted = 0
         AND d.is_enabled = 1
         AND d.final_outbound_area IS NOT NULL
         <if test="regionCode != null and regionCode != ''">
@@ -782,7 +785,9 @@
                 or d.id IN (
                 SELECT device_id::bigint
                 FROM ja_fw_device_per_share
-                WHERE loan_to_dept_id = #{currentDeptId}
+                WHERE
+                /* 修改点2:强制显式转换参数,防止 bigint = character varying */
+                loan_to_dept_id = #{currentDeptId}::bigint
                 AND is_deleted = 0
                 )
             </if>
@@ -791,14 +796,16 @@
         <if test="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}::timestamp)
-            and (dsm.effective_date_end is null or dsm.effective_date_end &gt;= #{flyTime}::timestamp)
+            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 匹配,去掉不稳定的 ::bigint[] */
+            and ad.id::VARCHAR = ANY(string_to_array(replace(ds_sub.area_divide_ids, ' ', ''), ','))
+            /* 修改点4:日期比对确保类型对等 */
+            and (dsm_sub.effective_date_start is null or dsm_sub.effective_date_start &lt;= #{flyTime})
+            and (dsm_sub.effective_date_end is null or dsm_sub.effective_date_end &gt;= #{flyTime})
             )
         </if>
         GROUP BY

--
Gitblit v1.9.3