-- PLM PDF 压缩包推送记录（主表 + 明细）

CREATE TABLE IF NOT EXISTS `plm_pdf_zip_push` (
    `id`                  bigint       NOT NULL AUTO_INCREMENT,
    `production_order_no` varchar(64)  NOT NULL COMMENT '生产令号',
    `archive_name`        varchar(256) DEFAULT NULL COMMENT '压缩包文件名',
    `manifest_json`       text         NOT NULL COMMENT 'manifest JSON 原文',
    `saved_dir`           varchar(512) DEFAULT NULL COMMENT '落盘目录',
    `item_count`          int          NOT NULL DEFAULT 0 COMMENT 'PDF 数量',
    `receive_time`        datetime     NOT NULL COMMENT '接收时间',
    PRIMARY KEY (`id`),
    KEY `idx_production_order_no` (`production_order_no`),
    KEY `idx_receive_time` (`receive_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='PLM PDF压缩包推送记录';

CREATE TABLE IF NOT EXISTS `plm_pdf_zip_push_item` (
    `id`               bigint       NOT NULL AUTO_INCREMENT,
    `push_id`          bigint       NOT NULL COMMENT '推送记录ID',
    `pdf_path`         varchar(512) DEFAULT NULL COMMENT '压缩包内/原始PDF路径',
    `dwg_path`         varchar(512) DEFAULT NULL COMMENT '压缩包内/原始DWG路径',
    `material_code`    varchar(64)  DEFAULT NULL COMMENT '物料编码',
    `material_name`    varchar(256) DEFAULT NULL COMMENT '物料名称',
    `unit_qty`         decimal(18,6) DEFAULT NULL COMMENT '单台数量',
    `batch_qty`        decimal(18,6) DEFAULT NULL COMMENT '本批数量',
    `is_drawing_changed` tinyint(1) DEFAULT NULL COMMENT '是否变更图纸(IsDrawingChanaged)',
    `saved_file_name`  varchar(256) DEFAULT NULL COMMENT 'PDF落盘文件名',
    `saved_path`       varchar(512) DEFAULT NULL COMMENT 'PDF落盘完整路径',
    `saved_dwg_file_name` varchar(256) DEFAULT NULL COMMENT 'DWG落盘文件名',
    `saved_dwg_path`   varchar(512) DEFAULT NULL COMMENT 'DWG落盘完整路径',
    PRIMARY KEY (`id`),
    KEY `idx_push_id` (`push_id`),
    KEY `idx_material_code` (`material_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='PLM PDF/DWG推送明细';

-- 菜单（parent_id 请按实际菜单树调整；21200 起避免与现有 menu_id 冲突）
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
VALUES (21200, 'PLM PDF推送记录', 0, 20, 'plmPdfZipPush', 'system/plmPdfZipPush/index', 1, 0, 'C', '0', '0', 'system:plmPdfZipPush:list', 'documentation', 'admin', sysdate(), '', NULL, 'PLM PDF压缩包推送追溯');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
VALUES (21201, 'PLM PDF推送查询', 21200, 1, '#', '', 1, 0, 'F', '0', '0', 'system:plmPdfZipPush:query', '#', 'admin', sysdate(), '', NULL, '');
