feat: 告警清除/确认/状态检查任务

This commit is contained in:
TsMask
2025-02-26 17:50:59 +08:00
parent 75b1efcc09
commit f583f0bffd
6 changed files with 284 additions and 286 deletions

View File

@@ -52,7 +52,7 @@ type AlarmController struct {
// @Summary Alarm List
// @Description Alarm List
// @Router /neData/alarm/list [get]
func (s *AlarmController) List(c *gin.Context) {
func (s AlarmController) List(c *gin.Context) {
var query model.AlarmQuery
if err := c.ShouldBindQuery(&query); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
@@ -67,7 +67,7 @@ func (s *AlarmController) List(c *gin.Context) {
// 告警删除
//
// DELETE /:id
func (s *AlarmController) Remove(c *gin.Context) {
func (s AlarmController) Remove(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
id := c.Param("id")
if id == "" {
@@ -91,3 +91,48 @@ func (s *AlarmController) Remove(c *gin.Context) {
msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
c.JSON(200, resp.OkMsg(msg))
}
// 告警清除
//
// PUT /clear
func (s AlarmController) Clear(c *gin.Context) {
var body struct {
Ids []int64 `json:"ids" binding:"required"`
}
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
clearUser := reqctx.LoginUserToUserName(c)
rows, err := s.alarmService.AlarmClearByIds(body.Ids, clearUser)
if err != nil {
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, resp.OkData(rows))
}
// 告警确认
//
// PUT /ack
func (s AlarmController) Ack(c *gin.Context) {
var body struct {
Ids []int64 `json:"ids" binding:"required"`
AckState bool `json:"ackState" binding:"omitempty"`
}
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
ackUser := reqctx.LoginUserToUserName(c)
rows, err := s.alarmService.AlarmAckByIds(body.Ids, ackUser, body.AckState)
if err != nil {
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, resp.OkData(rows))
}