<?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.utic.center.utic.stat.server.dao.mapper.UticStat04MinEtlpMapper">

    <select id="findTrafficCenter" resultType="com.utic.center.utic.stat.server.dto.TrafficCenterDto" timeout="30">
        <![CDATA[
        SELECT NVL(TO_CHAR(MAX(REGDATE), 'YYYYMMDDHH24MISS'), 'X') AS maxRegDate, COUNT(1) AS dataCount
        FROM TRAFFIC_CENTER@UTISDB
        ]]>
    </select>

    <insert id="insertTrafficCenterHist" parameterType="java.lang.String" timeout="120">
        <![CDATA[
        INSERT INTO TRAFFIC_CENTER_${yyMm} NOLOGGING (
                        regdate        ,
                        linkid         ,
                        missvalueyn    ,
                        linklevel      ,
                        speed          ,
                        traveltime     ,
                        trafficgrade   ,
                        incidentid     ,
                        datarestype    ,
                        centerid       ,
                        psdmissvalueyn ,
                        psdspeed
                        )
        SELECT regdate        ,
               linkid         ,
               missvalueyn    ,
               linklevel      ,
               speed          ,
               traveltime     ,
               trafficgrade   ,
               NULL           ,
               datarestype    ,
               centerid       ,
               psdmissvalueyn ,
               psdspeed
        FROM TRAFFIC_CENTER@UTISDB
        ]]>
    </insert>

    <insert id="insertRcvLinkTraffic" parameterType="java.lang.String" timeout="120">
        <![CDATA[
        INSERT INTO RCV_LINK_TRAFFIC_${yyMm}(REGDATE, TOCENTERID, LINKNUMBER, LOGDATE, FROMCENTERID, SPEEDRATE, VOLUMERATE, DENSITYRATE,
                                     TRAVELTIMEQUANTITY, DELAYQUANITY, VEHICLEQUEUELENGTHQUANTITY, OCCUPANCYPERCENT)
        SELECT REGDATE, TOCENTERID, LINKNUMBER, LOGDATE, FROMCENTERID, SPEEDRATE, VOLUMERATE, DENSITYRATE, TRAVELTIMEQUANTITY,
               DELAYQUANITY, VEHICLEQUEUELENGTHQUANTITY, OCCUPANCYPERCENT
        FROM RCV_LINK_TRAFFIC@TPEGDB a
        WHERE REGDATE > TO_DATE(#{past10Min}, 'YYYYMMDDHH24MISS')
            MINUS
        SELECT /*+ INDEX(T PK_RCV_LINK_TRAFFIC_${yyMm}) */
               T.REGDATE, T.TOCENTERID, T.LINKNUMBER, T.LOGDATE, T.FROMCENTERID, T.SPEEDRATE, T.VOLUMERATE, T.DENSITYRATE, T.TRAVELTIMEQUANTITY,
               T.DELAYQUANITY, T.VEHICLEQUEUELENGTHQUANTITY, T.OCCUPANCYPERCENT
        FROM RCV_LINK_TRAFFIC_${yyMm} T
        WHERE T.REGDATE > TO_DATE(#{past10Min}, 'YYYYMMDDHH24MISS')
        ]]>
    </insert>

</mapper>
