1.4.5.2
This commit is contained in:
55
EdgeAPI/internal/db/models/message_receiver_dao_plus.go
Normal file
55
EdgeAPI/internal/db/models/message_receiver_dao_plus.go
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package models
|
||||
|
||||
import "github.com/iwind/TeaGo/dbs"
|
||||
|
||||
// ExistsClusterReceiverWithRecipientId 检查和集群关联的接收者是否存在
|
||||
func (this *MessageReceiverDAO) ExistsClusterReceiverWithRecipientId(tx *dbs.Tx, role string, clusterId int64, recipientId int64) (bool, error) {
|
||||
if clusterId <= 0 || recipientId <= 0 {
|
||||
return false, nil
|
||||
}
|
||||
return this.Query(tx).
|
||||
Attr("role", role).
|
||||
Attr("clusterId", clusterId).
|
||||
Attr("nodeId", 0).
|
||||
Attr("serverId", 0).
|
||||
Attr("recipientId", recipientId).
|
||||
State(MessageReceiverStateEnabled).
|
||||
Exist()
|
||||
}
|
||||
|
||||
// FindAllEnabledReceivers 查询接收人
|
||||
func (this *MessageReceiverDAO) FindAllEnabledReceivers(tx *dbs.Tx, role string, clusterId int64, nodeId int64, serverId int64, messageType string) (result []*MessageReceiver, err error) {
|
||||
var query = this.Query(tx)
|
||||
if len(messageType) > 0 {
|
||||
query.Attr("type", []string{"*", messageType}) // *表示所有的
|
||||
}
|
||||
_, err = query.
|
||||
Attr("role", role).
|
||||
Attr("clusterId", clusterId).
|
||||
Attr("nodeId", nodeId).
|
||||
Attr("serverId", serverId).
|
||||
State(MessageReceiverStateEnabled).
|
||||
AscPk().
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
// FindAllEnabledReceiversWithRecipientId 根据接收人查询接收者
|
||||
func (this *MessageReceiverDAO) FindAllEnabledReceiversWithRecipientId(tx *dbs.Tx, recipientId int64) (result []*MessageReceiver, err error) {
|
||||
if recipientId <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
var query = this.Query(tx)
|
||||
_, err = query.
|
||||
Attr("recipientId", recipientId).
|
||||
State(MessageReceiverStateEnabled).
|
||||
AscPk().
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user