-- BattlefieldExplorationSystem 数据库设置脚本

-- 创建数据库
CREATE DATABASE IF NOT EXISTS fly_land_database;
USE fly_land_database;

-- 创建无人机表
CREATE TABLE IF NOT EXISTS uavdatabase (
    id VARCHAR(50) PRIMARY KEY,
    state INT DEFAULT 0,
    ip VARCHAR(15) NOT NULL,
    port INT DEFAULT 8080,
    lon DOUBLE DEFAULT 0.0,
    lat DOUBLE DEFAULT 0.0
);

-- 创建机器狗表
CREATE TABLE IF NOT EXISTS dogdatabase (
    id VARCHAR(50) PRIMARY KEY,
    state INT DEFAULT 0,
    ip VARCHAR(15) NOT NULL,
    port INT DEFAULT 9090,
    lon DOUBLE DEFAULT 0.0,
    lat DOUBLE DEFAULT 0.0
);

-- 插入测试数据 - 无人机
INSERT INTO uavdatabase (id, state, ip, port, lon, lat) VALUES
('UAV001', 1, '192.168.1.101', 8080, 116.40, 39.90),
('UAV002', 2, '192.168.1.102', 8080, 116.42, 39.92),
('UAV003', 0, '192.168.1.103', 8080, 116.44, 39.94)
ON DUPLICATE KEY UPDATE 
    state = VALUES(state),
    ip = VALUES(ip),
    port = VALUES(port),
    lon = VALUES(lon),
    lat = VALUES(lat);

-- 插入测试数据 - 机器狗
INSERT INTO dogdatabase (id, state, ip, port, lon, lat) VALUES
('DOG001', 1, '192.168.1.201', 9090, 116.38, 39.88),
('DOG002', 0, '192.168.1.202', 9090, 116.46, 39.86)
ON DUPLICATE KEY UPDATE 
    state = VALUES(state),
    ip = VALUES(ip),
    port = VALUES(port),
    lon = VALUES(lon),
    lat = VALUES(lat);

-- 验证数据
SELECT 'UAV Devices:' AS info;
SELECT * FROM uavdatabase;

SELECT 'Dog Devices:' AS info;
SELECT * FROM dogdatabase;