From 7443694f82d81cacafb3ed395230d4961f3a17c0 Mon Sep 17 00:00:00 2001
From: linwei <872216696@qq.com>
Date: Thu, 02 Apr 2026 14:59:39 +0800
Subject: [PATCH] opt: sql改造其他模块改造9
---
drone-service/drone-fw/src/main/java/org/sxkj/fw/device/mapper/FwDeviceMapper.xml | 358 +++++++++++++++++++++++++++++------------------------------
1 files changed, 178 insertions(+), 180 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..86bb63e 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
@@ -447,190 +447,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 <= #{flyTime})
- and (dsm.effective_date_end is null or dsm.effective_date_end >= #{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 <= #{flyTime})
- and (dsm.effective_date_end is null or dsm.effective_date_end >= #{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 <= #{flyTime})
- and (dsm.effective_date_end is null or dsm.effective_date_end >= #{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 <= #{flyTime})
+ and (dsm_sub.effective_date_end is null or dsm_sub.effective_date_end >= #{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 <= #{flyTime})
- and (dsm.effective_date_end is null or dsm.effective_date_end >= #{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 <= #{flyTime})
- and (dsm.effective_date_end is null or dsm.effective_date_end >= #{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 <= #{flyTime})
+ and (dsm_sub.effective_date_end is null or dsm_sub.effective_date_end >= #{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 <= #{flyTime})
+ and (dsm_sub.effective_date_end is null or dsm_sub.effective_date_end >= #{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 <= #{flyTime})
+ and (dsm_sub.effective_date_end is null or dsm_sub.effective_date_end >= #{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 <= #{flyTime})
+ and (dsm_sub.effective_date_end is null or dsm_sub.effective_date_end >= #{flyTime})
+ )
+ </if>
+ ) AS deviceAlarmCount
</select>
<select id="selectCockpitDevicePage" resultType="org.sxkj.fw.device.vo.CockpitFwDeviceVO">
--
Gitblit v1.9.3