<?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.BaseStudentMapper">
    <select id="getStudentInfo" resultType="com.xjrsoft.module.student.vo.StudentInfoVo">
        SELECT t1.user_id,t5.id as grade_id,t5.name AS grade_name,t4.id as class_id,t4.name AS class_name,t2.name AS student_name,t1.student_id,t2.gender,t3.enrollment_type,t6.id as major_id,t6.name AS major_name FROM base_student t1
        INNER 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_class t4 ON t3.class_id = t4.id
        LEFT JOIN base_grade t5 ON t3.grade_id = t5.id
        LEFT JOIN base_major_set t6 ON t3.major_set_id = t6.id
        where  t1.delete_mark=0 and t2.delete_mark=0 and t1.user_id=#{userId};
    </select>
    <!--姓名和性别，测试阶段采用姓名第一个字拼接user_id的方式脱敏-->
    <select id="getJianyueStudentList" resultType="com.xjrsoft.module.schedule.vo.StudentJianyuekbVo">
        SELECT t1.id AS registerNo, CONCAT(SUBSTRING(t2.name,1,1),t2.id) AS realName,t3.grade_id AS gradeSerialNo,CONCAT(SUBSTRING(t2.name,1,1),t2.id) AS alias,t2.gender,t2.id AS extendId FROM base_student t1
        INNER JOIN xjr_user t2 ON t1.user_id = t2.id
        INNER JOIN base_student_school_roll t3 ON t1.user_id = t3.user_id
        WHERE t1.delete_mark = 0 AND t2.delete_mark = 0
        AND t1.student_id IS NOT NULL AND t1.student_id != ''
        AND t3.archives_status = 'FB2901';
    </select>

    <!--个人财务画像，查询学生个人信息-->
    <select id="getPersonalInfo" resultType="com.xjrsoft.module.student.vo.StudentPersonalInfoVo">
        SELECT t1.user_id,t2.name,t5.name AS gender_cn,t4.id as class_id, t4.name AS class_name,t2.credential_number,t2.birth_date,t2.mobile,
        t6.name AS archives_status_cn,t7.name AS roll_modality_cn,t1.student_id,t8.name AS major_set_name,
        t9.name AS stduy_status_cn,t10.name AS teacher_name,t10.mobile AS teacher_phone,t11.bed_number,t12.room_name,
        t13.name AS build_name,t14.is_indemnify FROM base_student t1
        INNER JOIN xjr_user t2 ON t1.user_id = t2.id
        INNER JOIN base_student_school_roll t3 ON t2.id = t3.user_id
        LEFT JOIN base_class t4 ON t4.id = t3.class_id
        LEFT JOIN xjr_dictionary_detail t5 ON t2.gender = t5.code AND t5.item_id = 2023000000000000004
        LEFT JOIN xjr_dictionary_detail t6 ON t3.archives_status = t6.code AND t6.item_id = 2023000000000000029
        LEFT JOIN xjr_dictionary_detail t7 ON t3.roll_modality = t7.code AND t7.item_id = 1762024751192084482
        LEFT JOIN base_major_set t8 ON t3.major_set_id  = t8.id
        LEFT JOIN xjr_dictionary_detail t9 ON t3.stduy_status = t9.code AND t9.item_id = 2023000000000000030
        LEFT JOIN xjr_user t10 ON t4.teacher_id = t10.id
        LEFT JOIN room_bed t11 ON t1.user_id = t11.student_user_id
        LEFT JOIN room t12 ON t11.room_id = t12.id
        LEFT JOIN base_office_build t13 ON t12.office_build_id = t13.id
        LEFT JOIN base_student_subsidize t14 ON t1.user_id = t14.user_id
        WHERE t1.delete_mark = 0 AND t2.delete_mark = 0
        AND t2.id = #{id}
    </select>

    <!--查询系统中所有学生的身份证号-->
    <select id="getCredentialNumbers" resultType="java.lang.String">
        SELECT t1.credential_number FROM xjr_user t1
        INNER JOIN base_student t2 ON t1.id = t2.user_id
    </select>
    <select id="getStudentPage" parameterType="com.xjrsoft.module.student.dto.BaseStudentUserPageDto" resultType="com.xjrsoft.module.student.vo.BaseStudentUserPageVo">
        SELECT t1.id,t4.name AS class_name,t5.name AS teacher_name,t1.name,t6.name AS gender_cn,t1.credential_number,t1.user_name,
        t1.mobile,t7.name AS archives_status_cn ,t8.name AS stduy_status_cn,t9.name AS student_type_cn,t10.name as learn_status_cn FROM xjr_user t1
        INNER JOIN base_student t2 ON t1.id = t2.user_id
        LEFT JOIN base_student_school_roll t3 ON t1.id = t3.user_id
        LEFT JOIN base_class t4 ON t4.id = t3.class_id
        LEFT JOIN xjr_user t5 ON t4.teacher_id = t5.id
        LEFT JOIN xjr_dictionary_detail t6 ON t1.gender = t6.code AND t6.item_id = 2023000000000000004
        LEFT JOIN xjr_dictionary_detail t7 ON t3.archives_status = t7.code AND t7.item_id = 2023000000000000029
        LEFT JOIN xjr_dictionary_detail t8 ON t3.stduy_status = t8.code AND t8.item_id = 2023000000000000030
        LEFT JOIN xjr_dictionary_detail t9 ON t3.student_type = t9.code AND t9.item_id = 2023000000000000028
        LEFT JOIN xjr_dictionary_detail t10 ON t3.learn_status = t10.code AND t10.item_id = 1762024751192084482
        WHERE t1.delete_mark = 0 AND t2.delete_mark = 0
        and t3.archives_status = 'FB2901'
        <if test="dto.name != null and dto.name != ''">
            and t1.name like concat('%', #{dto.name},'%')
        </if>
        <if test="dto.credentialNumber != null and dto.credentialNumber != ''">
            and t1.credential_number like concat('%', #{dto.credentialNumber},'%')
        </if>
        <if test="dto.userName != null and dto.userName != ''">
            and t1.user_name like concat('%', #{dto.userName},'%')
        </if>
        <if test="dto.mobile != null and dto.mobile != ''">
            and t1.mobile like concat('%', #{dto.mobile},'%')
        </if>
        <if test="dto.email != null and dto.email != ''">
            and t1.email like concat('%', #{dto.email},'%')
        </if>
        <if test="dto.treeType != null and dto.queryId != null">
            <if test="dto.treeType == 1">
                and t4.org_id = #{dto.queryId}
            </if>
            <if test="dto.treeType == 2">
                and t3.major_set_id = #{dto.queryId}
            </if>
            <if test="dto.treeType == 3">
                and t4.grade_id = #{dto.queryId} and t3.major_set_id = #{dto.treeId}
            </if>
            <if test="dto.treeType == 4">
                and t4.id = #{dto.queryId}
            </if>
        </if>

        <if test="dto.order == null">
            order by t1.id
        </if>
        <if test="dto.order != null">
            <if test="dto.order == 'ascend'">
                <if test="dto.field != null and dto.field == 'stduyStatusCn'">
                    order by t8.name
                </if>
                <if test="dto.field != null and dto.field == 'name'">
                    order by t1.name asc
                </if>
            </if>
            <if test="dto.order == 'descend'">
                <if test="dto.field != null and dto.field == 'stduyStatusCn'">
                    order by t8.name desc
                </if>
                <if test="dto.field != null and dto.field == 'name'">
                    order by t1.name desc
                </if>
            </if>
        </if>
    </select>

    <select id="getStudentList" parameterType="com.xjrsoft.module.student.dto.BaseStudentUserPageDto" resultType="com.xjrsoft.module.student.vo.BaseStudentUserPageVo">
        SELECT t1.id,t4.name AS class_name,t5.name AS teacher_name,t1.name,t1.gender AS gender_cn,t1.credential_number,
        t1.mobile,t3.archives_status AS archives_status_cn ,t3.stduy_status AS stduy_status_cn,t3.student_type AS student_type_cn,t3.learn_status as learn_status_cn FROM xjr_user t1
        INNER JOIN base_student t2 ON t1.id = t2.user_id
        LEFT JOIN base_student_school_roll t3 ON t1.id = t3.user_id
        LEFT JOIN base_class t4 ON t4.id = t3.class_id
        LEFT JOIN xjr_user t5 ON t4.teacher_id = t5.id
        WHERE t1.delete_mark = 0 AND t2.delete_mark = 0
        and t3.archives_status = 'FB2901'
    </select>

</mapper>