<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" baseTable="ds_sms_send_white_list" alias="t1" needAccessControl="false">
    <bm:fields>
        <bm:field name="list_id"/>
        <bm:field name="white_list_type"/>
        <bm:field name="contract_id"/>
        <bm:field name="bp_tenant_id"/>
        <bm:field name="bp_agent_id"/>
        <bm:field name="contract_number" prompt="合同编号" forUpdate="false" forInsert="false"/>
        <bm:field name="bp_tenant_name" forUpdate="false" forInsert="false"/>
        <bm:field name="bp_agent_name" forUpdate="false" forInsert="false"/>
        <bm:field name="extra_nam" forUpdate="false" forInsert="false"/>
        <bm:field name="cell_phone" forUpdate="false" forInsert="false"/>
    </bm:fields>
    <bm:primary-key>
        <bm:pk-field name="list_id"/>
    </bm:primary-key>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
       select *
  from (select t.list_id,
               t.white_list_type,
               t.contract_id,
               (select cc.bp_id_tenant
                  from con_contract cc
                 where cc.contract_id = t.contract_id) bp_tenant_id,
               (select cc.bp_id_agent_level1
                  from con_contract cc
                 where cc.contract_id = t.contract_id) bp_agent_id,
               (select cc.contract_number
                  from con_contract cc
                 where cc.contract_id = t.contract_id) contract_number,
               (select hb.bp_name
                  from hls_bp_master hb, con_contract cc
                 where cc.contract_id = t.contract_id
                   and hb.bp_id = cc.bp_id_tenant) bp_tenant_name,
               (select hb.bp_name
                  from hls_bp_master hb, con_contract cc
                 where cc.contract_id = t.contract_id
                   and hb.bp_id = cc.bp_id_agent_level1) bp_agent_name,
               (select hb.extra_nam
                  from hls_bp_master hb, con_contract cc
                 where cc.contract_id = t.contract_id
                   and hb.bp_id = cc.bp_id_agent_level1) extra_nam,
               (select c.cell_phone
                  from con_contract_bp c, con_contract cc
                 where c.bp_id = cc.bp_id_tenant
                   and c.contract_id = cc.contract_id
                   and t.contract_id = cc.contract_id) cell_phone
          from ds_sms_send_white_list t) t1

                #WHERE_CLAUSE#
                #ORDER_BY_CLAUSE#
                ]]></bm:query-sql>
        </bm:operation>

        <bm:operation name="update">
            <bm:update-sql><![CDATA[
            begin
                sys407_save_pkg.white_list_save(p_list_id        => ${@list_id},
                                                    p_contract_id     => ${@contract_id},
                                                    p_bp_tenant_id    => ${@bp_tenant_id},
                                                    p_bp_agent_id     => ${@bp_agent_id},
                                                    p_white_list_type => ${@white_list_type},
                                                    p_user_id         => ${/session/@user_id});
            end;]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
            begin
                sys407_save_pkg.white_list_save(p_list_id        => ${@list_id},
                                                    p_contract_id     => ${@contract_id},
                                                    p_bp_tenant_id    => ${@bp_tenant_id},
                                                    p_bp_agent_id     => ${@bp_agent_id},
                                                    p_white_list_type => ${@white_list_type},
                                                    p_user_id         => ${/session/@user_id});
            end;]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field field="contract_number" queryOperator="like"/>
        <bm:query-field field="bp_agent_name" queryOperator="like"/>
        <bm:query-field field="extra_nam" queryOperator="like"/>
    </bm:query-fields>
</bm:model>
