Commit 64e49181 authored by 李科's avatar 李科

feat: 完善批量关闭预警

parent d3cc2651
...@@ -10,7 +10,7 @@ type DetailAlert struct { ...@@ -10,7 +10,7 @@ type DetailAlert struct {
type UpdateAlert struct { type UpdateAlert struct {
Id int `json:"id" form:"id" binding:"required"` Id int `json:"id" form:"id" binding:"required"`
Ids []string `json:"ids" form:"ids" binding:"required_without=Id"` // 预警ids //Ids []int `json:"ids" form:"ids" binding:"required_without=Id"` // 预警ids
CloseRemark string `json:"close_remark" form:"close_remark"` // 关闭备注 CloseRemark string `json:"close_remark" form:"close_remark"` // 关闭备注
DeferPush int `json:"defer_push" form:"defer_push" binding:"omitempty,oneof=0 1"` // 延迟三天推送: 0:否 1:是 三天内将不再自动推送该告警信息给处置人员,可手动推送,但告警数据依然会出现 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:重大风险 RiskLevel int `json:"risk_level" form:"risk_level" binding:"omitempty,oneof=1 2 3 4"` // 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险
...@@ -19,15 +19,15 @@ type UpdateAlert struct { ...@@ -19,15 +19,15 @@ type UpdateAlert struct {
} }
type BatchPushAlert struct { type BatchPushAlert struct {
Id string `json:"id" form:"id"` Id int `json:"id" form:"id"`
Ids []string `json:"ids" form:"ids" binding:"required_without=Id"` // 预警ids 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 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"` // 预警推送用户 NotifyRecipients []entity.NotifyRecipients `json:"notify_recipients" form:"notify_recipients" binding:"dive"` // 预警推送用户
} }
type BatchCloseAlert struct { type BatchCloseAlert struct {
Id string `json:"id" form:"id"` Id int `json:"id" form:"id"`
Ids []string `json:"ids" form:"ids" binding:"required_without=Id"` // 预警ids Ids []int `json:"ids" form:"ids" binding:"required_without=Id"` // 预警ids
CloseRemark string `json:"close_remark" form:"close_remark" binding:"required"` // 关闭备注 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:是 三天内将不再自动推送该告警信息给处置人员,可手动推送,但告警数据依然会出现 DeferPush int `json:"defer_push" form:"defer_push" binding:"omitempty,oneof=0 1"` // 延迟三天推送: 0:否 1:是 三天内将不再自动推送该告警信息给处置人员,可手动推送,但告警数据依然会出现
} }
......
...@@ -54,12 +54,7 @@ func BatchCloseAlert(c *gin.Context) { ...@@ -54,12 +54,7 @@ func BatchCloseAlert(c *gin.Context) {
} }
svc := service.AlertSvc{User: header.GetUser(c)} svc := service.AlertSvc{User: header.GetUser(c)}
db, err := client.GetDbClient() err := svc.BatchCloseAlert(req)
if err != nil {
SendJsonResponse(c, resp.DbConnectError.WithError(err), nil)
return
}
err = svc.BatchCloseAlert(db.NewSession(), req)
if err != nil { if err != nil {
SendJsonResponse(c, resp.FAIL.WithError(err), nil) SendJsonResponse(c, resp.FAIL.WithError(err), nil)
return return
......
...@@ -336,6 +336,7 @@ func (a *AlertSvc) IndexUpdate(req request.UpdateAlert) (err error) { ...@@ -336,6 +336,7 @@ func (a *AlertSvc) IndexUpdate(req request.UpdateAlert) (err error) {
if req.Status != 0 { if req.Status != 0 {
doc["status"] = req.Status doc["status"] = req.Status
} }
doc["updated_at"] = now
if req.DisposalContent != "" { if req.DisposalContent != "" {
var detailAlert response.AlertItem var detailAlert response.AlertItem
...@@ -409,23 +410,31 @@ func (a *AlertSvc) BatchPushAlert(session *xorm.Session, req request.BatchPushAl ...@@ -409,23 +410,31 @@ func (a *AlertSvc) BatchPushAlert(session *xorm.Session, req request.BatchPushAl
return nil return nil
} }
func (a *AlertSvc) BatchCloseAlert(session *xorm.Session, req request.BatchCloseAlert) (err error) { func (a *AlertSvc) BatchCloseAlert(req request.BatchCloseAlert) (err error) {
var ( if len(req.Ids) > 0 {
sources response.OpenSearchSource for _, id := range req.Ids {
) err = a.IndexUpdate(request.UpdateAlert{
Id: id,
cli, err := client.GetOpenSearch() CloseRemark: req.CloseRemark,
Status: 3,
})
if err != nil { if err != nil {
return return
} }
_ = sources }
_ = cli } else {
err = a.IndexUpdate(request.UpdateAlert{
now := jsontime.Now() Id: req.Id,
_ = now CloseRemark: req.CloseRemark,
// TODO 批量推送用户告警 DeferPush: req.DeferPush,
Status: 3,
})
if err != nil {
return
}
}
conf.Logger.Info("batch close", zap.Any("payload", req)) conf.Logger.Info("batch close", zap.Any("payload", req))
return nil return
} }
func (a *AlertSvc) GetDataById(req request.DetailAlert) (resp response.AlertItem, err error) { func (a *AlertSvc) GetDataById(req request.DetailAlert) (resp response.AlertItem, err error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment