-- =====================================================================
-- 店铺营销后台菜单与按钮权限初始化
-- 模块：business-marketing
-- 创建时间：2026-06-25
-- 号段：2006000000000000000（一级目录）/ 0010~0050（二级菜单）/ 1011~1051（按钮）
-- 幂等：INSERT ... NOT EXISTS / UPDATE，可重复执行
-- 权限标识与 Controller @PreAuthorize 一致：marketing:模块:操作
-- 说明：与 doc/sql/business-marketing/marketing_menu_permission.sql 保持一致
-- =====================================================================

-- 1) 一级目录：店铺营销
INSERT INTO sys_menu_info (
    id, create_by, create_date, update_by, update_date, remarks, del_flag, organize_id, tenant_id, tenant_code,
    sort_num, menu_name, menu_short_name, menu_path, target, menu_parent_ids, menu_parent_id, menu_icon, is_show,
    permission, menu_type, tip, subsystem_id, category, class_path, component, verification
)
SELECT '2006000000000000000', '1', NOW(), '1', NOW(), NULL, '0', NULL, '1', '1',
    28, '店铺营销', '店铺营销', '/business/marketing', '', '0,', '0', 'Shop', '1',
    '', '1', '', '2064594732123582466', 'WEB', '', '', '0'
FROM dual
WHERE NOT EXISTS (SELECT 1 FROM sys_menu_info WHERE id = '2006000000000000000');

UPDATE sys_menu_info
   SET menu_name = '店铺营销', menu_short_name = '店铺营销',
       menu_path = '/business/marketing', component = '',
       menu_parent_id = '0', menu_parent_ids = '0,',
       menu_icon = 'Shop', sort_num = 28, menu_type = '1',
       is_show = '1', permission = '', del_flag = '0', update_by = '1', update_date = NOW()
 WHERE id = '2006000000000000000';

-- 2) 二级菜单：店铺会员
INSERT INTO sys_menu_info (
    id, create_by, create_date, update_by, update_date, remarks, del_flag, organize_id, tenant_id, tenant_code,
    sort_num, menu_name, menu_short_name, menu_path, target, menu_parent_ids, menu_parent_id, menu_icon, is_show,
    permission, menu_type, tip, subsystem_id, category, class_path, component, verification
)
SELECT '2006000000000000010', '1', NOW(), '1', NOW(), NULL, '0', NULL, '1', '1',
    10, '店铺会员', '店铺会员', '/business/marketing/memberTenant', '', '0,2006000000000000000,', '2006000000000000000', 'User', '1',
    '', '2', '', '2064594732123582466', 'WEB', '', 'marketing/memberTenant/index', '0'
FROM dual
WHERE NOT EXISTS (SELECT 1 FROM sys_menu_info WHERE id = '2006000000000000010');

UPDATE sys_menu_info
   SET menu_name = '店铺会员', menu_short_name = '店铺会员',
       menu_path = '/business/marketing/memberTenant', component = 'marketing/memberTenant/index',
       menu_parent_id = '2006000000000000000', menu_parent_ids = '0,2006000000000000000,',
       menu_icon = 'User', sort_num = 10, menu_type = '2',
       is_show = '1', permission = '', del_flag = '0', update_by = '1', update_date = NOW()
 WHERE id = '2006000000000000010';

-- 3) 二级菜单：营销配置
INSERT INTO sys_menu_info (
    id, create_by, create_date, update_by, update_date, remarks, del_flag, organize_id, tenant_id, tenant_code,
    sort_num, menu_name, menu_short_name, menu_path, target, menu_parent_ids, menu_parent_id, menu_icon, is_show,
    permission, menu_type, tip, subsystem_id, category, class_path, component, verification
)
SELECT '2006000000000000020', '1', NOW(), '1', NOW(), NULL, '0', NULL, '1', '1',
    20, '营销配置', '营销配置', '/business/marketing/tenantExt', '', '0,2006000000000000000,', '2006000000000000000', 'Setting', '1',
    '', '2', '', '2064594732123582466', 'WEB', '', 'marketing/tenantExt/index', '0'
FROM dual
WHERE NOT EXISTS (SELECT 1 FROM sys_menu_info WHERE id = '2006000000000000020');

UPDATE sys_menu_info
   SET menu_name = '营销配置', menu_short_name = '营销配置',
       menu_path = '/business/marketing/tenantExt', component = 'marketing/tenantExt/index',
       menu_parent_id = '2006000000000000000', menu_parent_ids = '0,2006000000000000000,',
       menu_icon = 'Setting', sort_num = 20, menu_type = '2',
       is_show = '1', permission = '', del_flag = '0', update_by = '1', update_date = NOW()
 WHERE id = '2006000000000000020';

