Files
lpt-be/src/main/java/com/guo/learningprogresstracker/mapper/ReviewRecallMapper.java
T

38 lines
2.3 KiB
Java

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<ReviewRecallEntity> {
// 命中已有行时必须走「独占锁」而不是 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("<script>"
+ "SELECT task_num, SUM(active_duration_ms) AS active_duration_ms FROM review_recalls WHERE deleted = 0 AND"
+ " scope_type = 'TASK'"
+ " <if test='taskNums != null and taskNums.size() > 0'>AND task_num IN"
+ " <foreach item='num' collection='taskNums' open='(' separator=',' close=')'>#{num}</foreach></if>"
+ " GROUP BY task_num</script>")
@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<com.guo.learningprogresstracker.dto.recall.TaskRecallDuration> sumTaskDuration(
@org.apache.ibatis.annotations.Param("taskNums") java.util.Collection<String> taskNums);
}