-- =====================================================================
-- 优惠券后台菜单与按钮权限初始化
-- 模块：business-coupon
-- 创建时间：2026-07-07
-- 号段：2007000000000000000（一级目录）/ 0010~0020（二级菜单）/ 1011~1024（按钮）
-- 幂等：INSERT ... NOT EXISTS / UPDATE，可重复执行
-- 权限标识与 Controller @PreAuthorize 一致：coupon:模块:操作
-- 说明：
--   1. 菜单结构为「顶级目录(parent=0)」-> 「子菜单(menu_type=2)」两层。
--   2. 使用场景（bizScene）为通用配置页 /business/common/bizScene，由 common
--      模块管理（后端 /common/bizScene/v1），不纳入本菜单。
--   3. 菜单路径与前端 asyncRouter.ts 保持一致：
--      /business/coupon/couponTemplate -> coupon/couponTemplate/index
--      /business/coupon/memberCoupon   -> coupon/memberCoupon/index
-- =====================================================================

-- 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 '2007000000000000000', '1', NOW(), '1', NOW(), NULL, '0', NULL, '1', '1',
    30, '优惠券管理', '优惠券管理', '/business/coupon', '', '0,', '0', 'Ticket', '1',
    '', '1', '', '1820814889969582082', 'WEB', '', '', '0'
FROM dual
WHERE NOT EXISTS (SELECT 1 FROM sys_menu_info WHERE id = '2007000000000000000');

UPDATE sys_menu_info
   SET menu_name = '优惠券管理', menu_short_name = '优惠券管理',
       menu_path = '/business/coupon', component = '',
       menu_parent_id = '0', menu_parent_ids = '0,',
       menu_icon = 'Ticket', sort_num = 30, menu_type = '1',
       is_show = '1', permission = '', del_flag = '0', update_by = '1', update_date = NOW()
 WHERE id = '2007000000000000000';

-- 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 '2007000000000000010', '1', NOW(), '1', NOW(), NULL, '0', NULL, '1', '1',
    10, '优惠券模板', '优惠券模板', '/business/coupon/couponTemplate', '', '0,2007000000000000000,', '2007000000000000000', 'Ticket', '1',
    '', '2', '', '1820814889969582082', 'WEB', '', 'coupon/couponTemplate/index', '0'
FROM dual
WHERE NOT EXISTS (SELECT 1 FROM sys_menu_info WHERE id = '2007000000000000010');

UPDATE sys_menu_info
   SET menu_name = '优惠券模板', menu_short_name = '优惠券模板',
       menu_path = '/business/coupon/couponTemplate', component = 'coupon/couponTemplate/index',
       menu_parent_id = '2007000000000000000', menu_parent_ids = '0,2007000000000000000,',
       menu_icon = 'Ticket', sort_num = 10, menu_type = '2',
       is_show = '1', permission = '', del_flag = '0', update_by = '1', update_date = NOW()
 WHERE id = '2007000000000000010';

-- 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 '2007000000000000020', '1', NOW(), '1', NOW(), NULL, '0', NULL, '1', '1',
    20, '会员优惠券', '会员优惠券', '/business/coupon/memberCoupon', '', '0,2007000000000000000,', '2007000000000000000', 'Present', '1',
    '', '2', '', '1820814889969582082', 'WEB', '', 'coupon/memberCoupon/index', '0'
FROM dual
WHERE NOT EXISTS (SELECT 1 FROM sys_menu_info WHERE id = '2007000000000000020');

UPDATE sys_menu_info
   SET menu_name = '会员优惠券', menu_short_name = '会员优惠券',
       menu_path = '/business/coupon/memberCoupon', component = 'coupon/memberCoupon/index',
       menu_parent_id = '2007000000000000000', menu_parent_ids = '0,2007000000000000000,',
       menu_icon = 'Present', sort_num = 20, menu_type = '2',
       is_show = '1', permission = '', del_flag = '0', update_by = '1', update_date = NOW()
 WHERE id = '2007000000000000020';

-- 4) 按钮权限：优惠券模板（coupon:couponTemplate:*）
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 '2007000000000001011', NOW(), '1', NOW(), '1', '0', '1', '1', 'coupon:couponTemplate:list', '列表', '1', '2007000000000000010', 10, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2007000000000001011');
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 '2007000000000001012', NOW(), '1', NOW(), '1', '0', '1', '1', 'coupon:couponTemplate:info', '详情', '1', '2007000000000000010', 20, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2007000000000001012');
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 '2007000000000001013', NOW(), '1', NOW(), '1', '0', '1', '1', 'coupon:couponTemplate:save', '保存', '1', '2007000000000000010', 30, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2007000000000001013');
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 '2007000000000001014', NOW(), '1', NOW(), '1', '0', '1', '1', 'coupon:couponTemplate:delete', '删除', '1', '2007000000000000010', 40, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2007000000000001014');
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 '2007000000000001015', NOW(), '1', NOW(), '1', '0', '1', '1', 'coupon:couponTemplate:updateStatus', '上下架', '1', '2007000000000000010', 50, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2007000000000001015');

-- 5) 按钮权限：会员优惠券（coupon:memberCoupon:*）
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 '2007000000000001021', NOW(), '1', NOW(), '1', '0', '1', '1', 'coupon:memberCoupon:list', '列表', '1', '2007000000000000020', 10, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2007000000000001021');
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 '2007000000000001022', NOW(), '1', NOW(), '1', '0', '1', '1', 'coupon:memberCoupon:info', '详情', '1', '2007000000000000020', 20, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2007000000000001022');
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 '2007000000000001023', NOW(), '1', NOW(), '1', '0', '1', '1', 'coupon:memberCoupon:grant', '发放', '1', '2007000000000000020', 30, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2007000000000001023');
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 '2007000000000001024', NOW(), '1', NOW(), '1', '0', '1', '1', 'coupon:memberCoupon:cancel', '作废', '1', '2007000000000000020', 40, '0', '0'
FROM dual WHERE NOT EXISTS (SELECT 1 FROM sys_menu_button_info WHERE id = '2007000000000001024');
