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 }