-- ============================================================================
-- 个微联系人菜单（parent_id = 33104 微信管理）
-- 目标表：主库 ylrz_saas 的 tenant_sys_menu + tenant_company_menu
-- 执行后请按现有流程同步到各租户库 sys_menu / company_menu，并授权角色
-- 执行前确认: SELECT menu_id, menu_name, path FROM tenant_sys_menu WHERE menu_id = 33104;
-- ============================================================================

-- 1) 租户总后台模板 tenant_sys_menu
INSERT INTO tenant_sys_menu (
  menu_id, menu_name, parent_id, order_num, path, component,
  menu_type, visible, status, perms, icon, is_frame, is_cache,
  create_by, create_time, remark
) VALUES (
  32970, '个微联系人', 33104, 5, 'wxContact', 'wx/wxContact/index',
  'C', '0', '0', 'company:wxContact:list', 'el-icon-chat-dot-round', 1, 0,
  'admin', NOW(), '个微联系人列表与聊天记录'
) ON DUPLICATE KEY UPDATE
  menu_name = VALUES(menu_name),
  parent_id = VALUES(parent_id),
  path = VALUES(path),
  component = VALUES(component),
  perms = VALUES(perms),
  icon = VALUES(icon);

INSERT INTO tenant_sys_menu (
  menu_id, menu_name, parent_id, order_num, path, component,
  menu_type, visible, status, perms, icon, is_frame, is_cache,
  create_by, create_time
) VALUES
(329701, '联系人查询', 32970, 1, '', '', 'F', '0', '0', 'company:wxContact:list', '#', 1, 0, 'admin', NOW()),
(329702, '聊天记录查询', 32970, 2, '', '', 'F', '0', '0', 'company:wxMsgLog:list', '#', 1, 0, 'admin', NOW())
ON DUPLICATE KEY UPDATE perms = VALUES(perms);

-- 2) 销售端模板 tenant_company_menu
INSERT INTO tenant_company_menu (
  menu_id, menu_name, parent_id, order_num, path, component,
  menu_type, visible, status, perms, icon, is_frame, is_cache,
  create_by, create_time, remark
) VALUES (
  32970, '个微联系人', 33104, 5, 'wxContact', 'wx/wxContact/index',
  'C', '0', '0', 'company:wxContact:list', 'el-icon-chat-dot-round', 1, 0,
  'admin', NOW(), '个微联系人列表与聊天记录'
) ON DUPLICATE KEY UPDATE
  menu_name = VALUES(menu_name),
  parent_id = VALUES(parent_id),
  path = VALUES(path),
  component = VALUES(component),
  perms = VALUES(perms),
  icon = VALUES(icon);

INSERT INTO tenant_company_menu (
  menu_id, menu_name, parent_id, order_num, path, component,
  menu_type, visible, status, perms, icon, is_frame, is_cache,
  create_by, create_time
) VALUES
(329701, '联系人查询', 32970, 1, '', '', 'F', '0', '0', 'company:wxContact:list', '#', 1, 0, 'admin', NOW()),
(329702, '聊天记录查询', 32970, 2, '', '', 'F', '0', '0', 'company:wxMsgLog:list', '#', 1, 0, 'admin', NOW())
ON DUPLICATE KEY UPDATE perms = VALUES(perms);

-- 3) 若父菜单实际为 32380（文档 canonical），可改用:
-- UPDATE tenant_sys_menu SET parent_id = 32380 WHERE menu_id = 32970;
-- UPDATE tenant_company_menu SET parent_id = 32380 WHERE menu_id = 32970;
