<?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.traf.server.dao.mapper.utic.UticParamMapper">

    <select id="findTrafficGrade" resultType="com.utic.center.utic.traf.server.dto.utic.TrafficGrade" fetchSize="10">
        <![CDATA[
        SELECT DECODE(A.ROADRANK,
                      '101', 0,
                      '102', 1,
                      '103', 2,
                      '104', 3,
                      '105', 4,
                      '106', 5,
                      '107', 6,
                      '108', 7,
                             8)          AS roadRank,
               A.MINSPEED                AS minSpeed,
               A.MAXSPEED                AS maxSpeed,
               NVL(B.limitMinSpeed,   5) AS limitMinSpeed,
               NVL(B.limitMaxSpeed, 120) AS limitMaxSpeed
        FROM TRAFFICGRADE A,
             (SELECT DECODE(SUBCODE,
                            'T01', '101',
                            'T02', '102',
                            'T03', '103',
                                   '104') AS ROADRANK,
                     NVL(MINVALUE,   5)   AS limitMinSpeed,
                     NVL(MAXVALUE, 120)   AS limitMaxSpeed
              FROM CODEDEFINE
              WHERE MAINCODE = 'C02'
                AND SUBCODE IN ('T01', 'T02', 'T03', 'T04')
             ) B
        WHERE A.TRAFFICGRADE = '02'
          AND A.ROADRANK = B.ROADRANK(+)
        ]]>
    </select>

<!--    <select id="findTrafficGrade" resultType="com.utic.center.utic.traf.server.dto.utic.TrafficGrade" fetchSize="10">-->
<!--        <![CDATA[-->
<!--        SELECT DECODE(A.ROADRANK,-->
<!--                      '101', 0,-->
<!--                      '102', 1,-->
<!--                      '103', 2,-->
<!--                      '104', 3,-->
<!--                      '105', 4,-->
<!--                      '106', 5,-->
<!--                      '107', 6,-->
<!--                      '108', 7,-->
<!--                      8) AS roadRank,-->
<!--               A.MINSPEED AS minSpeed,-->
<!--               A.MAXSPEED AS maxSpeed,-->
<!--               5          AS limitMinSpeed,-->
<!--               120        AS limitMaxSpeed-->
<!--        FROM TRAFFICGRADE A-->
<!--        WHERE A.TRAFFICGRADE = '02'-->
<!--        ]]>-->
<!--    </select>-->
<!--    <select id="findTrafficGrade" resultType="com.utic.center.utic.traf.server.dto.utic.TrafficGrade" fetchSize="10">-->
<!--        <![CDATA[-->
<!--        SELECT A.ROADRANK AS roadRank,-->
<!--               A.MINSPEED AS minSpeed,-->
<!--               A.MAXSPEED AS maxSpeed-->
<!--        FROM TRAFFICGRADE A-->
<!--        WHERE A.TRAFFICGRADE = '02'-->
<!--        ]]>-->
<!--    </select>-->
    <select id="findTrafficWeight" resultType="com.utic.center.utic.traf.server.dto.utic.TrafficWeight" fetchSize="10">
        <![CDATA[
        SELECT WEIGHTCODE AS weightCode,
               DECODE(SUBSTR(WEIGHTCODE, 1, 1), '1', 8, 0) +
               DECODE(SUBSTR(WEIGHTCODE, 2, 1), '1', 4, 0) +
               DECODE(SUBSTR(WEIGHTCODE, 3, 1), '1', 2, 0) +
               DECODE(SUBSTR(WEIGHTCODE, 4, 1), '1', 1, 0) AS valIdx,
               NVL(GPS,    0) AS gps,
               NVL(UTIS,   0) AS utis,
               NVL(LOC,    0) AS loc,
               NVL(DONGBU, 0) AS dongbu,
               DATARESTYPE    AS dataResType
        FROM TRAFFIC_WEIGHT
        ORDER BY valIdx
        ]]>
    </select>

</mapper>
