<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangxing5129  
    $Date: 2013-12-10 下午03:41:29  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:e="leaf.service.exception" xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="AUT_AUTHORIZED_USER_BATCH_TMP">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
				select v.user_id,
				       v.user_name,
				       v.description authorized_user_desc,
				       v.employee_code,
				       v.employee_name,
				       t.session_id,
				       decode(t.session_id,null,'N','Y') checked
				  from sys_user_v v, aut_authorized_user_batch_tmp t
				 where v.user_id = t.user_id(+)
				   and t.session_id(+) = ${/session/@session_id}
			]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
    			    declare 
    			      v_count number;
    				begin
    				  if ${@checked} = 'N' then
    				    delete from aut_authorized_user_batch_tmp where user_id = ${@user_id} and session_id = ${/session/@session_id}; 
    				  elsif ${@checked} = 'Y' then
    				    begin
    				      select 1 into v_count from aut_authorized_user_batch_tmp where user_id = ${@user_id} and session_id = ${/session/@session_id};
    				    exception
    				      when others then
    				        INSERT INTO aut_authorized_user_batch_tmp
						  (session_id,
						   user_id,
						   CREATED_BY,
						   CREATION_DATE,
						   LAST_UPDATED_BY,
						   LAST_UPDATE_DATE)
						VALUES
						  (${/session/@session_id},
						   ${@user_id},
						   ${/session/@user_id},
						   sysdate,
						   ${/session/@user_id},
						   sysdate);
    				    end;
    				  end if;
    				end;
    			
    		]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="user_name" forInsert="false" forUpdate="false"/>
        <bm:field name="employee_name" forInsert="false" forUpdate="false"/>
        <bm:field name="authorized_user_desc" forInsert="false" forUpdate="false"/>
        <bm:field name="employee_code" forInsert="false" forUpdate="false"/>
        <bm:field name="checked"/>
        <bm:field name="session_id" databaseType="NUMBER" datatype="java.lang.Long" insertExpression="${/session/@session_id}" physicalName="SESSION_ID" prompt="AUT_OWNER_USER_BATCH_TMP.SESSION_ID"/>
        <bm:field name="user_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="USER_ID" prompt="AUT_OWNER_USER_BATCH_TMP.USER_ID"/>
    </bm:fields>
    <bm:primary-key>
        <bm:pk-field name="session_id"/>
        <bm:pk-field name="user_id"/>
    </bm:primary-key>
    <bm:features>
        <f:standard-who/>
    </bm:features>
    <e:exception-descriptor-config>
        <e:exception-descriptor exception="java.sql.SQLException" handleClass="leaf.database.SQLExceptionDescriptor">
            <e:error-message code="1" message="AUT106.USER_ID_UNIQUE_ERROR"/>
        </e:exception-descriptor>
    </e:exception-descriptor-config>
</bm:model>
