<?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.schoolinout.api.mapper.ApiStudentMapper">
    <select id="selectOnlyOne" resultType="com.schoolinout.system.domain.Student">
        SELECT
        id, school_id, class_id, student_name, student_pic, student_gender, student_num, del_flag, create_by,
        create_time, update_by, update_time
        FROM tb_school_student
        <where>
            <if test="id != null">
                AND id = #{id}
            </if>
            <if test="schoolId!=null">
                AND school_id = #{schoolId}
            </if>
            <if test="classId!=null">
                AND class_id = #{classId}
            </if>
            <if test="studentNum != null">
                AND student_num = #{studentNum}
            </if>
        </where>
    </select>
    <select id="selectListByParentId" resultType="com.schoolinout.api.domain.vo.Api_StudentListVo">
        SELECT stu.id as student_id,
               stu.school_id,
               stu.class_id,
               stu.student_name,
               stu.student_num,
               stu.student_pic,
               stu.student_gender,
               school.school_name,
               class.class_name
        FROM tb_school_student stu
                 LEFT JOIN tb_school_student_parent_relation tsspr
                           on stu.id = tsspr.student_id AND tsspr.parent_id = #{studentId}
                 LEFT JOIN tb_school school ON stu.school_id = school.id
                 LEFT JOIN tb_school_class class ON stu.class_id = class.id
    </select>
    <select id="selectEditInfo" resultType="com.schoolinout.system.domain.Student">
        SELECT stu.id as student_id,
               stu.student_name,
               stu.student_num,
               stu.student_pic,
               stu.student_gender,
               school.school_name,
               class.class_name
        FROM tb_school_student stu
                 LEFT JOIN tb_school_student_parent_relation tsspr on stu.id = tsspr.student_id
                 LEFT JOIN tb_school school ON stu.school_id = school.id
                 LEFT JOIN tb_school_class class ON stu.class_id = class.id
        where stu.id = #{id}
    </select>
</mapper>