From 3135ff5b85fcd43862dd15592c3cd71522459f04 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Wed, 24 Jan 2024 14:10:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20ws=20=E6=B6=88=E6=81=AF=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/ws/controller/ws.go | 26 ++++++++++++++++---------- src/modules/ws/service/ws_send.impl.go | 8 ++++++-- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/modules/ws/controller/ws.go b/src/modules/ws/controller/ws.go index b93342de..1257f594 100644 --- a/src/modules/ws/controller/ws.go +++ b/src/modules/ws/controller/ws.go @@ -82,17 +82,23 @@ func (s *WSController) Test(c *gin.Context) { return } - // err = s.wsSendService.ByClientID(c.Query("clientId"), loginUser) - // if err != nil { - // c.JSON(200, result.ErrMsg(err.Error())) - // return - // } + errMsgArr := []string{} - err = s.wsSendService.ByGroupID(c.Query("groupID"), loginUser) - if err != nil { - c.JSON(200, result.ErrMsg(err.Error())) - return + clientId := c.Query("clientId") + if clientId != "" { + err := s.wsSendService.ByClientID(c.Query("clientId"), loginUser) + if err != nil { + errMsgArr = append(errMsgArr, "clientId: "+err.Error()) + } } - c.JSON(200, result.Ok(nil)) + groupID := c.Query("groupID") + if groupID != "" { + err := s.wsSendService.ByGroupID(c.Query("groupID"), loginUser) + if err != nil { + errMsgArr = append(errMsgArr, "groupID: "+err.Error()) + } + } + + c.JSON(200, result.OkData(errMsgArr)) } diff --git a/src/modules/ws/service/ws_send.impl.go b/src/modules/ws/service/ws_send.impl.go index 942e6585..cab283a1 100644 --- a/src/modules/ws/service/ws_send.impl.go +++ b/src/modules/ws/service/ws_send.impl.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" + "ems.agt/src/framework/vo/result" "ems.agt/src/modules/ws/model" ) @@ -29,7 +30,7 @@ func (s *WSSendImpl) ByClientID(clientID string, data any) error { return fmt.Errorf("no fount client ID: %s", clientID) } - dataByte, err := json.Marshal(data) + dataByte, err := json.Marshal(result.OkData(data)) if err != nil { return err } @@ -61,7 +62,10 @@ func (s *WSSendImpl) ByGroupID(groupID string, data any) error { // 在用户中找到客户端并发送 uidClientIds := clientIds.(*[]string) for _, clientId := range *uidClientIds { - err := s.ByClientID(clientId, data) + err := s.ByClientID(clientId, map[string]any{ + "groupID": groupID, + "data": data, + }) if err != nil { continue }