<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: lpc 9874  
    $Date: 2017/11/21 9:39:12  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:s="leaf.plugin.script" xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    *
                FROM
                    (SELECT
                        c.contract_id,
                        c.data_class,
                        c.contract_number,
                        (SELECT
                            p.project_number
                        FROM
                            prj_project p
                        WHERE
                            p.project_id = c.project_id
                        ) project_number,
                        c.kingdee_contract_number,
                        c.bp_id_tenant,
                        (SELECT
                            h.kingdee_bp_code
                        FROM
                            hls_bp_master h
                        WHERE
                            h.bp_id = c.bp_id_tenant
                        ) kingdee_bp_code,
                        (SELECT h.bp_name FROM hls_bp_master h WHERE h.bp_id = c.bp_id_tenant
                        ) bp_name
                    FROM
                        con_contract c
                    ) t #WHERE_CLAUSE#
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
                BEGIN
                    UPDATE
                        con_contract
                    SET
                        kingdee_contract_number = ${@kingdee_contract_number}
                    WHERE
                        contract_id = ${@contract_id};
                        
                    UPDATE
                        hls_bp_master
                    SET
                        kingdee_bp_code = ${@kingdee_bp_code}
                    WHERE
                        bp_id = ${@bp_id_tenant};
                END;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="bp_id_tenant" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="contract_number" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="project_number" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="bp_name" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="data_class" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="kingdee_contract_number" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="kingdee_bp_code" databaseType="VARCHAR2" datatype="java.lang.String"/>
    </bm:fields>
    <bm:query-fields>
        <bm:query-field field="contract_number" queryExpression="contract_number like ${@contract_number}"/>
        <bm:query-field field="project_number" queryExpression="project_number like ${@project_number}"/>
        <bm:query-field field="bp_name" queryExpression="bp_name like ${@bp_name}"/>
        <bm:query-field field="data_class" queryExpression="t.data_class = &apos;NORMAL&apos;"/>
    </bm:query-fields>
</bm:model>
