<?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="parameterMapper">
	<select id="selectParameter" parameterType="java.util.HashMap" resultType="CamelHashMap">
		SELECT
		       A.parameter_type,
		       A.parameter_name,
		       A.parameter_desc,
		       A.multi,
		       A.parameter_program,
		       A.CREATED_AT,
		       A.CREATED_BY,
		       A.UPDATED_AT,
		       A.UPDATED_BY
		FROM   DBO.EMBO_PARAMETR_TYPE A

		WHERE  A.USE_YN = 'Y'
		<if test="@com.samsung.SdlComparator@isNotEmpty(parameterType)">
		AND    A.parameter_type = #{parameterType}
		</if>
		<if test="@com.samsung.SdlComparator@isNotEmpty(multi)">
		AND    A.multi = #{multi}
		</if>
		<if test="@com.samsung.SdlComparator@isNotEmpty(searchKeyword)">
				<if test="searchCondition.equals('parameterType')">
					AND LOWER(parameter_type) LIKE '%' + LOWER(#{searchKeyword}) + '%'
				</if>
				<if test="searchCondition.equals('parameterName')">
					AND LOWER(parameter_name) LIKE '%' + LOWER(#{searchKeyword}) + '%'
				</if>
				<if test="searchCondition.equals('parameterDesc')">
					AND LOWER(parameter_desc) LIKE '%' + LOWER(#{searchKeyword}) + '%'
				</if>
			</if>
		ORDER BY A.parameter_type DESC
	</select>

	<insert id="insertParameter" parameterType="HashMap" >
	INSERT
		INTO   dbo.EMBO_PARAMETR_TYPE
		       (
		              parameter_type,
		              parameter_name,
		              parameter_desc,
		              multi,
		              parameter_program,
		              created_at,
		              created_by,
		              updated_at,
		              updated_by
		       )
		       VALUES
		       (
		              #{parameterType},
		              #{parameterName},
		              #{parameterDesc},
		              #{multi},
		              #{parameterProgram},
		              GETDATE(),
		              #{userId},
		              GETDATE(),
		              #{userId}
		       )

	</insert>

	<update id="updateParameter">
		UPDATE dbo.EMBO_PARAMETR_TYPE
		SET
			parameter_name = #{parameterName}
			,parameter_desc = #{parameterDesc}
			,multi = #{multi}
			,parameter_program = #{parameterProgram}
			,updated_at = GETDATE()
			,updated_by = #{userId}
		WHERE  parameter_type = #{parameterType}
	</update>

	<delete id="deleteParameter" parameterType="java.util.HashMap">
		UPDATE dbo.EMBO_PARAMETR_TYPE
		SET    	USE_YN = 'N'
				,updated_at = GETDATE()
				,updated_by = #{userId}
		WHERE  parameter_type IN
			<foreach item="item" index="index" collection="items" open="(" separator="," close=")">
			#{item.parameterType}
		    </foreach>

	</delete>
</mapper>