From ac79481ec59fdabb224d7a7d343b65c3c4aa52a7 Mon Sep 17 00:00:00 2001 From: jjxu <428192774@qq.com> Date: Wed, 18 Jun 2025 15:59:01 +0800 Subject: [PATCH 1/2] =?UTF-8?q?perf:=20=E6=9C=AA=E5=AE=9E=E5=90=8D?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=98=BE=E7=A4=BA=E6=89=8B=E6=9C=BA=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/service/asChat/handler.go | 36 +++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/pkg/service/asChat/handler.go b/pkg/service/asChat/handler.go index 7260b25..f70038b 100644 --- a/pkg/service/asChat/handler.go +++ b/pkg/service/asChat/handler.go @@ -232,7 +232,7 @@ func (cr ChatHandler) MessageList(c *gin.Context) { } domain := c.GetHeader("domain") fmt.Println("MessageList domain:", domain) - if (request.Direction == 0 && request.Recent == false) || (request.Direction > 0 && request.Recent == true) { + if (request.Direction == 0 && !request.Recent) || (request.Direction > 0 && request.Recent) { service.Error(c, errors.New("组合条件校验失败")) return } @@ -501,7 +501,7 @@ func (cr ChatHandler) UserMessageStat(c *gin.Context) { } } if result[i].Name == "" { - result[i].Name = beautifulZeroName(result[i].Name, result[i].UserId) + result[i].Name = beautifulZeroNameWithPhone(result[i].Name, result[i].UserId) } } reverse(result) @@ -563,6 +563,10 @@ func (cr ChatHandler) UserDetail(c *gin.Context) { return } } + //fmt.Printf("chatUser:%#v\n", chatUser) + //if chatUser.Origin == "fiee" { + // chatUser.Origin = "app" + //} resp, err := service.AccountFieeProvider.Info(c, &accountFiee.InfoRequest{ID: uint64(chatUser.OriginId), Domain: chatUser.Origin}) if err != nil { service.Error(c, err) @@ -588,3 +592,31 @@ func (cr ChatHandler) UserDetail(c *gin.Context) { func beautifulZeroName(name string, userId int64) string { return utils.IfGec(name == "", fmt.Sprintf("未实名用户:%d", userId), name) } + +var userIdMapPhone = make(map[int64]string) + +func beautifulZeroNameWithPhone(name string, userId int64) string { + var ctx = context.Background() + if name == "" { + telNum, ok := userIdMapPhone[userId] + if ok { + return telNum + } + chatUserRes, err := service.AccountFieeProvider.GetChatUserDetail(ctx, &accountFiee.GetChatUserByIdRequest{Id: userId}) + if err != nil { + return fmt.Sprintf("未实名用户:%d", userId) + } else { + if userRes, errs := service.AccountFieeProvider.Info(ctx, &accountFiee.InfoRequest{ + Domain: chatUserRes.Origin, + ID: uint64(chatUserRes.OriginId), + Scene: "", + }); errs != nil { + return fmt.Sprintf("未实名用户:%d", userId) + } else { + userIdMapPhone[userId] = userRes.TelNum + return userRes.TelNum + } + } + } + return name +} From 5c8421027298bfb68a9c02527f3fffe0e38e16b5 Mon Sep 17 00:00:00 2001 From: jjxu <428192774@qq.com> Date: Wed, 18 Jun 2025 16:10:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?perf:=20=E8=B0=83=E8=AF=95=E9=87=8D?= =?UTF-8?q?=E7=BD=AE=E6=9C=AA=E8=AF=BB=E6=B6=88=E6=81=AF=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/service/asChat/chatCache/cache.go | 9 ++++++++- pkg/service/asChat/handler.go | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/service/asChat/chatCache/cache.go b/pkg/service/asChat/chatCache/cache.go index fddd470..d3897d3 100644 --- a/pkg/service/asChat/chatCache/cache.go +++ b/pkg/service/asChat/chatCache/cache.go @@ -144,29 +144,36 @@ func (cr ChatCache) IncreaseNewMessageTotal(ownerId int64, sessionId string) (er // 重置新消息数量 func (cr ChatCache) ResetNewMessageTotal(ownerId int64, sessionId string, total ...int64) error { + fmt.Printf("ResetNewMessageTotal: %d ,sessionId:%s ,total:%v\n", ownerId, sessionId, total) chatCacheLocker.Lock() defer chatCacheLocker.Unlock() var tl int64 if len(total) > 0 { tl = total[0] } + fmt.Println("ResetNewMessageTotal tl:", tl) ctx := context.Background() data := cr.GetNewMessageStat(ctx, ownerId) + fmt.Printf("ResetNewMessageTotal data:%+v\n", data) found := false for i, v := range data { if v.SessionId == sessionId { found = true data[i].Total = tl + fmt.Println("ResetNewMessageTotal found!") break } } if !found { + fmt.Println("ResetNewMessageTotal not found!") data = append(data, dto.UserMsgStatic{ SessionId: sessionId, Total: tl, }) } - return cr.coverOwnerNewMessageStat(ctx, ownerId, data) + err := cr.coverOwnerNewMessageStat(ctx, ownerId, data) + fmt.Println("ResetNewMessageTotal result:", err) + return err } func (cr ChatCache) RecountNewMessageTotal(ownerId int64) { diff --git a/pkg/service/asChat/handler.go b/pkg/service/asChat/handler.go index f70038b..0b5cd2c 100644 --- a/pkg/service/asChat/handler.go +++ b/pkg/service/asChat/handler.go @@ -249,7 +249,7 @@ func (cr ChatHandler) MessageList(c *gin.Context) { service.Success(c, resp) return } - chatUser, code := jwt.ParseToChatUser(c) + accessUser, code := jwt.ParseToChatUser(c) if code != 0 { service.ErrWithCode(c, code) return @@ -267,7 +267,7 @@ func (cr ChatHandler) MessageList(c *gin.Context) { defer func() { //获取最新数据时,重置新消息数量统计 if request.Direction == 2 || request.Recent { - cr.cache.ResetNewMessageTotal(chatUser.ID, request.SessionId) + cr.cache.ResetNewMessageTotal(accessUser.ID, request.SessionId) } //设置消息已被客服阅读,当客服重新通过通过websocket连接时,这些消息将不被纳入新消息数量统计 if len(returnDataIdList) > 0 && domain == "fontree" {