CREATE INDEX temp_tcbsid_IXU_TRANSACTION_HISTORY
ON IXU_TRANSACTION_HISTORY (TCBSID);
CREATE INDEX temp_tcbsid_IXU_GENERAL_LEDGER
ON IXU_GENERAL_LEDGER (TCBSID);
create procedure updateCurrentBalanceExactly(tcbsid_in IN varchar2, redeemablePoint_in IN number,
rankingPoint_in IN number) is
begin
update IXU_GENERAL_LEDGER
set RANKING_POINT = rankingPoint_in,
REDEEMABLE_POINT=redeemablePoint_in
where TCBSID = tcbsid_in;
-- caculate checksum here
-- commit;
end;
create procedure updateHistoryByID(id_in IN number, outstanding_in IN number) is
begin
update IXU_TRANSACTION_HISTORY
set OUTSTANDING = outstanding_in
where ID = id_in;
-- caculate checksum here
-- commit;
end;
create procedure arrangeHistoryByIssueDateAndGlIDExactly(tcbsid_in IN varchar2, award_type_in IN varchar2) is
initBalance number;
begin
initBalance = 0;
for txHistory in ( select ID, POINT, OUTSTANDING, ISSUED_DATE, AWARD_TYPE, ACTION
from IXU_TRANSACTION_HISTORY
where TCBSID = tcbsid_in
and AWARD_TYPE = award_type_in
order by ISSUED_DATE ASC, ID ASC)
loop
dbms_output.PUT_LINE(
'txRankHistory: id:' ||
txHistory.ID || '--' || txHistory.POINT || '--' || txHistory.OUTSTANDING || '--' ||
txHistory.ISSUED_DATE || '--' || txHistory.AWARD_TYPE);
if txHistory.ACTION = 'Credit' then
initBalance := initBalance + txHistory.POINT;
else
initBalance := initBalance - txHistory.POINT;
end if;
updateHistoryByID(txHistory.ID, initBalance);
end loop;
;
commit;
end;
create
procedure
verifyPointOutStandingByTcbsId(tcbsid_in IN varchar2)
is
sumOfCreditPointRedem number;
sumOfDebitPointRedem number;
resultRedem number;
currentBalanceRedem number;
sumOfCreditPointRank number;
sumOfDebitPointRank number;
resultRank number;
currentBalanceRank number;
begin
select sum(POINT)
into sumOfDebitPointRedem
from IXU_TRANSACTION_HISTORY
where ACTION = 'Debit'
and AWARD_TYPE = 'Redeemable'
and TCBSID = tcbsid_in;
select sum(POINT)
into sumOfDebitPointRank
from IXU_TRANSACTION_HISTORY
where ACTION = 'Debit'
and AWARD_TYPE = 'Ranking'
and TCBSID = tcbsid_in;
select sum(POINT)
into sumOfCreditPointRedem
from IXU_TRANSACTION_HISTORY
where ACTION = 'Credit'
and AWARD_TYPE = 'Redeemable'
and TCBSID = tcbsid_in;
select sum(POINT)
into sumOfCreditPointRank
from IXU_TRANSACTION_HISTORY
where ACTION = 'Credit'
and AWARD_TYPE = 'Ranking'
and TCBSID = tcbsid_in;
if sumOfDebitPointRedem is null then
sumOfDebitPointRedem := 0;
end if;
if sumOfDebitPointRank is null then
sumOfDebitPointRank := 0;
end if;
if sumOfCreditPointRedem is null then
sumOfCreditPointRedem := 0;
end if;
if sumOfCreditPointRank is null then
sumOfCreditPointRank := 0;
end if;
resultRedem := sumOfCreditPointRedem - sumOfDebitPointRedem;
resultRank := sumOfCreditPointRank - sumOfDebitPointRank;
SELECT (gl.REDEEMABLE_POINT)
into currentBalanceRedem
FROM IXU_GENERAL_LEDGER gl
where TCBSID = tcbsid_in;
SELECT (gl.RANKING_POINT)
into currentBalanceRank
FROM IXU_GENERAL_LEDGER gl
where TCBSID = tcbsid_in;
if currentBalanceRedem is null then
currentBalanceRedem := 0;
end if;
if currentBalanceRank is null then
currentBalanceRank := 0;
end if;
if currentBalanceRedem != resultRedem or currentBalanceRank != resultRank then
dbms_output.PUT_LINE(
'cbRedem: ' || currentBalanceRedem || '--' || 'resultRedem: ' || resultRedem || '==' ||
'cbRank: ' ||
currentBalanceRank || '--' || 'resultRank: ' || resultRank);
dbms_output.PUT_LINE('need check: ' || tcbsid_in);
updateCurrentBalanceExactly(tcbsid_in, resultRedem, resultRank);
arrangeHistoryByIssueDateAndGlIDExactly(tcbsid_in, 'Ranking');
arrangeHistoryByIssueDateAndGlIDExactly(tcbsid_in, 'Redeemable');
end if;
end;
BEGIN
FOR tx IN (
SELECT distinct TCBSID as tcbsid
FROM IXU_GENERAL_LEDGER
-- where TCBSID IN ( '0001907082')
)
LOOP
verifyPointOutStandingByTcbsId(tx.tcbsid);
END LOOP;
commit;
END;
Comments
Post a Comment