<?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 ="com.its.pis.mapper.batchPrkPlceMapper">

    <update id="batchUpdatePrkPlceStts" parameterType="java.util.Map">
    <![CDATA[
        MERGE INTO TB_PRK_PLCE_STTS L
            USING (SELECT #{PRK_PLCE_NMBR}  AS PRK_PLCE_NMBR,
                          #{UPDT_DT} 	 	AS UPDT_DT,
                          #{CMNC_STTS_CD}   AS CMNC_STTS_CD
                   FROM DUAL) M
            ON (L.PRK_PLCE_NMBR = M.PRK_PLCE_NMBR)
            WHEN MATCHED THEN
                UPDATE SET
                    L.UPDT_DT      = M.UPDT_DT,
                    L.CMNC_STTS_CD = M.CMNC_STTS_CD
            WHEN NOT MATCHED THEN
                INSERT (
                        PRK_PLCE_NMBR,
                        UPDT_DT,
                        CMNC_STTS_CD
                    )
                    VALUES (
                               M.PRK_PLCE_NMBR,
                               M.UPDT_DT,
                               M.CMNC_STTS_CD
                           )
        ]]>
    </update>

    <insert id="batchInsertPrkPlceSttsHs" parameterType="java.util.Map">
    <![CDATA[
        INSERT INTO TB_PRK_PLCE_STTS_HS (
            CRTN_DT,
            PRK_PLCE_NMBR,
            CMNC_STTS_CD
        )
        VALUES (
                   #{UPDT_DT},
                   #{PRK_PLCE_NMBR},
                   #{CMNC_STTS_CD}
               )
        ]]>
    </insert>

    <update id="batchUpdateRlTimeFlr" parameterType="java.util.Map">
    <![CDATA[
        MERGE INTO TB_PRK_PLCE_FLR L
            USING (SELECT #{PRK_PLCE_NMBR}           AS PRK_PLCE_NMBR,
                          #{FLR_NO} 	 	         AS FLR_NO,
                          #{FLR_PRK_CMPRT_CO} 	 	 AS FLR_PRK_CMPRT_CO,
                          #{FLR_REMNDR_PRK_CMPRT_CO} AS FLR_REMNDR_PRK_CMPRT_CO,
                          #{DATA_COLCT_TIME}         AS DATA_COLCT_TIME
                   FROM DUAL) M
            ON (L.PRK_PLCE_NMBR = M.PRK_PLCE_NMBR AND L.FLR_NO = M.FLR_NO)
            WHEN MATCHED THEN
                UPDATE SET
                    L.FLR_PRK_CMPRT_CO        = M.FLR_PRK_CMPRT_CO,
                    L.FLR_REMNDR_PRK_CMPRT_CO = M.FLR_REMNDR_PRK_CMPRT_CO,
                    L.DATA_COLCT_TIME         = M.DATA_COLCT_TIME
            WHEN NOT MATCHED THEN
                INSERT (
                        PRK_PLCE_NMBR,
                        FLR_NO,
                        FLR_PRK_CMPRT_CO,
                        FLR_REMNDR_PRK_CMPRT_CO,
                        DATA_COLCT_TIME
                    )
                    VALUES (
                               M.PRK_PLCE_NMBR,
                               M.FLR_NO,
                               M.FLR_PRK_CMPRT_CO,
                               M.FLR_REMNDR_PRK_CMPRT_CO,
                               M.DATA_COLCT_TIME
                           )
        ]]>
    </update>

    <update id="batchUpdateRlTimeAr" parameterType="java.util.Map">
    <![CDATA[
        MERGE INTO TB_PRK_PLCE_AR L
            USING (SELECT #{PRK_PLCE_NMBR}          AS PRK_PLCE_NMBR,
                          #{FLR_NO} 	 	        AS FLR_NO,
                          #{AR_NO} 	 	            AS AR_NO,
                          #{AR_PRK_CMPRT_CO}        AS AR_PRK_CMPRT_CO,
                          #{AR_REMNDR_PRK_CMPRT_CO} AS AR_REMNDR_PRK_CMPRT_CO
                   FROM DUAL) M
            ON (L.PRK_PLCE_NMBR = M.PRK_PLCE_NMBR AND L.FLR_NO = M.FLR_NO AND L.AR_NO = M.AR_NO)
            WHEN MATCHED THEN
                UPDATE SET
                    L.AR_PRK_CMPRT_CO        = M.AR_PRK_CMPRT_CO,
                    L.AR_REMNDR_PRK_CMPRT_CO = M.AR_REMNDR_PRK_CMPRT_CO
            WHEN NOT MATCHED THEN
                INSERT (
                        PRK_PLCE_NMBR,
                        FLR_NO,
                        AR_NO,
                        AR_PRK_CMPRT_CO,
                        AR_REMNDR_PRK_CMPRT_CO
                    )
                    VALUES (
                               M.PRK_PLCE_NMBR,
                               M.FLR_NO,
                               M.AR_NO,
                               M.AR_PRK_CMPRT_CO,
                               M.AR_REMNDR_PRK_CMPRT_CO
                           )
        ]]>
    </update>

    <update id="batchUpdateRlTimePrv" parameterType="java.util.Map">
    <![CDATA[
        MERGE INTO TB_PRK_PLCE_PRV L
            USING (SELECT #{PRK_PLCE_NMBR}                AS PRK_PLCE_NMBR,
                          #{VHCTY_AR_SE} 	 	          AS VHCTY_AR_SE,
                          #{VHCTY_AR_PRK_CMPRT_CO}        AS VHCTY_AR_PRK_CMPRT_CO,
                          #{VHCTY_AR_REMNDR_PRK_CMPRT_CO} AS VHCTY_AR_REMNDR_PRK_CMPRT_CO
                   FROM DUAL) M
            ON (L.PRK_PLCE_NMBR = M.PRK_PLCE_NMBR AND L.VHCTY_AR_SE = M.VHCTY_AR_SE)
            WHEN MATCHED THEN
                UPDATE SET
                    L.VHCTY_AR_PRK_CMPRT_CO        = M.VHCTY_AR_PRK_CMPRT_CO,
                    L.VHCTY_AR_REMNDR_PRK_CMPRT_CO = M.VHCTY_AR_REMNDR_PRK_CMPRT_CO
            WHEN NOT MATCHED THEN
                INSERT (
                        PRK_PLCE_NMBR,
                        VHCTY_AR_SE,
                        VHCTY_AR_PRK_CMPRT_CO,
                        VHCTY_AR_REMNDR_PRK_CMPRT_CO
                    )
                    VALUES (
                               M.PRK_PLCE_NMBR,
                               M.VHCTY_AR_SE,
                               M.VHCTY_AR_PRK_CMPRT_CO,
                               M.VHCTY_AR_REMNDR_PRK_CMPRT_CO
                           )
        ]]>
    </update>

    <update id="batchUpdateRlTimeDev" parameterType="java.util.Map">
    <![CDATA[
        MERGE INTO TB_PRK_PLCE_DEV L
            USING (SELECT #{PRK_PLCE_NMBR}      AS PRK_PLCE_NMBR,
                          #{DEVICE_ID} 	 	    AS DEVICE_ID,
                          #{DEVICE_TYPE} 	 	AS DEVICE_TYPE,
                          #{PRK_UNIT_ID}        AS PRK_UNIT_ID,
                          #{TYPED_PARKING_LOTS} AS TYPED_PARKING_LOTS,
                          #{OCCUPATION}         AS OCCUPATION,
                          #{CONNECTED}          AS CONNECTED
                   FROM DUAL) M
            ON (L.PRK_PLCE_NMBR = M.PRK_PLCE_NMBR AND L.DEVICE_ID = M.DEVICE_ID)
            WHEN MATCHED THEN
                UPDATE SET
                    L.OCCUPATION = M.OCCUPATION,
                    L.CONNECTED  = M.CONNECTED
            WHEN NOT MATCHED THEN
                INSERT (
                        PRK_PLCE_NMBR,
                        DEVICE_ID,
                        DEVICE_TYPE,
                        PRK_UNIT_ID,
                        TYPED_PARKING_LOTS,
                        OCCUPATION,
                        CONNECTED
                    )
                    VALUES (
                               M.PRK_PLCE_NMBR,
                               M.DEVICE_ID,
                               M.DEVICE_TYPE,
                               M.PRK_UNIT_ID,
                               M.TYPED_PARKING_LOTS,
                               M.OCCUPATION,
                               M.CONNECTED
                           )
        ]]>
    </update>

</mapper>
