⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cdrcombination.cpp

📁 Mysql的处理
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		//ClearGCdrMap();		//delete this;		//exit(0);//		WriteCombinedGCdrErrorInfoToFile("SaveCdr:Connect failed");//		return 0;//	}	int i = 0;	int SortId = 0;	//volume of each big CDR	int comb_vol = pCg->CauseForRecClosing.size();	//if ( comb_vol >= S_CGCDR_C::GCDRCG_NUM_LIMIT_OF_COMBINED)	if ( comb_vol > S_CGCDR_C::GCDRCG_NUM_LIMIT_OF_COMBINED)	{		//comb_vol = S_CGCDR_C::GCDRCG_NUM_LIMIT_OF_COMBINED;		//cdr.Disconnect();		return 0;	}		for(int icfrc = 0; icfrc < comb_vol; icfrc++)	{//		if( pCg->CauseForRecClosing[icfrc] == CAUSE_SGSNCHANGE_SORTING)//			pCg->CauseForRecClosing[icfrc] = CAUSE_SGSNCHANGE_REAL;		if((NULL != &(pCg->CauseForRecClosing))&&	   		(NULL != &(pCg->CauseForRecClosing[icfrc])))		{			if( pCg->CauseForRecClosing[icfrc] == CAUSE_SGSNCHANGE_SORTING)				pCg->CauseForRecClosing[icfrc] = CAUSE_SGSNCHANGE_REAL;		}	}	int sgsn_vol = pCg->SGSNIPAddress.size();	//if ( sgsn_vol >= S_CGCDR_C::GCDRCG_NUM_LIMIT_OF_COMBINED)	if ( sgsn_vol > S_CGCDR_C::GCDRCG_NUM_LIMIT_OF_COMBINED)	{		//sgsn_vol = S_CGCDR_C::GCDRCG_NUM_LIMIT_OF_COMBINED;		//cdr.Disconnect();		return 0;	}	//count of LCOMM in big CDR//	int size_lcomm = (COMBINATION_FIELD_NUM-1) * comb_vol + 1 + sgsn_vol;	//int size_lcomm = (COMBINATION_FIELD_NUM-1) * comb_vol + 2 + sgsn_vol;//volume of RSN & LRSN is one bigger than that of CFRC	//(-2) in (COMBINATION_FIELD_NUM-2) is for SGSNAddr and RecordExtensions	//(+2) is for two GGSN address	//(+1) is for "ExtensionType" and "ContentInfoLength" of RecordExtension	//int size_contentInfo = comb_vol * NUM_OF_CONTENT_INFO_NODE;	int size_contentInfo = pCg->ContentInfo.size();	pCg->ContentInfoLength = size_contentInfo*SIZE_S_CONTENT_INFO_C;	int size_lcomm = (COMBINATION_FIELD_NUM-2) * comb_vol + 			  2 + 			  sgsn_vol +			  1 +			  size_contentInfo;//volume of RSN & LRSN is one bigger than that of CFRC	//printf("\n\size_lcomm is :%d\n\n", size_lcomm);				//allocate memory 	S_CGCDR *pS_cgcdr = new S_CGCDR;	memset(pS_cgcdr,0x00,sizeof(S_CGCDR));	sprintf(pS_cgcdr->SeqId, "%d", m_serialNumForSerId);	//memcpy(pS_cgcdr->SeqId, "2006", strlen("2006"));	S_LCOMM *p_lcomm = new S_LCOMM[size_lcomm];//?S_LCOMM *p_lcomm = new S_LCOMM[comb_vol];	memset(p_lcomm,0x00,sizeof(S_LCOMM)*size_lcomm);	for (int i = 0; i < size_lcomm; i++)	{		//memcpy(p_lcomm[i].SeqId, "2006", strlen("2006"));		sprintf(p_lcomm[i].SeqId, "%d", m_serialNumForSerId);	}	S_LCOMM *p_lcomm_old=p_lcomm;		//set values for S_LLOTV	int size_llotv = comb_vol * NUM_OF_VOL_NODE;	S_LLOTV *p_llotv = new S_LLOTV[size_llotv];	for(int iv = 0; iv < size_llotv; iv++)	{		memcpy(p_llotv+iv, &(pCg->ListOfTrafficDataVolumes[iv]), SIZE_S_LLOTV);	}	printf("%d\n", __LINE__);	if (IsSortedRecSeqNumContinuous(pCg->SortedRecSeqNum))	{		printf("%d\n", __LINE__);		ComputerTotalDurationForSortedRecSeqNum(pCg);	}	//set values for S_CGCDR & S_LCOMM	memcpy(pS_cgcdr, pCg, sizeof(S_CGCDR_C_COMMON));	memcpy(pS_cgcdr->ChargingCharacteristics, pCg->ChargingCharacteristics, sizeof(pS_cgcdr->ChargingCharacteristics));	pS_cgcdr->AnonyAccessIndicator=pCg->AnonyAccessIndicator;	memcpy(pS_cgcdr->RemotePdpAddr,pCg->RemotePdpAddr,		sizeof(pS_cgcdr->RemotePdpAddr));	pS_cgcdr->FlagR499=0;	pS_cgcdr->FlagRepeat=0;	int j = 0;	//note that volume might differ between big CDRs	comb_vol = pCg->CauseForRecClosing.size();	//fprintf(fptr2,"comb_vol:%d\n",comb_vol);	//fill out L_COMM	for(j=0;j<sgsn_vol;j++) {		//fprintf(fptr2,"comb sgsn:%s\n",pCg->SGSNIPAddress[j].c_str());		memcpy(p_lcomm->SGSNAddr,pCg->SGSNIPAddress[j].c_str(),sizeof(p_lcomm->SGSNAddr));		p_lcomm->SubId=0;		sprintf(p_lcomm->SortId, "%d", SortId);		SortId++;		p_lcomm++;		//printf("p_lcomm->SGSNAddr is : %s\n", p_lcomm->SGSNAddr);	}	//fprintf(fptr2,"memcpy CauseForRecordClosing\n");	for(j=0;j<comb_vol;j++) {		//p_lcomm = p_lcomm_old;?		memcpy(p_lcomm->CauseForRecordClosing,pCg->CauseForRecClosing[j].c_str(),sizeof(p_lcomm->CauseForRecordClosing));		p_lcomm->SubId=1;		sprintf(p_lcomm->SortId, "%d", SortId);		SortId++;		p_lcomm++;		//printf("\n\nNum of CauseForRecordClosing combined is :%d\n\n", j);		//printf("p_lcomm->CauseForRecordClosing is : %s\n", p_lcomm->CauseForRecordClosing);	}	//fprintf(fptr2,"memcpy RecordSequenceNumber\n");	if( ! pCg->RecordSequenceNumber.empty() )	{		if ((NULL != &(pCg->RecordSequenceNumber))&&		    (NULL != &(pCg->RecordSequenceNumber[0])))		{			memcpy(p_lcomm->SGSNAddr,pCg->RecordSequenceNumber[0].c_str(),sizeof(p_lcomm->SGSNAddr));		}		else		{			memcpy(p_lcomm->SGSNAddr, "192.168.0.1", sizeof(p_lcomm->SGSNAddr));		}		p_lcomm->SubId=12;		sprintf(p_lcomm->SortId, "%d", SortId);		SortId++;		p_lcomm++;		for(j=1;j<comb_vol+1;j++) {			//p_lcomm = p_lcomm_old;?			memcpy(p_lcomm->RSN, pCg->RecordSequenceNumber[j].c_str(), sizeof(p_lcomm->RSN));			p_lcomm->SubId=2;			sprintf(p_lcomm->SortId, "%d", SortId);			SortId++;			p_lcomm++;			//printf("p_lcomm->RSN is : %s\n", p_lcomm->RSN);		}	}	//fprintf(fptr2,"memcpy LocalRecordSequeceNumnber\n");	if( ! pCg->LocalRecordSequeceNumnber.empty() )	{		if ((NULL != &(pCg->LocalRecordSequeceNumnber))&&		    (NULL != &(pCg->LocalRecordSequeceNumnber[0])))		{			memcpy(p_lcomm->SGSNAddr,pCg->LocalRecordSequeceNumnber[0].c_str(),sizeof(p_lcomm->SGSNAddr));		}		else		{			memcpy(p_lcomm->SGSNAddr, "192.168.0.1", sizeof(p_lcomm->SGSNAddr));		}		p_lcomm->SubId=13;//Use SGSNAddr to record GGSN		sprintf(p_lcomm->SortId, "%d", SortId);		SortId++;		p_lcomm++;		for(j=1;j<comb_vol+1;j++) {			//p_lcomm = p_lcomm_old;?			memcpy(p_lcomm->LRSN, pCg->LocalRecordSequeceNumnber[j].c_str(), sizeof(p_lcomm->LRSN));			p_lcomm->SubId=3;			sprintf(p_lcomm->SortId, "%d", SortId);			SortId++;			p_lcomm++;			//printf("p_lcomm->LRSN is : %s\n", p_lcomm->LRSN);		}	}	//fprintf(fptr2,"memcpy RecordExtensions\n");	/* Record Extensions信息的赋值 */	sprintf(p_lcomm->RSN, "%d", pCg->ExtensionType);	sprintf(p_lcomm->LRSN, "%d", pCg->ContentInfoLength);	p_lcomm->SubId = 10;//Use SGSNAddr to record GGSN	sprintf(p_lcomm->SortId, "%d", SortId);	SortId++;	p_lcomm++;	for(j = 0; j < size_contentInfo; j++) {		//p_lcomm = p_lcomm_old;?		sprintf(p_lcomm->NodeId, "%d", pCg->ContentInfo[j].ServiceCode);		sprintf(p_lcomm->RSN, "%d", pCg->ContentInfo[j].UpVolume);		sprintf(p_lcomm->LRSN, "%d", pCg->ContentInfo[j].DownVolume);		p_lcomm->RNC = pCg->ContentInfo[j].UsageDuration;		memcpy(p_lcomm->RecordExtensions, 		       pCg->ContentInfo[j].Url, 		       sizeof(p_lcomm->RecordExtensions));		p_lcomm->SubId = 11;		sprintf(p_lcomm->SortId, "%d", SortId);		SortId++;		p_lcomm++;	}	/*for(j=0;j<comb_vol;j++) {		//p_lcomm = p_lcomm_old;?		memcpy(p_lcomm->RecordExtensions,pCg->RecordExtensions[j].c_str(),sizeof(p_lcomm->RecordExtensions));		p_lcomm->SubId=8;		p_lcomm++;		//printf("p_lcomm->RecordExtensions is : %s\n", p_lcomm->RecordExtensions);	}*/	//fprintf(fptr2,"finished memcpy\n");	//还需要增加两种对DURATION的处理	//1.REC SEQ NUM连续:需要在话单进行合并时按序保存REC SEQ NUM、REC OPEN TIME和DURATION	//作为判断是否连续的依据和计算TOTAL DURATION的数据来源	//2.REC SEQ NUM不连续则取原来的数值	/* 修改结束:不定长列表需要增加RECORD SEQ NUM的赋值 */		char pOutSzTableDate[10];	char pOutSzSeqId[21];	C_CDRWriteCombined *pCDRWriteCombined = new C_CDRWriteCombined;	//fprintf(fptr2, "size_lcomm:%d\n", size_lcomm);	cout<<"Combined Cdr:"<<endl;	cout<<"ggsnaddr:"<<pS_cgcdr->GGSNAddress<<endl;	cout<<"ChargingID:"<<pS_cgcdr->ChargingID<<endl;	//cout<<"SGSNIPAddress:"<<pS_cgcdr->SGSNIPAddress<<endl;	cout<<"CallDuration:"<<pS_cgcdr->CallDuration<<endl;	cout<<"RecordOpenTime:"<<pS_cgcdr->RecordOpenTime<<endl;	cout<<endl;		//insert big CDR into db//	bool bSuccess = pCDRWriteCombined->InsertGCDR(pS_cgcdr,1,NULL,0,NULL,0,	//	p_lcomm_old,size_lcomm,1,pOutSzTableDate,pOutSzSeqId);	//C_GCdrCombination::OUTPUT_OR_NOT = "true";	if("true" == C_GCdrCombination::OUTPUT_OR_NOT)	{		WriteCombinedGCdrToFile(pS_cgcdr,					p_llotv,					size_llotv,					p_lcomm_old,					sgsn_vol,					comb_vol,					size_contentInfo,					pCg->SortedRecSeqNum);	}			bool bSuccess = pCDRWriteCombined->InsertGCDR(pS_cgcdr,1,NULL,0,p_llotv,size_llotv,		p_lcomm_old,size_lcomm,1,pOutSzTableDate,pOutSzSeqId);		//TODO: update original table	for(int i=0;i<comb_vol;i++)	{		string sUpdateSql;		sUpdateSql.append("UPDATE ").append(pCg->TableName[i]).append(" SET ")			.append("mergeid='").append(pS_cgcdr->SeqId).append("',mergetable='")			.append(pS_cgcdr->TableName).append("' WHERE ").append("SeqId='").append(pCg->SeqId[i]).append("'");			//.append("mergeid='").append(pS_cgcdr->MergeId).append("',mergetable='")			//.append(pS_cgcdr->MergeName).append("' WHERE ").append("SeqId='").append(pCg->SeqId[i]).append("'");		cout<<"update sql:"<<sUpdateSql<<endl;		//g_cdr.Update(sUpdateSql.c_str());		string sUpdateSql1;		sUpdateSql1.append("UPDATE ").append(pCg->TableName[i]).append(" SET ")			.append("flagread=").append("2").append(" where seqid='")			.append(pCg->SeqId[i]).append("'");		cout<<"update sql:"<<sUpdateSql1<<endl;		//g_cdr.Update(sUpdateSql1.c_str());	}	m_serialNumForSerId++;		if ( MAX_SEQ_ID == m_serialNumForSerId)	{		m_serialNumForSerId = 0;	}		if (NULL != pS_cgcdr)	{		delete pS_cgcdr;		pS_cgcdr = NULL;	}	if (NULL != pCDRWriteCombined)	{		delete pCDRWriteCombined;		pCDRWriteCombined = NULL;	}		delete [] p_lcomm;	//delete pCDRWriteCombined;	delete [] p_llotv;		//cdr.Disconnect();	//fprintf(fptr2, "disconnect\n");		return 1;}/*  * Append the record extension info to the combined cdr *//*void C_CdrCombination::RecordExtensionInfo(vector<string>& cdrCg_RecExtInfo,					   const char *cdr_RecExtInfo){	cdrCg_RecExtInfo.push_back(cdr_RecExtInfo);}*/void C_CdrCombination::RecordExtensionInfo(vector<S_CONTENT_INFO_C>& cdrCg_ContentInfo,					   const S_CONTENT_INFO_C& cdr_ContentInfo){	int size_contentInfo = cdrCg_ContentInfo.size();	bool bFindSameServiceCode = false;	int iPositionOfSameServiceCode = 0;		/* 在VACTOR中寻找有无相同的ServiceCode */	for(iPositionOfSameServiceCode = 0; 	    iPositionOfSameServiceCode < size_contentInfo; 	    iPositionOfSameServiceCode++)		{		if (cdrCg_ContentInfo[iPositionOfSameServiceCode].ServiceCode == cdr_ContentInfo.ServiceCode)		{			bFindSameServiceCode = true;			break ;		}	}		if (true == bFindSameServiceCode)	{		/* 1、如果业务编码相同,则进行上、下行流量和UsageDuration的累加 */		cdrCg_ContentInfo[iPositionOfSameServiceCode].UpVolume += cdr_ContentInfo.UpVolume;		cdrCg_ContentInfo[iPositionOfSameServiceCode].DownVolume += cdr_ContentInfo.DownVolume;		cdrCg_ContentInfo[iPositionOfSameServiceCode].UsageDuration += cdr_ContentInfo.UsageDuration;	}	else	{		/* 2、如果业务编码不同,则进行链表的累加 */		cdrCg_ContentInfo.push_back(cdr_ContentInfo);	}}/* * Append the record sequence number to the combined cdr */void C_CdrCombination::RecordRecSeqNumToList(deque<string>& cdrCg_RecSeqNum,											 const char *cdr_RecSeqNum){	cdrCg_RecSeqNum.push_back(cdr_RecSeqNum);	//cout<<"cdr_RecSeqNum:"<<cdr_RecSeqNum<<endl;	copy(cdrCg_RecSeqNum.begin(),cdrCg_RecSeqNum.end(),ostream_iterator<string>(cout," "));}/* * Append the local record sequence number to the combined cdr */void C_CdrCombination::RecordLocRecSeqNumToList(deque<string>& deque_CdrCg_LocRecSeqNum,												const char *cdr_LocRecSeqNum){	deque_CdrCg_LocRecSeqNum.push_back(cdr_LocRecSeqNum);}int C_CdrCombination::RecordDuration(){	return 1;}/* * Append the list of traffic data to the combined cdr */void C_GCdrCombination::RecordListOfTrafficDataToList(vector<S_LLOTV>& vector_cdrCg_ListOfTrafficDataVol, 	const S_LLOTV& cdr_ListOfTrafficDataVol){	vector_cdrCg_ListOfTrafficDataVol.push_back(cdr_ListOfTrafficDataVol);}//Cause for record closing: Normal releaseconst string C_GCdrCombination::CAUSE_FOR_CLOSING_NORMAL_RELEASE = "0";//Cause for record closing: Partial recordconst string C_GCdrCombination::CAUSE_FOR_CLOSING_PARTIAL_RECORD = "1";/* * Add cause for record closing to the result. * N.B., the result is required to be ordered. * To perform the operation:  * first insert the item into the result; * then sort the result with a binary predicate. */void C_GCdrCombination::RecordCauseForRecClosingToList(vector<string>& vector_cdrCg_CauseForRecClosing,							 //char *cdr_CauseForRecClosing)							 const char *cdr_CauseForRecClosing){			printf("%d\n", __LINE__);	printf("aaa");		char pCFRC[LEN_OF_CAUSE_FOR_REC_CLOSING+1];	printf("%d\n", __LINE__);	memset(pCFRC, 0, sizeof(pCFRC));	printf("%d\n", __LINE__);	if ((NULL == cdr_CauseForRecClosing)||	(0 == strcmp(cdr_CauseForRecClosing, "")))	{	printf("%d\n", __LINE__);		memcpy(pCFRC, "4", sizeof(pCFRC));	}	//precedence: PDP type, SGSN change, partial record	//replace SGSN change to some value bigger than PDP type, less than partial record.	//in this way, sorting can be performed easily.	//NOTE: before inserting to DB, replace SGSNCHANGE back to the real value.	else	{		//pCFRC = cdr_CauseForRecClosing;	printf("%d\n", __LINE__);		memcpy(pCFRC, cdr_CauseForRecClosing, sizeof(pCFRC));	printf("%d\n", __LINE__);		if ( strcmp(CAUSE_SGS

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -