From 3b71e62a3db0a431571ded6ddee4c26e9bfb4ed2 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Wed, 24 Feb 2021 15:02:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=A1=E7=AE=97WAF?= =?UTF-8?q?=E5=8A=A8=E4=BD=9C=E6=95=B0=E9=87=8FAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db/models/node_cluster_firewall_action_dao.go | 8 ++++++++ .../service_node_cluster_firewall_action.go | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/internal/db/models/node_cluster_firewall_action_dao.go b/internal/db/models/node_cluster_firewall_action_dao.go index 1847c6cf..5529aba1 100644 --- a/internal/db/models/node_cluster_firewall_action_dao.go +++ b/internal/db/models/node_cluster_firewall_action_dao.go @@ -153,6 +153,14 @@ func (this *NodeClusterFirewallActionDAO) ComposeFirewallActionConfig(tx *dbs.Tx return config, nil } +// 计算动作数量 +func (this *NodeClusterFirewallActionDAO) CountAllEnabledFirewallActions(tx *dbs.Tx, clusterId int64) (int64, error) { + return this.Query(tx). + State(NodeClusterFirewallActionStateEnabled). + Attr("clusterId", clusterId). + Count() +} + // 通知更新 func (this *NodeClusterFirewallActionDAO) NotifyUpdate(tx *dbs.Tx, actionId int64) error { clusterId, err := this.Query(tx). diff --git a/internal/rpc/services/service_node_cluster_firewall_action.go b/internal/rpc/services/service_node_cluster_firewall_action.go index 9c2dc662..60df5f36 100644 --- a/internal/rpc/services/service_node_cluster_firewall_action.go +++ b/internal/rpc/services/service_node_cluster_firewall_action.go @@ -124,3 +124,18 @@ func (this *NodeClusterFirewallActionService) FindEnabledNodeClusterFirewallActi ParamsJSON: []byte(action.Params), }}, nil } + +// 计算动作数量 +func (this *NodeClusterFirewallActionService) CountAllEnabledNodeClusterFirewallActions(ctx context.Context, req *pb.CountAllEnabledNodeClusterFirewallActionsRequest) (*pb.RPCCountResponse, error) { + _, err := this.ValidateAdmin(ctx, 0) + if err != nil { + return nil, err + } + + var tx = this.NullTx() + count, err := models.SharedNodeClusterFirewallActionDAO.CountAllEnabledFirewallActions(tx, req.NodeClusterId) + if err != nil { + return nil, err + } + return this.SuccessCount(count) +}