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

    <select id="findAnalysisType" resultType="com.utic.center.utic.traf.server.dto.dwdb.ParamAnalysisType">
        <![CDATA[
        SELECT TO_NUMBER(NVL(codevalue, '0')) AS analysisType
        FROM CODEDEFINE@DWDB
        WHERE maincode = 'C04'
          AND subcode  = 'T00'
        ]]>
    </select>

    <select id="findPtrnEffectDays" resultType="com.utic.center.utic.traf.server.dto.dwdb.ParamPatternEffectDay">
        <![CDATA[
        SELECT TO_NUMBER(DECODE(CODEVALUE, NULL, '365', CODEVALUE)) AS effectDays
        FROM CODEDEFINE@DWDB
        WHERE MAINCODE = 'C02'
          AND SUBCODE  = 'T05'
        ]]>
    </select>

    <select id="findMissing" resultType="com.utic.center.utic.traf.server.dto.dwdb.ParamMissing">
        <![CDATA[
        SELECT decode(SUBSTR(codevalue, 1, 1), 'Y', 1, 0) AS usePst,
               decode(SUBSTR(codevalue, 2, 1), 'Y', 1, 0) AS useKnn,
               decode(SUBSTR(codevalue, 3, 1), 'Y', 1, 0) AS usePtn,
               decode(SUBSTR(codevalue, 4, 1), 'Y', 1, 0) AS extKnn,
               NVL(minvalue, 0)                           AS missPri
        FROM CODEDEFINE@DWDB
        WHERE maincode = 'C03'
          AND subcode  = 'T00'
        ]]>
    </select>

    <select id="findHoliday" parameterType="java.lang.String" resultType="com.utic.center.utic.traf.server.dto.dwdb.ParamHoliday">
        <![CDATA[
        SELECT SUM(WDAY) AS wDay, SUM(HCNT) AS hCnt
        FROM (SELECT TO_NUMBER(TO_CHAR(TO_DATE(#{ptrnTime}, 'YYYYMMDDHH24MISS'), 'D')) AS WDAY, 0 HCNT
              FROM DUAL
              UNION ALL
              SELECT 0 AS WDAY, COUNT(1) AS HCNT
              FROM HOLIDAY@DWDB
              WHERE HOLIDAY = SUBSTR(#{ptrnTime}, 1, 8)
             )
        ]]>
    </select>

    <select id="findPtrnMissingLink" parameterType="java.lang.String" resultType="java.lang.String" fetchSize="2000">
        <![CDATA[
        SELECT A.LINKID AS linkId
        FROM LINK@DWDB A
        WHERE A.LINKLEVEL = '1'
          AND SUBSTR(A.LINKID, 1, 3) IN (SELECT SLOCAL_ID
                                         FROM LOCAL_AREA@DWDB
                                         WHERE REVISION_YN = 'Y'
                                        )
        ]]>
    </select>

</mapper>
