create or replace package pkg_rpt_jewel is -- Author : DALIN.CHEN -- Created : 2010-5-27 15:03:02 -- Purpose : call data extract inteface one by one with priority -- interface type declarations INTERFACE_TYPE_DAILY constant NUMBER := 1; INTERFACE_TYPE_WEEKLY constant NUMBER := 2; INTERFACE_TYPE_MONTHLY constant NUMBER := 3; INTERFACE_TYPE_QUARTERLY constant NUMBER := 4; INTERFACE_TYPE_SEMIYEARLY constant NUMBER := 5; INTERFACE_TYPE_YEARLY constant NUMBER := 6; -- more ... INTERFACE_TYPE_WORKDAY constant NUMBER := 11; INTERFACE_TYPE_DAY_OF_MONTH constant NUMBER := 12; --in batch will get interface count and use priority from 1 to interface count to call data exract interface one by one FUNCTION F_INTERFACE_CALL(I_PROCESS_DATE IN DATE, I_INTERFACE_TYPE IN NUMBER, I_RUN_ID IN NUMBER, I_EXTRA_PARAM IN NUMBER ) RETURN NUMBER; FUNCTION F_INTERFACE_CALL_S_R(I_PROCESS_DATE IN DATE, I_INTERFACE_TYPE IN NUMBER, I_RUN_ID IN NUMBER, I_EXTRA_PARAM IN NUMBER ) RETURN NUMBER; FUNCTION F_INTERFACE_CALL_OGIS(I_PROCESS_DATE IN DATE, I_INTERFACE_TYPE IN NUMBER, I_RUN_ID IN NUMBER, I_EXTRA_PARAM IN NUMBER ) RETURN NUMBER; end pkg_rpt_jewel; / CREATE OR REPLACE PACKAGE BODY pkg_rpt_jewel IS PROCEDURE P_LOG_TRACE(I_INTERFACE_CONFIG IN T_RPT_INTERFACE_CONFIG%ROWTYPE, I_PROCESS_DATE IN DATE, I_RUN_ID IN NUMBER, I_TRACE_LOG IN VARCHAR2 ) IS BEGIN IF (I_INTERFACE_CONFIG.Report_Name IS NOT NULL) THEN INSERT INTO T_RPT_TRACE (ID, REPORT_NAME, FREQUENCY, REPORT_DATE, TRACE_LOG, RUN_ID, INSERT_TIME) SELECT S_RPT_TRACE__ID.Nextval, I_INTERFACE_CONFIG.Report_Name, I_INTERFACE_CONFIG.Interface_Type, I_PROCESS_DATE, I_TRACE_LOG, I_RUN_ID, SYSDATE FROM DUAL; END IF; EXCEPTION WHEN OTHERS THEN NULL; END P_LOG_TRACE; FUNCTION F_EXECUTE_INTERFACE(I_PROCESS_DATE IN DATE, I_RUN_ID IN NUMBER, I_INTERFACE_CONFIG T_RPT_INTERFACE_CONFIG%ROWTYPE ) RETURN NUMBER IS V_PARAM_POS NUMBER := 0; V_TRACE_LOG T_RPT_TRACE.TRACE_LOG%TYPE; V_START_TIME DATE; V_EXECUTION_SECONDS NUMBER := 0; BEGIN BEGIN select SYSDATE into V_START_TIME from dual; select instr(I_INTERFACE_CONFIG.INTERFACE_NAME, ':1', 1) into V_PARAM_POS from dual; if (V_PARAM_POS > 0) then EXECUTE IMMEDIATE 'begin ' || I_INTERFACE_CONFIG.INTERFACE_NAME || '; end;' using in I_PROCESS_DATE; else EXECUTE IMMEDIATE 'begin ' || I_INTERFACE_CONFIG.INTERFACE_NAME || '; end;'; end if; select (sysdate - V_START_TIME) * 24 * 3600 INTO V_EXECUTION_SECONDS from dual; P_LOG_TRACE(I_INTERFACE_CONFIG, I_PROCESS_DATE, I_RUN_ID, 'successful - ' || V_EXECUTION_SECONDS || ' s'); COMMIT; RETURN 1; EXCEPTION WHEN OTHERS THEN BEGIN V_TRACE_LOG := SQLCODE || '::' || SUBSTR(SQLERRM, 0, 3950); ROLLBACK; P_LOG_TRACE(I_INTERFACE_CONFIG, I_PROCESS_DATE, I_RUN_ID, V_TRACE_LOG); COMMIT; EXCEPTION WHEN OTHERS THEN NULL; END; RETURN -1; END; END F_EXECUTE_INTERFACE; FUNCTION F_INTERFACE_CALL(I_PROCESS_DATE IN DATE, I_INTERFACE_TYPE IN NUMBER, I_RUN_ID IN NUMBER, I_EXTRA_PARAM IN NUMBER ) RETURN NUMBER is V_RPT_CONFIG T_RPT_INTERFACE_CONFIG%ROWTYPE; V_NEED_EXEC NUMBER; V_CONFIG_OK NUMBER; V_RESULT NUMBER := 0; V_SUCC NUMBER := 0; V_FAIL NUMBER := 0; BEGIN FOR V_RPT_CONFIG IN (SELECT * FROM T_RPT_INTERFACE_CONFIG WHERE INTERFACE_TYPE = I_INTERFACE_TYPE AND STATUS = 'Y' AND ID not in (108, 10000) order by MODULE_PRIORITY, PRIORITY_IN_MODULE) LOOP V_CONFIG_OK := 1; V_NEED_EXEC := 0; --except monthly, are day of XX, so interface parameter is necessary if (INTERFACE_TYPE_MONTHLY != I_INTERFACE_TYPE and INTERFACE_TYPE_DAILY != I_INTERFACE_TYPE) then if (V_RPT_CONFIG.INTERFACE_PARAM is null) then V_CONFIG_OK := 0; --skip P_LOG_TRACE(V_RPT_CONFIG, I_PROCESS_DATE, I_RUN_ID, 'must set INTERFACE_PARAM for interface:' || I_INTERFACE_TYPE); COMMIT; end if; end if; --check if need execute if (INTERFACE_TYPE_DAILY = I_INTERFACE_TYPE) then V_NEED_EXEC := 1; elsif (INTERFACE_TYPE_WORKDAY = I_INTERFACE_TYPE) then if (I_EXTRA_PARAM = V_RPT_CONFIG.INTERFACE_PARAM or 0 = V_RPT_CONFIG.INTERFACE_PARAM) then V_NEED_EXEC := 1; end if; elsif (INTERFACE_TYPE_WEEKLY = I_INTERFACE_TYPE) THEN if (I_EXTRA_PARAM = V_RPT_CONFIG.INTERFACE_PARAM or 0 = V_RPT_CONFIG.INTERFACE_PARAM) then V_NEED_EXEC := 1; end if; if (V_NEED_EXEC = 0) then if (I_EXTRA_PARAM = 999 and V_RPT_CONFIG.INTERFACE_PARAM = 7) THEN V_NEED_EXEC := 1; END IF; end if; elsif (INTERFACE_TYPE_DAY_OF_MONTH = I_INTERFACE_TYPE) then if (I_EXTRA_PARAM = V_RPT_CONFIG.INTERFACE_PARAM or 0 = V_RPT_CONFIG.INTERFACE_PARAM) then V_NEED_EXEC := 1; end if; elsif (INTERFACE_TYPE_QUARTERLY = I_INTERFACE_TYPE) then if (I_EXTRA_PARAM = V_RPT_CONFIG.INTERFACE_PARAM or 0 = V_RPT_CONFIG.INTERFACE_PARAM) then V_NEED_EXEC := 1; end if; elsif (INTERFACE_TYPE_SEMIYEARLY = I_INTERFACE_TYPE) then if (I_EXTRA_PARAM = V_RPT_CONFIG.INTERFACE_PARAM or 0 = V_RPT_CONFIG.INTERFACE_PARAM) then V_NEED_EXEC := 1; end if; elsif (INTERFACE_TYPE_YEARLY = I_INTERFACE_TYPE) then if (I_EXTRA_PARAM = V_RPT_CONFIG.INTERFACE_PARAM or 0 = V_RPT_CONFIG.INTERFACE_PARAM) then V_NEED_EXEC := 1; end if; end if; --execute if (1 = V_NEED_EXEC and 1 = V_CONFIG_OK) then V_RESULT := F_EXECUTE_INTERFACE(trunc(I_PROCESS_DATE), I_RUN_ID, V_RPT_CONFIG ); if (V_RESULT = 1) then V_SUCC := V_SUCC + 1; else V_FAIL := V_FAIL + 1; end if; end if; END LOOP; if (V_FAIL > 0 and V_SUCC = 0) then return -1; --faild elsif (V_SUCC > 0 and V_FAIL > 0) then return 0; --partial else return 1; --succ end if; END F_INTERFACE_CALL; FUNCTION F_INTERFACE_CALL_S_R(I_PROCESS_DATE IN DATE, I_INTERFACE_TYPE IN NUMBER, I_RUN_ID IN NUMBER, I_EXTRA_PARAM IN NUMBER ) RETURN NUMBER is V_RPT_CONFIG T_RPT_INTERFACE_CONFIG%ROWTYPE; V_NEED_EXEC NUMBER; V_CONFIG_OK NUMBER; V_RESULT NUMBER := 0; V_SUCC NUMBER := 0; V_FAIL NUMBER := 0; BEGIN FOR V_RPT_CONFIG IN (SELECT * FROM T_RPT_INTERFACE_CONFIG WHERE INTERFACE_TYPE = I_INTERFACE_TYPE AND STATUS = 'Y' AND ID = 108 order by MODULE_PRIORITY, PRIORITY_IN_MODULE) LOOP V_CONFIG_OK := 1; V_NEED_EXEC := 0; --except monthly, are day of XX, so interface parameter is necessary if (INTERFACE_TYPE_MONTHLY != I_INTERFACE_TYPE and INTERFACE_TYPE_DAILY != I_INTERFACE_TYPE) then if (V_RPT_CONFIG.INTERFACE_PARAM is null) then V_CONFIG_OK := 0; --skip P_LOG_TRACE(V_RPT_CONFIG, I_PROCESS_DATE, I_RUN_ID, 'must set INTERFACE_PARAM for interface:' || I_INTERFACE_TYPE); COMMIT; end if; end if; --check if need execute if (INTERFACE_TYPE_DAILY = I_INTERFACE_TYPE) then V_NEED_EXEC := 1; elsif (INTERFACE_TYPE_WORKDAY = I_INTERFACE_TYPE) then if (I_EXTRA_PARAM = V_RPT_CONFIG.INTERFACE_PARAM or 0 = V_RPT_CONFIG.INTERFACE_PARAM) then V_NEED_EXEC := 1; end if; elsif (INTERFACE_TYPE_WEEKLY = I_INTERFACE_TYPE) THEN if (I_EXTRA_PARAM = V_RPT_CONFIG.INTERFACE_PARAM or 0 = V_RPT_CONFIG.INTERFACE_PARAM) then V_NEED_EXEC := 1; end if; if (V_NEED_EXEC = 0) then if (I_EXTRA_PARAM = 999 and V_RPT_CONFIG.INTERFACE_PARAM = 7) THEN V_NEED_EXEC := 1; END IF; end if; elsif (INTERFACE_TYPE_DAY_OF_MONTH = I_INTERFACE_TYPE) then if (I_EXTRA_PARAM = V_RPT_CONFIG.INTERFACE_PARAM or 0 = V_RPT_CONFIG.INTERFACE_PARAM) then V_NEED_EXEC := 1; end if; elsif (INTERFACE_TYPE_QUARTERLY = I_INTERFACE_TYPE) then if (I_EXTRA_PARAM = V_RPT_CONFIG.INTERFACE_PARAM or 0 = V_RPT_CONFIG.INTERFACE_PARAM) then V_NEED_EXEC := 1; end if; elsif (INTERFACE_TYPE_SEMIYEARLY = I_INTERFACE_TYPE) then if (I_EXTRA_PARAM = V_RPT_CONFIG.INTERFACE_PARAM or 0 = V_RPT_CONFIG.INTERFACE_PARAM) then V_NEED_EXEC := 1; end if; elsif (INTERFACE_TYPE_YEARLY = I_INTERFACE_TYPE) then if (I_EXTRA_PARAM = V_RPT_CONFIG.INTERFACE_PARAM or 0 = V_RPT_CONFIG.INTERFACE_PARAM) then V_NEED_EXEC := 1; end if; end if; --execute if (1 = V_NEED_EXEC and 1 = V_CONFIG_OK) then V_RESULT := F_EXECUTE_INTERFACE(trunc(I_PROCESS_DATE), I_RUN_ID, V_RPT_CONFIG ); if (V_RESULT = 1) then V_SUCC := V_SUCC + 1; else V_FAIL := V_FAIL + 1; end if; end if; END LOOP; if (V_FAIL > 0 and V_SUCC = 0) then return -1; --faild elsif (V_SUCC > 0 and V_FAIL > 0) then return 0; --partial else return 1; --succ end if; END F_INTERFACE_CALL_S_R; FUNCTION F_INTERFACE_CALL_OGIS(I_PROCESS_DATE IN DATE, I_INTERFACE_TYPE IN NUMBER, I_RUN_ID IN NUMBER, I_EXTRA_PARAM IN NUMBER ) RETURN NUMBER is V_RPT_CONFIG T_RPT_INTERFACE_CONFIG%ROWTYPE; V_NEED_EXEC NUMBER; V_CONFIG_OK NUMBER; V_RESULT NUMBER := 0; V_SUCC NUMBER := 0; V_FAIL NUMBER := 0; BEGIN FOR V_RPT_CONFIG IN (SELECT * FROM T_RPT_INTERFACE_CONFIG WHERE INTERFACE_TYPE = I_INTERFACE_TYPE AND STATUS = 'Y' AND ID = 10000 order by MODULE_PRIORITY, PRIORITY_IN_MODULE) LOOP V_CONFIG_OK := 1; V_NEED_EXEC := 0; --except monthly, are day of XX, so interface parameter is necessary if (INTERFACE_TYPE_MONTHLY != I_INTERFACE_TYPE and INTERFACE_TYPE_DAILY != I_INTERFACE_TYPE) then if (V_RPT_CONFIG.INTERFACE_PARAM is null) then V_CONFIG_OK := 0; --skip P_LOG_TRACE(V_RPT_CONFIG, I_PROCESS_DATE, I_RUN_ID, 'must set INTERFACE_PARAM for interface:' || I_INTERFACE_TYPE); COMMIT; end if; end if; --check if need execute if (INTERFACE_TYPE_DAILY = I_INTERFACE_TYPE) then V_NEED_EXEC := 1; elsif (INTERFACE_TYPE_WORKDAY = I_INTERFACE_TYPE) then if (I_EXTRA_PARAM = V_RPT_CONFIG.INTERFACE_PARAM or 0 = V_RPT_CONFIG.INTERFACE_PARAM) then V_NEED_EXEC := 1; end if; elsif (INTERFACE_TYPE_WEEKLY = I_INTERFACE_TYPE) THEN if (I_EXTRA_PARAM = V_RPT_CONFIG.INTERFACE_PARAM or 0 = V_RPT_CONFIG.INTERFACE_PARAM) then V_NEED_EXEC := 1; end if; if (V_NEED_EXEC = 0) then if (I_EXTRA_PARAM = 999 and V_RPT_CONFIG.INTERFACE_PARAM = 7) THEN V_NEED_EXEC := 1; END IF; end if; elsif (INTERFACE_TYPE_DAY_OF_MONTH = I_INTERFACE_TYPE) then if (I_EXTRA_PARAM = V_RPT_CONFIG.INTERFACE_PARAM or 0 = V_RPT_CONFIG.INTERFACE_PARAM) then V_NEED_EXEC := 1; end if; elsif (INTERFACE_TYPE_QUARTERLY = I_INTERFACE_TYPE) then if (I_EXTRA_PARAM = V_RPT_CONFIG.INTERFACE_PARAM or 0 = V_RPT_CONFIG.INTERFACE_PARAM) then V_NEED_EXEC := 1; end if; elsif (INTERFACE_TYPE_SEMIYEARLY = I_INTERFACE_TYPE) then if (I_EXTRA_PARAM = V_RPT_CONFIG.INTERFACE_PARAM or 0 = V_RPT_CONFIG.INTERFACE_PARAM) then V_NEED_EXEC := 1; end if; elsif (INTERFACE_TYPE_YEARLY = I_INTERFACE_TYPE) then if (I_EXTRA_PARAM = V_RPT_CONFIG.INTERFACE_PARAM or 0 = V_RPT_CONFIG.INTERFACE_PARAM) then V_NEED_EXEC := 1; end if; end if; --execute if (1 = V_NEED_EXEC and 1 = V_CONFIG_OK) then V_RESULT := F_EXECUTE_INTERFACE(trunc(I_PROCESS_DATE), I_RUN_ID, V_RPT_CONFIG ); if (V_RESULT = 1) then V_SUCC := V_SUCC + 1; else V_FAIL := V_FAIL + 1; end if; end if; END LOOP; if (V_FAIL > 0 and V_SUCC = 0) then return -1; --faild elsif (V_SUCC > 0 and V_FAIL > 0) then return 0; --partial else return 1; --succ end if; END F_INTERFACE_CALL_OGIS; END pkg_rpt_jewel; /