<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Biz">
	
	<statement id="selectList" resultClass="java.util.HashMap">
		SELECT *
		FROM (
				SELECT 	@NO := @NO + 1 AS ROWNUMBER,
						EAIBZWKDSTCD,
						BZWKDSTICNAME,
						BZWKDSTICDESC 
						FROM $schemaId$.TSEAICM01,  (SELECT @NO := 0) R
			<dynamic prepend="WHERE">
				<isNotEmpty prepend="AND" property="searchEaiBzwkDstcd">
					UPPER(EaiBzwkDstcd) LIKE CONCAT( '%' ,  #searchEaiBzwkDstcd#  ,  '%' )
				</isNotEmpty>
			</dynamic>						
			) ORGTABLE
		WHERE ROWNUMBER BETWEEN #startNum# AND #endNum#
	</statement>	

	<statement id="selectListCount" resultClass="java.lang.Integer">
		SELECT 	COUNT(*) AS TotalCount
			FROM $schemaId$.TSEAICM01
			<dynamic prepend="WHERE">
				<isNotEmpty prepend="AND" property="searchEaiBzwkDstcd">
					UPPER(EaiBzwkDstcd) LIKE CONCAT( '%' ,  #searchEaiBzwkDstcd#  ,  '%' )
				</isNotEmpty>
			</dynamic>				
	</statement>	
	
	<statement id="selectUserBizList" resultClass="java.util.HashMap">
		SELECT C01.EAIBZWKDSTCD  BIZCODE
			 , C01.BZWKDSTICNAME BIZNAME
			 , C01.BZWKDSTICDESC BIZDESC
			 , CASE WHEN R06.EAIBZWKDSTCD IS NULL THEN 'false' ELSE 'true' END CHK
	      FROM $schemaId$.TSEAICM01 C01
	      LEFT OUTER JOIN $schemaId$.TSEAIRM06 R06 ON 
	       ( C01.EAIBZWKDSTCD = R06.EAIBZWKDSTCD	AND R06.USERID = #userId# )
	       WHERE 1=1
	       <isNotEmpty prepend ="AND" property="searchBzwkName">
			<iterate property="searchBzwkName" open="(" close=")" conjunction="OR">
				   UPPER(C01.EAIBZWKDSTCD) LIKE CONCAT( '%' , UPPER(#searchBzwkName[]#) , '%' )
				OR UPPER(C01.BZWKDSTICNAME) LIKE CONCAT( '%' , UPPER(#searchBzwkName[]#) , '%' )
			</iterate>
			</isNotEmpty>
	     order by 1
	</statement>
	
	<statement id="selectGroupCoCdByEAIBzwkDstCd" parameterClass="java.util.HashMap" resultClass="java.lang.String">
		SELECT GROUPCOCD AS "GROUPCOCD" FROM $schemaId$.TSEAICM01 WHERE EAIBZWKDSTCD = #eaiBzwkDstCd#
	</statement>

<statement id="insertMergeRM06" parameterClass="java.util.HashMap">
	 INSERT INTO $schemaId$.TSEAIRM06
		SELECT #userId# AS USERID
			  , EAIBZWKDSTCD
			  , #SAVETYPE# AS SAVETYPE 
		FROM $schemaId$.TSEAICM01 
		WHERE APPLCD = #EAIBZWKDSTCD# AND EAIBZWKDSTCD != #EAIBZWKDSTCD#
	MINUS
		SELECT USERID
			 , EAIBZWKDSTCD
			 , #SAVETYPE# AS SAVETYPE 
		FROM $schemaId$.TSEAIRM06 
		WHERE USERID = #userId#
	</statement>	
</sqlMap>
