<?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.MartialScheduleGroupMapper">

	<!-- 优化的一次性JOIN查询，获取完整的赛程编排数据 -->
	<select id="selectScheduleGroupDetails" resultType="org.springblade.modules.martial.pojo.vo.ScheduleGroupDetailVO">
		SELECT
			g.id AS groupId,
			g.group_name AS groupName,
			g.category AS category,
			g.project_type AS projectType,
			g.total_teams AS totalTeams,
			g.total_participants AS totalParticipants,
			g.display_order AS displayOrder,
			d.id AS detailId,
			d.venue_id AS venueId,
			d.venue_name AS venueName,
			d.time_slot AS timeSlot,
			d.time_slot_index AS timeSlotIndex,
			d.schedule_date AS scheduleDate,
			p.id AS participantId,
			p.organization AS organization,
			p.check_in_status AS checkInStatus,
			p.schedule_status AS scheduleStatus,
			p.performance_order AS performanceOrder,
			p.player_name AS playerName
		FROM
			martial_schedule_group g
		LEFT JOIN
			martial_schedule_detail d ON g.id = d.schedule_group_id AND d.is_deleted = 0
		LEFT JOIN
			martial_schedule_participant p ON g.id = p.schedule_group_id AND p.is_deleted = 0
		WHERE
			g.competition_id = #{competitionId}
			AND g.is_deleted = 0
		ORDER BY
			g.display_order ASC,
			p.performance_order ASC
	</select>

</mapper>
