desktop_task_schedule/code/db/pkg/telsale_archievement_pkg.pck

273 lines
9.5 KiB
Plaintext
Raw Normal View History

2023-03-10 09:32:13 +00:00
CREATE OR REPLACE PACKAGE telsale_archievement_pkg IS
-- Author : WANGWEI-202
-- Created : 2023/3/10 15:13:34
-- Purpose : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɰ<EFBFBD>
2023-05-18 07:40:04 +00:00
TYPE cur_type IS REF CURSOR;
2023-06-05 10:09:40 +00:00
-- <20>
DEPARTMENTCODE_EXCEPTION_CODE CONSTANT INTEGER := -20000;
2023-08-25 12:47:36 +00:00
DEPARTMENTCODE_EXCEPTION_MSG CONSTANT VARCHAR2(100) := '<27><><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>';
CALLERCODE_EXCEPTION_CODE CONSTANT INTEGER := -20001;
CALLERCODE_EXCEPTION_MSG CONSTANT VARCHAR2(100) := '<27><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>';
2023-06-05 10:09:40 +00:00
2023-05-15 12:06:17 +00:00
PROCEDURE department_archievement
2023-03-14 01:47:53 +00:00
(
2023-05-15 12:06:17 +00:00
a_department_code IN VARCHAR2,
a_attaching_rate OUT VARCHAR2,
2023-05-18 07:40:04 +00:00
a_renewal_rate OUT VARCHAR2,
2023-05-18 10:22:05 +00:00
a_total OUT INTEGER,
2023-05-18 07:40:04 +00:00
a_mensual_cur OUT cur_type
2023-03-14 01:47:53 +00:00
);
2023-08-25 12:47:36 +00:00
PROCEDURE caller_archievement
(
a_caller_code IN VARCHAR2,
a_attaching_rate OUT VARCHAR2,
a_renewal_rate OUT VARCHAR2,
a_total OUT INTEGER,
a_mensual_cur OUT cur_type
);
2023-06-02 10:04:26 +00:00
PROCEDURE caller_arch_ranking_list
(
2023-06-05 10:09:40 +00:00
a_department_code IN VARCHAR2,
a_year IN VARCHAR2,
a_month IN VARCHAR2,
a_attaching_ranking_list OUT cur_type,
a_renewal_ranking_list OUT cur_type
2023-06-02 10:04:26 +00:00
);
2023-03-10 09:32:13 +00:00
END telsale_archievement_pkg;
/
2023-08-25 12:47:36 +00:00
CREATE OR REPLACE PACKAGE BODY TELSALE_ARCHIEVEMENT_PKG IS
2023-07-27 13:43:56 +00:00
-- <20><><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5>
2023-08-25 12:47:36 +00:00
PROCEDURE DEPARTMENT_ARCHIEVEMENT
2023-03-14 01:47:53 +00:00
(
2023-08-25 12:47:36 +00:00
A_DEPARTMENT_CODE IN VARCHAR2,
A_ATTACHING_RATE OUT VARCHAR2,
A_RENEWAL_RATE OUT VARCHAR2,
A_TOTAL OUT INTEGER,
A_MENSUAL_CUR OUT CUR_TYPE
2023-03-14 01:47:53 +00:00
) IS
2023-08-25 12:47:36 +00:00
L_THIS_MONTH VARCHAR2(4);
L_THIS_YEAR VARCHAR2(4);
L_FIRSTDAY DATE;
L_DEPARTMENT_NAME VARCHAR2(100);
2023-03-14 01:47:53 +00:00
BEGIN
2023-08-25 12:47:36 +00:00
L_THIS_MONTH := TO_CHAR(SYSDATE,
2023-06-04 11:11:44 +00:00
'mm');
2023-08-25 12:47:36 +00:00
L_THIS_YEAR := TO_CHAR(SYSDATE,
2023-06-04 11:11:44 +00:00
'yyyy');
2023-08-25 12:47:36 +00:00
L_FIRSTDAY := TO_DATE(TO_CHAR(SYSDATE,
2023-06-04 11:11:44 +00:00
'yyyy') || '-01-01 00:00:00',
'yyyy-mm-dd hh24:mi:ss');
2023-06-05 10:09:40 +00:00
-- <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BEGIN
2023-08-25 12:47:36 +00:00
SELECT DEPARTMENT_NAME
INTO L_DEPARTMENT_NAME
FROM IDST0.BM_T BM
WHERE BM.DEPARTMENT_CODE = A_DEPARTMENT_CODE;
2023-06-05 10:09:40 +00:00
EXCEPTION
-- <20><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׳<EFBFBD><D7B3>
WHEN NO_DATA_FOUND THEN
2023-08-25 12:47:36 +00:00
RAISE_APPLICATION_ERROR(DEPARTMENTCODE_EXCEPTION_CODE,
2023-06-05 10:09:40 +00:00
DEPARTMENTCODE_EXCEPTION_MSG);
END;
2023-05-18 07:40:04 +00:00
--<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͸<EFBFBD><CDB8>
2023-08-25 12:47:36 +00:00
SELECT DECODE(SUM(CF.<2E><><EFBFBD>ո<EFBFBD><D5B8>˿ͻ<CBBF><CDBB><EFBFBD><EFBFBD><EFBFBD>),
2023-05-15 12:06:17 +00:00
0,
0,
2023-08-25 12:47:36 +00:00
ROUND((SUM(CF.<2E><><EFBFBD><EFBFBD><EFBFBD>ںϱ<DABA><CFB1><EFBFBD>) / SUM(CF.<2E><><EFBFBD>ո<EFBFBD><D5B8>˿ͻ<CBBF><CDBB><EFBFBD><EFBFBD><EFBFBD>) * 100),
2023-05-15 12:06:17 +00:00
2))
2023-08-25 12:47:36 +00:00
INTO A_ATTACHING_RATE
FROM <20><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD>ÿ<EFBFBD>ձ<EFBFBD><D5B1><EFBFBD> CF
WHERE CF.<2E>·<EFBFBD> = L_THIS_MONTH
AND CF.<2E><><EFBFBD><EFBFBD> = L_THIS_YEAR
AND <20><><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD> = A_DEPARTMENT_CODE;
2023-05-18 07:40:04 +00:00
--<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2023-08-25 12:47:36 +00:00
SELECT DECODE(SUM(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>),
2023-05-15 12:06:17 +00:00
0,
0,
2023-08-25 12:47:36 +00:00
ROUND(SUM(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼ<EFBFBD>) / SUM(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) * 100,
2023-05-15 12:06:17 +00:00
2))
2023-08-25 12:47:36 +00:00
INTO A_RENEWAL_RATE
2023-05-15 12:06:17 +00:00
FROM <20><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3>
2023-08-25 12:47:36 +00:00
WHERE <20><><EFBFBD><EFBFBD> = L_DEPARTMENT_NAME;
2023-05-18 07:40:04 +00:00
--<2D><>ҵ<EFBFBD><D2B5>
2023-08-25 12:47:36 +00:00
SELECT ROUND(NVL(SUM(CF.<2E><><EFBFBD>ո<EFBFBD><D5B8>˿ͻ<CBBF><CDBB><EFBFBD><EFBFBD><EFBFBD> + CF.<2E><><EFBFBD><EFBFBD><EFBFBD>ںϱ<DABA><CFB1><EFBFBD>),
2023-05-18 07:40:04 +00:00
0),
0)
2023-08-25 12:47:36 +00:00
INTO A_TOTAL
FROM <20><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD>ÿ<EFBFBD>ձ<EFBFBD><D5B1><EFBFBD> CF
WHERE <20><><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD> = A_DEPARTMENT_CODE
AND ǩ<><C7A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD> >= L_FIRSTDAY
AND ǩ<><C7A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <= SYSDATE;
--ÿ<><C3BF>ҵ<EFBFBD><D2B5>
OPEN A_MENSUAL_CUR FOR
SELECT CF.<2E>·<EFBFBD> MM,
ROUND(NVL(SUM(CF.<2E><><EFBFBD>ո<EFBFBD><D5B8>˿ͻ<CBBF><CDBB><EFBFBD><EFBFBD><EFBFBD> + CF.<2E><><EFBFBD><EFBFBD><EFBFBD>ںϱ<DABA><CFB1><EFBFBD>) / 10000,
0),
0) BF
FROM <20><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD>ÿ<EFBFBD>ձ<EFBFBD><D5B1><EFBFBD> CF
WHERE <20><><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD> = A_DEPARTMENT_CODE
AND ǩ<><C7A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD> >= TO_DATE(TO_CHAR(SYSDATE,
'yyyy') || '-01-01 00:00:00',
'yyyy-mm-dd hh24:mi:ss')
AND ǩ<><C7A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD> < TO_DATE(TO_CHAR(SYSDATE,
'yyyy-mm') || '-01 00:00:00',
'yyyy-mm-dd hh24:mi:ss')
GROUP BY CF.<2E>·<EFBFBD>
ORDER BY CF.<2E>·<EFBFBD>;
END;
/*******************************************************/
-- <20><>ϯҵ<CFAF><D2B5>
PROCEDURE caller_archievement
(
a_caller_code IN VARCHAR2,
a_attaching_rate OUT VARCHAR2,
a_renewal_rate OUT VARCHAR2,
a_total OUT INTEGER,
a_mensual_cur OUT cur_type
) IS
l_caller_name VARCHAR2(100);
l_this_month VARCHAR2(4);
l_this_year VARCHAR2(4);
l_firstday DATE;
BEGIN
--<2D><>ѯ<EFBFBD><D1AF>ϯ<EFBFBD><CFAF><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD>
BEGIN
SELECT saler_name
INTO l_caller_name
FROM tele_saler
WHERE saler_code = a_caller_code;
EXCEPTION
-- <20><><EFBFBD><EFBFBD>û<EFBFBD>в<EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>ϯ<EFBFBD><CFAF><EFBFBD>ƣ<EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׳<EFBFBD><D7B3>
WHEN no_data_found THEN
raise_application_error(CALLERCODE_EXCEPTION_CODE,
CALLERCODE_EXCEPTION_MSG);
END;
l_this_month := to_char(SYSDATE,
'mm');
l_this_year := to_char(SYSDATE,
'yyyy');
l_firstday := to_date(l_this_year || '-01-01 00:00:00',
'yyyy-mm-dd hh24:mi:ss');
--<2D>ܳ<EFBFBD><DCB3>ձ<EFBFBD><D5B1><EFBFBD>
2023-08-25 14:47:25 +00:00
SELECT round(nvl(SUM(cf.<2E><><EFBFBD>ո<EFBFBD><D5B8>˿ͻ<CBBF><CDBB><EFBFBD><EFBFBD><EFBFBD>),
0),
2023-08-25 12:47:36 +00:00
2) bf
2023-05-18 07:40:04 +00:00
INTO a_total
2023-06-04 11:11:44 +00:00
FROM <20><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD>ÿ<EFBFBD>ձ<EFBFBD><D5B1><EFBFBD> cf
2023-08-25 12:47:36 +00:00
WHERE cf.<2E><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD> = a_caller_code
AND cf.<2E><><EFBFBD><EFBFBD> = l_this_year;
--<2D><>͸<EFBFBD><CDB8>
2023-08-25 14:47:25 +00:00
SELECT decode(nvl(SUM(cf.<2E><><EFBFBD>ո<EFBFBD><D5B8>˿ͻ<CBBF><CDBB><EFBFBD><EFBFBD><EFBFBD>),
0),
2023-08-25 12:47:36 +00:00
0,
0,
round(SUM(cf.<2E><><EFBFBD><EFBFBD><EFBFBD>ںϱ<DABA><CFB1><EFBFBD>) / SUM(cf.<2E><><EFBFBD>ո<EFBFBD><D5B8>˿ͻ<CBBF><CDBB><EFBFBD><EFBFBD><EFBFBD>) * 100,
2))
INTO a_attaching_rate
FROM <20><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD>ÿ<EFBFBD>ձ<EFBFBD><D5B1><EFBFBD> cf
WHERE cf.<2E><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD> = a_caller_code
AND cf.<2E><><EFBFBD><EFBFBD> = l_this_year
AND cf.<2E>·<EFBFBD> = l_this_month;
--<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2023-08-25 14:47:25 +00:00
SELECT decode(nvl(SUM(xb.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>),
0),
2023-08-25 12:47:36 +00:00
0,
0,
round(SUM(xb.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼ<EFBFBD>) / SUM(xb.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) * 100,
2)) xbl
INTO a_renewal_rate
FROM <20><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3> xb
WHERE xb.<2E><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD> = a_caller_code;
2023-05-18 07:40:04 +00:00
--ÿ<><C3BF>ҵ<EFBFBD><D2B5>
2023-08-25 12:47:36 +00:00
OPEN A_MENSUAL_CUR FOR
SELECT CF.<2E>·<EFBFBD> MM,
2023-08-26 11:26:13 +00:00
ROUND(NVL(SUM(CF.<2E><><EFBFBD>ո<EFBFBD><D5B8>˿ͻ<CBBF><CDBB><EFBFBD><EFBFBD><EFBFBD> + CF.<2E><><EFBFBD><EFBFBD><EFBFBD>ںϱ<DABA><CFB1><EFBFBD>),
2023-05-18 07:40:04 +00:00
0),
2023-08-25 12:47:36 +00:00
0) BF
FROM <20><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD>ÿ<EFBFBD>ձ<EFBFBD><D5B1><EFBFBD> CF
WHERE cf.<2E><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD> = a_caller_code
AND ǩ<><C7A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD> >= TO_DATE(TO_CHAR(SYSDATE,
2023-05-18 07:40:04 +00:00
'yyyy') || '-01-01 00:00:00',
'yyyy-mm-dd hh24:mi:ss')
2023-09-05 10:37:41 +00:00
AND ǩ<><C7A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <= SYSDATE
2023-08-25 12:47:36 +00:00
GROUP BY CF.<2E>·<EFBFBD>
ORDER BY CF.<2E>·<EFBFBD>;
2023-04-04 09:58:05 +00:00
END;
2023-06-05 10:09:40 +00:00
/*******************************************************/
-- <20><>ϯ<EFBFBD><CFAF><EFBFBD>а<EFBFBD>
2023-08-25 12:47:36 +00:00
PROCEDURE CALLER_ARCH_RANKING_LIST
2023-06-02 10:04:26 +00:00
(
2023-08-25 12:47:36 +00:00
A_DEPARTMENT_CODE IN VARCHAR2,
A_YEAR IN VARCHAR2,
A_MONTH IN VARCHAR2,
A_ATTACHING_RANKING_LIST OUT CUR_TYPE,
A_RENEWAL_RANKING_LIST OUT CUR_TYPE
2023-06-02 10:04:26 +00:00
) IS
2023-08-25 12:47:36 +00:00
L_DEPARTMENT_NAME VARCHAR2(100);
2023-06-02 10:04:26 +00:00
BEGIN
2023-06-05 10:09:40 +00:00
-- <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BEGIN
2023-08-25 12:47:36 +00:00
SELECT DEPARTMENT_NAME
INTO L_DEPARTMENT_NAME
FROM IDST0.BM_T BM
WHERE BM.DEPARTMENT_CODE = A_DEPARTMENT_CODE;
2023-06-05 10:09:40 +00:00
EXCEPTION
-- <20><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׳<EFBFBD><D7B3>
WHEN NO_DATA_FOUND THEN
2023-08-25 12:47:36 +00:00
RAISE_APPLICATION_ERROR(DEPARTMENTCODE_EXCEPTION_CODE,
2023-06-05 10:09:40 +00:00
DEPARTMENTCODE_EXCEPTION_MSG);
END;
2023-08-25 12:47:36 +00:00
-- <20><><EFBFBD><EFBFBD><EFBFBD>ں<EFBFBD><DABA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>а<EFBFBD>
OPEN A_ATTACHING_RANKING_LIST FOR
SELECT ROWNUM,
<20><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD> AS CALLER_NAME,
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͸<EFBFBD><CDB8> AS ATTACHING_RATE
2023-07-30 14:12:14 +00:00
FROM (SELECT <20><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD>,
2023-08-25 14:47:25 +00:00
ROUND(DECODE(nvl(SUM(<28><><EFBFBD>ո<EFBFBD><D5B8>˿ͻ<CBBF><CDBB><EFBFBD><EFBFBD><EFBFBD>),
0),
2023-07-30 14:12:14 +00:00
0,
0,
(SUM(<28><><EFBFBD><EFBFBD><EFBFBD>ںϱ<DABA><CFB1><EFBFBD>) / SUM(<28><><EFBFBD>ո<EFBFBD><D5B8>˿ͻ<CBBF><CDBB><EFBFBD><EFBFBD><EFBFBD>)) * 100),
2) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͸<EFBFBD><CDB8>
FROM <20><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD>ÿ<EFBFBD>ձ<EFBFBD><D5B1><EFBFBD>
2023-08-25 12:47:36 +00:00
WHERE <20>·<EFBFBD> = A_MONTH
AND <20><><EFBFBD><EFBFBD> = A_YEAR
AND <20><><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD> = A_DEPARTMENT_CODE
2023-07-30 14:12:14 +00:00
GROUP BY <20><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD>
ORDER BY <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͸<EFBFBD><CDB8> DESC);
2023-06-05 10:09:40 +00:00
-- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>а<EFBFBD>
2023-08-25 12:47:36 +00:00
OPEN A_RENEWAL_RANKING_LIST FOR
SELECT ROWNUM,
<20><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD> AS CALLER_NAME,
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> AS RENEWAL_RATE
2023-07-30 14:12:14 +00:00
FROM (SELECT <20><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD>,
2023-08-25 14:47:25 +00:00
decode(nvl(SUM(xb.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>),
0),
0,
0,
round(SUM(xb.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼ<EFBFBD>) / SUM(xb.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) * 100,
2)) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2023-08-25 12:47:36 +00:00
FROM <20><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3> XB
WHERE XB.<2E><><EFBFBD><EFBFBD> = L_DEPARTMENT_NAME
2023-07-30 14:12:14 +00:00
GROUP BY <20><>ϯ<EFBFBD><CFAF><EFBFBD><EFBFBD>
ORDER BY <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> DESC);
2023-06-02 10:04:26 +00:00
END;
2023-03-10 09:32:13 +00:00
BEGIN
NULL;
2023-08-25 12:47:36 +00:00
END TELSALE_ARCHIEVEMENT_PKG;
2023-03-10 09:32:13 +00:00
/