jianghan 5 ヶ月 前
コミット
1701cea064

+ 1 - 1
api/aiSearch/v1/aiSearchApi.go

@@ -36,7 +36,7 @@ type HistorySsListRes struct {
 
 type SessionDetailReq struct {
 	g.Meta `path:"/session/detail" tags:"AiSearch" method:"post" summary:"会话详情"`
-	SId    string `json:"sId" dc:"当前会话id"`
+	SId    int64 `json:"sId" dc:"当前会话id"`
 }
 
 type SessionDetailRes struct {

+ 50 - 2
internal/controller/aiSearch/aiSearch_v1_history_ss_list.go

@@ -4,6 +4,8 @@ import (
 	"aiChat/internal/model"
 	"context"
 	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/os/gtime"
+	"time"
 
 	"github.com/gogf/gf/v2/errors/gcode"
 	"github.com/gogf/gf/v2/errors/gerror"
@@ -11,9 +13,55 @@ import (
 	"aiChat/api/aiSearch/v1"
 )
 
+type ChatItem struct {
+	Item       int        `json:"item"`
+	Question   string     `json:"question"`
+	Like       int        `json:"like"`
+	SessionId  int64      `json:"session_id"`
+	CreateTime gtime.Time `json:"create_time"`
+}
+
 func (c *ControllerV1) HistorySsList(ctx context.Context, req *v1.HistorySsListReq) (res *v1.HistorySsListRes, err error) {
 	jSession := model.SessionCtx.Get(ctx).JSession
 	all, count, err := g.Model("ai_search_chat").Fields("item", "question", "like", "session_id", "create_time").
-		Where("status = ? and position_id = ?", 1, jSession.PositionId).Limit(0, 10).AllAndCount(true)
-	return nil, gerror.NewCode(gcode.CodeNotImplemented)
+		Where("status = ? and position_id = ?", 1, jSession.PositionId).AllAndCount(true)
+	if err != nil {
+		g.Log().Error(ctx, "会话创建异常:%s", err)
+		return nil, gerror.NewCode(gcode.CodeInternalError)
+	}
+	mList := make(map[string]*[]ChatItem)
+	now := gtime.Now().Truncate(24 * time.Hour)
+	b7now := gtime.Now().Add(-7 * 24 * time.Hour).Truncate(24 * time.Hour) // 7天之前的日期
+	b1Mnow := gtime.Now().AddDate(0, -1, 0).Truncate(24 * time.Hour)       // 一个月之前的日期
+	for _, v := range all {
+		var item ChatItem
+		_ = v.Struct(&item)
+		var (
+			today    []ChatItem
+			b7Data   []ChatItem
+			bMData   []ChatItem
+			bOlddata []ChatItem
+		)
+
+		if item.CreateTime.Truncate(24 * time.Hour).Equal(now) { // 今天
+			today = append(today, item)
+		} else if item.CreateTime.Truncate(24 * time.Hour).After(b7now) { // 一周内
+			b7Data = append(b7Data, item)
+		} else if item.CreateTime.Truncate(24 * time.Hour).After(b1Mnow) { // 一个月之内
+			bMData = append(bMData, item)
+		} else { // 更早
+			bOlddata = append(bOlddata, item)
+		}
+		mList["今天"] = &today
+		mList["过去7天"] = &b7Data
+		mList["过去30天"] = &bMData
+		mList["更早"] = &bOlddata
+	}
+	res = &v1.HistorySsListRes{
+		ErrorCode: 0,
+		ErrorMsg:  "",
+		Data:      g.Map{"count": count, "list": mList},
+	}
+	return res, nil
+
 }

+ 19 - 4
internal/controller/aiSearch/aiSearch_v1_session_detail.go

@@ -1,14 +1,29 @@
 package aiSearch
 
 import (
+	"aiChat/api/aiSearch/v1"
 	"context"
-
 	"github.com/gogf/gf/v2/errors/gcode"
 	"github.com/gogf/gf/v2/errors/gerror"
-
-	"aiChat/api/aiSearch/v1"
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/os/gtime"
 )
 
+type SsDetail struct {
+	Id         int
+	Passport   string
+	Password   string
+	NickName   string
+	CreateTime *gtime.Time
+}
+
 func (c *ControllerV1) SessionDetail(ctx context.Context, req *v1.SessionDetailReq) (res *v1.SessionDetailRes, err error) {
-	return nil, gerror.NewCode(gcode.CodeNotImplemented)
+	results, err := g.Model("ai_search_chat").Where("session_id = ? and status = 1", req.SId).All()
+	if err != nil {
+		g.Log().Error(ctx, "会话详情查询异常:%s", err)
+		return nil, gerror.NewCode(gcode.CodeInternalError)
+	}
+	res.ErrorCode = 0
+	res.Data = results
+	return res, nil
 }