-- 4) 二级菜单：推广二维码
INSERT INTO sys_menu_info (
    id, create_by, create_date, update_by, update_date, remarks, del_flag, organize_id, tenant_id, tenant_code,
    sort_num, menu_name, menu_short_name, menu_path, target, menu_parent_ids, menu_parent_id, menu_icon, is_show,
    permission, menu_type, tip, subsystem_id, category, class_path, component, verification
)
SELECT '2006000000000000030', '1', NOW(), '1', NOW(), NULL, '0', NULL, '1', '1',
    30, '推广二维码', '推广二维码', '/business/marketing/tenantQrcode', '', '0,2006000000000000000,', '2006000000000000000', 'Link', '1',
    '', '2', '', '2064594732123582466', 'WEB', '', 'marketing/tenantQrcode/index', '0'
FROM dual
WHERE NOT EXISTS (SELECT 1 FROM sys_menu_info WHERE id = '2006000000000000030');

UPDATE sys_menu_info
   SET menu_name = '推广二维码', menu_short_name = '推广二维码',
       menu_path = '/business/marketing/tenantQrcode', component = 'marketing/tenantQrcode/index',
       menu_parent_id = '2006000000000000000', menu_parent_ids = '0,2006000000000000000,',
       menu_icon = 'Link', sort_num = 30, menu_type = '2',
       is_show = '1', permission = '', del_flag = '0', update_by = '1', update_date = NOW()
 WHERE id = '2006000000000000030';

-- 5) 二级菜单：核销记录
INSERT INTO sys_menu_info (
    id, create_by, create_date, update_by, update_date, remarks, del_flag, organize_id, tenant_id, tenant_code,
    sort_num, menu_name, menu_short_name, menu_path, target, menu_parent_ids, menu_parent_id, menu_icon, is_show,
    permission, menu_type, tip, subsystem_id, category, class_path, component, verification
)
SELECT '2006000000000000040', '1', NOW(), '1', NOW(), NULL, '0', NULL, '1', '1',
    40, '核销记录', '核销记录', '/business/marketing/couponVerifyLog', '', '0,2006000000000000000,', '2006000000000000000', 'Finished', '1',
    '', '2', '', '2064594732123582466', 'WEB', '', 'marketing/couponVerifyLog/index', '0'
FROM dual
WHERE NOT EXISTS (SELECT 1 FROM sys_menu_info WHERE id = '2006000000000000040');

UPDATE sys_menu_info
   SET menu_name = '核销记录', menu_short_name = '核销记录',
       menu_path = '/business/marketing/couponVerifyLog', component = 'marketing/couponVerifyLog/index',
       menu_parent_id = '2006000000000000000', menu_parent_ids = '0,2006000000000000000,',
       menu_icon = 'Finished', sort_num = 40, menu_type = '2',
       is_show = '1', permission = '', del_flag = '0', update_by = '1', update_date = NOW()
 WHERE id = '2006000000000000040';

-- 6) 二级菜单：营销统计
INSERT INTO sys_menu_info (
    id, create_by, create_date, update_by, update_date, remarks, del_flag, organize_id, tenant_id, tenant_code,
    sort_num, menu_name, menu_short_name, menu_path, target, menu_parent_ids, menu_parent_id, menu_icon, is_show,
    permission, menu_type, tip, subsystem_id, category, class_path, component, verification
)
SELECT '2006000000000000050', '1', NOW(), '1', NOW(), NULL, '0', NULL, '1', '1',
    50, '营销统计', '营销统计', '/business/marketing/stats', '', '0,2006000000000000000,', '2006000000000000000', 'DataAnalysis', '1',
    '', '2', '', '2064594732123582466', 'WEB', '', 'marketing/stats/index', '0'
FROM dual
WHERE NOT EXISTS (SELECT 1 FROM sys_menu_info WHERE id = '2006000000000000050');

UPDATE sys_menu_info
   SET menu_name = '营销统计', menu_short_name = '营销统计',
       menu_path = '/business/marketing/stats', component = 'marketing/stats/index',
       menu_parent_id = '2006000000000000000', menu_parent_ids = '0,2006000000000000000,',
       menu_icon = 'DataAnalysis', sort_num = 50, menu_type = '2',
       is_show = '1', permission = '', del_flag = '0', update_by = '1', update_date = NOW()
 WHERE id = '2006000000000000050';

