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}`
|
const BASE_URL = `${API_BASE.APP_TIK}`
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取启用的智能体列表
|
* 获取启用的智能体列表
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -179,7 +179,6 @@ import {
|
|||||||
SearchOutlined,
|
SearchOutlined,
|
||||||
RobotOutlined,
|
RobotOutlined,
|
||||||
CloseOutlined,
|
CloseOutlined,
|
||||||
ArrowRightOutlined,
|
|
||||||
MessageOutlined,
|
MessageOutlined,
|
||||||
AppstoreOutlined,
|
AppstoreOutlined,
|
||||||
StarOutlined,
|
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
|
if (a.isFavorite === b.isFavorite) return 0
|
||||||
return a.isFavorite ? -1 : 1
|
return a.isFavorite ? -1 : 1
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -55,11 +55,9 @@ public class AiAgentFavoriteServiceImpl implements AiAgentFavoriteService {
|
|||||||
@Override
|
@Override
|
||||||
public Set<Long> getFavoriteAgentIds(Long userId) {
|
public Set<Long> getFavoriteAgentIds(Long userId) {
|
||||||
List<AiAgentFavoriteDO> favorites = aiAgentFavoriteMapper.selectListByUserId(userId);
|
List<AiAgentFavoriteDO> favorites = aiAgentFavoriteMapper.selectListByUserId(userId);
|
||||||
Set<Long> agentIds = new HashSet<>();
|
return favorites.stream()
|
||||||
for (AiAgentFavoriteDO favorite : favorites) {
|
.map(AiAgentFavoriteDO::getAgentId)
|
||||||
agentIds.add(favorite.getAgentId());
|
.collect(java.util.stream.Collectors.toSet());
|
||||||
}
|
|
||||||
return agentIds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user