package com.pm.web.controller.publicBroadcasting;

import com.pm.common.config.PageData;
import com.pm.common.core.controller.BaseController;
import com.pm.interfaceInfo.service.InterfaceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 公共广播
 */
@RestController
@RequestMapping("/publicBroadcasting/info")
public class PublicBroadcastingController   extends BaseController {


    /**
     * 查询url 访问接口
     */
    @Autowired
    private InterfaceInfoService interfaceInfoService;


    // 模拟数据

    /**
     *
     * @return
     */
    public static List<Map<String, Object>> generateBroadcastDeviceData() {
        return Arrays.asList(
                createDeviceEntry("BRD-001", "1号楼大厅广播终端", "广播终端", 10.2, 18.5, 0, "1号楼1层大厅", "green", 50.0, "ZONE-B-001", "1号楼公共区", Arrays.asList("BRD-001", "BRD-002"), null, "2025-06-05 08:00:00"),
                createDeviceEntry("BRD-002", "1号楼走廊广播", "广播终端", 12.7, 22.3, 0, "1号楼1层走廊", "green", 45.0, "ZONE-B-001", "1号楼公共区", Arrays.asList("BRD-001", "BRD-002"), null, "2025-06-05 08:15:00"),
                createDeviceEntry("BRD-003", "2号楼电梯厅广播", "广播终端", 18.9, 25.6, 2, "2号楼2层电梯厅", "red", 0.0, "ZONE-B-002", "2号楼高区", Arrays.asList("BRD-003"), "F-B-001", "2025-06-05 08:30:00"),
                createDeviceEntry("BRD-004", "2号楼消防广播", "消防广播", 19.5, 28.7, 3, "2号楼3层安全通道", "green", 60.0, "ZONE-B-002", "2号楼高区", Arrays.asList("BRD-004", "BRD-005"), null, "2025-06-05 08:45:00"),
                createDeviceEntry("BRD-005", "2号楼安全出口广播", "消防广播", 20.1, 29.3, 3, "2号楼3层安全通道", "green", 60.0, "ZONE-B-002", "2号楼高区", Arrays.asList("BRD-004", "BRD-005"), null, "2025-06-05 09:00:00"),
                createDeviceEntry("BRD-006", "3号楼会议室广播", "会议广播", 8.3, 5.7, 2, "3号楼2层会议室", "green", 35.0, "ZONE-B-003", "3号楼办公区", Arrays.asList("BRD-006"), null, "2025-06-05 09:15:00"),
                createDeviceEntry("BRD-007", "3号楼走廊背景音乐", "背景音乐终端", 9.1, 6.2, 2, "3号楼2层走廊", "yellow", 25.0, "ZONE-B-003", "3号楼办公区", Arrays.asList("BRD-007", "BRD-008"), "F-B-002", "2025-06-05 09:30:00"),
                createDeviceEntry("BRD-008", "3号楼休息区广播", "背景音乐终端", 9.8, 7.5, 2, "3号楼2层休息区", "yellow", 25.0, "ZONE-B-003", "3号楼办公区", Arrays.asList("BRD-007", "BRD-008"), "F-B-002", "2025-06-05 09:45:00"),
                createDeviceEntry("BRD-009", "地下车库A广播", "环境广播", -5.5, 15.3, -1, "地下1层车库A区", "green", 55.0, "ZONE-B-004", "地下车库区", Arrays.asList("BRD-009", "BRD-010"), null, "2025-06-05 10:00:00"),
                createDeviceEntry("BRD-010", "地下车库B广播", "环境广播", -6.8, 18.2, -1, "地下1层车库B区", "green", 55.0, "ZONE-B-004", "地下车库区", Arrays.asList("BRD-009", "BRD-010"), null, "2025-06-05 10:15:00"),
                createDeviceEntry("BRD-011", "园区广场广播", "户外广播", 25.0, 30.0, 0, "园区中心广场", "green", 70.0, "ZONE-B-005", "户外公共区", Arrays.asList("BRD-011"), null, "2025-06-05 10:30:00"),
                createDeviceEntry("BRD-012", "园区道路广播", "户外广播", 22.5, 35.0, 0, "园区主干道", "green", 70.0, "ZONE-B-005", "户外公共区", Arrays.asList("BRD-012"), null, "2025-06-05 10:45:00"),
                createDeviceEntry("BRD-013", "食堂广播终端", "公共广播", 14.7, 12.3, 0, "1号楼负1层食堂", "red", 0.0, "ZONE-B-006", "生活服务区", Arrays.asList("BRD-013"), "F-B-003", "2025-06-05 11:00:00"),
                createDeviceEntry("BRD-014", "健身房广播", "公共广播", 15.2, 13.8, 0, "1号楼负1层健身房", "green", 40.0, "ZONE-B-006", "生活服务区", Arrays.asList("BRD-014"), null, "2025-06-05 11:15:00"),
                createDeviceEntry("BRD-015", "图书馆广播", "公共广播", 7.5, 8.9, 2, "3号楼1层图书馆", "green", 30.0, "ZONE-B-003", "3号楼办公区", Arrays.asList("BRD-015"), null, "2025-06-05 11:30:00")
        );
    }

