package com.guo.learningprogresstracker.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.guo.learningprogresstracker.entity.ReviewRecallEntity; import org.apache.ibatis.annotations.Mapper; @Mapper public interface ReviewRecallMapper extends BaseMapper { // 命中已有行时必须走「独占锁」而不是 INSERT IGNORE 的共享锁:否则本事务随后的 SELECT ... FOR UPDATE // 要做 S→X 升级,两个并发请求各持共享锁互等,InnoDB 直接判定死锁并回滚其一(前端表现为 500)。 @com.baomidou.mybatisplus.annotation.InterceptorIgnore(tenantLine = "true") @org.apache.ibatis.annotations.Insert( "INSERT INTO review_recall_owner_locks (owner_id) VALUES (#{userId})" + " ON DUPLICATE KEY UPDATE owner_id = owner_id") int ensureOwnerLock(@org.apache.ibatis.annotations.Param("userId") String userId); // Dedicated lock row, not a login/session mutation. Explicit owner id prevents cross-user locking. @com.baomidou.mybatisplus.annotation.InterceptorIgnore(tenantLine = "true") @org.apache.ibatis.annotations.Select( "SELECT owner_id FROM review_recall_owner_locks WHERE owner_id = #{userId} FOR UPDATE") String lockUser(@org.apache.ibatis.annotations.Param("userId") String userId); @org.apache.ibatis.annotations.Select("") @org.apache.ibatis.annotations.Results( id = "taskRecallDuration", value = { @org.apache.ibatis.annotations.Result(column = "task_num", property = "taskNum"), @org.apache.ibatis.annotations.Result(column = "active_duration_ms", property = "activeDurationMs") }) java.util.List sumTaskDuration( @org.apache.ibatis.annotations.Param("taskNums") java.util.Collection taskNums); }