12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package logic
- import (
- cm "app.yhyue.com/moapp/jybase/common"
- elastic "app.yhyue.com/moapp/jybase/esv1"
- "context"
- "fmt"
- "github.com/zeromicro/go-zero/core/logx"
- . "knowledgeBase/rpc/knowledge/init"
- "knowledgeBase/rpc/knowledge/internal/svc"
- "knowledgeBase/rpc/knowledge/knowledgeclient"
- "knowledgeBase/rpc/knowledge/util"
- "strconv"
- )
- type FindAnswerLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewFindAnswerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindAnswerLogic {
- return &FindAnswerLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- func (l *FindAnswerLogic) FindAnswer(in *knowledgeclient.FindAnswerReq) (*knowledgeclient.FindAnswerResp, error) {
- // todo: add your logic here and delete this line
- var question *knowledgeclient.Question
- tenantId := strconv.Itoa(int(in.TenantId))
- query := util.DSL4SmartResponse(in.Question, tenantId, int(in.Type))
- fmt.Println("query:", query)
- res := elastic.Get(C.Es.Index, C.Es.Type, query)
- if res != nil && len(*res) > 0 {
- data := (*res)[0]
- question.XId = cm.ObjToString(data["_id"])
- question.Answer = cm.ObjToString(data["answer"])
- question.Question = cm.ObjToString(data["question"])
- }
- fmt.Println("根据问题匹配答案:", question)
- return &knowledgeclient.FindAnswerResp{
- ErrorCode: 1,
- ErrorMsg: "请求成功",
- Data: question,
- }, nil
- }
|