12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package controller
- import (
- v1 "aiChat/api/v1"
- "aiChat/internal/model"
- "aiChat/utility"
- "app.yhyue.com/moapp/jybase/encrypt"
- "github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/os/glog"
- )
- // ChatHistory 获取聊天记录
- func ChatHistory(r *ghttp.Request) {
- final := func() (res v1.ChatHistoryRes) {
- res = v1.ChatHistoryRes{}
- session, _ := utility.GetSession(r)
- if session.AccountId == 0 {
- res.ErrorCode = -1
- res.ErrorMsg = "未登陆"
- return
- }
- pageSize := r.Get("PageSize", 5).Int()
- pageNum := r.Get("PageNum", 0).Int()
- history, err := model.Message.GetMessage(session.AccountId, pageNum, pageSize)
- if err != nil {
- glog.Error(r.Context(), "%d查询聊天记录异常,error:%s", session.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
- }()
- r.Response.Write(final)
- }
|