    private static Map<String, Object> createDeviceEntry(
            String deviceId, String deviceName, String deviceType,
            double xCoord, double yCoord, double zCoord,
            String area, String status, double volume,
            String zoneId, String zoneName, List<String> deviceList,
            String faultCode, String lastCheckTime
    ) {
        Map<String, Object> map = new HashMap<>();
        map.put("deviceId", deviceId);
        map.put("deviceName", deviceName);
        map.put("deviceType", deviceType);
        map.put("xCoord", xCoord);
        map.put("yCoord", yCoord);
        map.put("zCoord", zCoord);
        map.put("area", area);
        map.put("status", status);
        map.put("volume", volume);
        map.put("zoneId", zoneId);
        map.put("zoneName", zoneName);
        map.put("deviceList", deviceList);

        // 手动处理 null 值
        if (faultCode != null) {
            map.put("faultCode", faultCode);
        } else {
            map.put("faultCode", ""); // 或 null，取决于前端能否处理
        }

        map.put("lastCheckTime", lastCheckTime);
        return map;
    }


    public static List<Map<String, Object>> generateBroadcastData() {
        return Arrays.asList(
                new HashMap<String, Object>() {{
                    put("taskId", "TASK-001");
                    put("targetZoneIds", "ZONE-ALL");
                    put("currentVolume", 75.0);
                    put("setVolume", 75.0);
                    put("switchStatus", "开启");
                    put("operator", "ADMIN-001");
                    put("contentCode", "EMG-ALARM");
                    put("priority", 1);
                    put("broadcastStatus", "进行中");
                    put("startTime", "2025-06-05 08:00:00");
                }},
                new HashMap<String, Object>() {{
                    put("taskId", "TASK-002");
                    put("targetZoneIds", "ZONE-001,ZONE-002");
                    put("currentVolume", 60.0);
                    put("setVolume", 60.0);
                    put("switchStatus", "开启");
                    put("operator", "ADMIN-002");
                    put("contentCode", "PAGE-ANNOUNCE");
                    put("priority", 2);
                    put("broadcastStatus", "已完成");
                    put("startTime", "2025-06-05 08:30:00");
                }},
                new HashMap<String, Object>() {{
                    put("taskId", "TASK-003");
                    put("targetZoneIds", "ZONE-003");
                    put("currentVolume", 0.0);
                    put("setVolume", 50.0);
                    put("switchStatus", "关闭");
                    put("operator", "ADMIN-001");
                    put("contentCode", "NOTICE-INFO");
                    put("priority", 3);
                    put("broadcastStatus", "未开始");
                    put("startTime", "2025-06-05 09:00:00");
                }},
                new HashMap<String, Object>() {{
                    put("taskId", "TASK-004");
                    put("targetZoneIds", "ZONE-ALL");
                    put("currentVolume", 100.0);
                    put("setVolume", 100.0);
                    put("switchStatus", "开启");
                    put("operator", "ADMIN-003");
                    put("contentCode", "EMG-FIRE");
                    put("priority", 1);
                    put("broadcastStatus", "进行中");
                    put("startTime", "2025-06-05 09:15:00");
                }},
                new HashMap<String, Object>() {{
                    put("taskId", "TASK-005");
                    put("targetZoneIds", "ZONE-004");
                    put("currentVolume", 45.0);
                    put("setVolume", 50.0);
                    put("switchStatus", "开启");
                    put("operator", "ADMIN-002");
                    put("contentCode", "NOTICE-MAINTENANCE");
                    put("priority", 3);
                    put("broadcastStatus", "进行中");
                    put("startTime", "2025-06-05 10:00:00");
                }},
                new HashMap<String, Object>() {{
                    put("taskId", "TASK-006");
                    put("targetZoneIds", "ZONE-001");
                    put("currentVolume", 55.0);
                    put("setVolume", 55.0);
                    put("switchStatus", "开启");
                    put("operator", "ADMIN-001");
                    put("contentCode", "PAGE-STAFF");
                    put("priority", 2);
                    put("broadcastStatus", "已完成");
                    put("startTime", "2025-06-05 10:30:00");
                }},
                new HashMap<String, Object>() {{
                    put("taskId", "TASK-007");
                    put("targetZoneIds", "ZONE-002,ZONE-003");
                    put("currentVolume", 70.0);
                    put("setVolume", 70.0);
                    put("switchStatus", "开启");
                    put("operator", "ADMIN-003");
                    put("contentCode", "EMG-EVACUATION");
                    put("priority", 1);
                    put("broadcastStatus", "进行中");
                    put("startTime", "2025-06-05 11:00:00");
                }},
                new HashMap<String, Object>() {{
                    put("taskId", "TASK-008");
                    put("targetZoneIds", "ZONE-ALL");
                    put("currentVolume", 80.0);
                    put("setVolume", 80.0);
                    put("switchStatus", "开启");
                    put("operator", "ADMIN-002");
                    put("contentCode", "NOTICE-FESTIVAL");
                    put("priority", 3);
                    put("broadcastStatus", "未开始");
                    put("startTime", "2025-06-05 11:30:00");
                }},
                new HashMap<String, Object>() {{
                    put("taskId", "TASK-009");
                    put("targetZoneIds", "ZONE-004");
                    put("currentVolume", 30.0);
                    put("setVolume", 40.0);
                    put("switchStatus", "关闭");
                    put("operator", "ADMIN-001");
                    put("contentCode", "NOTICE-REMINDER");
                    put("priority", 3);
                    put("broadcastStatus", "未开始");
                    put("startTime", "2025-06-05 12:00:00");
                }},
                new HashMap<String, Object>() {{
                    put("taskId", "TASK-010");
                    put("targetZoneIds", "ZONE-001,ZONE-004");
                    put("currentVolume", 65.0);
                    put("setVolume", 65.0);
                    put("switchStatus", "开启");
                    put("operator", "ADMIN-003");
                    put("contentCode", "PAGE-GUEST");
                    put("priority", 2);
                    put("broadcastStatus", "已完成");
                    put("startTime", "2025-06-05 13:00:00");
                }},
                new HashMap<String, Object>() {{
                    put("taskId", "TASK-011");
                    put("targetZoneIds", "ZONE-ALL");
                    put("currentVolume", 90.0);
                    put("setVolume", 90.0);
                    put("switchStatus", "开启");
                    put("operator", "ADMIN-002");
                    put("contentCode", "EMG-SECURITY");
                    put("priority", 1);
                    put("broadcastStatus", "进行中");
                    put("startTime", "2025-06-05 13:30:00");
                }},
                new HashMap<String, Object>() {{
                    put("taskId", "TASK-012");
                    put("targetZoneIds", "ZONE-002");
                    put("currentVolume", 50.0);
                    put("setVolume", 50.0);
                    put("switchStatus", "开启");
                    put("operator", "ADMIN-001");
                    put("contentCode", "NOTICE-UPDATE");
                    put("priority", 3);
                    put("broadcastStatus", "已完成");
                    put("startTime", "2025-06-05 14:00:00");
                }},
                new HashMap<String, Object>() {{
                    put("taskId", "TASK-013");
                    put("targetZoneIds", "ZONE-003,ZONE-004");
                    put("currentVolume", 40.0);
                    put("setVolume", 40.0);
                    put("switchStatus", "开启");
                    put("operator", "ADMIN-003");
                    put("contentCode", "PAGE-EMERGENCY");
                    put("priority", 2);
                    put("broadcastStatus", "进行中");
                    put("startTime", "2025-06-05 14:30:00");
                }},
                new HashMap<String, Object>() {{
                    put("taskId", "TASK-014");
                    put("targetZoneIds", "ZONE-ALL");
                    put("currentVolume", 100.0);
                    put("setVolume", 100.0);
                    put("switchStatus", "开启");
                    put("operator", "ADMIN-002");
                    put("contentCode", "EMG-TEST");
                    put("priority", 1);
                    put("broadcastStatus", "进行中");
                    put("startTime", "2025-06-05 15:00:00");
                }},
                new HashMap<String, Object>() {{
                    put("taskId", "TASK-015");
                    put("targetZoneIds", "ZONE-001,ZONE-003");
                    put("currentVolume", 58.0);
                    put("setVolume", 60.0);
                    put("switchStatus", "开启");
                    put("operator", "ADMIN-001");
                    put("contentCode", "NOTICE-CLEANING");
                    put("priority", 3);
                    put("broadcastStatus", "未开始");
                    put("startTime", "2025-06-05 15:30:00");
                }}
        );
    }

