<?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.app.mapper.WcamMapper">

    <select id="selectAll" resultType="com.its.app.vo.voIcmpCtlr">
    <![CDATA[
        SELECT A.WCAM_CTLR_NMBR AS CTLR_NMBR,
               A.WCAM_CTLR_ID   AS CTLR_ID,
               A.WCAM_NM        AS ISTL_LCTN_NM,
               A.WCAM_CTLR_IP   AS CTLR_IP,
               A.WCAM_TYPE_CD   AS TYPE_CD,
               (SELECT CMMN_CD_KOR_NM
                  FROM TB_CMMN_CD
                 WHERE CMMN_CLSF_CD = 'WCAM'
                   AND CMMN_CD      = A.WCAM_TYPE_CD) AS TYPE_NM,
               A.DEL_YN AS DEL_YN
          FROM TB_WCAM_CTLR A
         WHERE A.DEL_YN = 'N'
    ]]>
    </select>

    <update id="updateStts" parameterType="com.its.app.vo.voIcmpCtlrStts">
    <![CDATA[
        MERGE INTO TB_WCAM_CTLR_STTS L
        USING (SELECT #{stts.CTLR_NMBR}    AS WCAM_CTLR_NMBR,
                      #{stts.UPDT_DT}      AS UPDT_DT,
                      #{stts.CMNC_STTS_CD} AS CMNC_STTS_CD
                 FROM DUAL) M
        ON (L.WCAM_CTLR_NMBR = M.WCAM_CTLR_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 (L.WCAM_CTLR_NMBR,
                    L.UPDT_DT,
                    L.CMNC_STTS_CD)
            VALUES (M.WCAM_CTLR_NMBR,
                    M.UPDT_DT,
                    M.CMNC_STTS_CD)
    ]]>
    </update>

    <insert id="insertSttsHs" parameterType="com.its.app.vo.voIcmpCtlrStts">
    <![CDATA[
        INSERT INTO TB_WCAM_CTLR_STTS_HS
                   (CRTN_DT,
                    WCAM_CTLR_NMBR,
                    CMNC_STTS_CD)
          VALUES (
                  #{stts.UPDT_DT},
                  #{stts.CTLR_NMBR},
                  #{stts.CMNC_STTS_CD}
                 )
    ]]>
    </insert>

</mapper>
