吉安感知网项目-后端
linwei
2026-04-02 d7dd44bd7f9171d0b4fcdcb2b7605d9377002440
opt: sql改造其他模块改造9
1 files modified
187 ■■■■ changed files
drone-service/drone-fw/src/main/java/org/sxkj/fw/device/mapper/FwDeviceMapper.xml 187 ●●●● patch | view | raw | blame | history
drone-service/drone-fw/src/main/java/org/sxkj/fw/device/mapper/FwDeviceMapper.xml
@@ -256,105 +256,102 @@
   <!-- 统计设备类型(察打一体同时计入侦测和反制) -->
    <select id="statisticalDeviceType" resultType="org.sxkj.fw.cockpit.vo.DeviceStatisticsVO">
        SELECT
            CASE split_device_type  -- 自定义排序(可选)
                WHEN '1' THEN '侦测设备'
                WHEN '2' THEN '反制设备'
                ELSE '其他'
                END AS type,
            COUNT(*) AS count
        CASE split_device_type
        WHEN '1' THEN '侦测设备'
        WHEN '2' THEN '反制设备'
        ELSE '其他'
        END AS type,
        COUNT(*) AS count
        FROM (
            -- 子查询:拆分察打一体设备为侦测/反制两类
            SELECT
                d.id,
            CASE
            WHEN
                device_type = '3' THEN '1'  -- 察打一体拆分为侦测
            ELSE
                device_type
            END AS
                split_device_type
            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 != 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>
        -- 子查询:拆分察打一体设备为侦测/反制两类
        SELECT
        d.id,
        CASE
        WHEN device_type = '3' THEN '1'  -- 察打一体拆分为侦测
        ELSE device_type::VARCHAR
        END AS split_device_type
        FROM
        ja_fw_device d
        LEFT JOIN ja_fw_area_divide ad
        /* 修改点1:统一用 VARCHAR 对齐,移除容易崩溃的 ::bigint[] */
        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
        /* 修改点2:修正 bpchar <> integer 报错,给 3 加引号 */
        AND d.status::VARCHAR != '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
                /* 修改点3:loan_to_dept_id 强制转 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>
            UNION ALL  -- 合并拆分的反制部分
            SELECT
                d.id,
            CASE
            WHEN
                device_type = '3' THEN '2'  -- 察打一体拆分为反制
            ELSE
                device_type
            END AS
                split_device_type
            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 is_enabled = 1
                AND d.status != 3
                AND device_type = '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 temp
        <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 != ''
            /* 修改点4:ad.id 转 VARCHAR 匹配 ANY */
            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>
        UNION ALL  -- 合并拆分的反制部分
        SELECT
        d.id,
        CASE
        WHEN device_type = '3' THEN '2'  -- 察打一体拆分为反制
        ELSE device_type::VARCHAR
        END AS split_device_type
        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 is_enabled = 1
        /* 修改点5:修正 bpchar <> integer 报错 */
        AND d.status::VARCHAR != '3'
        AND device_type = '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 temp
        GROUP BY split_device_type
        ORDER BY split_device_type
    </select>