<?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.water.mapper.TfRegionPMapper">

    <resultMap id="tfRegionPMap" type="com.tofly.water.entity.TfRegionP">
        <id property="id" column="ID"/>
        <result property="tenantId" column="TENANT_ID"/>
        <result property="name" column="NAME"/>
        <result property="fullName" column="FULL_NAME"/>
        <result property="regionCode" column="REGION_CODE"/>
        <result property="regionLevel" column="REGION_LEVEL"/>
        <result property="regionId" column="REGION_ID"/>
        <result property="isDel" column="IS_DEL"/>
        <result property="remark" column="REMARK"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="updateUser" column="UPDATE_USER"/>
        <result property="updateTime" column="UPDATE_TIME"/>
        <association property="createUserName" column="CREATE_USER"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="updateUserName" column="UPDATE_USER"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="isDelName" column="IS_DEL" select="getIsDelName"></association>
    </resultMap>

    <select id="getIsDelName" resultType="string">
        SELECT decode(#{isDel}, '0', '未删除', '1', '已删除') as isDelName
        FROM dual
    </select>


    <select id="getNameById" resultType="String">
        SELECT REPLACE( wm_concat ( NAME ), ',', '-' ) NAME
        FROM
            ( SELECT NAME FROM TF_REGION_P START WITH ID = #{id} CONNECT BY PRIOR REGION_ID = ID ORDER BY ID )
    </select>


</mapper>
