From 3dcef55348087d16bb6d2c5f604f3cfa52425fb8 Mon Sep 17 00:00:00 2001
From: linwei <872216696@qq.com>
Date: Thu, 02 Apr 2026 15:05:07 +0800
Subject: [PATCH] opt: sql改造其他模块改造9

---
 drone-service/drone-fw/src/main/java/org/sxkj/fw/area/mapper/FwAreaDivideMapper.xml |  271 ++++++++++++++++++++++++++----------------------------
 1 files changed, 131 insertions(+), 140 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 2fdfeb3..970e5e5 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 != ''">
@@ -79,7 +79,7 @@
             <if test="param2.areaTypeKeyList != null and param2.areaTypeKeyList.size > 0">
                 and (
                     <foreach collection="param2.areaTypeKeyList" item="key" separator=" or ">
-                        find_in_set(#{key}, ad.area_type_keys)
+                        ARRAY_POSITION(string_to_array(ad.area_type_keys, ','), #{key}) IS NOT NULL
                     </foreach>
                 )
             </if>
@@ -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,22 +112,22 @@
                 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 != ''
-                      and find_in_set(ad.id, replace(ds.area_divide_ids, ' ', ''))
+                      and ad.id = ANY(string_to_array(replace(ds.area_divide_ids, ' ', ''), ',')::bigint[])
                 )
             </if>
             <if test="isSetSceneManage != null and isSetSceneManage == 1 and flyTime != null">
                 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 != ''
-                      and find_in_set(ad.id, replace(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})
                 )
@@ -140,7 +140,7 @@
                         where ds.is_deleted = 0
                           and ds.area_divide_ids is not null
                           and ds.area_divide_ids != ''
-                          and find_in_set(ad.id, replace(ds.area_divide_ids, ' ', ''))
+                          and ad.id = ANY(string_to_array(replace(ds.area_divide_ids, ' ', ''), ',')::bigint[])
                     )
                     <if test="sceneId != null">
                         or exists (
@@ -150,7 +150,7 @@
                               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, ' ', ''))
+                              and ad.id = ANY(string_to_array(replace(ds.area_divide_ids, ' ', ''), ',')::bigint[])
                         )
                     </if>
                 )
@@ -163,13 +163,13 @@
                       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, ' ', ''))
+                      and ad.id = ANY(string_to_array(replace(ds.area_divide_ids, ' ', ''), ',')::bigint[])
                 )
             </if>
             <if test="areaTypeKeyList != null and areaTypeKeyList.size > 0">
                 and (
                     <foreach collection="areaTypeKeyList" item="key" separator=" or ">
-                        find_in_set(#{key}, ad.area_type_keys)
+                        ARRAY_POSITION(string_to_array(ad.area_type_keys, ','), #{key}) IS NOT NULL
                     </foreach>
                 )
             </if>
@@ -189,7 +189,7 @@
             <if test="deviceIds != null and deviceIds.size > 0">
                 and (
                     <foreach collection="deviceIds" item="deviceId" separator=" or ">
-                        find_in_set(#{deviceId}, replace(ad.device_ids, ' ', ''))
+                        #{deviceId} = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])
                     </foreach>
                 )
             </if>
@@ -209,7 +209,7 @@
             <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, ' ', ''))
+                        #{areaId} = ANY(string_to_array(replace(ds.area_divide_ids, ' ', ''), ',')::bigint[])
                     </foreach>
                 )
             </if>
@@ -223,7 +223,7 @@
             ad.is_deleted = 0
             and ad.device_ids is not null
             and ad.device_ids != ''
