12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package logic
- import (
- "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/api/messagecenter/util"
- "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
- "bp.jydev.jianyu360.cn/SocialPlatform/socialPlatform/entity"
- "bp.jydev.jianyu360.cn/SocialPlatform/socialPlatform/rpc/social/social"
- "context"
- "net/http"
- "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/api/messagecenter/internal/svc"
- "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/api/messagecenter/internal/types"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type MessageCountLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- r *http.Request
- }
- func NewMessageCountLogic(ctx context.Context, svcCtx *svc.ServiceContext, r *http.Request) *MessageCountLogic {
- return &MessageCountLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- r: r,
- }
- }
- func (l *MessageCountLogic) MessageCount(req *types.CountReq) (resp *types.CommonRes, err error) {
- if req.NewUserId == 0 {
- sessionId, trustedId, stErr := util.GetTouristCookieInfo(l.r)
- if stErr != nil {
- resp.Error_code = 1
- resp.Error_msg = stErr.Error()
- return resp, nil
- }
- result, rErr := l.svcCtx.Social.TouristInfo(l.ctx, &social.TouristInfoReq{
- SessionId: sessionId,
- Ip: entity.GetIp(l.r),
- TrustedId: trustedId,
- })
- if rErr != nil || result.Data.BaseUserId == 0 {
- resp.Error_code = 1
- resp.Error_msg = "当用户信息有误"
- logx.Error("获取当前游客信息有误:", rErr.Error())
- return resp, rErr
- }
- req.NewUserId = result.Data.BaseUserId
- }
- res, err := l.svcCtx.Message.Count(l.ctx, &messagecenter.CountReq{
- UserType: req.UserType,
- EntUserId: req.EntUserId,
- NewUserId: req.NewUserId,
- PositionId: req.PositionId,
- })
- if err != nil {
- return nil, err
- }
- resp = &types.CommonRes{
- Error_msg: res.ErrorMsg,
- Error_code: int(res.ErrorCode),
- Count: res.Count,
- Data: res.LastMessage,
- }
- return resp, nil
- }
|