<?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.yida.data.user.mapper.EduStudentMapper">
  <resultMap id="baseResult" type="com.yida.data.common.core.entity.user.EduStudent">
    <id property="id" column="id"/>
    <result property="stuName" column="stu_name"/>
    <result property="formerName" column="former_name"/>
    <result property="stuNumber" column="stu_number"/>
    <result property="stuExamNumber" column="stu_exam_number"/>
    <result property="creditCardNumbers" column="credit_card_numbers"/>
    <result property="nation" column="nation"/>
    <result property="qqCode" column="qq_code"/>
    <result property="wxCode" column="wx_code"/>
    <result property="email" column="email"/>
    <result property="startGrade" column="start_grade"/>
    <result property="nativePlace" column="native_place"/>
    <result property="politicsStatus" column="politics_status"/>
    <result property="postalCode" column="postal_code"/>
    <result property="presentAddress" column="present_address"/>
    <result property="stuCardNumber" column="stu_card_number"/>
    <result property="avatar" column="avatar"/>
    <result property="stuSex" column="stu_sex"/>
    <result property="schoolId" column="school_id"/>
    <result property="schoolName" column="school_name"/>
    <result property="campusId" column="campus_id"/>
    <result property="campusName" column="campus_name"/>
    <result property="sectionId" column="section_id"/>
    <result property="sectionName" column="section_name"/>
    <result property="gradeId" column="grade_id"/>
    <result property="gradeName" column="grade_name"/>
    <result property="classId" column="class_id"/>
    <result property="className" column="class_name"/>
    <result property="dormId" column="dorm_id"/>
    <result property="dormName" column="dorm_name"/>
    <result property="dormRoomId" column="dorm_room_id"/>
    <result property="dormRoomName" column="dorm_room_name"/>
    <result property="startDate" column="start_date"/>
    <result property="type" column="type"/>
    <result property="idNumber" column="id_number"/>
    <result property="familyType" column="family_type"/>
    <result property="wxId" column="wx_id"/>
    <result property="collectType" column="collect_type"/>
    <result property="status" column="status"/>
    <result property="studentStatus" column="student_status"/>
    <result property="dormStatus" column="dorm_status"/>
    <result property="dahuaId" column="dahua_id"/>
    <result property="dahuaCode" column="dahua_code"/>
    <collection property="parents" ofType="com.yida.data.common.core.entity.user.EduParent">
      <result property="id" column="pid"/>
      <result property="mobile" column="pmobile"/>
      <result property="schoolId" column="pschool_id"/>
      <result property="parentType" column="parent_type"/>
      <result property="parentTypeId" column="parent_type_id"/>
      <result property="wxId" column="pwx_id"/>
      <result property="wxPublicOpenId" column="pwx_pulic_open_id"/>
      <result property="yidaAppUserId" column="pyida_app_user_id"/>
    </collection>
  </resultMap>

  <sql id="listStudentSql">
    SELECT es.*,campus.DEPT_NAME campus_name,section.DEPT_NAME section_name,grade.DEPT_NAME
    grade_name,class.DEPT_NAME class_name
    FROM edu_student es
    left join edu_user_dept campus on es.campus_id=campus.DEPT_ID
    left join edu_user_dept section on es.section_id=section.DEPT_ID
    left join edu_user_dept grade on es.grade_id=grade.DEPT_ID
    left join edu_user_dept class on es.class_id=class.DEPT_ID
    <where>
      es.del_flag=0
      and es.school_id=#{dto.schoolId}
      <if test="dto.campusId != null">
        and es.campus_id=#{dto.campusId}
      </if>
      <if test="dto.sectionId != null">
        and es.section_id=#{dto.sectionId}
      </if>
      <if test="dto.gradeId != null">
        and es.grade_id=#{dto.gradeId}
      </if>
      <if test="dto.classId != null">
        and es.class_id=#{dto.classId}
      </if>
      <if test="dto.classIdList != null and dto.classIdList.size() > 0">
        AND es.class_id IN
        <foreach collection="dto.classIdList" item="item" close=")" open="(" separator=",">
          #{item}
        </foreach>
      </if>
      <if test="dto.stuNumber != null and dto.stuNumber != ''">
        and es.stu_number like concat('%',#{dto.stuNumber},'%')
      </if>
      <if test="dto.name != null and dto.name != ''">
        and es.stu_name like concat('%',#{dto.name},'%')
      </if>
      <if test="dto.familyType != null and  dto.familyType != ''">
        and FIND_IN_SET(#{dto.familyType},es.family_type)
      </if>
      <if test="dto.type != null">
        and es.type =#{dto.type}
      </if>
      <if test='dto.collectType == "1"'>
        and es.avatar is not null and es.avatar != ''
      </if>
      <if test='dto.collectType == "0"'>
        and (es.avatar is null or es.avatar = '')
      </if>
    </where>
    ORDER BY CONVERT(es.stu_name using gbk)
  </sql>

  <!--查询学生列表数据-->
  <select id="selectStudentPage" resultType="com.yida.data.common.core.entity.user.EduStudent">
    <include refid="listStudentSql">
    </include>
  </select>

  <select id="selectStudent" resultType="com.yida.data.common.core.entity.user.EduStudent">
    <include refid="listStudentSql">
    </include>
  </select>

  <select id="getStudentWithParent" resultMap="baseResult">
    select es.*,
    ep.id pid,
    ep.mobile pmobile,
    ep.wx_id pwx_id,
    ep.yida_app_user_id pyida_app_user_id,
    ep.school_id pschool_id,
    ep.wx_public_open_id pwx_pulic_open_id,
    ept.id parent_type_id,
    ept.name parent_type,
    campus.DEPT_NAME campus_name,
    section.DEPT_NAME section_name,
    grade.DEPT_NAME grade_name,
    class.DEPT_NAME class_name,
    dorm.name dorm_name,
    dormRoom.name dorm_room_name
    from edu_student es
    left join edu_parent_student eps on es.id = eps.student_id
    left join edu_parent ep on eps.parent_id = ep.id
    left join edu_parent_type ept on eps.parent_type_id = ept.id
    left join edu_user_dept campus on es.campus_id = campus.DEPT_ID
    left join edu_user_dept section on es.section_id = section.DEPT_ID
    left join edu_user_dept grade on es.grade_id = grade.DEPT_ID
    left join edu_user_dept class on es.class_id = class.DEPT_ID
    left join edu_dormitory dorm on es.dorm_id = dorm.id
    left join edu_dormitory_room dormRoom on es.dorm_room_id = dormRoom.id
    where es.del_flag = 0
    <if test="studentId != null">
      and es.id = #{studentId}
    </if>
    <if test="schoolId != null">
      and es.school_id = #{schoolId}
    </if>
    <if test="wxId != null and wxId != ''">
      and es.wx_id = #{wxId}
    </if>
  </select>

  <select id="getStudentListWithParent" resultMap="baseResult">
    select es.*,
    ep.id pid,
    ep.mobile pmobile,
    ep.wx_id pwx_id,
    ep.yida_app_user_id pyida_app_user_id,
    ep.school_id pschool_id,
    ep.wx_public_open_id pwx_pulic_open_id,
    ept.id parent_type_id,
    ept.name parent_type,
    campus.DEPT_NAME campus_name,
    school.DEPT_NAME school_name,
    section.DEPT_NAME section_name,
    grade.DEPT_NAME grade_name,
    class.DEPT_NAME class_name,
    dorm.name dorm_name,
    dormRoom.name dorm_room_name
    from edu_student es
    left join edu_parent_student eps on es.id = eps.student_id
    left join edu_parent ep on eps.parent_id = ep.id
    left join edu_parent_type ept on eps.parent_type_id = ept.id
    left join t_dept school on es.school_id = school.DEPT_ID
    left join edu_user_dept campus on es.campus_id = campus.DEPT_ID
    left join edu_user_dept section on es.section_id = section.DEPT_ID
    left join edu_user_dept grade on es.grade_id = grade.DEPT_ID
    left join edu_user_dept class on es.class_id = class.DEPT_ID
    left join edu_dormitory dorm on es.dorm_id = dorm.id
    left join edu_dormitory_room dormRoom on es.dorm_room_id = dormRoom.id
    where es.del_flag = 0
    <if test="studentIdList != null and studentIdList.size() > 0">
      AND es.id IN
      <foreach collection="studentIdList" item="item" close=")" open="(" separator=",">
        #{item}
      </foreach>
    </if>
    <if test="schoolId != null">
      and es.school_id = #{schoolId}
    </if>
    <if test="wxId != null and wxId != ''">
      and es.wx_id = #{wxId}
    </if>
  </select>

  <select id="listStudentByParent" resultType="com.yida.data.common.core.entity.user.EduStudent">
    select DISTINCT a.*,
                    d.pic_path        collectBasePic,
                    c.name            relation,
                    campus.DEPT_NAME  campusName,
                    section.DEPT_NAME sectionName,
                    grade.DEPT_NAME   gradeName,
                    class.DEPT_NAME   className
    from edu_student a
           left join edu_parent_student b on a.id = b.student_id
           left join edu_parent_type c on b.parent_type_id = c.id
           left join (select user_id, pic_path from edu_user_face where user_type = 0) d on a.id = d.user_id
           left join edu_user_dept campus on a.campus_id = campus.DEPT_ID
           left join edu_user_dept section
                     on a.section_id = section.DEPT_ID
           left join edu_user_dept grade on a.grade_id = grade.DEPT_ID
           left join edu_user_dept class on a.class_id = class.DEPT_ID
    where b.parent_id = #{parentId}
      and a.del_flag = 0
    ORDER BY CONVERT(a.stu_name using gbk)
  </select>

  <select id="getStudentInfo"
    resultType="com.yida.data.user.vo.StudentClassInfoVO">
    select a.campus_id,
           a.section_id,
           a.grade_id,
           a.class_id,
           a.school_id,
           a.id          student_id,
           a.stu_number  student_number,
           a.stu_name    student_name,
           a.family_type student_family_type,
           d.name        studentParentType
    from edu_student a
           left join edu_parent_student b on a.id = b.student_id
           left join edu_parent c on b.parent_id = c.id
           left join edu_parent_type d on b.parent_type_id = d.id
    where a.del_flag = 0
      and c.mobile = #{parentMobile}
      and a.id = #{studentId}
  </select>

  <select id="getParentByPhoneAndSchoolId" resultType="java.lang.String">
    SELECT wx_id
    FROM `edu_parent` a
    WHERE
    a.mobile in
    <foreach collection="phone" separator="," open="(" close=")" item="item">
      #{item}
    </foreach>
    and a.school_id = #{schoolId}
  </select>

  <select id="listNotBuyStudent"
    parameterType="com.yida.data.school.dto.transaction.ListBuyStudentDTO"
    resultType="com.yida.data.common.core.entity.user.EduStudent">
    SELECT section_id,
    id,
    stu_name,
    campus_id,
    grade_id,
    class_id,
    stu_number
    FROM edu_student
    WHERE del_flag = 0
    AND school_id = #{dto.schoolId}
    <if test="dto.studentId != null and dto.studentId.size() > 0">
      AND id NOT IN
      <foreach collection="dto.studentId" item="item" close=")" open="(" separator=",">
        #{item}
      </foreach>
    </if>
    <if test="dto.campusId != null">
      AND campus_id = #{dto.campusId}
    </if>
    <if test="dto.sectionId != null">
      AND section_id = #{dto.sectionId}
    </if>
    <if test="dto.gradeId != null">
      AND grade_id = #{dto.gradeId}
    </if>
    <if test="dto.classId != null">
      AND class_id = #{dto.classId}
    </if>
    <if test="dto.studentName != null and dto.studentName != ''">
      AND stu_name LIKE CONCAT('%', #{dto.studentName}, '%')
    </if>
    <if test="dto.stuNum != null  and dto.stuNum != ''">
      AND stu_number LIKE CONCAT('%', #{dto.stuNum}, '%')
    </if>
  </select>

  <select id="findParentWxId" resultType="java.lang.String">
    SELECT DISTINCT wx_id
    FROM edu_parent_student a
    LEFT JOIN edu_parent b ON a.parent_id = b.id
    WHERE 1 = 1
    <if test="studentIds != null and studentIds.size() > 0">
      and a.student_id IN
      <foreach collection="studentIds" item="item" close=")" open="(" separator=",">
        #{item}
      </foreach>
    </if>
  </select>

  <select id="listParentByStudentIds" resultType="com.yida.data.user.vo.ListParentByStudentIdsVO">
    SELECT (select DEPT_NAME from edu_user_dept where c.campus_id = DEPT_ID) campus_name,
    c.stu_number as student_number,
    (select DEPT_NAME from edu_user_dept where c.section_id = DEPT_ID) section_name,
    c.stu_name as studentName,
    (select DEPT_NAME from edu_user_dept where c.grade_id = DEPT_ID) grade_name,
    (select DEPT_NAME from edu_user_dept where c.class_id = DEPT_ID) class_name,
    d.`name` as relation,
    b.mobile as phone
    FROM edu_parent_student a
    LEFT JOIN edu_parent b on a.parent_id = b.id
    LEFT JOIN edu_student c on a.student_id = c.id
    LEFT JOIN edu_parent_type d ON a.parent_type_id = d.id
    WHERE a.student_id IN
    <foreach collection="studentIds" separator="," open="(" close=")" item="item">
      #{item}
    </foreach>
  </select>


  <select id="listStudent" resultMap="baseResult">
    select s.id
    <if test="!dto.onlyId">
      ,
      s.stu_name,
      s.stu_sex,
      s.stu_number,
      s.type,
      s.id_number,
      s.stu_card_number,
      s.school_id,
      s.campus_id,
      s.section_id,
      s.grade_id,
      s.class_id,
      s.dorm_id,
      s.dorm_room_id,
      s.status,
      s.student_status,
      s.dorm_status,
      s.family_type,
      s.avatar,
      s.wx_id,
      s.collect_type,
      s.update_wx,
      s.check_in_time,
      s.dahua_id,
      s.dahua_code
      <if test="dto.isQueryUserDept">
        ,
        campus.DEPT_NAME AS campus_name,
        section.DEPT_NAME AS section_name,
        grade.DEPT_NAME AS grade_name,
        class.DEPT_NAME AS class_name
      </if>
      <if test="dto.isQueryParent">
        ,
        ep.id pid,
        ep.mobile pmobile,
        ep.wx_id pwx_id,
        ep.yida_app_user_id pyida_app_user_id,
        ep.school_id pschool_id,
        ep.wx_public_open_id pwx_pulic_open_id,
        ept.id parent_type_id,
        ept.name parent_type
      </if>
    </if>
    from edu_student s
    <if test="dto.onlyId == null or !dto.onlyId">
      <if test="dto.isQueryParent">
        left join edu_parent_student eps on s.id = eps.student_id
        left join edu_parent ep on eps.parent_id = ep.id
        left join edu_parent_type ept on eps.parent_type_id = ept.id
      </if>
      <if test="dto.isQueryUserDept">
        LEFT JOIN edu_user_dept campus ON s.campus_id = campus.DEPT_ID
        LEFT JOIN edu_user_dept section ON s.section_id = section.DEPT_ID
        LEFT JOIN edu_user_dept grade ON s.grade_id = grade.DEPT_ID
        LEFT JOIN edu_user_dept class ON s.class_id = class.DEPT_ID
      </if>
    </if>
    <where>
      s.del_flag = 0
      <if test="dto.schoolId != null">
        and s.school_id = #{dto.schoolId}
      </if>
      <if test="dto.campusId != null">
        and s.campus_id = #{dto.campusId}
      </if>
      <if test="dto.sectionId != null">
        and s.section_id = #{dto.sectionId}
      </if>
      <if test="dto.gradeId != null">
        and s.grade_id = #{dto.gradeId}
      </if>
      <if test="dto.classId != null">
        and s.class_id = #{dto.classId}
      </if>
      <if test="dto.type != null">
        and s.type = #{dto.type}
      </if>
      <if test="dto.schoolIds != null and dto.schoolIds.size() > 0">
        and s.school_id in
        <foreach collection="dto.schoolIds" close=")" open="(" separator="," item="item">
          #{item}
        </foreach>
      </if>
      <if test="dto.studentIds != null and dto.studentIds.size() > 0">
        and s.id in
        <foreach collection="dto.studentIds" close=")" item="item" open="(" separator=",">
          #{item}
        </foreach>
      </if>
      <if test="dto.classIds != null and dto.classIds.size() > 0">
        and s.class_id in
        <foreach collection="dto.classIds" close=")" item="item" open="(" separator=",">
          #{item}
        </foreach>
      </if>
      <if test="dto.stuName != null and dto.stuName != ''">
        and (s.stu_name like concat('%', #{dto.stuName}, '%') or s.stu_number like concat('%', #{dto.stuName}, '%'))
      </if>
      <if test="dto.stuNum != null and dto.stuNum != ''">
        and s.stu_number like concat('%', #{dto.stuNum}, '%')
      </if>
      <if test="dto.dormIds != null and dto.dormIds.size() > 0">
        and s.dorm_id in
        <foreach collection="dto.dormIds" separator="," open="(" item="item" close=")">
          #{item}
        </foreach>
      </if>
      <if test="dto.dormRoomIds != null and dto.dormRoomIds.size() > 0">
        and s.dorm_room_id in
        <foreach collection="dto.dormRoomIds" separator="," open="(" item="item" close=")">
          #{item}
        </foreach>
      </if>
    </where>
    <if test="dto.isSort">
      ORDER BY CONVERT(s.stu_name using gbk)
    </if>
  </select>

  <select id="listStudentDormPage" resultType="com.yida.data.user.vo.StudentDormInfoVO">
    select id studentId,
    stu_name studentName,
    grade_id,
    class_id,
    stu_number studentNum,
    dorm_room_id
    dormRoomId,
    check_in_time
    from edu_student
    <where>
      del_flag = 0
      and type = 1
      <if test="dormRoomIds != null and dormRoomIds.size() != 0">
        and dorm_room_id in
        <foreach collection="dormRoomIds" item="item" close=")" open="(" separator=",">
          #{item}
        </foreach>
      </if>
      <if test="dto.classId != null">
        and class_id = #{dto.classId}
      </if>
      <if test="dto.keyword != null and dto.keyword != ''">
        and (
        stu_name like concat('%', #{dto.keyword}, '%')
        or stu_number like concat('%', #{dto.keyword}, '%')
        )
      </if>
    </where>
    order by stu_number
  </select>

  <select id="listStudentDorm" resultType="com.yida.data.common.core.entity.user.EduStudent">
    select
      id,
    stu_name,
    grade_id,
    class_id,
    stu_number,
    dorm_room_id,
    check_in_time
    from edu_student
    <where>
      del_flag = 0
      and type = 1
      <if test="dormRoomIds != null and dormRoomIds.size() != 0">
        and dorm_room_id in
        <foreach collection="dormRoomIds" item="item" close=")" open="(" separator=",">
          #{item}
        </foreach>
      </if>
      <if test="dto.classId != null">
        and class_id = #{dto.classId}
      </if>
      <if test="dto.keyword != null and dto.keyword != ''">
        and (
        stu_name like concat('%', #{dto.keyword}, '%')
        or stu_number like concat('%', #{dto.keyword}, '%')
        )
      </if>
    </where>
    order by stu_number
  </select>

  <select id="listTeacherByStudentId" resultType="com.yida.data.common.core.entity.user.EduTeacherDept">
    SELECT a.id,
           a.type,
           a.create_date,
           a.course_id,
           a.teacher_id,
           a.school_id,
           a.campus_id,
           a.section_id,
           a.grade_id,
           a.class_id,
           b.course_name,
           c.`name` as teacher_name
    FROM edu_teacher_dept a
           LEFT JOIN edu_course b ON a.course_id = b.id
           LEFT JOIN edu_staff c on a.teacher_id = c.id
    WHERE a.del_flag = 0
      AND class_id = #{classId}
  </select>

  <!-- 根据学生表字段查询学生id信息 -->
  <select id="listBaseStudentIds" parameterType="com.yida.data.common.core.entity.user.EduStudent"
    resultType="java.lang.Long">
    SELECT
    es.id
    FROM edu_student es
    left join edu_user_dept campus on es.campus_id=campus.DEPT_ID
    left join edu_user_dept section on es.section_id=section.DEPT_ID
    left join edu_user_dept grade on es.grade_id=grade.DEPT_ID
    left join edu_user_dept class on es.class_id=class.DEPT_ID
    <where>
      es.del_flag=0
      and es.school_id=#{schoolId}
      <if test="campusId != null">
        and es.campus_id=#{campusId}
      </if>
      <if test="sectionId != null">
        and es.section_id=#{sectionId}
      </if>
      <if test="gradeId != null">
        and es.grade_id=#{gradeId}
      </if>
      <if test="classId != null">
        and es.class_id=#{classId}
      </if>
      <if test="stuNumber != null and stuNumber != ''">
        and es.stu_number like concat('%',#{stuNumber},'%')
      </if>
      <if test="stuName != null and stuName != ''">
        and es.stu_name like concat('%',#{stuName},'%')
      </if>
      <if test="familyType != null and familyType != ''">
        and es.family_type like concat('%',#{familyType},'%')
      </if>
      <if test="type != null">
        and es.type =#{type}
      </if>
    </where>
  </select>

  <!-- 根据学生表字段查询学生列表信息 -->
  <select id="listBaseStudent" parameterType="com.yida.data.common.core.entity.user.EduStudent"
    resultType="com.yida.data.common.core.entity.user.EduStudent">
    SELECT
    es.*,
    campus.DEPT_NAME campusName,
    section.DEPT_NAME sectionName,
    grade.DEPT_NAME gradeName,
    class.DEPT_NAME className
    FROM edu_student es
    left join edu_user_dept campus on es.campus_id=campus.DEPT_ID
    left join edu_user_dept section on es.section_id=section.DEPT_ID
    left join edu_user_dept grade on es.grade_id=grade.DEPT_ID
    left join edu_user_dept class on es.class_id=class.DEPT_ID
    <where>
      es.del_flag=0
      and es.school_id=#{schoolId}
      <if test="campusId != null">
        and es.campus_id=#{campusId}
      </if>
      <if test="sectionId != null">
        and es.section_id=#{sectionId}
      </if>
      <if test="gradeId != null">
        and es.grade_id=#{gradeId}
      </if>
      <if test="classId != null">
        and es.class_id=#{classId}
      </if>
      <if test="stuNumber != null and stuNumber != ''">
        and es.stu_number like concat('%',#{stuNumber},'%')
      </if>
      <if test="stuName != null and stuName != ''">
        and es.stu_name like concat('%',#{stuName},'%')
      </if>
      <if test="familyType != null and familyType != ''">
        and es.family_type like concat('%',#{familyType},'%')
      </if>
      <if test="type != null">
        and es.type =#{type}
      </if>
    </where>
  </select>

  <select id="listDormIdsByDeptId" resultType="java.lang.Long">
    select dorm_id from edu_student
    <where>
      del_flag=0
      <if test="schoolId != null">
        and school_id=#{schoolId}
      </if>
      <if test="campusId != null">
        and campus_id=#{campusId}
      </if>
      <if test="sectionId != null">
        and section_id=#{sectionId}
      </if>
      <if test="gradeId != null">
        and grade_id=#{gradeId}
      </if>
      <if test="classId != null">
        and class_id=#{classId}
      </if>
    </where>
  </select>

  <select id="listStudentByCondition" parameterType="com.yida.data.user.dto.ListStudentDTO"
    resultType="com.yida.data.common.core.entity.user.EduStudent">
    SELECT es.id,
    es.type,
    es.avatar,
    es.stu_name stuName,
    ed.`name` dormName,
    edr.`name` dormRoomName
    FROM edu_student es
    LEFT JOIN edu_dormitory ed ON es.dorm_id = ed.id
    LEFT JOIN edu_dormitory_room edr ON es.dorm_room_id = edr.id
    WHERE es.del_flag = 0
    <if test="type != null">
      and es.type=#{type}
    </if>
    AND es.class_id = #{classId}
  </select>


  <!-- 单表查询学生信息 -->
  <select id="listBaseStudentNoJoin" parameterType="com.yida.data.common.core.entity.user.EduStudent"
    resultType="com.yida.data.common.core.entity.user.EduStudent">
    SELECT
    es.*
    FROM edu_student es
    <where>
      es.del_flag=0
      <if test="schoolId != null">
        and es.school_id=#{schoolId}
      </if>
      <if test="campusId != null">
        and es.campus_id=#{campusId}
      </if>
      <if test="sectionId != null">
        and es.section_id=#{sectionId}
      </if>
      <if test="gradeId != null">
        and es.grade_id=#{gradeId}
      </if>
      <if test="classId != null">
        and es.class_id=#{classId}
      </if>
      <if test="stuNumber != null and stuNumber != ''">
        and es.stu_number = #{stuNumber}
      </if>
      <if test="stuName != null and stuName != ''">
        and es.stu_name like concat('%',#{stuName},'%')
      </if>
      <if test="familyType != null and familyType != ''">
        and es.family_type like concat('%',#{familyType},'%')
      </if>
      <if test="type != null">
        and es.type =#{type}
      </if>
    </where>
  </select>

  <!-- 分页查询学生列表数据 -->
  <select id="listStudentOutPage" resultType="com.yida.data.user.vo.OutPageStudentVO">
    SELECT id       AS student_id,
           stu_name AS student_name,
           stu_card_number,
           avatar,
           school_id,
           create_date,
           update_date
    FROM edu_student
    WHERE del_flag = 0
      AND school_id = #{dto.schoolId}
    ORDER BY create_date DESC
  </select>

  <!-- 查询年级人数 -->
  <select id="selectGradeStudentNumber" resultType="long">
    SELECT COUNT(es.id)
    FROM edu_student es
    WHERE es.del_flag = 0
      AND es.grade_id = #{gradeId}
  </select>

</mapper>