<?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.overCheckpoint.mapper.OverCheckpointMapper">

    <resultMap id="OverCheckpointFeaVoMap" type="OverCheckpointFeaVO">
        <result column="UID"                property="uid"              />  <!-- 시점 -->
        <result column="ROAD_NO"            property="roadNo"           />  <!-- 노선번호 -->
        <result column="SECT"               property="sect"             />  <!-- 구간번호 -->
        <result column="DOCODE"             property="docode"           />  <!-- 구조물코드 -->
        <result column="DOSTA1"             property="dosta1"           />  <!-- 시점(측점) -->
        <result column="DOLR"               property="dolr"             />  <!-- 상, 하행 구분 -->
        <result column="TYPE"               property="type"             />  <!-- 종류 -->
        <result column="DODATE"             property="dodate"           />  <!-- 설치일자 -->
        <result column="RI_CODE"            property="riCode"           />  <!-- 법정코드 -->
        <result column="REM"                property="rem"              />  <!-- 비고 -->
        <!--추가-->
        <result column="LOC_NAM"            property="locNam"           />  <!-- 로케이션 명 -->
    </resultMap>

    <resultMap id="OverCheckpointGeoVoAddMap" type="OverCheckpointGeoVo" extends="OverCheckpointFeaVoMap">
        <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}DOSTA1
        , ${alias}DOLR
        , ${alias}TYPE
        , ${alias}DODATE
        , ${alias}RI_CODE
        , ${alias}REM
    </sql>

    <!-- 컬럼 -->
    <sql id="columns">
        UID
        , ROAD_NO
        , SECT
        , DOCODE
        , DOSTA1
        , DOLR
        , TYPE
        , DODATE
        , RI_CODE
        , REM
    </sql>

    <!-- 값 -->
    <sql id="values">
        #{uid}
        , #{roadNo}
        , #{sect}
        , #{docode}
        , #{dosta1}
        , #{dolr}
        , #{type}
        , #{dodate}
        , #{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="dosta1 != null">
                , DOSTA1        = #{dosta1}
            </if>
            <if test="dolr != null">
                , DOLR          = #{dolr}
            </if>
            <if test="type != null">
                , TYPE          = #{type}
            </if>
            <if test="dodate != null">
                , DODATE        = #{dodate}
            </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="OverCheckpointGeoVoAddMap">
        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    OVER_CHECKPOINT_FEA AS AF
        ,       OVER_CHECKPOINT_GEO AS AG
        WHERE   AF.UID = AG.UID
        <include refid="defaultWhere" />
        ORDER BY AF.DOSTA1 ASC
    </select>

    <!-- 도로교차로 정보 조회 -->
    <select id="selectGetInfo" parameterType="overCheckpointFeaVO" resultType="overCheckpointFeaVO">
        SELECT  <include refid="columns"/>
        FROM    OVER_CHECKPOINT_FEA
         WHERE   DOCODE   = #{docode}
    </select>

    <!-- 도로교차로 수정 -->
    <update id="updateFacilityInfo">
        UPDATE OVER_CHECKPOINT_FEA
        SET    <include refid="updateField" />
        WHERE   UID   = #{uid}
    </update>
</mapper>
