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

    <select id="findTableExist" parameterType="java.lang.String" resultType="com.utic.center.utic.stat.server.dto.TableExistDto" timeout="10">
        <![CDATA[
        SELECT COUNT(1) AS tableExist FROM USER_TABLES WHERE TABLE_NAME = #{tableName}
        ]]>
    </select>

    <update id="dropTable">
        <![CDATA[
        DROP TABLE ${tableName} PURGE
        ]]>
    </update>

    <update id="addTableComment" parameterType="java.lang.String">
        COMMENT ON TABLE ${tableName} IS '${tableComment}'
    </update>

    <update id="addColumnComment" parameterType="java.lang.String">
        COMMENT ON COLUMN ${tableName}.${columnName} IS '${columnComment}'
    </update>

    <update id="createTrafficCenterHistTable" parameterType="java.lang.String">
        create table TRAFFIC_CENTER_${crtMonth}
        (
            linkid         VARCHAR2(10) not null,
            missvalueyn    CHAR(1),
            regdate        DATE not null,
            linklevel      CHAR(1),
            speed          NUMBER(3),
            traveltime     NUMBER(7),
            trafficgrade   CHAR(2),
            incidentid     VARCHAR2(12),
            datarestype    CHAR(1),
            centerid       VARCHAR2(3),
            psdmissvalueyn CHAR(1),
            psdspeed       NUMBER(3),
            knnspeed       NUMBER(3),
            knncnt         NUMBER(3)
        )
        tablespace ODS_DATA
        pctfree 10
        initrans 1
        maxtrans 255
        storage
        (
           initial 64K
            next 1M
            minextents 1
            maxextents unlimited
        )
    </update>

    <update id="addTrafficCenterHistPrimaryKey" parameterType="java.lang.String">
        alter table TRAFFIC_CENTER_${crtMonth}
            add constraint PK_TRAFFIC_CENTER_${crtMonth} primary key (REGDATE, LINKID)
            using index
            tablespace ODS_INDX
            pctfree 10
            initrans 2
            maxtrans 255
            storage
            (
                initial 64K
                next 1M
                minextents 1
                maxextents unlimited
            )
    </update>

    <update id="createRcvLinkTrafficTable" parameterType="java.lang.String">
        create table RCV_LINK_TRAFFIC_${crtMonth}
        (
            regdate                    DATE not null,
            tocenterid                 VARCHAR2(20),
            linknumber                 VARCHAR2(20) not null,
            logdate                    DATE,
            fromcenterid               VARCHAR2(20) not null,
            speedrate                  NUMBER(3),
            volumerate                 NUMBER(6),
            densityrate                NUMBER(4),
            traveltimequantity         NUMBER(5),
            delayquanity               NUMBER(5),
            vehiclequeuelengthquantity NUMBER(6),
            occupancypercent           NUMBER(3)
        )
        tablespace ODS_DATA
        pctfree 10
        initrans 1
        maxtrans 255
        storage
        (
            initial 64K
            next 1M
            minextents 1
            maxextents unlimited
        )
    </update>

    <update id="addRcvLinkTrafficPrimaryKey" parameterType="java.lang.String">
        alter table RCV_LINK_TRAFFIC_${crtMonth}
            add constraint PK_RCV_LINK_TRAFFIC_${crtMonth} primary key (REGDATE, FROMCENTERID, LINKNUMBER)
            using index
            tablespace ODS_INDX
            pctfree 10
            initrans 2
            maxtrans 255
            storage
            (
                initial 64K
                next 1M
                minextents 1
                maxextents unlimited
            )
    </update>

    <update id="createPatnHistTable" parameterType="java.lang.String">
        create table ${tableName}
        (
            patn_date CHAR(8) not null,
            patn_time CHAR(4) not null,
            linkid    VARCHAR2(10) not null,
            speed     NUMBER(3),
            log_date  DATE,
            linklevel CHAR(1)
        )
        tablespace ${dataSpace}
        pctfree 10
        initrans 1
        maxtrans 255
        storage
        (
            initial 64K
            next 1M
            minextents 1
            maxextents unlimited
        )
    </update>

    <update id="addPatnHistPrimaryKey" parameterType="java.lang.String">
        alter table ${tableName}
            add constraint PK_${tableName} primary key (PATN_DATE, PATN_TIME, LINKID)
            using index
            tablespace ${indexSpace}
            pctfree 10
            initrans 2
            maxtrans 255
            storage
            (
                initial 64K
                next 1M
                minextents 1
                maxextents unlimited
            )
    </update>

    <update id="createStatLocalLogTable" parameterType="java.lang.String">
        create table STAT_LOCAL_LOG_${crtMonth}
        (
            local_date CHAR(14) not null,
            center_id  VARCHAR2(3) not null,
            linkid     VARCHAR2(10) not null,
            rev_type   CHAR(1),
            speed      NUMBER(3)
        )
        tablespace ODS_DATA
        pctfree 10
        initrans 1
        maxtrans 255
        storage
        (
            initial 64K
            next 1M
            minextents 1
            maxextents unlimited
        )
    </update>

    <update id="addStatLocalLogPrimaryKey" parameterType="java.lang.String">
        alter table STAT_LOCAL_LOG_${crtMonth}
            add constraint PK_STAT_LOCAL_LOG_${crtMonth} primary key (LOCAL_DATE, CENTER_ID, LINKID)
            using index
            tablespace ODS_INDX
            pctfree 10
            initrans 2
            maxtrans 255
            storage
            (
            initial 64K
            next 1M
            minextents 1
            maxextents unlimited
            )
    </update>

    <update id="createLinkFilterLogTable" parameterType="java.lang.String">
        create table LINK_FILTER_LOG_${crtMonth}
        (
            local_date          CHAR(14) not null,
            center_id           VARCHAR2(3) not null,
            linkid              VARCHAR2(10) not null,
            rev_type            CHAR(1),
            link_filter_yn      CHAR(1),
            linklevel_filter_yn CHAR(1),
            zero_yn             CHAR(1),
            std_yn              CHAR(1),
            sta_yn              CHAR(1),
            rgf_yn              CHAR(1)
        )
        tablespace ODS_DATA
        pctfree 10
        initrans 1
        maxtrans 255
        storage
        (
            initial 64K
            next 1M
            minextents 1
            maxextents unlimited
        )
    </update>

    <update id="addLinkFilterLogPrimaryKey" parameterType="java.lang.String">
        alter table LINK_FILTER_LOG_${crtMonth}
            add constraint PK_LINK_FILTER_LOG_${crtMonth} primary key (LOCAL_DATE, CENTER_ID, LINKID)
            using index
            tablespace ODS_INDX
            pctfree 10
            initrans 2
            maxtrans 255
            storage
            (
            initial 64K
            next 1M
            minextents 1
            maxextents unlimited
            )
    </update>

    <update id="createStatTable" parameterType="java.lang.String">
        create table ${tableName}
        (
            stat_date   CHAR(12) not null,
            linkid      VARCHAR2(10) not null,
            linklevel   CHAR(1),
            day_type    CHAR(1),
            speed       NUMBER(3),
            travel_time NUMBER(7),
            data_cnt    NUMBER(4)
        )
        tablespace DW_DATA
        pctfree 10
        initrans 1
        maxtrans 255
        storage
        (
            initial 64K
            next 1M
            minextents 1
            maxextents unlimited
        )
    </update>

    <update id="addStatPrimaryKey" parameterType="java.lang.String">
        alter table ${tableName}
            add constraint PK_${tableName} primary key (STAT_DATE, LINKID)
            using index
            tablespace DW_INDX
            pctfree 10
            initrans 2
            maxtrans 255
            storage
            (
            initial 64K
            next 1M
            minextents 1
            maxextents unlimited
            )
    </update>


</mapper>
