<?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.az080.mapper.Az080Mapper">

    <resultMap id="Az080FeaVoMap" type="Az080FeaVO">
        <result column="UID"                property="uid"                  />  <!-- 시점 -->
        <result column="ROAD_NO"            property="roadNo"               />  <!-- 노선번호 -->
        <result column="SECT"               property="sect"                 />  <!-- 구간번호 -->
        <result column="DOCODE"             property="docode"               />  <!-- 구조물코드 -->
        <result column="DOCHK"              property="dochk"                />  <!-- 옹벽/석축 구분 -->
        <result column="DOLENTH"            property="dolenth"              />  <!-- 연장 -->
        <result column="DOTYPE1"            property="dotype1"              />  <!-- 구조 -->
        <result column="DOTYPE2"            property="dotype2"              />  <!-- 재질 -->
        <result column="DOSTA1"             property="dosta1"               />  <!-- 시점(측점) -->
        <result column="DOSTA2"             property="dosta2"               />  <!-- 종점(측점) -->
        <result column="DOLR"               property="dolr"                 />  <!-- 상, 하행 구분 -->
        <result column="HIT_MAX"            property="hitMax"               />  <!-- 높이_최대 -->
        <result column="HIT_MIN"            property="hitMin"               />  <!-- 높이_최소 -->
        <result column="DOWIDTH"            property="dowidth"              />  <!-- 폭 -->
        <result column="RI_CODE"            property="riCode"               />  <!-- 법정코드 -->
        <result column="REM"                property="rem"                  />  <!-- 비고 -->
        <!--추가-->
        <result column="LOC_NAM"            property="locNam"               />  <!-- 로케이션 명 -->
    </resultMap>

    <resultMap id="Az080GeoVoAddMap" type="Az080GeoVo" extends="Az080FeaVoMap">
        <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}DOCHK
        , ${alias}DOLENTH
        , ${alias}DOTYPE1
        , ${alias}DOTYPE2
        , ${alias}DOSTA1
        , ${alias}DOSTA2
        , ${alias}DOLR
        , ${alias}HIT_MAX
        , ${alias}HIT_MIN
        , ${alias}DOWIDTH
        , ${alias}RI_CODE
        , ${alias}REM
    </sql>

    <!-- 컬럼 -->
    <sql id="columns">
        UID
        , ROAD_NO
        , SECT
        , DOCODE
        , DOCHK
        , DOLENTH
        , DOTYPE1
        , DOTYPE2
        , DOSTA1
        , DOSTA2
        , DOLR
        , HIT_MAX
        , HIT_MIN
        , DOWIDTH
        , RI_CODE
        , REM
    </sql>

    <!-- 값 -->
    <sql id="values">
        #{uid}
        , #{roadNo}
        , #{sect}
        , #{docode}
        , #{dochk}
        , #{dolenth}
        , #{dotype1}
        , #{dotype2}
        , #{dosta1}
        , #{dosta2}
        , #{dolr}
        , #{hitMax}
        , #{hitMin}
        , #{dowidth}
        , #{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="dochk != null">
                , DOCHK         = #{dochk}
            </if>
            <if test="dolenth != null">
                , DOLENTH       = #{dolenth}
            </if>
            <if test="dotype1 != null">
                , DOTYPE1       = #{dotype1}
            </if>
            <if test="dotype2 != null">
                , DOTYPE2       = #{dotype2}
            </if>
            <if test="dosta1 != null">
                , DOSTA1        = #{dosta1}
            </if>
            <if test="dosta2 != null">
                , DOSTA2        = #{dosta2}
            </if>
            <if test="dolr != null">
                , DOLR          = #{dolr}
            </if>
            <if test="hitMax != null">
                , HIT_MAX       = #{hitMax}
            </if>
            <if test="hitMin != null">
                , HIT_MIN       = #{hitMin}
            </if>
            <if test="dowidth != null">
                , DOWIDTH       = #{dowidth}
            </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="Az080GeoVoAddMap">
        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    AZ080_FEA AS AF
        ,       AZ080_GEO AS AG
        WHERE   AF.UID = AG.UID
        <include refid="defaultWhere" />
        ORDER BY AF.DOSTA1 ASC
    </select>

    <!-- 옹벽/석축 정보 조회 -->
    <select id="selectGetInfo" parameterType="az080FeaVO" resultType="az080FeaVO">
        SELECT  <include refid="columns"/>
        FROM    AZ080_FEA
         WHERE   DOCODE   = #{docode}
    </select>

    <!-- 옹벽/석축 수정 -->
    <update id="updateFacilityInfo">
        UPDATE AZ080_FEA
        SET    <include refid="updateField" />
        WHERE   UID   = #{uid}
    </update>
</mapper>