<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: chenlingfeng  
    $Date: 2017-7-21 下午3:38:00  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:s="leaf.plugin.script" xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    sysdate now_time,
                    to_date('3000-01-01','yyyy-mm-dd') never_date,
                    t1.employees_assign_id,
                    t1.enabled_flag,
                    t1.primary_position_flag,
                    t1.employee_id,
                    e.enabled_flag AS employee_enabled, --员工是否启用
                    e.employee_code,
                    e.name AS employee_name,
                    t1.company_id,
                    c.enabled_flag AS company_enabled, --公司是否启用
                    c.company_code,
                    c.company_short_name,
                    t1.position_id,
                    p.enabled_flag AS position_enabled, --岗位是否启用
                    p.position_code,
                    p.position_type,
                    p.description AS position_name,
                    p.unit_id,
                    u.enabled_flag AS unit_enabled, --部门是否启用
                    u.unit_code,
                    u.description AS unit_name,
                    t1.employee_job_id,
                    t1.employee_levels_id,
                    su.description user_desc
                FROM
                    exp_employee_assigns t1,
                    exp_employees e,
                    fnd_companies_vl c,
                    exp_org_position_vl p,
                    exp_org_unit_vl u,
                    sys_user su
                WHERE
                    e.employee_id             = t1.employee_id AND
                    c.company_id              = t1.company_id AND
                    su.employee_id            = e.employee_id AND
                    p.position_id             = t1.position_id AND
                    u.unit_id                 = p.unit_id AND
                    t1.primary_position_flag  ='Y' AND
                    e.enabled_flag            = 'Y' AND
                    c.company_code            ='HNTCFL' AND
                    NVL(su.end_date,sysdate) >=TRUNC(sysdate) AND
                    su.user_id                = ${/session/@user_id} AND
                    rownum                    =1
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="employees_assign_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="EMPLOYEES_ASSIGN_ID" required="true"/>
        <bm:field name="enabled_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ENABLED_FLAG" required="true"/>
        <bm:field name="primary_position_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PRIMARY_POSITION_FLAG" required="true"/>
        <bm:field name="employee_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="EMPLOYEE_ID" required="true"/>
        <bm:field name="employee_enabled" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="EMPLOYEE_ENABLED" required="true"/>
        <bm:field name="employee_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="EMPLOYEE_CODE" required="true"/>
        <bm:field name="employee_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="EMPLOYEE_NAME" required="true"/>
        <bm:field name="company_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="COMPANY_ID" required="true"/>
        <bm:field name="company_enabled" databaseType="CHAR" datatype="java.lang.String" physicalName="COMPANY_ENABLED"/>
        <bm:field name="company_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="COMPANY_CODE" required="true"/>
        <bm:field name="company_short_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="COMPANY_SHORT_NAME"/>
        <bm:field name="position_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="POSITION_ID" required="true"/>
        <bm:field name="position_enabled" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="POSITION_ENABLED" required="true"/>
        <bm:field name="position_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="POSITION_CODE"/>
        <bm:field name="position_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="POSITION_TYPE" required="true"/>
        <bm:field name="position_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="POSITION_NAME"/>
        <bm:field name="unit_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="UNIT_ID" required="true"/>
        <bm:field name="unit_enabled" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="UNIT_ENABLED" required="true"/>
        <bm:field name="unit_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="UNIT_CODE"/>
        <bm:field name="unit_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="UNIT_NAME"/>
        <bm:field name="employee_job_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="EMPLOYEE_JOB_ID"/>
        <bm:field name="employee_levels_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="EMPLOYEE_LEVELS_ID"/>
        <bm:field name="now_time" databaseType="DATE" datatype="java.util.Date"/>
        <bm:field name="never_date" databaseType="DATE" datatype="java.util.Date"/>
        <bm:field name="user_desc" databaseType="VARCHAR2" datatype="java.lang.String"/>
    </bm:fields>
</bm:model>
