Commit 15d68474 authored by 李科's avatar 李科

fix: 我的预警工单

parent 00d92526
...@@ -25,9 +25,9 @@ type SystemUser struct { ...@@ -25,9 +25,9 @@ type SystemUser struct {
} }
type SystemUserInfo struct { type SystemUserInfo struct {
Id int `json:"id" xorm:"pk autoincr" ` // id Id int `json:"id" xorm:"pk autoincr"` // id
Name string `json:"name" ` // 名称 Name string `json:"name" ` // 名称
SystemAccount string `json:"system_account" ` // 账号 SystemAccount string `json:"system_account"` // 账号
OrganizationId string `json:"organization_id" xorm:"organization_id"` // 所属组织 OrganizationId string `json:"organization_id" xorm:"organization_id"` // 所属组织
Password string `json:"password,omitempty"` // 密码 Password string `json:"password,omitempty"` // 密码
State int `json:"state" xorm:"state"` // 状态0禁用1启用 State int `json:"state" xorm:"state"` // 状态0禁用1启用
......
...@@ -9,14 +9,15 @@ type DetailAlert struct { ...@@ -9,14 +9,15 @@ type DetailAlert 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"` // 预警ids Ids []int `json:"ids" form:"ids"` // 预警ids
AlertRulesId string `json:"alert_rules_id" form:"alert_rules_id"` // 告警规则id AlertRulesId string `json:"alert_rules_id" form:"alert_rules_id"` // 告警规则id
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"` // 预警点/分类/指标
StartTime string `json:"start_time" form:"start_time" binding:"omitempty,datetime=2006-01-02 15:04:05"` SystemAccount string `json:"system_account" form:"system_account"` // 预警推送用户
EndTime string `json:"end_time" form:"end_time" binding:"omitempty,datetime=2006-01-02 15:04:05"` StartTime string `json:"start_time" form:"start_time" binding:"omitempty,datetime=2006-01-02 15:04:05"`
EndTime string `json:"end_time" form:"end_time" binding:"omitempty,datetime=2006-01-02 15:04:05"`
Pagination Pagination
} }
......
...@@ -31,6 +31,7 @@ func ListAlert(c *gin.Context) { ...@@ -31,6 +31,7 @@ func ListAlert(c *gin.Context) {
return return
} }
svc := service.AlertSvc{User: header.GetUser(c)} svc := service.AlertSvc{User: header.GetUser(c)}
// TODO 我的预警工单
data, err := svc.List(req) data, err := svc.List(req)
if err != nil { if err != nil {
SendJsonResponse(c, resp.FAIL.WithError(err), nil) SendJsonResponse(c, resp.FAIL.WithError(err), nil)
......
...@@ -243,3 +243,25 @@ func ListWorkOrderMe(c *gin.Context) { ...@@ -243,3 +243,25 @@ func ListWorkOrderMe(c *gin.Context) {
} }
SendJsonPageResponse(c, resp.OK, list, total) SendJsonPageResponse(c, resp.OK, list, total)
} }
// WorkOrderListAlert 我的预警工单
func WorkOrderListAlert(c *gin.Context) {
var req request.ListAlert
if err := c.ShouldBind(&req); err != nil {
SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil)
return
}
user := header.GetUser(c)
req.SystemAccount = user.SystemAccount
if user.SystemAccount == "" {
SendJsonResponse(c, resp.FAIL.WithError(errors.New("system_account cannot be empty")), nil)
return
}
svc := service.AlertSvc{User: user}
data, err := svc.List(req)
if err != nil {
SendJsonResponse(c, resp.FAIL.WithError(err), nil)
return
}
SendJsonResponse(c, resp.OK, data)
}
...@@ -5,11 +5,12 @@ import ( ...@@ -5,11 +5,12 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
) )
// InitAlertListRouter 初始化预警列表配置路由 // InitAlertListRouter 初始化预警列表配置路由
func InitAlertListRouter(e *gin.Engine) { func InitAlertListRouter(e *gin.Engine) {
group := e.Group(fmt.Sprintf("%s/alert", conf.Options.Prefix)) group := e.Group(fmt.Sprintf("%s/alert", conf.Options.Prefix), header.SetContext)
{ {
group.GET("", controller.DetailAlert) group.GET("", controller.DetailAlert)
group.GET("list", controller.ListAlert) group.GET("list", controller.ListAlert)
......
...@@ -5,11 +5,12 @@ import ( ...@@ -5,11 +5,12 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
) )
// InitAlertRulesRouter 初始化预警规则配置路由 // InitAlertRulesRouter 初始化预警规则配置路由
func InitAlertRulesRouter(e *gin.Engine) { func InitAlertRulesRouter(e *gin.Engine) {
group := e.Group(fmt.Sprintf("%s/alert_rules", conf.Options.Prefix)) group := e.Group(fmt.Sprintf("%s/alert_rules", conf.Options.Prefix), header.SetContext)
{ {
group.POST("", controller.AddAlertRules) group.POST("", controller.AddAlertRules)
group.PUT("", controller.UpdateAlertRules) group.PUT("", controller.UpdateAlertRules)
......
...@@ -5,11 +5,12 @@ import ( ...@@ -5,11 +5,12 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
) )
// InitAlertWebhookRouter 初始化预警回调路由 // InitAlertWebhookRouter 初始化预警回调路由
func InitAlertWebhookRouter(e *gin.Engine) { func InitAlertWebhookRouter(e *gin.Engine) {
group := e.Group(fmt.Sprintf("%s/alert_webhook", conf.Options.Prefix)) group := e.Group(fmt.Sprintf("%s/alert_webhook", conf.Options.Prefix), header.SetContext)
{ {
group.POST("", controller.AlertWebhook) group.POST("", controller.AlertWebhook)
} }
......
...@@ -5,11 +5,12 @@ import ( ...@@ -5,11 +5,12 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
) )
// InitMetricConfigRouter 初始化指标配置路由 // InitMetricConfigRouter 初始化指标配置路由
func InitMetricConfigRouter(e *gin.Engine) { func InitMetricConfigRouter(e *gin.Engine) {
mcGroup := e.Group(fmt.Sprintf("%s/metric_config", conf.Options.Prefix)) mcGroup := e.Group(fmt.Sprintf("%s/metric_config", conf.Options.Prefix), header.SetContext)
{ {
mcGroup.POST("", controller.AddMetricConfig) mcGroup.POST("", controller.AddMetricConfig)
mcGroup.PUT("", controller.UpdateMetricConfig) mcGroup.PUT("", controller.UpdateMetricConfig)
...@@ -18,7 +19,7 @@ func InitMetricConfigRouter(e *gin.Engine) { ...@@ -18,7 +19,7 @@ func InitMetricConfigRouter(e *gin.Engine) {
mcGroup.GET("list", controller.ListMetricConfig) mcGroup.GET("list", controller.ListMetricConfig)
} }
acGroup := e.Group(fmt.Sprintf("%s/alert_class", conf.Options.Prefix)) acGroup := e.Group(fmt.Sprintf("%s/alert_class", conf.Options.Prefix), header.SetContext)
{ {
acGroup.POST("", controller.AddAlertClass) acGroup.POST("", controller.AddAlertClass)
acGroup.PUT("move/:direction", controller.MoveAlertClass) acGroup.PUT("move/:direction", controller.MoveAlertClass)
......
...@@ -10,13 +10,13 @@ import ( ...@@ -10,13 +10,13 @@ import (
// InitWorkOrderRouter 初始化工单路由 // InitWorkOrderRouter 初始化工单路由
func InitWorkOrderRouter(e *gin.Engine) { func InitWorkOrderRouter(e *gin.Engine) {
so := e.Group(fmt.Sprintf("%s/work_order", conf.Options.Prefix)) so := e.Group(fmt.Sprintf("%s/work_order", conf.Options.Prefix), header.SetContext)
//预警工单管理 //预警工单管理
alert := so.Group("/alert") alert := so.Group("/alert")
{ {
alert.GET("", controller.DetailAlert) // 详情 alert.GET("", controller.DetailAlert) // 详情
alert.GET("/list", controller.ListAlert) // 列表 alert.GET("/list", controller.WorkOrderListAlert) // 列表
alert.PUT("/dispose", controller.DisposeAlert) // 处置反馈 alert.PUT("/dispose", controller.DisposeAlert) // 处置反馈
} }
//业务工单管理 //业务工单管理
......
...@@ -399,6 +399,11 @@ func (a *AlertSvc) DocSearch(req request.ListAlert) (resp response.AlertList, er ...@@ -399,6 +399,11 @@ func (a *AlertSvc) DocSearch(req request.ListAlert) (resp response.AlertList, er
boolQuery.Filter(elastic.NewRangeQuery("created_at").Gte(req.StartTime).Lte(req.EndTime)) boolQuery.Filter(elastic.NewRangeQuery("created_at").Gte(req.StartTime).Lte(req.EndTime))
} }
if req.SystemAccount != "" { // 匹配我的预警工单
boolQuery.Must(elastic.NewNestedQuery("push_records", elastic.NewTermQuery("push_records.system_account", req.SystemAccount)))
}
querySource, _ := boolQuery.Source() querySource, _ := boolQuery.Source()
b, _ := json.Marshal(querySource) b, _ := json.Marshal(querySource)
log.Printf("es statements: %s\n", string(b)) log.Printf("es statements: %s\n", string(b))
...@@ -715,17 +720,9 @@ func (a *AlertSvc) BatchPushAlert(req request.BatchPushAlert) (err error) { ...@@ -715,17 +720,9 @@ func (a *AlertSvc) BatchPushAlert(req request.BatchPushAlert) (err error) {
} }
for _, alert := range alertList.List { for _, alert := range alertList.List {
pushRecords := alert.PushRecords pushRecords := alert.PushRecords // 原始推送记录
// TODO 批量推送短信
//alertRulesSvc := AlertRulesSvc{User: a.User}
/*var alertRulesItem response.AlertRulesItem
alertRulesItem, err = alertRulesSvc.GetDataById(request.DetailAlertRules{Id: alert.AlertRulesId})
if err != nil {
return
}*/
var phones []string var phones []string
for _, v := range req.NotifyRecipients { for _, v := range req.NotifyRecipients { // +临时推送记录
phones = append(phones, v.Phone) phones = append(phones, v.Phone)
pushRecords = append(pushRecords, entity.PushRecord{ pushRecords = append(pushRecords, entity.PushRecord{
AlertId: alert.Id, AlertId: alert.Id,
...@@ -745,7 +742,7 @@ func (a *AlertSvc) BatchPushAlert(req request.BatchPushAlert) (err error) { ...@@ -745,7 +742,7 @@ func (a *AlertSvc) BatchPushAlert(req request.BatchPushAlert) (err error) {
}) })
} }
for _, method := range req.NotifyMethod { for _, method := range req.NotifyMethod { // 按照通知方式循环推送
switch method { // dingtalk sms switch method { // dingtalk sms
case "sms": // 发送短信 case "sms": // 发送短信
...@@ -781,7 +778,7 @@ func (a *AlertSvc) BatchPushAlert(req request.BatchPushAlert) (err error) { ...@@ -781,7 +778,7 @@ func (a *AlertSvc) BatchPushAlert(req request.BatchPushAlert) (err error) {
} }
} }
for i := 0; i < len(pushRecords); i++ { for i := 0; i < len(pushRecords); i++ { // id重新序列化
pushRecords[i].Id = i + 1 pushRecords[i].Id = i + 1
} }
err = a.DocUpdate(request.UpdateAlert{ err = a.DocUpdate(request.UpdateAlert{
...@@ -793,9 +790,6 @@ func (a *AlertSvc) BatchPushAlert(req request.BatchPushAlert) (err error) { ...@@ -793,9 +790,6 @@ func (a *AlertSvc) BatchPushAlert(req request.BatchPushAlert) (err error) {
return return
} }
} }
// TODO 批量推送用户告警
conf.Logger.Info("batch push", zap.Any("payload", req))
time.Sleep(time.Second) time.Sleep(time.Second)
return nil return nil
} }
......
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