<?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.qmth.distributed.print.business.mapper.TeachStudentMapper">

    <select id="findTeachStudentPage"
            resultType="com.qmth.distributed.print.business.bean.result.TeachStudentResult">
        SELECT
            ts.id AS id,
            bes.student_name AS studentName,
            bes.student_code AS studentCode,
            bes.college AS belongOrgName,
            bes.major AS majorName,
            tc.clazz_name AS clazzName
        FROM
            teach_student ts
                LEFT JOIN
            basic_exam_student bes ON ts.student_id = bes.id
                LEFT JOIN
            teach_clazz tc ON tc.id = ts.teach_clazz_id
        <where>
            <if test="schoolId != null and schoolId != ''">
                AND ts.school_id = #{schoolId}
            </if>
            <if test="teachClazzId != null and teachClazzId != ''">
                AND ts.teach_clazz_id = #{teachClazzId}
            </if>
            <if test="studentInfo != null and studentInfo != ''">
                AND (bes.student_name LIKE CONCAT('%',#{studentInfo},'%') OR bes.student_code LIKE CONCAT('%',#{studentInfo},'%'))
            </if>
        </where>
        ORDER BY id
    </select>
</mapper>