<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: DJ  
    $Date: 2013-3-22 上午10:38:15  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="SCH_CONCURRENT_JOB">
    <bm:fields>
        <bm:field name="job_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="JOB_ID" prompt="SCH111.SCH_CONCURRENT_JOB.JOB_ID"/>
        <bm:field name="description" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DESCRIPTION" prompt="SCH111.SCH_CONCURRENT_JOB.DESCRIPTION"/>
        <bm:field name="job_start_date" databaseType="DATE" datatype="java.lang.String" physicalName="JOB_START_DATE" prompt="SCH111.SCH_CONCURRENT_JOB.JOB_START_DATE"/>
        <bm:field name="job_end_date" databaseType="DATE" datatype="java.lang.String" physicalName="JOB_END_DATE" prompt="SCH111.SCH_CONCURRENT_JOB.JOB_END_DATE"/>
        <bm:field name="job_next_run_time" databaseType="DATE" datatype="java.lang.String" physicalName="JOB_NEXT_RUN_TIME" prompt="SCH111.SCH_CONCURRENT_JOB.JOB_NEXT_RUN_TIME"/>
        <bm:field name="job_last_run_time" databaseType="DATE" datatype="java.lang.String" physicalName="JOB_LAST_RUN_TIME" prompt="SCH111.SCH_CONCURRENT_JOB.JOB_LAST_RUN_TIME"/>
        <bm:field name="job_status" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="JOB_STATUS" prompt="SCH111.SCH_CONCURRENT_JOB.JOB_STATUS"/>
        <bm:field name="job_status_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="JOB_STATUS_NAME" prompt="SCH111.SCH_CONCURRENT_JOB.JOB_STATUS"/>
        <bm:field name="parent_job_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="PARENT_JOB_ID" prompt="SCH111.SCH_CONCURRENT_JOB.PARENT_JOB_ID"/>
        <bm:field name="task_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="TASK_CODE" prompt="SCH102.SCH_TASK.TASK_CODE"/>
        <bm:field name="task_name" datatype="java.lang.String" forInsert="false" forUpdate="false" prompt="SCH102.SCH_TASK.TASK_NAME"/>
        <bm:field name="cycle_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CYCLE_FLAG" prompt="SCH111.SCH_CONCURRENT_JOB.CYCLE_FLAG"/>
        <bm:field name="schedule_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="SCHEDULE_CODE" prompt="SCH101.SCH_SCHEDULE.SCHEDULE_NAME"/>
        <bm:field name="schedule_name" datatype="java.lang.String" forInsert="false" forUpdate="false" prompt="SCH101.SCH_SCHEDULE.SHORT_DESC"/>
        <bm:field name="what" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="WHAT" prompt="SCH111.SCH_CONCURRENT_JOB.WHAT"/>
        <bm:field name="start_date" databaseType="DATE" datatype="java.util.Date" physicalName="START_DATE" prompt="SCH111.SCH_CONCURRENT_JOB.START_DATE"/>
        <bm:field name="end_date" databaseType="DATE" datatype="java.util.Date" physicalName="END_DATE" prompt="SCH111.SCH_CONCURRENT_JOB.END_DATE"/>
        <bm:field name="repeat_interval" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REPEAT_INTERVAL" prompt="SCH111.SCH_CONCURRENT_JOB.REPEAT_INTERVAL"/>
        <bm:field name="company_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="COMPANY_ID" prompt="SCH111.SCH_CONCURRENT_JOB.COMPANY_ID"/>
        <bm:field name="role_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="ROLE_ID" prompt="SCH111.SCH_CONCURRENT_JOB.ROLE_ID"/>
        <bm:field name="user_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="USER_ID" prompt="SCH111.SCH_CONCURRENT_JOB.USER_ID"/>
        <bm:field name="create_sub_job_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CREATE_SUB_JOB_FLAG" prompt="SCH111.SCH_CONCURRENT_JOB.CREATE_SUB_JOB_FLAG"/>
        <bm:field name="run_times" databaseType="NUMBER" datatype="java.lang.Long" physicalName="RUN_TIMES" prompt="SCH111.SCH_CONCURRENT_JOB.RUN_TIMES"/>
        <bm:field name="error_times" databaseType="NUMBER" datatype="java.lang.Long" physicalName="RUN_TIMES" prompt="SCH111.SCH_CONCURRENT_JOB.ERROR_TIMES"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
    			select t1.job_id,
				       t1.description,
				       to_char(t1.job_start_date,'yyyy-mm-dd hh24:mi:ss') as job_start_date,
				       to_char(t1.job_last_run_time,'yyyy-mm-dd hh24:mi:ss') as job_last_run_time,
				       to_char(t1.job_next_run_time,'yyyy-mm-dd hh24:mi:ss') as job_next_run_time,
				       to_char(t1.job_end_date,'yyyy-mm-dd hh24:mi:ss') as job_end_date,
				       t1.task_code,
				       t1.job_status,
				       (select v.code_value_name
				          from sys_code_values_v v
				         where v.code = 'SCH_JOB_STATUS'
				           and v.code_value = t1.job_status) as job_status_name,
				       t1.parent_job_id,
				       (select t.task_name from sch_task t where t.task_code = t1.task_code) as task_name,
				       t1.cycle_flag,
				       t1.schedule_code,
				       (select s.short_desc
				          from sch_schedule s
				         where s.schedule_name = t1.schedule_code) as schedule_name,
				       t1.what,
				       t1.start_date,
				       t1.end_date,
				       t1.repeat_interval,
				       t1.company_id,
				       t1.role_id,
				       t1.user_id,
				       t1.create_sub_job_flag,
				       t1.run_times,
				       t1.error_times
				  from sch_concurrent_job t1
				  #WHERE_CLAUSE#
				 order by t1.job_id desc
    		]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="insert">
            <bm:parameters>
                <bm:parameter name="job_id" input="false" output="true" outputPath="@job_id"/>
            </bm:parameters>
            <bm:update-sql><![CDATA[
        		begin
				    ${@job_id} := sch_concurrent_job_pkg.job_submit(p_task_code 			=> ${@task_code},
								                                    p_schedule_code 		=> ${@schedule_code},
								                                    p_create_sub_job_flag	=> ${@create_sub_job_flag},
								                                    p_description 			=> ${@description},
								                                    p_company_id 			=> ${/session/@company_id},
								                                    p_role_id 				=> ${/session/@role_id},
								                                    p_user_id 				=> ${/session/@user_id},
								                                    p_parameter_1 			=> ${@parameter_1},
								                                    p_parameter_2 			=> ${@parameter_2},
								                                    p_parameter_3 			=> ${@parameter_3},
								                                    p_parameter_4 			=> ${@parameter_4},
								                                    p_parameter_5 			=> ${@parameter_5},
								                                    p_parameter_6 			=> ${@parameter_6},
								                                    p_parameter_7 			=> ${@parameter_7},
								                                    p_parameter_8 			=> ${@parameter_8},
								                                    p_parameter_9 			=> ${@parameter_9},
								                                    p_parameter_10 			=> ${@parameter_10},
								                                    p_parameter_11       	=> ${@parameter_11},
				                                                    p_parameter_12       	=> ${@parameter_12},
				                                                    p_parameter_13       	=> ${@parameter_13},
				                                                    p_parameter_14       	=> ${@parameter_14},
				                                                    p_parameter_15       	=> ${@parameter_15},
				                                                    p_parameter_16       	=> ${@parameter_16},
				                                                    p_parameter_17       	=> ${@parameter_17},
				                                                    p_parameter_18       	=> ${@parameter_18},
				                                                    p_parameter_19       	=> ${@parameter_19},
				                                                    p_parameter_20       	=> ${@parameter_20});
				end;
        	]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
        		begin
				     	 sch_system_job_pkg.cycle_job_handle(p_job_id         => ${@job_id},
								                             p_operation_type => ${@operation_type},
								                             p_user_id        => ${/session/@user_id});
				end;
        	]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:features>
        <f:standard-who/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="job_id"/>
    </bm:primary-key>
    <bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="exists( select 1 from sch_task_authorize a where a.task_code = t1.task_code and a.role_id = ${/session/@role_id})"/>
    </bm:data-filters>
    <bm:query-fields>
        <bm:query-field field="job_id" queryOperator="="/>
        <bm:query-field field="parent_job_id" queryOperator="="/>
        <bm:query-field field="description" queryOperator="like"/>
        <bm:query-field field="task_code" queryOperator="="/>
        <bm:query-field field="schedule_code" queryOperator="="/>
        <bm:query-field field="job_status" queryOperator="="/>
        <bm:query-field name="cycle_flag" queryExpression="(${@cycle_flag} = &apos;ALL&apos; or t1.cycle_flag = ${@cycle_flag})"/>
        <bm:query-field name="job_start_date" queryExpression="t1.job_start_date between trunc(to_date(${@job_start_date},&apos;yyyy-mm-dd&apos;)) and trunc(to_date(${@job_start_date},&apos;yyyy-mm-dd&apos;))+1"/>
    </bm:query-fields>
</bm:model>
