findmessagelogic.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package logic
  2. import (
  3. quitl "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/encrypt"
  5. "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/api/messagecenter/util"
  6. "bp.jydev.jianyu360.cn/SocialPlatform/socialPlatform/entity"
  7. "bp.jydev.jianyu360.cn/SocialPlatform/socialPlatform/rpc/social/social"
  8. "context"
  9. "net/http"
  10. "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/api/messagecenter/internal/svc"
  11. "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/api/messagecenter/internal/types"
  12. "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
  13. "github.com/zeromicro/go-zero/core/logx"
  14. )
  15. type FindMessageLogic struct {
  16. logx.Logger
  17. ctx context.Context
  18. svcCtx *svc.ServiceContext
  19. r *http.Request
  20. }
  21. func NewFindMessageLogic(ctx context.Context, svcCtx *svc.ServiceContext, r *http.Request) *FindMessageLogic {
  22. return &FindMessageLogic{
  23. Logger: logx.WithContext(ctx),
  24. ctx: ctx,
  25. svcCtx: svcCtx,
  26. r: r,
  27. }
  28. }
  29. func (l *FindMessageLogic) FindMessage(req *types.MessageReq) (resp *types.CommonRes, err error) {
  30. resp = &types.CommonRes{}
  31. if req.NewUserId == 0 {
  32. sessionId, trustedId, stErr := util.GetTouristCookieInfo(l.r)
  33. if stErr != nil {
  34. resp.Error_code = 1
  35. resp.Error_msg = stErr.Error()
  36. return resp, nil
  37. }
  38. result, rErr := l.svcCtx.Social.TouristInfo(l.ctx, &social.TouristInfoReq{
  39. SessionId: sessionId,
  40. Ip: entity.GetIp(l.r),
  41. TrustedId: trustedId,
  42. })
  43. if rErr != nil || result.Data.BaseUserId == 0 {
  44. resp.Error_code = 1
  45. resp.Error_msg = "当用户信息有误"
  46. logx.Error("获取当前游客信息有误:", rErr.Error())
  47. return resp, rErr
  48. }
  49. req.NewUserId = result.Data.BaseUserId
  50. }
  51. var res *messagecenter.MessageResp
  52. res, err = l.svcCtx.Message.FindMessage(l.ctx, &messagecenter.MessageReq{
  53. UserType: req.UserType,
  54. MsgType: req.MsgType,
  55. SendId: quitl.Int64All(encrypt.SE.Decode4Hex(req.SendId)),
  56. LastId: quitl.Int64All(encrypt.SE.Decode4Hex(req.LastId)),
  57. EntId: req.EntId,
  58. PageSize: req.PageSize,
  59. EntUserId: req.EntUserId,
  60. NewUserId: req.NewUserId,
  61. Sort: req.Sort,
  62. ChatGroupId: quitl.Int64All(encrypt.SE.Decode4Hex(req.ChatGroupId)),
  63. PositionId: req.PositionId,
  64. })
  65. if err != nil {
  66. return nil, err
  67. }
  68. resp = &types.CommonRes{
  69. Error_msg: res.ErrorMsg,
  70. Error_code: int(res.ErrorCode),
  71. Data: res.Data,
  72. Count: res.Count,
  73. }
  74. return resp, nil
  75. }