<?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.ak004.mapper.Ak004Mapper">

    <resultMap id="Ak004FeaVoMap" type="Ak004FeaVO">
        <result column="UID"                property="uid"              />  <!-- 시점 -->
        <result column="ROAD_NO"            property="roadNo"           />  <!-- 노선번호 -->
        <result column="SECT"               property="sect"             />  <!-- 구간번호 -->
        <result column="DOCODE"             property="docode"           />  <!-- 구조물코드 -->
        <result column="DOIP"               property="doip"             />  <!-- IP번호 -->
        <result column="DOIA1"              property="doia1"            />  <!-- 교각_도분초 -->
        <result column="DOIA2"              property="doia2"            />  <!-- 교각_분 -->
        <result column="DOIA3"              property="doia3"            />  <!-- 교각_초 -->
        <result column="DOR"                property="dor"              />  <!-- 곡선반경_R -->
        <result column="DOTL"               property="dotl"             />  <!-- 접선장TL -->
        <result column="DOCL"               property="docl"             />  <!-- 곡선장CL -->
        <result column="DOSL"               property="dosl"             />  <!-- 중앙종거SL -->
        <result column="DOS"                property="dos"              />  <!-- 구_배S -->
        <result column="DOW"                property="dow"              />  <!-- 확_폭W -->
        <result column="DOBC"               property="dobc"             />  <!-- 곡선시점BC -->
        <result column="DOEC"               property="doec"             />  <!-- 곡선종점EC -->
        <result column="DOSDST1"            property="dosdst1"          />  <!-- 인입시거 -->
        <result column="DOSDST2"            property="dosdst2"          />  <!-- 아웃시거 -->
        <result column="DOSTA1"             property="dosta1"           />  <!-- 시점_측점 -->
        <result column="LINE"               property="line"             />  <!-- 법정코드 -->
        <result column="RI_CODE"            property="riCode"           />  <!-- 직선장 -->
        <result column="IP_LBL"             property="ipLbl"            />  <!-- 라벨 -->
        <result column="REM"                property="rem"              />  <!-- 비고 -->
        <!--추가-->
        <result column="LOC_NAM"            property="locNam"           />  <!-- 로케이션 명 -->
    </resultMap>

    <resultMap id="Ak004GeoVoAddMap" type="Ak004GeoVo" extends="Ak004FeaVoMap">
        <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}DOIP
        , ${alias}DOIA1
        , ${alias}DOIA2
        , ${alias}DOIA3
        , ${alias}DOR
        , ${alias}DOTL
        , ${alias}DOCL
        , ${alias}DOSL
        , ${alias}DOS
        , ${alias}DOW
        , ${alias}DOBC
        , ${alias}DOEC
        , ${alias}DOSDST1
        , ${alias}DOSDST2
        , ${alias}DOSTA1
        , ${alias}LINE
        , ${alias}RI_CODE
        , ${alias}IP_LBL
        , ${alias}REM
    </sql>

    <!-- 컬럼 -->
    <sql id="columns">
          UID
        , ROAD_NO
        , SECT
        , DOCODE
        , DOIP
        , DOIA1
        , DOIA2
        , DOIA3
        , DOR
        , DOTL
        , DOCL
        , DOSL
        , DOS
        , DOW
        , DOBC
        , DOEC
        , DOSDST1
        , DOSDST2
        , DOSTA1
        , LINE
        , RI_CODE
        , IP_LBL
        , REM
    </sql>

    <!-- 값 -->
    <sql id="values">
          #{uid}
        , #{roadNo}
        , #{sect}
        , #{docode}
        , #{doip}
        , #{doia1}
        , #{doia2}
        , #{doia3}
        , #{dor}
        , #{dotl}
        , #{docl}
        , #{dosl}
        , #{dos}
        , #{dow}
        , #{dobc}
        , #{doec}
        , #{dosdst1}
        , #{dosdst2}
        , #{dosta1}
        , #{line}
        , #{riCode}
        , #{ipLbl}
        , #{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="doip != null">
                , DOIP          = #{doip}
            </if>
            <if test="doia1 != null">
                , DOIA1         = #{doia1}
            </if>
            <if test="doia2 != null">
                , DOIA2         = #{doia2}
            </if>
            <if test="doia3 != null">
                , DOIA3         = #{doia3}
            </if>
            <if test="dor != null">
                , DOR           = #{dor}
            </if>
            <if test="dotl != null">
                , DOTL          = #{dotl}
            </if>
            <if test="docl != null">
                , DOCL          = #{docl}
            </if>
            <if test="dosl != null">
                , DOSL          = #{dosl}
            </if>
            <if test="dos != null">
                , DOS           = #{dos}
            </if>
            <if test="dow != null">
                , DOW           = #{dow}
            </if>
            <if test="dobc != null">
                , DOBC          = #{dobc}
            </if>
            <if test="doec != null">
                , DOEC          = #{doec}
            </if>
            <if test="dosdst1 != null">
                , DOSDST1       = #{dosdst1}
            </if>
            <if test="dosdst2 != null">
                , DOSDST2       = #{dosdst2}
            </if>
            <if test="dosta1 != null">
                , DOSTA1        = #{dosta1}
            </if>
            <if test="line != null">
                , LINE          = #{line}
            </if>
            <if test="riCode != null">
                , RI_CODE       = #{riCode}
            </if>
            <if test="ipLbl != null">
                , IP_LBL        = #{ipLbl}
            </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>

    <!-- 시설 : IP교점 정보 조회 -->
    <select id="selectGetList" resultMap="Ak004GeoVoAddMap">
        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    AK004_FEA AS AF
        ,       AK004_GEO AS AG
        WHERE   AF.UID = AG.UID
        <include refid="defaultWhere" />
        ORDER BY AF.DOSTA1 ASC
    </select>

    <!-- IP교점 정보 조회 -->
    <select id="selectGetInfo" parameterType="ak004FeaVO" resultType="ak004FeaVO">
        SELECT  <include refid="columns"/>
        FROM    AK004_FEA
         WHERE   DOCODE   = #{docode}
    </select>

    <!-- IP교점 수정 -->
    <update id="updateFacilityInfo">
        UPDATE AK004_FEA
        SET    <include refid="updateField" />
        WHERE   UID   = #{uid}
    </update>
</mapper>