<?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="com.tofly.xrtygis.mapper.DmaregionMapper">

    <resultMap id="dmaregionMap" type="com.tofly.xrtygis.entity.Dmaregion">
        <id property="id" column="ID"/>
        <result property="dmaCode" column="DMA_CODE"/>
        <result property="geometry" column="GEOMETRY"/>
        <result property="dmaName" column="DMA_NAME"/>
        <result property="areas" column="AREAS"/>
        <result property="pipeLen" column="PIPE_LEN"/>
        <result property="refStandard" column="REF_STANDARD"/>
        <result property="minDiff" column="MIN_DIFF"/>
        <result property="maxDiff" column="MAX_DIFF"/>
        <result property="pid" column="PID"/>
        <result property="isyc" column="ISYC"/>
        <result property="notes" column="NOTES"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="partitionLevel" column="PARTITION_LEVEL"/>
        <result property="pointNumber" column="POINT_NUMBER"/>
        <result property="userPipeLen" column="USER_PIPE_LEN"/>
        <result property="avgPressure" column="AVG_PRESSURE"/>
        <result property="otherWater" column="OTHER_WATER"/>
        <association property="pName" column="PID" select="getPName"/>
        <association property="isYcName" column="ISYC" select="getIsycName"/>
        <association property="dmaGid" column="DMA_GID"/>
        <association property="createUserName" column="CREATE_USER"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
    </resultMap>
    <update id="updateMinFlow">
        update TF_YWPN_DMAREGION_W
        set REF_STANDARD = #{min}
        where ID = #{id}
    </update>

    <select id="getIsycName" resultType="string">
        select decode(#{isYc}, '0', '否', '1', '是')
        from dual
    </select>

    <select id="getPName" resultType="string">
        select DMA_NAME
        from TF_YWPN_DMAREGION_W
        where id = #{pId}
    </select>

    <select id="partitionNum" resultType="map">
        select PARTITION_LEVEL as grade, COUNT(PARTITION_LEVEL) as num
        from TF_YWPN_DMAREGION_W
        group by PARTITION_LEVEL
        ORDER BY PARTITION_LEVEL
    </select>


    <select id="getPartitionById" resultMap="dmaregionMap">
        select * from Tf_Ywpn_Dmaregion_w
        <where>
            <if test="content != null and content != '' ">
                DMA_NAME || DMA_CODE || NOTES like '%' || #{content} || '%'
            </if>
        </where>
        start with id=#{id} connect by prior id=pid order by pid
    </select>
    <!--    and kh.KHBH || kh.KHXM || kh.SSPQ LIKE '%' || #{bwglSbjd.srk,jdbcType=VARCHAR} || '%'-->
    <select id="getOneLevelByIds" resultMap="dmaregionMap">
        select * from Tf_Ywpn_Dmaregion_w
        <where>
            <if test="content != null and content != '' ">
                DMA_NAME || DMA_CODE || NOTES like '%' || #{content} || '%'
            </if>
        </where>
        start with id in (${ids}) connect by prior id=pid order by pid
    </select>
    <select id="getPartitionByIdList" resultMap="dmaregionMap">
        select * from Tf_Ywpn_Dmaregion_w
        <where>
            <if test="content != null and content != '' ">
                DMA_NAME || DMA_CODE || NOTES like '%' || #{content} || '%'
            </if>
        </where>
        start with id=#{id} connect by prior id=pid order by pid
    </select>
    <select id="getOneLevelByIdsList" resultMap="dmaregionMap">
        select * from Tf_Ywpn_Dmaregion_w
        <where>
            <if test="content != null and content != '' ">
                DMA_NAME || DMA_CODE || NOTES like '%' || #{content} || '%'
            </if>
        </where>
        start with id in (${ids}) connect by prior id=pid order by pid
    </select>
    <select id="getGuid" resultType="java.lang.String">
        select sys_guid() from dual
    </select>

</mapper>
