<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.modules.martial.mapper.MartialAthleteMapper">

	<!-- 分页查询参赛选手（包含关联字段） -->
	<select id="selectAthleteVOPage" resultType="org.springblade.modules.martial.pojo.vo.MartialAthleteVO">
		SELECT
			a.*,
			c.competition_name as competitionName,
			p.project_name as projectName
		FROM martial_athlete a
		LEFT JOIN martial_competition c ON a.competition_id = c.id AND c.is_deleted = 0
		LEFT JOIN martial_project p ON a.project_id = p.id AND p.is_deleted = 0
		WHERE a.is_deleted = 0
		AND (a.team_name IS NULL OR a.player_name != a.team_name)
		<if test="athlete.competitionId != null">
			AND a.competition_id = #{athlete.competitionId}
		</if>
		<if test="athlete.projectId != null">
			AND a.project_id = #{athlete.projectId}
		</if>
		<if test="athlete.playerName != null and athlete.playerName != ''">
			AND a.player_name LIKE CONCAT('%', #{athlete.playerName}, '%')
		</if>
		<if test="athlete.playerNo != null and athlete.playerNo != ''">
			AND a.player_no = #{athlete.playerNo}
		</if>
		<if test="athlete.gender != null">
			AND a.gender = #{athlete.gender}
		</if>
		<if test="athlete.organization != null and athlete.organization != ''">
			AND a.organization LIKE CONCAT('%', #{athlete.organization}, '%')
		</if>
		<if test="athlete.category != null and athlete.category != ''">
			AND a.category = #{athlete.category}
		</if>
		<if test="athlete.registrationStatus != null">
			AND a.registration_status = #{athlete.registrationStatus}
		</if>
		<if test="athlete.competitionStatus != null">
			AND a.competition_status = #{athlete.competitionStatus}
		</if>
		<if test="athlete.createUser != null">
			AND a.create_user = #{athlete.createUser}
		</if>
		ORDER BY a.create_time DESC
	</select>

</mapper>
