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

    <select id="selectAll" resultType="com.its.vds.entity.TbVdsDtct" fetchSize="50">
    <![CDATA[
        select t1.vds_ctlr_nmbr AS vdsCtlrNmbr,
               t2.vds_dtct_nmbr AS vdsDtctNmbr,
               t2.vds_dtct_id   AS vdsDtctId,
               t2.vds_dtct_nm   AS vdsDtctNm,
               t2.vds_cmra_no   AS vdsCmraNo,
               t2.dtct_type     AS dtctType,
               t2.dtct_dir      AS dtctDir,
               t2.detect_lane   AS detectLane,
               t2.istl_lane     AS istlLane,
               t2.sped_clct_yn  AS spedClctYn,
               t2.tfvl_clct_yn  AS tfvlClctYn,
               t2.ocpy_clct_yn  AS ocpyClctYn,
               t2.max_tfvl      AS maxTfvl,
               t2.min_tfvl      AS minTfvl,
               t2.max_ocpy_rate AS maxOcpyRate,
               t2.min_ocpy_rate AS minOcpyRate,
               t2.max_sped      AS maxSped,
               t2.min_sped      AS minSped,
               t2.use_yn        AS useYn,
               t2.del_yn        AS delYn
        from  tb_vds_ctlr t1, tb_vds_dtct t2
       where t1.del_yn = 'N'
         and t2.del_yn = 'N'
         and t1.vds_ctlr_nmbr = t2.vds_ctlr_nmbr
         and t2.detect_lane between 1 and 16
       order by t1.vds_ctlr_nmbr, t2.detect_lane, t2.istl_lane
    ]]>
    </select>

    <update id="updateVdsDtctStts" parameterType="com.its.vds.entity.TbVdsDtctStts">
    <![CDATA[
        merge into tb_vds_dtct_stts L
            using (select
                       #{obj.vdsDtctNmbr} AS vds_dtct_nmbr,
                       #{obj.updtDt}      AS updt_dt,
                       #{obj.dtctStts}    AS dtct_stts
                   from dual) M
            on (    L.vds_dtct_nmbr = M.vds_dtct_nmbr)
            when matched then
                update set
                    L.updt_dt   = M.updt_dt,
                    L.dtct_stts = M.dtct_stts
            when not matched then
                insert (
                        vds_dtct_nmbr,
                        updt_dt,
                        dtct_stts )
                values (
                        M.vds_dtct_nmbr,
                        M.updt_dt,
                        M.dtct_stts )
        ]]>
    </update>

    <update id="batchUpdateVdsDtctStts" parameterType="java.util.Map">
    <![CDATA[
        merge into tb_vds_dtct_stts L
            using (select
                       #{vdsDtctNmbr} AS vds_dtct_nmbr,
                       #{updtDt}      AS updt_dt,
                       #{dtctStts}    AS dtct_stts
                   from dual) M
            on (    L.vds_dtct_nmbr = M.vds_dtct_nmbr)
            when matched then
                update set
                    L.updt_dt   = M.updt_dt,
                    L.dtct_stts = M.dtct_stts
            when not matched then
                insert (
                        vds_dtct_nmbr,
                        updt_dt,
                        dtct_stts )
                values (
                        M.vds_dtct_nmbr,
                        M.updt_dt,
                        M.dtct_stts )
        ]]>
    </update>

    <insert id="insertVdsDtctSttsHs" parameterType="com.its.vds.entity.TbVdsDtctStts">
    <![CDATA[
        insert into tb_vds_dtct_stts_hs (
            crtn_dt,
            vds_dtct_nmbr,
            dtct_stts )
        values (
               #{obj.updtDt},
               #{obj.vdsDtctNmbr},
               #{obj.dtctStts}
           )
        ]]>
    </insert>

    <insert id="batchInsertVdsDtctSttsHs" parameterType="java.util.Map">
    <![CDATA[
        insert into tb_vds_dtct_stts_hs (
            crtn_dt,
            vds_dtct_nmbr,
            dtct_stts )
        values (
               #{updtDt},
               #{vdsDtctNmbr},
               #{dtctStts}
           )
        ]]>
    </insert>

    <insert id="insertVdsDtctClct" parameterType="com.its.vds.entity.TbVdsDtctClct">
    <![CDATA[
        insert into tb_vds_dtct_clct (
            clct_dt,
            vds_dtct_nmbr,
            traf_clct_cycl,
            tfvl,
            sped,
            avrg_ocpy_rate,
            avrg_lngt,
            hdwy,
            spce_ocpy_rate,
            spce_avrg_sped )
        values (
               #{obj.clctDt},
               #{obj.vdsDtctNmbr},
               #{obj.trafClctCycl},
               #{obj.tfvl},
               #{obj.sped},
               #{obj.avrgOcpyRate},
               #{obj.avrgLngt},
               #{obj.hdwy},
               #{obj.spceOcpyRate},
               #{obj.spceAvrgSped}
           )
        ]]>
    </insert>

    <insert id="batchInsertVdsDtctClct" parameterType="java.util.Map">
    <![CDATA[
        insert into tb_vds_dtct_clct (
            clct_dt,
            vds_dtct_nmbr,
            traf_clct_cycl,
            tfvl,
            sped,
            avrg_ocpy_rate,
            avrg_lngt,
            hdwy,
            spce_ocpy_rate,
            spce_avrg_sped )
        values (
               #{clctDt},
               #{vdsDtctNmbr},
               #{trafClctCycl},
               #{tfvl},
               #{sped},
               #{avrgOcpyRate},
               #{avrgLngt},
               #{hdwy},
               #{spceOcpyRate},
               #{spceAvrgSped}
           )
        ]]>
    </insert>

    <insert id="insertVdsDtctVehClct" parameterType="com.its.vds.entity.TbVdsDtctVehClct">
    <![CDATA[
        insert into tb_vds_dtct_veh_clct (
            clct_dt,
            vds_dtct_nmbr,
            clct_seq,
            detect_lane,
            veh_clct_dt,
            sync_pass_time,
            sped,
            ocpy_time,
            veh_type,
            hdwy_veh_time )
        values (
               #{obj.clctDt},
               #{obj.vdsDtctNmbr},
               #{obj.clctSeq},
               #{obj.detectLane},
               #{obj.vehClctDt},
               #{obj.syncPassTime},
               #{obj.sped},
               #{obj.ocpyTime},
               #{obj.vehType},
               #{obj.hdwyVehTime}
           )
        ]]>
    </insert>

    <insert id="batchInsertVdsDtctVehClct" parameterType="java.util.Map">
    <![CDATA[
        insert into tb_vds_dtct_veh_clct (
            clct_dt,
            vds_dtct_nmbr,
            clct_seq,
            detect_lane,
            veh_clct_dt,
            sync_pass_time,
            sped,
            ocpy_time,
            veh_type,
            hdwy_veh_time )
        values (
               #{clctDt},
               #{vdsDtctNmbr},
               #{clctSeq},
               #{detectLane},
               #{vehClctDt},
               #{syncPassTime},
               #{sped},
               #{ocpyTime},
               #{vehType},
               #{hdwyVehTime}
           )
        ]]>
    </insert>

    <update id="updateVdsDtctClctPnst" parameterType="com.its.vds.entity.TbVdsDtctVehClct">
    <![CDATA[
        merge into tb_vds_dtct_clct_pnst L
            using (select
                       #{obj.vdsDtctNmbr}  AS vds_dtct_nmbr,
                       #{obj.clctDt}       AS clct_dt,
                       #{obj.trafClctCycl} AS traf_clct_cycl,
                       #{obj.tfvl}         AS tfvl,
                       #{obj.sped}         AS sped,
                       #{obj.avrgOcpyRate} AS avrg_ocpy_rate,
                       #{obj.avrgLngt}     AS avrg_lngt,
                       #{obj.hdwy}         AS hdwy,
                       #{obj.spceOcpyRate} AS spce_ocpy_rate,
                       #{obj.spceAvrgSped} AS spce_avrg_sped
                   from dual) M
            on (    L.vds_dtct_nmbr = M.vds_dtct_nmbr)
            when matched then
                update set
                    L.clct_dt        = M.clct_dt,
                    L.traf_clct_cycl = M.traf_clct_cycl,
                    L.tfvl           = M.tfvl,
                    L.sped           = M.sped,
                    L.avrg_ocpy_rate = M.avrg_ocpy_rate,
                    L.avrg_lngt      = M.avrg_lngt,
                    L.hdwy           = M.hdwy,
                    L.spce_ocpy_rate = M.spce_ocpy_rate,
                    L.spce_avrg_sped = M.spce_avrg_sped
            when not matched then
                insert (
                        vds_dtct_nmbr,
                        clct_dt,
                        traf_clct_cycl,
                        tfvl,
                        sped,
                        avrg_ocpy_rate,
                        avrg_lngt,
                        hdwy,
                        spce_ocpy_rate,
                        spce_avrg_sped )
                values (
                       M.vds_dtct_nmbr,
                       M.clct_dt,
                       M.traf_clct_cycl,
                       M.tfvl,
                       M.sped,
                       M.avrg_ocpy_rate,
                       M.avrg_lngt,
                       M.hdwy,
                       M.spce_ocpy_rate,
                       M.spce_avrg_sped )
        ]]>
    </update>

    <update id="batchUpdateVdsDtctClctPnst" parameterType="java.util.Map">
    <![CDATA[
        merge into tb_vds_dtct_clct_pnst L
            using (select
                       #{vdsDtctNmbr}  AS vds_dtct_nmbr,
                       #{clctDt}       AS clct_dt,
                       #{trafClctCycl} AS traf_clct_cycl,
                       #{tfvl}         AS tfvl,
                       #{sped}         AS sped,
                       #{avrgOcpyRate} AS avrg_ocpy_rate,
                       #{avrgLngt}     AS avrg_lngt,
                       #{hdwy}         AS hdwy,
                       #{spceOcpyRate} AS spce_ocpy_rate,
                       #{spceAvrgSped} AS spce_avrg_sped
                   from dual) M
            on (    L.vds_dtct_nmbr = M.vds_dtct_nmbr)
            when matched then
                update set
                    L.clct_dt        = M.clct_dt,
                    L.traf_clct_cycl = M.traf_clct_cycl,
                    L.tfvl           = M.tfvl,
                    L.sped           = M.sped,
                    L.avrg_ocpy_rate = M.avrg_ocpy_rate,
                    L.avrg_lngt      = M.avrg_lngt,
                    L.hdwy           = M.hdwy,
                    L.spce_ocpy_rate = M.spce_ocpy_rate,
                    L.spce_avrg_sped = M.spce_avrg_sped
            when not matched then
                insert (
                        vds_dtct_nmbr,
                        clct_dt,
                        traf_clct_cycl,
                        tfvl,
                        sped,
                        avrg_ocpy_rate,
                        avrg_lngt,
                        hdwy,
                        spce_ocpy_rate,
                        spce_avrg_sped )
                values (
                       M.vds_dtct_nmbr,
                       M.clct_dt,
                       M.traf_clct_cycl,
                       M.tfvl,
                       M.sped,
                       M.avrg_ocpy_rate,
                       M.avrg_lngt,
                       M.hdwy,
                       M.spce_ocpy_rate,
                       M.spce_avrg_sped )
        ]]>
    </update>

</mapper>
