瀏覽代碼

知识编辑修改

renjiaojiao 3 年之前
父節點
當前提交
12eb1cce89

+ 1 - 6
api/knowledge/internal/logic/knowledgeaddlogic.go

@@ -3,11 +3,9 @@ package logic
 import (
 	"context"
 	"github.com/zeromicro/go-zero/core/logx"
-	"knowledgeBase/rpc/knowledge/knowledgeclient"
-	"log"
-
 	"knowledgeBase/api/knowledge/internal/svc"
 	"knowledgeBase/api/knowledge/internal/types"
+	"knowledgeBase/rpc/knowledge/knowledgeclient"
 )
 
 type KnowledgeAddLogic struct {
@@ -25,9 +23,7 @@ func NewKnowledgeAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) Knowl
 }
 
 func (l *KnowledgeAddLogic) KnowledgeAdd(req types.AddKnowledgeReq) (*types.CommonRes, error) {
-	// todo: add your logic here and delete this line
 
-	log.Println("req.Answer", req.Answer)
 	resp, err := l.svcCtx.Knowledge.KnowledgeAdd(l.ctx, &knowledgeclient.AddRequest{
 		Question:  req.Question,
 		Answer:    req.Answer,
@@ -43,5 +39,4 @@ func (l *KnowledgeAddLogic) KnowledgeAdd(req types.AddKnowledgeReq) (*types.Comm
 		Error_code: int(resp.ErrorCode),
 		Data:       resp.Data,
 	}, nil
-	//return &types.CommonRes{}, nil
 }

+ 3 - 3
rpc/knowledge/etc/knowledge.yaml

@@ -7,9 +7,9 @@ Etcd:
 WebRpcPort: 8015
 MysqlMain:
   dbName: base_service
-  address: 192.168.3.11:3366
+  address: 192.168.3.217:4000
   userName: root
-  passWord: Topnet123
+  passWord: =PDT49#80Z!RVv52_z
   maxOpenConns: 5
   maxIdleConns: 5
 Es:
@@ -29,5 +29,5 @@ Node: 1
 UserCenterConf:
   Etcd:
     Hosts:
-      - 192.168.3.206:2379
+      - 192.168.3.240:2379
     Key: usercenter.rpc

+ 5 - 18
rpc/knowledge/internal/logic/knowledgeaddlogic.go

@@ -11,7 +11,6 @@ import (
 	"knowledgeBase/rpc/knowledge/internal/svc"
 	"knowledgeBase/rpc/knowledge/knowledgeclient"
 	"knowledgeBase/rpc/knowledge/util"
-	"log"
 	"time"
 )
 
@@ -36,31 +35,27 @@ type Question struct {
 
 // KnowledgeAdd 知识新增
 func (l *KnowledgeAddLogic) KnowledgeAdd(in *knowledgeclient.AddRequest) (*knowledgeclient.AddResponse, error) {
-	// todo: add your logic here and delete this line
 	result := &knowledgeclient.AddResponse{}
 	//先查找知识库Id
 	query := map[string]interface{}{"status": 1, "appid": in.AppId, "ent_id": in.EntId}
-	log.Println("查询知识库条件:", query)
 	datalist := Mysql.Find(util.KNOWLEDGE, query, "id", "", -1, -1)
 	if datalist != nil && *datalist != nil && len(*datalist) > 0 {
 		//问题进行分词
 		keywords := util.HttpDo(in.Question)
-		log.Println("分词", keywords)
-		//通过entUserId获取创建人名称
+		//通过entUserId获取创建人名称,调用用户中心
 		req := &usercenter.EntUserReq{
 			EntId:     in.EntId,
 			EntUserId: in.EntUserId,
 			AppId:     in.AppId,
 		}
 		resp, err := entity.UserCenterLib.GetEntUserInfo(context.Background(), req)
-		//0:失败 1:成功 -1:不在有效期内 -2:数量不足 -3:没有授权
-		if resp.ErrorCode == 0 || err != nil {
-			logx.Infof("查询用户中台创建人信息失败", in.EntId, resp.ErrorCode, "err:", err)
+		if err != nil {
+			logx.Infof("查询用户中台创建人信息失败", in.EntId, in.EntUserId, "err:", err)
 			return nil, err
 		}
 		createPerson := resp.Data.Name
-		nowTime := time.Now().Local().Format(util.Date_Full_Layout)
 		var answerId int64
+		nowTime := time.Now().Local().Format(util.Date_Full_Layout)
 		fool := Mysql.ExecTx("添加知识", func(tx *sql.Tx) bool {
 			//插入答案
 			answerData := map[string]interface{}{
@@ -72,9 +67,6 @@ func (l *KnowledgeAddLogic) KnowledgeAdd(in *knowledgeclient.AddRequest) (*knowl
 				"content":       in.Answer,
 			}
 			answerId = Mysql.Insert(util.ANSWER, answerData)
-			if answerId <= 0 {
-				return false
-			}
 			//插入问题
 			questionData := map[string]interface{}{
 				"answer_id": answerId,
@@ -82,10 +74,7 @@ func (l *KnowledgeAddLogic) KnowledgeAdd(in *knowledgeclient.AddRequest) (*knowl
 				"keywords":  keywords,
 			}
 			questionId := Mysql.Insert(util.QUESTION, questionData)
-			if questionId <= 0 {
-				return false
-			}
-			return true
+			return answerId > 0 && questionId > 0
 		})
 		if fool {
 			//插入es
@@ -101,7 +90,6 @@ func (l *KnowledgeAddLogic) KnowledgeAdd(in *knowledgeclient.AddRequest) (*knowl
 				"entId":        in.EntId,
 			}
 			b := elastic.Save(C.Es.Index, C.Es.Type, knowledge)
-			log.Println("存es", b)
 			if b {
 				result.ErrorCode = 0
 				result.ErrorMsg = "插入数据成功"
@@ -118,6 +106,5 @@ func (l *KnowledgeAddLogic) KnowledgeAdd(in *knowledgeclient.AddRequest) (*knowl
 		result.ErrorCode = -1
 		result.ErrorMsg = "租户不存在"
 	}
-	log.Println(result)
 	return result, nil
 }

+ 8 - 10
rpc/knowledge/internal/logic/knowledgeeditlogic.go

@@ -31,13 +31,8 @@ func NewKnowledgeEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Kno
 
 // KnowledgeEdit 知识编辑
 func (l *KnowledgeEditLogic) KnowledgeEdit(in *knowledgeclient.KnowledgeEditReq) (*knowledgeclient.AddResponse, error) {
-	// todo: add your logic here and delete this line
+
 	result := &knowledgeclient.AddResponse{}
-	//修改答案
-	answerUpdate := map[string]interface{}{
-		"update_time": time.Now().Local().Format(util.Date_Full_Layout),
-		"content":     in.Answer,
-	}
 	//获取问题分词
 	keywords := util.HttpDo(in.Question)
 	//通过entUserId获取创建人名称
@@ -47,13 +42,17 @@ func (l *KnowledgeEditLogic) KnowledgeEdit(in *knowledgeclient.KnowledgeEditReq)
 		AppId:     in.AppId,
 	}
 	resp, err := entity.UserCenterLib.GetEntUserInfo(context.Background(), req)
-	//0:失败 1:成功 -1:不在有效期内 -2:数量不足 -3:没有授权
-	if resp.ErrorCode == 0 || err != nil {
-		logx.Infof("查询用户中台创建人信息失败", in.EntId, resp.ErrorCode, "err:", err)
+	if err != nil {
+		logx.Infof("查询用户中台创建人信息失败", in.EntId, in.EntUserId, "err:", err)
 		return nil, err
 	}
 	createPerson := resp.Data.Name
 	fool := Mysql.ExecTx("编辑问题、答案", func(tx *sql.Tx) bool {
+		//修改答案
+		answerUpdate := map[string]interface{}{
+			"update_time": time.Now().Local().Format(util.Date_Full_Layout),
+			"content":     in.Answer,
+		}
 		ok1 := Mysql.UpdateByTx(tx, util.ANSWER, map[string]interface{}{"id": in.AnswerId}, answerUpdate)
 		//修改问题
 		questionUpdate := map[string]interface{}{
@@ -65,7 +64,6 @@ func (l *KnowledgeEditLogic) KnowledgeEdit(in *knowledgeclient.KnowledgeEditReq)
 	})
 
 	if fool {
-		//先查询es获取es _id
 		query := `{"query":{"bool":{"must":[{"term":{"answerId":"` + strconv.Itoa(int(in.AnswerId)) + `"}}],"must_not":[],"should":[]}},"from":0,"size":10,"sort":[],"facets":{}}`
 		//修改es数据
 		newKnowledge := map[string]interface{}{