-            and find_in_set(#{deviceId}, replace(ad.device_ids, ' ', ''))
+            and #{deviceId} = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])
         </where>
     </select>
 
@@ -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>
@@ -258,67 +258,55 @@
                 end as control_effect
         from (
             select
-            ad.id,
-            ad.area_name,
-            ad.area_type_keys,
-            (
-                select group_concat(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
-                where ds.is_deleted = 0
-                  and find_in_set(ad.id, ds.area_divide_ids)
-            ) as scene_name,
-            (
-                select group_concat(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
-                where ds.is_deleted = 0
-                  and find_in_set(ad.id, ds.area_divide_ids)
-            ) as scene_type,
-            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
-            end as device_count,
-            case
-                when ad.device_ids is null or trim(ad.device_ids) = '' then 0
-                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
-                    where ar.is_deleted = 0
-                      and find_in_set(d.id, replace(ad.device_ids, ' ', ''))
-                )
-            end as alarm_count,
-            case
-                when ad.device_ids is null or trim(ad.device_ids) = '' then 0
-                else (
-                    select count(1)
-                    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 find_in_set(d.id, replace(ad.device_ids, ' ', ''))
-                )
-            end as counter_count,
-            case
-                when ad.device_ids is null or trim(ad.device_ids) = '' then 0
-                else (
-                    select count(1)
-                    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 ee.counter_effect = '1'
-                      and find_in_set(d.id, replace(ad.device_ids, ' ', ''))
-                )
-            end as counter_success_count
+                ad.id,
+                ad.area_name,
+                ad.area_type_keys,
+                -- 1. 场景名称聚合 (已补全 string_agg 参数并统一类型)
+                (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::VARCHAR = ds.id::VARCHAR AND dsm.is_deleted = 0
+                WHERE ds.is_deleted = 0
+                AND ad.id::VARCHAR = ANY(string_to_array(ds.area_divide_ids, ','))) AS scene_name,
+
+                -- 2. 场景类型聚合 (修正别名重复)
+                (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::VARCHAR = ds.id::VARCHAR AND dsm.is_deleted = 0
+                WHERE ds.is_deleted = 0
+                AND ad.id::VARCHAR = ANY(string_to_array(ds.area_divide_ids, ','))) AS scene_type,
+
+                -- 3. 设备数量计算
+                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 END AS device_count,
+
+                -- 4. 告警数量统计 (确保 d.id::VARCHAR 对齐) ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])
+                CASE WHEN ad.device_ids IS NULL OR trim(ad.device_ids) = '' THEN 0
+                ELSE (SELECT count(1) FROM ja_fw_drone_alarm_record ar
+                JOIN ja_fw_device d ON d.id::bigint = ar.device_id::bigint AND d.is_deleted = 0
+                WHERE ar.is_deleted = 0
+                AND d.id::bigint = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])) END AS alarm_count,
+
+                -- 5. 效果评估数量统计 (修正点:d.id::VARCHAR)
+                CASE WHEN ad.device_ids IS NULL OR trim(ad.device_ids) = '' THEN 0
+                ELSE (SELECT count(1) FROM ja_fw_effect_eval ee
+                JOIN ja_fw_device d ON d.id::bigint = ee.device_id::bigint AND d.is_deleted = 0
+                WHERE ee.is_deleted = 0
+                AND d.id::bigint = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])) END AS counter_count,
+
+                -- 6. 成功反制数量统计 (修正点:d.id::VARCHAR)
+                CASE WHEN ad.device_ids IS NULL OR trim(ad.device_ids) = '' THEN 0
+                ELSE (SELECT count(1) FROM ja_fw_effect_eval ee
+                JOIN ja_fw_device d ON d.id::bigint = ee.device_id::bigint AND d.is_deleted = 0
+                WHERE ee.is_deleted = 0 AND ee.counter_effect = '1'
+                AND d.id::bigint = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])) END AS counter_success_count
             from ja_fw_area_divide ad
             <where>
                 ad.is_deleted = 0
                 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
-                    where ds.is_deleted = 0
-                      and find_in_set(ad.id, ds.area_divide_ids)
+                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 ad.id::VARCHAR = ANY(string_to_array(ds.area_divide_ids, ','))
                 )
                 <if test="param2.id != null and param2.id != ''">
                     and ad.id = #{param2.id}
