fix: 收藏 toggle 用原生 SQL 绕过逻辑删除,彻底解决重新收藏冲突

This commit is contained in:
2026-07-19 23:59:54 +08:00
parent c0245d37fb
commit 4884099b9b
4 changed files with 55 additions and 23 deletions
@@ -3,13 +3,35 @@ package com.emotion.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.emotion.entity.EventFavorite;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
/**
* 人生事件收藏Mapper接口
* 人生事件收藏 Mapper
*
* @author huazhongmin
* @date 2026-07-19
*/
@Mapper
public interface EventFavoriteMapper extends BaseMapper<EventFavorite> {
/**
* 查询用户对某事件的收藏记录(包含已逻辑删除的记录,绕过 @TableLogic 自动过滤)
* 用于 toggle 时判断是否存在历史记录,避免重新收藏时产生重复记录
*/
@Select("SELECT * FROM t_event_favorite WHERE user_id = #{userId} AND event_id = #{eventId} LIMIT 1")
EventFavorite selectAnyByUserAndEvent(@Param("userId") String userId, @Param("eventId") String eventId);
/**
* 物理删除记录(绕过 @TableLogic 的逻辑删除)
*/
@Update("DELETE FROM t_event_favorite WHERE id = #{id}")
int physicalDeleteById(@Param("id") String id);
/**
* 恢复逻辑删除的记录为已收藏状态
*/
@Update("UPDATE t_event_favorite SET is_deleted = 0, update_time = NOW() WHERE id = #{id}")
int restoreById(@Param("id") String id);
}