    public static List<Map<String, Object>> generateSystemData() {
        return Arrays.asList(
                // 紧急通知（全区，设备总数100，故障数5）
                createContentEntry(
                        "CONT-001", "EMERGENCY", "/audio/emergency/alarm.mp3",
                        "CONT-001", "ZONE-ALL", "80%",
                        "100/5", "HIGH", Arrays.asList("DEV-012", "DEV-045"), "2025-06-03 08:30:15",
                        65.2, 12.5, 78.3
                ),
                // 日常通知（分区1+2，设备总数50，故障数2）
                createContentEntry(
                        "CONT-002", "NORMAL", "/audio/normal/notice1.mp3",
                        "CONT-002", "ZONE-001,ZONE-002", "45%",
                        "50/2", "MEDIUM", Arrays.asList("DEV-023"), "2025-06-03 09:15:30",
                        45.8, 8.2, 65.7
                ),
                // 背景音乐（分区3+4，无故障）
                createContentEntry(
                        "CONT-003", "MUSIC", "/audio/music/bg1.mp3",
                        "CONT-003", "ZONE-003,ZONE-004", "100%",
                        "48/0", "NONE", null, null,
                        30.1, 5.3, 82.4
                ),
                // 寻呼（分区1，设备总数25，故障数1）
                createContentEntry(
                        "CONT-004", "PAGING", "/audio/paging/staff.mp3",
                        "CONT-004", "ZONE-001", "20%",
                        "25/1", "LOW", Arrays.asList("DEV-018"), "2025-06-03 10:05:45",
                        55.7, 9.8, 70.1
                ),
                // 紧急演练（全区，设备总数100，故障数3）
                createContentEntry(
                        "CONT-005", "DRILL", "/audio/emergency/drill.mp3",
                        "CONT-005", "ZONE-ALL", "0%",
                        "100/3", "HIGH", Arrays.asList("DEV-007", "DEV-032", "DEV-056"), "2025-06-03 11:20:00",
                        78.9, 15.3, 60.5
                ),
                // 新增10条模拟数据（包含不同设备数和故障数）
                createContentEntry(
                        "CONT-006", "NORMAL", "/audio/normal/notice2.mp3",
                        "CONT-006", "ZONE-002", "60%",
                        "30/1", "LOW", Arrays.asList("DEV-028"), "2025-06-03 12:00:00",
                        40.2, 6.5, 75.0
                ),
                createContentEntry(
                        "CONT-007", "EMERGENCY", "/audio/emergency/fire.mp3",
                        "CONT-007", "ZONE-ALL", "90%",
                        "100/2", "HIGH", Arrays.asList("DEV-015"), "2025-06-03 13:30:00",
                        68.5, 10.8, 72.3
                ),
                createContentEntry(
                        "CONT-008", "MUSIC", "/audio/music/bg2.mp3",
                        "CONT-008", "ZONE-003", "75%",
                        "24/0", "NONE", null, null,
                        35.6, 4.9, 85.1
                ),
                createContentEntry(
                        "CONT-009", "PAGING", "/audio/paging/guest.mp3",
                        "CONT-009", "ZONE-001,ZONE-003", "30%",
                        "40/2", "MEDIUM", Arrays.asList("DEV-019", "DEV-033"), "2025-06-03 14:45:00",
                        52.1, 8.7, 68.4
                ),
                createContentEntry(
                        "CONT-010", "DRILL", "/audio/emergency/evacuation.mp3",
                        "CONT-010", "ZONE-004", "0%",
                        "18/1", "LOW", Arrays.asList("DEV-041"), "2025-06-03 15:30:00",
                        58.9, 11.2, 63.7
                ),
                createContentEntry(
                        "CONT-011", "NORMAL", "/audio/normal/reminder.mp3",
                        "CONT-011", "ZONE-002,ZONE-004", "55%",
                        "36/0", "NONE", null, null,
                        38.4, 5.6, 80.2
                ),
                createContentEntry(
                        "CONT-012", "EMERGENCY", "/audio/emergency/security.mp3",
                        "CONT-012", "ZONE-ALL", "100%",
                        "100/0", "NONE", null, "2025-06-03 16:15:00",
                        60.3, 9.3, 77.5
                ),
                createContentEntry(
                        "CONT-013", "MUSIC", "/audio/music/bg3.mp3",
                        "CONT-013", "ZONE-001,ZONE-004", "40%",
                        "28/1", "LOW", Arrays.asList("DEV-009"), "2025-06-03 17:00:00",
                        42.7, 7.4, 73.6
                ),
                createContentEntry(
                        "CONT-014", "PAGING", "/audio/paging/staff.mp3",
                        "CONT-014", "ZONE-003", "25%",
                        "15/0", "NONE", null, null,
                        32.0, 3.8, 88.0
                ),
                createContentEntry(
                        "CONT-015", "DRILL", "/audio/emergency/test.mp3",
                        "CONT-015", "ZONE-ALL", "10%",
                        "100/4", "HIGH", Arrays.asList("DEV-005", "DEV-021", "DEV-047", "DEV-053"), "2025-06-03 18:00:00",
                        75.1, 14.6, 59.8
                )
        );
    }