@@ -331,7 +319,7 @@
                         select 1
                         from ja_fw_defense_scene ds
                         where ds.is_deleted = 0
-                          and find_in_set(ad.id, ds.area_divide_ids)
+                        and ad.id::VARCHAR = ANY(string_to_array(ds.area_divide_ids, ','))
                           and ds.scene_type = #{param2.sceneType}
                     )
                 </if>
@@ -341,7 +329,7 @@
                 <if test="param2.areaTypeKeyList != null and param2.areaTypeKeyList.size > 0">
                     and (
                         <foreach collection="param2.areaTypeKeyList" item="key" separator=" or ">
-                            find_in_set(#{key}, ad.area_type_keys)
+                            ARRAY_POSITION(string_to_array(ad.area_type_keys, ','), #{key}) IS NOT NULL
                         </foreach>
                     )
                 </if>
@@ -378,16 +366,16 @@
         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
                 where ds.is_deleted = 0
-                  and find_in_set(ad.id, ds.area_divide_ids)
+                  and ad.id = ANY(string_to_array(ds.area_divide_ids, ',')::bigint[])
             ) as scene_name,
             (
-                select group_concat(distinct ds.scene_type)
+                select string_agg(distinct ds.scene_type, ',')
                 from ja_fw_defense_scene ds
                 where ds.is_deleted = 0
-                  and find_in_set(ad.id, ds.area_divide_ids)
+                  and ad.id = ANY(string_to_array(ds.area_divide_ids, ',')::bigint[])
             ) as scene_type,
             case
                 when ad.device_ids is null or trim(ad.device_ids) = '' then 0
@@ -400,7 +388,7 @@
                     from ja_fw_drone_alarm_record ar
                     join ja_fw_device d on d.id = ar.device_id::VARCHAR and d.is_deleted = 0
                     where ar.is_deleted = 0
-                      and find_in_set(d.id, replace(ad.device_ids, ' ', ''))
+                      and d.id = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])
                 )
             end as alarm_count,
             case
@@ -410,7 +398,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 find_in_set(d.id, replace(ad.device_ids, ' ', ''))
+                      and d.id = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])
                 )
             end as counter_count,
             case
@@ -421,7 +409,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 = 'success'
-                      and find_in_set(d.id, replace(ad.device_ids, ' ', ''))
+                      and d.id = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')::bigint[])
                 )
             end as counter_success_count
             from ja_fw_area_divide ad
@@ -467,75 +455,78 @@
         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
-                FROM
-                    ja_fw_device d
-                WHERE
-                    d.is_deleted = 0
-                    AND d.is_enabled = 1
-                    AND d.final_outbound_area IS NOT NULL
-                <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>
-                GROUP BY
-                    d.id
-        ) dd on find_in_set(dd.id, ad.device_ids)
+        SELECT
+        d.id
+        FROM
+        ja_fw_device d
+        WHERE
+        d.is_deleted = 0
+        AND d.is_enabled = 1
+        AND d.final_outbound_area IS NOT NULL
+        <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
+                /* 修改点1:参数强制转为 bigint 匹配数据库字段 */
+                WHERE loan_to_dept_id = #{currentDeptId}::bigint
+                AND is_deleted = 0
+                )
+            </if>
+            )
+        </if>
+        GROUP BY
+        d.id
+        /* 修改点2:dd.id 是 bigint,转 VARCHAR 匹配文本数组,去掉不稳定的 ::bigint[] */
+        ) dd on dd.id::VARCHAR = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ','))
         <where>
             ad.is_deleted = 0
             <if test="isSetSceneManage != null and isSetSceneManage == 1">
                 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
