From 8bdd35975efd6b6ca3fe695b7ba66c968303fec3 Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Tue, 22 Mar 2022 15:24:25 +0800 Subject: [PATCH] AlertCurEventGetByIds --- src/models/alert_cur_event.go | 11 +++++++++++ src/webapi/router/router.go | 2 +- src/webapi/router/router_alert_cur_event.go | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/models/alert_cur_event.go b/src/models/alert_cur_event.go index 5545eaa6..407d373c 100644 --- a/src/models/alert_cur_event.go +++ b/src/models/alert_cur_event.go @@ -350,6 +350,17 @@ func AlertCurEventGetAll(cluster string) ([]*AlertCurEvent, error) { return lst, err } +func AlertCurEventGetByIds(ids []int64) ([]*AlertCurEvent, error) { + var lst []*AlertCurEvent + + if len(ids) == 0 { + return lst, nil + } + + err := DB().Where("id in ?", ids).Order("id desc").Find(&lst).Error + return lst, err +} + func AlertCurEventGetByRule(ruleId int64) ([]*AlertCurEvent, error) { var lst []*AlertCurEvent err := DB().Where("rule_id=?", ruleId).Find(&lst).Error diff --git a/src/webapi/router/router.go b/src/webapi/router/router.go index 56b1ac11..7d7cbc3d 100644 --- a/src/webapi/router/router.go +++ b/src/webapi/router/router.go @@ -221,7 +221,7 @@ func configRoute(r *gin.Engine, version string) { // card logic pages.GET("/alert-cur-events/list", jwtAuth(), alertCurEventsList) pages.GET("/alert-cur-events/card", jwtAuth(), alertCurEventsCard) - pages.GET("/alert-cur-events/card/details", jwtAuth(), alertCurEventsCardDetails) + pages.POST("/alert-cur-events/card/details", jwtAuth(), alertCurEventsCardDetails) pages.GET("/alert-his-events/list", jwtAuth(), alertHisEventsList) pages.DELETE("/alert-cur-events", jwtAuth(), user(), perm("/alert-cur-events/del"), alertCurEventDel) diff --git a/src/webapi/router/router_alert_cur_event.go b/src/webapi/router/router_alert_cur_event.go index 03736094..a2a52f93 100644 --- a/src/webapi/router/router_alert_cur_event.go +++ b/src/webapi/router/router_alert_cur_event.go @@ -87,7 +87,11 @@ type AlertCard struct { } func alertCurEventsCardDetails(c *gin.Context) { + var f idsForm + ginx.BindJSON(c, &f) + lst, err := models.AlertCurEventGetByIds(f.Ids) + ginx.NewRender(c).Data(lst, err) } // 列表方式,拉取活跃告警