go-wxhelper/service/message/save.go

27 lines
580 B
Go
Raw Permalink Normal View History

2024-02-19 14:57:36 +08:00
package message
import (
"gitee.ltd/lxh/logger/log"
"wechat-robot/internal/database"
"wechat-robot/model/entity"
)
// Save
// @description: 保存消息
// @param ent entity.Message 消息实体
// @return err error 错误
func Save(ent entity.Message) (err error) {
// 判断是否存在
var count int64
database.Client.Model(&ent).Where("msg_id = ?", ent.MsgId).Where("to_user = ?", ent.ToUser).Count(&count)
if count > 0 {
return
}
// 保存入库
err = database.Client.Create(&ent).Error
if err != nil {
log.Errorf("消息保存失败: %v", err)
}
return
}