12345678910111213141516171819202122232425262728293031323334353637 |
- package controller
- import (
- v1 "aiChat/api/v1"
- "aiChat/internal/model"
- "app.yhyue.com/moapp/jybase/encrypt"
- "context"
- "github.com/gogf/gf/v2/os/glog"
- )
- var (
- ChatHistory = cChatHistory{}
- )
- type cChatHistory struct{}
- // Method 获取聊天记录
- func (c *cChatHistory) Method(ctx context.Context, req *v1.ChatHistoryReq) (res *v1.ChatHistoryRes, err error) {
- res = &v1.ChatHistoryRes{}
- history, err := model.Message.GetMessage(model.SessionCtx.Get(ctx).JSession.AccountId, req.PageNum, req.PageSize)
- if err != nil {
- glog.Error(ctx, "%d查询聊天记录异常,error:%s", model.SessionCtx.Get(ctx).JSession.AccountId, err)
- res.ErrorCode = -1
- res.ErrorMsg = "数据查询异常"
- return
- }
- for _, v := range history {
- res.Data = append(res.Data, v1.History{
- Id: encrypt.SE.Encode2Hex(v.Id),
- Content: v.Content,
- Type: v.Type,
- Useful: v.Useful,
- CreateTime: v.CreateTime.Unix(),
- })
- }
- return
- }
|