Commit 0e483ac4 authored by 李科's avatar 李科

fix: 指标配置&预警分类批量删除

parent 3d21bfb3
......@@ -12,7 +12,8 @@ type UpdateAlertClass struct {
}
type DeleteAlertClass struct {
ClassId int `json:"class_id" form:"class_id" binding:"required"`
ClassId int `json:"class_id" form:"class_id"`
ClassIds []int `json:"class_ids" form:"class_ids" binding:"required_without=ClassId"`
}
type MoveAlertClass struct {
......
......@@ -28,7 +28,8 @@ type UpdateMetricConfig struct {
}
type DeleteMetricConfig struct {
Id string `json:"id" form:"id" binding:"required"`
Id string `json:"id" form:"id"`
Ids []string `json:"ids" form:"ids" binding:"required_without=Id"`
}
type DetailMetricConfig struct {
......
......@@ -111,9 +111,16 @@ func DeleteAlertClass(c *gin.Context) {
SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil)
return
}
var ids []int
switch len(req.ClassIds) {
case 0:
ids = append(ids, req.ClassId)
default:
ids = req.ClassIds
}
svc := service.AlertClassSvc{User: header.GetUser(c)}
err := svc.DeleteDataById(req)
err := svc.Delete(ids)
if err != nil {
SendJsonResponse(c, resp.FAIL.WithError(err), nil)
return
......
......@@ -48,8 +48,16 @@ func DeleteMetricConfig(c *gin.Context) {
return
}
var ids []string
switch len(req.Ids) {
case 0:
ids = append(ids, req.Id)
default:
ids = req.Ids
}
svc := service.MetricConfigSvc{User: header.GetUser(c)}
err := svc.DeleteDataById(req)
err := svc.Delete(ids)
if err != nil {
SendJsonResponse(c, resp.FAIL.WithError(err), nil)
return
......
......@@ -218,11 +218,11 @@ func (m *AlertClassSvc) SortOrderMax(parentId int) (max int, err error) {
return
}
func (m *AlertClassSvc) DeleteDataById(req request.DeleteAlertClass) (err error) {
func (m *AlertClassSvc) Delete(ids []int) (err error) {
db, err := client.GetDbClient()
if err != nil {
return
}
_, err = db.NewSession().ID(req.ClassId).Delete(&entity.AlertClass{})
_, err = db.NewSession().In("class_id", ids).Delete(&entity.AlertClass{})
return
}
......@@ -94,11 +94,11 @@ func (m *MetricConfigSvc) List(req request.ListMetricConfig) (resp response.Unit
return
}
func (m *MetricConfigSvc) DeleteDataById(req request.DeleteMetricConfig) (err error) {
func (m *MetricConfigSvc) Delete(ids []string) (err error) {
db, err := client.GetDbClient()
if err != nil {
return
}
_, err = db.NewSession().Where("id = ?", req.Id).Delete(&entity.MetricConfig{})
_, err = db.NewSession().In("id", ids).Delete(new(entity.MetricConfig))
return
}
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