package controller import ( "net/http" "ezops/model" "ezops/pkg/aiopscontext" "github.com/gin-gonic/gin" "gorm.io/gorm" ) // AIOpsContextHandler 提供 AI 上下文包接口,供智能助手、告警分析、预测分析和后续 MCP 复用。 // Logan.Li type AIOpsContextHandler struct { service *aiopscontext.Service } // NewAIOpsContextHandler 创建 AI 上下文处理器。 // Logan.Li func NewAIOpsContextHandler(db *gorm.DB) *AIOpsContextHandler { return &AIOpsContextHandler{service: aiopscontext.NewService(db)} } // Summary GET /api/v1/aiops/context/summary // Logan.Li func (h *AIOpsContextHandler) Summary(c *gin.Context) { data, err := h.service.Summary(c.Request.Context()) if err != nil { c.JSON(http.StatusOK, model.Response{Code: 500, Message: err.Error()}) return } c.JSON(http.StatusOK, model.Response{Code: 200, Data: data}) } // BuildPack POST /api/v1/aiops/context/pack // Logan.Li func (h *AIOpsContextHandler) BuildPack(c *gin.Context) { var req aiopscontext.ContextPackRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, model.Response{Code: 400, Message: "请求参数错误: " + err.Error()}) return } data, err := h.service.BuildPack(c.Request.Context(), req) if err != nil { c.JSON(http.StatusOK, model.Response{Code: 500, Message: err.Error()}) return } c.JSON(http.StatusOK, model.Response{Code: 200, Data: data}) }