<?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.srs.teacher.mapper.SysTeacherExerciseMapper">
    
    <resultMap type="SysTeacherExercise" id="SysTeacherExerciseResult">
        <result property="exerciseId"    column="exercise_id"    />
        <result property="teacherId"    column="teacher_id"    />
        <result property="organization"    column="organization"    />
        <result property="receivingUnit"    column="receivingUnit"    />
        <result property="receivingType"    column="receivingType"    />
        <result property="exerciseNature"    column="exerciseNature"    />
        <result property="postName"    column="postName"    />
        <result property="startTime"    column="startTime"    />
        <result property="endTime"    column="endTime"    />
    </resultMap>

    <sql id="selectSysTeacherExerciseVo">
        select exercise_id, teacher_id, organization, receivingUnit, receivingType, exerciseNature, postName, startTime, endTime from sys_teacher_exercise
    </sql>

    <select id="selectSysTeacherExerciseList" parameterType="SysTeacherExercise" resultMap="SysTeacherExerciseResult">
        <include refid="selectSysTeacherExerciseVo"/>
        <where>  
            <if test="teacherId != null "> and teacher_id = #{teacherId}</if>
            <if test="organization != null  and organization != ''"> and organization = #{organization}</if>
            <if test="receivingUnit != null  and receivingUnit != ''"> and receivingUnit = #{receivingUnit}</if>
            <if test="receivingType != null  and receivingType != ''"> and receivingType = #{receivingType}</if>
            <if test="exerciseNature != null  and exerciseNature != ''"> and exerciseNature = #{exerciseNature}</if>
            <if test="postName != null  and postName != ''"> and postName like concat('%', #{postName}, '%')</if>
            <if test="startTime != null  and startTime != ''"> and startTime = #{startTime}</if>
            <if test="endTime != null  and endTime != ''"> and endTime = #{endTime}</if>
        </where>
    </select>
    
    <select id="selectSysTeacherExerciseByExerciseId" parameterType="Long" resultMap="SysTeacherExerciseResult">
        <include refid="selectSysTeacherExerciseVo"/>
        where exercise_id = #{exerciseId}
    </select>
        
    <insert id="insertSysTeacherExercise" parameterType="SysTeacherExercise">
        insert into sys_teacher_exercise
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="exerciseId != null">exercise_id,</if>
            <if test="teacherId != null">teacher_id,</if>
            <if test="organization != null">organization,</if>
            <if test="receivingUnit != null">receivingUnit,</if>
            <if test="receivingType != null">receivingType,</if>
            <if test="exerciseNature != null">exerciseNature,</if>
            <if test="postName != null">postName,</if>
            <if test="startTime != null">startTime,</if>
            <if test="endTime != null">endTime,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="exerciseId != null">#{exerciseId},</if>
            <if test="teacherId != null">#{teacherId},</if>
            <if test="organization != null">#{organization},</if>
            <if test="receivingUnit != null">#{receivingUnit},</if>
            <if test="receivingType != null">#{receivingType},</if>
            <if test="exerciseNature != null">#{exerciseNature},</if>
            <if test="postName != null">#{postName},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
         </trim>
    </insert>

    <update id="updateSysTeacherExercise" parameterType="SysTeacherExercise">
        update sys_teacher_exercise
        <trim prefix="SET" suffixOverrides=",">
            <if test="teacherId != null">teacher_id = #{teacherId},</if>
            <if test="organization != null">organization = #{organization},</if>
            <if test="receivingUnit != null">receivingUnit = #{receivingUnit},</if>
            <if test="receivingType != null">receivingType = #{receivingType},</if>
            <if test="exerciseNature != null">exerciseNature = #{exerciseNature},</if>
            <if test="postName != null">postName = #{postName},</if>
            <if test="startTime != null">startTime = #{startTime},</if>
            <if test="endTime != null">endTime = #{endTime},</if>
        </trim>
        where exercise_id = #{exerciseId}
    </update>

    <delete id="deleteSysTeacherExerciseByExerciseId" parameterType="Long">
        delete from sys_teacher_exercise where exercise_id = #{exerciseId}
    </delete>

    <delete id="deleteSysTeacherExerciseByExerciseIds" parameterType="String">
        delete from sys_teacher_exercise where exercise_id in 
        <foreach item="exerciseId" collection="array" open="(" separator="," close=")">
            #{exerciseId}
        </foreach>
    </delete>
</mapper>