Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
Internet-hospital
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
yuguo
Internet-hospital
Commits
aa5b7193
Commit
aa5b7193
authored
Mar 03, 2026
by
yuguo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
000d22a8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
53 deletions
+56
-53
server/pkg/agent/tools/navigate_page.go
server/pkg/agent/tools/navigate_page.go
+56
-53
No files found.
server/pkg/agent/tools/navigate_page.go
View file @
aa5b7193
...
...
@@ -4,58 +4,59 @@ import (
"context"
"fmt"
"strings"
"sync"
"time"
"internet-hospital/internal/model"
"internet-hospital/pkg/agent"
"internet-hospital/pkg/database"
)
// routeRegistry 后端路由注册表(与前端 config/routes.ts 对应)
// page_code → 默认路由路径
var
routeRegistry
=
map
[
string
]
string
{
// 管理端
"admin_dashboard"
:
"/admin/dashboard"
,
"admin_patients"
:
"/admin/patients"
,
"admin_doctors"
:
"/admin/doctors"
,
"admin_admins"
:
"/admin/admins"
,
"admin_departments"
:
"/admin/departments"
,
"admin_consultations"
:
"/admin/consultations"
,
"admin_prescription"
:
"/admin/prescription"
,
"admin_pharmacy"
:
"/admin/pharmacy"
,
"admin_users"
:
"/admin/users"
,
"admin_doctor_review"
:
"/admin/doctor-review"
,
"admin_statistics"
:
"/admin/statistics"
,
"admin_ai_config"
:
"/admin/ai-config"
,
"admin_ai_center"
:
"/admin/ai-center"
,
"admin_agents"
:
"/admin/agents"
,
"admin_tools"
:
"/admin/tools"
,
"admin_workflows"
:
"/admin/workflows"
,
"admin_tasks"
:
"/admin/tasks"
,
"admin_knowledge"
:
"/admin/knowledge"
,
"admin_safety"
:
"/admin/safety"
,
"admin_compliance"
:
"/admin/compliance"
,
"admin_roles"
:
"/admin/roles"
,
"admin_menus"
:
"/admin/menus"
,
// 医生端
"doctor_workbench"
:
"/doctor/workbench"
,
"doctor_consult"
:
"/doctor/consult"
,
"doctor_patient"
:
"/doctor/patient"
,
"doctor_schedule"
:
"/doctor/schedule"
,
"doctor_profile"
:
"/doctor/profile"
,
"doctor_certification"
:
"/doctor/certification"
,
"doctor_income"
:
"/doctor/income"
,
"doctor_ai_assist"
:
"/doctor/ai-assist"
,
"doctor_tasks"
:
"/doctor/tasks"
,
"doctor_chronic_review"
:
"/doctor/chronic/review"
,
// 患者端
"patient_home"
:
"/patient/home"
,
"patient_doctors"
:
"/patient/doctors"
,
"patient_consult"
:
"/patient/consult"
,
"patient_prescription"
:
"/patient/prescription"
,
"patient_health_records"
:
"/patient/health-records"
,
"patient_chronic"
:
"/patient/chronic"
,
"patient_payment"
:
"/patient/payment"
,
"patient_pre_consult"
:
"/patient/pre-consult"
,
"patient_profile"
:
"/patient/profile"
,
// routeCache 路由缓存(从数据库 menus 表动态加载)
var
(
routeCache
map
[
string
]
string
routeCacheMu
sync
.
RWMutex
routeCacheTime
time
.
Time
routeCacheTTL
=
5
*
time
.
Minute
// 缓存5分钟
)
// getRouteRegistry 从数据库查询路由注册表(带缓存)
func
getRouteRegistry
()
map
[
string
]
string
{
routeCacheMu
.
RLock
()
if
routeCache
!=
nil
&&
time
.
Since
(
routeCacheTime
)
<
routeCacheTTL
{
defer
routeCacheMu
.
RUnlock
()
return
routeCache
}
routeCacheMu
.
RUnlock
()
// 重新加载
routeCacheMu
.
Lock
()
defer
routeCacheMu
.
Unlock
()
db
:=
database
.
GetDB
()
if
db
==
nil
{
return
make
(
map
[
string
]
string
)
}
var
menus
[]
model
.
Menu
db
.
Where
(
"path != '' AND path IS NOT NULL"
)
.
Find
(
&
menus
)
registry
:=
make
(
map
[
string
]
string
,
len
(
menus
))
for
_
,
m
:=
range
menus
{
if
m
.
Path
==
""
{
continue
}
// 从 Path 生成 page_code: /admin/patients → admin_patients
pageCode
:=
strings
.
TrimPrefix
(
m
.
Path
,
"/"
)
pageCode
=
strings
.
ReplaceAll
(
pageCode
,
"/"
,
"_"
)
if
pageCode
!=
""
{
registry
[
pageCode
]
=
m
.
Path
}
}
routeCache
=
registry
routeCacheTime
=
time
.
Now
()
return
registry
}
// NavigatePageTool 页面导航工具 — 让 AI 助手能够控制前端页面跳转(v15 升级)
...
...
@@ -64,9 +65,10 @@ type NavigatePageTool struct{}
func
(
t
*
NavigatePageTool
)
Name
()
string
{
return
"navigate_page"
}
func
(
t
*
NavigatePageTool
)
Description
()
string
{
return
"导航到互联网医院系统页面"
}
func
(
t
*
NavigatePageTool
)
Parameters
()
[]
agent
.
ToolParameter
{
// 构建 page_code 枚举列表
codes
:=
make
([]
string
,
0
,
len
(
routeRegistry
))
for
code
:=
range
routeRegistry
{
// 动态从数据库构建 page_code 枚举列表
registry
:=
getRouteRegistry
()
codes
:=
make
([]
string
,
0
,
len
(
registry
))
for
code
:=
range
registry
{
codes
=
append
(
codes
,
code
)
}
return
[]
agent
.
ToolParameter
{
...
...
@@ -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
{
// 兼容旧格式: admin/doctors → admin_doctors
normalizedCode
:=
strings
.
ReplaceAll
(
pageCode
,
"/"
,
"_"
)
basePath
,
ok
=
r
outeR
egistry
[
normalizedCode
]
basePath
,
ok
=
registry
[
normalizedCode
]
if
!
ok
{
// 最后尝试直接当路径用
basePath
=
"/"
+
strings
.
ReplaceAll
(
pageCode
,
"_"
,
"/"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment