Browse Source

wip:消息保存

wangshan 11 months ago
parent
commit
b2e2c27008

+ 7 - 0
.idea/workspace.xml

@@ -6,6 +6,13 @@
   <component name="ChangeListManager">
     <list default="true" id="8ae7f6f2-adc5-4a6a-b6f0-2ff3221f7b1f" name="变更" comment="">
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/api/messagecenter/internal/handler/messageaddhandler.go" beforeDir="false" afterPath="$PROJECT_DIR$/api/messagecenter/internal/handler/messageaddhandler.go" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/api/messagecenter/internal/logic/findmessagelogic.go" beforeDir="false" afterPath="$PROJECT_DIR$/api/messagecenter/internal/logic/findmessagelogic.go" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/api/messagecenter/internal/logic/messageaddlogic.go" beforeDir="false" afterPath="$PROJECT_DIR$/api/messagecenter/internal/logic/messageaddlogic.go" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/api/messagecenter/internal/logic/messagecountlogic.go" beforeDir="false" afterPath="$PROJECT_DIR$/api/messagecenter/internal/logic/messagecountlogic.go" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/api/messagecenter/internal/types/types.go" beforeDir="false" afterPath="$PROJECT_DIR$/api/messagecenter/internal/types/types.go" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/api/messagecenter/messagecenter.api" beforeDir="false" afterPath="$PROJECT_DIR$/api/messagecenter/messagecenter.api" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/api/messagecenter/util/util.go" beforeDir="false" afterPath="$PROJECT_DIR$/api/messagecenter/util/util.go" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />

+ 1 - 1
api/messagecenter/internal/handler/messageaddhandler.go

@@ -17,7 +17,7 @@ func messageAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 			return
 		}
 
