messagecountlogic.go 2.0 KB

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