<?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.qiaoba.module.system.mapper.SysDeptMapper">

    <select id="checkDeptNameUnique" resultType="int">
        select count(1) from sys_dept
        where dept_name = #{deptName} and parent_id = #{parentId}
        <if test="deptId != null and deptId != ''">and dept_id != #{deptId}</if>
        limit 1
    </select>

    <select id="selectDeptIdsByRoleId" resultType="string">
        select d.dept_id
        from sys_dept d
        left join sys_role_dept rd on d.dept_id = rd.dept_id
        where rd.role_id = #{roleId}
        order by d.parent_id, d.order_num
    </select>

    <select id="existChild" resultType="string">
        SELECT dept_id FROM sys_dept where parent_id = #{deptId} LIMIT 1
    </select>

    <select id="existUsed" resultType="string">
        SELECT nickname from sys_user where dept_id =  #{deptId} limit 1
    </select>

</mapper>
