吉安感知网项目-后端
xiebin
2026-01-19 4e48664942bbefe70699ca43d25cbbd56ecc8daa
drone-service/drone-fw/src/main/java/org/sxkj/fw/area/mapper/FwAreaDivideMapper.xml
@@ -15,8 +15,7 @@
        <result column="response_mechanism" property="responseMechanism"/>
        <result column="control_level" property="controlLevel"/>
        <result column="police_station_id" property="policeStationId"/>
        <result column="fly_time_start" property="flyTimeStart"/>
        <result column="fly_time_end" property="flyTimeEnd"/>
        <result column="device_ids" property="deviceIds"/>
        <result column="fly_date_start" property="flyDateStart"/>
        <result column="fly_date_end" property="flyDateEnd"/>
        <result column="area_code" property="areaCode"/>
@@ -32,6 +31,19 @@
        <result column="is_deleted" property="isDeleted"/>
    </resultMap>
    <resultMap id="fwAreaDivideStatisticsResultMap" type="org.sxkj.fw.area.vo.FwAreaDivideStatisticsVO">
        <result column="id" property="id"/>
        <result column="area_name" property="areaName"/>
        <result column="area_type" property="areaType"/>
        <result column="scene_name" property="sceneName"/>
        <result column="scene_type" property="sceneType"/>
        <result column="device_count" property="deviceCount"/>
        <result column="alarm_count" property="alarmCount"/>
        <result column="counter_count" property="counterCount"/>
        <result column="counter_success_count" property="counterSuccessCount"/>
        <result column="control_effect" property="controlEffect"/>
    </resultMap>
    <select id="selectFwAreaDividePage" resultMap="fwAreaDivideResultMap">
        select
@@ -40,14 +52,17 @@
        ad.longitude,
        ad.latitude,
        ad.area_size,
        concat(ST_AsText(ad.geom), ' | ', ST_SRID(ad.geom)) as geom,
        case
            when ad.geom is null then null
            when ST_SRID(ad.geom) is null or ST_SRID(ad.geom) = 0 then ST_AsText(ad.geom)
            else concat(ST_AsText(ST_SwapXY(ad.geom)), ' | ', ST_SRID(ad.geom))
        end as geom,
        ad.area_type,
        ad.trigger_condition,
        ad.response_mechanism,
        ad.control_level,
        ad.police_station_id,
        ad.fly_time_start,
        ad.fly_time_end,
        ad.device_ids,
        ad.fly_date_start,
        ad.fly_date_end,
        ad.area_code,
@@ -78,17 +93,6 @@
            <if test="param2.areaSize != null and param2.areaSize != ''">
                and ad.area_size = #{param2.areaSize}
            </if>
            <if test="param2.geom != null and param2.geom != ''">
                and ST_Equals(
                    ad.geom,
                    ST_SRID(
                        ST_GeomFromText(
                            trim(case when instr(#{param2.geom}, '|') &gt; 0 then substring_index(#{param2.geom}, '|', 1) else #{param2.geom} end)
                        ),
                        case when instr(#{param2.geom}, '|') &gt; 0 then cast(trim(substring_index(#{param2.geom}, '|', -1)) as unsigned) else 4326 end
                    )
                )
            </if>
            <if test="param2.areaType != null and param2.areaType != ''">
                and ad.area_type = #{param2.areaType}
            </if>
@@ -104,11 +108,8 @@
            <if test="param2.policeStationId != null and param2.policeStationId != ''">
                and ad.police_station_id = #{param2.policeStationId}
            </if>
            <if test="param2.flyTimeStart != null and param2.flyTimeStart != ''">
                and ad.fly_time_start &gt;= #{param2.flyTimeStart}
            </if>
            <if test="param2.flyTimeEnd != null and param2.flyTimeEnd != ''">
                and ad.fly_time_end &lt;= #{param2.flyTimeEnd}
            <if test="param2.deviceIds != null and param2.deviceIds != ''">
                and ad.device_ids = #{param2.deviceIds}
            </if>
            <if test="param2.flyDateStart != null and param2.flyDateStart != ''">
                and ad.fly_date_start &gt;= #{param2.flyDateStart}
@@ -122,6 +123,116 @@
        </where>
    </select>
    <select id="selectFwAreaDivideList" resultMap="fwAreaDivideResultMap">
        select
        ad.id,
        ad.area_name,
        ad.longitude,
        ad.latitude,
        ad.area_size,
        case
            when ad.geom is null then null
            when ST_SRID(ad.geom) is null or ST_SRID(ad.geom) = 0 then ST_AsText(ad.geom)
            else concat(ST_AsText(ST_SwapXY(ad.geom)), ' | ', ST_SRID(ad.geom))
        end as geom,
        ad.area_type,
        ad.trigger_condition,
        ad.response_mechanism,
        ad.control_level,
        ad.police_station_id,
        ad.device_ids,
        ad.fly_date_start,
        ad.fly_date_end,
        ad.area_code,
        ps.station_name as police_station_name,
        ad.create_user,
        ad.create_dept,
        ad.create_time,
        ad.update_user,
        ad.update_time,
        ad.status,
        ad.is_deleted
        from ja_fw_area_divide ad
        left join ja_fw_police_station ps on ps.id = ad.police_station_id and ps.is_deleted = 0
        <where>
            ad.is_deleted = 0
            <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, ' ', ''))
                    )
                    <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>
    <select id="selectFwAreaDivideDetail" resultMap="fwAreaDivideResultMap">
        select
        ad.id,
