<?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.ae100.mapper.Ae100Mapper">

    <resultMap id="Ae100FeaVoMap" type="Ae100FeaVO">
        <result column="UID"                property="uid"              />  <!-- 시점 -->
        <result column="ROAD_NO"            property="roadNo"           />  <!-- 노선번호 -->
        <result column="SECT"               property="sect"             />  <!-- 구간번호 -->
        <result column="DOCODE"             property="docode"           />  <!-- 구조물코드 -->
        <result column="DONAME"             property="doname"           />  <!-- 육교명 -->
        <result column="DOSTA1"             property="dosta1"           />  <!-- 시점_측점 -->
        <result column="DOSTA2"             property="dosta2"           />  <!-- 종점_측점 -->
        <result column="CONSTHALL"          property="consthall"        />  <!-- 시행청 -->
        <result column="DOMANAGER"          property="domanager"        />  <!-- 시공자 -->
        <result column="DESIGNER"           property="designer"         />  <!-- 설계자 -->
        <result column="ST_DAY"             property="stDay"            />  <!-- 착공년월일 -->
        <result column="ED_DAY"             property="edDay"            />  <!-- 준공년월일 -->
        <result column="DOHEIGHT"           property="doheight"         />  <!-- 통행제한높이 -->
        <result column="DE_WET"             property="deWet"            />  <!-- 설계활하중 -->
        <result column="PER_WET"            property="perWet"           />  <!-- 허용통행하중 -->
        <result column="DOAREA"             property="doarea"           />  <!-- 소재지 -->
        <result column="DOWDT"              property="dowdt"            />  <!-- 구체_폭원 -->
        <result column="DOLEN"              property="dolen"            />  <!-- 연장 -->
        <result column="DOTYPE"             property="dotype"           />  <!-- 육교형식 -->
        <result column="DOGNUM"             property="dognum"           />  <!-- 계단_개소 -->
        <result column="DOGWDT"             property="dogwdt"           />  <!-- 계단_폭원 -->
        <result column="DOGLEN"             property="doglen"           />  <!-- 계단_연장 -->
        <result column="SR_TYPE"            property="srType"           />  <!-- 계단_재질 -->
        <result column="DONLEN"             property="donlen"           />  <!-- 난간_길이 -->
        <result column="DONHEIGHT"          property="donheight"        />  <!-- 난간_높이 -->
        <result column="RA_TYPE"            property="raType"           />  <!-- 난간_재질 -->
        <result column="LGT_TYPE"           property="lgtType"          />  <!-- 조명시설_종류 -->
        <result column="LGT_EA"             property="lgtEa"            />  <!-- 조명시설_수량 -->
        <result column="DIS_TYPE"           property="disType"          />  <!-- 장애인편익시설_종류 -->
        <result column="DIS_EA"             property="disEa"            />  <!-- 장애인편익시설_수량 -->
        <result column="FA_TYPE"            property="faType"           />  <!-- 부대시설_종류 -->
        <result column="FA_EA"              property="faEa"             />  <!-- 부대시설_수량 -->
        <result column="DOSSTYLE"           property="dosstyle"         />  <!-- 상부형식 -->
        <result column="DOHSTYLE"           property="dohstyle"         />  <!-- 하부형식 -->
        <result column="RI_CODE"            property="riCode"           />  <!-- 법정코드 -->
        <result column="REM"                property="rem"              />  <!-- 비고 -->
        <!--추가-->
        <result column="LOC_NAM"            property="locNam"           />  <!-- 로케이션 명 -->
    </resultMap>

    <resultMap id="Ae100GeoVoAddMap" type="Ae100GeoVo" extends="Ae100FeaVoMap">
        <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}DONAME
        , ${alias}DOSTA1
        , ${alias}DOSTA2
        , ${alias}CONSTHALL
        , ${alias}DOMANAGER
        , ${alias}DESIGNER
        , ${alias}ST_DAY
        , ${alias}ED_DAY
        , ${alias}DOHEIGHT
        , ${alias}DE_WET
        , ${alias}PER_WET
        , ${alias}DOAREA
        , ${alias}DOWDT
        , ${alias}DOLEN
        , ${alias}DOTYPE
        , ${alias}DOGNUM
        , ${alias}DOGWDT
        , ${alias}DOGLEN
        , ${alias}SR_TYPE
        , ${alias}DONLEN
        , ${alias}DONHEIGHT
        , ${alias}RA_TYPE
        , ${alias}LGT_TYPE
        , ${alias}LGT_EA
        , ${alias}DIS_TYPE
        , ${alias}DIS_EA
        , ${alias}FA_TYPE
        , ${alias}FA_EA
        , ${alias}DOSSTYLE
        , ${alias}DOHSTYLE
        , ${alias}RI_CODE
        , ${alias}REM
    </sql>

    <!-- 컬럼 -->
    <sql id="columns">
          UID
        , ROAD_NO
        , SECT
        , DOCODE
        , DONAME
        , DOSTA1
        , DOSTA2
        , CONSTHALL
        , DOMANAGER
        , DESIGNER
        , ST_DAY
        , ED_DAY
        , DOHEIGHT
        , DE_WET
        , PER_WET
        , DOAREA
        , DOWDT
        , DOLEN
        , DOTYPE
        , DOGNUM
        , DOGWDT
        , DOGLEN
        , SR_TYPE
        , DONLEN
        , DONHEIGHT
        , RA_TYPE
        , LGT_TYPE
        , LGT_EA
        , DIS_TYPE
        , DIS_EA
        , FA_TYPE
        , FA_EA
        , DOSSTYLE
        , DOHSTYLE
        , RI_CODE
        , REM
    </sql>

    <!-- 값 -->
    <sql id="values">
          #{uid}
        , #{roadNo}
        , #{sect}
        , #{docode}
        , #{doname}
        , #{dosta1}
        , #{dosta2}
        , #{consthall}
        , #{domanager}
        , #{designer}
        , #{stDay}
        , #{edDay}
        , #{doheight}
        , #{deWet}
        , #{perWet}
        , #{doarea}
        , #{dowdt}
        , #{dolen}
        , #{dotype}
        , #{dognum}
        , #{dogwdt}
        , #{doglen}
        , #{srType}
        , #{donlen}
        , #{donheight}
        , #{raType}
        , #{lgtType}
        , #{lgtEa}
        , #{disType}
        , #{disEa}
        , #{faType}
        , #{faEa}
        , #{dosstyle}
        , #{dohstyle}
        , #{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="doname != null">
                , DONAME        = #{doname}
            </if>
            <if test="dosta1 != null">
                , DOSTA1        = #{dosta1}
            </if>
            <if test="dosta2 != null">
                , DOSTA2        = #{dosta2}
            </if>
            <if test="consthall != null">
                , CONSTHALL     = #{consthall}
            </if>
            <if test="domanager != null">
                , DOMANAGER     = #{domanager}
            </if>
            <if test="designer != null">
                , DESIGNER      = #{designer}
            </if>
            <if test="stDay != null">
                , ST_DAY        = #{stDay}
            </if>
            <if test="edDay != null">
                , ED_DAY        = #{edDay}
            </if>
            <if test="doheight != null">
                , DOHEIGHT      = #{doheight}
            </if>
            <if test="deWet != null">
                , DE_WET        = #{deWet}
            </if>
            <if test="perWet != null">
                , PER_WET       = #{perWet}
            </if>
            <if test="doarea != null">
                , DOAREA        = #{doarea}
            </if>
            <if test="dowdt != null">
                , DOWDT         = #{dowdt}
            </if>
            <if test="dolen != null">
                , DOLEN         = #{dolen}
            </if>
            <if test="dotype != null">
                , DOTYPE        = #{dotype}
            </if>
            <if test="dognum != null">
                , DOGNUM        = #{dognum}
            </if>
            <if test="dogwdt != null">
                , DOGWDT        = #{dogwdt}
            </if>
            <if test="doglen != null">
                , DOGLEN        = #{doglen}
            </if>
            <if test="srType != null">
                , SR_TYPE       = #{srType}
            </if>
            <if test="donlen != null">
                , DONLEN        = #{donlen}
            </if>
            <if test="donheight != null">
                , DONHEIGHT     = #{donheight}
            </if>
            <if test="raType != null">
                , RA_TYPE       = #{raType}
            </if>
            <if test="lgtType != null">
                , LGT_TYPE      = #{lgtType}
            </if>
            <if test="lgtEa != null">
                , LGT_EA        = #{lgtEa}
            </if>
            <if test="disType != null">
                , DIS_TYPE      = #{disType}
            </if>
            <if test="disEa != null">
                , DIS_EA        = #{disEa}
            </if>
            <if test="faType != null">
                , FA_TYPE       = #{faType}
            </if>
            <if test="faEa != null">
                , FA_EA         = #{faEa}
            </if>
            <if test="dosstyle != null">
                , DOSSTYLE      = #{dosstyle}
            </if>
            <if test="dohstyle != null">
                , DOHSTYLE      = #{dohstyle}
            </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="Ae100GeoVoAddMap">
        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    AE100_FEA AS AF
        ,       AE100_GEO AS AG
        WHERE   AF.UID = AG.UID
        <include refid="defaultWhere" />
        ORDER BY AF.DOSTA1 ASC
    </select>

    <!-- 보도육교 정보 조회 -->
    <select id="selectGetInfo" parameterType="ae100FeaVO" resultType="ae100FeaVO">
        SELECT  <include refid="columns"/>
        FROM    AE100_FEA
         WHERE   DOCODE   = #{docode}
    </select>

    <!-- 보도육교 수정 -->
    <update id="updateFacilityInfo">
        UPDATE AE100_FEA
        SET    <include refid="updateField" />
        WHERE   UID   = #{uid}
    </update>
</mapper>