<?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.siginfo.dao.SigOpenDao">

    <!-- <resultMap type="com.siginfo.vo.CrossRoadInfoXmlVO" id="sigopenVO">
        <result property="regionCd" column="REGION_CD" />
        <result property="intNo" column="INT_NO" />
        <result property="intNm" column="INT_NM" />
        <result property="xCoord" column="X_COORD" />
        <result property="yCoord" column="Y_COORD" />
        <result property="updDtime" column="UPD_DTIME" />
    </resultMap>

    <select id="getCrossRoadInfoList" resultMap="sigopenVO">
        SELECT REGION_CD,
               INT_NO,
               INT_NM,
               X_COORD,
               Y_COORD,
               UPD_DTIME
          FROM TB_INT
    </select> -->

    <select id="getCrossRoadInfoList" parameterType="java.util.HashMap" resultType="com.siginfo.vo.CrossRoadInfoListVO">
        SELECT A.*
        FROM
        (
        SELECT ROWNUM RN,
        TI.REGION_CD,
        TI.INT_NO,
        TI.INT_NM,
        TI.X_COORD,
        TI.Y_COORD,
        TO_CHAR(NVL(TI.UPD_DTIME,SYSDATE),'YYYY-MM-DD HH24:MI:SS') UPD_DTIME
        FROM TB_INT TI, TB_OPENDB_CENTER TOC
        WHERE TI.REGION_CD = TOC.REGION_CD
        <if test='srchCTId != ""'>AND TI.REGION_CD = #{srchCTId}</if>
        <if test='srchCRNm != ""'>AND TI.INT_NM = #{srchCRNm}</if>
        ) A
        WHERE A.RN BETWEEN #{sRow} AND #{eRow}
        ORDER BY A.REGION_CD,A.INT_NO
    </select>

    <select id="getCrossRoadDetailList" parameterType="java.util.HashMap" resultType="com.siginfo.vo.CrossRoadInfoDetailVO">
        SELECT A.*
        FROM
        (
        SELECT ROWNUM RN,
        AA.REGION_CD,
        AA.INT_NO,
        AA.INT_NM,
        TIP.MAP_NO,
        TIP.INT_MAINPHASE,
        TIP.A_RING_1_PHASE_CONF_CD,
        TIP.A_RING_2_PHASE_CONF_CD,
        TIP.A_RING_3_PHASE_CONF_CD,
        TIP.A_RING_4_PHASE_CONF_CD,
        TIP.A_RING_5_PHASE_CONF_CD,
        TIP.A_RING_6_PHASE_CONF_CD,
        TIP.A_RING_7_PHASE_CONF_CD,
        TIP.A_RING_8_PHASE_CONF_CD,
        TIP.B_RING_1_PHASE_CONF_CD,
        TIP.B_RING_2_PHASE_CONF_CD,
        TIP.B_RING_3_PHASE_CONF_CD,
        TIP.B_RING_4_PHASE_CONF_CD,
        TIP.B_RING_5_PHASE_CONF_CD,
        TIP.B_RING_6_PHASE_CONF_CD,
        TIP.B_RING_7_PHASE_CONF_CD,
        TIP.B_RING_8_PHASE_CONF_CD
        FROM
        (
        SELECT TI.REGION_CD,
        TI.INT_NO,
        TI.INT_NM
        FROM TB_INT TI, TB_OPENDB_CENTER TOC
        WHERE TI.REGION_CD = TOC.REGION_CD
        ) AA,TB_INT_PHASE TIP
        WHERE 1=1
        AND AA.REGION_CD = TIP.REGION_CD
        AND AA.INT_NO = TIP.INT_NO
        <if test='srchCTId != ""'>AND AA.REGION_CD = #{srchCTId}</if>
        <if test='srchCRNm != ""'>AND AA.INT_NM = #{srchCRNm}</if>
        ) A
        WHERE A.RN BETWEEN #{sRow} AND #{eRow}
        ORDER BY A.REGION_CD,A.INT_NO,A.MAP_NO
    </select>

    <select id="getPlanCRHDInfoList" parameterType="java.util.HashMap" resultType="com.siginfo.vo.PlanCRHDInfoVO">
        SELECT A.*
        FROM
        (
        SELECT ROWNUM RN,
        AA.REGION_CD,
        AA.INT_NO,
        AA.INT_NO_SE,
        AA.INT_NM,
        TIHP.PLAN_SN,
        TIHP.HOLYDD_PLAN_MM,
        TIHP.HOLYDD_PLAN_DD,
        TIHP.INT_PLAN_NO,
        TO_CHAR(TIHP.COLLCT_DTIME,'YYYY-MM-DD HH24:MI:SS') COLLCT_DTIME
        FROM (
        SELECT TI.REGION_CD,
        TI.INT_NO,
        DECODE(TI.MAIN_INTNO,0,TI.INT_NO,TI.MAIN_INTNO) INT_NO_SE,
        TI.INT_NM
        FROM TB_INT TI, TB_OPENDB_CENTER TOC
        WHERE TI.REGION_CD = TOC.REGION_CD
        ) AA LEFT OUTER JOIN TB_INT_HOLYDD_PLAN TIHP
        ON AA.REGION_CD = TIHP.REGION_CD
        AND AA.INT_NO_SE = TIHP.INT_NO
        WHERE 1=1
        <if test='srchCTId != ""'>AND AA.REGION_CD = #{srchCTId}</if>
        <if test='srchCRNm != ""'>AND AA.INT_NM = #{srchCRNm}</if>
        ) A
        WHERE A.RN BETWEEN #{sRow} AND #{eRow}
        ORDER BY A.REGION_CD,A.INT_NO,A.PLAN_SN
    </select>

    <select id="getPlanCRWDInfoList" parameterType="java.util.HashMap" resultType="com.siginfo.vo.PlanCRWDInfoVO">
        SELECT A.*
        FROM
        (
        SELECT ROWNUM RN,
        AA.REGION_CD,
        AA.INT_NO,
        AA.INT_NO_SE,
        AA.INT_NM,
        TIDP.PLAN_DY,
        TIDP.INT_PLAN_NO,
        TO_CHAR(TIDP.COLLCT_DTIME,'YYYY-MM-DD HH24:MI:SS') COLLCT_DTIME
        FROM (
        SELECT TI.REGION_CD,
        TI.INT_NO,
        DECODE(TI.MAIN_INTNO,0,TI.INT_NO,TI.MAIN_INTNO) INT_NO_SE,
        TI.INT_NM
        FROM TB_INT TI, TB_OPENDB_CENTER TOC
        WHERE TI.REGION_CD = TOC.REGION_CD
        ) AA LEFT OUTER JOIN TB_INT_DY_PLAN TIDP
        ON AA.REGION_CD = TIDP.REGION_CD
        AND AA.INT_NO_SE = TIDP.INT_NO
        WHERE 1=1
        <if test='srchCTId != ""'>AND AA.REGION_CD = #{srchCTId}</if>
        <if test='srchCRNm != ""'>AND AA.INT_NM = #{srchCRNm}</if>
        ) A
        WHERE A.RN BETWEEN #{sRow} AND #{eRow}
        ORDER BY A.REGION_CD,A.INT_NO
    </select>

    <select id="getPlanCRRSInfoList" parameterType="java.util.HashMap" resultType="com.siginfo.vo.PlanCRRSInfoVO">
        <!--
        SELECT A.*
              FROM
                (
                SELECT ROWNUM RN,
                       AA.REGION_CD,
                       AA.INT_NO,
                       AA.INT_NO_SE,
                       AA.INT_NM,
                       TIRP.RESRV_NO,
                       TIRP.RESRV_MM,
                       TIRP.RESRV_DD,
                       TIRP.RESRV_DY,
                       TIRP.RESRV_STRT_HH,
                       TIRP.RESRV_STRT_MI,
                       TIRP.RESRV_END_HH,
                       TIRP.RESRV_END_MI,
                       TIRP.RESRV_CONTRL_CD,
                       TO_CHAR(TIRP.COLLCT_DTIME,'YYYY-MM-DD HH24:MI:SS') UPD_DTIME
                  FROM (
                    SELECT TI.REGION_CD,
                           TI.INT_NO,
                           DECODE(TI.MAIN_INTNO,0,TI.INT_NO,TI.MAIN_INTNO) INT_NO_SE,
                           TI.INT_NM
                      FROM TB_INT TI, TB_OPENDB_CENTER TOC
                    WHERE TI.REGION_CD = TOC.REGION_CD
                  ) AA LEFT OUTER JOIN TB_INT_RESRV_PLAN TIRP
                    ON AA.REGION_CD = TIRP.REGION_CD
                   AND AA.INT_NO_SE = TIRP.INT_NO
                 WHERE 1=1
                 <if test='srchCTId != ""'>AND AA.REGION_CD = #{srchCTId}</if>
                 <if test='srchCRNm != ""'>AND AA.INT_NM = #{srchCRNm}</if>
                 ) A
         WHERE A.RN BETWEEN #{sRow} AND #{eRow}
         ORDER BY A.REGION_CD,A.INT_NO
          -->
        SELECT A.*
        FROM
        (
        SELECT ROWNUM RN,
        AA.REGION_CD,
        AA.INT_NO,
        AA.INT_NO_SE,
        AA.INT_NM,
        TIRP.RESRV_NO,
        TIRP.RESRV_MM,
        TIRP.RESRV_DD,
        TIRP.RESRV_DY,
        TIRP.RESRV_STRT_HH,
        TIRP.RESRV_STRT_MI,
        TIRP.RESRV_END_HH,
        TIRP.RESRV_END_MI,
        TIRP.RESRV_CONTRL_CD,
        TIRP.RESRV_PLAN_NO,
        TO_CHAR(TIRP.COLLCT_DTIME,'YYYY-MM-DD HH24:MI:SS') UPD_DTIME
        FROM (
        SELECT TI.REGION_CD,
        TI.INT_NO,
        DECODE(TI.MAIN_INTNO,0,TI.INT_NO,TI.MAIN_INTNO) INT_NO_SE,
        TI.INT_NM
        FROM TB_INT TI, TB_OPENDB_CENTER TOC
        WHERE TI.REGION_CD = TOC.REGION_CD
        ) AA JOIN TB_INT_RESRV_PLAN TIRP
        ON AA.REGION_CD = TIRP.REGION_CD
        AND AA.INT_NO_SE = TIRP.INT_NO
        WHERE 1=1
        <if test='srchCTId != ""'>AND AA.REGION_CD = #{srchCTId}</if>
        <if test='srchCRNm != ""'>AND AA.INT_NM = #{srchCRNm}</if>
        AND TIRP.RESRV_CONTRL_CD != '0'
        ) A
        WHERE A.RN BETWEEN #{sRow} AND #{eRow}
        ORDER BY A.REGION_CD,A.INT_NO

    </select>

    <select id="getPlanCROPInfoList" parameterType="java.util.HashMap" resultType="com.siginfo.vo.PlanCROPInfoVO">
        SELECT A.*
        FROM
        (SELECT ROWNUM RN,
        AA.REGION_CD,
        AA.INT_NO,
        AA.INT_NO_SE,
        AA.INT_NM,
        TIOP.INT_PLAN_NO       ,
        TIOP.INT_PLAN_IDX_NO   ,
        TIOP.OPER_PLAN_HH      ,
        TIOP.OPER_PLAN_MI      ,
        TIOP.INT_OPER_CYCLE_VAL,
        TIOP.INT_OPER_OFFSET_VAL,
        TIOP.A_RING_1_PHASE_VAL,
        TIOP.A_RING_2_PHASE_VAL,
        TIOP.A_RING_3_PHASE_VAL,
        TIOP.A_RING_4_PHASE_VAL,
        TIOP.A_RING_5_PHASE_VAL,
        TIOP.A_RING_6_PHASE_VAL,
        TIOP.A_RING_7_PHASE_VAL,
        TIOP.A_RING_8_PHASE_VAL,
        TIOP.B_RING_1_PHASE_VAL,
        TIOP.B_RING_2_PHASE_VAL,
        TIOP.B_RING_3_PHASE_VAL,
        TIOP.B_RING_4_PHASE_VAL,
        TIOP.B_RING_5_PHASE_VAL,
        TIOP.B_RING_6_PHASE_VAL,
        TIOP.B_RING_7_PHASE_VAL,
        TIOP.B_RING_8_PHASE_VAL
        FROM (
        SELECT TI.REGION_CD,
        TI.INT_NO,
        DECODE(TI.MAIN_INTNO,0,TI.INT_NO,TI.MAIN_INTNO) INT_NO_SE,
        TI.INT_NM
        FROM TB_INT TI, TB_OPENDB_CENTER TOC
        WHERE TI.REGION_CD = TOC.REGION_CD
        ) AA LEFT OUTER JOIN TB_INT_OPER_PLAN TIOP
        ON AA.REGION_CD = TIOP.REGION_CD
        AND AA.INT_NO_SE = TIOP.INT_NO
        WHERE 1=1
        <if test='srchCTId != ""'>AND AA.REGION_CD = #{srchCTId}</if>
        <if test='srchCRNm != ""'>AND AA.INT_NM = #{srchCRNm}</if>
        ) A
        WHERE A.RN BETWEEN #{sRow} AND #{eRow}
        ORDER BY A.REGION_CD,A.INT_NO
    </select>

    <select id="getTotalCount" parameterType="java.util.HashMap" resultType="com.siginfo.vo.CrossRoadInfoHeaderVO">
        <!--
        SELECT
               COUNT(*) totCount,
               CEIL(COUNT(*) / #{numOfRows}) totPage
          FROM (
                   SELECT TI.REGION_CD,
                          DECODE(TI.MAIN_INTNO,0,TI.INT_NO,TI.MAIN_INTNO) INT_NO_SE,
                          TI.INT_NM
                     FROM TB_INT TI, TB_OPENDB_CENTER TOC
                   WHERE TI.REGION_CD = TOC.REGION_CD
                 ) AA LEFT OUTER JOIN ${tableId} A
            ON AA.REGION_CD = A.REGION_CD
           AND AA.INT_NO_SE = A.INT_NO
         <if test='srchCTId != ""'>WHERE AA.REGION_CD = #{srchCTId}</if>
          <if test='srchCRNm != ""'>AND AA.INT_NM = #{srchCRNm}</if>
           -->
        SELECT
        COUNT(*) totCount,
        CEIL(COUNT(*) / 10) totPage
        FROM (
        SELECT TI.REGION_CD,
        DECODE(TI.MAIN_INTNO,0,TI.INT_NO,TI.MAIN_INTNO) INT_NO_SE,
        TI.INT_NM
        FROM TB_INT TI, TB_OPENDB_CENTER TOC
        WHERE TI.REGION_CD = TOC.REGION_CD
        ) AA JOIN ${tableId} A
        ON AA.REGION_CD = A.REGION_CD
        AND AA.INT_NO_SE = A.INT_NO
        WHERE 1=1
        <if test='tableId eq "TB_INT_RESRV_eq PLAN".toString()'>AND A.RESRV_CONTRL_CD != '0'</if>
        <if test='srchCTId != ""'>AND AA.REGION_CD = #{srchCTId}</if>
        <if test='srchCRNm != ""'>AND AA.INT_NM = #{srchCRNm}</if>

    </select>

</mapper>