go-wxhelper/service/message.go
李寻欢 cab6b2633e
All checks were successful
BuildImage / build-image (push) Successful in 1m13s
🎨 优化 AI,支持记录几句上下文,并优化了 at 消息匹配的正则
2023-12-09 11:52:11 +08:00

30 lines
701 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package service
import (
"go-wechat/client"
"go-wechat/entity"
"log"
)
// SaveMessage
// @description: 消息入库
// @param msg
func SaveMessage(msg entity.Message) {
// 检查消息是否存在,存在就跳过
var count int64
err := client.MySQL.Model(&entity.Message{}).Where("msg_id = ?", msg.MsgId).Count(&count).Error
if err != nil {
log.Printf("检查消息是否存在失败, 错误信息: %v", err)
return
}
if count > 0 {
//log.Printf("消息已存在消息Id: %d", msg.MsgId)
return
}
err = client.MySQL.Create(&msg).Error
if err != nil {
log.Printf("消息入库失败, 错误信息: %v", err)
}
log.Printf("消息入库成功消息Id: %d", msg.MsgId)
}