<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: jack  
    $Date: 2014-12-12 上午11:24:14  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[select A.* from (SELECT unit_id   value_code,
       unit_name value_name
  FROM (SELECT a.user_id,
               a.user_name,
               a.description user_name_desc,
               b.position_id,
               b.position_code,
               b.position_name,
               b.unit_id,
               b.unit_code,
               b.unit_name,
               c.org_unit_type
          FROM sys_user               a,
               exp_employee_assigns_v b,
               exp_org_unit           c
         WHERE a.employee_id = b.employee_id
               AND c.unit_id = b.unit_id
               AND a.user_id = ${/session/@user_id}
               AND c.org_unit_type = '4S')
UNION
SELECT a.unit_id     value_code,
       a.description value_name
  FROM exp_org_unit_vl a
 WHERE a.org_unit_type = '4S'
       AND EXISTS (SELECT 1
          FROM sys_user               a,
               exp_employee_assigns_v b
         WHERE a.employee_id = b.employee_id
               AND b.position_code = '26'
               AND a.user_id = ${/session/@user_id})
UNION
SELECT a.unit_id     value_code,
       a.description value_name
  FROM exp_org_unit_vl a
 WHERE a.org_unit_type = '4S'
       AND 'HAND'=(SELECT  SU.USER_NAME FROM SYS_USER SU WHERE  SU.USER_ID=${/session/@user_id} ))  A  WHERE 1=
(SELECT count(1) FROM (SELECT unit_id   value_code,
       unit_name value_name
  FROM (SELECT a.user_id,
               a.user_name,
               a.description user_name_desc,
               b.position_id,
               b.position_code,
               b.position_name,
               b.unit_id,
               b.unit_code,
               b.unit_name,
               c.org_unit_type
          FROM sys_user               a,
               exp_employee_assigns_v b,
               exp_org_unit           c
         WHERE a.employee_id = b.employee_id
               AND c.unit_id = b.unit_id
               AND a.user_id = ${/session/@user_id}
               AND c.org_unit_type = '4S')
UNION
SELECT a.unit_id     value_code,
       a.description value_name
  FROM exp_org_unit_vl a
 WHERE a.org_unit_type = '4S'
       AND EXISTS (SELECT 1
          FROM sys_user               a,
               exp_employee_assigns_v b
         WHERE a.employee_id = b.employee_id
               AND b.position_code = '26'
               AND a.user_id = ${/session/@user_id})
UNION
SELECT a.unit_id     value_code,
       a.description value_name
  FROM exp_org_unit_vl a
 WHERE a.org_unit_type = '4S'
       AND 'HAND'=(SELECT  SU.USER_NAME FROM SYS_USER SU WHERE  SU.USER_ID=${/session/@user_id} )) t1)
]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
