南京邮电大学通达学院 许锦花 07003704
}
gpBillLog->Log(LOG_NORMAL, LOG_CODE_PCSTRANS , \#file_name:[%s] \\n\ if (!gbRunState) {
gpBillLog->Log(LOG_NORMAL, LOG_CODE_PCSTRANS , \\\n\
if (clRateFileDBIF.SetFileStateToWait()) { return false; }
if(!m_vFileProc.empty()) {
for(vector
strcpy(itor->sProcState, EVENT_SOURCE_FILE_STATE_WAIT); if (clRateFileDBIF.UpdateUnsettleRecInfo(&(*itor)))
{ }
this->gpDBBill->Commit();
this->gpDBBill->Rollback(); return false;
} }
return true; }
if (tPcsTransExecInfo.bMonitor) {
// 如果采用连接主控的方式处理,取处理命令
if (GetMonitorMessage(g_tExchangeMap, tPcsTransExecInfo) == GET_MONITOR_MSG_SUCCESS)
{
if (clRateFileDBIF.SetFileStateToWait()) { return false; } return true; } }
} //end of while // 判断是否取得退出信号 if (!gbRunState)
{
gpBillLog->Log(LOG_NORMAL, LOG_CODE_PCSTRANS , \quit signal! quit \\n\ return true; }
if (tPcsTransExecInfo.bMonitor) {
- 29 -
南京邮电大学通达学院 许锦花 07003704
// 如果采用连接主控的方式处理,取处理命令
if (GetMonitorMessage(g_tExchangeMap, tPcsTransExecInfo) == GET_MONITOR_MSG_SUCCESS) { return true; } }
if (CDR_RATE_GET_UNSETTLED_FILE_NONE == iRetDBIF) {
if( this->m_EventPcsInfo->GetBufferCount()>0)
{
if(!this->m_EventPcsInfo->PcsIntoDB(tPcsTransExecInfo)) {
for(vector
itor!=m_vFileProc.end(); itor++)
{
strcpy(itor->sProcState, EVENT_SOURCE_FILE_STATE_FAIL); if (clRateFileDBIF.UpdateUnsettleRecInfo(&(*itor)) != CDR_RATE_SUCCESS)
{ return false; } }
m_vFileProc.clear(); this->gpDBBill->Commit(); return false; } else
{
for(vector
itor!=m_vFileProc.end(); itor++) {
if (clRateFileDBIF.UpdateUnsettleRecInfo(&(*itor)) != CDR_RATE_SUCCESS)
{ return false; } }
m_vFileProc.clear();
this->gpDBBill->Commit(); } } else
{
for(vector
if (clRateFileDBIF.UpdateUnsettleRecInfo(&(*itor)) != CDR_RATE_SUCCESS)
- 30 -
南京邮电大学通达学院 许锦花 07003704
{ return false; } }
m_vFileProc.clear(); this->gpDBBill->Commit(); }
gpBillLog->Log(LOG_NORMAL, LOG_CODE_PCSTRANS , \tConfigInfo.iSleepSec);
sleep(tConfigInfo.iSleepSec); }
else if (CDR_RATE_SUCCESS != iRetDBIF) { return false; } } //end of first while(1) return true; }
4.3 一条话单的处理
4.3.1处理一条话单DealOneCdr()
bool TPcsTrans::DealOneCdr(TRateFileIOManager &clRateFileIOMan,TCdrEvent &tCdrEvent, TPcsTransExecInfo &tPcsTransExecInfo) {
int iRet = 0; //调用数据操作类转换函数完成事件属性的转换
if(!this->m_EventPcsInfo->Convert(tCdrEvent, tPcsTransExecInfo)) { return false; }
//往数据集合类里面插入数据
if(!m_EventPcsInfo->InsertPcsElement() || !m_EventPcsInfo->InsertPcsFeeElement()) { return false; } return true; }
4.3.2 入库结构的转换Convert()
bool TEventPcsInfo::Convert(TCdrEvent &tCdrEvent, TPcsTransExecInfo &tPcsTransExecInfo) {
// 清单表入库结构转换 int iattrId =0;
TEventAttr *pAttr = NULL;
pAttr = tCdrEvent.GetAttr(EA::EVENT_INS_ID);
if(!this->CheckAttr(pAttr,EA::EVENT_INS_ID)) { return false; }
m_EventPcs.event_inst_id = pAttr->AsInteger();
pAttr = tCdrEvent.GetAttr(EA::EVENT_TYPE_ID); if(!this->CheckAttr(pAttr,EA::EVENT_TYPE_ID))
{ return false; } m_EventPcs.event_type_id = pAttr->AsInteger(); //其他事件属性也是如此获得的,在此省略掉。
- 31 -
南京邮电大学通达学院 许锦花 07003704
// 费用表入库结构转换 Event_Pcs_Fee tmpPcsFee;
tmpPcsFee.event_inst_id = m_EventPcs.event_inst_id; tmpPcsFee.file_id = 0; //入库不生成文件
tmpPcsFee.acct_item_type_id = (int)GetAcctItemType(m_EventPcs.pcs_service_type); //取出事件对应的帐目类型
if(tmpPcsFee.acct_item_type_id == -1) //如果找不到帐目类型的,这个文件不能入库 { return false; }
tmpPcsFee.old_charge = tmpPcsFee.charge = tmp_float; tmpPcsFee.tariff_id = 0; //入库不批价 tmpPcsFee.tariff = 0; //目前没有费率
tmpPcsFee.rate_duration = m_EventPcs.duration; //数据源没有送过来,默认为实际时长 tmpPcsFee.cust_category = (double)m_EventPcs.cust_category; ve_EventPcsFee.push_back(tmpPcsFee);
//总帐表,入库结构转换
Acct_Item_Sd_Prepaypcs tmpPrepaypcs; tmpPrepaypcs.serv_id = m_EventPcs.serv_id;
tmpPrepaypcs.acct_item_type_id = tmpPcsFee.acct_item_type_id; //根据serv_id查找资料,来填充tmpPrepaypcs的相关字段,在这里略去 //查找帐务关系,并填充相关字段
if(this->m_bCurrent) //合到当前帐期
{
//查找acct_item_sd_prepaypcs内存hash中是否存在纪录
tmpPrepaypcs.billing_cycle_id = tPcsTransExecInfo.lBillingCycleID; tmpPrepaypcs.fee_cycle_id = tPcsTransExecInfo.lBillingCycleID; int iConn = 0;
iRet = SearchHashItem(m_phtSdCurrent, &tmpPrepaypcs, 3, &iConn, 1); if((iRet!=ERR_NO_ERR) && (iRet!=-1)) //出错
{ return false; }
else if(iRet==-1) //不存在纪录,对Insert容器进行操作
{
int iConn1 = 0;
//查看Insert容器是否已存在此纪录
int iTmp = SearchHashItem(m_phtSdInsertCurrent, &tmpPrepaypcs, 3, &iConn1, 1); if((iTmp!=ERR_NO_ERR) && (iTmp!=-1)) //出错 {
CloseHashConnect(m_phtSdCurrent, iConn); return false; }
else if(iTmp==-1) //Insert容器不存在此纪录 {
Acct_Item_Sd_Prepaypcs tmpPrepaypcs_bak; memcpy(&tmpPrepaypcs_bak, &tmpPrepaypcs, sizeof(Acct_Item_Sd_Prepaypcs));
- 32 -
南京邮电大学通达学院 许锦花 07003704
tmpPrepaypcs_bak.acct_item_id = m_acct_item_id_generator.Next(); tmpPrepaypcs_bak.charge = tmpPcsFee.charge;
strcpy(tmpPrepaypcs_bak.created_date, Time2Asc(time(NULL))); tmpPrepaypcs_bak.cust_category = tPcsTransExecInfo.iCustCategory; tmpPrepaypcs_bak.cust_id = m_EventPcs.cust_id; ???
strcpy(tmpPrepaypcs_bak.state, PREPAYPCS_EFF_STATE); strcpy(tmpPrepaypcs_bak.state_date, Time2Asc(time(NULL)));
tmpPrepaypcs_bak.unit_num++;
if(InsertHashItem(m_phtSdInsertCurrent, &tmpPrepaypcs_bak)!=ERR_NO_ERR) {
CloseHashConnect(m_phtSdInsertCurrent, iConn1); CloseHashConnect(m_phtSdCurrent, iConn); return false;
}
this->m_lSizeSdInsertCurrent++;
CloseHashConnect(m_phtSdInsertCurrent, iConn1); CloseHashConnect(m_phtSdCurrent, iConn);
m_vTmpSdInsertCurrent.push_back(tmpPrepaypcs_bak); }
else //Insert容器存在此纪录,需要合并 {
Acct_Item_Sd_Prepaypcs *p_find = NULL;
if( (GetHashNextItem(m_phtSdInsertCurrent,iConn1,(void **)&p_find)==ERR_NO_ERR) && (p_find!=NULL) )
{
p_find->charge += tmpPcsFee.charge; ????
p_find->rate_duration += m_EventPcs.duration; p_find->unit_num++; } else
{
CloseHashConnect(m_phtSdInsertCurrent, iConn1); CloseHashConnect(m_phtSdCurrent, iConn); return false; }
CloseHashConnect(m_phtSdInsertCurrent, iConn1); CloseHashConnect(m_phtSdCurrent, iConn); Acct_Item_Sd_Prepaypcs tmpPrepaypcs_bak; tmpPrepaypcs_bak.acct_id = p_find->acct_id; tmpPrepaypcs_bak.serv_id = p_find->serv_id; ???
tmpPrepaypcs_bak.rate_duration = m_EventPcs.duration; tmpPrepaypcs_bak.unit_num = 1;
- 33 -