package logic import ( "context" "database/sql" "github.com/zeromicro/go-zero/core/logx" "knowledgeBase/rpc/knowledge/init" "knowledgeBase/rpc/knowledge/knowledgeclient" "time" "knowledgeBase/rpc/knowledge/internal/svc" "log" ) 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, bool) { // 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 := init.Mysql.Find(init.KNOWLEDGE, query, "id", "", -1, -1) if datalist != nil && *datalist != nil && len(*datalist) > 0 { return result, init.Mysql.ExecTx("创建其他订单生成订单信息和合同信息", func(tx *sql.Tx) bool { //插入答案 answerData := map[string]interface{}{ "knowledge_id": (*datalist)[0]["id"], "status": 1, "create_time": time.Now().Local().Format(init.Date_Full_Layout), "update_time": time.Now().Local().Format(init.Date_Full_Layout), "create_person": in.Person, "content": in.Answer, } answer_id := init.Mysql.Insert(init.ANSWER, answerData) if answer_id <= 0 { return false } //插入问题 questionData := map[string]interface{}{ "answer_id": answer_id, "content": 1, "keywords": "", } question_id := init.Mysql.Insert(init.QUESTION, questionData) if question_id <= 0 { return false } return true }) } else { log.Println("租户不存在") result.ErrorCode = -1 result.ErrorMsg = "租户不存在" } return result, true }