Przeglądaj źródła

对前端入参企业id解密

renjiaojiao 3 lat temu
rodzic
commit
7ef0cf7ed0

+ 1 - 1
api/knowledge/internal/types/types.go

@@ -11,7 +11,7 @@ type AddKnowledgeReq struct {
 
 type FindAnswerReq struct {
 	Question   string `json:"question"`
-	RobotEntId int64  `json:"robotEntId"`
+	RobotEntId string `json:"robotEntId"`
 	Type       int64  `json:"type"` //1 文字  2 语音
 }
 

+ 1 - 1
api/knowledge/knowledge.api

@@ -8,7 +8,7 @@ type AddKnowledgeReq {
 
 type FindAnswerReq {
 	Question   string `json:"question"`
-	RobotEntId int64  `json:"robotEntId"`
+	RobotEntId string `json:"robotEntId"`
 	Type       int64  `json:"type"` //1 文字  2 语音
 }
 

+ 3 - 6
rpc/knowledge/internal/logic/findanswerlogic.go

@@ -2,15 +2,14 @@ package logic
 
 import (
 	cm "app.yhyue.com/moapp/jybase/common"
+	. "app.yhyue.com/moapp/jybase/encrypt"
 	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 {
@@ -29,14 +28,12 @@ func NewFindAnswerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindAn
 
 func (l *FindAnswerLogic) FindAnswer(in *knowledgeclient.FindAnswerReq) (*knowledgeclient.FindAnswerResp, error) {
 	var question knowledgeclient.Question
+	robotEntId := SE.Decode4Hex(in.RobotEntId)
 	//组装es query
-	query := util.DSL4SmartResponse(in.Question, in.RobotEntId, int(in.Type))
-	fmt.Println("query:", query)
+	query := util.DSL4SmartResponse(in.Question, robotEntId, int(in.Type))
 	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"])
 	}

+ 4 - 4
rpc/knowledge/internal/logic/recommendanswerlogic.go

@@ -1,16 +1,16 @@
 package logic
 
+import "C"
 import (
 	cm "app.yhyue.com/moapp/jybase/common"
+	. "app.yhyue.com/moapp/jybase/encrypt"
 	elastic "app.yhyue.com/moapp/jybase/esv1"
 	"context"
 	"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"
-	"strconv"
 )
 
 type RecommendAnswerLogic struct {
@@ -38,9 +38,9 @@ func (l *RecommendAnswerLogic) RecommendAnswer(in *knowledgeclient.FindAnswerReq
 	keyWords = util.HttpDo(in.Question)
 	log.Println("问题分词关键字:", keyWords)
 	if keyWords != "" {
-		var query = util.DSL4SearchByKwsOrid(keyWords, strconv.Itoa(int(in.RobotEntId)))
+		var query = util.DSL4SearchByKwsOrid(keyWords, SE.Decode4Hex(in.RobotEntId))
 		res := elastic.GetAllByNgram(C.Es.Index, C.Es.Type, query, "", "", searchField, 0, 3, 0, false)
-		//log.Println("link_obj:", link_obj)
+
 		if res != nil && len(*res) > 0 {
 			for _, val := range *res {
 				answers = append(answers, &knowledgeclient.Question{

+ 1 - 2
rpc/knowledge/knowledge.proto

@@ -26,9 +26,8 @@ message AddResponse{
 
 message FindAnswerReq{
   string question = 1;
-  int64 robotEntId = 2;//机器人的企业id
+  string robotEntId = 2;//机器人的企业id
   int64 type = 3;// 1文字  2语音
-  //  string appId = 4;
 }
 
 message FindAnswerResp{

+ 5 - 5
rpc/knowledge/knowledge/knowledge.pb.go

@@ -235,8 +235,8 @@ type FindAnswerReq struct {
 	unknownFields protoimpl.UnknownFields
 
 	Question   string `protobuf:"bytes,1,opt,name=question,proto3" json:"question,omitempty"`
-	RobotEntId int64  `protobuf:"varint,2,opt,name=robotEntId,proto3" json:"robotEntId,omitempty"` //机器人的企业id
-	Type       int64  `protobuf:"varint,3,opt,name=type,proto3" json:"type,omitempty"`             // 1文字  2语音
+	RobotEntId string `protobuf:"bytes,2,opt,name=robotEntId,proto3" json:"robotEntId,omitempty"` //机器人的企业id
+	Type       int64  `protobuf:"varint,3,opt,name=type,proto3" json:"type,omitempty"`            // 1文字  2语音
 }
 
 func (x *FindAnswerReq) Reset() {
@@ -278,11 +278,11 @@ func (x *FindAnswerReq) GetQuestion() string {
 	return ""
 }
 
-func (x *FindAnswerReq) GetRobotEntId() int64 {
+func (x *FindAnswerReq) GetRobotEntId() string {
 	if x != nil {
 		return x.RobotEntId
 	}
-	return 0
+	return ""
 }
 
 func (x *FindAnswerReq) GetType() int64 {
@@ -919,7 +919,7 @@ var file_knowledge_proto_rawDesc = []byte{
 	0x41, 0x6e, 0x73, 0x77, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x71, 0x75, 0x65,
 	0x73, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x71, 0x75, 0x65,
 	0x73, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1e, 0x0a, 0x0a, 0x72, 0x6f, 0x62, 0x6f, 0x74, 0x45, 0x6e,
-	0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x72, 0x6f, 0x62, 0x6f, 0x74,
+	0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x72, 0x6f, 0x62, 0x6f, 0x74,
 	0x45, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20,
 	0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x74, 0x0a, 0x0e, 0x46, 0x69, 0x6e,
 	0x64, 0x41, 0x6e, 0x73, 0x77, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1d, 0x0a, 0x0a, 0x65,

+ 7 - 7
rpc/knowledge/knowledgeclient/knowledge.go

@@ -13,18 +13,18 @@ import (
 )
 
 type (
+	FindAnswerReq       = knowledge.FindAnswerReq
+	FindAnswerResp      = knowledge.FindAnswerResp
+	KnowledgeEditReq    = knowledge.KnowledgeEditReq
+	Question            = knowledge.Question
+	AddResponse         = knowledge.AddResponse
 	ListData            = knowledge.ListData
 	ListRequest         = knowledge.ListRequest
 	ListResponse        = knowledge.ListResponse
-	KnowledgeEditReq    = knowledge.KnowledgeEditReq
-	InfoResponse        = knowledge.InfoResponse
-	AddRequest          = knowledge.AddRequest
-	AddResponse         = knowledge.AddResponse
-	FindAnswerResp      = knowledge.FindAnswerResp
 	KnowledgeEntity     = knowledge.KnowledgeEntity
+	InfoResponse        = knowledge.InfoResponse
 	KnowledgeDelReq     = knowledge.KnowledgeDelReq
-	Question            = knowledge.Question
-	FindAnswerReq       = knowledge.FindAnswerReq
+	AddRequest          = knowledge.AddRequest
 	RecommendAnswerResp = knowledge.RecommendAnswerResp
 
 	Knowledge interface {

+ 2 - 4
rpc/knowledge/util/elasticsearch_dsl.go

@@ -4,7 +4,6 @@ import (
 	"fmt"
 	. "knowledgeBase/rpc/knowledge/init"
 	"log"
-	"strconv"
 	"strings"
 )
 
@@ -12,7 +11,7 @@ import (
 	项目中所用到的几类查询dsl语句构建工具类
 */
 
-func DSL4SmartResponse(question string, entId int64, msgType int) string {
+func DSL4SmartResponse(question string, entId string, msgType int) string {
 	var (
 		totalQuery = `{"post_filter":{%s},"query":{%s},"_source":[%s],"size":%d}`
 		postFilter = `"script":{"script":"def sk=_source.must_keywords;def n=0;for(item in sk){ n++;if(que.indexOf(item)>-1){return true}};if(n==0){ return true}","params":{"que":"%s"}}`
@@ -33,7 +32,6 @@ func DSL4SmartResponse(question string, entId int64, msgType int) string {
 		} else if lenQuestion < 12 {
 			queryPercent = "55%"
 		}
-		log.Println("消息类型:", msgType)
 		if msgType == 1 {
 			typeStr = "keywords"
 		} else if msgType == 2 { //百度语音过来的
@@ -45,7 +43,7 @@ func DSL4SmartResponse(question string, entId int64, msgType int) string {
 		if mustque != "" {
 			postFilter = fmt.Sprintf(postFilter, mustque)
 		}
-		query = fmt.Sprintf(query, "", typeStr, question, queryPercent, strconv.Itoa(int(entId)))
+		query = fmt.Sprintf(query, "", typeStr, question, queryPercent, entId)
 		queryDSL := fmt.Sprintf(totalQuery, postFilter, query, `"answer","question"`, 1)
 		log.Println("queryDSL:", queryDSL)
 		return queryDSL