Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
so-operation-api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
smart-operation
so-operation-api
Commits
15d68474
Commit
15d68474
authored
Jul 25, 2023
by
李科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 我的预警工单
parent
00d92526
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
56 additions
and
34 deletions
+56
-34
src/bean/entity/system_user.go
src/bean/entity/system_user.go
+2
-2
src/bean/vo/request/alert.go
src/bean/vo/request/alert.go
+9
-8
src/controller/alert.go
src/controller/alert.go
+1
-0
src/controller/work_order_manage.go
src/controller/work_order_manage.go
+22
-0
src/router/alertrouter.go.go
src/router/alertrouter.go.go
+2
-1
src/router/alertrulesrouter.go.go
src/router/alertrulesrouter.go.go
+2
-1
src/router/alertwebhookrouter.go.go
src/router/alertwebhookrouter.go.go
+2
-1
src/router/metricconfigrouter.go
src/router/metricconfigrouter.go
+3
-2
src/router/workorderrouter.go
src/router/workorderrouter.go
+4
-4
src/service/alert.go
src/service/alert.go
+9
-15
No files found.
src/bean/entity/system_user.go
View file @
15d68474
...
...
@@ -25,9 +25,9 @@ type SystemUser struct {
}
type
SystemUserInfo
struct
{
Id
int
`json:"id" xorm:"pk autoincr"
`
// id
Id
int
`json:"id" xorm:"pk autoincr"
`
// id
Name
string
`json:"name" `
// 名称
SystemAccount
string
`json:"system_account"
`
// 账号
SystemAccount
string
`json:"system_account"
`
// 账号
OrganizationId
string
`json:"organization_id" xorm:"organization_id"`
// 所属组织
Password
string
`json:"password,omitempty"`
// 密码
State
int
`json:"state" xorm:"state"`
// 状态0禁用1启用
...
...
src/bean/vo/request/alert.go
View file @
15d68474
...
...
@@ -15,6 +15,7 @@ type ListAlert struct {
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:已关闭
Keyword
string
`json:"keyword" form:"keyword"`
// 预警点/分类/指标
SystemAccount
string
`json:"system_account" form:"system_account"`
// 预警推送用户
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
...
...
src/controller/alert.go
View file @
15d68474
...
...
@@ -31,6 +31,7 @@ func ListAlert(c *gin.Context) {
return
}
svc
:=
service
.
AlertSvc
{
User
:
header
.
GetUser
(
c
)}
// TODO 我的预警工单
data
,
err
:=
svc
.
List
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
...
...
src/controller/work_order_manage.go
View file @
15d68474
...
...
@@ -243,3 +243,25 @@ func ListWorkOrderMe(c *gin.Context) {
}
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
)
}
src/router/alertrouter.go.go
View file @
15d68474
...
...
@@ -5,11 +5,12 @@ import (
"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/controller"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
)
// InitAlertListRouter 初始化预警列表配置路由
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
(
"list"
,
controller
.
ListAlert
)
...
...
src/router/alertrulesrouter.go.go
View file @
15d68474
...
...
@@ -5,11 +5,12 @@ import (
"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/controller"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
)
// InitAlertRulesRouter 初始化预警规则配置路由
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
.
PUT
(
""
,
controller
.
UpdateAlertRules
)
...
...
src/router/alertwebhookrouter.go.go
View file @
15d68474
...
...
@@ -5,11 +5,12 @@ import (
"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/controller"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
)
// InitAlertWebhookRouter 初始化预警回调路由
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
)
}
...
...
src/router/metricconfigrouter.go
View file @
15d68474
...
...
@@ -5,11 +5,12 @@ import (
"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/controller"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
)
// InitMetricConfigRouter 初始化指标配置路由
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
.
PUT
(
""
,
controller
.
UpdateMetricConfig
)
...
...
@@ -18,7 +19,7 @@ func InitMetricConfigRouter(e *gin.Engine) {
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
.
PUT
(
"move/:direction"
,
controller
.
MoveAlertClass
)
...
...
src/router/workorderrouter.go
View file @
15d68474
...
...
@@ -10,12 +10,12 @@ import (
// InitWorkOrderRouter 初始化工单路由
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
.
GET
(
""
,
controller
.
DetailAlert
)
// 详情
alert
.
GET
(
"/list"
,
controller
.
ListAlert
)
// 列表
alert
.
GET
(
"/list"
,
controller
.
WorkOrderListAlert
)
// 列表
alert
.
PUT
(
"/dispose"
,
controller
.
DisposeAlert
)
// 处置反馈
}
...
...
src/service/alert.go
View file @
15d68474
...
...
@@ -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
))
}
if
req
.
SystemAccount
!=
""
{
// 匹配我的预警工单
boolQuery
.
Must
(
elastic
.
NewNestedQuery
(
"push_records"
,
elastic
.
NewTermQuery
(
"push_records.system_account"
,
req
.
SystemAccount
)))
}
querySource
,
_
:=
boolQuery
.
Source
()
b
,
_
:=
json
.
Marshal
(
querySource
)
log
.
Printf
(
"es statements: %s
\n
"
,
string
(
b
))
...
...
@@ -715,17 +720,9 @@ func (a *AlertSvc) BatchPushAlert(req request.BatchPushAlert) (err error) {
}
for
_
,
alert
:=
range
alertList
.
List
{
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
}*/
pushRecords
:=
alert
.
PushRecords
// 原始推送记录
var
phones
[]
string
for
_
,
v
:=
range
req
.
NotifyRecipients
{
for
_
,
v
:=
range
req
.
NotifyRecipients
{
// +临时推送记录
phones
=
append
(
phones
,
v
.
Phone
)
pushRecords
=
append
(
pushRecords
,
entity
.
PushRecord
{
AlertId
:
alert
.
Id
,
...
...
@@ -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
case
"sms"
:
// 发送短信
...
...
@@ -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
}
err
=
a
.
DocUpdate
(
request
.
UpdateAlert
{
...
...
@@ -793,9 +790,6 @@ func (a *AlertSvc) BatchPushAlert(req request.BatchPushAlert) (err error) {
return
}
}
// TODO 批量推送用户告警
conf
.
Logger
.
Info
(
"batch push"
,
zap
.
Any
(
"payload"
,
req
))
time
.
Sleep
(
time
.
Second
)
return
nil
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment