refactor(agent): 优化收藏功能代码实现
- 前端移除未使用的 ArrowRightOutlined 导入 - 优化智能体列表排序逻辑,避免修改原数组 - 后端使用 Stream API 简化收藏智能体 ID 获取逻辑
This commit is contained in:
@@ -8,7 +8,6 @@ import { API_BASE } from '@gold/config/api'
|
||||
|
||||
const BASE_URL = `${API_BASE.APP_TIK}`
|
||||
|
||||
|
||||
/**
|
||||
* 获取启用的智能体列表
|
||||
*/
|
||||
|
||||
@@ -179,7 +179,6 @@ import {
|
||||
SearchOutlined,
|
||||
RobotOutlined,
|
||||
CloseOutlined,
|
||||
ArrowRightOutlined,
|
||||
MessageOutlined,
|
||||
AppstoreOutlined,
|
||||
StarOutlined,
|
||||
@@ -246,8 +245,8 @@ const filteredAgentList = computed(() => {
|
||||
)
|
||||
}
|
||||
|
||||
// 收藏的智能体置顶
|
||||
return list.sort((a, b) => {
|
||||
// 收藏的智能体置顶(复制数组避免修改原数组)
|
||||
return [...list].sort((a, b) => {
|
||||
if (a.isFavorite === b.isFavorite) return 0
|
||||
return a.isFavorite ? -1 : 1
|
||||
})
|
||||
|
||||
@@ -55,11 +55,9 @@ public class AiAgentFavoriteServiceImpl implements AiAgentFavoriteService {
|
||||
@Override
|
||||
public Set<Long> getFavoriteAgentIds(Long userId) {
|
||||
List<AiAgentFavoriteDO> favorites = aiAgentFavoriteMapper.selectListByUserId(userId);
|
||||
Set<Long> agentIds = new HashSet<>();
|
||||
for (AiAgentFavoriteDO favorite : favorites) {
|
||||
agentIds.add(favorite.getAgentId());
|
||||
}
|
||||
return agentIds;
|
||||
return favorites.stream()
|
||||
.map(AiAgentFavoriteDO::getAgentId)
|
||||
.collect(java.util.stream.Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user