knowledgeditlogic.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package logic
  2. import (
  3. "context"
  4. "github.com/zeromicro/go-zero/core/logx"
  5. . "knowledgeBase/rpc/knowledge/init"
  6. "knowledgeBase/rpc/knowledge/internal/svc"
  7. "knowledgeBase/rpc/knowledge/knowledgeclient"
  8. "knowledgeBase/rpc/knowledge/util"
  9. "time"
  10. )
  11. type KnowledgEditLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewKnowledgEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *KnowledgEditLogic {
  17. return &KnowledgEditLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. // 知识编辑
  24. func (l *KnowledgEditLogic) KnowledgEdit(in *knowledgeclient.KnowledgeEntity) (*knowledgeclient.AddResponse, error) {
  25. // todo: add your logic here and delete this line
  26. result := &knowledgeclient.AddResponse{}
  27. //修改答案
  28. answerUpdate := map[string]interface{}{
  29. "update_time": time.Now().Local().Format(util.Date_Full_Layout),
  30. "content": in.Answer,
  31. }
  32. if in.State == 0 {
  33. answerUpdate["state"] = 0
  34. }
  35. ok := Mysql.Update(util.ANSWER, map[string]interface{}{"id": in.AnswerId}, answerUpdate)
  36. keywords := util.HttpDo(in.Question)
  37. questionUpdate := map[string]interface{}{
  38. "content": 1,
  39. "keywords": keywords,
  40. }
  41. if !ok {
  42. result.ErrorCode = -1
  43. result.ErrorMsg = "答案修改失败"
  44. return result, nil
  45. }
  46. //修改问题
  47. ok = Mysql.Update(util.QUESTION, map[string]interface{}{"answerId": in.AnswerId}, questionUpdate)
  48. if in.State != 0 {
  49. //修改es数据
  50. }
  51. if !ok {
  52. result.ErrorCode = -1
  53. result.ErrorMsg = "问题修改失败"
  54. return result, nil
  55. }
  56. return result, nil
  57. }