chatHistory.go 950 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package controller
  2. import (
  3. v1 "aiChat/api/v1"
  4. "aiChat/internal/model"
  5. "app.yhyue.com/moapp/jybase/encrypt"
  6. "context"
  7. "github.com/gogf/gf/v2/os/glog"
  8. )
  9. var (
  10. ChatHistory = cChatHistory{}
  11. )
  12. type cChatHistory struct{}
  13. // Method 获取聊天记录
  14. func (c *cChatHistory) Method(ctx context.Context, req *v1.ChatHistoryReq) (res *v1.ChatHistoryRes, err error) {
  15. res = &v1.ChatHistoryRes{}
  16. history, err := model.Message.GetMessage(model.SessionCtx.Get(ctx).JSession.AccountId, req.PageNum, req.PageSize)
  17. if err != nil {
  18. glog.Error(ctx, "%d查询聊天记录异常,error:%s", model.SessionCtx.Get(ctx).JSession.AccountId, err)
  19. res.ErrorCode = -1
  20. res.ErrorMsg = "数据查询异常"
  21. return
  22. }
  23. for _, v := range history {
  24. res.Data = append(res.Data, v1.History{
  25. Id: encrypt.SE.Encode2Hex(v.Id),
  26. Content: v.Content,
  27. Type: v.Type,
  28. Useful: v.Useful,
  29. CreateTime: v.CreateTime.Unix(),
  30. })
  31. }
  32. return
  33. }