1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- package logic
- import (
- "context"
- "database/sql"
- "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"
- "time"
- )
- type KnowledgeAddLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewKnowledgeAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *KnowledgeAddLogic {
- return &KnowledgeAddLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- type Question struct {
- Question string `json:"question"`
- KeyWords string `json:"keyWords"`
- }
- // 知识新增
- 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{}{"state": 1, "appid": in.AppId, "tenant_id": in.TenantId}
- datalist := Mysql.Find(util.KNOWLEDGE, query, "id", "", -1, -1)
- if datalist != nil && *datalist != nil && len(*datalist) > 0 {
- fool := Mysql.ExecTx("创建其他订单生成订单信息和合同信息", func(tx *sql.Tx) bool {
- //插入答案
- answerData := map[string]interface{}{
- "knowledge_id": (*datalist)[0]["id"],
- "status": 1,
- "create_time": time.Now().Local().Format(util.Date_Full_Layout),
- "update_time": time.Now().Local().Format(util.Date_Full_Layout),
- "create_person": in.Person,
- "content": in.Answer,
- }
- answer_id := Mysql.Insert(util.ANSWER, answerData)
- if answer_id <= 0 {
- return false
- }
- //插入问题
- //先分词
- keywords := util.HttpDo(in.Question)
- questionData := map[string]interface{}{
- "answer_id": answer_id,
- "content": 1,
- "keywords": keywords,
- }
- question_id := Mysql.Insert(util.QUESTION, questionData)
- if question_id <= 0 {
- return false
- }
- return true
- })
- if fool {
- result.ErrorCode = 0
- } else {
- result.ErrorCode = -1
- result.ErrorMsg = "新建失败"
- }
- } else {
- log.Println("租户不存在")
- result.ErrorCode = -1
- result.ErrorMsg = "租户不存在"
- }
- return result, nil
- }
|