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

    <select id="selectAll" resultType="com.its.vms.dto.TbVmsCtlrDto">
    <![CDATA[
        select t1.vms_ctlr_nmbr       AS vmsCtlrNmbr,
               t1.vms_ctlr_local_no   AS vmsCtlrLocalNo,
               t1.vms_ctlr_id         AS vmsCtlrId,
               t1.vms_nm              AS vmsNm,
               t1.vms_ctlr_ip         AS vmsCtlrIp,
               t1.vms_usag_type_cd    AS vmsUsagTypeCd,
               t1.vms_frm_type_cd     AS vmsFrmTypeCd,
               t1.vms_type_cd         AS vmsTypeCd,
               t1.vms_modl_type_cd    AS vmsModlTypeCd,
               t1.vms_ctlr_port       AS vmsCtlrPort,
               t1.oper_mode           AS operMode,
               t1.cmnc_fail_rate      AS cmncFailRate,
               t1.brgh_nght_step      AS brghNghtStep,
               t1.brgh_week_step      AS brghWeekStep,
               t1.def_phse_chng_cycl  AS defPhseChngCycl,
               t1.modl_err_rate       AS modlErrRate,
               t1.cmncfail_slot_nmbr  AS cmncfailSlotNmbr,
               t1.pwer_fail_slot_nmbr AS pwerFailSlotNmbr,
               t1.cmtrinfr_cnct_yn    AS cmtrinfrCnctYn,
               t1.wthrinfr_cnct_yn    AS wthrinfrCnctYn,
               t1.envrinfr_cnct_yn    AS envrinfrCnctYn,
               t1.vms_max_phse_num    AS vmsMaxPhseNum,
               t1.panl_on_time        AS panlOnTime,
               t1.panl_off_time       AS panlOffTime,
               t1.panl_pwer_mode      AS panlPwerMode,
               t1.brgh_mode           AS brghMode,
               t1.istl_lctn_nm        AS istlLctnNm,
               t1.trfc_strg_use_yn    AS trfcStrgUseYn,
               t1.vms_loc_ifsc_id     AS vmsLocIfscId,
               t1.fan_run_tmpr        AS fanRunTmpr,
               t1.hetr_run_tmpr       AS hetrRunTmpr,
               t1.fan_mode            AS fanMode,
               t1.hetr_mode           AS hetrMode,
               t1.brgh_curr_step      AS brghCurrStep,
               t1.istl_lctn_addr      AS istlLctnAddr,
               t1.protocol_ver        AS protocolVer,
               t1.del_yn              AS delYn,
               t2.vms_wdth            AS vmsWidth,
               t2.vms_hght            AS vmsHeight,
               t2.modl_row_num        AS powrRowNum,
               t2.modl_col_num        AS powrColNum,
               t2.powr_row_num        AS powrRowNum,
               t2.powr_col_num        AS powrColNum
        from tb_vms_ctlr t1
        inner join tb_vms_type t2
            on t1.del_yn = 'N'
            and t1.vms_type_cd = t2.vms_type_cd
        order by t1.vms_ctlr_nmbr
    ]]>
    </select>

    <select id="selectCtlrStts" resultType="com.its.vms.dto.TbVmsCtlrSttsDto">
    <![CDATA[
        SELECT A.RSE_CTLR_NMBR AS RSE_CTLR_NMBR,
               A.UPDT_DT,
               A.CMNC_STTS_CD,
               A.CNTL_DEVC_STTS,
               A.ATN_1_STTS,
               A.ATN_2_STTS,
               A.ATN_3_STTS,
               A.ATN_4_STTS,
               A.ATN_1_MTNS,
               A.ATN_2_MTNS,
               A.ATN_3_MTNS,
               A.ATN_4_MTNS
        FROM TB_RSE_CTLR_STTS A,
             TB_RSE_CTLR      B
        WHERE B.DEL_YN = 'N'
          AND A.RSE_CTLR_NMBR = B.RSE_CTLR_NMBR
        ]]>
    </select>

    <select id="selectRseObuNonCryptList" resultType="com.its.vms.entity.TbRseObuNonCrypt">
    <![CDATA[
	    SELECT TRIM(A.OBU_ID) AS OBU_ID,
	           TRIM(A.OBU_IDNT_NMBR) AS OBU_IDNT_NMBR
	      FROM TB_RSE_OBU_NON_CRPT A
	     ORDER BY A.OBU_ID
    ]]>
    </select>

    <update id="updateCtlrStts" parameterType="com.its.vms.dto.TbVmsCtlrSttsDto">
    <![CDATA[
        merge into tb_vms_ctlr_stts L
            using (select
                       #{vmsCtlrNmbr}     AS vms_ctlr_nmbr,
                       #{updtDt}          AS updt_dt,
                       #{cmncSttsCd}      AS cmnc_stts_cd,
                       #{pwerSttsCd}      AS pwer_stts_cd,
                       #{modlSttsCd}      AS modl_stts_cd,
                       #{cboxDoorSttsCd}  AS cbox_door_stts_cd,
                       #{fanSttsCd}       AS fan_stts_cd,
                       #{hetrSttsCd}      AS hetr_stts_cd,
                       #{cboxTmpr}        AS cbox_tmpr,
                       #{brghVal}         AS brgh_val,
                       #{commSttsCd}      AS comm_stts_cd,
                       #{modlStts}        AS modl_stts,
                       #{pwerStts}        AS pwer_stts
                   from dual) M
            on (    L.vms_ctlr_nmbr = M.vms_ctlr_nmbr)
            when matched then
                update set
                    L.updt_dt           = M.updt_dt,
                    L.cmnc_stts_cd      = M.cmnc_stts_cd,
                    L.pwer_stts_cd      = M.pwer_stts_cd,
                    L.modl_stts_cd      = M.modl_stts_cd,
                    L.cbox_door_stts_cd = M.cbox_door_stts_cd,
                    L.fan_stts_cd       = M.fan_stts_cd,
                    L.hetr_stts_cd      = M.hetr_stts_cd,
                    L.cbox_tmpr         = M.cbox_tmpr,
                    L.brgh_val          = M.brgh_val,
                    L.comm_stts_cd      = M.comm_stts_cd,
                    L.modl_stts         = M.modl_stts,
                    L.pwer_stts         = M.pwer_stts
            when not matched then
                insert (
                        vms_ctlr_nmbr,
                        updt_dt,
                        cmnc_stts_cd,
                        pwer_stts_cd,
                        modl_stts_cd,
                        cbox_door_stts_cd,
                        fan_stts_cd,
                        hetr_stts_cd,
                        cbox_tmpr,
                        brgh_val,
                        comm_stts_cd,
                        modl_stts,
                        pwer_stts )
                    values (
                               M.vms_ctlr_nmbr,
                               M.updt_dt,
                               M.cmnc_stts_cd,
                               M.pwer_stts_cd,
                               M.modl_stts_cd,
                               M.cbox_door_stts_cd,
                               M.fan_stts_cd,
                               M.hetr_stts_cd,
                               M.cbox_tmpr,
                               M.brgh_val,
                               M.comm_stts_cd,
                               M.modl_stts,
                               M.pwer_stts )
        ]]>
    </update>

    <update id="batchUpdateCtlrStts" parameterType="java.util.Map">
    <![CDATA[
        merge into tb_vms_ctlr_stts L
            using (select
                       #{vmsCtlrNmbr}     AS vms_ctlr_nmbr,
                       #{updtDt}           AS updt_dt,
                       #{cmncSttsCd}      AS cmnc_stts_cd,
                       #{pwerSttsCd}      AS pwer_stts_cd,
                       #{modlSttsCd}      AS modl_stts_cd,
                       #{cboxDoorSttsCd} AS cbox_door_stts_cd,
                       #{fanSttsCd}       AS fan_stts_cd,
                       #{hetrSttsCd}      AS hetr_stts_cd,
                       #{cboxTmpr}         AS cbox_tmpr,
                       #{brghVal}          AS brgh_val,
                       #{commSttsCd}      AS comm_stts_cd,
                       #{modlStts}         AS modl_stts,
                       #{pwerStts}         AS pwer_stts
                   from dual) M
            on (    L.vms_ctlr_nmbr = M.vms_ctlr_nmbr)
            when matched then
                update set
                    L.updt_dt           = M.updt_dt,
                    L.cmnc_stts_cd      = M.cmnc_stts_cd,
                    L.pwer_stts_cd      = M.pwer_stts_cd,
                    L.modl_stts_cd      = M.modl_stts_cd,
                    L.cbox_door_stts_cd = M.cbox_door_stts_cd,
                    L.fan_stts_cd       = M.fan_stts_cd,
                    L.hetr_stts_cd      = M.hetr_stts_cd,
                    L.cbox_tmpr         = M.cbox_tmpr,
                    L.brgh_val          = M.brgh_val,
                    L.comm_stts_cd      = M.comm_stts_cd,
                    L.modl_stts         = M.modl_stts,
                    L.pwer_stts         = M.pwer_stts
            when not matched then
                insert (
                        vms_ctlr_nmbr,
                        updt_dt,
                        cmnc_stts_cd,
                        pwer_stts_cd,
                        modl_stts_cd,
                        cbox_door_stts_cd,
                        fan_stts_cd,
                        hetr_stts_cd,
                        cbox_tmpr,
                        brgh_val,
                        comm_stts_cd,
                        modl_stts,
                        pwer_stts )
                    values (
                               M.vms_ctlr_nmbr,
                               M.updt_dt,
                               M.cmnc_stts_cd,
                               M.pwer_stts_cd,
                               M.modl_stts_cd,
                               M.cbox_door_stts_cd,
                               M.fan_stts_cd,
                               M.hetr_stts_cd,
                               M.cbox_tmpr,
                               M.brgh_val,
                               M.comm_stts_cd,
                               M.modl_stts,
                               M.pwer_stts )
        ]]>
    </update>

    <insert id="insertCtlrSttsHs" parameterType="com.its.vms.dto.TbVmsCtlrSttsDto">
    <![CDATA[
        insert into tb_vms_ctlr_stts_hs (
            crtn_dt,
            vms_ctlr_nmbr,
            cmnc_stts_cd,
            pwer_stts_cd,
            modl_stts_cd,
            cbox_door_stts_cd,
            fan_stts_cd,
            hetr_stts_cd,
            cbox_tmpr,
            brgh_val,
            comm_stts_cd,
            modl_stts,
            pwer_stts )
        values (
                   #{updtDt},
                   #{vmsCtlrNmbr},
                   #{cmncSttsCd},
                   #{pwerSttsCd},
                   #{modlSttsCd},
                   #{cboxDoorSttsCd},
                   #{fanSttsCd},
                   #{hetrSttsCd},
                   #{cboxTmpr},
                   #{brghVal},
                   #{commSttsCd},
                   #{modlStts},
                   #{pwerStts}
               )
        ]]>
    </insert>

    <insert id="batchInsertCtlrSttsHs" parameterType="java.util.Map">
    <![CDATA[
        insert into tb_vms_ctlr_stts_hs (
            crtn_dt,
            vms_ctlr_nmbr,
            cmnc_stts_cd,
            pwer_stts_cd,
            modl_stts_cd,
            cbox_door_stts_cd,
            fan_stts_cd,
            hetr_stts_cd,
            cbox_tmpr,
            brgh_val,
            comm_stts_cd,
            modl_stts,
            pwer_stts )
        values (
                   #{updtDt},
                   #{vmsCtlrNmbr},
                   #{cmncSttsCd},
                   #{pwerSttsCd},
                   #{modlSttsCd},
                   #{cboxDoorSttsCd},
                   #{fanSttsCd},
                   #{hetrSttsCd},
                   #{cboxTmpr},
                   #{brghVal},
                   #{commSttsCd},
                   #{modlStts},
                   #{pwerStts}
               )
        ]]>
    </insert>

    <insert id="insertRseCtlrCnncHs" parameterType="com.its.vms.entity.TbRseCtlrCnncHs">
    <![CDATA[
          INSERT INTO TB_RSE_CTLR_CNNC_HS (
                   RSE_CTLR_NMBR,
                   CLCT_DT,
                   LOG_TYPE,
                   LOG_ID,
                   LOG_ADDRESS )
          VALUES (
                  #{obj.RSE_CTLR_NMBR},
                  #{obj.CLCT_DT},
                  #{obj.LOG_TYPE},
                  #{obj.LOG_ID},
                  #{obj.LOG_ADDRESS}
                 )
    ]]>
    </insert>

    <insert id="insertRseCtrlHs" parameterType="com.its.vms.entity.TbRseCtrlHs">
    <![CDATA[
        INSERT INTO TB_RSE_CTRL_HS (
            RSE_CTLR_NMBR,
            CNTL_DT,
            DEVC_TYPE,
            CNTL_TYPE,
            RSPS_TYPE )
        VALUES (
                   #{obj.RSE_CTLR_NMBR},
                   #{obj.CNTL_DT},
                   #{obj.DEVC_TYPE},
                   #{obj.CNTL_TYPE},
                   #{obj.RSPS_TYPE}
               )
        ]]>
    </insert>

    <insert id="updateRseCtrlHs" parameterType="com.its.vms.entity.TbRseCtrlHs">
    <![CDATA[
        UPDATE TB_RSE_CTRL_HS
            SET RSPS_TYPE = #{obj.rspsType}
        WHERE CTRL_SEQ = #{obj.ctrlSeq}
        ]]>
    </insert>

</mapper>