@@ -129,14 +240,17 @@
        ad.longitude,
        ad.latitude,
        ad.area_size,
        concat(ST_AsText(ad.geom), ' | ', ST_SRID(ad.geom)) as geom,
        case
            when ad.geom is null then null
            when ST_SRID(ad.geom) is null or ST_SRID(ad.geom) = 0 then ST_AsText(ad.geom)
            else concat(ST_AsText(ST_SwapXY(ad.geom)), ' | ', ST_SRID(ad.geom))
        end as geom,
        ad.area_type,
        ad.trigger_condition,
        ad.response_mechanism,
        ad.control_level,
        ad.police_station_id,
        ad.fly_time_start,
        ad.fly_time_end,
        ad.device_ids,
        ad.fly_date_start,
        ad.fly_date_end,
        ad.area_code,
@@ -156,6 +270,185 @@
          and ad.id = #{id}
    </select>
    <select id="selectFwAreaDivideStatisticsPage" resultMap="fwAreaDivideStatisticsResultMap">
        select
        stats.id,
        stats.area_name,
        stats.area_type,
        stats.scene_name,
        stats.scene_type,
        stats.device_count,
        stats.alarm_count,
        stats.counter_count,
        stats.counter_success_count,
        case
            when stats.counter_count = 0 then '/'
            when stats.counter_success_count * 100.0 / stats.counter_count &gt;= 80 then '好'
            when stats.counter_success_count * 100.0 / stats.counter_count &gt;= 60 then '一般'
            else '差'
        end as control_effect
        from (
            select
            ad.id,
            ad.area_name,
            ad.area_type,
            (
                select group_concat(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)
            ) as scene_name,
            (
                select group_concat(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)
            ) 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 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 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 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, ' ', ''))
                )
            end as counter_success_count
            from ja_fw_area_divide ad
            <where>
                ad.is_deleted = 0
                <if test="param2.id != null and param2.id != ''">
                    and ad.id = #{param2.id}
                </if>
                <if test="param2.areaName != null and param2.areaName != ''">
                    and ad.area_name like concat('%', #{param2.areaName}, '%')
                </if>
                <if test="param2.areaType != null and param2.areaType != ''">
                    and ad.area_type = #{param2.areaType}
                </if>
                <if test="param2.sceneType != null and param2.sceneType != ''">
                    and exists (
                        select 1
                        from ja_fw_defense_scene ds
                        where ds.is_deleted = 0
                          and find_in_set(ad.id, ds.area_divide_ids)
                          and ds.scene_type = #{param2.sceneType}
                    )
                </if>
                <if test="param2.areaCode != null and param2.areaCode != ''">
                    and ad.area_code = #{param2.areaCode}
                </if>
            </where>
        ) stats
    </select>
    <select id="selectFwAreaDivideStatisticsDetail" resultMap="fwAreaDivideStatisticsResultMap">
        select
        stats.id,
        stats.area_name,
        stats.area_type,
        stats.scene_name,
        stats.scene_type,
        stats.device_count,
        stats.alarm_count,
        stats.counter_count,
        stats.counter_success_count,
        case
            when stats.counter_count = 0 then '/'
            when stats.counter_success_count * 100.0 / stats.counter_count &gt;= 80 then '好'
            when stats.counter_success_count * 100.0 / stats.counter_count &gt;= 60 then '一般'
            else '差'
        end as control_effect
        from (
            select
            ad.id,
            ad.area_name,
            ad.area_type,
            (
                select group_concat(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)
            ) as scene_name,
            (
                select group_concat(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)
            ) 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 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 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 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, ' ', ''))
                )
            end as counter_success_count
            from ja_fw_area_divide ad
            <where>
                ad.is_deleted = 0
                <if test="id != null and id != ''">
                    and ad.id = #{id}
                </if>
                <if test="areaCode != null and areaCode != ''">
                    and ad.area_code = #{areaCode}
                </if>
            </where>
        ) stats
    </select>
    <select id="exportFwAreaDivide" resultType="org.sxkj.fw.area.excel.FwAreaDivideExcel">
        SELECT
