knowledgeaddlogic.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package logic
  2. import (
  3. "context"
  4. <<<<<<< HEAD
  5. "database/sql"
  6. "github.com/zeromicro/go-zero/core/logx"
  7. "knowledgeBase/rpc/knowledge/init"
  8. "knowledgeBase/rpc/knowledge/knowledgeclient"
  9. "time"
  10. "knowledgeBase/rpc/knowledge/internal/svc"
  11. "log"
  12. =======
  13. "knowledgeBase/rpc/knowledge/knowledgeclient"
  14. "github.com/tal-tech/go-zero/core/logx"
  15. "knowledgeBase/rpc/knowledge/internal/svc"
  16. >>>>>>> origin/master
  17. )
  18. type KnowledgeAddLogic struct {
  19. ctx context.Context
  20. svcCtx *svc.ServiceContext
  21. logx.Logger
  22. }
  23. func NewKnowledgeAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *KnowledgeAddLogic {
  24. return &KnowledgeAddLogic{
  25. ctx: ctx,
  26. svcCtx: svcCtx,
  27. Logger: logx.WithContext(ctx),
  28. }
  29. }
  30. <<<<<<< HEAD
  31. type Question struct {
  32. Question string `json:"question"`
  33. KeyWords string `json:"keyWords"`
  34. }
  35. // 知识新增
  36. func (l *KnowledgeAddLogic) KnowledgeAdd(in *knowledgeclient.AddRequest) (*knowledgeclient.AddResponse, bool) {
  37. // todo: add your logic here and delete this line
  38. result := &knowledgeclient.AddResponse{}
  39. //先查找知识库Id
  40. query := map[string]interface{}{"state": 1, "appid": in.AppId, "tenant_id": in.TenantId}
  41. datalist := init.Mysql.Find(init.KNOWLEDGE, query, "id", "", -1, -1)
  42. if datalist != nil && *datalist != nil && len(*datalist) > 0 {
  43. return result, init.Mysql.ExecTx("创建其他订单生成订单信息和合同信息", func(tx *sql.Tx) bool {
  44. //插入答案
  45. answerData := map[string]interface{}{
  46. "knowledge_id": (*datalist)[0]["id"],
  47. "status": 1,
  48. "create_time": time.Now().Local().Format(init.Date_Full_Layout),
  49. "update_time": time.Now().Local().Format(init.Date_Full_Layout),
  50. "create_person": in.Person,
  51. "content": in.Answer,
  52. }
  53. answer_id := init.Mysql.Insert(init.ANSWER, answerData)
  54. if answer_id <= 0 {
  55. return false
  56. }
  57. //插入问题
  58. questionData := map[string]interface{}{
  59. "answer_id": answer_id,
  60. "content": 1,
  61. "keywords": "",
  62. }
  63. question_id := init.Mysql.Insert(init.QUESTION, questionData)
  64. if question_id <= 0 {
  65. return false
  66. }
  67. return true
  68. })
  69. } else {
  70. log.Println("租户不存在")
  71. result.ErrorCode = -1
  72. result.ErrorMsg = "租户不存在"
  73. }
  74. return result, true
  75. =======
  76. // 知识新增
  77. func (l *KnowledgeAddLogic) KnowledgeAdd(in *knowledgeclient.AddRequest) (*knowledgeclient.AddResponse, error) {
  78. // todo: add your logic here and delete this line
  79. return &knowledgeclient.AddResponse{}, nil
  80. >>>>>>> origin/master
  81. }