<?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.bonus.core.customer.mapper.CustPlaceMapper">


    <select id="queryChildPlaceById" resultType="com.bonus.core.customer.vo.CustPlaceListVO">
        SELECT IF (( SELECT count(*) FROM cust_place WHERE super_id = c.place_id )> 0,
        1,
        0
        ) hasChildren,
        c.*
        FROM
        cust_place c
        WHERE c.if_del = 2

        <choose>
            <when test="placeId != null">
                AND c.super_id = #{placeId}
            </when>
            <otherwise>
                AND c.place_level = 1
            </otherwise>
        </choose>
    </select>
</mapper>
