-- =============================================
-- 文件名: 2026-01-14_v1.6.001_周启威_设备点位.sql
-- 作者: 周启威
-- 日期: 2026-01-14
-- 描述: 补充设备管理模块按钮权限
--   1. 设备点位（query/add/edit/remove/export）
--   2. 点检记录（query/add/edit/remove/export）
--   3. 巡检计划（query/add/edit/remove/export）
--   4. 巡检记录（query/add/edit/remove/export）
--   5. 保养计划（query/add/edit/remove/export）
--   6. 保养记录（query/add/edit/remove/export）
-- =============================================

-- =============================================
-- 1. 设备点位按钮权限
-- =============================================
SET @point_menu_id = (SELECT menu_id FROM sys_menu WHERE path = 'inspectionPoint' AND component = 'mes/equipment/inspectionPoint/index' LIMIT 1);

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '设备点位查询', @point_menu_id, 1, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionPoint:query', '#', 'admin', NOW(), ''
FROM DUAL WHERE @point_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:inspectionPoint:query');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '设备点位新增', @point_menu_id, 2, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionPoint:add', '#', 'admin', NOW(), ''
FROM DUAL WHERE @point_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:inspectionPoint:add');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '设备点位修改', @point_menu_id, 3, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionPoint:edit', '#', 'admin', NOW(), ''
FROM DUAL WHERE @point_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:inspectionPoint:edit');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '设备点位删除', @point_menu_id, 4, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionPoint:remove', '#', 'admin', NOW(), ''
FROM DUAL WHERE @point_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:inspectionPoint:remove');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '设备点位导出', @point_menu_id, 5, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionPoint:export', '#', 'admin', NOW(), ''
FROM DUAL WHERE @point_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:inspectionPoint:export');

-- =============================================
-- 2. 点检记录按钮权限
-- =============================================
SET @spotcheck_record_menu_id = (SELECT menu_id FROM sys_menu WHERE path = 'spotcheckRecord' LIMIT 1);

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '点检记录查询', @spotcheck_record_menu_id, 1, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionPlanRecord:query', '#', 'admin', NOW(), ''
FROM DUAL WHERE @spotcheck_record_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE parent_id = @spotcheck_record_menu_id AND menu_name = '点检记录查询');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '点检记录新增', @spotcheck_record_menu_id, 2, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionPlanRecord:add', '#', 'admin', NOW(), ''
FROM DUAL WHERE @spotcheck_record_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE parent_id = @spotcheck_record_menu_id AND menu_name = '点检记录新增');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '点检记录修改', @spotcheck_record_menu_id, 3, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionPlanRecord:edit', '#', 'admin', NOW(), ''
FROM DUAL WHERE @spotcheck_record_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE parent_id = @spotcheck_record_menu_id AND menu_name = '点检记录修改');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '点检记录删除', @spotcheck_record_menu_id, 4, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionPlanRecord:remove', '#', 'admin', NOW(), ''
FROM DUAL WHERE @spotcheck_record_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE parent_id = @spotcheck_record_menu_id AND menu_name = '点检记录删除');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '点检记录导出', @spotcheck_record_menu_id, 5, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionPlanRecord:export', '#', 'admin', NOW(), ''
FROM DUAL WHERE @spotcheck_record_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE parent_id = @spotcheck_record_menu_id AND menu_name = '点检记录导出');

-- =============================================
-- 3. 巡检计划按钮权限
-- =============================================
SET @inspection_standard_menu_id = (SELECT menu_id FROM sys_menu WHERE path = 'inspectionStandard' AND component = 'mes/equipment/inspectionStandard/index' LIMIT 1);

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '巡检计划查询', @inspection_standard_menu_id, 1, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionStandard:query', '#', 'admin', NOW(), ''
FROM DUAL WHERE @inspection_standard_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:inspectionStandard:query');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '巡检计划新增', @inspection_standard_menu_id, 2, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionStandard:add', '#', 'admin', NOW(), ''
FROM DUAL WHERE @inspection_standard_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:inspectionStandard:add');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '巡检计划修改', @inspection_standard_menu_id, 3, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionStandard:edit', '#', 'admin', NOW(), ''
FROM DUAL WHERE @inspection_standard_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:inspectionStandard:edit');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '巡检计划删除', @inspection_standard_menu_id, 4, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionStandard:remove', '#', 'admin', NOW(), ''
FROM DUAL WHERE @inspection_standard_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:inspectionStandard:remove');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '巡检计划导出', @inspection_standard_menu_id, 5, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionStandard:export', '#', 'admin', NOW(), ''
FROM DUAL WHERE @inspection_standard_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:inspectionStandard:export');

