fix alert rule delete by service

This commit is contained in:
Ulric Qin 2022-06-01 12:58:09 +08:00
parent ab5e8c366e
commit 495632a064
3 changed files with 14 additions and 3 deletions

View File

@ -237,9 +237,13 @@ func (ar *AlertRule) DB2FE() {
json.Unmarshal([]byte(ar.AlgoParams), &ar.AlgoParamsJson) json.Unmarshal([]byte(ar.AlgoParams), &ar.AlgoParamsJson)
} }
func AlertRuleDels(ids []int64, busiGroupId int64) error { func AlertRuleDels(ids []int64, bgid ...int64) error {
for i := 0; i < len(ids); i++ { for i := 0; i < len(ids); i++ {
ret := DB().Where("id = ? and group_id=?", ids[i], busiGroupId).Delete(&AlertRule{}) session := DB().Where("id = ?", ids[i])
if len(bgid) > 0 {
session = session.Where("group_id = ?", bgid[0])
}
ret := session.Delete(&AlertRule{})
if ret.Error != nil { if ret.Error != nil {
return ret.Error return ret.Error
} }

View File

@ -278,7 +278,7 @@ func configRoute(r *gin.Engine, version string) {
service.GET("/alert-rules", alertRuleGets) service.GET("/alert-rules", alertRuleGets)
service.POST("/alert-rules", alertRuleAddByService) service.POST("/alert-rules", alertRuleAddByService)
service.DELETE("/alert-rules", alertRuleDel) service.DELETE("/alert-rules", alertRuleDelByService)
service.PUT("/alert-rule/:arid", alertRulePutByService) service.PUT("/alert-rule/:arid", alertRulePutByService)
service.GET("/alert-rule/:arid", alertRuleGet) service.GET("/alert-rule/:arid", alertRuleGet)
service.GET("/alert-rules-get-by-prod", alertRulesGetByProds) service.GET("/alert-rules-get-by-prod", alertRulesGetByProds)

View File

@ -129,6 +129,13 @@ func alertRuleDel(c *gin.Context) {
ginx.NewRender(c).Message(models.AlertRuleDels(f.Ids, ginx.UrlParamInt64(c, "id"))) ginx.NewRender(c).Message(models.AlertRuleDels(f.Ids, ginx.UrlParamInt64(c, "id")))
} }
func alertRuleDelByService(c *gin.Context) {
var f idsForm
ginx.BindJSON(c, &f)
f.Verify()
ginx.NewRender(c).Message(models.AlertRuleDels(f.Ids))
}
func alertRulePutByFE(c *gin.Context) { func alertRulePutByFE(c *gin.Context) {
var f models.AlertRule var f models.AlertRule
ginx.BindJSON(c, &f) ginx.BindJSON(c, &f)