<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: chenlingfeng  
    $Date: 2017-7-14 上午10:10:50  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:s="leaf.plugin.script" xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="HN_CHANCE_BP" defaultOrderBy="creation_date desc">
    <bm:fields>
        <bm:field name="chance_bp_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CHANCE_BP_ID" prompt="HN_CHANCE_BP.CHANCE_BP_ID"/>
        <bm:field name="chance_bp_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CHANCE_BP_NAME" prompt="HN_CHANCE_BP.CHANCE_BP_NAME"/>
        <bm:field name="hn_industry_classification" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="HN_INDUSTRY_CLASSIFICATION" prompt="HN_CHANCE_BP.HN_INDUSTRY_CLASSIFICATION"/>
        <bm:field name="binary_classification" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BINARY_CLASSIFICATION" prompt="HN_CHANCE_BP.BINARY_CLASSIFICATION"/>
        <bm:field name="orgcrdno" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ORGCRDNO" prompt="HN_CHANCE_BP.ORGCRDNO"/>
        <bm:field name="unit_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="UNIT_ID" prompt="HN_CHANCE_BP.UNIT_ID"/>
        <bm:field name="contact_person" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTACT_PERSON" prompt="HN_CHANCE_BP.CONTACT_PERSON"/>
        <bm:field name="cell_phone" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CELL_PHONE" prompt="HN_CHANCE_BP.CELL_PHONE"/>
        <bm:field name="owner_user_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="OWNER_USER_ID" prompt="HN_CHANCE_BP.OWNER_USER_ID"/>
        <bm:field name="id_card_no" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ID_CARD_NO" prompt="HN_CHANCE_BP.ID_CARD_NO"/>
        <bm:field name="bp_class" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_CLASS" prompt="HN_CHANCE_BP.BP_CLASS"/>
        <bm:field name="enabled_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ENABLED_FLAG" prompt="HN_CHANCE_BP.ENABLED_FLAG"/>
        <bm:field name="chance_source" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="owner_user_id_n" expression="(select description from sys_user su where su.user_id = t1.owner_user_id)" forInsert="false" forUpdate="false"/>
        <bm:field name="creation_date_desc" databaseType="DATE" datatype="java.util.Date" expression="trunc(creation_date)" forInsert="false" forUpdate="false"/>
        <bm:field name="unit_id_n" expression="(select un.unit_name from exp_org_unit_v un where un.unit_id = t1.unit_id)" forInsert="false" forUpdate="false"/>
        <bm:field name="is_bp" expression=" nvl((select &apos;商业伙伴&apos;              from dual             where exists (select 1                      from hls_bp_master hbm                     where hbm.bp_id = t1.bp_id)),            &apos;潜在客户&apos;)" forInsert="false" forUpdate="false"/>
        <bm:field name="bp_id" databaseType="NUMBER" datatype="java.lang.Long"/>
    </bm:fields>
    <bm:features>
        <f:standard-who/>
        <!--  <s:bm-script><![CDATA[
            var cx = Packages.leaf.javascript.Context.getCurrentContext();
            Packages.leaf.plugin.script.engine.ScriptImportor.defineExternScript(cx, this, $ctx.getData(), "aut_authority_bm_validate.js");
        ]]></s:bm-script> -->
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="chance_bp_id"/>
    </bm:primary-key>
    <bm:query-fields>
        <bm:query-field name="chance_bp_name" queryExpression="t1.chance_bp_name like &apos;%&apos;||${@chance_bp_name}||&apos;%&apos;"/>
        <bm:query-field name="bp_class" queryExpression="t1.bp_class =${@bp_class}"/>
        <bm:query-field name="is_bp" queryExpression="nvl((select &apos;商业伙伴&apos;              from dual             where exists (select 1                      from hls_bp_master hbm                     where hbm.bp_id = t1.bp_id)),            &apos;潜在客户&apos;) = ${@is_bp}"/>
    </bm:query-fields>
    <bm:data-filters>
        <bm:data-filter expression="(exists         (select 1             from aut_trx_user_authorize a1, aut_owner_user_authorize a2            where a1.trx_category = &apos;CHANCE_BP&apos;              and a1.trx_id = t1.chance_bp_id              and trunc(sysdate) between a1.start_date and                  nvl(a1.end_date, trunc(sysdate))              and a1.user_id = a2.owner_user_id              and a1.trx_category = a2.trx_category              and a2.authorized_user_id = ${/session/@user_id}              and trunc(sysdate) between a2.start_date and                  nvl(a2.end_date, trunc(sysdate)))                or exists (select 1                       from exp_emp_assign_e_v v                      where v.primary_position_flag = &apos;Y&apos;                        and v.user_id = ${/session/@user_id}                        and v.unit_id = t1.unit_id                      ))"/>
    </bm:data-filters>
</bm:model>