package apis import ( "go-admin/app/observe/service" "go-admin/app/observe/service/dto" "go-admin/config" "go-admin/utils" "net/http" "github.com/gin-gonic/gin" ) type Biz struct { utils.OtApi } // List 获取Biz列表 func (e Biz) List(c *gin.Context) { req := dto.BizListReq{} svc := service.Biz{} if err := e.Init(c, &req, &svc.OtService); err != nil { return } resp := make([]dto.BizListResp, 0) var count int64 if err := svc.List(&req, &resp, &count); err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } e.PageOK(resp, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功") } // Stats 获取单个业务的统计信息 func (e Biz) Stats(c *gin.Context) { req := dto.BizStatsReq{} svc := service.Biz{} if err := e.Init(c, &req, &svc.OtService); err != nil { return } resp := new(dto.BizStatsResp) if config.ExtConfig.ClickhouseMetrics { if err := svc.StatsFromClickhouse(&req, resp); err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } } else { if err := svc.Stats(&req, resp); err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } } e.OK(resp, "success") } // Detail 获取Biz详情列表 func (e Biz) Detail(c *gin.Context) { req := dto.BizDetailReq{} svc := service.Biz{} if err := e.Init(c, &req, &svc.OtService); err != nil { return } resp := make([]dto.BizDetailResp, 0) count := int64(0) if err := svc.Detail(&req, &resp, &count); err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } e.PageOK(resp, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功") } func (e Biz) Graph(c *gin.Context) { req := dto.BizGraphReq{} svc := service.Biz{} if err := e.Init(c, &req, &svc.OtService); err != nil { return } resp := []dto.BizGraphResp{} if err := svc.Graph(&req, &resp); err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } e.OK(resp, "success") } func (e Biz) GraphStats(c *gin.Context) { req := dto.BizGraphStatsReq{} svc := service.Biz{} if err := e.Init(c, &req, &svc.OtService); err != nil { return } resp := dto.BizGraphStatsResp{} if err := svc.GraphStats(&req, &resp); err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } e.OK(resp, "success") } // Digits 数字视图 func (e Biz) Digits(c *gin.Context) { req := dto.BizDigitsReq{} svc := service.Biz{} if err := e.Init(c, &req, &svc.OtService); err != nil { return } resp := dto.BizDigitsResp{} if config.ExtConfig.ClickhouseMetrics { if err := svc.DigitsFromClickhouse(&req, &resp); err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } } else { if err := svc.Digits(&req, &resp); err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } } e.OK(resp, "success") } // Mark 标记 func (e Biz) Mark(c *gin.Context) { req := dto.BizMarkReq{} svc := service.Biz{} if err := e.Init(c, &req, &svc.OtService); err != nil { return } if err := svc.Mark(&req); err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } e.OK("", "success") } // Favor 收藏 func (e Biz) Favor(c *gin.Context) { req := dto.BizFavorReq{} svc := service.Biz{} if err := e.Init(c, &req, &svc.OtService); err != nil { return } if err := svc.Favor(&req); err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } e.OK("", "success") } // Delete 删除 func (e Biz) Delete(c *gin.Context) { req := dto.BizDeleteReq{} svc := service.Biz{} if err := e.Init(c, &req, &svc.OtService); err != nil { return } if err := svc.Delete(&req); err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } e.OK("", "success") } // 生成业务列表 func (e Biz) GenList(c *gin.Context) { svc := service.Biz{} if err := e.MakeContext(c).MakeDB().MakeService(&svc.OtService).Errors; err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } if err := svc.GenGraph(); err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } e.OK("", "success") } func (e Biz) BasicGuy(c *gin.Context) { req := dto.BizBasicGuy{} svc := service.Biz{} if err := e.Init(c, &req, &svc.OtService); err != nil { return } resp := make(map[string]any) if err := svc.StatisticBasicGuy(&req, &resp); err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } e.OK(resp, "success") } // biz结点对应span列表 func (e Biz) NodeSpans(c *gin.Context) { req := dto.BizNodeSpansReq{} svc := service.Biz{} if err := e.Init(c, &req, &svc.OtService); err != nil { return } resp := make([]dto.ServiceSpansResp, 0) count := int64(0) if err := svc.NodeSpans(&req, &resp, &count); err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } e.PageOK(resp, int(count), req.GetPageIndex(), req.GetPageSize(), "ok") } func (e Biz) NodeStats(c *gin.Context) { req := dto.BizNodeStatsReq{} svc := service.Biz{} if err := e.Init(c, &req, &svc.OtService); err != nil { return } resp := dto.BizNodeStatsResp{} if config.ExtConfig.ClickhouseMetrics { if err := svc.NodeStatsFromClickhouse(&req, &resp); err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } } else { if err := svc.NodeStats(&req, &resp); err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } } e.OK(resp, "ok") } func (e Biz) NodeUpdate(c *gin.Context) { req := dto.BizNodeUpdateReq{} svc := service.Biz{} if err := e.Init(c, &req, &svc.OtService); err != nil { return } if err := svc.NodeUpdate(&req); err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } e.OK("", "修改成功") } func (e Biz) SlowTop(c *gin.Context) { req := dto.BizSlowTopReq{} svc := service.Biz{} if err := e.Init(c, &req, &svc.OtService); err != nil { return } resp := make([]dto.BizSlowTopResp, 0) if err := svc.SlowTop(&req, &resp); err != nil { e.Error(http.StatusInternalServerError, err, err.Error()) return } e.OK(resp, "ok") }