Files
label_backend/src/main/java/com/label/mapper/AnnotationTaskMapper.java

31 lines
1.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.label.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.label.entity.AnnotationTask;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
/**
* annotation_task 表 Mapper。
*/
@Mapper
public interface AnnotationTaskMapper extends BaseMapper<AnnotationTask> {
/**
* 原子性领取任务:仅当任务为 UNCLAIMED 且属于当前租户时才更新。
* 使用乐观 WHERE 条件实现并发安全(依赖数据库行级锁)。
*
* @param taskId 任务 ID
* @param userId 领取用户 ID
* @param companyId 当前租户
* @return 影响行数0 = 任务已被他人领取或不存在)
*/
@Update("UPDATE annotation_task " +
"SET status = 'IN_PROGRESS', claimed_by = #{userId}, claimed_at = NOW(), updated_at = NOW() " +
"WHERE id = #{taskId} AND status = 'UNCLAIMED' AND company_id = #{companyId}")
int claimTask(@Param("taskId") Long taskId,
@Param("userId") Long userId,
@Param("companyId") Long companyId);
}