| | |
| | | |
| | | <select id="selectFwAreaDivideStatisticsPage" resultMap="fwAreaDivideStatisticsResultMap"> |
| | | select |
| | | stats.id, |
| | | stats.area_name, |
| | | stats.area_type_keys, |
| | | 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 >= 80 then '好' |
| | | when stats.counter_success_count * 100.0 / stats.counter_count >= 60 then '一般' |
| | | else '差' |
| | | end as control_effect |
| | | stats.id, |
| | | stats.area_name, |
| | | stats.area_type_keys, |
| | | 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 >= 80 then '好' |
| | | when stats.counter_success_count * 100.0 / stats.counter_count >= 60 then '一般' |
| | | else '差' |
| | | end as control_effect |
| | | from ( |
| | | select |
| | | 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, |
| | | select |
| | | ad.id, |
| | | ad.area_name, |
| | | ad.area_type_keys, |
| | | (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::text = ds.id::text AND dsm.is_deleted = 0 |
| | | WHERE ds.is_deleted = 0 |
| | | AND ad.id::text = 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, |
| | | (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::text = ds.id::text AND dsm.is_deleted = 0 |
| | | WHERE ds.is_deleted = 0 |
| | | AND ad.id::text = 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, |
| | | 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, |
| | | 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 d.id = 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, |
| | | 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 d.id = 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 |
| | | 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 = '1' |
| | | AND d.id = 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::text = ds.id::text AND dsm.is_deleted = 0 |
| | | WHERE ds.is_deleted = 0 |
| | | AND ad.id::text = ANY(string_to_array(ds.area_divide_ids, ',')) |
| | | ) |
| | | <if test="param2.id != null and param2.id != ''"> |
| | | and ad.id = #{param2.id}::bigint |
| | | </if> |
| | | <if test="param2.areaName != null and param2.areaName != ''"> |
| | | and ad.area_name like concat('%', #{param2.areaName}, '%') |
| | | </if> |
| | | <if test="param2.sceneType != null and param2.sceneType != ''"> |
| | | 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 ad.id::VARCHAR = ANY(string_to_array(ds.area_divide_ids, ',')) |
| | | select 1 |
| | | from ja_fw_defense_scene ds |
| | | where ds.is_deleted = 0 |
| | | and ad.id::text = ANY(string_to_array(ds.area_divide_ids, ',')) |
| | | and ds.scene_type = #{param2.sceneType} |
| | | ) |
| | | <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.sceneType != null and param2.sceneType != ''"> |
| | | and exists ( |
| | | select 1 |
| | | from ja_fw_defense_scene ds |
| | | where ds.is_deleted = 0 |
| | | and ad.id::VARCHAR = ANY(string_to_array(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> |
| | | <if test="param2.areaTypeKeyList != null and param2.areaTypeKeyList.size > 0"> |
| | | and ( |
| | | <foreach collection="param2.areaTypeKeyList" item="key" separator=" or "> |
| | | ARRAY_POSITION(string_to_array(ad.area_type_keys, ','), #{key}) IS NOT NULL |
| | | </foreach> |
| | | ) |
| | | </if> |
| | | <if test="param2.deptList != null and param2.deptList.size > 0"> |
| | | and ad.create_dept in |
| | | <foreach collection="param2.deptList" item="deptId" open="(" separator="," close=")"> |
| | | #{deptId} |
| | | </foreach> |
| | | </if> |
| | | </where> |
| | | </if> |
| | | <if test="param2.areaCode != null and param2.areaCode != ''"> |
| | | and ad.area_code = #{param2.areaCode} |
| | | </if> |
| | | <if test="param2.areaTypeKeyList != null and param2.areaTypeKeyList.size > 0"> |
| | | and ( |
| | | <foreach collection="param2.areaTypeKeyList" item="key" separator=" or "> |
| | | array_position(string_to_array(ad.area_type_keys, ','), #{key}::text) is not null |
| | | </foreach> |
| | | ) |
| | | </if> |
| | | <if test="param2.deptList != null and param2.deptList.size > 0"> |
| | | and ad.create_dept in |
| | | <foreach collection="param2.deptList" item="deptId" open="(" separator="," close=")"> |
| | | #{deptId}::bigint |
| | | </foreach> |
| | | </if> |
| | | </where> |
| | | ) stats |
| | | </select> |
| | | |