<?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.xunwang.education.mapper.TeacherCoursesMapper">

    <insert id="batchInsert">
        insert into teacher_courses (course_id, uid, teacher_type, introduce, teach_age, teach_time, subject, location, mode, experience)
        values
        <foreach collection="teacherCourses" item="item" index="index" separator=",">
            ( #{item.courseId}, #{item.uid}, #{item.teacherType}, #{item.introduce}, #{item.teachAge}, #{item.teachTime}, #{item.subject}, #{item.location}, #{item.mode}, #{item.experience})
        </foreach>
    </insert>

    <select id="selectTeachers" resultType="teacherList">
        select tcou.uid ,tcou.introduce, tcou.teach_age, tcou.datetime, tcou.subject, tcou.teacher_type, tcou.experience, tc.name, tc.profile_photo
        from teacher_courses tcou join teacher_certifications tc
        on tcou.uid = tc.uid
        <where>
            <if test="obj.course != null and obj.course != ''">
                tcou.subject = #{obj.course}
            </if>
            <if test="obj.identify != null and obj.identify != ''">
                tcou.teacher_type = #{obj.identify}
            </if>
            <if test="obj.education != null and obj.education != ''">
                tc.education = #{obj.education}
            </if>
            <if test="obj.sex != null and obj.sex != ''">
                tc.sex = #{obj.sex}
            </if>
            <if test="obj.school != null and obj.school != ''">
                tc.school = #{obj.school}
            </if>
            <if test="obj.mode != null and obj.mode != ''">
                tcou.mode = #{obj.mode}
            </if>
            and tcou.display = "上架" and tcou.deal = "未成交" and tcou.deleted = "0" and tcou.verify_status = "已通过"
        </where>
        limit #{obj.pageNum}, #{obj.pageSize}
    </select>
    
    <select id="selectLatest" resultType="java.lang.String">
        select tc.datetime from teacher_courses tc where deal = '已成交' and uid = #{uid} order by datetime desc limit 1;
    </select>
</mapper>
