// SynThirdMgr.cpp: implementation of the CSynThirdMgr class.
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Construction/Destruction //
CSynThirdMgr::CSynThirdMgr()
CSynThirdMgr::~CSynThirdMgr()
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
bool CSynThirdMgr::prepare()
if(m_ConnectPool.Connect(m_strTnsName)==1)
sprintf(pstrResMsg,(char *)"数据库连接成功!");
writeStatuslog(m_nProType,"0",0,pstrResMsg);
cerr<< pstrResMsg <<endl;
sprintf(pstrResMsg,(char *)"数据库连接失败!!!");
writeErrlog(m_nProType,"0",0,pstrResMsg);
cerr<< pstrResMsg <<endl;
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void CSynThirdMgr::finish()
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
DWORD WINAPI ReadDataProc(LPVOID lpParamter)
CSynThirdMgr *pCSynThirdMgr=(CSynThirdMgr*)lpParamter;
/*if(0==m_ConnectPool.ReadData(
lckID)) /// the second param is groupid
if(0==pCSynThirdMgr->m_ConnectPool.ReadData(pCSynThirdMgr->m_strRealFile,pCSynThirdMgr->m_pfile,pCSynThirdMgr->m_strUserLabelTable,pCSynThirdMgr->m_nFlag,pCSynThirdMgr->m_n64ID))
//cout<<"数据写入成功,文件名"<<szFileName<<endl;
cout<<"手机字段:"<<pCSynThirdMgr->m_nFlag<<"\t写入成功"<<endl;
cerr << "DB Exception!!!" << endl;
//pCSynThirdMgr->writeErrlog(pCSynThirdMgr->m_nProType,pCSynThirdMgr->m_n64ID,0,"DB Exception!!!");
void CSynThirdMgr::handle()
char szFilePath[512]={0};
char szFileName[128]={0};
char szDealedLine[16]={0};
char szOldFullName[1024]={0};
char szNewFullName[1024]={0};
//char szFileRealName[256]={0}; ///file name will be writed
long lDownNum=0;
///need to bedown
struct tm *localTimeBeg=NULL;
struct tm *localTimeEnd=NULL;
//std::ofstream *pfile=new ofstream(); ///a point to file
cerr <<"Program Running"<< endl;
//int nRet = m_ConnectPool.GetDownLoadFile(m_strPlatForm,m_strSrcTable,szID,szFilePath,szFileName,szDealedLine,m_nProType,m_nTotNumer);
bool bRet=m_ConnectPool.bckDownLoadData(m_strCkTable,szStatue,&lReadLine,&lckID);
localTimeBeg=localtime(&tm_beg);
strftime(str_timeBeg, sizeof(str_timeBeg), "%Y-%m-%d,%H:%M:%S", localTimeBeg);
//文件名格式 userlabel_YYYYMMDD24HHMISS+.txt
strftime( szTimeNow, sizeof(szTimeNow), "%Y%m%d%H%M%S",localtime(&t) );
sprintf(szFileName,"userlabel_%s.txt",szTimeNow);
sprintf(m_strRealFile,"%s\\%s",m_strSucFilePath,szFileName);/// 成功文件路径
//pfile->open(m_strRealFile,ios_base::in|ios_base::app);
mMutex=CreateMutex(NULL,FALSE,NULL);
m_pfile->open(m_strRealFile,ios_base::in|ios_base::app);
//for(int nFlag=lReadLine;nFlag<=99;nFlag++)
//
cout<<"**********\r\n"<<nFlag<<"\r\n**********"<<endl;
strftime( szTimeNow, sizeof(szTimeNow), "%Y%m%d%H%M%S",localtime(&t) );
sprintf(szFileName,"userlabel_%s.txt",szTimeNow);
sprintf(m_strRealFile,"%s\\%s",m_strSucFilePath,szFileName);/// 成功文件路径
//vfile.open(szFileRealName,ios_base::in|ios_base::app);
//if file no exit create,others append the data
/*pfile->open(m_strRealFile,ios_base::in|ios_base::app);*/
cout<<"open file error!"<<endl;
writeErrlog(m_nProType,szID,0,"Open File error!");
thread1=CreateThread(NULL,0,ReadDataProc,NULL,0,NULL);
thread2=CreateThread(NULL,0,ReadDataProc,NULL,0,NULL);
if(0==m_ConnectPool.ReadData(
lckID)) /// the second param is groupid
//cout<<"数据写入成功,文件名"<<szFileName<<endl;
cout<<"手机字段:"<<nFlag<<"\t写入成功"<<endl;
cerr << "DB Exception!!!" << endl;
writeErrlog(m_nProType,szID,0,"DB Exception!!!");
localTimeEnd=localtime(&tm_end);
//无论之前的时间取值是多少。在这里如果开始、结束连在一起的话可就没有时间差了
strftime(str_timeEnd, sizeof(str_timeEnd), "%Y-%m-%d,%H:%M:%S", localTimeEnd);
printf("***\nbegin_time:%s\t end_time:%s\n***\n",str_timeBeg,str_timeEnd);
result=difftime(tm_end,tm_beg);
printf("********\n耗费时间:%f 秒\n***********\n",result);
sprintf(szLogBuf,"数据写入文件完成,最后一个文件名:%s",szFileName);
writeStatuslog(m_nProType,szID,0,szLogBuf);
//
cerr << "Finish or DB Exception!!!" << endl;
//
writeErrlog(m_nProType,szID,0,"DB Exception!!!");
cout<<"Finish!!!\r\n"<<endl;
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
int CSynThirdMgr::initialize(int argc,char* argv[])
char strCfgFileName[512];
if(strcmp(argv[1],"-stop") == 0 && argc == 3)
strcpy(strCfgFileName, argv[2]);
else if(strcmp(argv[1],"-start") == 0 && argc == 4)
strcpy(strCfgFileName, argv[3]);
cerr << "missing parameter" << endl;
if( m_cConfigFile.Open(strCfgFileName) < 0 )
cerr << "Can not open " << strCfgFileName << endl;
if (initCommon(argc,argv,m_cConfigFile)!=0)
//------------------------------------[配置文件]-------------------
if(m_cConfigFile.GetValue((char *)"APPINFO",(char *)"ProgramID",strTemp)!=0)
cerr << "没有找到配置文件中的ProgramID的数据!"<<endl;
m_nProgramID = atoi(strTemp);
if(m_cConfigFile.GetValue((char *)"APPINFO",(char *)"ProgramName",m_strProgramName)!=0)
cerr << "没有找到配置文件中的ProgramName的数据!"<<endl;
if( m_cConfigFile.GetValue((char *)"APPINFO",(char *)"Version",m_strVersion)!=0 )
cerr << "没有找到配置文件中的Version的数据!"<<endl;
if( m_cConfigFile.GetValue((char *)"APPINFO",(char *)"AppPath",m_strAppPath)!=0 )
cerr << "没有找到配置文件中的AppPath的数据!"<<endl;
MakeSureDirectoryPathExists(m_strAppPath);
if( m_cConfigFile.GetValue((char *)"APPINFO",(char *)"PlatForm",m_strPlatForm)!=0 )
cerr << "没有找到配置文件中的PlatForm的数据!"<<endl;
if( m_cConfigFile.GetValue((char *)"GLOBAL",(char *)"SleepTime",strTemp)!=0 )
cerr << "没有找到配置文件中的SleepTime的数据!"<<endl;
m_nSleepTime = atoi(strTemp);
if( m_cConfigFile.GetValue((char *)"GLOBAL",(char *)"ProType",strTemp) !=0 )
cerr << "没有找到配置文件中的ProType的数据!"<<endl;
m_nProType = atoi(strTemp);
if( m_cConfigFile.GetValue((char *)"GLOBAL",(char *)"TotNumer",strTemp) !=0 )
cerr << "没有找到配置文件中的TotNumer的数据!"<<endl;
m_nTotNumer = atoi(strTemp);
if( m_cConfigFile.GetValue((char *)"GLOBAL",(char *)"SrcFilePath",m_strSrcFilePath) !=0 )
cerr << "没有找到配置文件中的SrcFilePath的数据!"<<endl;
MakeSureDirectoryPathExists(m_strSrcFilePath);
if( m_cConfigFile.GetValue((char *)"GLOBAL",(char *)"SucFilePath",m_strSucFilePath) !=0 )
cerr << "没有找到配置文件中的SucFilePath的数据!"<<endl;
MakeSureDirectoryPathExists(m_strSucFilePath);
if( m_cConfigFile.GetValue((char *)"GLOBAL",(char *)"BadFilePath",m_strBadFilePath) !=0 )
cerr << "没有找到配置文件中的BadFilePath的数据!"<<endl;
MakeSureDirectoryPathExists(m_strBadFilePath);
if( m_cConfigFile.GetValue((char *)"GLOBAL",(char *)"CopyFilePath",m_strCopyFilePath) !=0 )
cerr << "没有找到配置文件中的CopyFilePath的数据!"<<endl;
MakeSureDirectoryPathExists(m_strCopyFilePath);
if( m_cConfigFile.GetValue((char *)"DATABASE",(char *)"TnsName",m_strTnsName) !=0 )
cerr << "没有找到配置文件中的TnsName的数据!"<<endl;
if( m_cConfigFile.GetValue((char *)"DATABASE",(char *)"SrcTable",m_strSrcTable) !=0 )
cerr << "没有找到配置文件中的SrcTable的数据!"<<endl;
if( m_cConfigFile.GetValue((char *)"DATABASE",(char *)"CkTable",m_strCkTable) !=0 )
cerr << "没有找到配置文件中的CkTable的数据!"<<endl;
if( m_cConfigFile.GetValue((char *)"DATABASE",(char *)"UserTable",m_strUserLabelTable) !=0 )
cerr << "没有找到配置文件中的UserTable的数据!"<<endl;
if( m_cConfigFile.GetValue((char *)"DATABASE",(char *)"ExceptionTable",m_strExceptionTable) !=0 )
cerr << "没有找到配置文件中的ExceptionTable的数据!"<<endl;
if( m_cConfigFile.GetValue((char *)"DATABASE",(char *)"CommitRow",strTemp)!=0 )
cerr << "没有找到配置文件中的CommitRow的数据!"<<endl;
m_nCommitRow = atoi(strTemp);
if( m_cConfigFile.GetValue((char *)"MONITOR",(char *)"MonPath",m_strMonPath) !=0 )
cerr << "没有找到配置文件中的MonPath的数据!"<<endl;
if( m_cConfigFile.GetValue((char *)"MONITOR",(char *)"Interval1",strTemp) !=0 )
cerr << "没有找到配置文件中的Interval1的数据!"<<endl;
m_nInterval1 = atoi(strTemp);
if( m_cConfigFile.GetValue((char *)"MONITOR",(char *)"Interval2",strTemp) !=0 )
cerr << "没有找到配置文件中的Interval2的数据!"<<endl;
m_nInterval2 = atoi(strTemp);
if( m_cConfigFile.GetValue((char *)"MONITOR",(char *)"LogLevel",strTemp) !=0 )
cerr << "没有找到配置文件中的LogLevel的数据!"<<endl;
m_nLogLevel = atoi(strTemp);
//------------------------------------[配置文件]-------------------
int CSynThirdMgr::writeErrlog(int m_intPro_type,char *str_id,int flag_type,char *pstrResMsg)
char strBadFileName[512]={0};
//错误日志文件名
char strQZBadFilePath[256]={0}; //前缀错误日志路径
char strZGBadLogFileName[512]={0}; //整个错误日志路径文件名
char strSysdate_pro[15]={0};
char strResMsg[1024]={0};
rNewTime = localtime(&lTime);
sprintf(strSysdate_pro,"%04d-%02d-%02d",rNewTime->tm_year+1900,rNewTime->tm_mon+1,rNewTime->tm_mday);
sprintf(strBadFileName,(char *)"%d_%s%s",m_nProgramID,strSysdate_pro,LOGFILE_APPEND);
sprintf(strQZBadFilePath,(char *)"%s",m_strBadFilePath);
sprintf(strZGBadLogFileName,(char *)"%s%s",strQZBadFilePath,strBadFileName);
locale loc = locale::global(locale(""));//将全局区域设为操作系统默认区域//lin
fBad.open(strZGBadLogFileName,ios::out|ios::app);
locale::global(loc);//还原全局区域设定//linlocale("C")
fBad <<"时间:"<<strSysdate_pro;
fBad <<"进程:"<<m_intPro_type<<" 处理文件id:"<<str_id;
fBad <<" "<<pstrResMsg<<endl;
fBad <<" 文件打开失败!!!"<<endl;
sprintf(pstrResMsg,(char *)" -401 写文件异常:%s",(char *)Err);
sprintf(pstrResMsg,(char *)"OK");
int CSynThirdMgr::writeStatuslog(int m_intPro_type,char *str_id,int flag_type,char *pstrResMsg)
char strSucFileName[512]={0};
//状态日志文件名
char strQZSucFilePath[256]={0}; //前缀状态日志路径
char strZGSucLogFileName[512]={0}; //整个状态日志路径文件名
char strSysdate_pro[15]={0};
char strResMsg[1024]={0};
rNewTime = localtime(&lTime);
sprintf(strSysdate_pro,"%04d-%02d-%02d",rNewTime->tm_year+1900,rNewTime->tm_mon+1,rNewTime->tm_mday);
sprintf(strSucFileName,(char *)"%d_%s%s",m_nProgramID,strSysdate_pro,STAFILE_APPEND);
sprintf(strQZSucFilePath,(char *)"%s",m_strSucFilePath);
sprintf(strZGSucLogFileName,(char *)"%s%s",strQZSucFilePath,strSucFileName);
locale loc = locale::global(locale(""));//将全局区域设为操作系统默认区域//lin
fSuc.open(strZGSucLogFileName,ios::out|ios::app);
locale::global(loc);//还原全局区域设定//linlocale("C")
fSuc <<"时间:"<<strSysdate_pro;
fSuc <<"进程:"<<m_intPro_type<<" 处理文件id:"<<str_id;
fSuc <<" "<<pstrResMsg<<endl;
fSuc <<" 文件打开失败!!!"<<endl;
sprintf(pstrResMsg,(char *)" -401 写文件异常:%s",(char *)Err);
sprintf(pstrResMsg,(char *)"OK");
//.h
// SynThirdMgr.h: interface for the CSynThirdMgr class.
//
//
//----------------------------------------------------------------------------
// 程序名称: SynThirdMgr.h
// 程序说明: 业务处理类
// 程序作者: 林江
// 开始日期: 2009-10-26
//----------------------------------------------------------------------------
#ifndef WQF_SYNTHIRDMGR_H__20040919__INCLUDED_
#define WQF_SYNTHIRDMGR_H__20040919__INCLUDED_
#include "FlowCtrl.h"
class CSynThirdMgr : public CFlowCtrl
{
public:
CSynThirdMgr();
virtual ~CSynThirdMgr();
bool prepare();
//退出
void finish();
//一个周期中的所有处理,如处理完一个文件,提交;如果出严重错误,抛出异常
void handle();
int initialize(int argc,char* argv[]);
//private:
public:
//----------开始------------------------------------
//应用程序号
int m_nProgramID;
//应用名称
char m_strProgramName[128];
//应用版本号
char m_strVersion[128];
//应用所在路径
char m_strAppPath[512];
//平台ID
char m_strPlatForm[32];
//休眠时间
int m_nSleepTime;
//进程号
int m_nProType;
//总的进程数
int m_nTotNumer;
//源文件路径
char m_strSrcFilePath[512];
//成功日志文件路径
char m_strSucFilePath[512];
//错误日志文件路径
char m_strBadFilePath[512];
//备份文件路径
char m_strCopyFilePath[512];
//完整文件名
char m_strRealFile[256];
//数据库连接串
char m_strTnsName[512];
//源数据表
char m_strSrcTable[128];
//入库表
char m_strUserLabelTable[128];
//control table
char m_strCkTable[128];
//storage data table
char m_strDownTable[128];
//异常表
char m_strExceptionTable[128];
//多少条提交一次
int m_nCommitRow;
//监控路径
char m_strMonPath[512];
//慢时间间隔
int m_nInterval1;
//挂死时间间隔
int m_nInterval2;
//日志等级
int m_nLogLevel;
//是否有效
bool m_bDownFlag;
//---------------结束---------------------------------
CConfigFile m_cConfigFile;
int writeErrlog(int m_intPro_type,char *str_id,int flag_type,char *pstrResMsg);
int writeStatuslog(int m_intPro_type,char *str_id,int flag_type,char *pstrResMsg);
DWORD WINAPI uploadDataThread(LPVOID lpParamter);
public:
int m_nFlag; //控制标识
std::ofstream *m_pfile;//=new ofstream();
__int64 m_n64ID;
};
#endif // WQF_SYNTHIRDMGR_H__20040919__INCLUDED_