package com.designhub.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.designhub.entity.ContestParticipant; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.util.List; /** * 竞赛参与者Mapper */ @Mapper public interface ContestParticipantMapper extends BaseMapper { /** * 获取竞赛排行榜 */ @Select("SELECT * FROM contest_participant WHERE contest_id = #{contestId} ORDER BY total_score DESC, task_completed DESC") List getLeaderboard(@Param("contestId") Long contestId); /** * 获取用户在竞赛中的排名 */ @Select("SELECT COUNT(*) + 1 FROM contest_participant WHERE contest_id = #{contestId} AND total_score > (SELECT total_score FROM contest_participant WHERE contest_id = #{contestId} AND user_id = #{userId})") Integer getUserRank(@Param("contestId") Long contestId, @Param("userId") Long userId); }