<?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.cutfillSlope.mapper.CutfillSlopeMapper">

    <resultMap id="CutfillSlopeFeaVoMap" type="CutfillSlopeFeaVO">
        <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="DOSTA2"             property="dosta2"           />  <!-- 종점(측점) -->
        <result column="DOLR"               property="dolr"             />  <!-- 상, 하행 구분 -->
        <result column="EQP_LEN"            property="eqpLen"           />  <!-- 연장 -->
        <result column="CUT_TYPE"           property="cutType"          />  <!-- 종류 -->
        <result column="HIT_MAX"            property="hitMax"           />  <!-- 높이_최대 -->
        <result column="HIT_MIN"            property="hitMin"           />  <!-- 높이_최소 -->
        <result column="SLOPE"              property="slope"            />  <!-- 경사 -->
        <result column="SLOPE_TYPE"         property="slopeType"        />  <!-- 사면유형 -->
        <result column="SLOPE_OUTS"         property="slopeOuts"        />  <!-- 사면주변지형 -->
        <result column="SB_YN"              property="sbYn"             />  <!-- 사면보호시설 여부 -->
        <result column="SB_TYPE"            property="sbType"           />  <!-- 사면보호시설 유형 -->
        <result column="RI_CODE"            property="riCode"           />  <!-- 법정코드 -->
        <result column="REM"                property="rem"              />  <!-- 비고 -->
        <!--추가-->
        <result column="LOC_NAM"            property="locNam"           />  <!-- 로케이션 명 -->
    </resultMap>

    <resultMap id="CutfillSlopeGeoVoAddMap" type="CutfillSlopeGeoVo" extends="CutfillSlopeFeaVoMap">
        <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}DOSTA2
        , ${alias}DOLR
        , ${alias}EQP_LEN
        , ${alias}CUT_TYPE
        , ${alias}HIT_MAX
        , ${alias}HIT_MIN
        , ${alias}SLOPE
        , ${alias}SLOPE_TYPE
        , ${alias}SLOPE_OUTS
        , ${alias}SB_YN
        , ${alias}SB_TYPE
        , ${alias}RI_CODE
        , ${alias}REM
    </sql>

    <!-- 컬럼 -->
    <sql id="columns">
        UID
        , ROAD_NO
        , SECT
        , DOCODE
        , DOSTA1
        , DOSTA2
        , DOLR
        , EQP_LEN
        , CUT_TYPE
        , HIT_MAX
        , HIT_MIN
        , SLOPE
        , SLOPE_TYPE
        , SLOPE_OUTS
        , SB_YN
        , SB_TYPE
        , RI_CODE
        , REM
    </sql>

    <!-- 값 -->
    <sql id="values">
        #{uid}
        , #{roadNo}
        , #{sect}
        , #{docode}
        , #{dosta1}
        , #{dosta2}
        , #{dolr}
        , #{eqpLen}
        , #{cutType}
        , #{hitMax}
        , #{hitMin}
        , #{slope}
        , #{slopeType}
        , #{slopeOuts}
        , #{sbYn}
        , #{sbType}
        , #{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="dosta2 != null">
                , DOSTA2        = #{dosta2}
            </if>
            <if test="dolr != null">
                , DOLR          = #{dolr}
            </if>
            <if test="eqpLen != null">
                , EQP_LEN       = #{eqpLen}
            </if>
            <if test="cutType != null">
                , CUT_TYPE      = #{cutType}
            </if>
            <if test="hitMax != null">
                , HIT_MAX       = #{hitMax}
            </if>
            <if test="hitMin != null">
                , HIT_MIN       = #{hitMin}
            </if>
            <if test="slope != null">
                , SLOPE         = #{slope}
            </if>
            <if test="slopeType != null">
                , SLOPE_TYPE    = #{slopeType}
            </if>
            <if test="slopeOuts != null">
                , SLOPE_OUTS    = #{slopeOuts}
            </if>
            <if test="sbYn != null">
                , SB_YN         = #{sbYn}
            </if>
            <if test="sbType != null">
                , SB_TYPE       = #{sbType}
            </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="CutfillSlopeGeoVoAddMap">
        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    CUTFILL_SLOPE_FEA AS AF
        ,       CUTFILL_SLOPE_GEO AS AG
        WHERE   AF.UID = AG.UID
        <include refid="defaultWhere" />
        ORDER BY AF.DOSTA1 ASC
    </select>

    <!-- 도로법면 정보 조회 -->
    <select id="selectGetInfo" parameterType="cutfillSlopeFeaVO" resultType="cutfillSlopeFeaVO">
        SELECT  <include refid="columns"/>
        FROM    CUTFILL_SLOPE_FEA
         WHERE   DOCODE   = #{docode}
    </select>

    <!-- 도로법면 수정 -->
    <update id="updateFacilityInfo">
        UPDATE CUTFILL_SLOPE_FEA
        SET    <include refid="updateField" />
        WHERE   UID   = #{uid}
    </update>
</mapper>
