<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
            	SELECT
                    -1 grant_id,
                    NULL parent_grant_id,
                    'BRAND' grant_type,
                    '吉利' grant_desc,
                    'N' checked
                FROM
                    dual
                UNION ALL
                SELECT
                    hb.brand_id grant_id,
                    -1 parent_grant_id,
                    'BRAND' grant_type,
                    (select hv.description from hls_car_brands_vl hv where hv.brand_id=hb.brand_id) grant_desc,
                    DECODE(
                    (SELECT
                        COUNT(*) FROM hls_product_car_discount ar WHERE ar.brand_id = hb.brand_id and
                        ar.product_grant_id                                             =${/parameter/@product_plan_id}
                    ),0,'N','Y') checked
                FROM
                    hls_car_brands hb
                WHERE
                    hb.enabled_flag = 'Y'
                UNION ALL
                SELECT
                    hs.series_id grant_id,
                    hb.brand_id parent_grant_id,
                    'SERIES' grant_type,
                    (select hv.description from hls_car_series_vl hv where hv.series_id=hs.series_id) grant_desc,
                    DECODE(
                    (SELECT
                        COUNT(*) FROM hls_product_car_discount ar WHERE ar.brand_id = hb.brand_id AND
                        ar.series_id                                                = hs.series_id and
                        ar.product_grant_id                                             =${/parameter/@product_plan_id}
                    ),0,'N','Y') checked
                FROM
                    hls_car_series hs,
                    hls_car_brands hb
                WHERE
                    hs.brand_id    = hb.brand_id AND
                    hs.enabled_flag   = 'Y' AND
                    hb.enabled_flag   = 'Y'
                order by parent_grant_id,grant_id
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
