diff --git a/src/bean/vo/request/alert.go b/src/bean/vo/request/alert.go index f7b14740e846302a275b273e48754d03b392201c..2e045b031c188049665e64074f45b970f294bfff 100644 --- a/src/bean/vo/request/alert.go +++ b/src/bean/vo/request/alert.go @@ -9,27 +9,27 @@ type DetailAlert struct { } type UpdateAlert struct { - Id int `json:"id" form:"id" binding:"required"` - Ids []string `json:"ids" form:"ids" binding:"required_without=Id"` // 预警ids - CloseRemark string `json:"close_remark" form:"close_remark"` // 关闭备注 - DeferPush int `json:"defer_push" form:"defer_push" binding:"omitempty,oneof=0 1"` // 延迟三天推送: 0:否 1:是 三天内将不再自动推送该告警信息给处置人员,可手动推送,但告警数据依然会出现 - RiskLevel int `json:"risk_level" form:"risk_level" binding:"omitempty,oneof=1 2 3 4"` // 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险 - Status int `json:"status" form:"status" binding:"omitempty,oneof=1 2 3"` // 状态,1:已恢复 2:未恢复 3:已关闭 - DisposalContent string `json:"disposal_content" form:"disposal_content"` // 处置内容(工单管理,结果反馈) + Id int `json:"id" form:"id" binding:"required"` + //Ids []int `json:"ids" form:"ids" binding:"required_without=Id"` // 预警ids + CloseRemark string `json:"close_remark" form:"close_remark"` // 关闭备注 + DeferPush int `json:"defer_push" form:"defer_push" binding:"omitempty,oneof=0 1"` // 延迟三天推送: 0:否 1:是 三天内将不再自动推送该告警信息给处置人员,可手动推送,但告警数据依然会出现 + RiskLevel int `json:"risk_level" form:"risk_level" binding:"omitempty,oneof=1 2 3 4"` // 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险 + Status int `json:"status" form:"status" binding:"omitempty,oneof=1 2 3"` // 状态,1:已恢复 2:未恢复 3:已关闭 + DisposalContent string `json:"disposal_content" form:"disposal_content"` // 处置内容(工单管理,结果反馈) } type BatchPushAlert struct { - Id string `json:"id" form:"id"` - Ids []string `json:"ids" form:"ids" binding:"required_without=Id"` // 预警ids + Id int `json:"id" form:"id"` + Ids []int `json:"ids" form:"ids" binding:"required_without=Id"` // 预警ids NotifyMethod []string `json:"notify_method" form:"notify_method" binding:"max=2,dive,oneof=dingtalk sms"` // 预警通知方式 dingtalk sms NotifyRecipients []entity.NotifyRecipients `json:"notify_recipients" form:"notify_recipients" binding:"dive"` // 预警推送用户 } type BatchCloseAlert struct { - Id string `json:"id" form:"id"` - Ids []string `json:"ids" form:"ids" binding:"required_without=Id"` // 预警ids - CloseRemark string `json:"close_remark" form:"close_remark" binding:"required"` // 关闭备注 - DeferPush int `json:"defer_push" form:"defer_push" binding:"omitempty,oneof=0 1"` // 延迟三天推送: 0:否 1:是 三天内将不再自动推送该告警信息给处置人员,可手动推送,但告警数据依然会出现 + Id int `json:"id" form:"id"` + Ids []int `json:"ids" form:"ids" binding:"required_without=Id"` // 预警ids + CloseRemark string `json:"close_remark" form:"close_remark" binding:"required"` // 关闭备注 + DeferPush int `json:"defer_push" form:"defer_push" binding:"omitempty,oneof=0 1"` // 延迟三天推送: 0:否 1:是 三天内将不再自动推送该告警信息给处置人员,可手动推送,但告警数据依然会出现 } type ListAlert struct { diff --git a/src/controller/alert.go b/src/controller/alert.go index 02421a46e767124c49b76d40b8b836a349717f3b..7aa7924eaec8b47a436bedf06c27456b09ccef4b 100644 --- a/src/controller/alert.go +++ b/src/controller/alert.go @@ -54,12 +54,7 @@ func BatchCloseAlert(c *gin.Context) { } svc := service.AlertSvc{User: header.GetUser(c)} - db, err := client.GetDbClient() - if err != nil { - SendJsonResponse(c, resp.DbConnectError.WithError(err), nil) - return - } - err = svc.BatchCloseAlert(db.NewSession(), req) + err := svc.BatchCloseAlert(req) if err != nil { SendJsonResponse(c, resp.FAIL.WithError(err), nil) return diff --git a/src/service/alert.go b/src/service/alert.go index 417e1a86fd427c12f937064571d5b6cf9742eff5..520315e4f0e1b3d9feb0a5e767960c26136586cf 100644 --- a/src/service/alert.go +++ b/src/service/alert.go @@ -336,6 +336,7 @@ func (a *AlertSvc) IndexUpdate(req request.UpdateAlert) (err error) { if req.Status != 0 { doc["status"] = req.Status } + doc["updated_at"] = now if req.DisposalContent != "" { var detailAlert response.AlertItem @@ -409,23 +410,31 @@ func (a *AlertSvc) BatchPushAlert(session *xorm.Session, req request.BatchPushAl return nil } -func (a *AlertSvc) BatchCloseAlert(session *xorm.Session, req request.BatchCloseAlert) (err error) { - var ( - sources response.OpenSearchSource - ) - - cli, err := client.GetOpenSearch() - if err != nil { - return +func (a *AlertSvc) BatchCloseAlert(req request.BatchCloseAlert) (err error) { + if len(req.Ids) > 0 { + for _, id := range req.Ids { + err = a.IndexUpdate(request.UpdateAlert{ + Id: id, + CloseRemark: req.CloseRemark, + Status: 3, + }) + if err != nil { + return + } + } + } else { + err = a.IndexUpdate(request.UpdateAlert{ + Id: req.Id, + CloseRemark: req.CloseRemark, + DeferPush: req.DeferPush, + Status: 3, + }) + if err != nil { + return + } } - _ = sources - _ = cli - - now := jsontime.Now() - _ = now - // TODO 批量推送用户告警 conf.Logger.Info("batch close", zap.Any("payload", req)) - return nil + return } func (a *AlertSvc) GetDataById(req request.DetailAlert) (resp response.AlertItem, err error) {