|
@@ -1,14 +1,41 @@
|
|
|
package aiChat
|
|
|
|
|
|
import (
|
|
|
+ "aiChat/internal/model"
|
|
|
+ "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
"context"
|
|
|
-
|
|
|
- "github.com/gogf/gf/v2/errors/gcode"
|
|
|
- "github.com/gogf/gf/v2/errors/gerror"
|
|
|
+ "fmt"
|
|
|
+ "github.com/gogf/gf/v2/frame/g"
|
|
|
|
|
|
"aiChat/api/aiChat/v1"
|
|
|
)
|
|
|
|
|
|
func (c *ControllerV1) ChatHistory(ctx context.Context, req *v1.ChatHistoryReq) (res *v1.ChatHistoryRes, err error) {
|
|
|
- return nil, gerror.NewCode(gcode.CodeNotImplemented)
|
|
|
+ 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
|
|
|
}
|