From 58cb76ed75857a5e913b996d8ce3268639b15a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Fri, 8 Dec 2023 11:41:59 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/mysql.go | 10 +++++++--- tasks/friends/friends.go | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/client/mysql.go b/client/mysql.go index eb774c1..c4a8dac 100644 --- a/client/mysql.go +++ b/client/mysql.go @@ -6,9 +6,11 @@ import ( "gorm.io/gorm" "gorm.io/gorm/logger" "log" + "os" + "strconv" ) -// MySQL客户端 +// MySQL MySQL客户端 var MySQL *gorm.DB func InitMySQLClient() { @@ -20,8 +22,10 @@ func InitMySQLClient() { } // gorm 配置 - gormConfig := gorm.Config{ - Logger: logger.Default.LogMode(logger.Info), + gormConfig := gorm.Config{} + // 是否开启调试模式 + if flag, _ := strconv.ParseBool(os.Getenv("GORM_DEBUG")); flag { + gormConfig.Logger = logger.Default.LogMode(logger.Info) } conn, err := gorm.Open(mysql.New(mysqlConfig), &gormConfig) diff --git a/tasks/friends/friends.go b/tasks/friends/friends.go index 166846a..81940df 100644 --- a/tasks/friends/friends.go +++ b/tasks/friends/friends.go @@ -48,7 +48,7 @@ func Sync() { if slices.Contains(constant.SpecialId, friend.Wxid) { continue } - log.Printf("昵称: %s -> 类型: %d -> 微信号: %s -> 微信原始Id: %s", friend.Nickname, friend.Type, friend.CustomAccount, friend.Wxid) + //log.Printf("昵称: %s -> 类型: %d -> 微信号: %s -> 微信原始Id: %s", friend.Nickname, friend.Type, friend.CustomAccount, friend.Wxid) nowIds = append(nowIds, friend.Wxid) // 判断是否存在,不存在的话就新增,存在就修改一下名字 @@ -121,7 +121,7 @@ func syncGroupUsers(tx *gorm.DB, gid string) { // 昵称Id wxIds := strings.Split(baseResp.Data.Members, "^G") - log.Printf(" 群成员数: %d", len(wxIds)) + //log.Printf(" 群成员数: %d", len(wxIds)) // 修改不在数组的群成员状态为不在 pm := map[string]any{ @@ -138,7 +138,7 @@ func syncGroupUsers(tx *gorm.DB, gid string) { // 获取成员信息 cp, _ := getContactProfile(wxid) if cp.Wxid != "" { - log.Printf(" 微信Id: %s -> 昵称: %s -> 微信号: %s", wxid, cp.Nickname, cp.Account) + //log.Printf(" 微信Id: %s -> 昵称: %s -> 微信号: %s", wxid, cp.Nickname, cp.Account) // 查询成员是否存在,不在就新增,否则修改 var count int64 err = tx.Model(&entity.GroupUser{}).Where("group_id = ?", gid).Where("wxid = ?", wxid).Count(&count).Error