Explorar el Código

refactor(db): 移除数据库初始化中修改菜单内容的迁移脚本

- 删除迁移249 migrateSysMenuReorg(菜单归类调整/权限点拆分)
- 删除迁移251/372 migrateHealthMenuMount(健康饮食组菜单重组)
- 删除迁移267 migratePlanCenterMenu(方案中心菜单插入)
- 连带删除专属辅助方法 insertPlanCenterChild/updateMenuPermByPath/
  deleteHealthMenuByPath/insertHealthMenu/moveMenu
- 保留 queryMenuId/seedSysMenus(244 种子数据与建表仍执行)与
  grantMenuToRole(迁移318 系统提示词菜单仍使用)

菜单内容(sys_menu 行)不再由初始化脚本在每次启动时改写,交由人工/管理端维护
Xiaogang Liao hace 1 semana
padre
commit
dca5fd01c9

+ 1 - 290
cfc-backend/src/main/java/com/etotem/cfc/config/DatabaseInitializer.java

@@ -9309,8 +9309,6 @@ sqls.add("INSERT IGNORE INTO health_norm_reference (dimension, gender, age_min,
             }
         }
 
-        // 迁移249: sys_menu 菜单归类调整 + 权限点拆分(《角色权限与菜单归类整合方案》第二部分/B-3,幂等)
-        migrateSysMenuReorg();
 
         // 迁移250: 清理测试脏数据(B-7:TEST-Energy-Grant 测试任务、乱码昵称)
         try {
@@ -9323,8 +9321,6 @@ sqls.add("INSERT IGNORE INTO health_norm_reference (dimension, gender, age_min,
             log.warn("迁移250失败: {}", e.getMessage());
         }
 
-        // 迁移251/372: 健康饮食组报告管理模块重组(挂载报告管理/代传报告/应季食材,删除健康报告/报告审核菜单)
-        migrateHealthMenuMount();
 
         // 迁移252: 创建用户画像表
         try {
@@ -9504,8 +9500,6 @@ sqls.add("INSERT IGNORE INTO health_norm_reference (dimension, gender, age_min,
             log.warn("扩展 tasks.status 枚举失败(可能已修改): {}", e.getMessage());
         }
 
-        // 迁移267: 方案中心菜单(插在家庭运营与任务中心之间)
-        migratePlanCenterMenu();
         // 迁移268: coupon 表添加 status 列(优惠券停用/启用)
         migrateCouponStatus();
 // 迁移276: five_dimension_self_checks 表添加 question_ids_json 列(自检轮换用)
@@ -9529,64 +9523,7 @@ sqls.add("INSERT IGNORE INTO health_norm_reference (dimension, gender, age_min,
         ensureColumn("users", "family_inviter_id", "BIGINT DEFAULT NULL COMMENT '家庭邀请人ID(首次注册时绑定,用于追踪邀请来源)'");
     }
 
-    /**
-     * 迁移267: 存量库插入「方案中心」一级菜单及子菜单(幂等)
-     * 位置:家庭运营(sort=1) 与 任务中心 之间;任务中心及之后顶级菜单 sort+1
-     */
-    private void migratePlanCenterMenu() {
-        try {
-            Long existed = queryMenuId("SELECT id FROM sys_menu WHERE parent_id=0 AND title='方案中心'");
-            if (existed == null) {
-                // 为任务中心及之后的顶级菜单腾出 sort=2
-                jdbcTemplate.update(
-                        "UPDATE sys_menu SET sort = sort + 1 WHERE parent_id=0 AND sort >= 2 " +
-                        "AND title <> '方案中心'");
-                jdbcTemplate.update(
-                        "INSERT INTO sys_menu (parent_id, title, label, path, icon, perm, sort, visible) " +
-                        "VALUES (0, '方案中心', NULL, NULL, 'el-icon-notebook-2', 'plan:*', 2, 1)");
-                existed = jdbcTemplate.queryForObject("SELECT LAST_INSERT_ID()", Long.class);
-                log.info("迁移267: 已插入方案中心一级菜单");
-            }
-            if (existed == null) {
-                return;
-            }
-            Long healthPlanId = insertPlanCenterChild(existed, "健康方案管理", "/health-plan-manage",
-                    "el-icon-first-aid-kit", "plan:health", 0);
-            Long assessmentPlanId = insertPlanCenterChild(existed, "测评方案管理", "/assessment-plan-manage",
-                    "el-icon-edit", "plan:assessment", 1);
-            Integer grantCount = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM sys_role_menu", Integer.class);
-            if (grantCount != null && grantCount > 0) {
-                String[] roles = {"admin", "butler", "nutritionist", "operator"};
-                Long[] menuIds = {existed, healthPlanId, assessmentPlanId};
-                for (String role : roles) {
-                    for (Long menuId : menuIds) {
-                        grantMenuToRole(role, menuId);
-                    }
-                }
-            }
-            log.info("迁移267: 方案中心菜单挂载完成");
-        } catch (Exception e) {
-            log.warn("迁移267失败: {}", e.getMessage());
-        }
-    }
-
-    private Long insertPlanCenterChild(Long parentId, String label, String path, String icon, String perm, int sort) {
-        try {
-            Long existed = queryMenuId("SELECT id FROM sys_menu WHERE parent_id=" + parentId + " AND path='" + path + "'");
-            if (existed != null) {
-                return existed;
-            }
-            jdbcTemplate.update(
-                    "INSERT INTO sys_menu (parent_id, title, label, path, icon, perm, sort, visible) VALUES (?, NULL, ?, ?, ?, ?, ?, 1)",
-                    parentId, label, path, icon, perm, sort
-            );
-            return jdbcTemplate.queryForObject("SELECT LAST_INSERT_ID()", Long.class);
-        } catch (Exception e) {
-            log.warn("迁移267: 挂载子菜单「{}」失败: {}", label, e.getMessage());
-            return null;
-        }
-    }
-
+    
     /**
      * 迁移268: coupon 表添加 status 列(优惠券停用/启用,幂等)
      * 存量数据 status 为 NULL,查询层按 ACTIVE 处理,不影响现有券。
@@ -9600,222 +9537,6 @@ sqls.add("INSERT IGNORE INTO health_norm_reference (dimension, gender, age_min,
         }
     }
 
-    /**
-     * 迁移249: 存量库 sys_menu 菜单归类调整 + 权限点拆分(幂等,按 path/title 定位)
-     * 1. 审核中心改为分组,归集:服务角色申请审核/活动审核/待退款管理/收益提现审核
-     * 2. 能量规则/能量行为/周期性服务 → 系统配置·健康配置
-     * 3. LangGraph 管理 → 报告解析系统
-     * 4. 测评管理/测评订单/待分配规划师 → 测评咨询(删除系统配置下原"测评管理"子组)
-     * 5. 菜单组权限统一 模块:* 格式;system:config 拆分为 system:base/config:member/config:dimension/config:health/config:report-parser
-     * 6. 术语统一:七维能量配置 → 五维能量配置
-     */
-    private void migrateSysMenuReorg() {
-        try {
-            // A. 审核中心:顶级叶子 → 分组,并插入"审核中心总览"子项
-            jdbcTemplate.update("UPDATE sys_menu SET title='审核中心', label=NULL, path=NULL, perm='audit', sort=3 WHERE path='/review-center' AND parent_id=0 AND title IS NULL");
-            Long reviewGroup = queryMenuId("SELECT id FROM sys_menu WHERE parent_id=0 AND title='审核中心' AND (path IS NULL OR path='')");
-            if (reviewGroup != null) {
-                Integer childCount = jdbcTemplate.queryForObject(
-                        "SELECT COUNT(*) FROM sys_menu WHERE parent_id=" + reviewGroup + " AND path='/review-center'", Integer.class);
-                if (childCount == null || childCount == 0) {
-                    jdbcTemplate.update(
-                            "INSERT INTO sys_menu (parent_id, title, label, path, icon, perm, sort, visible) VALUES (?, NULL, '审核中心总览', '/review-center', 'el-icon-s-check', 'audit', 0, 1)",
-                            reviewGroup);
-                }
-                // 迁入审核中心
-                moveMenu("/service-role-applications", reviewGroup, "audit:service-role", 1);
-                moveMenu("/activity-review", reviewGroup, "audit:activity", 2);
-                moveMenu("/pending-refund", reviewGroup, "audit:refund", 3);
-                moveMenu("/family-earnings-withdraw", reviewGroup, "audit:withdraw", 4);
-            }
-
-            // B. 能量规则/能量行为/周期性服务 → 系统配置·健康配置
-            Long healthConfig = queryMenuId("SELECT id FROM sys_menu WHERE title='健康配置' AND (path IS NULL OR path='')");
-            if (healthConfig != null) {
-                jdbcTemplate.update("UPDATE sys_menu SET perm='config:health' WHERE id=" + healthConfig);
-                moveMenu("/energy-rule", healthConfig, "config:health", 3);
-                moveMenu("/energy-behavior-config", healthConfig, "config:health", 4);
-                moveMenu("/periodic-service-config", healthConfig, "config:health", 5);
-            }
-
-            // C. LangGraph 管理 → 报告解析系统
-            Long reportParser = queryMenuId("SELECT id FROM sys_menu WHERE parent_id=0 AND title='报告解析系统'");
-            if (reportParser != null) {
-                jdbcTemplate.update("UPDATE sys_menu SET perm='config:report-parser' WHERE id=" + reportParser);
-                moveMenu("/langgraph-admin", reportParser, "config:report-parser", 4);
-                updateMenuPermByPath("/report-types", "config:report-parser");
-                updateMenuPermByPath("/report-parser-import", "config:report-parser");
-                updateMenuPermByPath("/report-unknown-clusters", "config:report-parser");
-                updateMenuPermByPath("/report-auto-learn", "config:report-parser");
-            }
-
-            // D. 测评管理/测评订单/待分配规划师 → 测评咨询
-            Long assessment = queryMenuId("SELECT id FROM sys_menu WHERE parent_id=0 AND title='测评咨询'");
-            Long oldAssessmentManage = queryMenuId("SELECT id FROM sys_menu WHERE title='测评管理' AND (path IS NULL OR path='')");
-            if (assessment != null) {
-                moveMenu("/assessment-admin", assessment, "assessment:manage", 0);
-                moveMenu("/assessment-orders", assessment, "assessment:orders", 1);
-                moveMenu("/assessment-assign", assessment, "assessment:assign", 2);
-            }
-            if (oldAssessmentManage != null && assessment != null && !oldAssessmentManage.equals(assessment)) {
-                // 子项已迁走,删除系统配置下空的"测评管理"子组及其授权关联
-                jdbcTemplate.update("DELETE FROM sys_role_menu WHERE menu_id=" + oldAssessmentManage);
-                jdbcTemplate.update("DELETE FROM sys_menu WHERE id=" + oldAssessmentManage);
-            }
-
-            // E. 菜单组权限统一 模块:* 格式(废弃 operation/content/commerce/health 单段写法)
-            jdbcTemplate.update("UPDATE sys_menu SET perm='family:*' WHERE parent_id=0 AND title='家庭运营'");
-            jdbcTemplate.update("UPDATE sys_menu SET perm='articles:*' WHERE parent_id=0 AND title='知识中心'");
-            jdbcTemplate.update("UPDATE sys_menu SET perm='commerce:*' WHERE parent_id=0 AND title='商城营销'");
-            jdbcTemplate.update("UPDATE sys_menu SET perm='health:*' WHERE parent_id=0 AND title='健康饮食'");
-
-            // F. system:config 拆分
-            updateMenuPermByPath("/sys-config", "system:base");
-            updateMenuPermByPath("/gates", "system:base");
-            updateMenuPermByPath("/membership-center", "config:member");
-            updateMenuPermByPath("/badge-manage", "config:member");
-            updateMenuPermByPath("/virtual-goods-config", "config:member");
-            updateMenuPermByPath("/dimension-config", "config:dimension");
-            updateMenuPermByPath("/zodiac-configs", "config:dimension");
-            updateMenuPermByPath("/bazi-configs", "config:dimension");
-            updateMenuPermByPath("/blood-type-configs", "config:dimension");
-            updateMenuPermByPath("/health-norm-config", "config:health");
-            updateMenuPermByPath("/health-data-source", "config:health");
-            // 术语统一:七维能量配置 → 五维能量配置
-            jdbcTemplate.update("UPDATE sys_menu SET label='五维能量配置', perm='config:health' WHERE path='/health-energy-config'");
-            updateMenuPermByPath("/virtual-teams", "system:base");
-            updateMenuPermByPath("/knowledge-base", "knowledge:base");
-            updateMenuPermByPath("/health-knowledge", "knowledge:base");
-            updateMenuPermByPath("/supplier-products", "supply:manage");
-            updateMenuPermByPath("/nutrition-products", "health:products");
-            updateMenuPermByPath("/energy-sandbox", "health:energy");
-            // 子组权限
-            jdbcTemplate.update("UPDATE sys_menu SET perm='system:base' WHERE title='基础管理' AND (path IS NULL OR path='')");
-            jdbcTemplate.update("UPDATE sys_menu SET perm='config:dimension' WHERE title='配置中心' AND (path IS NULL OR path='')");
-            jdbcTemplate.update("UPDATE sys_menu SET perm='config:dimension' WHERE title='人生维度' AND (path IS NULL OR path='')");
-            jdbcTemplate.update("UPDATE sys_menu SET perm='system:base' WHERE title='虚拟团队' AND (path IS NULL OR path='')");
-
-            // G. 商城营销叶子权限统一(B-4 映射可识别)
-            updateMenuPermByPath("/product-manage", "commerce:products,commerce:self");
-            updateMenuPermByPath("/inventory", "inventory:self");
-            updateMenuPermByPath("/order-manage", "commerce:orders,order:self");
-            updateMenuPermByPath("/ecom-supplier", "commerce:supplier");
-            updateMenuPermByPath("/product-profit-rate", "finance:profit-rate");
-            updateMenuPermByPath("/coupon", "commerce:coupon");
-            updateMenuPermByPath("/coupon-grant-log", "commerce:coupon");
-            updateMenuPermByPath("/promotion", "commerce:promotion");
-            updateMenuPermByPath("/family-earnings", "finance:family-earnings");
-            updateMenuPermByPath("/activities", "activity:list,activity:self");
-            updateMenuPermByPath("/activity-registration-review", "activity:registration");
-            updateMenuPermByPath("/families", "family:list,family:read,family:bound");
-            updateMenuPermByPath("/children", "family:children,family:read,family:bound");
-            updateMenuPermByPath("/points-log", "family:points,family:bound");
-            updateMenuPermByPath("/growth-task", "task:growth");
-
-            log.info("迁移249: sys_menu 菜单归类调整与权限拆分完成");
-        } catch (Exception e) {
-            log.warn("迁移249失败: {}", e.getMessage());
-        }
-    }
-
-    /**
-     * 按 path 更新菜单权限(找不到时忽略)
-     */
-    private void updateMenuPermByPath(String path, String perm) {
-        try {
-            jdbcTemplate.update("UPDATE sys_menu SET perm=? WHERE path=?", perm, path);
-        } catch (Exception ignored) {
-        }
-    }
-
-    /**
-     * 迁移251/372: 健康饮食组 报告管理模块重组(存量库 sys_menu 幂等补齐)
-     * - 迁移251:挂载 报告管理/应季食材 并排序对齐《浠艾福后台-角色权限与菜单归类整合方案》最终菜单树;
-     * - 迁移372:报告管理模块重组——删除已下线 健康报告(/health-reports) 与 报告审核(/report-audit) 菜单,
-     *   新增 代传报告(/report-proxy-upload) 菜单(对应前端 ProxyReportUpload.vue / 路由 /report-proxy-upload)。
-     */
-    private void migrateHealthMenuMount() {
-        try {
-            Long healthGroup = queryMenuId("SELECT id FROM sys_menu WHERE parent_id=0 AND title='健康饮食'");
-            if (healthGroup == null) {
-                log.warn("迁移251: 未找到健康饮食分组,跳过");
-                return;
-            }
-            // 0. 迁移372: 删除已下线的 健康报告/报告审核 菜单(含角色授权,幂等)
-            deleteHealthMenuByPath(healthGroup, "/health-reports");
-            deleteHealthMenuByPath(healthGroup, "/report-audit");
-            // 1. 存量菜单排序对齐(报告管理0..五维能量10),先更新防止插入冲突
-            jdbcTemplate.update("UPDATE sys_menu SET sort=0 WHERE parent_id=" + healthGroup + " AND path='/report-management'");
-            jdbcTemplate.update("UPDATE sys_menu SET sort=2 WHERE parent_id=" + healthGroup + " AND path='/health-indicators'");
-            jdbcTemplate.update("UPDATE sys_menu SET sort=3 WHERE parent_id=" + healthGroup + " AND path='/health-checkins'");
-            jdbcTemplate.update("UPDATE sys_menu SET sort=4 WHERE parent_id=" + healthGroup + " AND path='/emotion-alert'");
-            jdbcTemplate.update("UPDATE sys_menu SET sort=5 WHERE parent_id=" + healthGroup + " AND path='/nutrition-mappings'");
-            jdbcTemplate.update("UPDATE sys_menu SET sort=6 WHERE parent_id=" + healthGroup + " AND path='/foods'");
-            jdbcTemplate.update("UPDATE sys_menu SET sort=7 WHERE parent_id=" + healthGroup + " AND path='/recipes'");
-            jdbcTemplate.update("UPDATE sys_menu SET sort=8 WHERE parent_id=" + healthGroup + " AND path='/seasonal-foods'");
-            jdbcTemplate.update("UPDATE sys_menu SET sort=9 WHERE parent_id=" + healthGroup + " AND path='/nutrition-products'");
-            jdbcTemplate.update("UPDATE sys_menu SET sort=10 WHERE parent_id=" + healthGroup + " AND path='/energy-sandbox'");
-            // 2. 按 path 幂等插入页面菜单
-            Long reportManagementId = insertHealthMenu(healthGroup, "报告管理", "/report-management", "el-icon-document", "health:reports", 0);
-            Long proxyUploadId = insertHealthMenu(healthGroup, "代传报告", "/report-proxy-upload", "el-icon-upload", "health:reports", 1);
-            Long seasonalFoodsId = insertHealthMenu(healthGroup, "应季食材", "/seasonal-foods", "el-icon-apple", "diet:foods", 8);
-            // 3. 条件授权:仅当已配置过角色授权(sys_role_menu 非空)时补授权,
-            //    避免破坏"所有角色均未授权 → 返回全量可见树"的兼容逻辑(SysMenuService.userMenus)
-            Integer grantCount = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM sys_role_menu", Integer.class);
-            if (grantCount != null && grantCount > 0) {
-                String[] roles = {"admin", "butler", "nutritionist"};
-                Long[] menuIds = {reportManagementId, proxyUploadId, seasonalFoodsId};
-                for (String role : roles) {
-                    for (Long menuId : menuIds) {
-                        grantMenuToRole(role, menuId);
-                    }
-                }
-                log.info("迁移251/372: 已为 admin/butler/nutritionist 补授权健康菜单");
-            }
-            log.info("迁移251/372: 健康饮食组菜单重组完成(报告管理/代传报告/应季食材)");
-        } catch (Exception e) {
-            log.warn("迁移251失败: {}", e.getMessage());
-        }
-    }
-
-    /**
-     * 按 path 删除健康饮食叶子菜单并清理角色授权(幂等)
-     */
-    private void deleteHealthMenuByPath(Long parentId, String path) {
-        try {
-            Long menuId = queryMenuId("SELECT id FROM sys_menu WHERE parent_id=" + parentId + " AND path='" + path + "'");
-            if (menuId == null) {
-                return;
-            }
-            jdbcTemplate.update("DELETE FROM sys_role_menu WHERE menu_id=" + menuId);
-            jdbcTemplate.update("DELETE FROM sys_menu WHERE id=" + menuId);
-            log.info("迁移372: 已删除下线健康菜单「{}」", path);
-        } catch (Exception e) {
-            log.warn("迁移372: 删除菜单「{}」失败: {}", path, e.getMessage());
-        }
-    }
-
-    /**
-     * 按 path 幂等插入健康饮食叶子菜单,返回菜单 id(已存在返回原 id)
-     */
-    private Long insertHealthMenu(Long parentId, String label, String path, String icon, String perm, int sort) {
-        try {
-            Long existed = queryMenuId("SELECT id FROM sys_menu WHERE parent_id=" + parentId + " AND path='" + path + "'");
-            if (existed != null) {
-                return existed;
-            }
-            jdbcTemplate.update(
-                    "INSERT INTO sys_menu (parent_id, title, label, path, icon, perm, sort, visible) VALUES (?, NULL, ?, ?, ?, ?, ?, 1)",
-                    parentId, label, path, icon, perm, sort
-            );
-            Long id = jdbcTemplate.queryForObject("SELECT LAST_INSERT_ID()", Long.class);
-            log.info("迁移251: 已挂载健康饮食菜单「{}」", label);
-            return id;
-        } catch (Exception e) {
-            log.warn("迁移251: 挂载菜单「{}」失败: {}", label, e.getMessage());
-            return null;
-        }
-    }
 
     /**
      * 角色-菜单授权(幂等,唯一键 uk_role_menu 冲突忽略)
@@ -9830,16 +9551,6 @@ sqls.add("INSERT IGNORE INTO health_norm_reference (dimension, gender, age_min,
         }
     }
 
-    /**
-     * 将菜单(按 path)移动到指定父组并更新权限/排序(幂等)
-     */
-    private void moveMenu(String path, Long parentId, String perm, int sort) {
-        try {
-            jdbcTemplate.update("UPDATE sys_menu SET parent_id=?, perm=?, sort=? WHERE path=?", parentId, perm, sort, path);
-        } catch (Exception ignored) {
-        }
-    }
-
     /**
      * 查询单个菜单 id,不存在返回 null
      */