CREATE TABLE mes_wm_material_stock_bag (
    id BIGINT NOT NULL AUTO_INCREMENT COMMENT '编号',
    material_stock_id BIGINT NOT NULL COMMENT '库存汇总记录ID',
    bag_code_id BIGINT NOT NULL COMMENT '生产袋码ID',
    bag_code VARCHAR(64) NOT NULL COMMENT '袋码',
    item_id BIGINT NOT NULL COMMENT '物料ID',
    batch_id BIGINT NULL COMMENT '仓库批次ID',
    batch_code VARCHAR(64) NULL COMMENT '批次号',
    vendor_id BIGINT NULL COMMENT '供应商ID',
    warehouse_id BIGINT NOT NULL COMMENT '仓库ID',
    location_id BIGINT NULL COMMENT '库区ID',
    area_id BIGINT NULL COMMENT '库位ID',
    stock_state TINYINT NOT NULL COMMENT '库存状态：10暂存，20合格，30已出库，40报废',
    status TINYINT NOT NULL DEFAULT 1 COMMENT '明细状态：1在库，2已出库，3已报废',
    quantity DECIMAL(18, 6) NOT NULL DEFAULT 1 COMMENT '袋码库存数量',
    frozen BIT NOT NULL DEFAULT 0 COMMENT '是否冻结',
    last_transaction_id BIGINT NULL COMMENT '最近库存事务ID',
    inbound_time DATETIME NULL COMMENT '入库时间',
    outbound_time DATETIME NULL COMMENT '出库时间',
    creator VARCHAR(64) DEFAULT '' COMMENT '创建者',
    create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    updater VARCHAR(64) DEFAULT '' COMMENT '更新者',
    update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    deleted BIT NOT NULL DEFAULT 0 COMMENT '是否删除',
    PRIMARY KEY (id),
    UNIQUE KEY uk_bag_code (bag_code),
    KEY idx_material_stock (material_stock_id),
    KEY idx_batch_state (batch_id, stock_state, status),
    KEY idx_location_state (warehouse_id, location_id, area_id, stock_state, status),
    KEY idx_bag_code_id (bag_code_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='MES库存袋码明细';
