ALTER TABLE mes_pro_bag_code ADD COLUMN inbound_time datetime NULL COMMENT '入库时间';
ALTER TABLE mes_pro_bag_code ADD COLUMN inbound_event_id bigint NULL COMMENT '入库事件ID';
ALTER TABLE mes_pro_bag_code ADD COLUMN inbound_device_code varchar(64) NULL COMMENT '入库设备编码';
ALTER TABLE mes_pro_bag_code ADD COLUMN inbound_line_code varchar(64) NULL COMMENT '入库产线编码';
ALTER TABLE mes_pro_batch ADD COLUMN inbound_bag_quantity int NULL DEFAULT 0 COMMENT '累计入库袋数' AFTER pallet_quantity;

ALTER TABLE mes_pro_batch ADD COLUMN inbound_event_id bigint NULL COMMENT '入库事件ID';
ALTER TABLE mes_pro_batch ADD COLUMN inbound_device_code varchar(64) NULL COMMENT '入库设备编码';
ALTER TABLE mes_pro_batch ADD COLUMN inbound_line_code varchar(64) NULL COMMENT '入库产线编码';
CREATE TABLE mes_pro_scan_event (
  id bigint NOT NULL AUTO_INCREMENT,
  event_id varchar(64) NOT NULL,
  bag_code varchar(128) NOT NULL,
  bag_code_id bigint NULL,
  batch_id bigint NULL,
  batch_code varchar(128) NULL,
  item_id bigint NULL,
  quantity decimal(18,6) NULL,
  device_code varchar(64) NOT NULL,
  line_code varchar(64) NULL,
  warehouse_id bigint NULL,
  location_id bigint NULL,
  area_id bigint NULL,
  transaction_id bigint NULL,
  status varchar(16) NOT NULL DEFAULT 'FAILED',
  error_code varchar(64) NULL,
  error_message varchar(500) NULL,
  received_time datetime NOT NULL,
  failed_time datetime NULL,
  event_time datetime NULL,
  remark varchar(500) NULL,
  creator varchar(64) NULL, create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updater varchar(64) NULL, update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  deleted bit NOT NULL DEFAULT 0,
  PRIMARY KEY (id), UNIQUE KEY uk_mes_scan_event_event_id (event_id), UNIQUE KEY uk_mes_scan_event_bag (bag_code_id), KEY idx_mes_scan_event_status (status), KEY idx_mes_scan_event_error_code (error_code), KEY idx_mes_scan_event_received_time (received_time)
) ENGINE=InnoDB COMMENT='MES袋码扫码入库事件';
