<?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.xjrsoft.module.student.mapper.BaseStudentGraduateMapper">
    <select id="getPage" parameterType="com.xjrsoft.module.student.dto.BaseStudentGraduatePageDto" resultType="com.xjrsoft.module.student.vo.BaseStudentGraduatePageVo">
        SELECT t5.id,
        t1.user_id,
        t1.student_id,
        t2.name,
        t2.gender,
        t9.name as genderCn,
        t2.mobile as phone,
        t4.name              AS major_name,
        t3.stduy_status,
        t6.name              AS stduy_status_cn,
        t3.archives_status,
        t10.name              AS archives_status_cn,
        t3.roll_modality,
        t12.name              AS roll_modality_cn,
        IFNULL(t5.status, 0) AS status,
        t5.certificate_number,
        t5.certificate_date,
        t7.name              AS class_name,
        t8.name              AS grade_name,
        t5.appendix_id,
        ifnull((SELECT enroll_type FROM base_student_development WHERE base_student_graduate_id = t5.id ORDER BY create_date DESC limit 0, 1), 0) as enroll_status
        FROM base_student t1
        LEFT JOIN xjr_user t2 ON t1.user_id = t2.id
        LEFT JOIN base_student_school_roll t3 ON t1.user_id = t3.user_id
        LEFT JOIN base_major_set t4 ON t3.major_set_id = t4.id
        LEFT JOIN base_student_graduate t5 ON t1.user_id = t5.user_id
        LEFT JOIN xjr_dictionary_detail t6 ON t3.stduy_status = t6.code
        LEFT JOIN base_class t7 ON t7.id = t3.class_id
        LEFT JOIN base_grade t8 ON t8.id = t3.grade_id
        LEFT JOIN xjr_dictionary_detail t9 on t9.code = t2.gender
        LEFT JOIN xjr_dictionary_detail t10 on t10.code = t3.archives_status
        LEFT JOIN xjr_dictionary_detail t12 on t12.code = t3.roll_modality
        WHERE t1.delete_mark = 0
        AND t2.delete_mark = 0
        AND t3.delete_mark = 0
        <if test="dto.archivesStatus != null and dto.archivesStatus != ''">
            and t3.archives_status = #{dto.archivesStatus}
        </if>
        <if test="dto.stduyStatus != null and dto.stduyStatus != ''">
            and t3.stduy_status = #{dto.stduyStatus}
        </if>
        <if test="dto.rollModality != null and dto.rollModality != ''">
            and t3.learn_status = #{dto.rollModality}
        </if>
        <if test="dto.name != null and dto.name != ''">
            and t2.name like concat('%',#{dto.name}, '%')
        </if>
        <if test="dto.status != null">
            and t5.status = #{dto.status}
        </if>
        <if test="dto.classId != null and dto.classId > 0">
            and t3.class_id = #{dto.classId}
        </if>
    </select>

    <select id="getInfoById" resultType="com.xjrsoft.module.student.vo.BaseStudentGraduateVo">
        SELECT t5.id,t1.user_id,t1.student_id,t2.name,t4.name AS major_name,t6.name AS stduy_status_cn,
        IFNULL(t5.status,0) AS status,t5.certificate_number,t5.certificate_date,t7.name AS class_name,t8.name AS grade_name,t5.appendix_id FROM base_student t1
        LEFT JOIN xjr_user t2 ON t1.user_id = t2.id
        LEFT JOIN base_student_school_roll t3 ON t1.user_id = t3.user_id
        LEFT JOIN base_major_set t4 ON t3.major_set_id = t4.id
        LEFT JOIN base_student_graduate t5 ON t1.user_id = t5.user_id
        LEFT JOIN xjr_dictionary_detail t6 ON t3.stduy_status = t6.code AND t6.item_id = 2023000000000000030
        LEFT JOIN base_class t7 ON t7.id = t3.class_id
        LEFT JOIN base_grade t8 ON t8.id = t3.grade_id
        WHERE t1.delete_mark = 0 AND t2.delete_mark = 0
        AND t3.delete_mark = 0
        AND t1.user_id = #{id}
    </select>
</mapper>