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

	<resultMap id="adminAddressResult" type="adminAddress" extends="common.markedObjectResult" >
		<result property="id" column="ID"/>
		<result property="name" column="NAME"/>
		<result property="address" column="ADDRESS"/>
	</resultMap>
	
	<sql id="tableAdminAddress">TN_CF_ADMIN_ADDRESS</sql>
	
	<sql id="columnsAdminAddress">
		ID, NAME, ADDRESS, FIRST_REG_DATETIME, FIRST_REGR_ID, LAST_MOD_DATETIME, LAST_MODR_ID
	</sql>
	
    <sql id="conditionAdminAddress">
        <trim prefix="WHERE" prefixOverrides="AND|OR">
            <if test="@com.samsung.SdlComparator@isNotEmpty(id)">
              	ID = #{id}
            </if>
            <if test="@com.samsung.SdlComparator@isNotEmpty(name)">
                NAME LIKE CONCAT('%', #{name}, '%')
            </if>
            <if test="@com.samsung.SdlComparator@isNotEmpty(address)">
                ADDRESS LIKE CONCAT('%', #{address}, '%')
            </if>
        </trim>
    </sql>
    
	<select id="selectAdminAddressPagingList" parameterType="AdminAddressSearchDto" resultMap="adminAddressResult">
		SELECT *
		FROM   (SELECT ROW_NUMBER() OVER (<if test="@com.samsung.SdlComparator@isNotEmptyForDynamicSql(orderBy)">ORDER BY ${orderBy}</if>
		                                  <if test="@com.samsung.SdlComparator@isEmpty(orderBy)">ORDER BY FIRST_REG_DATETIME DESC</if>) RNUM,
		               <include refid="columnsAdminAddress" />
		        FROM   <include refid="tableAdminAddress" />
		        <include refid="conditionAdminAddress" />) T
		WHERE T.RNUM BETWEEN (#{pageIndex} - 1) * #{pageSize} + 1 AND #{pageIndex} * #{pageSize}
    </select>
    
	<select id="countAdminAddress" parameterType="java.util.HashMap" resultType="int">
		SELECT COUNT(*) AS TOTAL
		FROM   <include refid="tableAdminAddress" />
		<include refid="conditionAdminAddress" />
	</select>
    
	<select id="selectAdminAddressList"  parameterType="java.util.HashMap" resultMap="adminAddressResult">
		SELECT <include refid="columnsAdminAddress" />
		FROM   <include refid="tableAdminAddress" />
		ORDER BY FIRST_REG_DATETIME DESC
	</select>
	
	<insert id="insertAdminAddress" parameterType="adminAddress">
		INSERT INTO <include refid="tableAdminAddress" />
		(ID, NAME, ADDRESS,
		 FIRST_REG_DATETIME, FIRST_REGR_ID, LAST_MOD_DATETIME, LAST_MODR_ID)
		VALUES
		(#{id}, #{name}, #{address},
		 #{firstRegDatetime}, #{firstRegrId}, #{lastModDatetime}, #{lastModrId})
	</insert>
	
	<delete id="deleteAdminAddress" parameterType="java.util.HashMap">
		DELETE FROM <include refid="tableAdminAddress" />
		WHERE  ID IN
		<foreach item="id" index="index" collection="ids" open="(" separator="," close=")">#{id}</foreach>
	</delete>
	
</mapper>