feat: 修复
This commit is contained in:
@@ -203,7 +203,6 @@ import FullWidthLayout from '@/layouts/components/FullWidthLayout.vue'
|
|||||||
import ChatDrawer from '@/components/agents/ChatDrawer.vue'
|
import ChatDrawer from '@/components/agents/ChatDrawer.vue'
|
||||||
import HistoryPanel from '@/components/agents/HistoryPanel.vue'
|
import HistoryPanel from '@/components/agents/HistoryPanel.vue'
|
||||||
import { getAgentList, addFavorite, removeFavorite } from '@/api/agent'
|
import { getAgentList, addFavorite, removeFavorite } from '@/api/agent'
|
||||||
import tokenManager from '@gold/utils/token-manager'
|
|
||||||
|
|
||||||
// 状态管理
|
// 状态管理
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
@@ -357,11 +356,6 @@ const handleChat = (agent) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleHistory = (agent) => {
|
const handleHistory = (agent) => {
|
||||||
// 检查登录状态
|
|
||||||
if (!tokenManager.isLoggedIn()) {
|
|
||||||
message.warning('请先登录')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
historyAgentId.value = agent.id
|
historyAgentId.value = agent.id
|
||||||
historyPanelVisible.value = true
|
historyPanelVisible.value = true
|
||||||
}
|
}
|
||||||
@@ -374,27 +368,22 @@ const handleSendMessage = (data) => {
|
|||||||
console.log('发送消息:', data)
|
console.log('发送消息:', data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 收藏切换
|
// 收藏切换(乐观更新)
|
||||||
const handleFavorite = async (agent) => {
|
const handleFavorite = async (agent) => {
|
||||||
// 检查登录状态
|
const newStatus = !agent.isFavorite
|
||||||
if (!tokenManager.isLoggedIn()) {
|
agent.isFavorite = newStatus // 立即更新 UI
|
||||||
message.warning('请先登录')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (agent.isFavorite) {
|
if (newStatus) {
|
||||||
await removeFavorite(agent.id)
|
|
||||||
agent.isFavorite = false
|
|
||||||
message.success('已取消收藏')
|
|
||||||
} else {
|
|
||||||
await addFavorite(agent.id)
|
await addFavorite(agent.id)
|
||||||
agent.isFavorite = true
|
|
||||||
message.success('收藏成功')
|
message.success('收藏成功')
|
||||||
|
} else {
|
||||||
|
await removeFavorite(agent.id)
|
||||||
|
message.success('已取消收藏')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch {
|
||||||
console.error('收藏操作失败:', error)
|
agent.isFavorite = !newStatus // 失败时回滚
|
||||||
message.error('操作失败,请重试')
|
message.error('操作失败')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ package cn.iocoder.yudao.module.tik.muye.aiagent.mapper;
|
|||||||
|
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
import cn.iocoder.yudao.module.tik.muye.aiagent.dal.AiAgentFavoriteDO;
|
import cn.iocoder.yudao.module.tik.muye.aiagent.dal.AiAgentFavoriteDO;
|
||||||
|
import org.apache.ibatis.annotations.Delete;
|
||||||
|
import org.apache.ibatis.annotations.Insert;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -18,4 +21,16 @@ public interface AiAgentFavoriteMapper extends BaseMapperX<AiAgentFavoriteDO> {
|
|||||||
return selectList(AiAgentFavoriteDO::getUserId, userId);
|
return selectList(AiAgentFavoriteDO::getUserId, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插入收藏(幂等:重复时更新时间)
|
||||||
|
*/
|
||||||
|
@Insert("INSERT INTO muye_ai_agent_favorite (user_id, agent_id, creator, create_time, updater, update_time, deleted, tenant_id) VALUES (#{userId}, #{agentId}, #{userId}, NOW(), #{userId}, NOW(), 0, 1) ON DUPLICATE KEY UPDATE update_time = NOW(), deleted = 0")
|
||||||
|
void insertOrUpdate(@Param("userId") Long userId, @Param("agentId") Long agentId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物理删除收藏记录(绕过逻辑删除)
|
||||||
|
*/
|
||||||
|
@Delete("DELETE FROM muye_ai_agent_favorite WHERE id = #{id}")
|
||||||
|
void deletePhysicsById(@Param("id") Long id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import jakarta.annotation.Resource;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -27,19 +26,10 @@ public class AiAgentFavoriteServiceImpl implements AiAgentFavoriteService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long createFavorite(Long userId, Long agentId) {
|
public Long createFavorite(Long userId, Long agentId) {
|
||||||
// 检查是否已收藏(幂等:已存在则直接返回)
|
// 幂等插入:重复时更新时间
|
||||||
AiAgentFavoriteDO existFavorite = aiAgentFavoriteMapper.selectByUserIdAndAgentId(userId, agentId);
|
aiAgentFavoriteMapper.insertOrUpdate(userId, agentId);
|
||||||
if (existFavorite != null) {
|
AiAgentFavoriteDO favorite = aiAgentFavoriteMapper.selectByUserIdAndAgentId(userId, agentId);
|
||||||
return existFavorite.getId();
|
return favorite != null ? favorite.getId() : null;
|
||||||
}
|
|
||||||
|
|
||||||
// 创建收藏
|
|
||||||
AiAgentFavoriteDO favorite = AiAgentFavoriteDO.builder()
|
|
||||||
.userId(userId)
|
|
||||||
.agentId(agentId)
|
|
||||||
.build();
|
|
||||||
aiAgentFavoriteMapper.insert(favorite);
|
|
||||||
return favorite.getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -48,7 +38,7 @@ public class AiAgentFavoriteServiceImpl implements AiAgentFavoriteService {
|
|||||||
if (favorite == null) {
|
if (favorite == null) {
|
||||||
throw exception(FAVORITE_NOT_EXISTS);
|
throw exception(FAVORITE_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
aiAgentFavoriteMapper.deleteById(favorite.getId());
|
aiAgentFavoriteMapper.deletePhysicsById(favorite.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user