Browse Source

修改记录的统计来源

kobe6258 2 weeks ago
parent
commit
034a06a0af
2 changed files with 13 additions and 15 deletions
  1. 9 3
      controllers/llm/user_chat_controller.go
  2. 4 12
      models/llm/user_llm_chat.go

+ 9 - 3
controllers/llm/user_chat_controller.go

@@ -195,18 +195,24 @@ func (ucCtrl *UserChatController) GetUserChatList() {
 		br.Msg = "获取用户聊天列表失败"
 		br.ErrMsg = "获取用户聊天列表失败,Err:" + err.Error()
 		return
+	}
+	for _, chat := range chatList {
+
 	}
 	data := new(llm_http.UserChatListResp)
 	data.WeekList = make([]llm.UserLlmChatListViewItem, 0)
 	data.YesterdayList = make([]llm.UserLlmChatListViewItem, 0)
 	data.TodayList = make([]llm.UserLlmChatListViewItem, 0)
 	for _, v := range chatList {
+		list, _ := llmService.GetChatRecordsFromRedis(v.Id)
+		item := llm.CovertItemToView(v)
+		item.RecordCount = len(list)
 		if v.CreatedTime.Format(utils.FormatDate) == today {
-			data.TodayList = append(data.TodayList, llm.CovertItemToView(v))
+			data.TodayList = append(data.TodayList, item)
 		} else if v.CreatedTime.Format(utils.FormatDate) == yesterday {
-			data.YesterdayList = append(data.YesterdayList, llm.CovertItemToView(v))
+			data.YesterdayList = append(data.YesterdayList, item)
 		} else {
-			data.WeekList = append(data.WeekList, llm.CovertItemToView(v))
+			data.WeekList = append(data.WeekList, item)
 		}
 	}
 

+ 4 - 12
models/llm/user_llm_chat.go

@@ -16,13 +16,7 @@ type UserLlmChat struct {
 	UpdateTime  time.Time `gorm:"autoUpdateTime;comment:更新时间"`
 }
 
-type UserLlmChatListItem struct {
-	Id          int       `gorm:"primaryKey;autoIncrement;comment:会话主键"`
-	UserId      int       `gorm:"comment:用户id"`
-	ChatTitle   string    `gorm:"comment:会话标题"`
-	CreatedTime time.Time `gorm:"comment:创建时间"`
-	RecordCount int       `gorm:"comment:会话记录数"`
-}
+
 type UserLlmChatListViewItem struct {
 	Id          int    `gorm:"primaryKey;autoIncrement;comment:会话主键"`
 	UserId      int    `gorm:"comment:用户id"`
@@ -31,13 +25,12 @@ type UserLlmChatListViewItem struct {
 	RecordCount int    `gorm:"comment:会话记录数"`
 }
 
-func CovertItemToView(item UserLlmChatListItem) UserLlmChatListViewItem {
+func CovertItemToView(item UserLlmChat) UserLlmChatListViewItem {
 	return UserLlmChatListViewItem{
 		Id:          item.Id,
 		UserId:      item.UserId,
 		ChatTitle:   item.ChatTitle,
 		CreatedTime: item.CreatedTime.Format(utils.FormatDateTime),
-		RecordCount: item.RecordCount,
 	}
 
 }
@@ -72,10 +65,9 @@ func (u *UserLlmChat) DeleteChatSession() (err error) {
 	err = o.Select("is_deleted").Updates(u).Error
 	return
 }
-func GetUserChatList(userId int, monDay, toDay string) (chatList []UserLlmChatListItem, err error) {
+func GetUserChatList(userId int, monDay, toDay string) (chatList []UserLlmChat, err error) {
 	o := global.DbMap[utils.DbNameAI]
-	sql := `select ulc.id AS id ,ulc.user_id as user_id,ulc.chat_title as chat_title,ulc.created_time,COUNT(ucr.id) AS record_count from user_llm_chat ulc left join user_chat_record ucr
-    ON ucr.chat_id = ulc.id where ulc.user_id=? and ` + utils.GenerateQuerySql(utils.ToDate, &utils.QueryParam{Column: "ulc.created_time"}) + ` BETWEEN ? and ? AND is_deleted=0 GROUP BY ulc.id order by ulc.created_time desc`
+	sql := `select ulc.id AS id ,ulc.user_id as user_id,ulc.chat_title as chat_title,ulc.created_time from user_llm_chat ulc  where ulc.user_id=? and ` + utils.GenerateQuerySql(utils.ToDate, &utils.QueryParam{Column: "ulc.created_time"}) + ` BETWEEN ? and ? AND is_deleted=0 GROUP BY ulc.id order by ulc.created_time desc`
 	err = o.Raw(sql, userId, monDay, toDay).Find(&chatList).Error
 	return
 }