-- 独立废料业务:入库按生产订单登记;出售单在财务审批通过后过账。 -- 此脚本仅创建业务表,不创建审批模型、菜单或仓库基础数据。 CREATE TABLE IF NOT EXISTS `mes_wm_scrap_receipt` ( `id` bigint NOT NULL AUTO_INCREMENT, `code` varchar(64) NOT NULL COMMENT '入库单号', `work_order_id` bigint NOT NULL COMMENT '生产工单编号', `work_order_code` varchar(64) NOT NULL COMMENT '生产工单号快照', `item_id` bigint NOT NULL COMMENT '废料物料编号', `quantity` decimal(20,4) NOT NULL COMMENT '入库数量', `warehouse_id` bigint NOT NULL, `location_id` bigint NOT NULL, `area_id` bigint NOT NULL, `batch_id` bigint DEFAULT NULL, `batch_code` varchar(100) DEFAULT NULL, `receipt_time` datetime NOT NULL, `transaction_id` bigint DEFAULT NULL COMMENT '入库库存流水编号', `remark` varchar(500) DEFAULT NULL, `creator` varchar(64) DEFAULT '', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `updater` varchar(64) DEFAULT '', `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `deleted` bit(1) NOT NULL DEFAULT b'0', PRIMARY KEY (`id`), UNIQUE KEY `uk_scrap_receipt_code` (`code`), KEY `idx_scrap_receipt_order_time` (`work_order_id`,`receipt_time`), KEY `idx_scrap_receipt_area` (`area_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='废料入库'; CREATE TABLE IF NOT EXISTS `mes_wm_scrap_sale` ( `id` bigint NOT NULL AUTO_INCREMENT, `code` varchar(64) NOT NULL COMMENT '出售单号', `buyer` varchar(200) NOT NULL COMMENT '购买方', `status` tinyint NOT NULL DEFAULT 0 COMMENT '0草稿 1审批中 2已出库 3已驳回 4已取消', `process_instance_id` varchar(64) DEFAULT NULL COMMENT '审批流程实例', `remark` varchar(500) DEFAULT NULL, `creator` varchar(64) DEFAULT '', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `updater` varchar(64) DEFAULT '', `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `deleted` bit(1) NOT NULL DEFAULT b'0', PRIMARY KEY (`id`), UNIQUE KEY `uk_scrap_sale_code` (`code`), KEY `idx_scrap_sale_process` (`process_instance_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='废料出售单'; CREATE TABLE IF NOT EXISTS `mes_wm_scrap_sale_line` ( `id` bigint NOT NULL AUTO_INCREMENT, `sale_id` bigint NOT NULL, `material_stock_id` bigint NOT NULL COMMENT '指定库存记录', `quantity` decimal(20,4) NOT NULL, `unit_price` decimal(20,4) NOT NULL, `transaction_id` bigint DEFAULT NULL COMMENT '审批通过后的出库流水编号', `creator` varchar(64) DEFAULT '', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `updater` varchar(64) DEFAULT '', `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `deleted` bit(1) NOT NULL DEFAULT b'0', PRIMARY KEY (`id`), KEY `idx_scrap_sale_line_sale` (`sale_id`), KEY `idx_scrap_sale_line_stock` (`material_stock_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='废料出售明细';