<?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.ae340.mapper.Ae340Mapper">

    <resultMap id="Ae340FeaVoMap" type="Ae340FeaVO">
        <result column="UID"                property="uid"              />  <!-- 시점 -->
        <result column="ROAD_NO"            property="roadNo"           />  <!-- 노선번호 -->
        <result column="SECT"               property="sect"             />  <!-- 구간번호 -->
        <result column="DOCODE"             property="docode"           />  <!-- 구조물코드 -->
        <result column="STANDARD"           property="standard"         />  <!-- 규격 -->
        <result column="LEN"                property="len"              />  <!-- 연장 -->
        <result column="EQP_MET"            property="eqpMet"           />  <!-- 재질_관 -->
        <result column="EQP_MET1"           property="eqpMet1"          />  <!-- 재질_면벽 -->
        <result column="ANGLE"              property="angle"            />  <!-- 각도 -->
        <result column="JIP_R"              property="jipR"             />  <!-- 집수정_유무_상행 -->
        <result column="JIP_L"              property="jipL"             />  <!-- 집수정_유무_하행 -->
        <result column="WING_R"             property="wingR"            />  <!-- 날개벽_유무_상행 -->
        <result column="WING_L"             property="wingL"            />  <!-- 날개벽_유무_하행 -->
        <result column="DOSTA1"             property="dosta1"           />  <!-- 시점_측점 -->
        <result column="HPTYPE"             property="hptype"           />  <!-- 흄관_박스_구분 -->
        <result column="RI_CODE"            property="riCode"           />  <!-- 법정코드 -->
        <result column="REM"                property="rem"              />  <!-- 비고 -->
        <!--추가-->
        <result column="LOC_NAM"            property="locNam"           />  <!-- 로케이션 명 -->
    </resultMap>

    <resultMap id="Ae340GeoVoAddMap" type="Ae340GeoVo" extends="Ae340FeaVoMap">
        <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}STANDARD
        , ${alias}LEN
        , ${alias}EQP_MET
        , ${alias}EQP_MET1
        , ${alias}ANGLE
        , ${alias}JIP_R
        , ${alias}JIP_L
        , ${alias}WING_R
        , ${alias}WING_L
        , ${alias}DOSTA1
        , ${alias}HPTYPE
        , ${alias}RI_CODE
        , ${alias}REM
    </sql>

    <!-- 컬럼 -->
    <sql id="columns">
          UID
        , ROAD_NO
        , SECT
        , DOCODE
        , STANDARD
        , LEN
        , EQP_MET
        , EQP_MET1
        , ANGLE
        , JIP_R
        , JIP_L
        , WING_R
        , WING_L
        , DOSTA1
        , HPTYPE
        , RI_CODE
        , REM
    </sql>

    <!-- 값 -->
    <sql id="values">
          #{uid}
        , #{roadNo}
        , #{sect}
        , #{docode}
        , #{standard}
        , #{len}
        , #{eqpMet}
        , #{eqpMet1}
        , #{angle}
        , #{jipR}
        , #{jipL}
        , #{wingR}
        , #{wingL}
        , #{dosta1}
        , #{hptype}
        , #{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="standard != null">
                , STANDARD      = #{standard}
            </if>
            <if test="len != null">
                , LEN           = #{len}
            </if>
            <if test="eqpMet != null">
                , EQP_MET       = #{eqpMet}
            </if>
            <if test="eqpMet1 != null">
                , EQP_MET1      = #{eqpMet1}
            </if>
            <if test="angle != null">
                , ANGLE         = #{angle}
            </if>
            <if test="jipR != null">
                , JIP_R         = #{jipR}
            </if>
            <if test="jipL != null">
                , JIP_L         = #{jipL}
            </if>
            <if test="wingR != null">
                , WING_R        = #{wingR}
            </if>
            <if test="wingL != null">
                , WING_L        = #{wingL}
            </if>
            <if test="dosta1 != null">
                , DOSTA1        = #{dosta1}
            </if>
            <if test="hptype != null">
                , HPTYPE        = #{hptype}
            </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="Ae340GeoVoAddMap">
        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    AE340_FEA AS AF
        ,       AE340_GEO AS AG
        WHERE   AF.UID = AG.UID
        <include refid="defaultWhere" />
        ORDER BY AF.DOSTA1 ASC
    </select>

    <!-- 암거배수관 정보 조회 -->
    <select id="selectGetInfo" parameterType="ae340FeaVO" resultType="ae340FeaVO">
        SELECT  <include refid="columns"/>
        FROM    AE340_FEA
         WHERE   DOCODE   = #{docode}
    </select>

    <!-- 암거배수관 수정 -->
    <update id="updateFacilityInfo">
        UPDATE AE340_FEA
        SET    <include refid="updateField" />
        WHERE   UID   = #{uid}
    </update>
</mapper>