save_api_chat_logic.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package chatrecords
  2. import (
  3. "context"
  4. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  5. "github.com/zeromicro/go-zero/core/errorx"
  6. "wechat-api/internal/svc"
  7. "wechat-api/internal/types"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type SaveApiChatLogic struct {
  11. logx.Logger
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. }
  15. func NewSaveApiChatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveApiChatLogic {
  16. return &SaveApiChatLogic{
  17. Logger: logx.WithContext(ctx),
  18. ctx: ctx,
  19. svcCtx: svcCtx}
  20. }
  21. func (l *SaveApiChatLogic) SaveApiChat(req *types.ChatRecordsInfo) (*types.BaseMsgResp, error) {
  22. userId := l.ctx.Value("userId").(uint64)
  23. sessionId := *req.SessionId
  24. // 记录下问题
  25. _, err := l.svcCtx.DB.ChatRecords.Create().
  26. SetUserID(userId).
  27. SetSessionID(sessionId).
  28. SetBotType(*req.BotType).
  29. SetBotID(*req.BotId).
  30. SetContentType(2).
  31. SetContent(*req.Content).
  32. Save(l.ctx)
  33. if err != nil {
  34. return nil, errorx.NewInternalError(err.Error())
  35. }
  36. return &types.BaseMsgResp{Msg: errormsg.Success}, nil
  37. }