    private static Map<String, Object> createContentEntry(
            String contentId, String contentType, String audioPath,
            String currentPlayContent, String playZones, String progress,
            String zoneStatusMatrix, String alarmLevel, List<String> faultyDevices, String triggerTime,
            double cpuLoad, double networkLatency, double storageUsage
    ) {
        Map<String, Object> data = new HashMap<>();
        data.put("contentId", contentId);
        data.put("contentType", contentType);
        data.put("audioPath", audioPath);
        data.put("currentPlayContent", currentPlayContent);
        data.put("playZones", playZones);
        data.put("progress", progress);
        data.put("zoneStatusMatrix", zoneStatusMatrix); // 新增字段
        data.put("alarmLevel", alarmLevel);
        data.put("faultyDevices", faultyDevices);
        data.put("triggerTime", triggerTime);
        data.put("cpuLoad", cpuLoad);
        data.put("networkLatency", networkLatency);
        data.put("storageUsage", storageUsage);
        return data;
    }

    // 日志
    public static List<Map<String, Object>> generateAuditLogData() {
        return Arrays.asList(
                // 广播操作审计（控制类型）
                createLogEntry(
                        "LOG-20250605001", "2025-06-05 08:00:00", "ADMIN-001",
                        "控制", "TARGET-ZONE-ALL", null, null,
                        "成功", "全区", "500ms",
                        "192.168.1.101", "DEVICE-001", "SIGN-1a2b3c"
                ),
                // 配置变更审计（配置类型）
                createLogEntry(
                        "LOG-20250605002", "2025-06-05 08:15:30", "ADMIN-002",
                        "配置", "VOLUME-SETTING", "60dB", "75dB",
                        "成功", "分区1-2", "800ms",
                        "192.168.1.102", "DEVICE-002", "SIGN-4d5e6f"
                ),
                // 广播任务审计（广播类型，带修改记录）
                createLogEntry(
                        "LOG-20250605003", "2025-06-05 09:00:00", "ADMIN-001",
                        "广播", "TASK-001", "未开始", "进行中",
                        "成功", "分区3", "300ms",
                        "192.168.1.101", "DEVICE-001", "SIGN-7g8h9i"
                ),
                // 失败操作审计（控制类型）
                createLogEntry(
                        "LOG-20250605004", "2025-06-05 09:30:00", "ADMIN-003",
                        "控制", "TARGET-ZONE-004", null, null,
                        "失败", "分区4", "200ms",
                        "192.168.1.103", "DEVICE-003", "SIGN-0j1k2l"
                ),
                // 批量配置变更（配置类型，多对象）
                createLogEntry(
                        "LOG-20250605005", "2025-06-05 10:00:00", "ADMIN-002",
                        "配置", "ZONE-001,ZONE-003", "开启", "关闭",
                        "成功", "分区1+3", "1200ms",
                        "192.168.1.102", "DEVICE-002", "SIGN-3m4n5o"
                ),
                // 紧急广播审计（广播类型）
                createLogEntry(
                        "LOG-20250605006", "2025-06-05 10:30:00", "ADMIN-001",
                        "广播", "EMG-ALARM", null, null,
                        "成功", "全区", "400ms",
                        "192.168.1.101", "DEVICE-001", "SIGN-6p7q8r"
                ),
                // 权限变更审计（配置类型）
                createLogEntry(
                        "LOG-20250605007", "2025-06-05 11:00:00", "ADMIN-003",
                        "配置", "USER-ROLE", "普通用户", "管理员",
                        "成功", "用户ADMIN-004", "500ms",
                        "192.168.1.103", "DEVICE-003", "SIGN-9s0t1u"
                ),
                // 定时任务配置（配置类型）
                createLogEntry(
                        "LOG-20250605008", "2025-06-05 11:30:00", "ADMIN-002",
                        "配置", "CRON-JOB", "0 0 9 * * MON", "0 0 10 * * TUE",
                        "成功", "定时任务ID-001", "700ms",
                        "192.168.1.102", "DEVICE-002", "SIGN-2v3w4x"
                ),
                // 设备重启审计（控制类型）
                createLogEntry(
                        "LOG-20250605009", "2025-06-05 12:00:00", "ADMIN-001",
                        "控制", "DEVICE-005", null, null,
                        "成功", "设备5", "600ms",
                        "192.168.1.101", "DEVICE-001", "SIGN-5y6z7a"
                ),
                // 失败的广播操作（广播类型）
                createLogEntry(
                        "LOG-20250605010", "2025-06-05 12:30:00", "ADMIN-003",
                        "广播", "TASK-002", "已取消", "失败",
                        "失败", "分区2", "350ms",
                        "192.168.1.103", "DEVICE-003", "SIGN-8b9c0d"
                ),
                // 音量批量调整（配置类型）
                createLogEntry(
                        "LOG-20250605011", "2025-06-05 13:00:00", "ADMIN-002",
                        "配置", "VOLUME-BATCH", "45dB", "55dB",
                        "成功", "分区1-4", "1500ms",
                        "192.168.1.102", "DEVICE-002", "SIGN-1e2f3g"
                ),
                // 安全策略变更（配置类型）
                createLogEntry(
                        "LOG-20250605012", "2025-06-05 13:30:00", "ADMIN-001",
                        "配置", "SECURITY-POLICY", "允许匿名访问", "禁止匿名访问",
                        "成功", "系统全局", "900ms",
                        "192.168.1.101", "DEVICE-001", "SIGN-4h5i6j"
                ),
                // 手动寻呼审计（广播类型）
                createLogEntry(
                        "LOG-20250605013", "2025-06-05 14:00:00", "ADMIN-003",
                        "广播", "PAGE-GUEST", null, null,
                        "成功", "分区1+2", "450ms",
                        "192.168.1.103", "DEVICE-003", "SIGN-7k8l9m"
                ),
                // 设备参数修改（配置类型）
                createLogEntry(
                        "LOG-20250605014", "2025-06-05 14:30:00", "ADMIN-002",
                        "配置", "DEVICE-002/PARAM", "阈值80%", "阈值90%",
                        "成功", "设备2参数", "850ms",
                        "192.168.1.102", "DEVICE-002", "SIGN-0n1o2p"
                ),
                // 分区故障处理（控制类型）
                createLogEntry(
                        "LOG-20250605015", "2025-06-05 15:00:00", "ADMIN-001",
                        "控制", "ZONE-003/RECOVER", null, null,
                        "成功", "分区3", "1000ms",
                        "192.168.1.101", "DEVICE-001", "SIGN-3q4r5s"
                ),
                // 备份操作审计（配置类型）
                createLogEntry(
                        "LOG-20250605016", "2025-06-05 15:30:00", "ADMIN-003",
                        "配置", "SYSTEM-BACKUP", "未备份", "已备份",
                        "成功", "系统数据", "2000ms",
                        "192.168.1.103", "DEVICE-003", "SIGN-6t7u8v"
                ),
                // 权限回收审计（配置类型）
                createLogEntry(
                        "LOG-20250605017", "2025-06-05 16:00:00", "ADMIN-002",
                        "配置", "USER-ROLE/ADMIN-005", "管理员", "普通用户",
                        "成功", "用户ADMIN-005", "600ms",
                        "192.168.1.102", "DEVICE-002", "SIGN-9w0x1y"
                ),
                // 紧急按钮触发（控制类型）
                createLogEntry(
                        "LOG-20250605018", "2025-06-05 16:30:00", "ADMIN-001",
                        "控制", "EMERGENCY-BUTTON", null, null,
                        "成功", "全区", "300ms",
                        "192.168.1.101", "DEVICE-001", "SIGN-2z3a4b"
                ),
                // 固件升级审计（配置类型）
                createLogEntry(
                        "LOG-20250605019", "2025-06-05 17:00:00", "ADMIN-003",
                        "配置", "DEVICE-004/FIRMWARE", "V1.0.1", "V1.0.2",
                        "成功", "设备4", "1800ms",
                        "192.168.1.103", "DEVICE-003", "SIGN-5c6d7e"
                ),
                // 测试操作审计（控制类型，失败）
                createLogEntry(
                        "LOG-20250605020", "2025-06-05 17:30:00", "ADMIN-002",
                        "控制", "TEST-OPERATION", null, null,
                        "失败", "测试环境", "120ms",
                        "192.168.1.102", "DEVICE-002", "SIGN-8f9g0h"
                )
        );
    }

