From 8ac34cbae4ea8cc47194f51389a4e2dddebcc7d5 Mon Sep 17 00:00:00 2001
From: linwei <872216696@qq.com>
Date: Thu, 02 Apr 2026 13:55:20 +0800
Subject: [PATCH] opt: sql改造其他模块改造7

---
 drone-service/drone-fw/src/main/java/org/sxkj/fw/area/mapper/FwAreaDivideMapper.xml |   48 +++++++++++++++++++++++-------------------------
 1 files changed, 23 insertions(+), 25 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 bbc12c0..979404b 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
@@ -43,7 +43,7 @@
         from
             ja_fw_area_divide ad
         left join
-            ja_fw_police_station ps on ps.id = ad.police_station_id::VARCHAR and ps.is_deleted = 0
+            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="param2.id != null and param2.id != ''">
@@ -99,7 +99,7 @@
             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::VARCHAR 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
             <if test="deptList != null and deptList.size > 0">
@@ -112,7 +112,7 @@
                 and exists (
                     select 1
                     from ja_fw_defense_scene ds
-                    join ja_fw_defense_scene_manage dsm on dsm.defense_scene_id = ds.id::VARCHAR and dsm.is_deleted = 0
+                    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 != ''
@@ -123,7 +123,7 @@
                 and exists (
                     select 1
                     from ja_fw_defense_scene ds
-                    join ja_fw_defense_scene_manage dsm on dsm.defense_scene_id = ds.id::VARCHAR and dsm.is_deleted = 0
+                    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 != ''
@@ -234,7 +234,7 @@
             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::VARCHAR 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>
@@ -262,19 +262,17 @@
             ad.area_name,
             ad.area_type_keys,
             (
-                select group_concat(distinct ds.scene_name)
+                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 = ds.id::VARCHAR and dsm.is_deleted = 0
+                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 ad.id = ANY(string_to_array(ds.area_divide_ids, ',')::bigint[])
-            ) as scene_name,
+                AND ad.id::VARCHAR = 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 = ds.id::VARCHAR and dsm.is_deleted = 0
+                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 ad.id = ANY(string_to_array(ds.area_divide_ids, ',')::bigint[])
-            ) as scene_type,
+                AND ad.id::VARCHAR = ANY(string_to_array(ds.area_divide_ids, ','))) AS scene_name,
             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
@@ -284,9 +282,9 @@
                 else (
                     select count(1)
                     from ja_fw_drone_alarm_record ar
-                    join ja_fw_device d on d.id = ar.device_id::VARCHAR and d.is_deleted = 0
+                    join ja_fw_device d on d.id::VARCHAR = ar.device_id::VARCHAR and d.is_deleted = 0
                     where ar.is_deleted = 0
-                      and d.id = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])
+                      and ad.id::VARCHAR = ANY(string_to_array(ad.device_ids, ','))
                 )
             end as alarm_count,
             case
@@ -296,7 +294,7 @@
                     from ja_fw_effect_eval ee
                     join ja_fw_device d on d.id = ee.device_id::VARCHAR and d.is_deleted = 0
                     where ee.is_deleted = 0
-                      and d.id = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])
+                      and ad.id::VARCHAR = ANY(string_to_array(ad.device_ids, ','))
                 )
             end as counter_count,
             case
@@ -307,7 +305,7 @@
                     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 = '1'
-                      and d.id = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])
+                      and ad.id::VARCHAR = ANY(string_to_array(ad.device_ids, ','))
                 )
             end as counter_success_count
             from ja_fw_area_divide ad
@@ -316,9 +314,9 @@
                 and exists (
                     select 1
                     from ja_fw_defense_scene ds
-                    join ja_fw_defense_scene_manage dsm on dsm.defense_scene_id = ds.id::VARCHAR and dsm.is_deleted = 0
+                    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 ad.id = ANY(string_to_array(ds.area_divide_ids, ',')::bigint[])
+                    and ad.id::VARCHAR = ANY(string_to_array(ad.device_ids, ','))
                 )
                 <if test="param2.id != null and param2.id != ''">
                     and ad.id = #{param2.id}
@@ -331,7 +329,7 @@
                         select 1
                         from ja_fw_defense_scene ds
                         where ds.is_deleted = 0
-                          and ad.id = ANY(string_to_array(ds.area_divide_ids, ',')::bigint[])
+                        and ad.id::VARCHAR = ANY(string_to_array(ad.device_ids, ','))
                           and ds.scene_type = #{param2.sceneType}
                     )
                 </if>
@@ -467,7 +465,7 @@
         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::VARCHAR 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
         inner join (
                 SELECT
                     d.id
@@ -497,7 +495,7 @@
                 and exists (
                 select 1
                 from ja_fw_defense_scene ds
-                join ja_fw_defense_scene_manage dsm on dsm.defense_scene_id = ds.id::VARCHAR and dsm.is_deleted = 0
+                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 != ''
@@ -508,7 +506,7 @@
                 and exists (
                 select 1
                 from ja_fw_defense_scene ds
-                join ja_fw_defense_scene_manage dsm on dsm.defense_scene_id = ds.id::VARCHAR and dsm.is_deleted = 0
+                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 != ''
@@ -565,7 +563,7 @@
         select
         count(1)
         from ja_fw_defense_scene_manage dsm
-        left join ja_fw_defense_scene ds on ds.id = dsm.defense_scene_id::VARCHAR and ds.is_deleted = 0
+        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
@@ -608,8 +606,8 @@
             #{createTime},
             #{updateUser},
             #{updateTime},
-            IFNULL(#{status}, '0'),
-            IFNULL(#{isDeleted}, 0)
+            COALESCE(#{status}, '0'),
+            COALESCE(#{isDeleted}, 0)
         )
     </insert>
 

--
Gitblit v1.9.3