-                where ds.is_deleted = 0
-                and ds.area_divide_ids is not null
-                and ds.area_divide_ids != ''
-                and find_in_set(ad.id, replace(ds.area_divide_ids, ' ', ''))
+                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 匹配 ANY */
+                and ad.id::VARCHAR = ANY(string_to_array(replace(ds_sub.area_divide_ids, ' ', ''), ','))
                 )
             </if>
             <if test="isSetSceneManage != null and isSetSceneManage == 1 and flyTime != null">
                 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
-                where ds.is_deleted = 0
-                and ds.area_divide_ids is not null
-                and ds.area_divide_ids != ''
-                and find_in_set(ad.id, replace(ds.area_divide_ids, ' ', ''))
-                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})
+                from ja_fw_defense_scene ds_sub2
+                join ja_fw_defense_scene_manage dsm_sub2 on dsm_sub2.defense_scene_id::VARCHAR = ds_sub2.id::VARCHAR and dsm_sub2.is_deleted = 0
+                where ds_sub2.is_deleted = 0
+                and ds_sub2.area_divide_ids is not null
+                and ds_sub2.area_divide_ids != ''
+                and ad.id::VARCHAR = ANY(string_to_array(replace(ds_sub2.area_divide_ids, ' ', ''), ','))
+                and (dsm_sub2.effective_date_start is null or dsm_sub2.effective_date_start &lt;= #{flyTime})
+                and (dsm_sub2.effective_date_end is null or dsm_sub2.effective_date_end &gt;= #{flyTime})
                 )
             </if>
             <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.area_divide_ids is not null
-                and ds.area_divide_ids != ''
-                and find_in_set(ad.id, replace(ds.area_divide_ids, ' ', ''))
+                from ja_fw_defense_scene ds_sub3
+                where ds_sub3.is_deleted = 0
+                and ds_sub3.area_divide_ids is not null
+                and ds_sub3.area_divide_ids != ''
+                and ad.id::VARCHAR = ANY(string_to_array(replace(ds_sub3.area_divide_ids, ' ', ''), ','))
                 )
                 <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, ' ', ''))
+                    from ja_fw_defense_scene ds_sub4
+                    where ds_sub4.is_deleted = 0
+                    and ds_sub4.id = #{sceneId}::bigint
+                    and ds_sub4.area_divide_ids is not null
+                    and ds_sub4.area_divide_ids != ''
+                    and ad.id::VARCHAR = ANY(string_to_array(replace(ds_sub4.area_divide_ids, ' ', ''), ','))
                     )
                 </if>
                 )
@@ -543,18 +534,18 @@
             <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, ' ', ''))
+                from ja_fw_defense_scene ds_sub5
+                where ds_sub5.is_deleted = 0
+                and ds_sub5.id = #{sceneId}::bigint
+                and ds_sub5.area_divide_ids is not null
+                and ds_sub5.area_divide_ids != ''
+                and ad.id::VARCHAR = ANY(string_to_array(replace(ds_sub5.area_divide_ids, ' ', ''), ','))
                 )
             </if>
             <if test="areaTypeKeyList != null and areaTypeKeyList.size > 0">
                 and (
                 <foreach collection="areaTypeKeyList" item="key" separator=" or ">
-                    find_in_set(#{key}, ad.area_type_keys)
+                    ARRAY_POSITION(string_to_array(ad.area_type_keys, ','), #{key}::VARCHAR) IS NOT NULL
                 </foreach>
                 )
             </if>
@@ -565,9 +556,9 @@
         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 find_in_set(#{areaId}, ds.area_divide_ids)
+        and #{areaId} = ANY(string_to_array(ds.area_divide_ids, ',')::bigint[])
         and dsm.is_deleted = 0
     </select>
 
@@ -608,8 +599,8 @@
             #{createTime},
             #{updateUser},
             #{updateTime},
-            IFNULL(#{status}, '0'),
-            IFNULL(#{isDeleted}, 0)
+            COALESCE(#{status}, '0'),
+            COALESCE(#{isDeleted}, 0)
         )
     </insert>
 

--
Gitblit v1.9.3