    private static Map<String, Object> createLogEntry(
            String logId, String operateTime, String operator,
            String operateType, String targetObject, String oldValue, String newValue,
            String successStatus, String affectRange, String duration,
            String ipAddress, String deviceFingerprint, String digitalSignature
    ) {
        Map<String, Object> data = new HashMap<>();
        data.put("logId", logId); // 日志ID
        data.put("operateTime", operateTime); // 操作时间
        data.put("operator", operator); // 操作人
        data.put("operateType", operateType); // 操作类型（控制/广播/配置）
        data.put("targetObject", targetObject); // 目标对象
        data.put("oldValue", oldValue); // 修改前值（配置变更时有效）
        data.put("newValue", newValue); // 修改后值（配置变更时有效）
        data.put("successStatus", successStatus); // 成功状态（成功/失败）
        data.put("affectRange", affectRange); // 影响范围
        data.put("duration", duration); // 耗时
        data.put("ipAddress", ipAddress); // IP地址
        data.put("deviceFingerprint", deviceFingerprint); // 设备指纹
        data.put("digitalSignature", digitalSignature); // 数字签名
        return data;
    }


    // 查询门禁设备状态（支持分页和条件查询）

    /**
     * 1. 三维设备地图
     * 功能整合：
     * 设备位置展示（三维坐标）
     * 实时状态监控（颜色标识）
     * 分区配置管理
     * 故障状态监视
     * @throws Exception
     */
    @GetMapping("/broadcastDevice")
    public Map<String, Object> getBroadcastDevice() throws Exception {
        List<Map<String, Object>> data = generateBroadcastDeviceData();
        PageData pd = this.getPageData();
        String deviceId = pd.getString("deviceId");
        String area = pd.getString("area");
        // 条件过滤
        if (deviceId != null && !deviceId.isEmpty()) {
            data = data.stream()
                    .filter(item -> item.get("deviceId").toString().contains(deviceId))
                    .collect(Collectors.toList());
        }
        if (area != null && !area.isEmpty()) {
            data = data.stream()
                    .filter(item -> item.get("area").toString().contains(area))
                    .collect(Collectors.toList());
        }

        // 分页逻辑
        int total = data.size();
        int fromIndex = (pd.getInteger("pageNum") - 1) * pd.getInteger("pageSize");
        int toIndex = Math.min(fromIndex + pd.getInteger("pageSize"), total);
        List<Map<String, Object>> pageData = data.subList(fromIndex, toIndex);

        // 返回结果
        Map<String, Object> response = Map.of(
                "msg", "操作成功",
                "code", 200,
                "data", Map.of("list", pageData,"total", total)
        );
        return response;
    }


