-- 1.0.383：供应商欠料看板 — 催料待办快照表 + 隐藏菜单
-- 功能：刷新/手动触发时快照 WorkOrdDetailTotalKB，生成催料待办并发起 MATERIAL_SHORTAGE (MS001) 审批流。
-- 幂等：表用 CREATE IF NOT EXISTS；菜单用 Id NOT EXISTS。

-- ① 催料待办快照表
CREATE TABLE IF NOT EXISTS `ado_material_shortage_todo` (
  `id`                BIGINT       NOT NULL AUTO_INCREMENT,
  `tenant_id`         BIGINT       NOT NULL DEFAULT 0,
  `snapshot_data`     LONGTEXT     NULL     COMMENT '欠料列表 JSON 快照',
  `flow_status`       VARCHAR(32)  NOT NULL DEFAULT 'PENDING' COMMENT 'PENDING/IN_PROGRESS/APPROVED/REJECTED/CANCELLED/TERMINATED',
  `flow_instance_id`  BIGINT       NULL     COMMENT '审批流实例 Id',
  `total_count`       INT          NOT NULL DEFAULT 0 COMMENT '快照行数',
  `create_by`         BIGINT       NULL,
  `create_time`       DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_tenant_time` (`tenant_id`, `create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='催料待办快照（供应商欠料看板）';

-- ② 催料待办详情隐藏菜单（Id=1329004010007，Pid=S4采购执行目录 1322000000004）
INSERT INTO SysMenu (Id, Pid, Type, Title, Name, Path, Component, Icon, IsIframe, IsHide, IsKeepAlive, IsAffix, OrderNo, Status, CreateTime)
SELECT 1329004010007, 1322000000004, 2, '催料待办详情', 'aidopS4MaterialShortageTodoDetail',
       '/aidop/s4/execution-kanban/material-shortage-todo-detail', '/aidop/s4/execution-kanban/materialShortageTodoDetail', 'ele-Document',
       0, 1, 1, 0, 25, 1, NOW()
WHERE NOT EXISTS (SELECT 1 FROM SysMenu WHERE Id = 1329004010007);
