<?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.dbnt.faisp.organMgt.mapper.OrganConfigMapper">
  <select id="selectDownOrganListWhereUserOgCd" resultType="string" parameterType="string">
    with recursive organ_list (
                            organ_cd
      ) as(
      select
        organ_cd
      from organ_config
      where organ_cd  = #{ogCd}
      union all
      select
        a.organ_cd
      from organ_config a
        inner join organ_list b on a.parent_organ = b.organ_cd
    )
    select * from organ_list
  </select>
  <select id="selectUpOrganListWhereUserOgCd" resultType="string" parameterType="string">
    with recursive organ_list (
                               parent_organ
      ) as(
      select
        parent_organ
      from organ_config
      where organ_cd  = #{ogCd}
      union all
      select
        a.parent_organ
      from organ_config a
             inner join organ_list b on a.organ_cd = b.parent_organ
      where a.parent_organ is not null
    )
    select * from organ_list
  </select>

</mapper>