<?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.translator.mapper.TranslatorMapper">
 
 <select id="selectTranslatorList" resultType="Translator" parameterType="Translator">
	    select a.translator_key,
		 version_no,
		 c.item_value  as ogdp1,
		 d.item_value  as tr_lang,
		 tr_career,
		 tr_name,
		 e.item_value  as tr_sex,
		 tr_age,
		 f.item_value  as tr_nny,
		 g.item_value  as tr_edu,
		 tr_cft,
		 h.item_value  as tr_visa,
		 dml_yn,
		 apt_dt,
		 tr_phone
	from translator_info a 
		inner join (select translator_key, max(version_no) as lastVer
					from translator_info
					group by translator_key) b 
				on a.translator_key =b.translator_key and a.version_no = b.lastVer
		left outer join code_mgt c on a.ogdp1 = c.item_cd
		left outer join code_mgt d on a.tr_lang = d.item_cd 
		left outer join code_mgt e on a.tr_sex = e.item_cd 
		left outer join code_mgt f on a.tr_nny = f.item_cd 
		left outer join code_mgt g on a.tr_edu = g.item_cd 
		left outer join code_mgt h on a.tr_visa = h.item_cd 
	where wrt_organ in 
	 <foreach collection="organCdList" item="item" index="index" separator="," open="(" close=")">
        #{item}
     </foreach>
	order by translator_key desc
    limit #{rowCnt} offset #{firstIndex}
  </select>
  
  <select id="selectTranslatorListCnt" resultType="int" parameterType="Translator">
    select count(*)
	from(
	select a.translator_key,
		 version_no,
		 c.item_value  as ogdp1,
		 d.item_value  as tr_lang,
		 tr_career,
		 tr_name,
		 e.item_value  as tr_sex,
		 tr_age,
		 f.item_value  as tr_nny,
		 g.item_value  as tr_edu,
		 tr_cft,
		 h.item_value  as tr_visa,
		 dml_yn,
		 apt_dt,
		 tr_phone
	from translator_info a 
		inner join (select translator_key, max(version_no) as lastVer
					from translator_info
					group by translator_key) b 
				on a.translator_key =b.translator_key and a.version_no = b.lastVer
		left outer join code_mgt c on a.ogdp1 = c.item_cd
		left outer join code_mgt d on a.tr_lang = d.item_cd 
		left outer join code_mgt e on a.tr_sex = e.item_cd 
		left outer join code_mgt f on a.tr_nny = f.item_cd 
		left outer join code_mgt g on a.tr_edu = g.item_cd 
		left outer join code_mgt h on a.tr_visa = h.item_cd
	where wrt_organ in
	 <foreach collection="organCdList" item="item" index="index" separator="," open="(" close=")">
        #{item}
     </foreach>
     ) a
  </select>

</mapper>