<?xml version="1.0" encoding="UTF-8"?><!--Converted at: Wed May 11 15:49:38 KST 2016-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="nlib.col.service.impl.CartDAO">

 	<select id="listCartItems" parameterType="String" resultType="CollectionVO">
		SELECT 
              A.MB_CART_ID
            , A.MB_INFO_ID
            , A.MASTER_ID
            , A.CART_TYPE_CD
            , A.REL_RSRV_ID
            , A.REL_REQ_ID
            , A.CART_PROC_DIV_CD
            , A.DELETE_YN
            , A.REG_ID
            , DATE_FORMAT(A.REG_DD, '%Y-%M-%D') AS REG_DD
            , A.MOD_ID
            , DATE_FORMAT(A.MOD_DD, '%Y-%M-%D') AS MOD_DD
            , B.MNG_ORG_CD 
            , B.MNG_ORG_NM 
        FROM MB_CART A 
        INNER JOIN RG_MASTER B ON A.MASTER_ID = B.MASTER_ID
		WHERE A.MB_INFO_ID = #{mbInfoId} 
		<if test='cartTypeCd != null and !cartTypeCd.equals("") and !cartTypeCd.equals("0")'>
            AND A.CART_TYPE_CD = #{cartTypeCd}
        </if>
		AND A.DELETE_YN = 'N'
		AND IFNULL(A.CART_PROC_DIV_CD, 'N') = 'N'
		ORDER BY B.MNG_ORG_CD 
 	</select>
 	
    <update id="changeCartProcDivCd" parameterType="CollectionVO">
        <![CDATA[
        UPDATE MB_CART SET CART_PROC_DIV_CD = #{cartProcDivCd}, MOD_ID = #{modId}, MOD_DD = NOW() 
        WHERE MB_INFO_ID = #{mbInfoId}
        AND MASTER_ID = #{masterId}
        AND DELETE_YN = 'N'
        ]]>
    </update>
    
    <select id="countCartItems" parameterType="String" resultType="Integer">
        SELECT COUNT(A.MB_CART_ID) AS CNT
        FROM MB_CART A 
        INNER JOIN RG_MASTER B ON A.MASTER_ID = B.MASTER_ID
        WHERE A.MB_INFO_ID = #{mbInfoId} 
        <if test='cartTypeCd != null and !cartTypeCd.equals("") and !cartTypeCd.equals("0")'>
            AND A.CART_TYPE_CD = #{cartTypeCd}
        </if>
        AND A.DELETE_YN = 'N'
        AND IFNULL(A.CART_PROC_DIV_CD, 'N') = 'N'
    </select> 	
 	
 	<select id="countCartItem" parameterType="CollectionVO" resultType="Integer">
        SELECT COUNT(1)
        FROM MB_CART A 
        WHERE MB_INFO_ID = #{mbInfoId}
        AND MASTER_ID = #{masterId}
        AND DELETE_YN = 'N'
    </select>
    
    <insert id="insertCartItem" parameterType="CollectionVO">
        <![CDATA[
		INSERT INTO MB_CART (   
		      MB_CART_ID
		    , MB_INFO_ID
		    , MASTER_ID
		    , CART_TYPE_CD
		    , REL_RSRV_ID
		    , REL_REQ_ID
		    , CART_PROC_DIV_CD
		    , DELETE_YN
		    , REG_ID
		    , REG_DD
		    , MOD_ID
		    , MOD_DD
		) VALUES (
		      NULL /* 자동생성 */ 
		    , #{mbInfoId}
		    , #{masterId}
		    , #{cartTypeCd}
		    , NULL
		    , NULL
		    , 'N'
		    , 'N'
		    , #{regId}
		    , NOW()
		    , NULL
		    , NULL
		)
        ]]>
    </insert>
    
    <delete id="deleteCartItems" parameterType="CollectionVO">
        <![CDATA[
        UPDATE MB_CART SET DELETE_YN = 'Y', MOD_ID = #{modId}, MOD_DD = NOW() 
        WHERE MB_INFO_ID = #{mbInfoId}
        AND MASTER_ID IN (${selItems})
        AND DELETE_YN = 'N'
        ]]>
    </delete>
    
    <update id="changeCartType" parameterType="CollectionVO">
        <![CDATA[
        UPDATE MB_CART SET CART_TYPE_CD = #{cartTypeCd}, MOD_ID = #{modId}, MOD_DD = NOW() 
        WHERE MB_INFO_ID = #{mbInfoId}
        AND MASTER_ID IN (${selItems})
        AND DELETE_YN = 'N'
        ]]>
    </update>
    
</mapper>