CREATE TABLE IF NOT EXISTS wms_furnace (
  furnace_id BIGINT AUTO_INCREMENT PRIMARY KEY,
  furnace_code VARCHAR(50) NOT NULL COMMENT '炉编号',
  furnace_name VARCHAR(100) NOT NULL COMMENT '名称',
  busy_flag TINYINT DEFAULT 0 COMMENT '是否忙碌(0否1是)',
  status TINYINT DEFAULT 1 COMMENT '状态(0停用1启用)',
  remark VARCHAR(500) NULL COMMENT '备注',
  del_flag TINYINT DEFAULT 0 COMMENT '删除标记(0正常 1删除)',
  create_by VARCHAR(64) NULL,
  update_by VARCHAR(64) NULL,
  create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
  update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY uk_wms_furnace_code (furnace_code)
) COMMENT = '退火炉信息表';

CREATE TABLE IF NOT EXISTS wms_furnace_plan (
  plan_id BIGINT AUTO_INCREMENT PRIMARY KEY,
  plan_no VARCHAR(60) NOT NULL COMMENT '计划号',
  plan_start_time DATETIME NULL COMMENT '计划开始时间',
  actual_start_time DATETIME NULL COMMENT '实际开始时间',
  end_time DATETIME NULL COMMENT '结束时间',
  target_furnace_id BIGINT NOT NULL COMMENT '目标炉子ID',
  status TINYINT DEFAULT 0 COMMENT '计划状态(0未开始 1进行中 2已完成)',
  remark VARCHAR(500) NULL COMMENT '备注',
  del_flag TINYINT DEFAULT 0 COMMENT '删除标记(0正常 1删除)',
  create_by VARCHAR(64) NULL,
  update_by VARCHAR(64) NULL,
  create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
  update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY uk_wms_furnace_plan_no (plan_no),
  INDEX idx_wms_furnace_plan_furnace (target_furnace_id),
  INDEX idx_wms_furnace_plan_status (status)
) COMMENT = '退火计划表';

CREATE TABLE IF NOT EXISTS wms_furnace_plan_coil (
  plan_coil_id BIGINT AUTO_INCREMENT PRIMARY KEY,
  plan_id BIGINT NOT NULL COMMENT '计划ID',
  coil_id BIGINT NOT NULL COMMENT '钢卷ID',
  del_flag TINYINT DEFAULT 0 COMMENT '删除标记(0正常 1删除)',
  create_by VARCHAR(64) NULL,
  update_by VARCHAR(64) NULL,
  create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
  update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY uk_wms_furnace_plan_coil (plan_id, coil_id),
  INDEX idx_wms_furnace_plan_coil_plan (plan_id),
  INDEX idx_wms_furnace_plan_coil_coil (coil_id)
) COMMENT = '退火计划钢卷关系表';
