|
@@ -5,14 +5,16 @@ import (
|
|
|
. "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
elastic "app.yhyue.com/moapp/jybase/esv1"
|
|
|
"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
|
|
|
+ . "bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/entity"
|
|
|
+ "bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/rpc/knowledge/internal/config"
|
|
|
+
|
|
|
+ //. "bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/rpc/knowledge/init"
|
|
|
+ "bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/rpc/knowledge/knowledgeclient"
|
|
|
+ "bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/rpc/knowledge/util"
|
|
|
"context"
|
|
|
"database/sql"
|
|
|
"errors"
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
- "knowledgeBase/entity"
|
|
|
- . "knowledgeBase/rpc/knowledge/init"
|
|
|
- "knowledgeBase/rpc/knowledge/knowledgeclient"
|
|
|
- "knowledgeBase/rpc/knowledge/util"
|
|
|
"log"
|
|
|
"strconv"
|
|
|
"time"
|
|
@@ -20,15 +22,20 @@ import (
|
|
|
|
|
|
type KnowledgeService struct{}
|
|
|
|
|
|
+var (
|
|
|
+ Index = "smart_new"
|
|
|
+ Type = "smart"
|
|
|
+)
|
|
|
+
|
|
|
func (k *KnowledgeService) KnowledgeAdd(param *knowledgeclient.AddRequest) (bool, string, error) {
|
|
|
//先查找知识库Id
|
|
|
query := map[string]interface{}{"status": 1, "appid": param.AppId, "ent_id": param.EntId}
|
|
|
datalist := Mysql.Find(util.KNOWLEDGE, query, "id", "", -1, -1)
|
|
|
if datalist != nil && *datalist != nil && len(*datalist) > 0 {
|
|
|
//问题进行分词
|
|
|
- keywords := util.HttpDo(param.Question)
|
|
|
- if keywords == "" {
|
|
|
- keywords = param.Question
|
|
|
+ keywords := util.HanlpGetNormalWords(param.Question, config.C.Segment)
|
|
|
+ if len(keywords) == 0 {
|
|
|
+ keywords = append(keywords, param.Question)
|
|
|
}
|
|
|
//通过entUserId获取创建人名称,调用用户中心
|
|
|
req := &usercenter.EntUserReq{
|
|
@@ -36,9 +43,9 @@ func (k *KnowledgeService) KnowledgeAdd(param *knowledgeclient.AddRequest) (bool
|
|
|
EntUserId: param.EntUserId,
|
|
|
AppId: param.AppId,
|
|
|
}
|
|
|
- resp, err := entity.UserCenterLib.GetEntUserInfo(context.Background(), req)
|
|
|
+ resp, err := UserCenterLib.GetEntUserInfo(context.Background(), req)
|
|
|
if err != nil {
|
|
|
- logx.Infof("查询用户中台创建人信息失败", param.EntId, param.EntUserId, "err:", err)
|
|
|
+ logx.Info("查询用户中台创建人信息失败", param.EntId, param.EntUserId, "err:", err)
|
|
|
return false, "查询用户中台创建人信息失败", err
|
|
|
}
|
|
|
createPerson := resp.Data.Name
|
|
@@ -77,7 +84,7 @@ func (k *KnowledgeService) KnowledgeAdd(param *knowledgeclient.AddRequest) (bool
|
|
|
"answerId": answerId,
|
|
|
"entId": param.EntId,
|
|
|
}
|
|
|
- b := elastic.Save(C.Es.Index, C.Es.Type, knowledge)
|
|
|
+ b := elastic.Save(Index, Type, knowledge)
|
|
|
if b {
|
|
|
return true, "插入es成功", nil
|
|
|
} else {
|
|
@@ -104,9 +111,9 @@ func (k *KnowledgeService) KnowledgeEdit(param *knowledgeclient.KnowledgeEditReq
|
|
|
AppId: param.AppId,
|
|
|
}
|
|
|
resp := &usercenter.EntUserResp{}
|
|
|
- resp, err = entity.UserCenterLib.GetEntUserInfo(context.Background(), req)
|
|
|
+ resp, err = UserCenterLib.GetEntUserInfo(context.Background(), req)
|
|
|
if err != nil {
|
|
|
- logx.Infof("查询用户中台创建人信息失败", param.EntId, param.EntUserId, "err:", err)
|
|
|
+ logx.Info("查询用户中台创建人信息失败", param.EntId, param.EntUserId, "err:", err)
|
|
|
return false, "查询用户中台创建人信息失败", err
|
|
|
}
|
|
|
createPerson := resp.Data.Name
|
|
@@ -140,8 +147,8 @@ func (k *KnowledgeService) KnowledgeEdit(param *knowledgeclient.KnowledgeEditReq
|
|
|
"answerId": param.AnswerId,
|
|
|
"entId": param.EntId,
|
|
|
}
|
|
|
- ok1 := elastic.Del(C.Es.Index, C.Es.Type, query)
|
|
|
- ok := elastic.Save(C.Es.Index, C.Es.Type, newKnowledge)
|
|
|
+ ok1 := elastic.Del(Index, Type, query)
|
|
|
+ ok := elastic.Save(Index, Type, newKnowledge)
|
|
|
if ok && ok1 {
|
|
|
ok = true
|
|
|
msg = "修改问题成功"
|
|
@@ -216,7 +223,7 @@ func (k *KnowledgeService) KnowledgeDel(answerId int64) (ok bool, msg string) {
|
|
|
if fool {
|
|
|
//删除es数据
|
|
|
query := `{"query":{"bool":{"must":[{"term":{"answerId":"` + strconv.Itoa(int(answerId)) + `"}}],"must_not":[],"should":[]}},"from":0,"size":10,"sort":[],"facets":{}}`
|
|
|
- ok := elastic.Del(C.Es.Index, C.Es.Type, query)
|
|
|
+ ok := elastic.Del(Index, Type, query)
|
|
|
if ok {
|
|
|
return true, "删除成功"
|
|
|
} else {
|
|
@@ -233,7 +240,7 @@ func (k *KnowledgeService) FindAnswer(param *knowledgeclient.FindAnswerReq) *kno
|
|
|
//组装es query
|
|
|
query := util.DSL4SmartResponse(param.Question, robotEntId, int(param.Type))
|
|
|
logx.Info("es查询:", query)
|
|
|
- res := elastic.Get(C.Es.Index, C.Es.Type, query)
|
|
|
+ res := elastic.Get(Index, Type, query)
|
|
|
if res != nil && len(*res) > 0 {
|
|
|
data := (*res)[0]
|
|
|
question.Answer = cm.ObjToString(data["answer"])
|
|
@@ -252,7 +259,7 @@ func (k *KnowledgeService) RecommendAnswer(param *knowledgeclient.FindAnswerReq)
|
|
|
keyWords = util.HttpDo(param.Question)
|
|
|
log.Println("问题分词关键字:", keyWords)
|
|
|
var query = util.DSL4SearchByKwsOrid(keyWords, SE.Decode4Hex(param.RobotEntId))
|
|
|
- res := elastic.GetAllByNgram(C.Es.Index, C.Es.Type, query, "", "", searchField, 0, 3, 0, false)
|
|
|
+ res := elastic.GetAllByNgram(Index, Type, query, "", "", searchField, 0, 3, 0, false)
|
|
|
//log.Println("推荐3个答案:", res)
|
|
|
if res != nil && len(*res) > 0 {
|
|
|
for _, val := range *res {
|