<?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.ozs.system.mapper.SysRegionMapper">

    <resultMap type="com.ozs.system.domain.vo.SysRegionVO" id="divisionList">
        <id property="id" column="id" />
        <result property="administrativeDivision" column="administrative_division" />
        <result property="pid" column="pid" />
        <result property="code" column="code" />
        <result property="level" column="level" />
        <collection property="children"
                    ofType="com.ozs.system.domain.vo.SysRegionVO"
                    select="findChildDivisions"
                    column="code"/>
    </resultMap>

    <select id="findChildDivisions" resultMap="divisionList">
        SELECT m.id, m.administrative_division, m.pid, m.code, m.level
        FROM sys_region m
        WHERE pid = (select n.id from sys_region n where n.code = #{pcode})
    </select>

    <select id="selectInfoByCode" resultType="com.ozs.system.domain.vo.SysRegionVO">
        SELECT m.id, m.administrative_division as administrativeDivision, m.pid, m.code, m.level
        FROM sys_region m
        WHERE code = #{code}
    </select>

</mapper>
