-- 防伪防窜货管理菜单与按钮权限初始化
-- 独立一级菜单（parent_id=0，type=1），采用 WHERE NOT EXISTS 幂等插入。
-- 执行前请确认目标数据库为项目实际业务库，并逐条执行。

INSERT INTO system_menu
    (id, name, permission, type, sort, parent_id, path, icon, component, component_name,
     status, visible, keep_alive, always_show, creator, create_time, updater, update_time, deleted)
SELECT 6070, '防伪防窜货管理', '', 1, 21, 0, 'trace-anti', 'ep:warning', '', '',
       0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'
WHERE NOT EXISTS (SELECT 1 FROM system_menu WHERE id = 6070 AND deleted = b'0');

INSERT INTO system_menu
    (id, name, permission, type, sort, parent_id, path, icon, component, component_name,
     status, visible, keep_alive, always_show, creator, create_time, updater, update_time, deleted)
SELECT 6071, '窜货预警', '', 2, 1, 6070, 'cross-region', 'ep:location-danger', 'mes/trace/crossregion/index', 'MesTraceCrossRegion',
       0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'
WHERE NOT EXISTS (SELECT 1 FROM system_menu WHERE id = 6071 AND deleted = b'0');

INSERT INTO system_menu
    (id, name, permission, type, sort, parent_id, path, icon, component, component_name,
     status, visible, keep_alive, always_show, creator, create_time, updater, update_time, deleted)
SELECT 6072, '窜货预警查询', 'mes:trace-cross-region:query', 3, 1, 6071, '', '', '', '',
       0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'
WHERE NOT EXISTS (SELECT 1 FROM system_menu WHERE id = 6072 AND deleted = b'0');

INSERT INTO system_menu
    (id, name, permission, type, sort, parent_id, path, icon, component, component_name,
     status, visible, keep_alive, always_show, creator, create_time, updater, update_time, deleted)
SELECT 6073, '窜货预警处理', 'mes:trace-cross-region:handle', 3, 2, 6071, '', '', '', '',
       0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'
WHERE NOT EXISTS (SELECT 1 FROM system_menu WHERE id = 6073 AND deleted = b'0');

INSERT INTO system_menu
    (id, name, permission, type, sort, parent_id, path, icon, component, component_name,
     status, visible, keep_alive, always_show, creator, create_time, updater, update_time, deleted)
SELECT 6074, '扫码地理分布', '', 2, 2, 6070, 'scan-distribution', 'ep:map-location', 'mes/trace-consumer-scan/index', 'MesConsumerScanDistribution',
       0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'
WHERE NOT EXISTS (SELECT 1 FROM system_menu WHERE id = 6074 AND deleted = b'0');

INSERT INTO system_menu
    (id, name, permission, type, sort, parent_id, path, icon, component, component_name,
     status, visible, keep_alive, always_show, creator, create_time, updater, update_time, deleted)
SELECT 6075, '扫码分布查询', 'mes:trace-consumer-scan:query', 3, 1, 6074, '', '', '', '',
       0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'
WHERE NOT EXISTS (SELECT 1 FROM system_menu WHERE id = 6075 AND deleted = b'0');

INSERT INTO system_menu
    (id, name, permission, type, sort, parent_id, path, icon, component, component_name,
     status, visible, keep_alive, always_show, creator, create_time, updater, update_time, deleted)
SELECT 6076, '数据完整性校验', '', 2, 3, 6070, 'integrity', 'ep:lock', 'mes/trace/integrity/index', 'MesTraceIntegrity',
       0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'
WHERE NOT EXISTS (SELECT 1 FROM system_menu WHERE id = 6076 AND deleted = b'0');

INSERT INTO system_menu
    (id, name, permission, type, sort, parent_id, path, icon, component, component_name,
     status, visible, keep_alive, always_show, creator, create_time, updater, update_time, deleted)
SELECT 6077, '完整性记录查询', 'mes:trace-integrity:query', 3, 1, 6076, '', '', '', '',
       0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'
WHERE NOT EXISTS (SELECT 1 FROM system_menu WHERE id = 6077 AND deleted = b'0');

INSERT INTO system_menu
    (id, name, permission, type, sort, parent_id, path, icon, component, component_name,
     status, visible, keep_alive, always_show, creator, create_time, updater, update_time, deleted)
SELECT 6078, '数据完整性校验', 'mes:trace-integrity:verify', 3, 2, 6076, '', '', '', '',
       0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'
WHERE NOT EXISTS (SELECT 1 FROM system_menu WHERE id = 6078 AND deleted = b'0');
