<?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.SysTeacherCourseMapper">
    
    <resultMap type="SysTeacherCourse" id="SysTeacherCourseResult">
        <result property="courseId"    column="course_id"    />
        <result property="teacherId"    column="teacher_id"    />
        <result property="name"    column="name"    />
        <result property="courseType"    column="courseType"    />
        <result property="courseNature"    column="courseNature"    />
        <result property="courseHour"    column="courseHour"    />
        <result property="studentNumber"    column="studentNumber"    />
        <result property="startTime"    column="startTime"    />
        <result property="endTime"    column="endTime"    />
    </resultMap>

    <sql id="selectSysTeacherCourseVo">
        select course_id, teacher_id, name, courseType, courseNature, courseHour, studentNumber, startTime, endTime from sys_teacher_course
    </sql>

    <select id="selectSysTeacherCourseList" parameterType="SysTeacherCourse" resultMap="SysTeacherCourseResult">
        <include refid="selectSysTeacherCourseVo"/>
        <where>  
            <if test="teacherId != null "> and teacher_id = #{teacherId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="courseType != null  and courseType != ''"> and courseType = #{courseType}</if>
            <if test="courseNature != null  and courseNature != ''"> and courseNature = #{courseNature}</if>
            <if test="courseHour != null "> and courseHour = #{courseHour}</if>
            <if test="studentNumber != null "> and studentNumber = #{studentNumber}</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="selectSysTeacherCourseByCourseId" parameterType="Long" resultMap="SysTeacherCourseResult">
        <include refid="selectSysTeacherCourseVo"/>
        where course_id = #{courseId}
    </select>
        
    <insert id="insertSysTeacherCourse" parameterType="SysTeacherCourse" useGeneratedKeys="true" keyProperty="courseId">
        insert into sys_teacher_course
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="teacherId != null">teacher_id,</if>
            <if test="name != null">name,</if>
            <if test="courseType != null">courseType,</if>
            <if test="courseNature != null">courseNature,</if>
            <if test="courseHour != null">courseHour,</if>
            <if test="studentNumber != null">studentNumber,</if>
            <if test="startTime != null">startTime,</if>
            <if test="endTime != null">endTime,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="teacherId != null">#{teacherId},</if>
            <if test="name != null">#{name},</if>
            <if test="courseType != null">#{courseType},</if>
            <if test="courseNature != null">#{courseNature},</if>
            <if test="courseHour != null">#{courseHour},</if>
            <if test="studentNumber != null">#{studentNumber},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
         </trim>
    </insert>

    <update id="updateSysTeacherCourse" parameterType="SysTeacherCourse">
        update sys_teacher_course
        <trim prefix="SET" suffixOverrides=",">
            <if test="teacherId != null">teacher_id = #{teacherId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="courseType != null">courseType = #{courseType},</if>
            <if test="courseNature != null">courseNature = #{courseNature},</if>
            <if test="courseHour != null">courseHour = #{courseHour},</if>
            <if test="studentNumber != null">studentNumber = #{studentNumber},</if>
            <if test="startTime != null">startTime = #{startTime},</if>
            <if test="endTime != null">endTime = #{endTime},</if>
        </trim>
        where course_id = #{courseId}
    </update>

    <delete id="deleteSysTeacherCourseByCourseId" parameterType="Long">
        delete from sys_teacher_course where course_id = #{courseId}
    </delete>

    <delete id="deleteSysTeacherCourseByCourseIds" parameterType="String">
        delete from sys_teacher_course where course_id in 
        <foreach item="courseId" collection="array" open="(" separator="," close=")">
            #{courseId}
        </foreach>
    </delete>
</mapper>