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" "log" ) 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) { var question knowledgeclient.Question //组装es query query := util.DSL4SmartResponse(in.Question, in.RobotEntId, int(in.Type)) fmt.Println("query:", query) res := elastic.Get(C.Es.Index, C.Es.Type, query) log.Println("结果:", res) if res != nil && len(*res) > 0 { data := (*res)[0] log.Println(data["answer"]) question.Answer = cm.ObjToString(data["answer"]) question.Question = cm.ObjToString(data["question"]) } return &knowledgeclient.FindAnswerResp{ ErrorCode: 0, ErrorMsg: "请求成功", Data: &question, }, nil }