-- 直接使用SQL创建屠宰场表并添加测试数据
USE ningxia_zhengfu;

-- 删除旧表（如果存在）
DROP TABLE IF EXISTS government_slaughterhouses;

-- 创建新表，指定字符集支持中文
CREATE TABLE government_slaughterhouses (
  id INT AUTO_INCREMENT PRIMARY KEY COMMENT '屠宰场ID',
  name VARCHAR(100) NOT NULL UNIQUE COMMENT '屠宰场名称',
  address VARCHAR(255) NOT NULL COMMENT '地址',
  contactPerson VARCHAR(50) NOT NULL COMMENT '联系人',
  contactPhone VARCHAR(20) NOT NULL COMMENT '联系电话',
  licenseNumber VARCHAR(50) NOT NULL UNIQUE COMMENT '许可证号',
  status ENUM('active', 'inactive') NOT NULL DEFAULT 'active' COMMENT '状态（active: 正常, inactive: 停用）',
  createTime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  created_by INT NULL COMMENT '创建人ID',
  updated_by INT NULL COMMENT '更新人ID',
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  deleted_at DATETIME NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='政府系统屠宰场表';

-- 添加索引
CREATE INDEX idx_name ON government_slaughterhouses (name);
CREATE INDEX idx_licenseNumber ON government_slaughterhouses (licenseNumber);
CREATE INDEX idx_status ON government_slaughterhouses (status);

-- 插入测试数据
INSERT INTO government_slaughterhouses (
  name, 
  address, 
  contactPerson, 
  contactPhone, 
  licenseNumber, 
  status, 
  createTime, 
  created_by, 
  updated_by
) VALUES
(
  '宁夏银川市第一屠宰场',
  '宁夏回族自治区银川市金凤区良田镇植物园路',
  '张明',
  '13800138001',
  'SC1234567890123',
  'active',
  '2023-01-15 00:00:00',
  1,
  1
),
(
  '宁夏石嘴山市肉类加工厂',
  '宁夏回族自治区石嘴山市大武口区星海镇',
  '李强',
  '13900139002',
  'SC1234567890124',
  'active',
  '2023-02-10 00:00:00',
  1,
  1
),
(
  '宁夏吴忠市清真屠宰场',
  '宁夏回族自治区吴忠市利通区金银滩镇',
  '王芳',
  '13700137003',
  'SC1234567890125',
  'active',
  '2023-03-05 00:00:00',
  1,
  1
),
(
  '宁夏固原市牲畜屠宰场',
  '宁夏回族自治区固原市原州区官厅镇',
  '赵伟',
  '13600136004',
  'SC1234567890126',
  'inactive',
  '2023-04-20 00:00:00',
  1,
  1
),
(
  '宁夏中卫市肉类屠宰加工中心',
  '宁夏回族自治区中卫市沙坡头区迎水桥镇',
  '陈静',
  '13500135005',
  'SC1234567890127',
  'active',
  '2023-05-15 00:00:00',
  1,
  1
);

-- 查询插入的记录数
SELECT COUNT(*) AS total_records FROM government_slaughterhouses;