refactor: unify kubernetes_ table prefix, merge CI/CD models, LLM session support
- Rename container_clusters → kubernetes_clusters, container_topology_layouts → kubernetes_topology_layouts - LLM: add session_id to chat history for multi-turn conversation support - CI/CD: add pipeline_id, deploy_type, artifact_url, k8s_cluster_id to AppRelease - Cleanup: remove deprecated playbook handler, simplify automation models - Database: optimize auto-migrate model list - Frontend: AIOps assistant improvements, api.ts updates
This commit is contained in:
1 parent
9365c1e9db
commit
732974d152
14 files changed
+121
-474
No files matched your search
@@ -9,16 +9,24 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// GetChatHistory 获取当前用户的对话历史(按时间正序,仅返回最近 100 条避免过大) // Logan.Li
|
||||
// GET /api/v1/aiops/chat-history
|
||||
// GetChatHistory 获取当前用户的对话历史(按 session_id 过滤,默认返回最新 session) // Logan.Li
|
||||
// GET /api/v1/aiops/chat-history?session_id=xxx
|
||||
func (h *LLMHandler) GetChatHistory(c *gin.Context) {
|
||||
uid := middleware.GetUserID(c)
|
||||
sid := c.Query("session_id")
|
||||
var rows []models.ChatHistory
|
||||
// 子查询取最近 100 条后再正序返回,保证前端渲染顺序正确 // Logan.Li
|
||||
h.db.Where("user_id = ?", uid).
|
||||
Order("id DESC").
|
||||
Limit(100).
|
||||
Find(&rows)
|
||||
q := h.db.Where("user_id = ?", uid)
|
||||
// 指定 session_id 直接过滤;未指定则查最新 session // Logan.Li
|
||||
if sid != "" {
|
||||
q = q.Where("session_id = ?", sid)
|
||||
} else {
|
||||
// 取该用户最新的 session_id(id 最大那条的 session_id)
|
||||
var latest models.ChatHistory
|
||||
if err := h.db.Where("user_id = ?", uid).Order("id DESC").First(&latest).Error; err == nil && latest.SessionID != "" {
|
||||
q = q.Where("session_id = ?", latest.SessionID)
|
||||
}
|
||||
}
|
||||
q.Order("id DESC").Limit(100).Find(&rows)
|
||||
// 反转为时间正序(最早在前)
|
||||
for i, j := 0, len(rows)-1; i < j; i, j = i+1, j-1 {
|
||||
rows[i], rows[j] = rows[j], rows[i]
|
||||
|
||||
Reference in new issue
Block a user