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

	<!-- 裁判邀请VO结果映射 -->
	<resultMap id="judgeInviteVOResultMap" type="org.springblade.modules.martial.pojo.vo.MartialJudgeInviteVO">
		<id column="id" property="id"/>
		<result column="competition_id" property="competitionId"/>
		<result column="judge_id" property="judgeId"/>
		<result column="invite_code" property="inviteCode"/>
		<result column="role" property="role"/>
		<result column="venue_id" property="venueId"/>
		<result column="projects" property="projects"/>
		<result column="expire_time" property="expireTime"/>
		<result column="is_used" property="isUsed"/>
		<result column="use_time" property="useTime"/>
		<result column="device_info" property="deviceInfo"/>
		<result column="login_ip" property="loginIp"/>
		<result column="access_token" property="accessToken"/>
		<result column="token_expire_time" property="tokenExpireTime"/>
		<result column="invite_status" property="inviteStatus"/>
		<result column="invite_time" property="inviteTime"/>
		<result column="reply_time" property="replyTime"/>
		<result column="reply_note" property="replyNote"/>
		<result column="contact_phone" property="contactPhone"/>
		<result column="contact_email" property="contactEmail"/>
		<result column="invite_message" property="inviteMessage"/>
		<result column="cancel_reason" property="cancelReason"/>
		<result column="competition_name" property="competitionName"/>
		<result column="venue_name" property="venueName"/>
		<result column="create_user" property="createUser"/>
		<result column="create_dept" property="createDept"/>
		<result column="create_time" property="createTime"/>
		<result column="update_user" property="updateUser"/>
		<result column="update_time" property="updateTime"/>
		<result column="status" property="status"/>
		<result column="is_deleted" property="isDeleted"/>
	</resultMap>

	<!-- 分页查询裁判邀请列表（关联裁判信息） -->
	<select id="selectJudgeInvitePage" resultMap="judgeInviteVOResultMap">
		SELECT
			ji.id,
			ji.competition_id,
			ji.judge_id,
			ji.invite_code,
			ji.role,
			ji.venue_id,
			ji.projects,
			ji.expire_time,
			ji.is_used,
			ji.use_time,
			ji.device_info,
			ji.login_ip,
			ji.access_token,
			ji.token_expire_time,
			ji.invite_status,
			ji.invite_time,
			ji.reply_time,
			ji.reply_note,
			ji.contact_phone,
			ji.contact_email,
			ji.invite_message,
			ji.cancel_reason,
			ji.create_user,
			ji.create_dept,
			ji.create_time,
			ji.update_user,
			ji.update_time,
			ji.status,
			ji.is_deleted,
			ji.referee_type,
			j.name AS judge_name,
			j.level AS judge_level,
			c.competition_name,
			v.venue_name
		FROM
			martial_judge_invite ji
		LEFT JOIN martial_judge j ON ji.judge_id = j.id
		LEFT JOIN martial_competition c ON ji.competition_id = c.id
		LEFT JOIN martial_venue v ON ji.venue_id = v.id
		WHERE ji.is_deleted = 0
        <if test="judgeInvite.competitionId != null">
            AND ji.competition_id = #{judgeInvite.competitionId}
        </if>
        <if test="judgeInvite.inviteStatus != null">
            AND ji.invite_status = #{judgeInvite.inviteStatus}
        </if>
        <if test="judgeInvite.venueId != null">
            AND ji.venue_id = #{judgeInvite.venueId}
        </if>
		ORDER BY ji.create_time DESC
	</select>

</mapper>
