CREATE TABLE IF NOT EXISTS dispatch_duty_schedule (
    id BIGSERIAL PRIMARY KEY, user_id BIGINT, user_name VARCHAR(50),
    duty_date DATE, start_time TIME, end_time TIME, area VARCHAR(100),
    created_time TIMESTAMP DEFAULT NOW(), updated_time TIMESTAMP DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS dispatch_command (
    id BIGSERIAL PRIMARY KEY, cmd_no VARCHAR(50) UNIQUE, title VARCHAR(200),
    content TEXT, type VARCHAR(20), status INT DEFAULT 0,
    issued_time TIMESTAMP, completed_time TIMESTAMP,
    created_time TIMESTAMP DEFAULT NOW(), updated_time TIMESTAMP DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS dispatch_work_order (
    id BIGSERIAL PRIMARY KEY, order_no VARCHAR(50) UNIQUE, title VARCHAR(200),
    description TEXT, type VARCHAR(20), priority VARCHAR(10), status INT DEFAULT 0,
    assignee_id BIGINT, creator_id BIGINT, deadline TIMESTAMP, completed_at TIMESTAMP,
    created_time TIMESTAMP DEFAULT NOW(), updated_time TIMESTAMP DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS dispatch_duty_log (
    id BIGSERIAL PRIMARY KEY, schedule_id BIGINT, user_id BIGINT,
    log_type VARCHAR(20), content TEXT, attachments TEXT,
    created_time TIMESTAMP DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS dispatch_strategy (
    id BIGSERIAL PRIMARY KEY, name VARCHAR(100), type VARCHAR(20),
    description TEXT, rule_config TEXT, status INT DEFAULT 1,
    created_time TIMESTAMP DEFAULT NOW(), updated_time TIMESTAMP DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS dispatch_emergency_plan (
    id BIGSERIAL PRIMARY KEY, plan_no VARCHAR(50) UNIQUE, name VARCHAR(100),
    type VARCHAR(20), content TEXT, resource_config TEXT,
    status INT DEFAULT 0, creator_id BIGINT,
    created_time TIMESTAMP DEFAULT NOW(), updated_time TIMESTAMP DEFAULT NOW()
);
