Эх сурвалжийг харах

RecommendAnswer企业id从header里取

renjiaojiao 2 жил өмнө
parent
commit
6641485eef

+ 3 - 0
api/etc/api-api.yaml

@@ -0,0 +1,3 @@
+Name: api-api
+Host: 0.0.0.0
+Port: 8888

+ 7 - 0
api/internal/config/config.go

@@ -0,0 +1,7 @@
+package config
+
+import "github.com/tal-tech/go-zero/rest"
+
+type Config struct {
+	rest.RestConf
+}

+ 29 - 0
api/internal/handler/apihandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"api/internal/logic"
+	"api/internal/svc"
+	"api/internal/types"
+
+	"github.com/tal-tech/go-zero/rest/httpx"
+)
+
+func ApiHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.Request
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewApiLogic(r.Context(), ctx)
+		resp, err := l.Api(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 22 - 0
api/internal/handler/routes.go

@@ -0,0 +1,22 @@
+// Code generated by goctl. DO NOT EDIT.
+package handler
+
+import (
+	"net/http"
+
+	"api/internal/svc"
+
+	"github.com/tal-tech/go-zero/rest"
+)
+
+func RegisterHandlers(engine *rest.Server, serverCtx *svc.ServiceContext) {
+	engine.AddRoutes(
+		[]rest.Route{
+			{
+				Method:  http.MethodGet,
+				Path:    "/from/:name",
+				Handler: ApiHandler(serverCtx),
+			},
+		},
+	)
+}

+ 30 - 0
api/internal/logic/apilogic.go

@@ -0,0 +1,30 @@
+package logic
+
+import (
+	"context"
+
+	"api/internal/svc"
+	"api/internal/types"
+
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type ApiLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) ApiLogic {
+	return ApiLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *ApiLogic) Api(req types.Request) (*types.Response, error) {
+	// todo: add your logic here and delete this line
+
+	return &types.Response{}, nil
+}

+ 15 - 0
api/internal/svc/servicecontext.go

@@ -0,0 +1,15 @@
+package svc
+
+import (
+	"api/internal/config"
+)
+
+type ServiceContext struct {
+	Config config.Config
+}
+
+func NewServiceContext(c config.Config) *ServiceContext {
+	return &ServiceContext{
+		Config: c,
+	}
+}

+ 10 - 0
api/internal/types/types.go

@@ -0,0 +1,10 @@
+// Code generated by goctl. DO NOT EDIT.
+package types
+
+type Request struct {
+	Name string `path:"name,options=you|me"`
+}
+
+type Response struct {
+	Message string `json:"message"`
+}

+ 29 - 0
api/knowledge/internal/handler/knowledgehandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"knowledge/internal/logic"
+	"knowledge/internal/svc"
+	"knowledge/internal/types"
+
+	"github.com/tal-tech/go-zero/rest/httpx"
+)
+
+func KnowledgeHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.Request
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewKnowledgeLogic(r.Context(), ctx)
+		resp, err := l.Knowledge(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 2 - 1
api/knowledge/internal/handler/routes.go

@@ -2,10 +2,11 @@
 package handler
 
 import (
-	"github.com/zeromicro/go-zero/rest"
 	"net/http"
 
 	"bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/api/knowledge/internal/svc"
+
+	"github.com/tal-tech/go-zero/rest"
 )
 
 func RegisterHandlers(engine *rest.Server, serverCtx *svc.ServiceContext) {

+ 30 - 0
api/knowledge/internal/logic/knowledgelogic.go

@@ -0,0 +1,30 @@
+package logic
+
+import (
+	"context"
+
+	"knowledge/internal/svc"
+	"knowledge/internal/types"
+
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type KnowledgeLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewKnowledgeLogic(ctx context.Context, svcCtx *svc.ServiceContext) KnowledgeLogic {
+	return KnowledgeLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *KnowledgeLogic) Knowledge(req types.Request) (*types.Response, error) {
+	// todo: add your logic here and delete this line
+
+	return &types.Response{}, nil
+}

+ 6 - 0
api/knowledge/internal/types/types.go

@@ -15,6 +15,12 @@ type FindAnswerReq struct {
 	Type       int64  `json:"type"` //1 文字  2 语音
 }
 
+type RecommendAnswerReq struct {
+	Question   string `json:"question"`
+	RobotEntId string `header:"entId"`
+	Type       int64  `json:"type"` //1 文字  2 语音
+}
+
 type ListReq struct {
 	PageSize  int64 `json:"pageSize"`
 	PageIndex int64 `json:"pageIndex"`

+ 63 - 0
api/knowledge/knowledge.api

@@ -0,0 +1,63 @@
+type AddKnowledgeReq {
+	Question  string `json:"question"`
+	Answer    string `json:"answer"`
+	EntId     int64  `header:"entId"`
+	AppId     string `header:"appId"`
+	EntUserId int64  `header:"entUserId"`
+}
+
+type FindAnswerReq {
+	Question   string `json:"question"`
+	RobotEntId string `json:"robotEntId"`
+	Type       int64  `json:"type"` //1 文字  2 语音
+}
+type RecommendAnswerReq {
+	Question   string `json:"question"`
+	RobotEntId string `header:"entId"`
+	Type       int64  `json:"type"` //1 文字  2 语音
+}
+
+type ListReq {
+	PageSize  int64 `json:"pageSize"`
+	PageIndex int64 `json:"pageIndex"`
+	EntId     int64 `header:"entId"`
+}
+type InfoReq {
+	AnswerId int64 `json:"answerId"`
+}
+
+type EditReq {
+	Question    string `json:"question"`
+	Answer      string `json:"answer"`
+	EntUserId   int64  `header:"entUserId"`
+	AnswerId    int64  `json:"answerId"`
+	EntId       int64  `header:"entId"`
+	KnowledgeId int64  `json:"knowledgeId"`
+	AppId       string `header:"appId"`
+}
+type DeleteReq {
+	AnswerId int64 `json:"answerId"`
+}
+
+type CommonRes {
+	Error_code int         `json:"error_code"`
+	Error_msg  string      `json:"error_msg"`
+	Data       interface{} `json:"data"`
+}
+
+service knowledge-api {
+	@handler knowledgeAdd
+	post /knowledge/knowledgeAdd (AddKnowledgeReq) returns (CommonRes);
+	@handler knowledgeList
+	post /knowledge/knowledgeList (ListReq) returns (CommonRes);
+	@handler knowledgeInfo
+	post /knowledge/knowledgeInfo (InfoReq) returns (CommonRes);
+	@handler knowledgeEdit
+	post /knowledge/knowledgeEdit (EditReq) returns (CommonRes);
+	@handler knowledgeDel
+	post /knowledge/knowledgeDel (DeleteReq) returns (CommonRes);
+	@handler findAnswer
+	post /knowledge/findAnswer (FindAnswerReq) returns (CommonRes);
+	@handler recommendAnswer
+	post /knowledge/recommendAnswer (RecommendAnswerReq) returns (CommonRes);
+}