From afb01b0258c852efe75e81d59dfdfb4cdc9217ab Mon Sep 17 00:00:00 2001 From: 710leo <710leo@gmail.com> Date: Thu, 26 Aug 2021 11:03:32 +0800 Subject: [PATCH] fix: batch update alert rule --- http/router_alert_rule.go | 8 ++++---- models/alert_rule.go | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/http/router_alert_rule.go b/http/router_alert_rule.go index 3953922a..83d5fba0 100644 --- a/http/router_alert_rule.go +++ b/http/router_alert_rule.go @@ -164,7 +164,7 @@ func alertRuleStatusPut(c *gin.Context) { alertRuleWritePermCheck(arg, me) } - renderMessage(c, models.AlertRuleUpdateStatus(f.Ids, f.Status)) + renderMessage(c, models.AlertRuleUpdateStatus(f.Ids, f.Status, me.Username)) } type alertRuleNotifyGroupsForm struct { @@ -189,7 +189,7 @@ func alertRuleNotifyGroupsPut(c *gin.Context) { alertRuleWritePermCheck(arg, me) } - renderMessage(c, models.AlertRuleUpdateNotifyGroups(f.Ids, f.NotifyGroups, f.NotifyUsers)) + renderMessage(c, models.AlertRuleUpdateNotifyGroups(f.Ids, f.NotifyGroups, f.NotifyUsers, me.Username)) } type alertRuleNotifyChannelsForm struct { @@ -211,7 +211,7 @@ func alertRuleNotifyChannelsPut(c *gin.Context) { alertRuleWritePermCheck(arg, me) } - renderMessage(c, models.AlertRuleUpdateNotifyChannels(f.Ids, f.NotifyChannels)) + renderMessage(c, models.AlertRuleUpdateNotifyChannels(f.Ids, f.NotifyChannels, me.Username)) } type alertRuleAppendTagsForm struct { @@ -233,7 +233,7 @@ func alertRuleAppendTagsPut(c *gin.Context) { alertRuleWritePermCheck(arg, me) } - renderMessage(c, models.AlertRuleUpdateAppendTags(f.Ids, f.AppendTags)) + renderMessage(c, models.AlertRuleUpdateAppendTags(f.Ids, f.AppendTags, me.Username)) } func alertRuleDel(c *gin.Context) { diff --git a/models/alert_rule.go b/models/alert_rule.go index fd49224b..8d08f082 100644 --- a/models/alert_rule.go +++ b/models/alert_rule.go @@ -291,23 +291,23 @@ func (ar *AlertRule) Update(cols ...string) error { return nil } -func AlertRuleUpdateStatus(ids []int64, status int) error { - _, err := DB.Exec("UPDATE alert_rule SET status=? WHERE id in ("+str.IdsString(ids)+")", status) +func AlertRuleUpdateStatus(ids []int64, status int, username string) error { + _, err := DB.Exec("UPDATE alert_rule SET status=?, update_at=?, update_by=? WHERE id in ("+str.IdsString(ids)+")", status, time.Now().Unix(), username) return err } -func AlertRuleUpdateNotifyGroups(ids []int64, notifyGroups string, notifyUsers string) error { - _, err := DB.Exec("UPDATE alert_rule SET notify_groups = ? , notify_users = ? where id in ("+str.IdsString(ids)+")", notifyGroups, notifyUsers) +func AlertRuleUpdateNotifyGroups(ids []int64, notifyGroups, notifyUsers, username string) error { + _, err := DB.Exec("UPDATE alert_rule SET notify_groups = ? , notify_users = ?, update_at = ?, update_by = ? where id in ("+str.IdsString(ids)+")", notifyGroups, notifyUsers, time.Now().Unix(), username) return err } -func AlertRuleUpdateNotifyChannels(ids []int64, notifyChannels string) error { - _, err := DB.Exec("UPDATE alert_rule SET notify_channels = ? where id in ("+str.IdsString(ids)+")", notifyChannels) +func AlertRuleUpdateNotifyChannels(ids []int64, notifyChannels, username string) error { + _, err := DB.Exec("UPDATE alert_rule SET notify_channels = ?, update_at = ?, update_by = ? where id in ("+str.IdsString(ids)+")", notifyChannels, time.Now().Unix(), username) return err } -func AlertRuleUpdateAppendTags(ids []int64, appendTags string) error { - _, err := DB.Exec("UPDATE alert_rule SET append_tags = ? where id in ("+str.IdsString(ids)+")", appendTags) +func AlertRuleUpdateAppendTags(ids []int64, appendTags, username string) error { + _, err := DB.Exec("UPDATE alert_rule SET append_tags = ?, update_at = ?, update_by = ? where id in ("+str.IdsString(ids)+")", appendTags, time.Now().Unix(), username) return err }