-- =============================================
-- 4. 巡检记录按钮权限
-- =============================================
SET @inspection_record_menu_id = (SELECT menu_id FROM sys_menu WHERE path = 'inspectionPlanRecord' AND component = 'mes/equipment/inspectionPlanRecord/index' LIMIT 1);

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '巡检记录查询', @inspection_record_menu_id, 1, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionPlanRecord:query', '#', 'admin', NOW(), ''
FROM DUAL WHERE @inspection_record_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE parent_id = @inspection_record_menu_id AND menu_name = '巡检记录查询');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '巡检记录新增', @inspection_record_menu_id, 2, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionPlanRecord:add', '#', 'admin', NOW(), ''
FROM DUAL WHERE @inspection_record_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE parent_id = @inspection_record_menu_id AND menu_name = '巡检记录新增');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '巡检记录修改', @inspection_record_menu_id, 3, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionPlanRecord:edit', '#', 'admin', NOW(), ''
FROM DUAL WHERE @inspection_record_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE parent_id = @inspection_record_menu_id AND menu_name = '巡检记录修改');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '巡检记录删除', @inspection_record_menu_id, 4, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionPlanRecord:remove', '#', 'admin', NOW(), ''
FROM DUAL WHERE @inspection_record_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE parent_id = @inspection_record_menu_id AND menu_name = '巡检记录删除');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '巡检记录导出', @inspection_record_menu_id, 5, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:inspectionPlanRecord:export', '#', 'admin', NOW(), ''
FROM DUAL WHERE @inspection_record_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE parent_id = @inspection_record_menu_id AND menu_name = '巡检记录导出');

-- =============================================
-- 5. 保养计划按钮权限
-- =============================================
SET @maintenance_plan_menu_id = (SELECT menu_id FROM sys_menu WHERE path = 'maintenancePlan' AND component = 'mes/equipment/maintenancePlan/index' LIMIT 1);

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '保养计划查询', @maintenance_plan_menu_id, 1, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:maintenancePlan:query', '#', 'admin', NOW(), ''
FROM DUAL WHERE @maintenance_plan_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:maintenancePlan:query');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '保养计划新增', @maintenance_plan_menu_id, 2, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:maintenancePlan:add', '#', 'admin', NOW(), ''
FROM DUAL WHERE @maintenance_plan_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:maintenancePlan:add');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '保养计划修改', @maintenance_plan_menu_id, 3, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:maintenancePlan:edit', '#', 'admin', NOW(), ''
FROM DUAL WHERE @maintenance_plan_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:maintenancePlan:edit');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '保养计划删除', @maintenance_plan_menu_id, 4, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:maintenancePlan:remove', '#', 'admin', NOW(), ''
FROM DUAL WHERE @maintenance_plan_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:maintenancePlan:remove');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '保养计划导出', @maintenance_plan_menu_id, 5, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:maintenancePlan:export', '#', 'admin', NOW(), ''
FROM DUAL WHERE @maintenance_plan_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:maintenancePlan:export');

-- =============================================
-- 6. 保养记录按钮权限
-- =============================================
SET @maintenance_record_menu_id = (SELECT menu_id FROM sys_menu WHERE path = 'maintenanceRecord' AND component = 'mes/equipment/maintenanceRecord/index' LIMIT 1);

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '保养记录查询', @maintenance_record_menu_id, 1, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:maintenanceRecord:query', '#', 'admin', NOW(), ''
FROM DUAL WHERE @maintenance_record_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:maintenanceRecord:query');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '保养记录新增', @maintenance_record_menu_id, 2, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:maintenanceRecord:add', '#', 'admin', NOW(), ''
FROM DUAL WHERE @maintenance_record_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:maintenanceRecord:add');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '保养记录修改', @maintenance_record_menu_id, 3, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:maintenanceRecord:edit', '#', 'admin', NOW(), ''
FROM DUAL WHERE @maintenance_record_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:maintenanceRecord:edit');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '保养记录删除', @maintenance_record_menu_id, 4, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:maintenanceRecord:remove', '#', 'admin', NOW(), ''
FROM DUAL WHERE @maintenance_record_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:maintenanceRecord:remove');

INSERT INTO `sys_menu` (`menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '保养记录导出', @maintenance_record_menu_id, 5, '', NULL, NULL, 1, 0, 'F', '0', '0', 'equipment:maintenanceRecord:export', '#', 'admin', NOW(), ''
FROM DUAL WHERE @maintenance_record_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'equipment:maintenanceRecord:export');
