<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: wangwei  
    $Date: 2015-5-21 下午1:39:05  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:e="leaf.service.exception" xmlns:o="leaf.database.local.oracle" xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="HLS_DOC_FILE_TEMPLET">
    <bm:fields>
        <bm:field name="templet_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="TEMPLET_ID" prompt="HLS_DOC_FILE_TEMPLET.TEMPLET_ID"/>
        <bm:field name="templet_code" databaseType="VARCHAR2" datatype="java.lang.String" forDisplay="true" forQuery="true" physicalName="TEMPLET_CODE" prompt="模板代码"/>
        <bm:field name="templet_name" databaseType="VARCHAR2" datatype="java.lang.String" forDisplay="true" forQuery="true" physicalName="TEMPLET_NAME" prompt="模板名称"/>
        <bm:field name="usage_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="USAGE_CODE" prompt="HLS_DOC_FILE_TEMPLET.USAGE_CODE"/>
        <bm:field name="note" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="NOTE" prompt="HLS_DOC_FILE_TEMPLET.NOTE"/>
        <bm:field name="templet_file_path" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="TEMPLET_FILE_PATH" prompt="HLS_DOC_FILE_TEMPLET.TEMPLET_FILE_PATH"/>
        <bm:field name="templet_file_name" databaseType="VARCHAR2" datatype="java.lang.String" forDisplay="true" physicalName="TEMPLET_FILE_NAME" prompt="文件名"/>
        <bm:field name="enabled_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ENABLED_FLAG" prompt="HLS_DOC_FILE_TEMPLET.ENABLED_FLAG"/>
        <bm:field name="usage_code_des" expression="(select sc.code_value_name from sys_code_values_v sc where sc.code=&apos;HLS_DOC_FILE_USAGE&apos; and sc.code_value=t1.usage_code)" forInsert="false" forUpdate="false"/>
        <bm:field name="pwd"/>
        <bm:field name="encryption_pwd" insertExpression="nvl2(${@pwd},sys_login_pkg.md5(p_password =&gt; nvl(${@pwd},&apos;1&apos;)),null)" updateExpression="sys_login_pkg.md5(  =&gt; ${@pwd})"/>

        <bm:field name="main_flag"/>
        <bm:field name="tenant_flag"/>
        <bm:field name="guarantor_flag"/>
        <bm:field name="agent_flag"/>

        <bm:field name="main_key_word"/>
        <bm:field name="tenant_key_word"/>
        <bm:field name="guarantor_key_word"/>
        <bm:field name="agent_key_word"/>

        <bm:field name="tenant_loop_flag"/>
        <bm:field name="agent_loop_flag"/>
        <bm:field name="guarantor_loop_flag"/>

        <bm:field name="main_timestamp_key_word"/>
        <bm:field name="tenant_timestamp_key_word"/>
        <bm:field name="guarantor_timestamp_key_word"/>
        <bm:field name="agent_timestamp_key_word"/>



    </bm:fields>
    <bm:features>
        <o:sequence-pk sequenceName="hls_doc_file_templet_s"/>
        <f:standard-who/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="templet_id"/>
    </bm:primary-key>
    <bm:query-fields>
        <bm:query-field field="templet_code" queryOperator="like"/>
        <bm:query-field field="templet_name" queryOperator="like"/>
        <bm:query-field field="usage_code" queryOperator="="/>
        <bm:query-field name="enabled_flag" queryExpression="((${@enabled_flag}=&apos;Y&apos; and t1.enabled_flag=&apos;Y&apos;) or (${@enabled_flag}=&apos;N&apos; and nvl(t1.enabled_flag,&apos;N&apos;)=&apos;N&apos;) or  (${@enabled_flag}=&apos;ALL&apos; and nvl(t1.enabled_flag,&apos;N&apos;) in(&apos;N&apos;,&apos;Y&apos;)) )"/>
    </bm:query-fields>
    <e:exception-descriptor-config>
        <e:exception-descriptor exception="java.sql.SQLException" handleClass="leaf.database.SQLExceptionDescriptor">
            <e:error-message code="1" message="文件模板代码已存在！"/>
        </e:exception-descriptor>
    </e:exception-descriptor-config>
    <bm:operations>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
    		
    			UPDATE HLS_DOC_FILE_TEMPLET t1
				SET t1.TEMPLET_CODE=${@templet_code},
					t1.TEMPLET_NAME=${@templet_name},
					t1.USAGE_CODE=${@usage_code},
					t1.NOTE=${@note},
					t1.TEMPLET_FILE_PATH=${@templet_file_path},
					t1.TEMPLET_FILE_NAME=${@templet_file_name},
					t1.ENABLED_FLAG=${@enabled_flag},
					t1.pwd=${@pwd},
					t1.encryption_pwd=nvl2(${@pwd},sys_login_pkg.md5(p_password => nvl(${@pwd},'1')),null),
					t1.LAST_UPDATED_BY=${/session/@user_id},
					t1.LAST_UPDATE_DATE=sysdate,
					t1.main_flag=${@main_flag},
					t1.tenant_flag=${@tenant_flag},
					t1.guarantor_flag=${@guarantor_flag},
					t1.agent_flag=${@agent_flag},
					t1.main_key_word=${@main_key_word},
					t1.tenant_key_word=${@tenant_key_word},
					t1.guarantor_key_word=${@guarantor_key_word},
					t1.agent_key_word=${@agent_key_word},
					t1.tenant_loop_flag=${@tenant_loop_flag},
					t1.agent_loop_flag=${@agent_loop_flag},
					t1.guarantor_loop_flag=${@guarantor_loop_flag},

					t1.main_timestamp_key_word=${@main_timestamp_key_word},
					t1.tenant_timestamp_key_word=${@tenant_timestamp_key_word},
					t1.guarantor_timestamp_key_word=${@guarantor_timestamp_key_word},
					t1.agent_timestamp_key_word=${@agent_timestamp_key_word}

				WHERE t1.TEMPLET_ID = ${@templet_id}
    		
    	]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