-		l := logic.NewMessageAddLogic(r.Context(), svcCtx)
+		l := logic.NewMessageAddLogic(r.Context(), svcCtx, r)
 		resp, err := l.MessageAdd(&req)
 		if err != nil {
 			httpx.Error(w, err)

+ 4 - 19
api/messagecenter/internal/logic/findmessagelogic.go

@@ -4,8 +4,6 @@ import (
 	quitl "app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/encrypt"
 	"bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/api/messagecenter/util"
-	"bp.jydev.jianyu360.cn/SocialPlatform/socialPlatform/entity"
-	"bp.jydev.jianyu360.cn/SocialPlatform/socialPlatform/rpc/social/social"
 	"context"
 	"net/http"
 
@@ -34,24 +32,11 @@ func NewFindMessageLogic(ctx context.Context, svcCtx *svc.ServiceContext, r *htt
 func (l *FindMessageLogic) FindMessage(req *types.MessageReq) (resp *types.CommonRes, err error) {
 	resp = &types.CommonRes{}
 	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
+		r, err := util.GetTouristInfo(l.r, l.svcCtx.Social, l.ctx)
+		if err != nil || r.BaseUserId == 0 {
+			return nil, err
 		}
-		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
+		req.NewUserId = r.BaseUserId
 	}
 	var res *messagecenter.MessageResp
 	res, err = l.svcCtx.Message.FindMessage(l.ctx, &messagecenter.MessageReq{

+ 12 - 1
api/messagecenter/internal/logic/messageaddlogic.go

@@ -1,7 +1,9 @@
 package logic
 
 import (
+	"bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/api/messagecenter/util"
 	"context"
+	"net/http"
 
 	quitl "app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/encrypt"
@@ -19,13 +21,15 @@ type MessageAddLogic struct {
 	logx.Logger
 	ctx    context.Context
 	svcCtx *svc.ServiceContext
+	r      *http.Request
 }
 
-func NewMessageAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MessageAddLogic {
+func NewMessageAddLogic(ctx context.Context, svcCtx *svc.ServiceContext, r *http.Request) *MessageAddLogic {
 	return &MessageAddLogic{
 		Logger: logx.WithContext(ctx),
 		ctx:    ctx,
 		svcCtx: svcCtx,
+		r:      r,
 	}
 }
 
@@ -41,6 +45,13 @@ func init() {
 }
 
 func (l *MessageAddLogic) MessageAdd(req *types.MessageEntity) (*types.CommonRes, error) {
+	if req.NewUserId == 0 {
+		r, err := util.GetTouristInfo(l.r, l.svcCtx.Social, l.ctx)
+		if err != nil || r.BaseUserId == 0 {
+			return nil, err
+		}
+		req.NewUserId = r.BaseUserId
+	}
 	receiverIds := []int64{}
 	for _, v := range req.ReceiverIds {
 		receiverIds = append(receiverIds, gconv.Int64(encrypt.SE.Decode4Hex(v)))

+ 4 - 19
api/messagecenter/internal/logic/messagecountlogic.go

@@ -3,8 +3,6 @@ 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"
 
@@ -32,24 +30,11 @@ func NewMessageCountLogic(ctx context.Context, svcCtx *svc.ServiceContext, r *ht
 
 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
+		r, err := util.GetTouristInfo(l.r, l.svcCtx.Social, l.ctx)
+		if err != nil || r.BaseUserId == 0 {
+			return nil, err
 		}
-		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
+		req.NewUserId = r.BaseUserId
 	}
 	res, err := l.svcCtx.Message.Count(l.ctx, &messagecenter.CountReq{
 		UserType:   req.UserType,

+ 2 - 2
api/messagecenter/internal/types/types.go

@@ -38,11 +38,11 @@ type MessageEntity struct {
 	Item        int64    `json:"item"`
 	Type        int64    `json:"type"`
 	Link        string   `json:"link"`
-	Appid       string   `header:"appId"`
+	Appid       string   `header:"appId,optional"`
 	ItemType    int64    `json:"itemType"`
 	SendId      string   `json:"sendId,optional"`
 	EntUserId   int64    `header:"entUserId,optional"`
-	NewUserId   int64    `header:"newUserId"`
+	NewUserId   int64    `header:"newUserId,optional"`
 	ReceiveId   string   `json:"receiveId,optional"`
 	ReceiverIds []string `json:"receiverIds,optional"` //个人[可多个]
 	GroupIds    []string `json:"groupIds,optional"`    //群聊[可多个]

+ 2 - 2
api/messagecenter/messagecenter.api

@@ -34,11 +34,11 @@ type MessageEntity {
 	Item        int64    `json:"item"`
 	Type        int64    `json:"type"`
 	Link        string   `json:"link"`
-	Appid       string   `header:"appId"`
+	Appid       string   `header:"appId,optional"`
 	ItemType    int64    `json:"itemType"`
 	SendId      string   `json:"sendId,optional"`
 	EntUserId   int64    `header:"entUserId,optional"`
-	NewUserId   int64    `header:"newUserId"`
+	NewUserId   int64    `header:"newUserId,optional"`
 	ReceiveId   string   `json:"receiveId,optional"`
 	ReceiverIds []string `json:"receiverIds,optional"` //个人[可多个]
 	GroupIds    []string `json:"groupIds,optional"`    //群聊[可多个]

+ 22 - 1
api/messagecenter/util/util.go

@@ -1,7 +1,9 @@
 package util
 
 import (
-	"bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/entity"
+	"bp.jydev.jianyu360.cn/SocialPlatform/socialPlatform/entity"
+	"bp.jydev.jianyu360.cn/SocialPlatform/socialPlatform/rpc/social/social"
+	"context"
 	"fmt"
 	"github.com/zeromicro/go-zero/core/logx"
 	"net/http"
@@ -24,3 +26,22 @@ func GetTouristCookieInfo(r *http.Request) (sessionId, trustedId string, err err
 	trustedId = ti.Value
 	return
 }
+
+// tourist
+func GetTouristInfo(r *http.Request, sl social.Social, ctx context.Context) (ti *social.TouristInfo, err error) {
+	sessionId, trustedId, stErr := GetTouristCookieInfo(r)
+	if stErr != nil {
+		return nil, stErr
+	}
+	result, rErr := sl.TouristInfo(ctx, &social.TouristInfoReq{
+		SessionId: sessionId,
+		Ip:        entity.GetIp(r),
+		TrustedId: trustedId,
+	})
+	if rErr != nil || result.Data.BaseUserId == 0 {
+		logx.Error(result, "-获取当前游客信息有误:", rErr.Error())
+		return nil, rErr
+	}
+	ti = result.Data
+	return
+}