PROCEDURE UPDATE_RESOURCE_FATE AS
cursor resource_cur is
select trim(id) ID,
TRIM(organization_code) ORGANIZATION_CODE, --组织
TRIM(DEPT_CODE) DEPT_CODE, --部门
TRIM(RATE) RATE --费率
from CUX.UPDATE_RESOURCE_TEMP;
L_organization_id NUMBER := 0;
L_count NUMBER := 0;
V_ORG_COUNT NUMBER := 0;
E_CHECK EXCEPTION;
V_ERR_MESSAGE VARCHAR2(2000);
BEGIN
SELECT COUNT(DISTINCT CWI.ORGANIZATION_CODE)
INTO V_ORG_COUNT
FROM CUX.UPDATE_RESOURCE_TEMP CWI;
IF V_ORG_COUNT <> 1 THEN
V_ERR_MESSAGE := V_ERR_MESSAGE || '-导入数据只能是同个组织-';
RAISE E_CHECK;
END IF;
BEGIN
select mco.ORGANIZATION_ID
INTO L_organization_id
from meg_cux_org_v mco,CUX.UPDATE_RESOURCE_TEMP CWI
where mco.organization_code = cwi.ORGANIZATION_CODE
and rownum=1;
EXCEPTION
WHEN NO_DATA_FOUND THEN
insert into CUX_Blue_Gold
(A, B, c)
VALUES
('资源费率导入',
'组织不存在-',
to_char(sysdate, 'yyyy-mm-dd'));
commit;
V_ERR_MESSAGE := '组织不存在-';
RAISE E_CHECK;
END;
for resource_rec in resource_cur loop
BEGIN
select count(*)
into l_count
from BOM_RESOURCES
where substr(RESOURCE_CODE, 1, 3) = resource_rec.DEPT_CODE
and organization_id = L_organization_id;
EXCEPTION
WHEN NO_DATA_FOUND THEN
insert into CUX_Blue_Gold
(A, B, c)
VALUES
('资源费率导入',
'部门【' || resource_rec.DEPT_CODE || '】不存在-',
to_char(sysdate, 'yyyy-mm-dd'));
commit;
V_ERR_MESSAGE := '部门【' || resource_rec.DEPT_CODE || '】不存在-';
RAISE E_CHECK;
END;
insert into CUX_Blue_Gold
(A, B, c)
values( L_organization_id,resource_rec.DEPT_CODE,resource_rec.RATE);
update CST_RESOURCE_COSTS
set resource_rate = round(resource_rec.RATE,6)
where cost_type_id = 1001
and organization_id = L_organization_id
and resource_id in
(select resource_id
from BOM_RESOURCES
where substr(RESOURCE_CODE, 1, 3) = resource_rec.DEPT_CODE
and organization_id = L_organization_id);
end loop;
commit;
END UPDATE_RESOURCE_FATE;