<?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.batchPisInfrMapper">

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

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

</mapper>
