<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: peter soong  
    $Date: 2014-07-27 10:38:19 
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    *
                FROM
                    (SELECT
                        (SELECT
                            b.pattern
                        FROM
                            prj_project_lease_item b
                        WHERE
                            b.project_lease_item_id = a.project_lease_item_id AND
                            b.main_engine           = 'CAR_MAIN'
                        ) main_pattern,
                        (SELECT
                            b.engine
                        FROM
                            prj_project_lease_item b
                        WHERE
                            b.project_lease_item_id = a.project_lease_item_id AND
                            b.main_engine           = 'CAR_MAIN'
                        ) main_engine,
                        (SELECT
                            b.pattern
                        FROM
                            prj_project_lease_item b
                        WHERE
                            b.project_lease_item_id = a.project_lease_item_id AND
                            b.main_engine           = 'CAR_Trailer'
                        ) trailer_pattern,
                        (SELECT
                            b.engine
                        FROM
                            prj_project_lease_item b
                        WHERE
                            b.project_lease_item_id = a.project_lease_item_id AND
                            b.main_engine           = 'CAR_Trailer'
                        ) trailer_engine
                    FROM
                        prj_project_lease_item a
                    WHERE
                        a.project_id = ${/parameter/@project_id}
                    ) t1
            ]]></bm:query-sql>
            <bm:parameters>
                <bm:parameter inputPath="/parameter/@project_id"/>
            </bm:parameters>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
            	BEGIN
            	    UPDATE
            	        prj_project_lease_item a
            	    SET
            	        a.engine  = ${@trailer_engine},
            	        a.pattern = ${@trailer_pattern}
            	    WHERE
            	        a.project_id  = ${@project_id} AND
            	        a.main_engine = ${@engine_type} ;
            	END ;
            	
        	  	]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="main_pattern" databaseType="VARCHAR2" datatype="java.lang.String" prompt="发动机号"/>
        <bm:field name="main_engine" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="trailer_pattern" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="trailer_engine" databaseType="VARCHAR2" datatype="java.lang.String"/>
    </bm:fields>
</bm:model>
