<?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.dao.mapper.PrltCtlrMapper">

    <select id="selectAll" resultType="com.its.pis.entity.TbPrkPlce">
    <![CDATA[
        SELECT A.PRK_PLCE_NMBR      AS PRK_PLCE_NMBR,
               A.PRK_PLCE_MANAGE_NO AS PRK_PLCE_MANAGE_NO,
               A.PRK_PLCE_NM        AS PRK_PLCE_NM,
               A.PIS_TYPE           AS PIS_TYPE
        FROM TB_PRK_PLCE A
        WHERE A.PIS_TYPE != 'N'
        ORDER BY A.PRK_PLCE_NMBR
    ]]>
    </select>

    <update id="updatePrltCtlrStts" parameterType="com.its.pis.entity.TbPrkPlceStts">
    <![CDATA[
		MERGE INTO TB_PRK_PLCE_STTS L
		USING (SELECT #{stts.PRK_PLCE_NMBR} AS PRK_PLCE_NMBR,
		              #{stts.UPDT_DT} 	 	 AS UPDT_DT,
		              #{stts.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="insertPrltCtlrSttsHs" parameterType="com.its.pis.entity.TbPrkPlceStts">
    <![CDATA[
          INSERT INTO TB_PRK_PLCE_STTS_HS (
		          CRTN_DT,
                  PRK_PLCE_NMBR,
                  CMNC_STTS_CD
		         )
          VALUES (
				  #{stts.UPDT_DT},
				  #{stts.PRK_PLCE_NMBR},
				  #{stts.CMNC_STTS_CD}
                 )
    ]]>
    </insert>

    <update id="batchUpdatePrltCtlrStts" 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="batchInsertPrltCtlrSttsHs" 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="updatePrkPlceRlTime" parameterType="com.its.pis.entity.TbPrkPlceRt">
    <![CDATA[
        MERGE INTO TB_PRK_PLCE_RT L
            USING (SELECT
                       #{obj.prkPlceNmbr}           AS PRK_PLCE_NMBR,
                       #{obj.dataColctTime}         AS DATA_COLCT_TIME,
                       #{obj.parkingCgsSttus}       AS PARKING_CGS_STTUS,
                       #{obj.prkCmprtCo}            AS PRK_CMPRT_CO,
                       #{obj.remndrPrkCmprtCo}      AS REMNDR_PRK_CMPRT_CO,
                       #{obj.prkResveAvailCmprtCo}  AS PRK_RESVE_AVAIL_CMPRT_CO,
                       #{obj.partclrMatter}         AS PARTCLR_MATTER
                   FROM DUAL) M
            ON (L.PRK_PLCE_NMBR = M.PRK_PLCE_NMBR)
            WHEN MATCHED THEN
                UPDATE SET
                    L.DATA_COLCT_TIME          = M.DATA_COLCT_TIME,
                    L.PARKING_CGS_STTUS        = M.PARKING_CGS_STTUS,
                    L.PRK_CMPRT_CO             = M.PRK_CMPRT_CO,
                    L.REMNDR_PRK_CMPRT_CO      = M.REMNDR_PRK_CMPRT_CO,
                    L.PRK_RESVE_AVAIL_CMPRT_CO = M.PRK_RESVE_AVAIL_CMPRT_CO,
                    L.PARTCLR_MATTER           = M.PARTCLR_MATTER
            WHEN NOT MATCHED THEN
                INSERT (
                        PRK_PLCE_NMBR,
                        DATA_COLCT_TIME,
                        PARKING_CGS_STTUS,
                        PRK_CMPRT_CO,
                        REMNDR_PRK_CMPRT_CO,
                        PRK_RESVE_AVAIL_CMPRT_CO,
                        PARTCLR_MATTER )
                    VALUES (
                               M.PRK_PLCE_NMBR,
                               M.DATA_COLCT_TIME,
                               M.PARKING_CGS_STTUS,
                               M.PRK_CMPRT_CO,
                               M.REMNDR_PRK_CMPRT_CO,
                               M.PRK_RESVE_AVAIL_CMPRT_CO,
                               M.PARTCLR_MATTER )
        ]]>
    </update>

    <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>
