knowledgeaddlogic.go 2.0 KB

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