<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: LIJINGJING
    $Date: 2019-09-10 下午4:38:18
    $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 con_contract_history_lv t
 where t.Id_Card_No =
       (select hbm.id_card_no from hls_bp_master hbm where hbm.bp_id = ${@bp_id})
   and t.unit_id in (select vv.unit_id from exp_emp_assign_e_v vv where vv.user_id = ${/session/@user_id})
   and t.Id_Card_No is not null
   and exists(
select vv.unit_id from exp_emp_assign_e_v vv where vv.user_id = ${/session/@user_id} and vv.POSITION_TYPE = 'SALES'
   )
union all
--非代理店(自然人)
select *
  from con_contract_history_lv t
 where t.Id_Card_No =
       (select hbm.id_card_no from hls_bp_master hbm where hbm.bp_id = ${@bp_id})
   and t.Id_Card_No is not null
   and  not exists(
select vv.unit_id from exp_emp_assign_e_v vv where vv.user_id = ${/session/@user_id} and vv.POSITION_TYPE = 'SALES'
   )
union all
--代理店(法人)
select *
  from con_contract_history_lv t
 where t.social_code = (select hbm.social_code
                          from hls_bp_master hbm
                         where hbm.bp_id = ${@bp_id})
   and t.unit_id in (select vv.unit_id from exp_emp_assign_e_v vv where vv.user_id = ${/session/@user_id})
   and t.Id_Card_No is not null
   and exists(
select vv.unit_id from exp_emp_assign_e_v vv where vv.user_id = ${/session/@user_id} and vv.POSITION_TYPE = 'SALES'
   )
union all
--非代理店(法人)
select *
  from con_contract_history_lv t
 where t.social_code = (select hbm.social_code
                          from hls_bp_master hbm
                         where hbm.bp_id = ${@bp_id})
   and t.Id_Card_No is not null
   and not exists(
select vv.unit_id from exp_emp_assign_e_v vv where vv.user_id = ${/session/@user_id} and vv.POSITION_TYPE = 'SALES'
   )
#WHERE_CLAUSE#
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
