Compare commits

..

2 Commits

Author SHA1 Message Date
8b7487b42b 🎨 优化写法
All checks were successful
BuildImage / build-image (push) Successful in 1m8s
2023-12-07 23:00:57 +08:00
ac9f68c80d 🎨 打印 sql 语句 2023-12-07 23:00:16 +08:00
2 changed files with 10 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import (
"go-wechat/config"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"log"
)
@ -17,7 +18,13 @@ func InitMySQLClient() {
DontSupportRenameIndex: true, // 重命名索引时采用删除并新建的方式
DontSupportRenameColumn: true, // 用 `change` 重命名列
}
conn, err := gorm.Open(mysql.New(mysqlConfig))
// gorm 配置
gormConfig := gorm.Config{
Logger: logger.Default.LogMode(logger.Info),
}
conn, err := gorm.Open(mysql.New(mysqlConfig), &gormConfig)
if err != nil {
log.Panicf("初始化MySQL连接失败, 错误信息: %v", err)
} else {

View File

@ -6,7 +6,6 @@ import (
"go-wechat/entity"
"go-wechat/model"
"go-wechat/utils"
"log"
)
// handleNewUserJoin
@ -15,12 +14,8 @@ import (
func handleNewUserJoin(m model.Message) {
// 判断是否开启迎新
var count int64
err := client.MySQL.Model(&entity.Friend{}).
Where("enable_welcome IS TRUE").
Where("wxid = ?", m.FromUser).
Count(&count).Error
if err != nil {
log.Printf("查询是否开启迎新失败: %s", err.Error())
client.MySQL.Model(&entity.Friend{}).Where("enable_welcome IS TRUE").Where("wxid = ?", m.FromUser).Count(&count)
if count < 1 {
return
}
if count < 1 {