Explorar o código

猜你想问接口

renjiaojiao %!s(int64=2) %!d(string=hai) anos
pai
achega
2341eb4a12

+ 28 - 0
api/knowledge/internal/handler/guesstoaskhandler.go

@@ -0,0 +1,28 @@
+package handler
+
+import (
+	"github.com/zeromicro/go-zero/rest/httpx"
+	"net/http"
+
+	"bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/api/knowledge/internal/logic"
+	"bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/api/knowledge/internal/svc"
+	"bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/api/knowledge/internal/types"
+)
+
+func guessToAskHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.GuessToAskReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewGuessToAskLogic(r.Context(), ctx)
+		resp, err := l.GuessToAsk(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 6 - 0
api/knowledge/internal/handler/routes.go

@@ -7,6 +7,7 @@ import (
 
 	"bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/api/knowledge/internal/svc"
 
+
 )
 
 func RegisterHandlers(engine *rest.Server, serverCtx *svc.ServiceContext) {
@@ -47,6 +48,11 @@ func RegisterHandlers(engine *rest.Server, serverCtx *svc.ServiceContext) {
 				Path:    "/knowledge/recommendAnswer",
 				Handler: recommendAnswerHandler(serverCtx),
 			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/knowledge/guessToAsk",
+				Handler: guessToAskHandler(serverCtx),
+			},
 			{
 				Method:  http.MethodPost,
 				Path:    "/knowledge/commonPhrase/commonPhrasesAddOrUpdate",

+ 43 - 0
api/knowledge/internal/logic/guesstoasklogic.go

@@ -0,0 +1,43 @@
+package logic
+
+import (
+	. "app.yhyue.com/moapp/jybase/encrypt"
+	"bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/rpc/knowledge/knowledgeclient"
+	"context"
+	"github.com/zeromicro/go-zero/core/logx"
+
+	"bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/api/knowledge/internal/svc"
+	"bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/api/knowledge/internal/types"
+)
+
+type GuessToAskLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGuessToAskLogic(ctx context.Context, svcCtx *svc.ServiceContext) GuessToAskLogic {
+	return GuessToAskLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *GuessToAskLogic) GuessToAsk(req types.GuessToAskReq) (*types.CommonRes, error) {
+	// todo: add your logic here and delete this line
+	resp, err := l.svcCtx.Knowledge.RecommendAnswer(l.ctx, &knowledgeclient.FindAnswerReq{
+		Type:       req.Type,
+		RobotEntId: SE.Decode4Hex(req.EntId),
+		Question:   req.Question,
+		ReqSource:  req.ReqSource,
+	})
+	if err != nil {
+		return nil, err
+	}
+	return &types.CommonRes{
+		Error_code: int(resp.ErrorCode),
+		Error_msg:  resp.ErrorMsg,
+		Data:       resp.Data,
+	}, nil
+}

+ 0 - 1
api/knowledge/internal/logic/recommendanswerlogic.go

@@ -28,7 +28,6 @@ func (l *RecommendAnswerLogic) RecommendAnswer(req types.RecommendAnswerReq) (*t
 		Type:       req.Type,
 		RobotEntId: req.RobotEntId,
 		Question:   req.Question,
-		ReqSource:  req.ReqSource,
 	})
 	if err != nil {
 		return nil, err

+ 8 - 2
api/knowledge/internal/types/types.go

@@ -18,8 +18,14 @@ type FindAnswerReq struct {
 type RecommendAnswerReq struct {
 	Question   string `json:"question"`
 	RobotEntId string `header:"entId"`
-	Type       int64  `json:"type"`      //1 文字  2 语音
-	ReqSource  int64  `json:"reqSource"` //0 客服端请求 1 用户端请求
+	Type       int64  `json:"type"` //1 文字  2 语音
+}
+
+type GuessToAskReq struct {
+	Question  string `json:"question"`
+	EntId     string `json:"entId"`
+	Type      int64  `json:"type"`      //1 文字  2 语音
+	ReqSource int64  `json:"reqSource"` // 1
 }
 
 type ListReq struct {

+ 9 - 2
api/knowledge/knowledge.api

@@ -14,8 +14,13 @@ type FindAnswerReq {
 type RecommendAnswerReq {
 	Question   string `json:"question"`
 	RobotEntId string `header:"entId"`
-	Type       int64  `json:"type"`      //1 文字  2 语音
-	ReqSource  int64  `json:"reqSource"` //0 客服端请求 1 用户端请求
+	Type       int64  `json:"type"` //1 文字  2 语音
+}
+type GuessToAskReq {
+	Question  string `json:"question"`
+	EntId     string `json:"entId"`
+	Type      int64  `json:"type"`      //1 文字  2 语音
+	ReqSource int64  `json:"reqSource"` // 1
 }
 
 type ListReq {
@@ -89,6 +94,8 @@ service knowledge-api {
 	post /knowledge/findAnswer (FindAnswerReq) returns (CommonRes);
 	@handler recommendAnswer
 	post /knowledge/recommendAnswer (RecommendAnswerReq) returns (CommonRes);
+	@handler guessToAsk
+	post /knowledge/guessToAsk (GuessToAskReq) returns (CommonRes);
 	@handler commonPhrasesAddOrUpdate
 	post /knowledge/commonPhrase/commonPhrasesAddOrUpdate (CommonPhrasesAddReq) returns (CommonRes);
 	@handler commonPhrasesInfo