<?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.lframework.xingyun.template.inner.mappers.system.SysUserDeptMapper">

    <sql id="SysUserDeptDto_sql">
        SELECT
            ud.*
        FROM sys_user_dept AS ud
        INNER JOIN sys_dept AS d ON d.id = ud.dept_id
    </sql>
    <select id="getByUserId" resultType="com.lframework.xingyun.template.inner.entity.SysUserDept">
        <include refid="SysUserDeptDto_sql"/>
        WHERE ud.user_id = #{userId}
        ORDER BY d.code
    </select>

    <select id="hasByDeptId" resultType="com.lframework.xingyun.template.inner.entity.SysUserDept">
        <include refid="SysUserDeptDto_sql"/>
        WHERE ud.dept_id = #{deptId}
        LIMIT 1
    </select>
</mapper>
