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
4cbae66d
Commit
4cbae66d
authored
Jun 29, 2023
by
李科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 预警分类
parent
a66408fb
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
432 additions
and
27 deletions
+432
-27
src/bean/entity/alert_class.go
src/bean/entity/alert_class.go
+18
-0
src/bean/vo/request/alert_class.go
src/bean/vo/request/alert_class.go
+31
-0
src/bean/vo/request/metric_config.go
src/bean/vo/request/metric_config.go
+14
-6
src/bean/vo/response/alert_class.go
src/bean/vo/response/alert_class.go
+12
-0
src/bean/vo/response/metric_config.go
src/bean/vo/response/metric_config.go
+1
-1
src/controller/alert_class.go
src/controller/alert_class.go
+107
-0
src/controller/metric_config.go
src/controller/metric_config.go
+30
-13
src/router/metricconfigrouter.go
src/router/metricconfigrouter.go
+16
-5
src/service/alert_class.go
src/service/alert_class.go
+177
-0
src/service/metric_config.go
src/service/metric_config.go
+26
-2
No files found.
src/bean/entity/alert_class.go
0 → 100644
View file @
4cbae66d
package
entity
import
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
type
AlertClass
struct
{
ClassId
int
`json:"class_id" xorm:"'class_id' pk autoincr" `
// 主键id
ClassName
string
`json:"class_name" xorm:"'class_name'"`
// 分类名称
ParentId
int
`json:"parent_id" xorm:"'parent_id'"`
// 父级id
SortOrder
int
`json:"sort_order" xorm:"'sort_order'"`
// 排序
CreatedBy
string
`json:"created_by" xorm:"'created_by'"`
// 创建人
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'"`
// 更新时间
}
func
(
m
*
AlertClass
)
TableName
()
string
{
return
"alert_class"
}
src/bean/vo/request/alert_class.go
0 → 100644
View file @
4cbae66d
package
request
type
AddAlertClass
struct
{
ClassName
string
`json:"class_name" form:"class_name" binding:"required"`
ParentId
int
`json:"parent_id" form:"parent_id" binding:"omitempty"`
SortOrder
int
`json:"sort_order" form:"sort_order"`
}
type
UpdateAlertClass
struct
{
ClassId
int
`json:"class_id" form:"class_id" binding:"required"`
ClassName
string
`json:"class_name" form:"class_name" binding:"required"`
}
type
DeleteAlertClass
struct
{
ClassId
int
`json:"class_id" form:"class_id" binding:"required"`
}
type
MoveAlertClass
struct
{
ClassId
int
`json:"class_id" form:"class_id" binding:"required"`
Direction
string
`json:"direction" form:"direction" binding:"oneof=up down"`
}
type
DetailAlertClass
struct
{
ClassId
int
`json:"class_id" form:"class_id" binding:"required"`
}
type
ListAlertClass
struct
{
ClassId
int
`json:"class_id" form:"class_id"`
ClassName
string
`json:"class_name" form:"class_name"`
Pagination
}
src/bean/vo/request/metric_config.go
View file @
4cbae66d
...
...
@@ -10,7 +10,7 @@ type AddMetricConfig struct {
Duration
int
`json:"duration" form:"duration"`
// 持续时间
DurationUnit
string
`json:"duration_unit" form:"duration_unit" binding:"required"`
// 持续时间单位 s m h
CheckPeriod
int
`json:"check_period" form:"check_period" binding:"oneof=1 3 5 10 20 30"`
// 检查周期 单位:分钟
IsEnabled
int
`json:"is_enabled" form:"is_enabled"
`
// 是否开启 0:关闭 1:启动
IsEnabled
int
`json:"is_enabled" form:"is_enabled"
binding:"oneof=0 1 2"`
// 是否开启 1:启动 2:停用
AlertRuleType
string
`json:"alert_rule_type" form:"alert_rule_type" binding:"required"`
// 预警规则类型 关联字典表
}
...
...
@@ -23,14 +23,22 @@ type UpdateMetricConfig struct {
Duration
int
`json:"duration" form:"duration"`
// 持续时间
DurationUnit
string
`json:"duration_unit" form:"duration_unit" binding:"required"`
// 持续时间单位 s m h
CheckPeriod
int
`json:"check_period" form:"check_period" binding:"oneof=1 3 5 10 20 30"`
// 检查周期 单位:分钟
IsEnabled
int
`json:"is_enabled" form:"is_enabled"
`
// 是否开启 0:关闭 1:启动
IsEnabled
int
`json:"is_enabled" form:"is_enabled"
binding:"oneof=0 1 2"`
// 是否开启 1:启动 2:停用
AlertRuleType
string
`json:"alert_rule_type" form:"alert_rule_type" binding:"required"`
// 预警规则类型 关联字典表
}
type
Get
MetricConfig
struct
{
Id
string
`json:"id" form:"id" binding:"required"`
// 主键id
type
Delete
MetricConfig
struct
{
Id
string
`json:"id" form:"id" binding:"required"`
}
type
DeleteMetricConfig
struct
{
Id
string
`json:"id" form:"id" binding:"required"`
// 主键id
type
DetailMetricConfig
struct
{
Id
string
`json:"id" form:"id" binding:"required"`
}
type
ListMetricConfig
struct
{
Id
string
`json:"id" form:"id"`
ClassId
int
`json:"class_id" form:"class_id"`
MetricName
string
`json:"metric_name" form:"metric_name"`
IsEnabled
int
`json:"is_enabled" form:"is_enabled" binding:"omitempty,oneof=0 1 2"`
Pagination
}
src/bean/vo/response/alert_class.go
0 → 100644
View file @
4cbae66d
package
response
import
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
type
AlertClassItem
struct
{
entity
.
AlertClass
`xorm:"extends"`
}
type
AlertClassList
struct
{
TotalCount
int64
`json:"total_count"`
List
[]
AlertClassItem
`json:"list"`
}
src/bean/vo/response/metric_config.go
View file @
4cbae66d
...
...
@@ -8,6 +8,6 @@ type MetricConfigItem struct {
}
type
UnitsList
struct
{
TotalCount
int
`json:"total_count"`
TotalCount
int
64
`json:"total_count"`
List
[]
MetricConfigItem
`json:"list"`
}
src/controller/alert_class.go
0 → 100644
View file @
4cbae66d
package
controller
import
(
"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/pkg/beagle/resp"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
)
// AddAlertClass 新增任务
func
AddAlertClass
(
c
*
gin
.
Context
)
{
var
req
request
.
AddAlertClass
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
svc
:=
service
.
AlertClassSvc
{
User
:
header
.
GetUser
(
c
)}
err
:=
svc
.
Add
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
nil
)
}
func
UpdateAlertClass
(
c
*
gin
.
Context
)
{
var
req
request
.
UpdateAlertClass
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
svc
:=
service
.
AlertClassSvc
{
User
:
header
.
GetUser
(
c
)}
err
:=
svc
.
Update
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
nil
)
}
func
MoveAlertClass
(
c
*
gin
.
Context
)
{
direction
:=
c
.
Param
(
"direction"
)
req
:=
request
.
MoveAlertClass
{
Direction
:
direction
,
}
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
svc
:=
service
.
AlertClassSvc
{
User
:
header
.
GetUser
(
c
)}
err
:=
svc
.
Move
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
nil
)
}
func
DetailAlertClass
(
c
*
gin
.
Context
)
{
var
req
request
.
DetailAlertClass
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
svc
:=
service
.
AlertClassSvc
{
User
:
header
.
GetUser
(
c
)}
data
,
err
:=
svc
.
GetDataById
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
data
)
}
func
ListAlertClass
(
c
*
gin
.
Context
)
{
var
req
request
.
ListAlertClass
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
svc
:=
service
.
AlertClassSvc
{
User
:
header
.
GetUser
(
c
)}
data
,
err
:=
svc
.
List
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
data
)
}
func
DeleteAlertClass
(
c
*
gin
.
Context
)
{
var
req
request
.
DeleteAlertClass
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
svc
:=
service
.
AlertClassSvc
{
User
:
header
.
GetUser
(
c
)}
err
:=
svc
.
DeleteDataById
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
nil
)
}
src/controller/metric_config.go
View file @
4cbae66d
...
...
@@ -4,6 +4,7 @@ import (
"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/pkg/beagle/resp"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
)
...
...
@@ -15,10 +16,10 @@ func AddMetricConfig(c *gin.Context) {
return
}
svc
:=
service
.
MetricConfigSvc
{}
svc
:=
service
.
MetricConfigSvc
{
User
:
header
.
GetUser
(
c
)
}
err
:=
svc
.
Add
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
err
,
nil
)
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
)
,
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
nil
)
...
...
@@ -31,43 +32,59 @@ func UpdateMetricConfig(c *gin.Context) {
return
}
svc
:=
service
.
MetricConfigSvc
{}
svc
:=
service
.
MetricConfigSvc
{
User
:
header
.
GetUser
(
c
)
}
err
:=
svc
.
Update
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
err
,
nil
)
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
nil
)
}
func
DeleteMetricConfig
(
c
*
gin
.
Context
)
{
var
req
request
.
DeleteMetricConfig
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
svc
:=
service
.
MetricConfigSvc
{
User
:
header
.
GetUser
(
c
)}
err
:=
svc
.
DeleteDataById
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
nil
)
}
func
DetailMetricConfig
(
c
*
gin
.
Context
)
{
var
req
request
.
Get
MetricConfig
var
req
request
.
Detail
MetricConfig
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
svc
:=
service
.
MetricConfigSvc
{}
svc
:=
service
.
MetricConfigSvc
{
User
:
header
.
GetUser
(
c
)
}
data
,
err
:=
svc
.
GetDataById
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
err
,
nil
)
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
)
,
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
data
)
}
func
Delete
MetricConfig
(
c
*
gin
.
Context
)
{
var
req
request
.
Delete
MetricConfig
func
List
MetricConfig
(
c
*
gin
.
Context
)
{
var
req
request
.
List
MetricConfig
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
svc
:=
service
.
MetricConfigSvc
{}
err
:=
svc
.
DeleteDataById
(
req
)
svc
:=
service
.
MetricConfigSvc
{
User
:
header
.
GetUser
(
c
)
}
data
,
err
:=
svc
.
List
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
err
,
nil
)
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
)
,
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
nil
)
SendJsonResponse
(
c
,
resp
.
OK
,
data
)
}
src/router/metricconfigrouter.go
View file @
4cbae66d
...
...
@@ -9,11 +9,22 @@ import (
// InitMetricConfigRouter 初始化指标配置路由
func
InitMetricConfigRouter
(
e
*
gin
.
Engine
)
{
base
:=
e
.
Group
(
fmt
.
Sprintf
(
"%s/metric_config"
,
conf
.
Options
.
Prefix
))
mcGroup
:=
e
.
Group
(
fmt
.
Sprintf
(
"%s/metric_config"
,
conf
.
Options
.
Prefix
))
{
base
.
POST
(
""
,
controller
.
AddMetricConfig
)
base
.
PUT
(
""
,
controller
.
UpdateMetricConfig
)
base
.
GET
(
""
,
controller
.
DetailMetricConfig
)
base
.
DELETE
(
""
,
controller
.
DeleteMetricConfig
)
mcGroup
.
POST
(
""
,
controller
.
AddMetricConfig
)
mcGroup
.
PUT
(
""
,
controller
.
UpdateMetricConfig
)
mcGroup
.
DELETE
(
""
,
controller
.
DeleteMetricConfig
)
mcGroup
.
GET
(
""
,
controller
.
DetailMetricConfig
)
mcGroup
.
GET
(
"list"
,
controller
.
ListMetricConfig
)
}
acGroup
:=
e
.
Group
(
fmt
.
Sprintf
(
"%s/alert_class"
,
conf
.
Options
.
Prefix
))
{
acGroup
.
POST
(
""
,
controller
.
AddAlertClass
)
acGroup
.
PUT
(
"move/:direction"
,
controller
.
MoveAlertClass
)
acGroup
.
PUT
(
""
,
controller
.
UpdateAlertClass
)
acGroup
.
DELETE
(
""
,
controller
.
DeleteAlertClass
)
acGroup
.
GET
(
""
,
controller
.
DetailAlertClass
)
acGroup
.
GET
(
"list"
,
controller
.
ListAlertClass
)
}
}
src/service/alert_class.go
0 → 100644
View file @
4cbae66d
package
service
import
(
"errors"
"github.com/jinzhu/copier"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/response"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
)
type
AlertClassSvc
struct
{
User
entity
.
SystemUserInfo
}
func
(
m
*
AlertClassSvc
)
Add
(
req
request
.
AddAlertClass
)
(
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
err
=
resp
.
DbConnectError
.
WithError
(
err
)
return
err
}
now
:=
jsontime
.
Now
()
data
:=
entity
.
AlertClass
{
CreatedBy
:
""
,
CreatedAt
:
now
,
UpdatedBy
:
""
,
UpdatedAt
:
now
,
}
_
=
copier
.
Copy
(
&
data
,
&
req
)
max
,
err
:=
m
.
SortOrderMax
(
data
.
ParentId
)
if
err
!=
nil
{
return
}
data
.
SortOrder
=
max
+
1
_
,
err
=
db
.
NewSession
()
.
Insert
(
&
data
)
return
nil
}
func
(
m
*
AlertClassSvc
)
Update
(
req
request
.
UpdateAlertClass
)
error
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
err
=
resp
.
DbConnectError
.
WithError
(
err
)
return
err
}
now
:=
jsontime
.
Now
()
data
:=
entity
.
AlertClass
{
UpdatedBy
:
""
,
UpdatedAt
:
now
,
}
_
=
copier
.
Copy
(
&
data
,
&
req
)
_
,
err
=
db
.
NewSession
()
.
Cols
(
"class_name"
,
"updated_by"
,
"updated_at"
)
.
ID
(
data
.
ClassId
)
.
Update
(
&
data
)
if
err
!=
nil
{
return
err
}
return
nil
}
func
(
m
*
AlertClassSvc
)
Move
(
req
request
.
MoveAlertClass
)
(
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
err
=
resp
.
DbConnectError
.
WithError
(
err
)
return
err
}
now
:=
jsontime
.
Now
()
data
:=
entity
.
AlertClass
{
UpdatedBy
:
""
,
UpdatedAt
:
now
,
}
_
=
copier
.
Copy
(
&
data
,
&
req
)
var
list
[]
entity
.
AlertClass
_
,
err
=
db
.
NewSession
()
.
Where
(
"id = ?"
,
req
.
ClassId
)
.
Get
(
&
data
)
err
=
db
.
NewSession
()
.
Where
(
"parent_id = ?"
,
data
.
ParentId
)
.
OrderBy
(
"sort_order asc"
)
.
Find
(
&
list
)
var
previousIndex
int
var
nextIndex
int
for
i
:=
0
;
i
<
len
(
list
);
i
++
{
if
list
[
i
]
.
ClassId
==
req
.
ClassId
{
previousIndex
=
i
-
1
nextIndex
=
i
+
1
break
}
}
var
(
mover
entity
.
AlertClass
moved
entity
.
AlertClass
)
switch
req
.
Direction
{
case
"up"
:
if
previousIndex
<
0
{
err
=
errors
.
New
(
"top data cannot be moved"
)
return
}
list
[
previousIndex
]
.
SortOrder
,
list
[
previousIndex
+
1
]
.
SortOrder
=
list
[
previousIndex
+
1
]
.
SortOrder
,
list
[
previousIndex
]
.
SortOrder
mover
,
moved
=
list
[
previousIndex
+
1
],
list
[
previousIndex
]
case
"down"
:
if
nextIndex
>
len
(
list
)
-
1
{
err
=
errors
.
New
(
"bottom data cannot be moved"
)
return
}
list
[
nextIndex
-
1
]
.
SortOrder
,
list
[
nextIndex
]
.
SortOrder
=
list
[
nextIndex
]
.
SortOrder
,
list
[
nextIndex
-
1
]
.
SortOrder
mover
,
moved
=
list
[
nextIndex
-
1
],
list
[
nextIndex
]
}
mover
.
UpdatedBy
,
moved
.
UpdatedBy
=
""
,
""
mover
.
UpdatedAt
,
moved
.
UpdatedAt
=
now
,
now
session
:=
db
.
NewSession
()
defer
session
.
Close
()
err
=
session
.
Begin
()
_
,
err
=
session
.
Cols
(
"sort_order"
,
"updated_by"
,
"updated_at"
)
.
ID
(
mover
.
ClassId
)
.
Update
(
&
mover
)
if
err
!=
nil
{
err
=
session
.
Rollback
()
return
}
_
,
err
=
session
.
Cols
(
"sort_order"
,
"updated_by"
,
"updated_at"
)
.
ID
(
moved
.
ClassId
)
.
Update
(
&
moved
)
if
err
!=
nil
{
err
=
session
.
Rollback
()
return
}
err
=
session
.
Commit
()
if
err
!=
nil
{
return
}
return
nil
}
func
(
m
*
AlertClassSvc
)
GetDataById
(
req
request
.
DetailAlertClass
)
(
resp
response
.
AlertClassItem
,
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
return
}
_
,
err
=
db
.
NewSession
()
.
Table
(
resp
.
TableName
())
.
ID
(
req
.
ClassId
)
.
Get
(
&
resp
)
return
}
func
(
m
*
AlertClassSvc
)
List
(
req
request
.
ListAlertClass
)
(
resp
response
.
AlertClassList
,
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
return
}
session
:=
db
.
NewSession
()
defer
session
.
Close
()
if
req
.
ClassId
!=
0
{
session
.
Where
(
"class_id = ?"
,
req
.
ClassId
)
}
if
req
.
ClassName
!=
""
{
session
.
Where
(
"class_name LIKE ?"
,
"%"
+
req
.
ClassName
+
"%"
)
}
resp
.
TotalCount
,
err
=
session
.
Limit
(
req
.
GetPageSize
(),
(
req
.
GetPage
()
-
1
)
*
req
.
GetPageSize
())
.
OrderBy
(
"sort_order"
)
.
FindAndCount
(
&
resp
.
List
)
return
}
func
(
m
*
AlertClassSvc
)
SortOrderMax
(
parentId
int
)
(
max
int
,
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
return
}
_
,
err
=
db
.
NewSession
()
.
Table
(
new
(
entity
.
AlertClass
))
.
Select
(
"max(sort_order)"
)
.
Where
(
"parent_id = ?"
,
parentId
)
.
Get
(
&
max
)
return
}
func
(
m
*
AlertClassSvc
)
DeleteDataById
(
req
request
.
DeleteAlertClass
)
(
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
return
}
_
,
err
=
db
.
NewSession
()
.
ID
(
req
.
ClassId
)
.
Delete
(
&
entity
.
AlertClass
{})
return
}
src/service/metric_config.go
View file @
4cbae66d
...
...
@@ -13,7 +13,7 @@ import (
)
type
MetricConfigSvc
struct
{
User
*
entity
.
SystemUser
User
entity
.
SystemUserInfo
}
func
(
m
*
MetricConfigSvc
)
Add
(
req
request
.
AddMetricConfig
)
error
{
...
...
@@ -61,7 +61,7 @@ func (m *MetricConfigSvc) Update(req request.UpdateMetricConfig) error {
return
nil
}
func
(
m
*
MetricConfigSvc
)
GetDataById
(
req
request
.
Get
MetricConfig
)
(
resp
response
.
MetricConfigItem
,
err
error
)
{
func
(
m
*
MetricConfigSvc
)
GetDataById
(
req
request
.
Detail
MetricConfig
)
(
resp
response
.
MetricConfigItem
,
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
return
...
...
@@ -70,6 +70,30 @@ func (m *MetricConfigSvc) GetDataById(req request.GetMetricConfig) (resp respons
return
}
func
(
m
*
MetricConfigSvc
)
List
(
req
request
.
ListMetricConfig
)
(
resp
response
.
UnitsList
,
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
return
}
session
:=
db
.
NewSession
()
defer
session
.
Close
()
if
req
.
Id
!=
""
{
session
.
Where
(
"id = ?"
,
req
.
Id
)
}
if
req
.
ClassId
!=
0
{
session
.
Where
(
"class_id = ?"
,
req
.
ClassId
)
}
if
req
.
MetricName
!=
""
{
session
.
Where
(
"class_name LIKE ?"
,
"%"
+
req
.
MetricName
+
"%"
)
}
if
req
.
IsEnabled
!=
0
{
session
.
Where
(
"is_enabled = ?"
,
req
.
IsEnabled
)
}
resp
.
TotalCount
,
err
=
session
.
Limit
(
req
.
GetPageSize
(),
(
req
.
GetPage
()
-
1
)
*
req
.
GetPageSize
())
.
OrderBy
(
"id"
)
.
FindAndCount
(
&
resp
.
List
)
return
}
func
(
m
*
MetricConfigSvc
)
DeleteDataById
(
req
request
.
DeleteMetricConfig
)
(
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
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