    /**
     * 2. 广播控制中心
     * 功能整合：
     * 音量大小控制
     * 分区开关控制
     * 广播任务发起
     * 紧急广播喊话
     * @throws Exception
     */
    @GetMapping("/broadcastTask")
    public Map<String, Object> getbroadcastTask() throws Exception {
        List<Map<String, Object>> data = generateBroadcastData();
        PageData pd = this.getPageData();
        String targetZone = pd.getString("targetZone");
        String contentType = pd.getString("contentType");
        String broadcastStatus = pd.getString("broadcastStatus");
        // 条件过滤
        if (targetZone != null && !targetZone.isEmpty()) {
            data = data.stream()
                    .filter(item -> item.get("targetZoneIds").toString().contains(targetZone))
                    .collect(Collectors.toList());
        }
        if (contentType != null && !contentType.isEmpty()) {
            data = data.stream()
                    .filter(item -> item.get("contentCode").toString().contains(contentType))
                    .collect(Collectors.toList());
        }
        if (broadcastStatus != null && !broadcastStatus.isEmpty()) {
            data = data.stream()
                    .filter(item -> item.get("broadcastStatus").toString().contains(broadcastStatus))
                    .collect(Collectors.toList());
        }

        // 分页逻辑
        int total = data.size();
        int fromIndex = (pd.getInteger("pageNum") - 1) * pd.getInteger("pageSize");
        int toIndex = Math.min(fromIndex + pd.getInteger("pageSize"), total);
        List<Map<String, Object>> pageData = data.subList(fromIndex, toIndex);

        // 返回结果
        Map<String, Object> response = Map.of(
                "msg", "操作成功",
                "code", 200,
                "data", Map.of("list", pageData,"total", total)
        );
        return response;
    }

    /**
     * 2. 广播控制中心
     * 功能整合：
     * 音量大小控制
     * 分区开关控制
     * 广播任务发起
     * 紧急广播喊话
     * @throws Exception
     */
    @GetMapping("/broadcastDataGenerator")
    public Map<String, Object> getBroadcastDataGenerator() throws Exception {
        List<Map<String, Object>> data = generateSystemData();
        PageData pd = this.getPageData();
        String contentId = pd.getString("contentId");
        String playZone = pd.getString("playZone");
        String contentType = pd.getString("contentType");
        String alarmLevel = pd.getString("alarmLevel");
        // 条件过滤
        if (contentId != null && !contentId.isEmpty()) {
            data = data.stream()
                    .filter(item -> item.get("contentId").toString().contains(contentId))
                    .collect(Collectors.toList());
        }
        if (playZone != null && !playZone.isEmpty()) {
            data = data.stream()
                    .filter(item -> item.get("playZones").toString().contains(playZone))
                    .collect(Collectors.toList());
        }
        if (contentType != null && !contentType.isEmpty()) {
            data = data.stream()
                    .filter(item -> item.get("contentCode").toString().contains(contentType))
                    .collect(Collectors.toList());
        }
        if (alarmLevel != null && !alarmLevel.isEmpty()) {
            data = data.stream()
                    .filter(item -> item.get("alarmLevel").toString().contains(alarmLevel))
                    .collect(Collectors.toList());
        }

        // 分页逻辑
        int total = data.size();
        int fromIndex = (pd.getInteger("pageNum") - 1) * pd.getInteger("pageSize");
        int toIndex = Math.min(fromIndex + pd.getInteger("pageSize"), total);
        List<Map<String, Object>> pageData = data.subList(fromIndex, toIndex);

        // 返回结果
        Map<String, Object> response = Map.of(
                "msg", "操作成功",
                "code", 200,
                "data", Map.of("list", pageData,"total", total)
        );
        return response;
    }
    /**
     * 2. 广播控制中心
     * 功能整合：
     * 音量大小控制
     * 分区开关控制
     * 广播任务发起
     * 紧急广播喊话
     * @throws Exception
     */
    @GetMapping("/broadcastLog")
    public Map<String, Object> getBroadcastLog() throws Exception {
        List<Map<String, Object>> data = generateAuditLogData();
        PageData pd = this.getPageData();
        String logId = pd.getString("logId");
        String operator = pd.getString("operator");
        String operateType = pd.getString("operateType");
        String successStatus = pd.getString("successStatus");
        // 条件过滤
        if (logId != null && !logId.isEmpty()) {
            data = data.stream()
                    .filter(item -> item.get("logId").toString().contains(logId))
                    .collect(Collectors.toList());
        }
        if (operator != null && !operator.isEmpty()) {
            data = data.stream()
                    .filter(item -> item.get("operator").toString().contains(operator))
                    .collect(Collectors.toList());
        }
        if (operateType != null && !operateType.isEmpty()) {
            data = data.stream()
                    .filter(item -> item.get("operateType").toString().contains(operateType))
                    .collect(Collectors.toList());
        }
        if (successStatus != null && !successStatus.isEmpty()) {
            data = data.stream()
                    .filter(item -> item.get("successStatus").toString().contains(successStatus))
                    .collect(Collectors.toList());
        }

        // 分页逻辑
        int total = data.size();
        int fromIndex = (pd.getInteger("pageNum") - 1) * pd.getInteger("pageSize");
        int toIndex = Math.min(fromIndex + pd.getInteger("pageSize"), total);
        List<Map<String, Object>> pageData = data.subList(fromIndex, toIndex);

        // 返回结果
        Map<String, Object> response = Map.of(
                "msg", "操作成功",
                "code", 200,
                "data", Map.of("list", pageData,"total", total)
        );
        return response;
    }
}
