2020-10-20 16:45:03 +08:00
|
|
|
|
package models
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"crypto/md5"
|
|
|
|
|
|
"fmt"
|
2024-07-27 14:15:25 +08:00
|
|
|
|
"time"
|
|
|
|
|
|
|
2020-10-20 20:18:06 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
2022-10-03 16:07:14 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
2021-08-08 10:29:48 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
2020-10-20 16:45:03 +08:00
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
|
|
"github.com/iwind/TeaGo/Tea"
|
|
|
|
|
|
"github.com/iwind/TeaGo/dbs"
|
|
|
|
|
|
"github.com/iwind/TeaGo/types"
|
|
|
|
|
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
|
MessageStateEnabled = 1 // 已启用
|
|
|
|
|
|
MessageStateDisabled = 0 // 已禁用
|
|
|
|
|
|
|
|
|
|
|
|
MessageLevelInfo = "info"
|
|
|
|
|
|
MessageLevelWarning = "warning"
|
|
|
|
|
|
MessageLevelError = "error"
|
2020-11-16 09:20:24 +08:00
|
|
|
|
MessageLevelSuccess = "success"
|
2020-10-20 16:45:03 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type MessageType = string
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
2023-10-14 17:16:08 +08:00
|
|
|
|
MessageTypeAll MessageType = "*"
|
|
|
|
|
|
|
2021-12-01 17:20:09 +08:00
|
|
|
|
// 这里的命名问题(首字母大写)为历史遗留问题,暂不修改
|
|
|
|
|
|
|
2021-04-12 19:19:15 +08:00
|
|
|
|
MessageTypeHealthCheckFailed MessageType = "HealthCheckFailed" // 节点健康检查失败
|
|
|
|
|
|
MessageTypeHealthCheckNodeUp MessageType = "HealthCheckNodeUp" // 因健康检查节点上线
|
|
|
|
|
|
MessageTypeHealthCheckNodeDown MessageType = "HealthCheckNodeDown" // 因健康检查节点下线
|
2021-08-08 10:29:48 +08:00
|
|
|
|
MessageTypeNodeInactive MessageType = "NodeInactive" // 边缘节点不活跃
|
|
|
|
|
|
MessageTypeNodeActive MessageType = "NodeActive" // 边缘节点活跃
|
2021-04-12 19:19:15 +08:00
|
|
|
|
MessageTypeClusterDNSSyncFailed MessageType = "ClusterDNSSyncFailed" // DNS同步失败
|
2020-12-19 19:09:14 +08:00
|
|
|
|
MessageTypeSSLCertExpiring MessageType = "SSLCertExpiring" // SSL证书即将过期
|
|
|
|
|
|
MessageTypeSSLCertACMETaskFailed MessageType = "SSLCertACMETaskFailed" // SSL证书任务执行失败
|
|
|
|
|
|
MessageTypeSSLCertACMETaskSuccess MessageType = "SSLCertACMETaskSuccess" // SSL证书任务执行成功
|
|
|
|
|
|
MessageTypeLogCapacityOverflow MessageType = "LogCapacityOverflow" // 日志超出最大限制
|
2021-12-01 17:20:09 +08:00
|
|
|
|
MessageTypeServerNamesAuditingSuccess MessageType = "ServerNamesAuditingSuccess" // 服务域名审核成功(用户)
|
|
|
|
|
|
MessageTypeServerNamesAuditingFailed MessageType = "ServerNamesAuditingFailed" // 服务域名审核失败(用户)
|
|
|
|
|
|
MessageTypeServerNamesRequireAuditing MessageType = "serverNamesRequireAuditing" // 服务域名需要审核(管理员)
|
2021-05-05 19:50:55 +08:00
|
|
|
|
MessageTypeThresholdSatisfied MessageType = "ThresholdSatisfied" // 满足阈值
|
2021-07-18 15:52:34 +08:00
|
|
|
|
MessageTypeFirewallEvent MessageType = "FirewallEvent" // 防火墙事件
|
2021-08-18 16:19:16 +08:00
|
|
|
|
MessageTypeIPAddrUp MessageType = "IPAddrUp" // IP地址上线
|
|
|
|
|
|
MessageTypeIPAddrDown MessageType = "IPAddrDown" // IP地址下线
|
2021-08-08 10:29:48 +08:00
|
|
|
|
|
2021-09-05 11:10:18 +08:00
|
|
|
|
MessageTypeNSNodeInactive MessageType = "NSNodeInactive" // NS节点不活跃
|
|
|
|
|
|
MessageTypeNSNodeActive MessageType = "NSNodeActive" // NS节点活跃
|
|
|
|
|
|
|
|
|
|
|
|
MessageTypeReportNodeInactive MessageType = "ReportNodeInactive" // 区域监控节点节点不活跃
|
|
|
|
|
|
MessageTypeReportNodeActive MessageType = "ReportNodeActive" // 区域监控节点活跃
|
2023-05-17 18:42:21 +08:00
|
|
|
|
MessageTypeConnectivity MessageType = "Connectivity" // 连通性
|
|
|
|
|
|
MessageTypeNodeSchedule MessageType = "NodeSchedule" // 节点调度信息
|
|
|
|
|
|
MessageTypeNodeOfflineDay MessageType = "NodeOfflineDay" // 节点到下线日期
|
2020-10-20 16:45:03 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type MessageDAO dbs.DAO
|
|
|
|
|
|
|
|
|
|
|
|
func NewMessageDAO() *MessageDAO {
|
|
|
|
|
|
return dbs.NewDAO(&MessageDAO{
|
|
|
|
|
|
DAOObject: dbs.DAOObject{
|
|
|
|
|
|
DB: Tea.Env,
|
|
|
|
|
|
Table: "edgeMessages",
|
|
|
|
|
|
Model: new(Message),
|
|
|
|
|
|
PkName: "id",
|
|
|
|
|
|
},
|
|
|
|
|
|
}).(*MessageDAO)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var SharedMessageDAO *MessageDAO
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
|
dbs.OnReady(func() {
|
|
|
|
|
|
SharedMessageDAO = NewMessageDAO()
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-12 19:19:15 +08:00
|
|
|
|
// EnableMessage 启用条目
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *MessageDAO) EnableMessage(tx *dbs.Tx, id int64) error {
|
|
|
|
|
|
_, err := this.Query(tx).
|
2020-10-20 16:45:03 +08:00
|
|
|
|
Pk(id).
|
|
|
|
|
|
Set("state", MessageStateEnabled).
|
|
|
|
|
|
Update()
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-12 19:19:15 +08:00
|
|
|
|
// DisableMessage 禁用条目
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *MessageDAO) DisableMessage(tx *dbs.Tx, id int64) error {
|
|
|
|
|
|
_, err := this.Query(tx).
|
2020-10-20 16:45:03 +08:00
|
|
|
|
Pk(id).
|
|
|
|
|
|
Set("state", MessageStateDisabled).
|
|
|
|
|
|
Update()
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-12 19:19:15 +08:00
|
|
|
|
// FindEnabledMessage 查找启用中的条目
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *MessageDAO) FindEnabledMessage(tx *dbs.Tx, id int64) (*Message, error) {
|
|
|
|
|
|
result, err := this.Query(tx).
|
2020-10-20 16:45:03 +08:00
|
|
|
|
Pk(id).
|
|
|
|
|
|
Attr("state", MessageStateEnabled).
|
|
|
|
|
|
Find()
|
|
|
|
|
|
if result == nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
return result.(*Message), err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-12 19:19:15 +08:00
|
|
|
|
// CreateClusterMessage 创建集群消息
|
2023-11-03 09:54:42 +08:00
|
|
|
|
func (this *MessageDAO) CreateClusterMessage(tx *dbs.Tx, role string, clusterId int64, messageType MessageType, level string, subject string, shortBody string, body string, paramsJSON []byte) error {
|
|
|
|
|
|
if len(shortBody) == 0 {
|
|
|
|
|
|
shortBody = body
|
|
|
|
|
|
}
|
|
|
|
|
|
_, err := this.createMessage(tx, role, clusterId, 0, messageType, level, subject, shortBody, paramsJSON)
|
2021-04-12 19:19:15 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 发送给媒介接收人
|
2023-10-17 13:49:23 +08:00
|
|
|
|
err = SharedMessageTaskDAO.CreateMessageTasks(tx, role, clusterId, 0, 0, messageType, subject, body)
|
2021-04-12 19:19:15 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
2020-10-20 16:45:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-12 19:19:15 +08:00
|
|
|
|
// CreateNodeMessage 创建节点消息
|
2021-09-14 11:36:22 +08:00
|
|
|
|
func (this *MessageDAO) CreateNodeMessage(tx *dbs.Tx, role string, clusterId int64, nodeId int64, messageType MessageType, level string, subject string, body string, paramsJSON []byte, force bool) error {
|
2021-05-05 19:50:55 +08:00
|
|
|
|
// 检查N分钟内是否已经发送过
|
2021-08-08 10:29:48 +08:00
|
|
|
|
hash := this.calHash(role, clusterId, nodeId, subject, body, paramsJSON)
|
2021-09-14 11:36:22 +08:00
|
|
|
|
if !force {
|
|
|
|
|
|
exists, err := this.Query(tx).
|
|
|
|
|
|
Attr("hash", hash).
|
|
|
|
|
|
Gt("createdAt", time.Now().Unix()-10*60). // 10分钟
|
|
|
|
|
|
Exist()
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
if exists {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
2021-05-05 19:50:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-14 11:36:22 +08:00
|
|
|
|
_, err := this.createMessage(tx, role, clusterId, nodeId, messageType, level, subject, body, paramsJSON)
|
2021-04-12 19:19:15 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-24 14:22:44 +08:00
|
|
|
|
// 发送给媒介接收人 - 集群
|
|
|
|
|
|
err = SharedMessageTaskDAO.CreateMessageTasks(tx, role, clusterId, nodeId, 0, messageType, subject, body)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
2021-04-12 19:19:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
2020-10-25 18:26:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-12 19:19:15 +08:00
|
|
|
|
// CreateMessage 创建普通消息
|
|
|
|
|
|
func (this *MessageDAO) CreateMessage(tx *dbs.Tx, adminId int64, userId int64, messageType MessageType, level string, subject string, body string, paramsJSON []byte) error {
|
2023-03-28 16:25:18 +08:00
|
|
|
|
subject = utils.LimitString(subject, 100)
|
2022-10-03 16:07:14 +08:00
|
|
|
|
body = utils.LimitString(body, 1024)
|
|
|
|
|
|
|
2022-07-24 09:56:27 +08:00
|
|
|
|
var op = NewMessageOperator()
|
2020-11-27 09:57:21 +08:00
|
|
|
|
op.AdminId = adminId
|
|
|
|
|
|
op.UserId = userId
|
|
|
|
|
|
op.Type = messageType
|
|
|
|
|
|
op.Level = level
|
2021-04-12 19:19:15 +08:00
|
|
|
|
|
2022-10-03 16:07:14 +08:00
|
|
|
|
op.Subject = subject
|
2020-11-27 09:57:21 +08:00
|
|
|
|
op.Body = body
|
|
|
|
|
|
if len(paramsJSON) > 0 {
|
|
|
|
|
|
op.Params = paramsJSON
|
|
|
|
|
|
}
|
|
|
|
|
|
op.State = MessageStateEnabled
|
|
|
|
|
|
op.IsRead = false
|
|
|
|
|
|
op.Day = timeutil.Format("Ymd")
|
2021-08-08 10:29:48 +08:00
|
|
|
|
op.Hash = this.calHash(nodeconfigs.NodeRoleAdmin, 0, 0, subject, body, paramsJSON)
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2021-04-12 19:19:15 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
2020-11-27 09:57:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-12 19:19:15 +08:00
|
|
|
|
// DeleteMessagesBeforeDay 删除某天之前的消息
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *MessageDAO) DeleteMessagesBeforeDay(tx *dbs.Tx, dayTime time.Time) error {
|
2020-10-20 16:45:03 +08:00
|
|
|
|
day := timeutil.Format("Ymd", dayTime)
|
2021-01-01 23:31:30 +08:00
|
|
|
|
_, err := this.Query(tx).
|
2020-10-20 16:45:03 +08:00
|
|
|
|
Where("day<:day").
|
|
|
|
|
|
Param("day", day).
|
|
|
|
|
|
Delete()
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-12 19:19:15 +08:00
|
|
|
|
// CountUnreadMessages 计算未读消息数量
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *MessageDAO) CountUnreadMessages(tx *dbs.Tx, adminId int64, userId int64) (int64, error) {
|
|
|
|
|
|
query := this.Query(tx).
|
2020-12-15 11:52:57 +08:00
|
|
|
|
Attr("isRead", false)
|
|
|
|
|
|
if adminId > 0 {
|
|
|
|
|
|
query.Where("(adminId=:adminId OR (adminId=0 AND userId=0))").
|
|
|
|
|
|
Param("adminId", adminId)
|
|
|
|
|
|
} else if userId > 0 {
|
|
|
|
|
|
query.Attr("userId", userId)
|
|
|
|
|
|
}
|
|
|
|
|
|
return query.Count()
|
2020-10-20 20:18:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-12 19:19:15 +08:00
|
|
|
|
// ListUnreadMessages 列出单页未读消息
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *MessageDAO) ListUnreadMessages(tx *dbs.Tx, adminId int64, userId int64, offset int64, size int64) (result []*Message, err error) {
|
|
|
|
|
|
query := this.Query(tx).
|
2020-12-15 11:52:57 +08:00
|
|
|
|
Attr("isRead", false)
|
|
|
|
|
|
if adminId > 0 {
|
|
|
|
|
|
query.Where("(adminId=:adminId OR (adminId=0 AND userId=0))").
|
|
|
|
|
|
Param("adminId", adminId)
|
|
|
|
|
|
} else if userId > 0 {
|
|
|
|
|
|
query.Attr("userId", userId)
|
|
|
|
|
|
}
|
|
|
|
|
|
_, err = query.
|
2020-10-20 20:18:06 +08:00
|
|
|
|
Offset(offset).
|
|
|
|
|
|
Limit(size).
|
|
|
|
|
|
DescPk().
|
|
|
|
|
|
Slice(&result).
|
|
|
|
|
|
FindAll()
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-12 19:19:15 +08:00
|
|
|
|
// UpdateMessageRead 设置消息已读状态
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *MessageDAO) UpdateMessageRead(tx *dbs.Tx, messageId int64, b bool) error {
|
2020-10-20 20:18:06 +08:00
|
|
|
|
if messageId <= 0 {
|
|
|
|
|
|
return errors.New("invalid messageId")
|
|
|
|
|
|
}
|
2022-07-24 09:56:27 +08:00
|
|
|
|
var op = NewMessageOperator()
|
2020-10-20 20:18:06 +08:00
|
|
|
|
op.Id = messageId
|
|
|
|
|
|
op.IsRead = b
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2020-10-20 20:18:06 +08:00
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-12 19:19:15 +08:00
|
|
|
|
// UpdateMessagesRead 设置一组消息为已读状态
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *MessageDAO) UpdateMessagesRead(tx *dbs.Tx, messageIds []int64, b bool) error {
|
2020-10-20 20:18:06 +08:00
|
|
|
|
// 这里我们一个一个更改,因为In语句不容易Prepare,且效率不高
|
|
|
|
|
|
for _, messageId := range messageIds {
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.UpdateMessageRead(tx, messageId, b)
|
2020-10-20 20:18:06 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-12 19:19:15 +08:00
|
|
|
|
// UpdateAllMessagesRead 设置所有消息为已读
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *MessageDAO) UpdateAllMessagesRead(tx *dbs.Tx, adminId int64, userId int64) error {
|
|
|
|
|
|
query := this.Query(tx).
|
2020-12-15 11:52:57 +08:00
|
|
|
|
Attr("isRead", false)
|
|
|
|
|
|
if adminId > 0 {
|
|
|
|
|
|
query.Where("(adminId=:adminId OR (adminId=0 AND userId=0))").
|
|
|
|
|
|
Param("adminId", adminId)
|
|
|
|
|
|
} else if userId > 0 {
|
|
|
|
|
|
query.Attr("userId", userId)
|
|
|
|
|
|
}
|
|
|
|
|
|
_, err := query.
|
2020-10-20 20:18:06 +08:00
|
|
|
|
Set("isRead", true).
|
|
|
|
|
|
Update()
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-12 19:19:15 +08:00
|
|
|
|
// CheckMessageUser 检查消息权限
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *MessageDAO) CheckMessageUser(tx *dbs.Tx, messageId int64, adminId int64, userId int64) (bool, error) {
|
2020-12-15 11:52:57 +08:00
|
|
|
|
if messageId <= 0 || (adminId <= 0 && userId <= 0) {
|
|
|
|
|
|
return false, nil
|
|
|
|
|
|
}
|
2021-01-01 23:31:30 +08:00
|
|
|
|
query := this.Query(tx).
|
2020-12-15 11:52:57 +08:00
|
|
|
|
Pk(messageId)
|
|
|
|
|
|
if adminId > 0 {
|
|
|
|
|
|
query.Where("(adminId=:adminId OR (adminId=0 AND userId=0))").
|
|
|
|
|
|
Param("adminId", adminId)
|
|
|
|
|
|
} else if userId > 0 {
|
|
|
|
|
|
query.Attr("userId", userId)
|
|
|
|
|
|
}
|
|
|
|
|
|
return query.Exist()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-20 16:45:03 +08:00
|
|
|
|
// 创建消息
|
2021-08-08 10:29:48 +08:00
|
|
|
|
func (this *MessageDAO) createMessage(tx *dbs.Tx, role string, clusterId int64, nodeId int64, messageType MessageType, level string, subject string, body string, paramsJSON []byte) (int64, error) {
|
2020-10-20 16:45:03 +08:00
|
|
|
|
// TODO 检查同样的消息最近是否发送过
|
|
|
|
|
|
|
|
|
|
|
|
// 创建新消息
|
2022-07-24 09:56:27 +08:00
|
|
|
|
var op = NewMessageOperator()
|
2020-10-20 16:45:03 +08:00
|
|
|
|
op.AdminId = 0 // TODO
|
|
|
|
|
|
op.UserId = 0 // TODO
|
2021-08-08 10:29:48 +08:00
|
|
|
|
op.Role = role
|
2020-10-20 16:45:03 +08:00
|
|
|
|
op.ClusterId = clusterId
|
|
|
|
|
|
op.NodeId = nodeId
|
|
|
|
|
|
op.Type = messageType
|
|
|
|
|
|
op.Level = level
|
2021-04-12 19:19:15 +08:00
|
|
|
|
|
|
|
|
|
|
subjectRunes := []rune(subject)
|
|
|
|
|
|
if len(subjectRunes) > 100 {
|
|
|
|
|
|
op.Subject = string(subjectRunes[:100]) + "..."
|
|
|
|
|
|
} else {
|
|
|
|
|
|
op.Subject = subject
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-20 16:45:03 +08:00
|
|
|
|
op.Body = body
|
|
|
|
|
|
if len(paramsJSON) > 0 {
|
|
|
|
|
|
op.Params = paramsJSON
|
|
|
|
|
|
}
|
|
|
|
|
|
op.IsRead = false
|
|
|
|
|
|
op.State = MessageStateEnabled
|
|
|
|
|
|
op.CreatedAt = time.Now().Unix()
|
|
|
|
|
|
op.Day = timeutil.Format("Ymd")
|
2021-08-08 10:29:48 +08:00
|
|
|
|
op.Hash = this.calHash(role, clusterId, nodeId, subject, body, paramsJSON)
|
2020-10-20 16:45:03 +08:00
|
|
|
|
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2020-10-20 16:45:03 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return 0, err
|
|
|
|
|
|
}
|
|
|
|
|
|
return types.Int64(op.Id), nil
|
|
|
|
|
|
}
|
2021-05-05 19:50:55 +08:00
|
|
|
|
|
|
|
|
|
|
// 计算Hash
|
2021-08-08 10:29:48 +08:00
|
|
|
|
func (this *MessageDAO) calHash(role string, clusterId int64, nodeId int64, subject string, body string, paramsJSON []byte) string {
|
2021-05-05 19:50:55 +08:00
|
|
|
|
h := md5.New()
|
2021-08-08 10:29:48 +08:00
|
|
|
|
h.Write([]byte(role + "@" + types.String(clusterId) + "@" + types.String(nodeId)))
|
|
|
|
|
|
h.Write([]byte(subject + "@"))
|
|
|
|
|
|
h.Write([]byte(body + "@"))
|
2021-05-05 19:50:55 +08:00
|
|
|
|
h.Write(paramsJSON)
|
|
|
|
|
|
return fmt.Sprintf("%x", h.Sum(nil))
|
|
|
|
|
|
}
|