Commit aa5b7193 authored by yuguo's avatar yuguo

fix

parent 000d22a8
...@@ -4,58 +4,59 @@ import ( ...@@ -4,58 +4,59 @@ import (
"context" "context"
"fmt" "fmt"
"strings" "strings"
"sync"
"time"
"internet-hospital/internal/model"
"internet-hospital/pkg/agent" "internet-hospital/pkg/agent"
"internet-hospital/pkg/database" "internet-hospital/pkg/database"
) )
// routeRegistry 后端路由注册表(与前端 config/routes.ts 对应) // routeCache 路由缓存(从数据库 menus 表动态加载)
// page_code → 默认路由路径 var (
var routeRegistry = map[string]string{ routeCache map[string]string
// 管理端 routeCacheMu sync.RWMutex
"admin_dashboard": "/admin/dashboard", routeCacheTime time.Time
"admin_patients": "/admin/patients", routeCacheTTL = 5 * time.Minute // 缓存5分钟
"admin_doctors": "/admin/doctors", )
"admin_admins": "/admin/admins",
"admin_departments": "/admin/departments", // getRouteRegistry 从数据库查询路由注册表(带缓存)
"admin_consultations": "/admin/consultations", func getRouteRegistry() map[string]string {
"admin_prescription": "/admin/prescription", routeCacheMu.RLock()
"admin_pharmacy": "/admin/pharmacy", if routeCache != nil && time.Since(routeCacheTime) < routeCacheTTL {
"admin_users": "/admin/users", defer routeCacheMu.RUnlock()
"admin_doctor_review": "/admin/doctor-review", return routeCache
"admin_statistics": "/admin/statistics", }
"admin_ai_config": "/admin/ai-config", routeCacheMu.RUnlock()
"admin_ai_center": "/admin/ai-center",
"admin_agents": "/admin/agents", // 重新加载
"admin_tools": "/admin/tools", routeCacheMu.Lock()
"admin_workflows": "/admin/workflows", defer routeCacheMu.Unlock()
"admin_tasks": "/admin/tasks",
"admin_knowledge": "/admin/knowledge", db := database.GetDB()
"admin_safety": "/admin/safety", if db == nil {
"admin_compliance": "/admin/compliance", return make(map[string]string)
"admin_roles": "/admin/roles", }
"admin_menus": "/admin/menus",
// 医生端 var menus []model.Menu
"doctor_workbench": "/doctor/workbench", db.Where("path != '' AND path IS NOT NULL").Find(&menus)
"doctor_consult": "/doctor/consult",
"doctor_patient": "/doctor/patient", registry := make(map[string]string, len(menus))
"doctor_schedule": "/doctor/schedule", for _, m := range menus {
"doctor_profile": "/doctor/profile", if m.Path == "" {
"doctor_certification": "/doctor/certification", continue
"doctor_income": "/doctor/income", }
"doctor_ai_assist": "/doctor/ai-assist", // 从 Path 生成 page_code: /admin/patients → admin_patients
"doctor_tasks": "/doctor/tasks", pageCode := strings.TrimPrefix(m.Path, "/")
"doctor_chronic_review": "/doctor/chronic/review", pageCode = strings.ReplaceAll(pageCode, "/", "_")
// 患者端 if pageCode != "" {
"patient_home": "/patient/home", registry[pageCode] = m.Path
"patient_doctors": "/patient/doctors", }
"patient_consult": "/patient/consult", }
"patient_prescription": "/patient/prescription",
"patient_health_records": "/patient/health-records", routeCache = registry
"patient_chronic": "/patient/chronic", routeCacheTime = time.Now()
"patient_payment": "/patient/payment", return registry
"patient_pre_consult": "/patient/pre-consult",
"patient_profile": "/patient/profile",
} }
// NavigatePageTool 页面导航工具 — 让 AI 助手能够控制前端页面跳转(v15 升级) // NavigatePageTool 页面导航工具 — 让 AI 助手能够控制前端页面跳转(v15 升级)
...@@ -64,9 +65,10 @@ type NavigatePageTool struct{} ...@@ -64,9 +65,10 @@ type NavigatePageTool struct{}
func (t *NavigatePageTool) Name() string { return "navigate_page" } func (t *NavigatePageTool) Name() string { return "navigate_page" }
func (t *NavigatePageTool) Description() string { return "导航到互联网医院系统页面" } func (t *NavigatePageTool) Description() string { return "导航到互联网医院系统页面" }
func (t *NavigatePageTool) Parameters() []agent.ToolParameter { func (t *NavigatePageTool) Parameters() []agent.ToolParameter {
// 构建 page_code 枚举列表 // 动态从数据库构建 page_code 枚举列表
codes := make([]string, 0, len(routeRegistry)) registry := getRouteRegistry()
for code := range routeRegistry { codes := make([]string, 0, len(registry))
for code := range registry {
codes = append(codes, code) codes = append(codes, code)
} }
return []agent.ToolParameter{ return []agent.ToolParameter{
...@@ -122,12 +124,13 @@ func (t *NavigatePageTool) Execute(ctx context.Context, params map[string]interf ...@@ -122,12 +124,13 @@ func (t *NavigatePageTool) Execute(ctx context.Context, params map[string]interf
} }
} }
// 从路由注册表查找基础路径 // 从数据库查询路由注册表
basePath, ok := routeRegistry[pageCode] registry := getRouteRegistry()
basePath, ok := registry[pageCode]
if !ok { if !ok {
// 兼容旧格式: admin/doctors → admin_doctors // 兼容旧格式: admin/doctors → admin_doctors
normalizedCode := strings.ReplaceAll(pageCode, "/", "_") normalizedCode := strings.ReplaceAll(pageCode, "/", "_")
basePath, ok = routeRegistry[normalizedCode] basePath, ok = registry[normalizedCode]
if !ok { if !ok {
// 最后尝试直接当路径用 // 最后尝试直接当路径用
basePath = "/" + strings.ReplaceAll(pageCode, "_", "/") basePath = "/" + strings.ReplaceAll(pageCode, "_", "/")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment