<?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="cbdoro.mods.facilityInfo.ae050.mapper.Ae050Mapper">

    <resultMap id="Ae050FeaVoMap" type="Ae050FeaVO">
        <result column="UID"                property="uid"               /> <!-- 시점 -->
        <result column="ROAD_NO"            property="roadNo"            /> <!-- 노선번호 -->
        <result column="SECT"               property="sect"              /> <!-- 구간번호 -->
        <result column="DOCODE"             property="docode"            /> <!-- 구조물코드 -->
        <result column="DOSTYLE"            property="dostyle"           /> <!-- 지하도 구분 -->
        <result column="DONAME"             property="doname"            /> <!-- 지하도명 -->
        <result column="FA_TYPE"            property="faType"            /> <!-- 시설물종별 -->
        <result column="ST_DAY"             property="stDay"             /> <!-- 착공일자 -->
        <result column="END_DAY"            property="endDay"            /> <!-- 준공일자 -->
        <result column="DOSTA1"             property="dosta1"            /> <!-- 시점(측점) -->
        <result column="DOSTA2"             property="dosta2"            /> <!-- 종점(측점) -->
        <result column="DOAREA"             property="doarea"            /> <!-- 소재지 -->
        <result column="STR_LEVEL"          property="strLevel"          /> <!-- 상태등급 -->
        <result column="RE_DIA"             property="reDia"             /> <!-- 진단결과 -->
        <result column="DOSNAME"            property="dosname"           /> <!-- 조명시설 -->
        <result column="DOSLIGHT"           property="doslight"          /> <!-- 조명밝기 -->
        <result column="DOJONUM"            property="dojonum"           /> <!-- 조명등갯수 -->
        <result column="ET_TYPE"            property="etType"            /> <!-- 소화시설종류 -->
        <result column="ET_EA"              property="etEa"              /> <!-- 소화시설수량 -->
        <result column="DOOPNUM"            property="doopnum"           /> <!-- 펌프대수 -->
        <result column="DOGHEIGHT"          property="dogheight"         /> <!-- 구체높이 -->
        <result column="TYPE"               property="type"              /> <!-- 지하도 규격 -->
        <result column="LANE_U"             property="laneU"             /> <!-- 차로수 상행 -->
        <result column="LANE_D"             property="laneD"             /> <!-- 차로수 하행 -->
        <result column="VER_S"              property="verS"              /> <!-- 종단경사 -->
        <result column="CUR_R"              property="curR"              /> <!-- 곡선반경 -->
        <result column="HIT_MAX"            property="hitMax"            /> <!-- 옹벽_높이(최대) -->
        <result column="HIT_MIN"            property="hitMin"            /> <!-- 옹벽_높이(최소) -->
        <result column="WALL_LEN"           property="wallLen"           /> <!-- 옹벽연장 -->
        <result column="DOGWDT1"            property="dogwdt1"           /> <!-- 구체폭원(보도) -->
        <result column="DOGWDT2"            property="dogwdt2"           /> <!-- 구체폭원(차도) -->
        <result column="MA_CE"              property="maCe"              /> <!-- 마감재_천정 -->
        <result column="MA_BL"              property="maBl"              /> <!-- 마감재_벽체 -->
        <result column="PER_HIT"            property="perHit"            /> <!-- 통행제한높이 -->
        <result column="AW_FA"              property="awFa"              /> <!-- 환기방식 -->
        <result column="DRAINAGE"           property="drainage"          /> <!-- 배수시설 -->
        <result column="PERIOD"             property="period"            /> <!-- 공사기간 -->
        <result column="CONSTHALL"          property="consthall"         /> <!-- 시행청 -->
        <result column="CONST"              property="CONST"            /> <!-- 시공자 -->
        <result column="LEN"                property="len"               /> <!-- 연장 -->
        <result column="RI_CODE"            property="riCode"            /> <!-- 법정코드 -->
        <result column="REM"                property="rem"               /> <!-- 비고 -->
        <!--추가-->
        <result column="LOC_NAM"            property="locNam"            /> <!-- 로케이션 명 -->
    </resultMap>

    <resultMap id="Ae050GeoVoAddMap" type="Ae050GeoVo" extends="Ae050FeaVoMap">
        <result column="UID"                property="uid"               /> <!-- 시점 -->
        <result column="XMIN"               property="xmin"              /> <!-- X축 최소 -->
        <result column="XMAX"               property="xmax"              /> <!-- X축 최대 -->
        <result column="YMIN"               property="ymin"              /> <!-- Y축 최소 -->
        <result column="YMAX"               property="ymax"              /> <!-- Y축 최대 -->
        <result column="SHAPETYPE"          property="shapetype"         /> <!-- 도형타입 -->
        <result column="GEOMETRY"           property="geometry"          /> <!-- 기하학 -->
    </resultMap>

    <sql id="selectColumns">
        ${alias}UID
        , ${alias}ROAD_NO
        , ${alias}SECT
        , ${alias}DOCODE
        , ${alias}DOSTYLE
        , ${alias}DONAME
        , ${alias}FA_TYPE
        , ${alias}ST_DAY
        , ${alias}END_DAY
        , ${alias}DOSTA1
        , ${alias}DOSTA2
        , ${alias}DOAREA
        , ${alias}STR_LEVEL
        , ${alias}RE_DIA
        , ${alias}DOSNAME
        , ${alias}DOSLIGHT
        , ${alias}DOJONUM
        , ${alias}ET_TYPE
        , ${alias}ET_EA
        , ${alias}DOOPNUM
        , ${alias}DOGHEIGHT
        , ${alias}TYPE
        , ${alias}LANE_U
        , ${alias}LANE_D
        , ${alias}VER_S
        , ${alias}CUR_R
        , ${alias}HIT_MAX
        , ${alias}HIT_MIN
        , ${alias}WALL_LEN
        , ${alias}DOGWDT1
        , ${alias}DOGWDT2
        , ${alias}MA_CE
        , ${alias}MA_BL
        , ${alias}PER_HIT
        , ${alias}AW_FA
        , ${alias}DRAINAGE
        , ${alias}PERIOD
        , ${alias}CONSTHALL
        , ${alias}CONST
        , ${alias}LEN
        , ${alias}RI_CODE
        , ${alias}REM
    </sql>

    <!-- 컬럼 -->
    <sql id="columns">
        UID
        , ROAD_NO
        , SECT
        , DOCODE
        , DOSTYLE
        , DONAME
        , FA_TYPE
        , ST_DAY
        , END_DAY
        , DOSTA1
        , DOSTA2
        , DOAREA
        , STR_LEVEL
        , RE_DIA
        , DOSNAME
        , DOSLIGHT
        , DOJONUM
        , ET_TYPE
        , ET_EA
        , DOOPNUM
        , DOGHEIGHT
        , TYPE
        , LANE_U
        , LANE_D
        , VER_S
        , CUR_R
        , HIT_MAX
        , HIT_MIN
        , WALL_LEN
        , DOGWDT1
        , DOGWDT2
        , MA_CE
        , MA_BL
        , PER_HIT
        , AW_FA
        , DRAINAGE
        , PERIOD
        , CONSTHALL
        , CONST
        , LEN
        , RI_CODE
        , REM
    </sql>

    <!-- 값 -->
    <sql id="values">
        #{uid}
        , #{roadNo}
        , #{sect}
        , #{docode}
        , #{dostyle}
        , #{doname}
        , #{faType}
        , #{stDay}
        , #{endDay}
        , #{dosta1}
        , #{dosta2}
        , #{doarea}
        , #{strLevel}
        , #{reDia}
        , #{dosname}
        , #{doslight}
        , #{dojonum}
        , #{etType}
        , #{etEa}
        , #{doopnum}
        , #{dogheight}
        , #{type}
        , #{laneU}
        , #{laneD}
        , #{verS}
        , #{curR}
        , #{hitMax}
        , #{hitMin}
        , #{wallLen}
        , #{dogwdt1}
        , #{dogwdt2}
        , #{maCe}
        , #{maBl}
        , #{perHit}
        , #{awFa}
        , #{drainage}
        , #{period}
        , #{consthall}
        , #{CONST}
        , #{len}
        , #{riCode}
        , #{rem}
    </sql>

    <!-- 업데이트 값 -->
    <sql id="updateField">
        <trim prefixOverrides=",">
            <if test="uid != null">
                , UID            = #{uid}
            </if>
            <if test="roadNo != null">
                , ROAD_NO       = #{roadNo}
            </if>
            <if test="sect != null">
                , SECT          = #{sect}
            </if>
            <if test="docode != null">
                , DOCODE        = #{docode}
            </if>
            <if test="dostyle != null">
                , DOSTYLE       = #{dostyle}
            </if>
            <if test="doname != null">
                , DONAME        = #{doname}
            </if>
            <if test="faType != null">
                , FA_TYPE       = #{faType}
            </if>
            <if test="stDay != null">
                , ST_DAY        = #{stDay}
            </if>
            <if test="endDay != null">
                , END_DAY       = #{endDay}
            </if>
            <if test="dosta1 != null">
                , DOSTA1        = #{dosta1}
            </if>
            <if test="dosta2 != null">
                , DOSTA2        = #{dosta2}
            </if>
            <if test="doarea != null">
                , DOAREA        = #{doarea}
            </if>
            <if test="strLevel != null">
                , STR_LEVEL     = #{strLevel}
            </if>
            <if test="reDia != null">
                , RE_DIA        = #{reDia}
            </if>
            <if test="dosname != null">
                , DOSNAME       = #{dosname}
            </if>
            <if test="doslight != null">
                , DOSLIGHT      = #{doslight}
            </if>
            <if test="dojonum != null">
                , DOJONUM       = #{dojonum}
            </if>
            <if test="etType != null">
                , ET_TYPE       = #{etType}
            </if>
            <if test="etEa != null">
                , ET_EA         = #{etEa}
            </if>
            <if test="doopnum != null">
                , DOOPNUM       = #{doopnum}
            </if>
            <if test="dogheight != null">
                , DOGHEIGHT     = #{dogheight}
            </if>
            <if test="type != null">
                , TYPE          = #{type}
            </if>
            <if test="laneU != null">
                , LANE_U        = #{laneU}
            </if>
            <if test="laneD != null">
                , LANE_D        = #{laneD}
            </if>
            <if test="verS != null">
                , VER_S         = #{verS}
            </if>
            <if test="curR != null">
                , CUR_R         = #{curR}
            </if>
            <if test="hitMax != null">
                , HIT_MAX       = #{hitMax}
            </if>
            <if test="hitMin != null">
                , HIT_MIN       = #{hitMin}
            </if>
            <if test="wallLen != null">
                , WALL_LEN      = #{wallLen}
            </if>
            <if test="dogwdt1 != null">
                , DOGWDT1       = #{dogwdt1}
            </if>
            <if test="dogwdt2 != null">
                , DOGWDT2       = #{dogwdt2}
            </if>
            <if test="maCe != null">
                , MA_CE         = #{maCe}
            </if>
            <if test="maBl != null">
                , MA_BL         = #{maBl}
            </if>
            <if test="perHit != null">
                , PER_HIT       = #{perHit}
            </if>
            <if test="awFa != null">
                , AW_FA         = #{awFa}
            </if>
            <if test="drainage != null">
                , DRAINAGE      = #{drainage}
            </if>
            <if test="period != null">
                , PERIOD        = #{period}
            </if>
            <if test="consthall != null">
                , CONSTHALL     = #{consthall}
            </if>
            <if test="CONST != null">
                , CONST         = #{CONST}
            </if>
            <if test="len != null">
                , LEN           = #{len}
            </if>
            <if test="riCode != null">
                , RI_CODE       = #{riCode}
            </if>
            <if test="rem != null">
                , REM           = #{rem}
            </if>
        </trim>
    </sql>

    <sql id="defaultWhere">
        <trim prefix="AND" prefixOverrides="AND">
            <if  test="'' != roadNo and null != roadNo">
                AND AF.ROAD_NO  LIKE CONCAT('%', #{roadNo}, '%')
            </if>
            <if test="'' != sect and null != sect">
                AND AF.SECT     LIKE CONCAT('%', #{sect}, '%')
            </if>
        </trim>
    </sql>

    <!-- 시설 : 지하차도 정보 조회 -->
    <select id="selectGetList" resultMap="Ae050GeoVoAddMap">
        SELECT  <include refid="selectColumns">
        <property name="alias" value="AF." />
    </include>
        ,       (SELECT LOC_NAM FROM BML_DNRI_AS_FEA WHERE RI_CD = AF.RI_CODE) AS LOC_NAM
        ,       AG.XMIN
        ,       AG.XMAX
        ,       AG.YMIN
        ,       AG.YMAX
        ,       AG.SHAPETYPE
        FROM    AE050_FEA AS AF
        ,       AE050_GEO AS AG
        WHERE   AF.UID = AG.UID
        <include refid="defaultWhere" />
        ORDER BY AF.DOSTA1 ASC
    </select>

    <!-- 지하차도 정보 조회 -->
    <select id="selectGetInfo" parameterType="ae050FeaVO" resultType="ae050FeaVO">
        SELECT  <include refid="columns"/>
        FROM    AE050_FEA
         WHERE   DOCODE   = #{docode}
    </select>

    <!-- 지하차도 수정 -->
    <update id="updateFacilityInfo">
        UPDATE AE050_FEA
        SET    <include refid="updateField" />
        WHERE   UID   = #{uid}
    </update>
</mapper>