CREATE TABLE IF NOT EXISTS sys_system_config (
  id BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '主键ID',
  config_code VARCHAR(100) NOT NULL COMMENT '配置编码',
  config_name VARCHAR(100) NOT NULL COMMENT '配置名称',
  config_value VARCHAR(500) NOT NULL COMMENT '配置值',
  remark VARCHAR(500) NULL COMMENT '备注',
  status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态：ACTIVE/INACTIVE',
  created_by BIGINT NULL COMMENT '创建用户ID',
  updated_by BIGINT NULL COMMENT '更新用户ID',
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  UNIQUE KEY uk_system_config_code (config_code),
  KEY idx_system_config_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='系统配置';

INSERT INTO sys_system_config (config_code, config_name, config_value, remark, status)
SELECT
  'RAW_MATERIAL_LOT_PREFIX',
  '原材料库存批次号前缀',
  'YL',
  '原材料库存批次号默认前缀，例如 YL0001',
  'ACTIVE'
FROM DUAL
WHERE NOT EXISTS (
  SELECT 1 FROM sys_system_config WHERE config_code = 'RAW_MATERIAL_LOT_PREFIX'
);
