<?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.pathWay.mapper.PathwayMapper">

    <resultMap id="PathwayFeaVoMap" type="PathwayFeaVO">
        <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="WID"                property="wid"              /> <!-- 규격_가로 -->
        <result column="HIT"                property="hit"              /> <!-- 규격_세로 -->
        <result column="MET"                property="met"              /> <!-- 재질 -->
        <result column="PURPOSE"            property="purpose"          /> <!-- 설치목적 -->
        <result column="PUMP"               property="pump"             /> <!-- 배수시설 -->
        <result column="LEN"                property="len"              /> <!-- 연장 -->
        <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="PathwayGeoVoAddMap" type="PathwayGeoVo" extends="PathwayFeaVoMap">
        <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}WID
        , ${alias}HIT
        , ${alias}MET
        , ${alias}PURPOSE
        , ${alias}PUMP
        , ${alias}LEN
        , ${alias}DODATE
        , ${alias}RI_CODE
        , ${alias}REM
    </sql>

    <!-- 컬럼 -->
    <sql id="columns">
        UID
        , ROAD_NO
        , SECT
        , DOCODE
        , DOSTA1
        , WID
        , HIT
        , MET
        , PURPOSE
        , PUMP
        , LEN
        , DODATE
        , RI_CODE
        , REM
    </sql>

    <!-- 값 -->
    <sql id="values">
        #{uid}
        , #{roadNo}
        , #{sect}
        , #{docode}
        , #{dosta1}
        , #{wid}
        , #{hit}
        , #{met}
        , #{purpose}
        , #{pump}
        , #{len}
        , #{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="wid != null">
                , WID               = #{wid}
            </if>
            <if test="hit != null">
                , HIT               = #{hit}
            </if>
            <if test="met != null">
                , MET               = #{met}
            </if>
            <if test="purpose != null">
                , PURPOSE           = #{purpose}
            </if>
            <if test="pump != null">
                
		        , PUMP              = #{pump}
            </if>
            <if test="len != null">
		        , LEN               = #{len}
            </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 PF.ROAD_NO  LIKE CONCAT('%', #{roadNo}, '%')
            </if>
            <if test="'' != sect and null != sect">
                AND PF.SECT     LIKE CONCAT('%', #{sect}, '%')
            </if>
        </trim>
    </sql>

    <!-- 시설 : 통로박스 정보 조회 -->
    <select id="selectGetList" resultMap="PathwayGeoVoAddMap">
        SELECT  <include refid="selectColumns">
        <property name="alias" value="PF." />
    </include>
        ,       (SELECT LOC_NAM FROM BML_DNRI_AS_FEA WHERE RI_CD = PF.RI_CODE) AS LOC_NAM
        ,       PG.XMIN
        ,       PG.XMAX
        ,       PG.YMIN
        ,       PG.YMAX
        ,       PG.SHAPETYPE
        FROM    PATHWAY_FEA AS PF
        ,       PATHWAY_GEO AS PG
        WHERE   PF.UID = PG.UID
        <include refid="defaultWhere" />
        ORDER BY PF.DOSTA1 ASC
    </select>

    <!-- 통로박스 정보 조회 -->
    <select id="selectGetInfo" parameterType="pathwayFeaVO" resultType="pathwayFeaVO">
        SELECT  <include refid="columns"/>
        FROM    PATHWAY_FEA
         WHERE   DOCODE   = #{docode}
    </select>
     <update id="updateFacilityInfo">
        UPDATE PATHWAY_FEA
        SET    <include refid="updateField" />
        WHERE   UID   = #{uid}
    </update>
</mapper>
