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

feat: 完善批量关闭预警

parent d3cc2651
......@@ -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 {
......
......@@ -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
......
......@@ -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) {
......
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