From fefe259f19a251d90d17d8a42e04f6332a4cad3e Mon Sep 17 00:00:00 2001
From: linwei <872216696@qq.com>
Date: Fri, 23 Jan 2026 15:37:30 +0800
Subject: [PATCH] sql 优化
---
drone-service/drone-fw/src/main/java/org/sxkj/fw/area/mapper/FwAreaDivideMapper.xml | 84 +++++++++++++++++++++++++++++++++--------
1 files changed, 67 insertions(+), 17 deletions(-)
diff --git a/drone-service/drone-fw/src/main/java/org/sxkj/fw/area/mapper/FwAreaDivideMapper.xml b/drone-service/drone-fw/src/main/java/org/sxkj/fw/area/mapper/FwAreaDivideMapper.xml
index d561a38..da5d2e1 100644
--- a/drone-service/drone-fw/src/main/java/org/sxkj/fw/area/mapper/FwAreaDivideMapper.xml
+++ b/drone-service/drone-fw/src/main/java/org/sxkj/fw/area/mapper/FwAreaDivideMapper.xml
@@ -28,7 +28,6 @@
<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">
@@ -156,29 +155,80 @@
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 (
+ <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.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>
+ <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 find_in_set(ad.id, replace(ds.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
+ 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, ' ', ''))
+ )
+ </if>
+ </where>
+ </select>
+
+ <select id="selectFwAreaDivideListByDeviceIds" resultMap="fwAreaDivideResultMap">
+ select
+ ad.id,
+ ad.area_name,
+ ad.device_ids
+ from ja_fw_area_divide ad
+ <where>
+ ad.is_deleted = 0
+ 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 ">
+ find_in_set(#{deviceId}, replace(ad.device_ids, ' ', ''))
+ </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 ">
+ find_in_set(#{areaId}, replace(ds.area_divide_ids, ' ', ''))
+ </foreach>
+ )
+ </if>
</where>
</select>
--
Gitblit v1.9.3