-- 7) 按钮权限：店铺会员
INSERT INTO sys_menu_button_info (id, create_date, create_by, update_date, update_by, del_flag, tenant_id, tenant_code, button_code, button_name, enable, menu_id, sort_num, sys_data, source)
SELECT '2006000000000001011', NOW(), '1', NOW(), '1', '0', '1', '1', 'marketing:memberTenant:list', '列表', '1', '2006000000000000010', 10, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2006000000000001011');
INSERT INTO sys_menu_button_info (id, create_date, create_by, update_date, update_by, del_flag, tenant_id, tenant_code, button_code, button_name, enable, menu_id, sort_num, sys_data, source)
SELECT '2006000000000001012', NOW(), '1', NOW(), '1', '0', '1', '1', 'marketing:memberTenant:info', '详情', '1', '2006000000000000010', 20, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2006000000000001012');
INSERT INTO sys_menu_button_info (id, create_date, create_by, update_date, update_by, del_flag, tenant_id, tenant_code, button_code, button_name, enable, menu_id, sort_num, sys_data, source)
SELECT '2006000000000001013', NOW(), '1', NOW(), '1', '0', '1', '1', 'marketing:memberTenant:export', '导出', '1', '2006000000000000010', 30, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2006000000000001013');
INSERT INTO sys_menu_button_info (id, create_date, create_by, update_date, update_by, del_flag, tenant_id, tenant_code, button_code, button_name, enable, menu_id, sort_num, sys_data, source)
SELECT '2006000000000001014', NOW(), '1', NOW(), '1', '0', '1', '1', 'marketing:memberTenant:assignRole', '设置角色', '1', '2006000000000000010', 40, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2006000000000001014');
INSERT INTO sys_menu_button_info (id, create_date, create_by, update_date, update_by, del_flag, tenant_id, tenant_code, button_code, button_name, enable, menu_id, sort_num, sys_data, source)
SELECT '2006000000000001015', NOW(), '1', NOW(), '1', '0', '1', '1', 'marketing:memberTenant:create', '绑定会员', '1', '2006000000000000010', 50, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2006000000000001015');

-- 8) 按钮权限：营销配置
INSERT INTO sys_menu_button_info (id, create_date, create_by, update_date, update_by, del_flag, tenant_id, tenant_code, button_code, button_name, enable, menu_id, sort_num, sys_data, source)
SELECT '2006000000000001021', NOW(), '1', NOW(), '1', '0', '1', '1', 'marketing:tenantExt:info', '详情', '1', '2006000000000000020', 10, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2006000000000001021');
INSERT INTO sys_menu_button_info (id, create_date, create_by, update_date, update_by, del_flag, tenant_id, tenant_code, button_code, button_name, enable, menu_id, sort_num, sys_data, source)
SELECT '2006000000000001022', NOW(), '1', NOW(), '1', '0', '1', '1', 'marketing:tenantExt:update', '保存', '1', '2006000000000000020', 20, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2006000000000001022');

-- 9) 按钮权限：推广二维码
INSERT INTO sys_menu_button_info (id, create_date, create_by, update_date, update_by, del_flag, tenant_id, tenant_code, button_code, button_name, enable, menu_id, sort_num, sys_data, source)
SELECT '2006000000000001031', NOW(), '1', NOW(), '1', '0', '1', '1', 'marketing:tenantQrcode:list', '列表', '1', '2006000000000000030', 10, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2006000000000001031');
INSERT INTO sys_menu_button_info (id, create_date, create_by, update_date, update_by, del_flag, tenant_id, tenant_code, button_code, button_name, enable, menu_id, sort_num, sys_data, source)
SELECT '2006000000000001032', NOW(), '1', NOW(), '1', '0', '1', '1', 'marketing:tenantQrcode:create', '生成', '1', '2006000000000000030', 20, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2006000000000001032');
INSERT INTO sys_menu_button_info (id, create_date, create_by, update_date, update_by, del_flag, tenant_id, tenant_code, button_code, button_name, enable, menu_id, sort_num, sys_data, source)
SELECT '2006000000000001033', NOW(), '1', NOW(), '1', '0', '1', '1', 'marketing:tenantQrcode:delete', '删除', '1', '2006000000000000030', 30, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2006000000000001033');

-- 10) 按钮权限：核销记录
INSERT INTO sys_menu_button_info (id, create_date, create_by, update_date, update_by, del_flag, tenant_id, tenant_code, button_code, button_name, enable, menu_id, sort_num, sys_data, source)
SELECT '2006000000000001041', NOW(), '1', NOW(), '1', '0', '1', '1', 'marketing:couponVerifyLog:list', '列表', '1', '2006000000000000040', 10, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2006000000000001041');
INSERT INTO sys_menu_button_info (id, create_date, create_by, update_date, update_by, del_flag, tenant_id, tenant_code, button_code, button_name, enable, menu_id, sort_num, sys_data, source)
SELECT '2006000000000001042', NOW(), '1', NOW(), '1', '0', '1', '1', 'marketing:couponVerifyLog:info', '详情', '1', '2006000000000000040', 20, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2006000000000001042');
INSERT INTO sys_menu_button_info (id, create_date, create_by, update_date, update_by, del_flag, tenant_id, tenant_code, button_code, button_name, enable, menu_id, sort_num, sys_data, source)
SELECT '2006000000000001043', NOW(), '1', NOW(), '1', '0', '1', '1', 'marketing:couponVerifyLog:export', '导出', '1', '2006000000000000040', 30, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2006000000000001043');

-- 11) 按钮权限：营销统计
INSERT INTO sys_menu_button_info (id, create_date, create_by, update_date, update_by, del_flag, tenant_id, tenant_code, button_code, button_name, enable, menu_id, sort_num, sys_data, source)
SELECT '2006000000000001051', NOW(), '1', NOW(), '1', '0', '1', '1', 'marketing:stats:overview', '概览', '1', '2006000000000000050', 10, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2006000000000001051');
