getbuoymsglogic.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/MessageCenter/rpc/messageclient"
  4. "context"
  5. "app.yhyue.com/moapp/MessageCenter/api/internal/svc"
  6. "app.yhyue.com/moapp/MessageCenter/api/internal/types"
  7. "github.com/zeromicro/go-zero/core/logx"
  8. )
  9. type GetBuoyMsgLogic struct {
  10. logx.Logger
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. }
  14. func NewGetBuoyMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) GetBuoyMsgLogic {
  15. return GetBuoyMsgLogic{
  16. Logger: logx.WithContext(ctx),
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. }
  20. }
  21. func (l *GetBuoyMsgLogic) GetBuoyMsg(req types.GetBuoyMsgReq) (*types.GetBuoyMsgResp, error) {
  22. if req.Size > 10 {
  23. req.Size = 10
  24. }
  25. if req.Size <= 0 {
  26. req.Size = 1
  27. }
  28. result := &types.GetBuoyMsgResp{}
  29. lsi := l.svcCtx.MessageCenter
  30. res, err := lsi.FindUserBuoyMsg(l.ctx, &messageclient.FindUserBuoyMsgReq{
  31. UserId: req.UserId,
  32. PageSize: req.Size,
  33. Appid: req.AppId,
  34. })
  35. if err != nil {
  36. return nil, err
  37. }
  38. result.Code = res.Code
  39. result.Message = res.Message
  40. for _, msg := range res.Data {
  41. result.Data = append(result.Data, map[string]interface{}{
  42. "id": msg.Id,
  43. "buoyDetail": msg.BuoyDetail,
  44. "pcUrl": msg.PcUrl,
  45. "androidUrl": msg.AndroidUrl,
  46. "iosUrl": msg.IosUrl,
  47. "weChatUrl": msg.WeChatUrl,
  48. })
  49. }
  50. return result, nil
  51. }