<?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.organization.mapper.UserMapper">
    <select id="getResetUserPage" parameterType="com.xjrsoft.module.organization.dto.UserPageDto" resultType="com.xjrsoft.module.organization.vo.ResetUserPageVo">
        SELECT DISTINCT t1.*,t3.name AS gender_cn FROM xjr_user t1
        INNER JOIN xjr_user_role_relation t2 ON t2.user_id = t1.id
        LEFT JOIN xjr_dictionary_detail t3 ON t1.gender = t3.code
        WHERE t1.delete_mark = 0
        <if test="dto.keyword != null and dto.keyword !=''">
            and (t1.name like concat('%', #{dto.keyword}, '%') or t1.mobile like concat('%', #{dto.keyword}, '%'))
        </if>
        <if test="dto.roleId != null">
            and t2.role_id = #{dto.roleId}
        </if>
    </select>
    <select id="getInfosByParam" parameterType="com.xjrsoft.module.student.dto.BaseStudentSimpleInfoDto" resultType="com.xjrsoft.module.student.vo.BaseStudentSompleInfoVo">
        SELECT t1.id, t1.name as student_name, t1.enabled_mark, t1.credential_number, t4.name AS class_name,t1.mobile,
        (SELECT name FROM base_student_family_member WHERE delete_mark = 0 AND user_id = t1.id ORDER BY create_date ASC LIMIT 0,1) as parent_name,
        (SELECT mobile FROM base_student_family_member WHERE delete_mark = 0 AND user_id = t1.id ORDER BY create_date ASC LIMIT 0,1) as parent_mobile,
        t1.gender,t4.id as class_id, t4.teacher_id
        FROM xjr_user t1
        INNER JOIN base_student t2 ON t1.id = t2.user_id
        INNER JOIN base_student_school_roll t3 ON t1.id = t3.user_id
        INNER JOIN base_class t4 ON t4.id = t3.class_id
        WHERE t1.delete_mark = 0
        <if test="dto.keyword != null and dto.keyword != ''">
            AND (t1.name = #{dto.keyword} OR t1.credential_number = #{dto.keyword})
        </if>
        <if test="dto.userId != null">
            AND t1.id = #{dto.userId}
        </if>
    </select>
</mapper>