<?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="cokr.xit.fims.cmmn.dao.FactionMapper">

<select id="selectAllFactionList" resultType="dataobject">
/* 전체 기관,부서 목록 조회(factionMapper.selectAllFactionList) */
SELECT CONCAT(A.INST_CD,'/',B.DEPT_CD) AS FACTION_CD
     , CONCAT(A.INST_NM,' / ',B.DEPT_NM) AS FACTION_NM
     , A.INST_CD
     , A.INST_NM
     , B.DEPT_CD
     , B.DEPT_NM
FROM TB_SGG_INFO A
LEFT OUTER JOIN TB_DEPT_INFO B ON (A.INST_CD = B.INST_CD)
UNION
SELECT 'default/default' AS FACTION_CD
     , CONCAT('기본 기관',' / ','기본 부서') AS FACTION_NM
     , 'default' AS INST_CD
     , '기본 기관' AS INST_NM
     , 'default' AS DEPT_CD
     , '기본 부서' AS DEPT_NM
FROM DUAL
</select>

<select id="selectAbleFactionList" parameterType="map" resultType="dataobject">
/* 사용가능한 기관,부서 목록 조회(factionMapper.selectAbleFactionList) */
SELECT CONCAT(A.INST_CD,'/',B.DEPT_CD) AS FACTION_CD
     , CONCAT(A.INST_NM,' / ',B.DEPT_NM) AS FACTION_NM
     , A.INST_CD
     , A.INST_NM
     , B.DEPT_CD
     , B.DEPT_NM
FROM TB_SGG_INFO A
LEFT OUTER JOIN TB_DEPT_INFO B ON (A.INST_CD = B.INST_CD)
<if test="currentUser.institute != 'default'">
WHERE A.INST_CD = #{currentUser.institute}
</if>
<if test="currentUser.institute == 'default'">
UNION
SELECT 'default/default' AS FACTION_CD
     , CONCAT('기본 기관',' / ','기본 부서') AS FACTION_NM
     , 'default' AS INST_CD
     , '기본 기관' AS INST_NM
     , 'default' AS DEPT_CD
     , '기본 부서' AS DEPT_NM
FROM DUAL
</if>
</select>

</mapper>