<?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="com.ruoyi.mxjb.mapper.MxjbSelectedRoundMapper">
    
    <resultMap type="MxjbSelectedRound" id="MxjbSelectedRoundResult">
        <result property="roundId"    column="round_id"    />
        <result property="schoolId"    column="school_id"    />
        <result property="year"    column="year"    />
        <result property="round"    column="round"    />
        <result property="name"    column="name"    />
        <result property="beginTime"    column="begin_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="groupIds"    column="group_ids"    />
        <result property="state"    column="state"    />
        <result property="modelId"    column="model_id"    />
        <result property="generation"    column="generation"    />
        <result property="preferenceCount"    column="preference_count"    />
        <result property="rankInvisible"    column="rank_invisible"    />
        <result property="scoreInvisible"    column="score_invisible"    />
        <result property="enableEsign"    column="enable_esign"    />
        <result property="enablePaperSign"    column="enable_paper_sign"    />
        <result property="enablePushForceAdjust"    column="enable_push_force_adjust"    />
        <result property="dispatchStatus"    column="dispatch_status"    />
        <result property="activeDate"    column="active_date"    />
        <result property="teacherDone"    column="teacher_done"    />
        <result property="studentDone"    column="student_done"    />
    </resultMap>

    <sql id="selectMxjbSelectedRoundVo">
        select round_id, school_id, year, round, name, begin_time, end_time, group_ids, state, model_id, generation, preference_count, rank_invisible, score_invisible, enable_esign, enable_paper_sign, enable_push_force_adjust, dispatch_status, active_date, teacher_done, student_done, active_date from mxjb_selected_round
    </sql>

    <select id="selectSelectedRoundLatest" parameterType="map" resultMap="MxjbSelectedRoundResult">
        <include refid="selectMxjbSelectedRoundVo"/>
        where school_id = #{schoolId} and year = #{year} and begin_time &lt;= #{date}
        order by begin_time desc
        limit 1
    </select>

    <select id="selectMxjbSelectedRoundList" parameterType="MxjbSelectedRound" resultMap="MxjbSelectedRoundResult">
        <include refid="selectMxjbSelectedRoundVo"/>
        <where>  
            <if test="schoolId != null "> and school_id = #{schoolId}</if>
            <if test="year != null "> and year = #{year}</if>
            <if test="round != null "> and round = #{round}</if>
            <if test="name != null "> and name = #{name}</if>
            <if test="beginTime != null "> and begin_time = #{beginTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="groupIds != null  and groupIds != ''"> and group_ids = #{groupIds}</if>
            <if test="state != null  and state != ''"> and state = #{state}</if>
            <if test="modelId != null "> and model_id = #{modelId}</if>
            <if test="generation != null "> and generation = #{generation}</if>
            <if test="preferenceCount != null "> and preference_count = #{preferenceCount}</if>
            <if test="rankInvisible != null "> and rank_invisible = #{rankInvisible}</if>
            <if test="scoreInvisible != null "> and score_invisible = #{scoreInvisible}</if>
            <if test="enableEsign != null "> and enable_esign = #{enableEsign}</if>
            <if test="enablePaperSign != null "> and enable_paper_sign = #{enablePaperSign}</if>
            <if test="enablePushForceAdjust != null "> and enable_push_force_adjust = #{enablePushForceAdjust}</if>
            <if test="dispatchStatus != null  and dispatchStatus != ''"> and dispatch_status = #{dispatchStatus}</if>
            <if test="activeDate != null"> and active_date = #{activeDate}</if>
            <if test="teacherDone != null"> and teacher_done = #{teacherDone}</if>
            <if test="studentDone != null"> and student_done = #{studentDone}</if>
        </where>
        order by begin_time desc
    </select>
    
    <select id="selectMxjbSelectedRoundById" parameterType="Integer" resultMap="MxjbSelectedRoundResult">
        <include refid="selectMxjbSelectedRoundVo"/>
        where round_id = #{roundId}
    </select>
        
    <insert id="insertMxjbSelectedRound" parameterType="MxjbSelectedRound" useGeneratedKeys="true" keyProperty="roundId">
        insert into mxjb_selected_round
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="schoolId != null">school_id,</if>
            <if test="year != null">year,</if>
            <if test="round != null">round,</if>
            <if test="name != null">name,</if>
            <if test="beginTime != null">begin_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="groupIds != null">group_ids,</if>
            <if test="state != null">state,</if>
            <if test="modelId != null">model_id,</if>
            <if test="generation != null">generation,</if>
            <if test="preferenceCount != null">preference_count,</if>
            <if test="rankInvisible != null">rank_invisible,</if>
            <if test="scoreInvisible != null">score_invisible,</if>
            <if test="enableEsign != null">enable_esign,</if>
            <if test="enablePaperSign != null">enable_paper_sign,</if>
            <if test="enablePushForceAdjust != null">enable_push_force_adjust,</if>
            <if test="dispatchStatus != null">dispatch_status,</if>
            <if test="activeDate != null">active_date,</if>
            <if test="teacherDone != null">teacher_done,</if>
            <if test="studentDone != null">student_done,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="schoolId != null">#{schoolId},</if>
            <if test="year != null">#{year},</if>
            <if test="round != null">#{round},</if>
            <if test="name != null">#{name},</if>
            <if test="beginTime != null">#{beginTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="groupIds != null">#{groupIds},</if>
            <if test="state != null">#{state},</if>
            <if test="modelId != null">#{modelId},</if>
            <if test="generation != null">#{generation},</if>
            <if test="preferenceCount != null">#{preferenceCount},</if>
            <if test="rankInvisible != null">#{rankInvisible},</if>
            <if test="scoreInvisible != null">#{scoreInvisible},</if>
            <if test="enableEsign != null">#{enableEsign},</if>
            <if test="enablePaperSign != null">#{enablePaperSign},</if>
            <if test="enablePushForceAdjust != null">#{enablePushForceAdjust},</if>
            <if test="dispatchStatus != null">#{dispatchStatus},</if>
            <if test="activeDate != null">#{activeDate},</if>
            <if test="teacherDone != null">#{teacherDone},</if>
            <if test="studentDone != null">#{studentDone},</if>
         </trim>
    </insert>

    <update id="updateMxjbSelectedRound" parameterType="MxjbSelectedRound">
        update mxjb_selected_round
        <trim prefix="SET" suffixOverrides=",">
            <if test="schoolId != null">school_id = #{schoolId},</if>
            <if test="year != null">year = #{year},</if>
            <if test="round != null">round = #{round},</if>
            <if test="name != null">name = #{name},</if>
            <if test="beginTime != null">begin_time = #{beginTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="groupIds != null">group_ids = #{groupIds},</if>
            <if test="state != null">state = #{state},</if>
            <if test="modelId != null">model_id = #{modelId},</if>
            <if test="generation != null">generation = #{generation},</if>
            <if test="preferenceCount != null">preference_count = #{preferenceCount},</if>
            <if test="rankInvisible != null">rank_invisible = #{rankInvisible},</if>
            <if test="scoreInvisible != null">score_invisible = #{scoreInvisible},</if>
            <if test="enableEsign != null">enable_esign = #{enableEsign},</if>
            <if test="enablePaperSign != null">enable_paper_sign = #{enablePaperSign},</if>
            <if test="enablePushForceAdjust != null">enable_push_force_adjust = #{enablePushForceAdjust},</if>
            <if test="dispatchStatus != null">dispatch_status = #{dispatchStatus},</if>
            <if test="activeDate != null">active_date = #{activeDate},</if>
            <if test="teacherDone != null">teacher_done = #{teacherDone},</if>
            <if test="studentDone != null">student_done = #{studentDone},</if>
        </trim>
        where round_id = #{roundId}
    </update>

    <delete id="deleteMxjbSelectedRoundById" parameterType="Integer">
        delete from mxjb_selected_round where round_id = #{roundId}
    </delete>

    <delete id="deleteMxjbSelectedRoundByIds" parameterType="String">
        delete from mxjb_selected_round where round_id in 
        <foreach item="roundId" collection="array" open="(" separator="," close=")">
            #{roundId}
        </foreach>
    </delete>
</mapper>