'use strict'; /** * 新增「消息和自动回复」根菜单及「群列表」「消息记录」子页面。 * * 固定 ID(开发库 & 生产库 wms_permission 当前 max_id 均为 491): * 492 — 父级菜单 "消息和自动回复" * 493 — inbox.groups(群列表) * 494 — inbox.messages(消息记录) * * 授权角色(permissions 不为 "*" 的 主管/经理 级角色): * 8 — 经理 * 26 — 仓库组-主管 * 28 — 客服组-主管 * 29 — 生产组-主管 */ module.exports = { // eslint-disable-next-line no-unused-vars async up(queryInterface, Sequelize) { // ── 1. 插入父级权限 (type=web_pages, sort=13) ── // 使用 INSERT IGNORE 兼容生产环境已有数据(路径相同但名称可能略有差异) await queryInterface.sequelize.query(` INSERT IGNORE INTO wms_permission (id, path, component, name, redirect, meta_title, meta_icon, hidden, always_show, parent_id, type, sort, status, created_at, update_at) VALUES (492, '/inbox', NULL, '消息和自动回复', NULL, '消息和自动回复', NULL, 0, 0, NULL, 'web_pages', 13, 1, NOW(), NOW()) `); // ── 2. 插入子页面权限 ── // 群列表 await queryInterface.sequelize.query(` INSERT IGNORE INTO wms_permission (id, path, component, name, redirect, meta_title, meta_icon, hidden, always_show, parent_id, type, sort, status, created_at, update_at) VALUES (493, '/inbox/groups', NULL, 'inbox.groups', NULL, '群列表', NULL, 0, 0, 492, 'web_pages', 0, 1, NOW(), NOW()) `); // 消息记录 await queryInterface.sequelize.query(` INSERT IGNORE INTO wms_permission (id, path, component, name, redirect, meta_title, meta_icon, hidden, always_show, parent_id, type, sort, status, created_at, update_at) VALUES (494, '/inbox/messages', NULL, 'inbox.messages', NULL, '消息记录', NULL, 0, 0, 492, 'web_pages', 1, 1, NOW(), NOW()) `); // ── 3. 给 客服组-主管及以上角色 追加权限 ID(幂等:已包含则跳过)── const newIdSuffix = ', 492, 493, 494'; await queryInterface.sequelize.query(` UPDATE wms_role SET permissions = CONCAT(LEFT(permissions, LENGTH(permissions) - 1), '${newIdSuffix}]') WHERE id IN (8, 26, 28, 29) AND permissions != '*' AND permissions IS NOT NULL AND LENGTH(permissions) > 2 AND permissions NOT LIKE '% 492,%' `); }, // eslint-disable-next-line no-unused-vars async down(queryInterface, Sequelize) { // ── 1. 从角色权限中移除新增的 ID ── await queryInterface.sequelize.query(` UPDATE wms_role SET permissions = REPLACE(permissions, ', 492, 493, 494', '') WHERE id IN (8, 26, 28, 29) `); // ── 2. 删除子页面权限 ── await queryInterface.sequelize.query( 'DELETE FROM wms_permission WHERE id IN (493, 494)' ); // ── 3. 删除父级权限 ── await queryInterface.sequelize.query( 'DELETE FROM wms_permission WHERE id = 492' ); }, };