12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package logic
- import (
- "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"
- "time"
- )
- type KnowledgEditLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewKnowledgEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *KnowledgEditLogic {
- return &KnowledgEditLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- // 知识编辑
- func (l *KnowledgEditLogic) KnowledgEdit(in *knowledgeclient.KnowledgeEntity) (*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,
- }
- if in.State == 0 {
- answerUpdate["state"] = 0
- }
- ok := Mysql.Update(util.ANSWER, map[string]interface{}{"id": in.AnswerId}, answerUpdate)
- keywords := util.HttpDo(in.Question)
- questionUpdate := map[string]interface{}{
- "content": 1,
- "keywords": keywords,
- }
- if !ok {
- result.ErrorCode = -1
- result.ErrorMsg = "答案修改失败"
- return result, nil
- }
- //修改问题
- ok = Mysql.Update(util.QUESTION, map[string]interface{}{"answerId": in.AnswerId}, questionUpdate)
- if in.State != 0 {
- //修改es数据
- }
- if !ok {
- result.ErrorCode = -1
- result.ErrorMsg = "问题修改失败"
- return result, nil
- }
- return result, nil
- }
|