📄 preuser.cc
字号:
/****************************preuser.cc***************************** * 文件类型: .cc * 功 能: 用户资料预处理 * 开发平台: Sun OS 2.6 , C++ 3.3 * 编 者: 郭世强 * 完成日期: 2004-04-1 * 修改日期: 2004-08-20 *******************************************************************/ #include "preuser.hpp"TMap mapFileDir;TMap mapAcct1;TCustMap mapCust1;TServAcct1Map mapServAcct1;TServProd1Map mapServProd1;int main(int argc, char* argv[]){ time_t start, end; if (argc < 2) { cout << "Please input config file name!\n"; return -1; } if(GetInfoBySection(argv[1], "[file_dir]", mapFileDir) < 0) return -1; #ifdef _SERV_PROCESS_FLAG rlogit(PREUSER_ERR(1000), "serv info process."); // serv信息预处理 preServInfo(); #endif #ifdef _CUST_PROCESS_FLAG rlogit(PREUSER_ERR(1000), "cust info process."); // cust信息预处理 preCustInfo(); #endif #ifdef _ACCT_PROCESS_FLAG rlogit(PREUSER_ERR(1000), "acct info process."); // acct信息预处理 preAcctInfo(); #endif #ifdef _SERV_ACCT_PROCESS_FLAG rlogit(PREUSER_ERR(1000), "serv_acct info process."); // serv_acct信息预处理 preServAcctInfo(); #endif #ifdef _SERV_PROD_PROCESS_FLAG rlogit(PREUSER_ERR(1000), "serv_prod info process."); // serv_prod信息预处理 preServProdInfo(); #endif return 0;}// serv信息预处理void preServInfo(){ char strBuff[LINE_MAX_LEN]; char *strLine; FILE *streamIn, *streamErr, *streamOut, *streamTemp, *streamExtOut; TSet setDup; TServMap mapServ; TServMapit mapIt; int seq_nbr, old_seq_nbr; time_t start, end; int iLineNo; // 打开用户资料文件 streamIn = fopen64(mapFileDir["serv_in"].c_str(), "r"); if (streamIn == NULL) { rlogit(PREUSER_ERR(-5), "Could not open file [%s].", mapFileDir["serv_in"].c_str()); exit(-1); } // 打开错单文件 streamErr = fopen(mapFileDir["serv_err"].c_str(), "w"); if (streamErr == NULL) { rlogit(PREUSER_ERR(-6), "Could not open file [%s].", mapFileDir["serv_err"].c_str()); exit(-1); } iLineNo = 0; time(&start); // 读用户资料文件 while(!feof(streamIn)) { memset(strBuff, 0, LINE_MAX_LEN); iLineNo++; if(fgets(strBuff, LINE_MAX_LEN, streamIn) == NULL) if(strlen(strBuff) == LINE_MAX_LEN - 1) { fclose(streamIn); fclose(streamErr); rlogit(PREUSER_ERR(-7), "file [%s] line [%d] is too long.", mapFileDir["serv_in"].c_str(), iLineNo); return; } strLine = trim(strBuff); if(strlen(strLine) == 0) continue; if( judgeError(strLine, 1) == 0 ) { // 查重 setDup.insert(TSettype(strLine)); } else { // 写错单文件 fprintf(streamErr, "%s\n", strLine); fflush(streamErr); } } fclose(streamIn); fclose(streamErr); time(&end); rlogit(PREUSER_ERR(1000), "serv check dup and correct error [%d] use time [%d].", iLineNo, end - start); time(&start); streamTemp = fopen64(mapFileDir["serv_temp"].c_str(), "w"); if (streamTemp == NULL) { rlogit(PREUSER_ERR(-12), "Could not open file [%s].", mapFileDir["serv_temp"].c_str()); return; } // 写入临时文件 for(TSetit it = setDup.begin(); it != setDup.end(); it++) { fprintf(streamTemp, "%s\n", (*it).c_str()); fflush(streamTemp); } fclose(streamTemp); time(&end); rlogit(PREUSER_ERR(1000), "serv write temp file [%d] use time [%d].", setDup.size(), end - start); setDup.clear(); // 用户资料过滤 time(&start); streamTemp = fopen64(mapFileDir["serv_temp"].c_str(), "r"); if (streamTemp == NULL) { rlogit(PREUSER_ERR(-12), "Could not open file [%s].", mapFileDir["serv_temp"].c_str()); return; } iLineNo = 0; while(!feof(streamTemp)) { memset(strBuff, 0, LINE_MAX_LEN); iLineNo++; if(fgets(strBuff, LINE_MAX_LEN, streamIn) == NULL) if(strlen(strBuff) == LINE_MAX_LEN - 1) { fclose(streamTemp); cout << "file [" << mapFileDir["serv_temp"] << "] line " << iLineNo << " is too long" << endl; return; } strLine = trim(strBuff); if(strlen(strLine) == 0) continue; // 获取用户信息 TVector serv; getServInfo(strLine, serv); // 在用户信息表中查找 mapIt = mapServ.find(serv[SERV_SERV_ID_POS]); if( mapIt != mapServ.end() ) { // 已经存在此用户信息 seq_nbr = atoi(serv[SERV_SEQ_NBR_POS].c_str()); old_seq_nbr = atoi(mapIt->second[SERV_SEQ_NBR_POS].c_str()); // 比较序列号,将最大的插入用户结构中 if (seq_nbr > old_seq_nbr) { mapServ.erase(mapIt); mapServ.insert(TServMaptype(serv[SERV_SERV_ID_POS], serv)); } } else { // 无此用户信息 mapServ.insert(TServMaptype(serv[SERV_SERV_ID_POS], serv)); } } fclose(streamTemp); // 删除临时文件 string strCommand; strCommand.append("rm -f ").append(mapFileDir["serv_temp"]); if(system(strCommand.c_str()) != 0) { cout << "delete temp file [" << mapFileDir["serv_temp"] << "] error." << endl; return; } time(&end); rlogit(PREUSER_ERR(1000), "serv filter [%d] use time [%d].", iLineNo, end - start); // 装载帐务关系信息 loadServAcctInfo(); // 装载占用资源信息 loadServProdInfo(); // 装载帐户信息 loadAcctInfo(); // 装载客户信息 loadCustInfo(); // 打开用户资料输出文件 streamOut = fopen64(mapFileDir["serv_out"].c_str(), "w"); if (streamOut == NULL) { rlogit(PREUSER_ERR(-8), "Could not open file [%s].", mapFileDir["serv_out"].c_str()); exit(-1); } // 打开扩充后的用户资料输出文件 streamExtOut = fopen64(mapFileDir["serv_ext_out"].c_str(), "w"); if (streamOut == NULL) { rlogit(PREUSER_ERR(-8), "Could not open file [%s].", mapFileDir["serv_ext_out"].c_str()); exit(-1); } time(&start); // 将纠错、查重、过滤后的用户资料保存到文件中 for(TServMapit it = mapServ.begin(); it != mapServ.end(); it++) { // 查找帐务关系 TServAcct1Mapit itServAcct; itServAcct = mapServAcct1.find(it->first); if( itServAcct != mapServAcct1.end() ) { it->second.push_back(TVecType(itServAcct->second.acct_id)); } else { // 写入错单文件(找不到对应的帐务关系) string strServ; for(TVecIt vecIt = it->second.begin(); vecIt != it->second.end(); vecIt++) { strServ.append(*vecIt).append("|"); } writeErrorInfo(strServ, "can't found serv_acct info!"); continue; } // 查找帐户信息 TMapit itAcct; itAcct = mapAcct1.find(it->second[SERV_ACCT_ID_POS]); if( itAcct != mapAcct1.end() ) { // 插入acct_name it->second.push_back(TVecType(itAcct->second)); } else { // 写入错单文件(找不到对应的帐户信息) string strServ; for(TVecIt vecIt = it->second.begin(); vecIt != it->second.end(); vecIt++) { strServ.append(*vecIt).append("|"); } writeErrorInfo(strServ, "can't found acct info!"); continue; } // 查找占用资源 TServProd1Mapit itServProd; itServProd = mapServProd1.find(it->first); if( itServProd != mapServProd1.end() ) { it->second.push_back(TVecType(itServProd->second.product_id)); it->second.push_back(TVecType(itServProd->second.product_quantity)); } else { // 写入错单文件(找不到对应的占用资源) it->second.push_back(TVecType("-99")); it->second.push_back(TVecType("0")); } // 查找客户信息 TCustMapit itCust; itCust = mapCust1.find(it->second[SERV_CUST_ID_POS]); if( itCust != mapCust1.end() ) { it->second.push_back(TVecType(itCust->second[CUST_CUST_NAME_1_POS])); it->second.push_back(TVecType(itCust->second[CUST_TYPE_ID_1_POS])); it->second.push_back(TVecType(itCust->second[CUST_VIP_FLAG_1_POS])); it->second.push_back(TVecType(itCust->second[CUST_STATE_1_POS])); } else { // 写入错单文件(找不到对应的客户信息) string strServ; for(TVecIt vecIt = it->second.begin(); vecIt != it->second.end(); vecIt++) { strServ.append(*vecIt).append("|"); } writeErrorInfo(strServ, "can't found cust info!"); continue; } // 写扩充后的用户资料表 string strServTemp; for(TVecIt vecIt = it->second.begin(); vecIt != it->second.end(); vecIt++) { strServTemp.append(*vecIt).append("|"); } fprintf(streamExtOut, "%s\n", strServTemp.c_str()); fflush(streamExtOut); //写账目及清单表需要的用户资料文件 char strTemp[FILTER_LINE_LEN]; memset(strTemp, 0, sizeof(strTemp)); snprintf(strTemp, FILTER_LINE_LEN, "%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|", it->second[SERV_SERV_ID_POS].c_str(), it->second[SERV_ACC_NBR_POS].c_str(), it->second[SERV_CUST_GROUP_ID_POS].c_str(), it->second[SERV_EXCHANGE_ID_POS].c_str(), it->second[SERV_AREA_ID_POS].c_str(), it->second[SERV_EXCHANGE_97_POS].c_str(), it->second[SERV_TYPE_ID_POS].c_str(), it->second[SERV_BILLING_TYPE_ID_POS].c_str(), it->second[SERV_VIP_FLAG_POS].c_str(), it->second[SERV_CUST_ID_POS].c_str(), it->second[SERV_LATN_ID_POS].c_str(), it->second[SERV_OCCUPATION_ID_POS].c_str(), it->second[SERV_PROPERTY_ID_POS].c_str(), it->second[SERV_BILLING_FLAG_ID_POS].c_str(), it->second[SERV_CREATED_DATE_POS].c_str(), it->second[SERV_ACCT_ID_POS].c_str(), it->second[SERV_STATE_POS].c_str()); fprintf(streamOut, "%s\n", strTemp); fflush(streamOut); } fclose(streamOut); fclose(streamExtOut); mapServ.clear(); mapAcct1.clear(); mapServAcct1.clear(); mapServProd1.clear(); time(&end); rlogit(PREUSER_ERR(1000), "serv write [%d] use time [%d].", iLineNo, end - start); rlogit(PREUSER_ERR(1000), "用户资料预处理完成.");}// cust信息预处理void preCustInfo(){ static const char* func = "preCustInfo"; char strBuff[LINE_MAX_LEN]; char *strLine; FILE *streamIn, *streamErr, *streamOut, *streamSrcOut; TSet setDup; TCustMap mapCust; TCustMapit mapIt; int seq_nbr, old_seq_nbr; int iLineNo; time_t start, end; // 打开客户资料文件 streamIn = fopen64(mapFileDir["cust_in"].c_str(), "r"); if (streamIn == NULL) { rlogit(PREUSER_ERR(-9), "Could not open file [%s].", mapFileDir["cust_in"].c_str()); exit(-1); } // 打开错单文件 streamErr = fopen(mapFileDir["cust_err"].c_str(), "w"); if (streamErr == NULL) { rlogit(PREUSER_ERR(-10), "Could not open file [%s].", mapFileDir["cust_err"].c_str()); exit(-1); } iLineNo = 0; time(&start); // 读客户资料文件 while(!feof(streamIn)) { memset(strBuff, 0, LINE_MAX_LEN); iLineNo++; if(fgets(strBuff, LINE_MAX_LEN, streamIn) == NULL) continue; if(strlen(strBuff) == LINE_MAX_LEN - 1) { fclose(streamIn); fclose(streamErr); rlogit(PREUSER_ERR(-11), "file [%s] line [%d] is too long.", mapFileDir["cust_in"].c_str(), iLineNo); return; } strLine = trim(strBuff); if(strlen(strLine) == 0) continue; if( judgeError(strLine, 2) == 0 ) { // 查重 setDup.insert(TSettype(strLine)); } else { // 写错单文件 fprintf(streamErr, "%s\n", strLine); fflush(streamErr); } } fclose(streamIn); fclose(streamErr); time(&end); rlogit(PREUSER_ERR(1000), "cust check dup and correct error [%d] use time [%d].", iLineNo, end - start); time(&start); // 客户资料过滤 for(TSetit it = setDup.begin(); it != setDup.end(); it++) { TVector cust; // 获取客户信息 getCustInfo(*it, cust); // 在客户信息表中查找 mapIt = mapCust.find(cust[CUST_CUST_ID_POS]); if( mapIt != mapCust.end() ) { // 已经存在此客户信息 seq_nbr = atoi(cust[CUST_SEQ_NBR_POS].c_str()); old_seq_nbr = atoi(mapIt->second[CUST_SEQ_NBR_POS].c_str()); // 比较序列号,将最大的插入客户结构中 if (seq_nbr > old_seq_nbr) { mapCust.erase(mapIt); mapCust.insert(TCustMaptype(cust[CUST_CUST_ID_POS], cust)); } } else { // 无此客户信息 mapCust.insert(TCustMaptype(cust[CUST_CUST_ID_POS], cust)); } } setDup.clear(); time(&end); rlogit(PREUSER_ERR(1000), "cust filter [%d] use time [%d].", iLineNo, end - start); time(&start); // 打开客户资料输出文件 streamOut = fopen64(mapFileDir["cust_out"].c_str(), "w"); if (streamOut == NULL) { rlogit(PREUSER_ERR(-12), "Could not open file [%s].", mapFileDir["cust_out"].c_str()); return; } // 打开客户资料原始数据输出文件 streamSrcOut = fopen64(mapFileDir["cust_src_out"].c_str(), "w"); if (streamOut == NULL) { rlogit(PREUSER_ERR(-12), "Could not open file [%s].", mapFileDir["cust_src_out"].c_str()); return; } // 将纠错、查重、过滤后的客户资料保存到文件中 for(TCustMapit it = mapCust.begin(); it != mapCust.end(); it++) { // 写扩充后的客户资料表 string strCustTemp; for(TVecIt vecIt = it->second.begin(); vecIt != it->second.end(); vecIt++) { strCustTemp.append(*vecIt).append("|"); } fprintf(streamSrcOut, "%s\n", strCustTemp.c_str()); fflush(streamSrcOut); char strTemp[FILTER_LINE_LEN]; memset(strTemp, 0, sizeof(strTemp)); snprintf(strTemp, FILTER_LINE_LEN, "%s|%s|%s|%s|%s|", it->second[CUST_CUST_ID_POS].c_str(), it->second[CUST_CUST_NAME_POS].c_str(), it->second[CUST_TYPE_ID_POS].c_str(), it->second[CUST_VIP_FLAG_POS].c_str(), it->second[CUST_STATE_POS].c_str()); fprintf(streamOut, "%s\n", strTemp); fflush(streamOut); } fclose(streamSrcOut); fclose(streamOut); mapCust.clear();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -