-- 创建项目信息表
-- 执行日期: 2026-06-11

CREATE TABLE IF NOT EXISTS project_info (
    id VARCHAR(36) PRIMARY KEY,
    project_code VARCHAR(100) NOT NULL,
    project_name VARCHAR(255) NOT NULL,
    project_address VARCHAR(500),
    install_date TIMESTAMP,
    acceptance_date TIMESTAMP,
    online_date TIMESTAMP,
    device_count INTEGER DEFAULT 0,
    online_device_count INTEGER DEFAULT 0,
    offline_device_count INTEGER DEFAULT 0,
    gateway_count INTEGER DEFAULT 0,
    online_gateway_count INTEGER DEFAULT 0,
    offline_gateway_count INTEGER DEFAULT 0,
    project_manager VARCHAR(100),
    electricity_price DECIMAL(10, 4),
    create_by VARCHAR(64),
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_by VARCHAR(64),
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    remark VARCHAR(500)
);

-- 添加字段注释
COMMENT ON TABLE project_info IS '项目信息表';
COMMENT ON COLUMN project_info.id IS '主键ID';
COMMENT ON COLUMN project_info.project_code IS '用户项目编码';
COMMENT ON COLUMN project_info.project_name IS '项目名称';
COMMENT ON COLUMN project_info.project_address IS '项目地址';
COMMENT ON COLUMN project_info.install_date IS '安装日期';
COMMENT ON COLUMN project_info.acceptance_date IS '验收日期';
COMMENT ON COLUMN project_info.online_date IS '上线日期';
COMMENT ON COLUMN project_info.device_count IS '设备数量';
COMMENT ON COLUMN project_info.online_device_count IS '在线设备数量';
COMMENT ON COLUMN project_info.offline_device_count IS '离线设备数量';
COMMENT ON COLUMN project_info.gateway_count IS '网关数量';
COMMENT ON COLUMN project_info.online_gateway_count IS '在线网关数量';
COMMENT ON COLUMN project_info.offline_gateway_count IS '离线网关数量';
COMMENT ON COLUMN project_info.project_manager IS '项目负责人';
COMMENT ON COLUMN project_info.electricity_price IS '电单价';
COMMENT ON COLUMN project_info.create_by IS '创建者';
COMMENT ON COLUMN project_info.create_time IS '创建时间';
COMMENT ON COLUMN project_info.update_by IS '更新者';
COMMENT ON COLUMN project_info.update_time IS '更新时间';
COMMENT ON COLUMN project_info.remark IS '备注';

-- 创建索引
CREATE INDEX IF NOT EXISTS idx_project_code ON project_info(project_code);
CREATE INDEX IF NOT EXISTS idx_project_name ON project_info(project_name);
CREATE INDEX IF NOT EXISTS idx_project_manager ON project_info(project_manager);
CREATE INDEX IF NOT EXISTS idx_install_date ON project_info(install_date);
