<?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.koobietech.eas.dao.mapper.RoleMapper">


    <select id="getAllUsers" resultType="com.koobietech.eas.dao.pojo.RolePojo">
        SELECT
            id, '用户' AS type, relname AS username
        FROM
            eas_sys_userinfo  WHERE disabled = 'N'
        UNION ALL
        SELECT
            id, '学生' AS type, student_name AS username
        FROM
            eas_sys_student WHERE disabled = 'N'
    </select>

    <select id="queryUserByRoleId" resultType="com.koobietech.eas.dao.pojo.RolePojo">
        SELECT
            eas_sys_roleusers.*
        FROM
            eas_sys_dep_relation
        JOIN eas_sys_roleusers ON eas_sys_roleusers.id =
                   IF( eas_sys_dep_relation.user_id > 0,
                       eas_sys_dep_relation.user_id, eas_sys_dep_relation.student_id )
        WHERE
            eas_sys_dep_relation.department_id = #{departmentId}
    </select>

</mapper>