<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author:   HAND技术
    $Date:     2013/12/12
    $Revision: 1.0
    $Purpose:  车系
-->
<bm:model xmlns:e="leaf.service.exception" xmlns:o="leaf.database.local.oracle" xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t" baseTable="HLS_CAR_SERIES">
    <bm:fields>
        <bm:field name="series_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="SERIES_ID"/>
        <bm:field name="brand_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="BRAND_ID"/>
        <bm:field name="series_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="SERIES_CODE" prompt="HLS_CAR_SERIES.SERIES_CODE"/>
        <bm:field name="description" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DESCRIPTION" prompt="HLS_CAR_SERIES.DESCRIPTION"/>
        <bm:field name="enabled_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ENABLED_FLAG" prompt="HLS.ENABLED_FLAG"/>
        <bm:field name="plate_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="PLATE_ID" prompt="平台"/>
        <bm:field name="plate_id_n"/>
        <bm:field name="guide_price"/>
        <bm:field name="vehicle_type"/>
        <bm:field name="vehicle_type_desc" forInsert="false" forUpdate="false"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
				select v.series_id,
				       v.brand_id,
				       v.series_code,
				       v.description,
				       v.enabled_flag,
				       v.guide_price,
				       v.vehicle_type,
				       (select v1.code_value_name  
				        from sys_code_values_v v1 
				        where v1.code = 'HLS_VEHICLE_TYPE' 
				        and v1.code_value = v.vehicle_type) as vehicle_type_desc,
				       v.plate_id,
				       v.plate_id_n
				  from hls_car_series_vl v
				  #WHERE_CLAUSE#
				 order by v.series_code
    		]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="insert">
            <bm:parameters>
                <bm:parameter name="series_id" input="false" output="true" outputPath="@series_id"/>
            </bm:parameters>
            <bm:update-sql><![CDATA[
        		begin
				  HLS222_SAVE_PKG.series_manage(p_sql_type	 => 'INSERT',
				  							      p_series_id    => ${@series_id},
				  							      p_brand_id     => ${@brand_id},
								                  p_series_code  => ${@series_code},
								                  p_description  => ${@description},
								                  p_enabled_flag => ${@enabled_flag},
								                  p_guide_price  => ${@guide_price},
								                  p_vehicle_type => ${@vehicle_type},
								                  p_plate_id	 => ${@plate_id},
								                  p_user_id      => ${/session/@user_id});
				end;
        	]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
        		begin
				  HLS222_SAVE_PKG.series_manage(p_sql_type	 => 'UPDATE',
				  							      p_series_id    => ${@series_id},
				  							      p_brand_id     => ${@brand_id},
								                  p_series_code  => ${@series_code},
								                  p_description  => ${@description},
								                  p_enabled_flag => ${@enabled_flag},
								                  p_guide_price  => ${@guide_price},
								                  p_vehicle_type => ${@vehicle_type},
								                  p_plate_id	 => ${@plate_id},
								                  p_user_id      => ${/session/@user_id});
				end;
        	]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="delete">
            <bm:update-sql><![CDATA[
        		begin
				  HLS222_SAVE_PKG.series_manage(p_sql_type	 => 'DELETE',
				  							      p_series_id    => ${@series_id},
				  							      p_brand_id     => ${@brand_id},
								                  p_series_code  => ${@series_code},
								                  p_description  => ${@description},
								                  p_enabled_flag => ${@enabled_flag},
								                  p_guide_price  => ${@guide_price},
								                  p_vehicle_type => ${@vehicle_type},
								                  p_plate_id	 => ${@plate_id},
								                  p_user_id      => ${/session/@user_id});
				end;
        	]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:data-filters>
        <bm:data-filter name="brand_id" enforceOperations="query" expression="v.brand_id=${@brand_id}"/>
    </bm:data-filters>
    <bm:query-fields>
        <bm:query-field name="series_id" queryExpression="v.series_id=${@series_id}"/>
    </bm:query-fields>
    <bm:features>
        <f:standard-who/>
        <o:sequence-pk/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="series_id"/>
    </bm:primary-key>
    <e:exception-descriptor-config>
        <e:exception-descriptor exception="java.sql.SQLException" handleClass="leaf.database.SQLExceptionDescriptor">
            <e:error-message code="1" message="同一品牌下车系代码重复"/>
        </e:exception-descriptor>
    </e:exception-descriptor-config>
</bm:model>
