<?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.EduSchoolStudentInformationMapper">
  <select id="listStudentInfo" resultType="com.yida.data.user.vo.EduSchoolStudentInformationVo">
    SELECT
    stu.id,
    stu.campus_name campusName,
    stu.class_name className,
    stu.student_id_card studentIdCard,
    stu.student_name studentName,
    stu.grade_name gradeName,
    group_concat(
    par.report_parents_info
    ) patriarch,
    MIN(par.check_date) checkDate
    FROM
    edu_school_student_information stu
    LEFT JOIN edu_school_parent_information par ON stu.id = par.student_information_id
    WHERE stu.del_flag = 0
    <if test="schoolId != null">
      and stu.school_id = #{schoolId}
    </if>
    <if test="campusId != null">
      and stu.campus_id = #{campusId}
    </if>
    <if test="sectionId != null">
      and stu.section_id = #{sectionId}
    </if>
    <if test="classId != null">
      and stu.class_id = #{classId}
    </if>
    <if test="gradeId != null">
      and stu.grade_id = #{gradeId}
    </if>
    <if test="studentName != null">
      and stu.student_name like concat('%',#{studentName},'%')
    </if>
    <if test="studentIdCard != null">
      and stu.student_id_card like concat('%',#{studentIdCard},'%')
    </if>
    <if test='reportStatus != -1 and reportStatus != null'>
      and stu.report_status = #{reportStatus}
    </if>
    GROUP BY
    stu.id,
    stu.campus_name,
    stu.class_name,
    stu.student_id_card,
    stu.student_name,
    stu.grade_name,
    stu.create_date
    ORDER BY
    stu.create_date DESC
  </select>

  <!-- 根据查询条件导出迎新学生数据 -->
  <select id="exportWelcomeStudentData"
    resultType="com.yida.data.user.dto.WelcomeStudentExportDTO">
    SELECT
    @rank := @rank + 1 AS indexNo,
    a.*
    FROM
    (SELECT
    stu.student_name studentName,
    stu.student_number studentNumber,
    stu.student_id_card studentIdCard,
    stu.campus_name campusName,
    stu.section_name sectionName,
    stu.class_name className,
    stu.grade_name gradeName,
    stu.parent_type_name parentTypeName,
    stu.parent_telephone parentTelephone,
    CASE stu.report_status
    WHEN 0 THEN '未报到'
    WHEN 1 THEN '已报到'
    END reportStatus,
    group_concat(
    par.report_parents_info
    ) reportParentsInfo,
    MIN(par.check_date) checkDate
    FROM
    edu_school_student_information stu
    LEFT JOIN edu_school_parent_information par ON stu.id = par.student_information_id
    WHERE stu.del_flag = '0'
    <if test="schoolId != null">
      and stu.school_id = #{schoolId}
    </if>
    <if test="campusId != null">
      and stu.campus_id = #{campusId}
    </if>
    <if test="classId != null">
      and stu.class_id = #{classId}
    </if>
    <if test="gradeId != null">
      and stu.grade_id = #{gradeId}
    </if>
    <if test='studentName != null and studentName != ""'>
      and stu.student_name like concat('%',#{studentName},'%')
    </if>
    <if test='studentIdCard != null and studentIdCard != ""'>
      and stu.student_id_card like concat('%',#{studentIdCard},'%')
    </if>
    <if test='reportStatus != -1 and reportStatus != null'>
      and stu.report_status = #{reportStatus}
    </if>
    GROUP BY
    studentName,
    studentNumber,
    studentIdCard,
    stu.campus_name,
    stu.section_name,
    stu.class_name,
    stu.student_id_card,
    stu.student_name,
    stu.grade_name,
    parentTypeName,
    parentTelephone,
    reportStatus
    ) AS a,
    ( SELECT @rank := 0 ) AS p
  </select>
</mapper>