From 301e94808d172280d9f04b7440e4e366b74f0cba Mon Sep 17 00:00:00 2001 From: jjxu <428192774@qq.com> Date: Thu, 19 Jun 2025 14:23:01 +0800 Subject: [PATCH 1/2] Update chat.go --- pkg/service/asChat/logic/chat.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/service/asChat/logic/chat.go b/pkg/service/asChat/logic/chat.go index 6fdd54e..1a4d983 100644 --- a/pkg/service/asChat/logic/chat.go +++ b/pkg/service/asChat/logic/chat.go @@ -40,7 +40,7 @@ func NewMessage(ctx context.Context, cache *chatCache.ChatCache, sender *account cacheMap[request.AtUserId] = request } else { fmt.Println(request.LocalStamp - msgRecord.LocalStamp) - if msgRecord.Message.Text == request.Message.Text && request.LocalStamp-msgRecord.LocalStamp < 10 { + if msgRecord.Message.Text == request.Message.Text && request.LocalStamp-msgRecord.LocalStamp < 1 { //秒级 cacheMap[request.AtUserId] = request return nil } else { From bc17428bd69542bade04d63c53b476e5096afca4 Mon Sep 17 00:00:00 2001 From: jjxu <428192774@qq.com> Date: Thu, 19 Jun 2025 14:39:42 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/service/asChat/handler.go | 49 +++++++++---------------------- pkg/service/asChat/logic/chat.go | 3 +- pkg/service/asChat/logic/utils.go | 42 ++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 36 deletions(-) create mode 100644 pkg/service/asChat/logic/utils.go diff --git a/pkg/service/asChat/handler.go b/pkg/service/asChat/handler.go index 25660cd..4302949 100644 --- a/pkg/service/asChat/handler.go +++ b/pkg/service/asChat/handler.go @@ -24,7 +24,6 @@ import ( "fonchain-fiee/pkg/service/asChat/logic" "fonchain-fiee/pkg/service/asChat/robot" "fonchain-fiee/pkg/service/upload" - "fonchain-fiee/pkg/utils" "fonchain-fiee/pkg/utils/stime" "io" "log" @@ -503,9 +502,22 @@ func (cr ChatHandler) UserMessageStat(c *gin.Context) { } } if result[i].Name == "" { - result[i].Name = beautifulZeroNameWithPhone(result[i].Name, result[i].UserId) + result[i].Name = logic.BeautifulZeroNameWithPhone(result[i].Name, result[i].UserId) } } + //筛选 + if request.Account != "" || request.Name != "" { + newData := []dto.UserMsgStatic{} + for _, v := range listRes.List { + for _, vv := range result { + if v.UserId == vv.UserId { + vv := vv + newData = append(newData, vv) + } + } + } + result = newData + } reverse(result) if chatUser.Role == 1 { userSessionId := fmt.Sprintf("%d", chatUser.ID) @@ -600,36 +612,3 @@ func (cr ChatHandler) UserDetail(c *gin.Context) { service.Success(c, detail) } - -// 对没有名字的name进行优化 -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 -} diff --git a/pkg/service/asChat/logic/chat.go b/pkg/service/asChat/logic/chat.go index 1a4d983..e3ed49e 100644 --- a/pkg/service/asChat/logic/chat.go +++ b/pkg/service/asChat/logic/chat.go @@ -54,7 +54,8 @@ func NewMessage(ctx context.Context, cache *chatCache.ChatCache, sender *account //存储入库 if sender.NickName == "" { - sender.NickName = fmt.Sprintf("未知用户(%d)", sender.ID) + //sender.NickName = fmt.Sprintf("未知用户(%d)", sender.ID) + sender.NickName = BeautifulZeroNameWithPhone(sender.NickName, sender.ID) } fmt.Println("NewMessage 3333333333333333333333333333333333") var data = accountFiee.ChatRecordData{ diff --git a/pkg/service/asChat/logic/utils.go b/pkg/service/asChat/logic/utils.go new file mode 100644 index 0000000..e423b3d --- /dev/null +++ b/pkg/service/asChat/logic/utils.go @@ -0,0 +1,42 @@ +package logic + +import ( + "context" + "fmt" + "fonchain-fiee/api/accountFiee" + "fonchain-fiee/pkg/service" + "fonchain-fiee/pkg/utils" +) + +// 对没有名字的name进行优化 +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 +}