1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package controller
- import (
- v1 "aiChat/api/aiChat/v1"
- "aiChat/internal/model"
- "app.yhyue.com/moapp/jybase/encrypt"
- "context"
- "fmt"
- "github.com/gogf/gf/v2/frame/g"
- )
- var (
- ChatHistory = cChatHistory{}
- )
- type cChatHistory struct{}
- // Method 获取聊天记录
- func (c *cChatHistory) Method(ctx context.Context, req *v1.ChatHistoryReq) (res *v1.ChatHistoryRes, err error) {
- session := model.SessionCtx.Get(ctx).JSession
- if session.PositionId <= 0 {
- return nil, fmt.Errorf("请登录")
- }
- res = &v1.ChatHistoryRes{}
- if req.PrevId != "" {
- req.PrevId = encrypt.SE.Decode4Hex(req.PrevId) //id解密
- }
- history, hasNext, err := model.ChatHistory.GetMessage(session.PositionId, req.PageNum, req.PageSize, req.PrevId)
- if err != nil {
- g.Log().Error(ctx, "%d查询聊天记录异常,error:%s", session.PositionId, err)
- res.ErrorCode = -1
- res.ErrorMsg = "数据查询异常"
- return
- }
- res.Data.HasMore = hasNext
- for _, v := range history {
- res.Data.List = append(res.Data.List, v1.History{
- Id: encrypt.SE.Encode2Hex(v.Id),
- Content: v.Content,
- Type: v.Type,
- Useful: v.Useful,
- Actions: v.Actions,
- CreateTime: v.CreateTime.Unix(),
- })
- }
- return
- }
|