Commit 498bfc45 authored by 李科's avatar 李科

feat: 完善批量推送逻辑

parent 0de4349f
...@@ -6,34 +6,36 @@ import ( ...@@ -6,34 +6,36 @@ import (
// Alert 预警表 // Alert 预警表
type Alert struct { type Alert struct {
Id int `json:"id"` // 预警列表ID,主键,自增长 Id int `json:"id"` // 预警列表ID,主键,自增长
AlertPoint string `json:"alert_point"` // 预警点 AlertPoint string `json:"alert_point"` // 预警点
AlertRulesId string `json:"alert_rules_id"` // 告警规则id AlertRulesId string `json:"alert_rules_id"` // 告警规则id
RiskLevel int `json:"risk_level"` // 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险 RiskLevel int `json:"risk_level"` // 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险
AlertTime jsontime.Time `json:"alert_time"` // 预警时间 AlertTime jsontime.Time `json:"alert_time"` // 预警时间
ClassId int `json:"class_id"` // 预警对象id(级联:预警分类/预警对象) ClassId int `json:"class_id"` // 预警对象id(级联:预警分类/预警对象)
ClassParentName string `json:"class_parent_name"` // 预警分类名称 TODO 该字段做关联存储或查询 ClassParentName string `json:"class_parent_name"` // 预警分类名称 TODO 该字段做关联存储或查询
ClassName string `json:"class_name"` // 预警对象名称 TODO 该字段做关联存储或查询 ClassName string `json:"class_name"` // 预警对象名称 TODO 该字段做关联存储或查询
MetricConfigId string `json:"metric_config_id"` // 预警指标id // 预警指标 MetricConfigId string `json:"metric_config_id"` // 预警指标id // 预警指标
MetricConfigName string `json:"metric_config_name"` // 预警指标名称 MetricConfigName string `json:"metric_config_name"` // 预警指标名称
AlertRuleType string `json:"alert_rule_type"` // 预警规则类型id TODO 该字段做关联存储或查询 AlertRuleType string `json:"alert_rule_type"` // 预警规则类型id TODO 该字段做关联存储或查询
AlertRuleTypeName string `json:"alert_rule_type_name"` // 预警规则类型名称 TODO 该字段做关联存储或查询 AlertRuleTypeName string `json:"alert_rule_type_name"` // 预警规则类型名称 TODO 该字段做关联存储或查询
CurrentValue float64 `json:"current_value"` // 当前报警值 CurrentValue float64 `json:"current_value"` // 当前报警值
AlertCondition string `json:"alert_condition" xorm:"'alert_condition'"` // 预警规则(预警阈值) 字典值 AlertCondition AlertCondition `json:"alert_condition" xorm:"alert_condition"`
NotificationCount int `json:"notification_count"` // 通知人数 NotificationCount int `json:"notification_count"` // 通知人数
PushCount int `json:"push_count"` // 推送次数 PushCount int `json:"push_count"` // 推送次数
LastPushTime jsontime.Time `json:"last_push_time"` // 最近推送时间 LastPushTime jsontime.Time `json:"last_push_time"` // 最近推送时间
Status int `json:"status"` // 状态,1:已恢复 2:未恢复 3:已关闭 Status int `json:"status"` // 状态,1:已恢复 2:未恢复 3:已关闭
DisposedList []DisposedList `json:"disposed_list"` // 处置列表 PushRecords []PushRecord `json:"push_records"`
IsDisposed int `json:"is_disposed"` // 是否处置(工单管理),1:已处置,2:未处置 通过DisposedList逻辑处理回显 DisposedList []DisposedList `json:"disposed_list"` // 处置列表
CloseRemark string `json:"close_remark"` // 关闭备注(预警关闭提醒) IsDisposed int `json:"is_disposed"` // 是否处置(工单管理),1:已处置,2:未处置 通过DisposedList逻辑处理回显
CloseUser string `json:"close_user"` // 关闭用户,预警关闭提醒 CloseRemark string `json:"close_remark"` // 关闭备注(预警关闭提醒)
CloseTime jsontime.Time `json:"close_time"` // 关闭关闭时间,预警关闭提醒 CloseUser string `json:"close_user"` // 关闭用户,预警关闭提醒
DeferPush int `json:"defer_push" xorm:"defer_push"` // 延迟三天推送: 0:否 1:是 三天内将不再自动推送该告警信息给处置人员,可手动推送,但告警数据依然会出现 CloseTime jsontime.Time `json:"close_time"` // 关闭关闭时间,预警关闭提醒
CreatedBy string `json:"created_by" xorm:"'created_by'"` // 创建人 DeferPush int `json:"defer_push" xorm:"defer_push"` // 延迟三天推送: 0:否 1:是 三天内将不再自动推送该告警信息给处置人员,可手动推送,但告警数据依然会出现
CreatedAt jsontime.Time `json:"created_at" xorm:"'created_at'"` // 创建时间
UpdatedBy string `json:"updated_by" xorm:"'updated_by'"` // 更新人 CreatedBy string `json:"created_by" xorm:"'created_by'"` // 创建人
UpdatedAt jsontime.Time `json:"updated_at" xorm:"'updated_at'"` // 更新时间 CreatedAt jsontime.Time `json:"created_at" xorm:"'created_at'"` // 创建时间
UpdatedBy string `json:"updated_by" xorm:"'updated_by'"` // 更新人
UpdatedAt jsontime.Time `json:"updated_at" xorm:"'updated_at'"` // 更新时间
} }
type DisposedList struct { type DisposedList struct {
...@@ -43,6 +45,12 @@ type DisposedList struct { ...@@ -43,6 +45,12 @@ type DisposedList struct {
DisposalTime jsontime.Time `json:"disposal_time"` // 处置时间(工单管理,结果反馈) DisposalTime jsontime.Time `json:"disposal_time"` // 处置时间(工单管理,结果反馈)
} }
type OpenSearchIds struct {
Ids struct {
Values []string `json:"values"`
} `json:"ids"`
}
func (a *Alert) TableName() string { func (a *Alert) TableName() string {
return "alert" return "alert"
} }
...@@ -7,11 +7,13 @@ type PushRecord struct { ...@@ -7,11 +7,13 @@ type PushRecord struct {
AlertId int `json:"alert_id" xorm:"alert_id"` // 告警id AlertId int `json:"alert_id" xorm:"alert_id"` // 告警id
AlertRulesId string `json:"alert_rules_id" xorm:"'alert_rules_id'"` // 告警规则id AlertRulesId string `json:"alert_rules_id" xorm:"'alert_rules_id'"` // 告警规则id
RiskLevel int `json:"risk_level" xorm:"'risk_level'"` // 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险 RiskLevel int `json:"risk_level" xorm:"'risk_level'"` // 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险
NotifyMethod string `json:"notify_method" xorm:"'notify_method'"` // 预警通知方式 dingtalk sms NotifyMethod []string `json:"notify_method" xorm:"notify_method"` // 预警通知方式 dingtalk sms
SystemAccount string `json:"system_account" xorm:"system_account"` // 预警推送用户 SystemAccount string `json:"system_account" xorm:"system_account"` // 预警推送用户
PushTime jsontime.Time `json:"push_time" xorm:"'push_time'"` // 推送时间 PushTime jsontime.Time `json:"push_time" xorm:"'push_time'"` // 推送时间
PushType int `json:"push_type" xorm:"'push_type'"` // 推送类型,1:自动推送,2:手动推送 PushType int `json:"push_type" xorm:"'push_type'"` // 推送类型,1:自动推送,2:手动推送
Status int `json:"status" xorm:"'status'"` // 推送状态,1:成功,2:失败 Status int `json:"status" xorm:"'status'"` // 推送状态,1:成功,2:失败
UserName string `json:"user_name" xorm:"user_name"` // 推送用户名称
Phone string `json:"phone" xorm:"phone"` // 推送手机号
CreatedBy string `json:"created_by" xorm:"'created_by'"` // 创建人 CreatedBy string `json:"created_by" xorm:"'created_by'"` // 创建人
CreatedAt jsontime.Time `json:"created_at" xorm:"'created_at'"` // 创建时间 CreatedAt jsontime.Time `json:"created_at" xorm:"'created_at'"` // 创建时间
UpdatedBy string `json:"updated_by" xorm:"'updated_by'"` // 更新人 UpdatedBy string `json:"updated_by" xorm:"'updated_by'"` // 更新人
......
...@@ -11,11 +11,12 @@ type DetailAlert struct { ...@@ -11,11 +11,12 @@ 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 []int `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:重大风险
Status int `json:"status" form:"status" binding:"omitempty,oneof=1 2 3"` // 状态,1:已恢复 2:未恢复 3:已关闭 Status int `json:"status" form:"status" binding:"omitempty,oneof=1 2 3"` // 状态,1:已恢复 2:未恢复 3:已关闭
DisposalContent string `json:"disposal_content" form:"disposal_content"` // 处置内容(工单管理,结果反馈) DisposalContent string `json:"disposal_content" form:"disposal_content"` // 处置内容(工单管理,结果反馈)
PushRecords []entity.PushRecord `json:"push_records" form:"push_records"`
} }
type BatchPushAlert struct { type BatchPushAlert struct {
...@@ -34,6 +35,7 @@ type BatchCloseAlert struct { ...@@ -34,6 +35,7 @@ type BatchCloseAlert struct {
type ListAlert struct { type ListAlert struct {
Id int `json:"id" form:"id"` Id int `json:"id" form:"id"`
Ids []int `json:"ids" form:"ids" binding:"required_without=Id"` // 预警ids
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:重大风险
Status int `json:"status" form:"status" binding:"omitempty,oneof=1 2 3"` // 状态,1:已恢复 2:未恢复 3:已关闭 Status int `json:"status" form:"status" binding:"omitempty,oneof=1 2 3"` // 状态,1:已恢复 2:未恢复 3:已关闭
Keyword string `json:"keyword" form:"keyword"` // 预警点/分类/指标 Keyword string `json:"keyword" form:"keyword"` // 预警点/分类/指标
......
...@@ -5,9 +5,7 @@ import ( ...@@ -5,9 +5,7 @@ import (
) )
type AlertItem struct { type AlertItem struct {
entity.Alert `xorm:"extends"` entity.Alert `xorm:"extends"`
AlertCondition entity.AlertCondition `json:"alert_condition" xorm:"alert_condition"`
PushRecords []PushRecordItem `json:"push_records"`
} }
type AlertList struct { type AlertList struct {
......
...@@ -4,7 +4,6 @@ import "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity" ...@@ -4,7 +4,6 @@ import "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
type PushRecordItem struct { type PushRecordItem struct {
entity.PushRecord `xorm:"extends"` entity.PushRecord `xorm:"extends"`
NotifyMethod []string `json:"notify_method" xorm:"notify_method"` // 预警通知方式 dingtalk sms
} }
type PushRecordList struct { type PushRecordList struct {
......
...@@ -3,7 +3,6 @@ package controller ...@@ -3,7 +3,6 @@ package controller
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/service" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
...@@ -33,12 +32,7 @@ func BatchPushAlert(c *gin.Context) { ...@@ -33,12 +32,7 @@ func BatchPushAlert(c *gin.Context) {
} }
svc := service.AlertSvc{User: header.GetUser(c)} svc := service.AlertSvc{User: header.GetUser(c)}
db, err := client.GetDbClient() err := svc.BatchPushAlert(req)
if err != nil {
SendJsonResponse(c, resp.DbConnectError.WithError(err), nil)
return
}
err = svc.BatchPushAlert(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
......
This diff is collapsed.
...@@ -49,8 +49,10 @@ func (m *PushRecordSvc) GetDataById(req request.DetailPushRecord) (resp response ...@@ -49,8 +49,10 @@ func (m *PushRecordSvc) GetDataById(req request.DetailPushRecord) (resp response
data := response.PushRecordItem{ data := response.PushRecordItem{
PushRecord: entity.PushRecord{ PushRecord: entity.PushRecord{
Id: 1, Id: 1,
AlertId: 1,
AlertRulesId: "83343ef6-4a99-47bd-abb4-bcff52feb2ec", AlertRulesId: "83343ef6-4a99-47bd-abb4-bcff52feb2ec",
RiskLevel: 1, RiskLevel: 1,
NotifyMethod: []string{"dingtalk", "sms"},
SystemAccount: "xiaowang", SystemAccount: "xiaowang",
PushTime: now, PushTime: now,
PushType: 1, PushType: 1,
...@@ -60,7 +62,6 @@ func (m *PushRecordSvc) GetDataById(req request.DetailPushRecord) (resp response ...@@ -60,7 +62,6 @@ func (m *PushRecordSvc) GetDataById(req request.DetailPushRecord) (resp response
UpdatedBy: "admin", UpdatedBy: "admin",
UpdatedAt: now, UpdatedAt: now,
}, },
NotifyMethod: []string{"dingtalk", "sms"},
} }
resp = data resp = data
return return
...@@ -81,8 +82,8 @@ func (m *PushRecordSvc) List(req request.ListPushRecord) (resp response.PushReco ...@@ -81,8 +82,8 @@ func (m *PushRecordSvc) List(req request.ListPushRecord) (resp response.PushReco
CreatedAt: now, CreatedAt: now,
UpdatedBy: "admin", UpdatedBy: "admin",
UpdatedAt: now, UpdatedAt: now,
NotifyMethod: []string{"dingtalk", "sms"},
}, },
NotifyMethod: []string{"dingtalk", "sms"},
} }
data2 := response.PushRecordItem{ data2 := response.PushRecordItem{
PushRecord: entity.PushRecord{ PushRecord: entity.PushRecord{
...@@ -97,8 +98,8 @@ func (m *PushRecordSvc) List(req request.ListPushRecord) (resp response.PushReco ...@@ -97,8 +98,8 @@ func (m *PushRecordSvc) List(req request.ListPushRecord) (resp response.PushReco
CreatedAt: now, CreatedAt: now,
UpdatedBy: "admin", UpdatedBy: "admin",
UpdatedAt: now, UpdatedAt: now,
NotifyMethod: []string{"dingtalk", "sms"},
}, },
NotifyMethod: []string{"dingtalk", "sms"},
} }
resp.List = append(resp.List, data1, data2) resp.List = append(resp.List, data1, data2)
resp.TotalCount = int64(len(resp.List)) resp.TotalCount = int64(len(resp.List))
......
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