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

    <select id="selectRseSectAll" resultType="com.its.vms.entity.TbRseSect">
    <![CDATA[
        SELECT A.RSE_SECT_ID,
               A.SECT_LNGT,
               A.RSE_SECT_NM,
               A.STRT_SPOT_NM,
               A.END_SPOT_NM,
               A.STRT_RSE_CTLR_NMBR,
               A.END_RSE_CTLR_NMBR,
               A.DEL_YN
          FROM TB_RSE_SECT A, TB_RSE_CTLR S, TB_RSE_CTLR E
         WHERE A.DEL_YN  = 'N'
           AND A.STRT_RSE_CTLR_NMBR = S.RSE_CTLR_NMBR
           AND A.END_RSE_CTLR_NMBR  = E.RSE_CTLR_NMBR
         ORDER BY A.RSE_SECT_ID
    ]]>
    </select>

    <update id="updateRseSectTraf" parameterType="com.its.vms.entity.TbRseSectTraf">
    <![CDATA[
        MERGE INTO TB_RSE_SECT_TRAF L
            USING (SELECT
                       #{obj.RSE_SECT_ID} AS RSE_SECT_ID,
                       #{obj.PRCN_DT}     AS PRCN_DT,
                       #{obj.TFVL}        AS TFVL,
                       #{obj.TRVL_SPED}   AS TRVL_SPED,
                       #{obj.TRVL_HH}     AS TRVL_HH
                   FROM DUAL) M
            ON (L.RSE_SECT_ID = M.RSE_SECT_ID)
            WHEN MATCHED THEN
                UPDATE SET
                    L.PRCN_DT     = M.PRCN_DT,
                    L.TFVL        = M.TFVL,
                    L.TRVL_SPED   = M.TRVL_SPED,
                    L.TRVL_HH     = M.TRVL_HH
            WHEN NOT MATCHED THEN
                INSERT (
                        RSE_SECT_ID,
                        PRCN_DT,
                        TFVL,
                        TRVL_SPED,
                        TRVL_HH )
                VALUES (
                       M.RSE_SECT_ID,
                       M.PRCN_DT,
                       M.TFVL,
                       M.TRVL_SPED,
                       M.TRVL_HH )

        ]]>
    </update>

    <insert id="insertRseSectTrafHs" parameterType="com.its.vms.entity.TbRseSectTraf">
    <![CDATA[
        INSERT INTO TB_RSE_SECT_TRAF_HS (
            RSE_SECT_ID,
            PRCN_DT,
            TFVL,
            TRVL_SPED,
            TRVL_HH )
        VALUES (
                   #{obj.RSE_SECT_ID},
                   #{obj.PRCN_DT},
                   #{obj.TFVL},
                   #{obj.TRVL_SPED},
                   #{obj.TRVL_HH}
               )
        ]]>
    </insert>

    <insert id="insertRseSectPassHs" parameterType="com.its.vms.entity.TbRseSectPassHs">
    <![CDATA[
          INSERT INTO TB_RSE_SECT_PASS_HS (
                   RSE_SECT_ID,
                   CRTN_DT,
                   OBU_IDNT_NMBR,
                   STRT_SPOT_PASS_DT,
                   END_SPOT_PASS_DT )
          VALUES (
                  #{obj.RSE_SECT_ID},
                  #{obj.CRTN_DT},
                  #{obj.OBU_IDNT_NMBR},
                  #{obj.STRT_SPOT_PASS_DT},
                  #{obj.END_SPOT_PASS_DT}
                 )
    ]]>
    </insert>

</mapper>
