-- 市场进栏登记（主表 + 耳标子表）
SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS `biz_market_entry` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `entry_time` datetime NOT NULL COMMENT '进栏时间',
  `stall_id` bigint(20) NOT NULL COMMENT '市场栏位ID',
  `stall_code` char(2) NOT NULL COMMENT '栏位编号冗余',
  `supplier_id` bigint(20) NOT NULL COMMENT '供应商ID',
  `quantity` int(11) NOT NULL COMMENT '数量头',
  `del_flag` char(1) NOT NULL DEFAULT '0' COMMENT '0存在 2删除',
  `create_by` varchar(64) DEFAULT '' COMMENT '创建者',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `update_by` varchar(64) DEFAULT '' COMMENT '更新者',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `remark` varchar(500) DEFAULT NULL COMMENT '备注',
  PRIMARY KEY (`id`),
  KEY `idx_entry_time` (`entry_time`),
  KEY `idx_stall_code` (`stall_code`),
  KEY `idx_supplier` (`supplier_id`),
  KEY `idx_del_flag` (`del_flag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='市场进栏登记';

CREATE TABLE IF NOT EXISTS `biz_market_entry_ear_tag` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `entry_id` bigint(20) NOT NULL COMMENT '进栏登记主表ID',
  `supplier_id` bigint(20) NOT NULL COMMENT '供应商ID',
  `ear_tag` varchar(32) NOT NULL COMMENT '耳标号',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_entry_ear` (`entry_id`,`ear_tag`),
  KEY `idx_entry_id` (`entry_id`),
  KEY `idx_supplier_id` (`supplier_id`),
  KEY `idx_ear_tag` (`ear_tag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='市场进栏登记耳标明细';
