// Copyright (c) 2007,联创科技股份有限公司电信事业部
// All rights reserved.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include "ProdOfferAggr.h"
#include "Value.h"
#include "InterfaceProdAggr.h"
#include "Timesten_Env.h"
ProdOfferAggrAttach::ProdOfferAggrAttach()//Attach
{
}
void ProdOfferAggrAttach::FreeProdOfferAggrShm()
{
}
void ProdOfferAggrAttach::ProdOfferAggrReset()
{}
ProdOfferDisctAggr::ProdOfferDisctAggr():ProdOfferAggrAttach()
{}
ProdOfferDisctAggr::~ProdOfferDisctAggr()
{
}
//modify by linbt@linkage 2009.04.10
void ProdOfferDisctAggr::doProdOfferDisct(ProdOfferTotalData * poAcctItem, vector<ProdOfferAggrData> &v_ProdOfferAggr, vector<ProdOfferDetailDataEx> &v_ProdOfferDetailData)
{
long lItemDisctSeq = 0,lAcctDisctSeq = 0,lAggrHoldSeq = 0,lValue = 0,lInCharge = 0;
long lDisctValue = 0,lOutCharge = 0,lChangeFee = 0,lDisctHoldSeq = 0;
ProdOfferAggrData aProdOfferAggrData;
ProdOfferDetailDataEx aProdOfferDetailData;
static DEFINE_TTCMD( qry1);
static DEFINE_TTCMD( qry2);
static DEFINE_TTCMD( qry3);
static DEFINE_TTCMD( selectAggrData);
static DEFINE_TTCMD( selectAggrDataHold);
static DEFINE_TTCMD( insertAggrData);
static DEFINE_TTCMD( insertAggrDataHold);
static DEFINE_TTCMD( updateAggrDateHold);
static DEFINE_TTCMD( updateAggrDateHoldEx);
static DEFINE_TTCMD( selectDetailData);
static DEFINE_TTCMD( selectDetailDataHold);
static DEFINE_TTCMD( insertDetailData);
static DEFINE_TTCMD( insertDetailHold);
static DEFINE_TTCMD( updateDetailHold);
static DEFINE_TTCMD( updateDetailHoldEx);
selectAggrData.Prepare(
"SELECT ITEM_DISCT_SEQ,VALUE,DISCT_VALUE FROM OCS_ACCT_DISCT_AGGR WHERE OFFER_INST_ID=:OFFER_INST_ID AND \
BILLING_CYCLE_ID=:BILLING_CYCLE_ID AND PRICING_COMBINE_ID=:PRICING_COMBINE_ID AND MEASURE_SEQ=:MEASURE_SEQ \
AND ITEM_GROUP_ID=:ITEM_GROUP_ID AND OWNER_TYPE=:OWNER_TYPE AND OWNER_ID=:OWNER_ID");
selectAggrData.setParam(1, poAcctItem->m_lProdOfferID);
selectAggrData.setParam(2, poAcctItem->m_iBillingCycleID);
selectAggrData.setParam(3, poAcctItem->m_iProdOfferCombine);
selectAggrData.setParam(4, poAcctItem->m_iPricingMeasure);
selectAggrData.setParam(5, poAcctItem->m_iItemGroupID);
selectAggrData.setParam(6, poAcctItem->m_iInType);
selectAggrData.setParam(7, poAcctItem->m_lInValue);
selectAggrData.Execute();
if (selectAggrData.FetchNext())
{
aProdOfferAggrData.m_lProdOfferID = poAcctItem->m_lProdOfferID;
aProdOfferAggrData.m_iBillingCycleID = poAcctItem->m_iBillingCycleID;
aProdOfferAggrData.m_iProdOfferCombine = poAcctItem->m_iProdOfferCombine;
aProdOfferAggrData.m_iPricingMeasure = poAcctItem->m_iPricingMeasure;
aProdOfferAggrData.m_iItemGroupID = poAcctItem->m_iItemGroupID;
aProdOfferAggrData.m_iInType = poAcctItem->m_iInType;
aProdOfferAggrData.m_lInValue = poAcctItem->m_lInValue;
aProdOfferDetailData.m_lServID = poAcctItem->m_lServID;
aProdOfferDetailData.m_iAcctItemTypeID = poAcctItem->m_iAcctItemTypeID;
aProdOfferDetailData.m_lOfferInstID = poAcctItem->m_lProdOfferID;
qry2.Prepare("SELECT ITEM_DISCT_SEQ.NEXTVAL FROM DUAL");
qry2.Execute();
if (!qry2.FetchNext())
{
qry2.getColumn(1, &lItemDisctSeq);
}
insertAggrData.Prepare(
"INSERT INTO OCS_ACCT_DISCT_AGGR(ITEM_DISCT_SEQ,OFFER_INST_ID,BILLING_CYCLE_ID,PRICING_COMBINE_ID,MEASURE_SEQ,ITEM_GROUP_ID,OWNER_TYPE,OWNER_ID,VALUE,DISCT_VALUE) \
VALUES(:ITEM_DISCT_SEQ,:OFFER_INST_ID,:BILLING_CYCLE_ID,:PRICING_COMBINE_ID,:MEASURE_SEQ,:ITEM_GROUP_ID,:OWNER_TYPE,:OWNER_ID,:VALUE,:DISCT_VALUE)");
insertAggrData.setParam(1, lItemDisctSeq);
insertAggrData.setParam(2, aProdOfferAggrData.m_lProdOfferID);
insertAggrData.setParam(3, aProdOfferAggrData.m_iBillingCycleID);
insertAggrData.setParam(4, aProdOfferAggrData.m_iProdOfferCombine);
insertAggrData.setParam(5, aProdOfferAggrData.m_iPricingMeasure);
insertAggrData.setParam(6, aProdOfferAggrData.m_iItemGroupID);
insertAggrData.setParam(7, aProdOfferAggrData.m_iInType);
insertAggrData.setParam(8, aProdOfferAggrData.m_lInValue);
aProdOfferAggrData.m_iValue = 0;
aProdOfferAggrData.m_iDisctValue = 0;
insertAggrData.setParam(9, aProdOfferAggrData.m_iValue);
insertAggrData.setParam(10, aProdOfferAggrData.m_iDisctValue);
insertAggrData.Execute();
insertAggrDataHold.Prepare(
"INSERT INTO OCS_ACCT_DISCT_AGGR_HOLD(AGGR_HOLD_SEQ,SESSION_ID,NUMBER_FLAG,ITEM_DISCT_SEQ,OFFER_INST_ID,BILLING_CYCLE_ID,PRICING_COMBINE_ID, \
MEASURE_SEQ,ITEM_GROUP_ID,OWNER_TYPE,OWNER_ID,VALUE,DISCT_VALUE) VALUES(AGGR_HOLD_SEQ.NEXTVAL,:SESSION_ID,:NUMBER_FLAG,:ITEM_DISCT_SEQ,\
:OFFER_INST_ID,:BILLING_CYCLE_ID,:PRICING_COMBINE_ID,:MEASURE_SEQ,:ITEM_GROUP_ID,:OWNER_TYPE,:OWNER_ID,:VALUE,:DISCT_VALUE)");
insertAggrDataHold.setParam(1, m_interface_prodaggr.s_sSessionID.c_str());
insertAggrDataHold.setParam(2, m_interface_prodaggr.s_iNumberFlag);
insertAggrDataHold.setParam(3, lItemDisctSeq);
insertAggrDataHold.setParam(4, aProdOfferAggrData.m_lProdOfferID);
insertAggrDataHold.setParam(5, aProdOfferAggrData.m_iBillingCycleID);
insertAggrDataHold.setParam(6, aProdOfferAggrData.m_iProdOfferCombine);
insertAggrDataHold.setParam(7, aProdOfferAggrData.m_iPricingMeasure);
insertAggrDataHold.setParam(8, aProdOfferAggrData.m_iItemGroupID);
insertAggrDataHold.setParam(9, aProdOfferAggrData.m_iInType);
insertAggrDataHold.setParam(10, aProdOfferAggrData.m_lInValue);
if (poAcctItem->m_bInOutType == true)
{
aProdOfferAggrData.m_iValue = poAcctItem->m_iValue;
aProdOfferAggrData.m_iDisctValue = 0;
insertAggrDataHold.setParam(11, aProdOfferAggrData.m_iValue);
insertAggrDataHold.setParam(12, aProdOfferAggrData.m_iDisctValue);
}
else
{
aProdOfferAggrData.m_iValue = 0;
aProdOfferAggrData.m_iDisctValue = poAcctItem->m_iValue;
insertAggrDataHold.setParam(11, aProdOfferAggrData.m_iValue);
insertAggrDataHold.setParam(12, aProdOfferAggrData.m_iDisctValue);
}
insertAggrDataHold.Execute();
qry3.Prepare("SELECT ACCT_DISCT_SEQ.NEXTVAL FROM DUAL");
qry3.Execute();
if (!qry3.FetchNext())
{
qry3.getColumn(1, &lAcctDisctSeq);
}
insertDetailData.Prepare("INSERT INTO OCS_ACCT_DISCT(ACCT_DISCT_SEQ,ITEM_DISCT_SEQ,SERV_ID,ACCT_ITEM_TYPE_ID,IN_CHARGE,OUT_CHARGE) \
VALUES(:ACCT_DISCT_SEQ,:ITEM_DISCT_SEQ,:SERV_ID,:ACCT_ITEM_TYPE_ID,:IN_CHARGE,:OUT_CHARGE)");
insertDetailData.setParam(1, lAcctDisctSeq);
insertDetailData.setParam(2, lItemDisctSeq);
insertDetailData.setParam(3, aProdOfferDetailData.m_lServID);
insertDetailData.setParam(4, aProdOfferDetailData.m_iAcctItemTypeID);
aProdOfferDetailData.m_iInCharge = 0;
aProdOfferDetailData.m_iOutCharge = 0;
insertDetailData.setParam(5, aProdOfferDetailData.m_iInCharge);
insertDetailData.setParam(6, aProdOfferDetailData.m_iOutCharge);
insertDetailData.Execute();
insertDetailHold.Prepare(
"INSERT INTO OCS_ACCT_DISCT_HOLD(DISCT_HOLD_SEQ,ACCT_DISCT_SEQ,SESSION_ID,NUMBER_FLAG,ITEM_DISCT_SEQ,SERV_ID,ACCT_ITEM_TYPE_ID,IN_CHARGE,OUT_CHARGE) \
VALUES(DISCT_HOLD_SEQ.NEXTVAL,:ACCT_DISCT_SEQ,:SESSION_ID,:NUMBER_FLAG,:ITEM_DISCT_SEQ,:SERV_ID,:ACCT_ITEM_TYPE_ID,:IN_CHARGE,:OUT_CHARGE)");
insertDetailHold.setParam(1, lAcctDisctSeq);
insertDetailHold.setParam(2, m_interface_prodaggr.s_sSessionID.c_str());
insertDetailHold.setParam(3, m_interface_prodaggr.s_iNumberFlag);
insertDetailHold.setParam(4, lItemDisctSeq);
insertDetailHold.setParam(5, aProdOfferDetailData.m_lServID);
insertDetailHold.setParam(6, aProdOfferDetailData.m_iAcctItemTypeID);
if (poAcctItem->m_bInOutType == true)
{
aProdOfferDetailData.m_iInCharge = poAcctItem->m_iValue;
aProdOfferDetailData.m_iOutCharge = 0;
insertDetailHold.setParam(7, aProdOfferDetailData.m_iInCharge);
insertDetailHold.setParam(8, aProdOfferDetailData.m_iOutCharge);
}
else
{
aProdOfferDetailData.m_iInCharge = 0;
aProdOfferDetailData.m_iOutCharge = poAcctItem->m_iValue;
insertDetailHold.setParam(