@@ -170,8 +463,7 @@
        response_mechanism,
        control_level,
        police_station_id,
        fly_time_start,
        fly_time_end,
        device_ids,
        fly_date_start,
        fly_date_end,
        area_code,
@@ -198,8 +490,7 @@
            response_mechanism,
            control_level,
            police_station_id,
            fly_time_start,
            fly_time_end,
            device_ids,
            fly_date_start,
            fly_date_end,
            area_code,
@@ -218,12 +509,13 @@
            #{areaSize},
            <choose>
                <when test="geom != null and geom != ''">
                    ST_SRID(
                        ST_GeomFromText(
                            trim(case when instr(#{geom}, '|') &gt; 0 then substring_index(#{geom}, '|', 1) else #{geom} end)
                        ),
                        case when instr(#{geom}, '|') &gt; 0 then cast(trim(substring_index(#{geom}, '|', -1)) as unsigned) else 4326 end
                    )
                    case
                        when instr(#{geom}, '|') &gt; 0 then ST_GeomFromText(
                            trim(substring_index(#{geom}, '|', 1)),
                            cast(trim(substring_index(#{geom}, '|', -1)) as unsigned)
                        )
                        else ST_GeomFromText(trim(#{geom}))
                    end
                </when>
                <otherwise>null</otherwise>
            </choose>,
@@ -232,8 +524,7 @@
            #{responseMechanism},
            #{controlLevel},
            #{policeStationId},
            #{flyTimeStart},
            #{flyTimeEnd},
            #{deviceIds},
            #{flyDateStart},
            #{flyDateEnd},
            #{areaCode},
@@ -242,8 +533,8 @@
            #{createTime},
            #{updateUser},
            #{updateTime},
            #{status},
            #{isDeleted}
            IFNULL(#{status}, '0'),
            IFNULL(#{isDeleted}, 0)
        )
    </insert>
@@ -255,20 +546,20 @@
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="areaSize != null">area_size = #{areaSize},</if>
            <if test="geom != null and geom != ''">
                geom = ST_SRID(
                    ST_GeomFromText(
                        trim(case when instr(#{geom}, '|') &gt; 0 then substring_index(#{geom}, '|', 1) else #{geom} end)
                    ),
                    case when instr(#{geom}, '|') &gt; 0 then cast(trim(substring_index(#{geom}, '|', -1)) as unsigned) else 4326 end
                ),
                geom = case
                    when instr(#{geom}, '|') &gt; 0 then ST_GeomFromText(
                        trim(substring_index(#{geom}, '|', 1)),
                        cast(trim(substring_index(#{geom}, '|', -1)) as unsigned)
                    )
                    else ST_GeomFromText(trim(#{geom}))
                end,
            </if>
            <if test="areaType != null">area_type = #{areaType},</if>
            <if test="triggerCondition != null">trigger_condition = #{triggerCondition},</if>
            <if test="responseMechanism != null">response_mechanism = #{responseMechanism},</if>
            <if test="controlLevel != null">control_level = #{controlLevel},</if>
            <if test="policeStationId != null">police_station_id = #{policeStationId},</if>
            <if test="flyTimeStart != null">fly_time_start = #{flyTimeStart},</if>
            <if test="flyTimeEnd != null">fly_time_end = #{flyTimeEnd},</if>
            <if test="deviceIds != null">device_ids = #{deviceIds},</if>
            <if test="flyDateStart != null">fly_date_start = #{flyDateStart},</if>
            <if test="flyDateEnd != null">fly_date_end = #{flyDateEnd},</if>
            <if test="areaCode != null">area_code = #{areaCode},</if>