findanswerlogic.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package logic
  2. import (
  3. cm "app.yhyue.com/moapp/jybase/common"
  4. . "app.yhyue.com/moapp/jybase/encrypt"
  5. elastic "app.yhyue.com/moapp/jybase/esv1"
  6. "context"
  7. "github.com/zeromicro/go-zero/core/logx"
  8. . "knowledgeBase/rpc/knowledge/init"
  9. "knowledgeBase/rpc/knowledge/internal/svc"
  10. "knowledgeBase/rpc/knowledge/knowledgeclient"
  11. "knowledgeBase/rpc/knowledge/util"
  12. "log"
  13. )
  14. type FindAnswerLogic struct {
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. logx.Logger
  18. }
  19. func NewFindAnswerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindAnswerLogic {
  20. return &FindAnswerLogic{
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. Logger: logx.WithContext(ctx),
  24. }
  25. }
  26. func (l *FindAnswerLogic) FindAnswer(in *knowledgeclient.FindAnswerReq) (*knowledgeclient.FindAnswerResp, error) {
  27. var question knowledgeclient.Question
  28. robotEntId := SE.Decode4Hex(in.RobotEntId)
  29. log.Println("机器人企业id:", robotEntId)
  30. //组装es query
  31. query := util.DSL4SmartResponse(in.Question, robotEntId, int(in.Type))
  32. res := elastic.Get(C.Es.Index, C.Es.Type, query)
  33. if res != nil && len(*res) > 0 {
  34. data := (*res)[0]
  35. question.Answer = cm.ObjToString(data["answer"])
  36. question.Question = cm.ObjToString(data["question"])
  37. }
  38. return &knowledgeclient.FindAnswerResp{
  39. ErrorCode: 0,
  40. ErrorMsg: "请求成功",
  41. Data: &question,
  42. }, nil
  43. }