<?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="knoxDepartmentSync">

	<resultMap id="departmentLDAPSyncResult" type="knoxDepartmentSync">
		<result property="deptCode" column="DEPT_CODE"/>
		<result property="deptName" column="DEPT_NAME"/>
		<result property="upperDeptCode" column="UPPER_DEPT_CODE"/>
		<result property="companyCode" column="COMPANY_CODE"/>
		<result property="companyName" column="COMPANY_NAME"/>
		<result property="deptLevel" column="DEPT_LEVEL" />
		<result property="deptSequence" column="DEPT_SEQUENCE"/>
		<result property="deptBossId" column="DEPT_BOSS_ID" />
		<result property="deptBossName" column="DEPT_BOSS_NAME"/>
		<result property="opertDivCode" column="OPERT_DIV_CODE"/>
		<result property="operDivName" column="OPERT_DIV_NAME"/>
		<result property="bizPlaceCode" column="BIZ_PLACE_CODE"/>
		<result property="bizPlaceName" column="BIZ_PLACE_NAME"/>
		<result property="regionCode" column="REGION_CODE"/>
		<result property="regionName" column="REGION_NAME"/>
		<result property="innerDeptCode" column="INNER_DEPT_CODE"/>
		<result property="engDeptName" column="ENG_DEPT_NAME"/>
		<result property="engCompanyName" column="ENG_COMPANY_NAME"/>
		<result property="engOpertDivName" column="ENG_OPERT_DIV_NAME"/>
		<result property="languageTypeCodeId" column="LANGUAGE_TYPE_CODE_ID"/>
	</resultMap>

	<sql id="tableDepartmentLDAPSync">TN_CF_DEPT_LDAP_SYNC</sql>

	<sql id="columnsDepartmentLDAPSync">
	DEPT_CODE, DEPT_NAME, UPPER_DEPT_CODE,
	COMPANY_CODE, COMPANY_NAME, DEPT_LEVEL,DEPT_SEQUENCE,
	DEPT_BOSS_ID, DEPT_BOSS_NAME, OPERT_DIV_CODE, OPERT_DIV_NAME,
	IZ_PLACE_CODE, BIZ_PLACE_NAME, REGION_CODE, REGION_NAME, INNER_DEPT_CODE,
	ENG_DEPT_NAME, ENG_COMPANY_NAME, ENG_OPERT_DIV_NAME, LANGUAGE_TYPE_CODE_ID
	</sql>

	<sql id="conditionDepartmentLDAPSync">
		<trim prefix="WHERE" prefixOverrides="AND|OR">
			<if test="@com.samsung.SdlComparator@isNotEmpty(deptCode)">
				DEPT_CODE = #{deptCode}
			</if>
			<if test="@com.samsung.SdlComparator@isNotEmpty(deptName)">
				AND DEPT_NAME = #{deptName}
			</if>
			<if test="@com.samsung.SdlComparator@isNotEmpty(upperDeptCode)">
				AND UPPER_DEPT_CODE = #{upperDeptCode}
			</if>
		</trim>
	</sql>

	<select id="countDepartmentLDAPSync" parameterType="java.util.HashMap" resultType="int">
		SELECT COUNT(*) AS TOTAL
		FROM   <include refid="tableDepartmentLDAPSync" />
		<include refid="conditionDepartmentLDAPSync" />
	</select>

	<select id="selectDepartmentLDAPSync" parameterType="java.util.HashMap" resultMap="departmentLDAPSyncResult">
		SELECT <include refid="columnsDepartmentLDAPSync" />
		FROM   <include refid="tableDepartmentLDAPSync" />
		<include refid="conditionDepartmentLDAPSync" />
		<if test="@com.samsung.SdlComparator@isNotEmptyForDynamicSql(orderBy)">ORDER BY ${orderBy}</if>
	</select>

	<select id="selectDepartmentLDAPSyncList" parameterType="java.util.HashMap" resultMap="departmentLDAPSyncResult">
		SELECT <include refid="columnsDepartmentLDAPSync" />
		FROM   <include refid="tableDepartmentLDAPSync" />
	</select>

	<select id="selectDepartmentLDAPSyncSubList" parameterType="java.util.HashMap" resultMap="departmentLDAPSyncResult">
		SELECT <include refid="columnsDepartmentLDAPSync" />
		FROM   <include refid="tableDepartmentLDAPSync" />
		<include refid="conditionDepartmentLDAPSync" />
		ORDER BY DEPT_LEVEL, DEPT_SEQUENCE
	</select>

	<insert id="insertDepartmentLDAPSync"  parameterType="knoxDepartmentSync">
		INSERT INTO <include refid="tableDepartmentLDAPSync" />
		(<include refid="columnsDepartmentLDAPSync" />)
		VALUES
		(#{deptCode}, #{deptName}, #{upperDeptCode},
		 #{companyCode}, #{companyName}, #{deptLevel}, #{deptSequence},
		 #{deptBossId}, #{deptBossName}, #{opertDivCode}, #{operDivName},
		 #{bizPlaceCode}, #{bizPlaceName}, #{regionCode}, #{regionName}, #{innerDeptCode},
		 #{engDeptName}, #{engCompanyName}, #{engOpertDivName}, #{languageTypeCodeId})
	</insert>

	<update id="updateDepartmentLDAPSync"  parameterType="knoxDepartmentSync">
		UPDATE <include refid="tableDepartmentLDAPSync" />
		SET    DEPT_NAME = #{deptName},
		       UPPER_DEPT_CODE = #{upperDeptCode},
		       COMPANY_CODE = #{companyCode},
		       COMPANY_NAME = #{companyName},
		       DEPT_LEVEL = #{deptLevel},
		       DEPT_SEQUENCE = #{deptSequence},
		       DEPT_BOSS_ID = #{deptBossId},
		       DEPT_BOSS_NAME = #{deptBossName},
		       OPERT_DIV_CODE = #{opertDivCode},
		       OPERT_DIV_NAME = #{operDivName},
		       BIZ_PLACE_CODE = #{bizPlaceCode},
		       BIZ_PLACE_NAME = #{bizPlaceName},
		       REGION_CODE = #{regionCode},
		       REGION_NAME = #{regionName},
		       INNER_DEPT_CODE = #{innerDeptCode},
		       ENG_DEPT_NAME = #{engDeptName},
		       ENG_COMPANY_NAME = #{engCompanyName},
		       ENG_OPERT_DIV_NAME = #{engOpertDivName},
		       LANGUAGE_TYPE_CODE_ID = #{languageTypeCodeId}
		WHERE  DEPT_CODE = #{deptCode}
	</update>

	<update id="updateMoveDepartmentLDAPSync" parameterType="knoxDepartmentSync">
		UPDATE <include refid="tableDepartmentLDAPSync" />
		SET    DEPT_SEQUENCE = #{deptSequence},
		       DEPT_LEVEL = #{deptLevel}
		WHERE  DEPT_CODE = #{deptCode}
	</update>

	<delete id="deleteDepartmentLDAPSync" parameterType="java.util.HashMap">
		DELETE FROM <include refid="tableDepartmentLDAPSync" />
		WHERE  DEPT_CODE = #{deptCode}
	</delete>

</mapper>