Update AgentChatHistoryServiceImpl.java

添加降序排序,
1.改用id的原因:数据形式,id越大的创建时间就越晚,所以使用id的结果和创建时间降序排列结果一样
 2.id作为降序排列的优势,性能高,有主键索引,不用在排序的时候重新进行排除扫描比较
This commit is contained in:
gitjianyu
2025-07-28 14:12:42 +08:00
committed by GitHub
parent 1b3a55b105
commit 99f6209c57
@@ -104,7 +104,10 @@ public class AgentChatHistoryServiceImpl extends ServiceImpl<AiAgentChatHistoryD
.eq(AgentChatHistoryEntity::getAgentId, agentId)
.eq(AgentChatHistoryEntity::getChatType, AgentChatHistoryType.USER.getValue())
.isNotNull(AgentChatHistoryEntity::getAudioId)
.orderByDesc(AgentChatHistoryEntity::getCreatedAt); // 添加此行,确保查询结果按照创建时间降序排列
// 添加此行,确保查询结果按照创建时间降序排列
// 使用id的原因:数据形式,id越大的创建时间就越晚,所以使用id的结果和创建时间降序排列结果一样
// id作为降序排列的优势,性能高,有主键索引,不用在排序的时候重新进行排除扫描比较
.orderByDesc(AgentChatHistoryEntity::getId);
// 构建分页查询,查询前50页数据
Page<AgentChatHistoryEntity> pageParam = new Page<>(0, 50);