UploadFSM.cpp 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872
  1. #include "stdafx.h"
  2. #include "UploadFSM.h"
  3. #include <regex>
  4. #include <fileutil.h>
  5. #include <array.h>
  6. #ifdef RVC_OS_WIN
  7. #include <cstdlib>
  8. #include <ctime>
  9. #include "EventCode.h"
  10. #else
  11. #include <thread>
  12. #include "upload.h"
  13. #include "path.h"
  14. #include <sys/stat.h>
  15. #include <sys/types.h>
  16. #include <fcntl.h>
  17. #include <time.h>
  18. #include <stdio.h>
  19. #include <cstdio>
  20. #include <iostream>
  21. #include <errno.h>
  22. #include "EventCode.h"
  23. #endif
  24. #define UPLOAD_CONTENT_EACH_LEN 512*1024
  25. UploadFSM::UploadFSM() : m_currUploadFile(NULL)
  26. {
  27. m_uploadList = new list<UploadFileInfo*>();
  28. m_uploadPlanList = new list<UploadPlan *>();
  29. m_overLenFileList = new list<string>();
  30. m_eachUploadLen=UPLOAD_CONTENT_EACH_LEN;
  31. m_uploadMaxNum = 200;
  32. m_isOffLine=true;//初始离线状态为true
  33. m_printPlan = true;//初始化为打印
  34. }
  35. UploadFSM::~UploadFSM()
  36. {
  37. }
  38. namespace Task
  39. {
  40. struct SendFileTask : public ITaskSp
  41. {
  42. UploadFSM* m_fsm;
  43. explicit SendFileTask(UploadFSM* e) : m_fsm(e) {}
  44. void Process(){
  45. //判断是分行url请求还是总行url请求
  46. //判断是临时文件还是永久文件
  47. //循环上传
  48. //登记上传流水或者失败流水
  49. //根据最终上传结果返回成功还是失败
  50. CSystemStaticInfo info;
  51. auto rc = m_fsm->GetEntityBase()->GetFunction()->GetSystemStaticInfo(info);
  52. if (rc != Error_Succeed)
  53. {
  54. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SendFileTask")("get CSystemStaticInfo fail,file = %s",m_fsm->m_currUploadFile->filePath.c_str());
  55. m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_UPLOAD_FAIL));//失败发送
  56. return;
  57. }
  58. bool isLanTerminal=true;//行内行外标志
  59. if(strcmp(m_fsm->m_currUploadFile->upload_address_env.c_str(),"BIZ")==0){
  60. isLanTerminal=true;
  61. }else{
  62. isLanTerminal=false;
  63. }
  64. IHttpFunc* client;
  65. client = create_http(m_fsm->HttpsLogCallBack);
  66. bool hasSend=false;
  67. if(m_fsm->m_currUploadFile->plan_type=="T"){
  68. //查询失败统一需要上传
  69. if(queryTempFile(client,info)){
  70. hasSend=true;
  71. }
  72. }
  73. //是否需要上传文件
  74. bool sendOk = false;
  75. if(!hasSend){
  76. string errmsg ="";
  77. if(isLanTerminal){
  78. //DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SendFileTask")("上传文件到分行:%s",m_fsm->m_currUploadFile->filePath.c_str());
  79. }else{
  80. //DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SendFileTask")("上传文件到总行:%s",m_fsm->m_currUploadFile->filePath.c_str());
  81. }
  82. string MD5str = ""; //返回的MD5值
  83. string branchFilePath = ""; //返回的分行保存路径值
  84. //修改为重试上传机制,防止上传当中网络抖动,避免等待下次上传
  85. bool isUploadSucc=false;
  86. for (int i =0 ; i<2;i++ )
  87. {
  88. errmsg="";//每次上传前清空错误信息,只记录最后一次的
  89. if(uploadFile(client,info,MD5str,branchFilePath,errmsg)){
  90. isUploadSucc = true;
  91. break;
  92. }
  93. Sleep(3000);//等待3秒下次传送
  94. }
  95. if(isUploadSucc){
  96. if(updateState(client,info,isLanTerminal,MD5str,branchFilePath,errmsg)){
  97. if(operateFile(errmsg)){
  98. sendOk = true;//成功
  99. }else{
  100. m_fsm->m_uploadReport.operateFileFail++;//添加操作失败计数
  101. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SendFileTask")("operateFile fail,file = %s",m_fsm->m_currUploadFile->filePath.c_str());
  102. addUploadFail(client,info,isLanTerminal,"2",errmsg);//操作失败
  103. }
  104. }else{
  105. m_fsm->m_uploadReport.updateState++;//添加登记失败计数
  106. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SendFileTask")("updateState fail,file = %s",m_fsm->m_currUploadFile->filePath.c_str());
  107. addUploadFail(client,info,isLanTerminal,"1",errmsg);//登记失败
  108. }
  109. }else{
  110. m_fsm->m_uploadReport.uploadFail++;//添加上传失败计数
  111. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SendFileTask")("uploadFile fail,file = %s",m_fsm->m_currUploadFile->filePath.c_str());
  112. addUploadFail(client,info,isLanTerminal,"1",errmsg);//上传失败
  113. }
  114. }else{
  115. sendOk=true;
  116. }
  117. client->Destory();
  118. if(sendOk){
  119. m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_UPLOAD_SUCC));//成功发送
  120. }else{
  121. m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_UPLOAD_FAIL));//失败发送
  122. }
  123. }
  124. //上传文件:断点续传,多次调用
  125. bool uploadFile(IHttpFunc* client,CSystemStaticInfo info,string &MD5str,string &branchFilePath, string &errmsg){
  126. string reqUrl;
  127. unsigned seed;
  128. seed = time(0);
  129. srand(seed);
  130. if(m_fsm->m_branchIpList.size()>0){
  131. int branchSeq = (rand() % m_fsm->m_branchIpList.size()) + 1;
  132. map<int,string>::iterator it = m_fsm->m_branchIpList.find(branchSeq);
  133. if(it != m_fsm->m_branchIpList.end())
  134. {
  135. reqUrl = it->second;
  136. }else{
  137. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("uploadFile is fail ,branchIp[%d] is null",branchSeq);
  138. errmsg = CSimpleStringA::Format("uploadFile is fail ,branchIp[%d] is null",branchSeq).GetData();
  139. return false;
  140. }
  141. }else{
  142. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("uploadFile is fail ,branchIp is null");
  143. errmsg = "uploadFile is fail ,branchIp is null";
  144. return false;
  145. }
  146. //获取服务器文件长度
  147. unsigned char* contentFirst = new unsigned char[1];
  148. memset(contentFirst,0,1);
  149. UploadDataRet respFirst ={0};
  150. bool is_finish =false; //是否续传
  151. if(!uploadFileImpl(client,info,reqUrl,contentFirst,0,"",respFirst)){
  152. delete[] contentFirst;
  153. errmsg=CSimpleStringA::Format("url=%s, uploadFileImpl first is fail",reqUrl.c_str()).GetData();
  154. return false;//返回失败
  155. }else{
  156. delete[] contentFirst;
  157. }
  158. long uploadedLen = respFirst.uploaded_length;//服务器返回已上传的长度
  159. if(uploadedLen>m_fsm->m_currUploadFile->fileLen){
  160. //服务器返回长度大于终端文件长度
  161. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("uploadFile is fail, server filelen [%d] is over terminal filelen [%d]",uploadedLen,m_fsm->m_currUploadFile->fileLen);
  162. errmsg=CSimpleStringA::Format("uploadFile is fail, server filelen [%d] is over terminal filelen [%d]",uploadedLen,m_fsm->m_currUploadFile->fileLen).GetData();
  163. return false;
  164. }
  165. if (uploadedLen < 0) {
  166. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("uploadFile uploadedLen beginPos < 0");
  167. errmsg = CSimpleStringA::Format("uploadFile is fail, server filelen [%d] is <0", uploadedLen).GetData();
  168. return false;
  169. }
  170. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("文件[%s] 开始传送位置 uploadedLen = %d, file len=%d",m_fsm->m_currUploadFile->filePath.c_str(), uploadedLen, m_fsm->m_currUploadFile->fileLen);
  171. //循环传送数据块
  172. FILE* pFile =fopen(m_fsm->m_currUploadFile->filePath.c_str(),"rb");
  173. if(pFile==NULL){
  174. //读取文件失败;
  175. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("uploadFile is fail, file open fail");
  176. errmsg="uploadFile is fail, file open fail";
  177. return false;
  178. }
  179. //获取首次文件hash
  180. CSimpleStringA firstSM3Str = "";
  181. if (Error_Succeed == m_fsm->SM3FileToStr(m_fsm->m_currUploadFile->filePath.c_str(), firstSM3Str, false)) {
  182. m_fsm->m_currUploadFile->firstMD5Str = firstSM3Str.GetData();
  183. m_fsm->m_currUploadFile->lastMD5Str = "";
  184. }
  185. else {
  186. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("uploadFile is fail, get file first SM3 hash fail");
  187. errmsg = "uploadFile is fail , get file first SM3 hash fail";
  188. return false;
  189. }
  190. bool uploadSucc= false;
  191. while(true){
  192. //续传
  193. if((m_fsm->m_currUploadFile->fileLen-uploadedLen)>m_fsm->m_eachUploadLen){
  194. int uploadLen = m_fsm->m_eachUploadLen;//传送数据长度
  195. unsigned char* content = new unsigned char[uploadLen];
  196. memset(content,0,uploadLen);
  197. //从文件拷贝字节
  198. if(m_fsm->getFileContent(pFile,content,uploadedLen,uploadLen)){
  199. UploadDataRet resp ={0};
  200. if(uploadFileImpl(client,info,reqUrl,content,uploadLen,"",resp)){
  201. delete[] content;
  202. uploadedLen +=uploadLen;//改变已上传长度
  203. }else{
  204. delete[] content;
  205. errmsg=CSimpleStringA::Format("url=%s, uploadFileImpl continue is fail",reqUrl.c_str()).GetData();
  206. break;//上传失败
  207. }
  208. }else{
  209. delete[] content;
  210. errmsg="uploadFile is fail , getFileContent fail";
  211. break;//获取文件内存失败
  212. }
  213. }else{
  214. //获取最后一次传送时文件长度
  215. CSimpleStringA filepath = m_fsm->m_currUploadFile->filePath.c_str();
  216. long fileLastLen = 0;
  217. if(!m_fsm->GetFileLength(filepath.GetData(),fileLastLen)){
  218. errmsg="uploadFile is fail , end get file len fail";
  219. break;//计算sm3出错
  220. }
  221. string fileLastLenStr= CSimpleStringA::Format("%d",fileLastLen).GetData();//计算出解密后总长度
  222. //获取最后文件hash
  223. CSimpleStringA lastSM3Str = "";
  224. if(Error_Succeed == m_fsm->SM3FileToStr(filepath.GetData(), lastSM3Str, false)) {
  225. m_fsm->m_currUploadFile->lastMD5Str = lastSM3Str.GetData();
  226. }
  227. else {
  228. errmsg = "uploadFile is fail , get file last SM3 hash fail";
  229. break;//计算sm3出错
  230. }
  231. //最后一块
  232. int uploadLen = m_fsm->m_currUploadFile->fileLen-uploadedLen;
  233. unsigned char* contentEnd;
  234. if(uploadLen==0){
  235. //对零的长度特殊处理
  236. contentEnd = new unsigned char[1];
  237. memset(contentEnd,0,1);
  238. }else{
  239. contentEnd = new unsigned char[uploadLen];
  240. memset(contentEnd,0,uploadLen);
  241. }
  242. if(m_fsm->getFileContent(pFile,contentEnd,uploadedLen,uploadLen)){
  243. UploadDataRet respEnd ={0};
  244. if(uploadFileImpl(client,info,reqUrl,contentEnd,uploadLen,fileLastLenStr,respEnd)){
  245. delete[] contentEnd;
  246. if(respEnd.upload_finish){
  247. uploadSucc =true;//成功
  248. branchFilePath = respEnd.branchFilePath;//分行保存地址
  249. }else{
  250. uploadSucc =false;//失败
  251. }
  252. break;
  253. }else{
  254. delete[] contentEnd;
  255. errmsg=CSimpleStringA::Format("url=%s, uploadFileImpl end is fail",reqUrl.c_str()).GetData();
  256. break;//上传失败
  257. }
  258. }else{
  259. delete[] contentEnd;
  260. errmsg="uploadFile is fail , end getFileContent fail";
  261. break;//获取文件内存失败
  262. }
  263. }
  264. }
  265. if(uploadSucc){
  266. //DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("uploadFile succ");
  267. }else{
  268. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("uploadFile fail url=%s",reqUrl.c_str());
  269. }
  270. if(pFile){
  271. if(fclose(pFile)!=0){
  272. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("uploadFile fail, close file fail ,url=%s",reqUrl.c_str());
  273. errmsg="uploadFile fail, close file fail";
  274. return false;
  275. }
  276. }
  277. return uploadSucc;
  278. }
  279. //上传文件:具体实现
  280. bool uploadFileImpl(IHttpFunc* client,CSystemStaticInfo info,string httpUrl,unsigned char* fileContent,long fileContentSize,string lastFileLength,UploadDataRet& uploadData){
  281. UploadFileReq qTempReq;
  282. UploadFileRet qTempRet;
  283. qTempRet.m_userCode ="";
  284. qTempRet.m_errMsg="";
  285. Json::Value rootReq;
  286. Json::FastWriter writer;
  287. rootReq["terminal_no"] = info.strTerminalID.GetData();
  288. rootReq["branch_no"] = m_fsm->m_currUploadFile->branch_no.c_str();
  289. rootReq["file_name"] = m_fsm->m_currUploadFile->fileName.c_str();
  290. rootReq["file_path"] = m_fsm->m_currUploadFile->fileUploadPath.c_str();
  291. rootReq["plan_id"] = m_fsm->m_currUploadFile->plan_id.c_str();
  292. rootReq["file_type"] = m_fsm->m_currUploadFile->file_type.c_str();
  293. //rootReq["origin_file_length"] = CSimpleStringA::Format("%d",m_fsm->m_currUploadFile->fileLen).GetData();
  294. rootReq["first_file_length"] = CSimpleStringA::Format("%d",m_fsm->m_currUploadFile->fileLen).GetData();//加密后需要修改,服务端根据此长度做判断
  295. rootReq["last_file_length"] = lastFileLength.c_str();//加密后需要修改,最后一次长度跟服务端保存长度做对比
  296. rootReq["upload_length"] = CSimpleStringA::Format("%d",fileContentSize).GetData();
  297. rootReq["first_sm3"] = m_fsm->m_currUploadFile->firstMD5Str.c_str();
  298. rootReq["last_sm3"] = m_fsm->m_currUploadFile->lastMD5Str.c_str();
  299. rootReq["file_head_custom"] = "";//自定义解密的头json格式,可为空
  300. #ifdef RVC_OS_WIN
  301. rootReq["system_type"] = "W";//系统标记,代表路径分隔符
  302. #else
  303. rootReq["system_type"] = "L";//系统标记,代表路径分隔符
  304. #endif
  305. string jsonReq = writer.write(rootReq);
  306. qTempReq.url = httpUrl;
  307. qTempReq.paramContent = jsonReq;
  308. qTempReq.fileName = m_fsm->m_currUploadFile->fileName;
  309. qTempReq.fileContent = fileContent;
  310. qTempReq.fileContentSize= fileContentSize;
  311. qTempReq.m_timeOut = 5*60;//设置超时时间
  312. //qTempReq.m_printDbg=true;
  313. //调用上传接口
  314. //最后一次上传时,文件hash和长度告警
  315. if (m_fsm->m_currUploadFile->lastMD5Str.length() != 0) {
  316. LogWarn(Severity_Low, Error_Unexpect, LOG_WARN_UPLOAD_FILE_INFO, CSimpleStringA::Format("upload %s file size is %s byte,sm3 digest is %s.", m_fsm->m_currUploadFile->fileName.c_str(), lastFileLength.c_str(), m_fsm->m_currUploadFile->lastMD5Str.c_str()).GetData());
  317. }
  318. PROCESS_LINK_CONTEXT("LR0402104UploadFile")
  319. if (!client->UploadFileBlock(qTempReq, qTempRet, &nextLink)) {
  320. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("uploadFile http req fail ,url =%s ,fileName = %s",httpUrl.c_str(), m_fsm->m_currUploadFile->fileName.c_str());
  321. return false;
  322. }
  323. if(qTempRet.httpCode!=200){
  324. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("uploadFile http req fail ,url =%s ,retHttpCode=%d, fileName = %s",httpUrl.c_str(), qTempRet.httpCode, m_fsm->m_currUploadFile->fileName.c_str());
  325. return false;
  326. }
  327. //解析回应报文
  328. Json::Reader reader;
  329. Json::Value rootRet;
  330. if (!reader.parse(qTempRet.strBody, rootRet, false))
  331. {
  332. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("uploadFile http parse resp is fail,fileName = %s",m_fsm->m_currUploadFile->fileName.c_str());
  333. return false;//解析失败
  334. }
  335. uploadData.strBody = qTempRet.strBody;
  336. bool isSucc = rootRet["success"].asBool();
  337. if(isSucc){
  338. if(rootRet.isMember("data")){
  339. uploadData.uploaded_length= rootRet["data"]["uploaded_length"].asInt();
  340. uploadData.upload_finish = rootRet["data"]["upload_finish"].asBool();
  341. uploadData.branchFilePath = rootRet["data"]["branch_file_path"].asCString();
  342. return true;//返回值
  343. }else{
  344. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("uploadFile http [success][data] is invaild ,url =%s, fileName = %s",httpUrl.c_str(),m_fsm->m_currUploadFile->fileName.c_str());
  345. return false;//无data字段
  346. }
  347. }else{
  348. //失败
  349. if (m_fsm->m_currUploadFile->lastMD5Str.length() == 0) {
  350. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("uploadFile http [success] is false, url[%s],userCode[%s],errmsg[%s],fileName = %s", httpUrl.c_str(), qTempRet.m_userCode.c_str(), qTempRet.m_errMsg.c_str(), m_fsm->m_currUploadFile->fileName.c_str());
  351. }
  352. else {
  353. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("uploadFile http [success] is false, url[%s],userCode[%s],errmsg[%s],fileName = %s,first_sm3 =[%s],last_sm3=[%s]", httpUrl.c_str(), qTempRet.m_userCode.c_str(), qTempRet.m_errMsg.c_str(), m_fsm->m_currUploadFile->fileName.c_str(), m_fsm->m_currUploadFile->firstMD5Str.c_str(), m_fsm->m_currUploadFile->lastMD5Str.c_str());
  354. }
  355. return false;
  356. }
  357. }
  358. //查询临时文件 post
  359. bool queryTempFile(IHttpFunc* client,CSystemStaticInfo info){
  360. UploadQueryTempFileReq qTempReq;
  361. UploadQueryTempFileRet qTempRet;
  362. qTempRet.m_userCode ="";
  363. qTempRet.m_errMsg="";
  364. Json::Value rootReq;
  365. Json::FastWriter writer;
  366. rootReq["terminal_no"] = info.strTerminalID.GetData();
  367. rootReq["plan_id"] = m_fsm->m_currUploadFile->plan_id.c_str();
  368. rootReq["file_path"] = m_fsm->m_currUploadFile->fileUploadPath.c_str();
  369. rootReq["file_type"] = m_fsm->m_currUploadFile->file_type.c_str();
  370. string jsonReq = writer.write(rootReq);
  371. qTempReq.m_reqStr = jsonReq;//请求参数
  372. //qTempReq.m_printDbg = true;
  373. qTempReq.m_url=m_fsm->m_centerUrl.queryTempFileUrl;//访问地址
  374. PROCESS_LINK_CONTEXT("LR0402104QueryTempFile")
  375. if(!client->Post(qTempReq, qTempRet, &nextLink)){
  376. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("queryTempFile http req fail ,fileName = %s, err=%s",m_fsm->m_currUploadFile->filePath.c_str(),qTempRet.m_errMsg.c_str());
  377. return false;
  378. }
  379. //解析报文
  380. //解析回应报文
  381. Json::Reader reader;
  382. Json::Value rootRet;
  383. if (!reader.parse(qTempRet.m_retStr, rootRet, false))
  384. {
  385. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("queryTempFile parse resp is fail,fileName = %s",m_fsm->m_currUploadFile->filePath.c_str());
  386. m_fsm->m_uploadReport.queryTempFail++;//添加查询临时失败计数
  387. return false;//解析失败
  388. }
  389. bool isSucc = rootRet["success"].asBool();
  390. if(isSucc){
  391. if(rootRet.isMember("data")){
  392. if(rootRet["data"]["upload_flag"].asBool()){
  393. return true;//查询有
  394. }else{
  395. return false;//查询没有
  396. }
  397. }else{
  398. m_fsm->m_uploadReport.queryTempFail++;//添加查询临时失败计数
  399. return false;//无data字段
  400. }
  401. }else{
  402. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("queryTempFile [success] is false, fileName = %s",m_fsm->m_currUploadFile->filePath.c_str());
  403. m_fsm->m_uploadReport.queryTempFail++;//添加查询临时失败计数
  404. return false;
  405. }
  406. }
  407. //登记文件流水状态 post
  408. bool updateState(IHttpFunc* client,CSystemStaticInfo info,bool isLanTerminal, string MD5str,string branchFilePath, string &errmsg){
  409. if(!isLanTerminal){
  410. return true;//行外默认是总行那边登记交易流水,终端不再发送交易流水登记,直接返回成功
  411. }
  412. UploadUpdateStateReq updateStateReq;
  413. UploadUpdateStateRet updateStateRet;
  414. updateStateRet.m_userCode="";
  415. updateStateRet.m_errMsg="";
  416. Json::Value rootReq;
  417. Json::FastWriter writer;
  418. rootReq["plan_id"] = m_fsm->m_currUploadFile->plan_id.c_str();
  419. rootReq["branch_no"] = m_fsm->m_currUploadFile->branch_no.c_str();
  420. rootReq["terminal_no"] = info.strTerminalID.GetData();
  421. rootReq["file_type"] = m_fsm->m_currUploadFile->file_type.c_str();
  422. rootReq["file_name"] = m_fsm->m_currUploadFile->fileName.c_str();
  423. rootReq["file_path"] = m_fsm->m_currUploadFile->fileUploadPath.c_str();
  424. rootReq["branch_file_path"] = branchFilePath.c_str();
  425. rootReq["file_length"] = CSimpleStringA::Format("%d",m_fsm->m_currUploadFile->fileLen).GetData();
  426. if(isLanTerminal){
  427. rootReq["status"] = "1";//分行
  428. }else{
  429. rootReq["status"] = "2";//总行
  430. }
  431. rootReq["upload_time"] = CSmallDateTime::GetNow().ToTimeString().GetData();
  432. rootReq["remark"] = "";
  433. rootReq["sm3"] = MD5str.c_str();
  434. string jsonReq = writer.write(rootReq);
  435. updateStateReq.m_reqStr = jsonReq;//请求参数
  436. updateStateReq.m_url=m_fsm->m_centerUrl.updateStateUrl;//访问地址
  437. PROCESS_LINK_CONTEXT("LR0402104UpdateState")
  438. if(!client->Post(updateStateReq, updateStateRet, &nextLink)){
  439. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("updateState is fail, userCode = %s, errmsg = %s",updateStateRet.m_userCode.c_str(), updateStateRet.m_errMsg.c_str());
  440. errmsg = CSimpleStringA::Format("updateState is fail, userCode = %s, errmsg = %s",updateStateRet.m_userCode.c_str(), updateStateRet.m_errMsg.c_str());
  441. return false;
  442. }
  443. //解析报文
  444. //解析回应报文
  445. Json::Reader reader;
  446. Json::Value rootRet;
  447. if (!reader.parse(updateStateRet.m_retStr, rootRet, false))
  448. {
  449. errmsg="return pack parse is fail";
  450. return false;//解析失败
  451. }
  452. bool isSucc = rootRet["success"].asBool();
  453. if(isSucc){
  454. if(rootRet.isMember("data")){
  455. if(rootRet["data"]["update_flag"].asBool()){
  456. return true;//登记成功
  457. }else{
  458. errmsg="return pack [data][update_flag] is not bool";
  459. return false;//登记失败
  460. }
  461. }else{
  462. errmsg="return pack [data] is null";
  463. return false;//无data字段
  464. }
  465. }else{
  466. errmsg="return pack [success] is false";
  467. return false;
  468. }
  469. }
  470. //登记失败文件流水 post
  471. bool addUploadFail(IHttpFunc* client,CSystemStaticInfo info,bool isLanTerminal,string operation,string errmsg){
  472. UploadUploadFailReq updateFailReq;
  473. UploadUploadFailRet updateFailRet;
  474. updateFailRet.m_userCode="";
  475. updateFailRet.m_errMsg="";
  476. Json::Value rootReq;
  477. Json::FastWriter writer;
  478. rootReq["plan_id"] = m_fsm->m_currUploadFile->plan_id.c_str();
  479. rootReq["branch_no"] = m_fsm->m_currUploadFile->branch_no.c_str();
  480. rootReq["terminal_no"] = info.strTerminalID.GetData();
  481. rootReq["file_name"] = m_fsm->m_currUploadFile->fileName.c_str();
  482. rootReq["file_path"] = m_fsm->m_currUploadFile->fileUploadPath.c_str();
  483. if(isLanTerminal){
  484. rootReq["stage"] = "1";//分行
  485. }else{
  486. rootReq["stage"] = "2";//总行
  487. }
  488. rootReq["operation"] = operation;
  489. rootReq["upload_time"] = CSmallDateTime::GetNow().ToTimeString().GetData();//2021-03-11 10:20:02
  490. rootReq["reason"] = errmsg.c_str();
  491. rootReq["remark"] = "";
  492. string jsonReq = writer.write(rootReq);
  493. updateFailReq.m_reqStr = jsonReq;//请求参数
  494. updateFailReq.m_url = m_fsm->m_centerUrl.addUploadFailUrl;//访问地址
  495. PROCESS_LINK_CONTEXT("LR0402104UpdateFail")
  496. if(!client->Post(updateFailReq, updateFailRet, &nextLink)){
  497. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("addUploadFail is fail,userCode = %s",updateFailRet.m_userCode.c_str());
  498. return false;
  499. }
  500. //解析报文
  501. //解析回应报文
  502. Json::Reader reader;
  503. Json::Value rootRet;
  504. if (!reader.parse(updateFailRet.m_retStr, rootRet, false))
  505. {
  506. return false;//解析失败
  507. }
  508. bool isSucc = rootRet["success"].asBool();
  509. if(isSucc){
  510. if(rootRet.isMember("data")){
  511. if(rootRet["data"]["update_flag"].asBool()){
  512. return true;//登记成功
  513. }else{
  514. return false;//登记失败
  515. }
  516. }else{
  517. return false;//无data字段
  518. }
  519. }else{
  520. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("addUploadFail [success] is false");
  521. return false;
  522. }
  523. }
  524. //上传后文件处理
  525. bool operateFile(string &errmsg){
  526. if(m_fsm->m_currUploadFile->after_deal_type=="D"){
  527. #ifdef RVC_OS_WIN
  528. if(remove(m_fsm->m_currUploadFile->filePath.c_str())==0){
  529. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete file is ok, file =%s",m_fsm->m_currUploadFile->filePath.c_str());
  530. return true;
  531. }else{
  532. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete file is error, file =%s, errno=%d",m_fsm->m_currUploadFile->filePath.c_str(),(int)GetLastError());
  533. errmsg = CSimpleStringA::Format("delete file is error, file =%s, errno=%d",m_fsm->m_currUploadFile->filePath.c_str(),(int)GetLastError());
  534. return false;
  535. }
  536. #else
  537. if (changeFileAtt(m_fsm->m_currUploadFile->filePath.c_str()) == 0) {
  538. if (remove(m_fsm->m_currUploadFile->filePath.c_str()) == 0) {
  539. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete file is ok, file =%s",m_fsm->m_currUploadFile->filePath.c_str());
  540. return true;
  541. }
  542. else {
  543. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete file is error,file =%s, errno=%d",m_fsm->m_currUploadFile->filePath.c_str(), errno);
  544. errmsg = CSimpleStringA::Format("delete file is error, file =%s, errno=%d",m_fsm->m_currUploadFile->filePath.c_str(), errno);
  545. return false;
  546. }
  547. }
  548. else {
  549. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete file is error,changefileAtt fail,file =%s, errno=%d",m_fsm->m_currUploadFile->filePath.c_str(), errno);
  550. errmsg = CSimpleStringA::Format("delete file is error,changefileAtt fail,file =%s, errno=%d",m_fsm->m_currUploadFile->filePath.c_str(), errno);
  551. return false;
  552. }
  553. #endif
  554. }else if(m_fsm->m_currUploadFile->after_deal_type=="M"){
  555. string destPath="";
  556. string destDir="";
  557. //根据路径类型组成最后移动路径
  558. if(m_fsm->m_currUploadFile->path_type=="R"){
  559. #ifdef RVC_OS_WIN
  560. destPath = m_fsm->m_rootPath+"\\"+m_fsm->m_currUploadFile->after_deal_text+"\\"+m_fsm->m_currUploadFile->fileName;
  561. destDir = m_fsm->m_rootPath+"\\"+m_fsm->m_currUploadFile->after_deal_text;
  562. #else
  563. destPath = m_fsm->m_rootPath + SPLIT_SLASH_STR + m_fsm->m_currUploadFile->after_deal_text + SPLIT_SLASH_STR + m_fsm->m_currUploadFile->fileName;
  564. destDir = m_fsm->m_rootPath + SPLIT_SLASH_STR + m_fsm->m_currUploadFile->after_deal_text;
  565. #endif
  566. }else{
  567. #ifdef RVC_OS_WIN
  568. destPath = m_fsm->m_currUploadFile->after_deal_text+"\\"+m_fsm->m_currUploadFile->fileName;
  569. #else
  570. destPath = m_fsm->m_currUploadFile->after_deal_text + SPLIT_SLASH_STR + m_fsm->m_currUploadFile->fileName;
  571. #endif
  572. destDir = m_fsm->m_currUploadFile->after_deal_text;
  573. }
  574. string srcPath = m_fsm->m_currUploadFile->filePath;
  575. //DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("move file %s to %s",srcPath.c_str(),destPath.c_str());
  576. //判断是否存在目标文件,如存在,则先删除
  577. #ifdef RVC_OS_WIN
  578. if(ExistsFileA(destPath.c_str())){
  579. if(remove(destPath.c_str())==0){
  580. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete dest file is ok [%s]",destPath.c_str());
  581. }else{
  582. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete dest file is error, errno=%d, [%s]",(int)GetLastError(),destPath.c_str());
  583. errmsg = CSimpleStringA::Format("delete dest file is error, errno=%d, [%s]",(int)GetLastError(),destPath.c_str());
  584. return false;
  585. }
  586. }
  587. //判断移动目标文件夹是否存在,不存在,则创建
  588. if(!ExistsDirA(destDir.c_str())){
  589. if(!CreateDirRecursiveA(destDir.c_str())){
  590. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("create dest dir [%s] is error, errno=%d",destDir.c_str(),GetLastError());
  591. errmsg = CSimpleStringA::Format("create dest dir [%s] is error, errno=%d",destDir.c_str(),GetLastError());
  592. return false;
  593. }
  594. }
  595. //移动文件
  596. int i;
  597. int tries = 10;
  598. bool isSucc = false;
  599. for (i = 0; i < tries; ++i) {
  600. if(rename(srcPath.c_str(),destPath.c_str())==0){
  601. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("move file ok! tries:%d, [%s] to [%s] ", i, srcPath.c_str(),destPath.c_str());
  602. isSucc = true;
  603. break;
  604. } else {
  605. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("move file failed! errno:%d, [%s] to [%s] ", (int)GetLastError(), srcPath.c_str(),destPath.c_str());
  606. errmsg = CSimpleStringA::Format("move file failed! errno:%d, [%s] to [%s] ", (int)GetLastError(), srcPath.c_str(),destPath.c_str());
  607. Sleep(1000);
  608. }
  609. }
  610. return isSucc;
  611. #else
  612. if (ExistsFileA(destPath.c_str())) {
  613. if (changeFileAtt(destPath.c_str()) == 0) {
  614. if (remove(destPath.c_str()) == 0) {
  615. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete dest file is ok [%s]",destPath.c_str());
  616. }
  617. else {
  618. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete dest file is error, errno=%d, [%s]", errno, destPath.c_str());
  619. errmsg = CSimpleStringA::Format("delete src file is error, errno=%d, [%s]", errno, destPath.c_str());
  620. return false;
  621. }
  622. }
  623. else {
  624. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete dest file is error,changefileAtt fail ,errno=%d , file=%s ", errno, destPath.c_str());
  625. errmsg = CSimpleStringA::Format("delete src file is error, changefileAtt fail, errno=%d, file=%s", errno, destPath.c_str());
  626. return false;
  627. }
  628. }
  629. //判断移动目标文件夹是否存在,不存在,则创建
  630. if (!ExistsDirA(destDir.c_str())) {
  631. if (!CreateDirRecursiveA(destDir.c_str())) {
  632. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("create dest dir [%s] is error, errno=%d", destDir.c_str(), errno);
  633. errmsg = CSimpleStringA::Format("create dest dir [%s] is error, errno=%d", destDir.c_str(), errno);
  634. return false;
  635. }
  636. }
  637. //移动文件
  638. if (changeFileAtt(srcPath.c_str()) == 0)
  639. {
  640. int i;
  641. int tries = 10;
  642. bool isSucc = false;
  643. for (i = 0; i < tries; ++i) {
  644. //rename函数对于跨分支的目录存在拷贝不成功的情况,故采用先拷贝后删除的操作修复此bug
  645. if (fileutil_copy_file(destPath.c_str(), srcPath.c_str()) == 0) {
  646. if (remove(srcPath.c_str()) == 0) {
  647. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("move file ok! tries:%d, [%s] to [%s] ", i, srcPath.c_str(),destPath.c_str());
  648. isSucc = true;
  649. break;
  650. }
  651. else {
  652. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("move file failed! errno:%d, [%s] to [%s] ", errno, srcPath.c_str(),destPath.c_str());
  653. errmsg = CSimpleStringA::Format("move file failed! errno:%d, [%s] to [%s] ", errno, srcPath.c_str(),destPath.c_str());
  654. Sleep(1000);
  655. }
  656. }
  657. else {
  658. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("move file failed! copy src file fail, errno:%d, [%s] to [%s] ", errno, srcPath.c_str(),destPath.c_str());
  659. errmsg = CSimpleStringA::Format("move file failed! copy src file fail, errno:%d, [%s] to [%s] ", errno, srcPath.c_str(),destPath.c_str());
  660. Sleep(1000);
  661. }
  662. }
  663. return isSucc;
  664. }
  665. else {
  666. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("move file failed! changefileAtt fail, errno:%d, [%s] to [%s] ", errno, srcPath.c_str(),destPath.c_str());
  667. errmsg = CSimpleStringA::Format("move file failed! changefileAtt fail, errno:%d, [%s] to [%s] ", errno, srcPath.c_str(),destPath.c_str());
  668. return false;
  669. }
  670. #endif
  671. }else if(m_fsm->m_currUploadFile->after_deal_type=="N"){
  672. return true;
  673. }else{
  674. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("file [%s] invalid after_deal_type=%s",m_fsm->m_currUploadFile->fileName.c_str(),m_fsm->m_currUploadFile->after_deal_type.c_str());
  675. errmsg = CSimpleStringA::Format("invalid after_deal_type=%s",m_fsm->m_currUploadFile->after_deal_type.c_str());
  676. return false;
  677. }
  678. }
  679. };
  680. }
  681. void UploadFSM::OnStateTrans( int iSrcState, int iDstState )
  682. {
  683. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("trans from %s to %s", GetStateName(iSrcState), GetStateName(iDstState));
  684. }
  685. void UploadFSM::OnSysVarEvent( const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName )
  686. {
  687. //DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("rx sysvar %s from %s, %s to %s", pszKey, pszEntityName, pszOldValue, pszValue);
  688. if (pszValue[0] == 'O') {
  689. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("rx sysvar %s from %s, %s to %s", pszKey, pszEntityName, pszOldValue, pszValue);
  690. m_isOffLine = true;
  691. PostEventFIFO(new FSMEvent(USER_EVT_JMP_ENABLE));
  692. } else {
  693. if (m_isOffLine) {
  694. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("rx sysvar %s from %s, %s to %s", pszKey, pszEntityName, pszOldValue, pszValue);
  695. }
  696. m_isOffLine = false;
  697. PostEventFIFO(new FSMEvent(USER_EVT_JMP_DISABLE));
  698. }
  699. }
  700. ErrorCodeEnum UploadFSM::OnInit()
  701. {
  702. ErrorCodeEnum Error;
  703. CSimpleStringA checkStr="";
  704. CSmartPointer<IConfigInfo> spConfig;
  705. Error = m_pEntity->GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
  706. if(Error==Error_Succeed){
  707. //获取模式控制参数
  708. m_centerModel = (int)centerModel;//强制总行模式
  709. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("model is centerModel, CenterModel = %d", m_centerModel);
  710. //增加总行接口Url参数
  711. CSimpleStringA str="";
  712. Error = spConfig->ReadConfigValue("upload", "QueryPlanUrl", str);
  713. if (Error == Error_Succeed)
  714. {
  715. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("[CenterUrl] QueryPlanUrl =%s",str.GetData());
  716. m_centerUrl.queryPlanUrl = str.GetData();
  717. }
  718. else
  719. {
  720. return Error;
  721. }
  722. Error = spConfig->ReadConfigValue("upload", "QueryTempFileUrl", str);
  723. if (Error == Error_Succeed)
  724. {
  725. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("[CenterUrl] QueryTempFileUrl =%s",str.GetData());
  726. m_centerUrl.queryTempFileUrl = str.GetData();
  727. }
  728. else
  729. {
  730. return Error;
  731. }
  732. Error = spConfig->ReadConfigValue("upload", "UpdateStateUrl", str);
  733. if (Error == Error_Succeed)
  734. {
  735. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("[CenterUrl] UpdateStateUrl =%s",str.GetData());
  736. m_centerUrl.updateStateUrl = str.GetData();
  737. }
  738. else
  739. {
  740. return Error;
  741. }
  742. Error = spConfig->ReadConfigValue("upload", "AddUploadFailUrl", str);
  743. if (Error == Error_Succeed)
  744. {
  745. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("[CenterUrl] AddUploadFailUrl =%s",str.GetData());
  746. m_centerUrl.addUploadFailUrl = str.GetData();
  747. }
  748. else
  749. {
  750. return Error;
  751. }
  752. Error = spConfig->ReadConfigValue("upload", "EachUploadLen", str);
  753. if (Error == Error_Succeed)
  754. {
  755. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("[CenterUrl] EachUploadLen =%s",str.GetData());
  756. if(str.IsNullOrEmpty()){
  757. m_eachUploadLen = UPLOAD_CONTENT_EACH_LEN;
  758. }else{
  759. m_eachUploadLen = atoi(str.GetData())*1024;
  760. }
  761. }
  762. else
  763. {
  764. return Error;
  765. }
  766. int uploadMaxNum = 0;
  767. Error = spConfig->ReadConfigValueInt("upload", "UploadMaxNum", uploadMaxNum);
  768. if (Error == Error_Succeed)
  769. {
  770. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("[CenterUrl] UploadMaxNum =%d",uploadMaxNum);
  771. if(uploadMaxNum<=10){
  772. m_uploadMaxNum = 200;
  773. }else{
  774. m_uploadMaxNum = uploadMaxNum;
  775. }
  776. }
  777. else
  778. {
  779. return Error;
  780. }
  781. //获取系统文件根路径
  782. CSimpleStringA runPath ;
  783. Error =this->GetEntityBase()->GetFunction()->GetPath("rvc",runPath);//例如:C:\\Run /opt/Run
  784. if(Error_Succeed == Error){
  785. if(!runPath.IsNullOrEmpty()){
  786. string runPathStr = runPath.GetData();
  787. #ifdef RVC_OS_WIN
  788. int pos = runPathStr.find_last_of('\\');
  789. #else
  790. int pos = runPathStr.find_last_of(SPLIT_SLASH);//修改为路径分隔符
  791. #endif
  792. m_rootPath = runPathStr.substr(0,pos);
  793. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("get rvc path is %s",m_rootPath.c_str());
  794. }else{
  795. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("get rvc path is null");
  796. return Error_Unexpect;
  797. }
  798. }else{
  799. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("get rvc path is error");
  800. return Error_Unexpect;
  801. }
  802. }else{
  803. return Error;
  804. }
  805. Error = m_pEntity->GetFunction()->RegistSysVarEvent("CallState", this);
  806. if (Error == Error_Succeed) {
  807. AddStateHooker(this);
  808. }
  809. //......
  810. return Error;
  811. }
  812. ErrorCodeEnum UploadFSM::OnExit()
  813. {
  814. m_pEntity->GetFunction()->UnregistSysVarEvent("CallState");
  815. return Error_Succeed;
  816. }
  817. void UploadFSM::s0_on_entry()
  818. {
  819. CSimpleStringA strValue;
  820. ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSysVar("CallState", strValue);
  821. if (Error == Error_Succeed) {
  822. if (strValue[0] == 'O') { // only upload when CallState in offline state
  823. PostEventLIFO(new FSMEvent(USER_EVT_JMP_ENABLE));
  824. } else {
  825. PostEventLIFO(new FSMEvent(USER_EVT_JMP_DISABLE));
  826. }
  827. }
  828. }
  829. void UploadFSM::s0_on_exit()
  830. {
  831. }
  832. unsigned int UploadFSM::s0_on_event( FSMEvent* event )
  833. {
  834. return 0;
  835. }
  836. void UploadFSM::s1_on_entry()
  837. {
  838. ScheduleTimer(8, 30000);
  839. }
  840. void UploadFSM::s1_on_exit()
  841. {
  842. CancelTimer(8);
  843. }
  844. unsigned int UploadFSM::s1_on_event(FSMEvent* event)
  845. {
  846. if (event->iEvt == EVT_TIMER) {
  847. if(m_isOffLine){
  848. PostEventLIFO(new FSMEvent(USER_EVT_JMP_ENABLE));
  849. }else{
  850. ScheduleTimer(8, 30000);//继续等待
  851. }
  852. }
  853. return 0;
  854. }
  855. void UploadFSM::s2_on_entry()
  856. {
  857. m_uploadModel = true;//默认总行上传模式
  858. //清理上次扫描文件列表,扫描计划,分行ip列表
  859. if(m_uploadList!=NULL){
  860. list<UploadFileInfo*>::iterator iter ;
  861. for(iter=m_uploadList->begin();iter!=m_uploadList->end();++iter){
  862. delete *iter;
  863. }
  864. m_uploadList->clear();
  865. }
  866. if(m_uploadPlanList!=NULL){
  867. list<UploadPlan*>::iterator iter ;
  868. for(iter=m_uploadPlanList->begin();iter!=m_uploadPlanList->end();++iter){
  869. delete *iter;
  870. }
  871. m_uploadPlanList->clear();
  872. }
  873. m_branchIpList.clear();
  874. if(m_centerModel == (int)centerModel){
  875. //DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("centerModel");
  876. //防止url无效,新模式直接停止上传 等待下一次
  877. if(m_centerUrl.addUploadFailUrl.empty()||m_centerUrl.queryPlanUrl.empty()||
  878. m_centerUrl.queryTempFileUrl.empty()||m_centerUrl.updateStateUrl.empty()){
  879. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("centerModel mode ,centerUrl is null , wait for next time");
  880. ScheduleTimer(1, 120000);
  881. return ;
  882. }
  883. //新模式,查询策略
  884. if(queryPlan()){
  885. m_uploadModel = true;
  886. }else{
  887. //查询策略失败,等待下一次
  888. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("queryPlan is fail , wait for next time");
  889. ScheduleTimer(1, 120000);
  890. return ;
  891. }
  892. }else{
  893. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("m_centerModel is invalid");
  894. ScheduleTimer(1, 120000);
  895. return;
  896. }
  897. if(m_uploadModel){
  898. //新模式扫描
  899. PostEventLIFO(new FSMEvent(USER_EVT_JMP_NEW_SCAN));
  900. }else{
  901. //旧模式扫描
  902. PostEventLIFO(new FSMEvent(USER_EVT_JMP_OLD_SCAN));
  903. }
  904. }
  905. void UploadFSM::s2_on_exit()
  906. {
  907. CancelTimer(1);
  908. }
  909. unsigned int UploadFSM::s2_on_event(FSMEvent* event)
  910. {
  911. if (event->iEvt == EVT_TIMER) {
  912. m_uploadModel = true;//默认是分行上传模式
  913. //清理上次扫描文件列表,扫描计划,分行ip列表
  914. if(m_uploadList!=NULL){
  915. list<UploadFileInfo*>::iterator iter ;
  916. for(iter=m_uploadList->begin();iter!=m_uploadList->end();++iter){
  917. delete *iter;
  918. }
  919. m_uploadList->clear();
  920. }
  921. if(m_uploadPlanList!=NULL){
  922. list<UploadPlan*>::iterator iter ;
  923. for(iter=m_uploadPlanList->begin();iter!=m_uploadPlanList->end();++iter){
  924. delete *iter;
  925. }
  926. m_uploadPlanList->clear();
  927. }
  928. m_branchIpList.clear();
  929. //上传模式确定
  930. if(m_centerModel == (int)centerModel){
  931. //DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("centerModel");
  932. //防止url无效,新模式直接停止上传,等待下一次
  933. if(m_centerUrl.addUploadFailUrl.empty()||m_centerUrl.queryPlanUrl.empty()||
  934. m_centerUrl.queryTempFileUrl.empty()||m_centerUrl.updateStateUrl.empty()){
  935. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("centerModel mode ,centerUrl is null , wait for next time");
  936. ScheduleTimer(1, 240000);
  937. return 0;
  938. }
  939. //新模式,查询策略
  940. if(queryPlan()){
  941. m_uploadModel = true;
  942. }else{
  943. //查询策略失败,等待下一次
  944. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("queryPlan is fail , wait for next time");
  945. ScheduleTimer(1, 240000);
  946. return 0;
  947. }
  948. }else{
  949. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("m_centerModel is invalid");
  950. ScheduleTimer(1, 240000);
  951. return 0;
  952. }
  953. if(m_uploadModel){
  954. //新模式扫描
  955. PostEventLIFO(new FSMEvent(USER_EVT_JMP_NEW_SCAN));
  956. }else{
  957. //旧模式扫描
  958. PostEventLIFO(new FSMEvent(USER_EVT_JMP_OLD_SCAN));
  959. }
  960. }else if (event->iEvt == USER_EVT_JMP_NEW_SCAN) {
  961. //DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("enter new model upload");
  962. //新模式
  963. if (m_uploadList->size() == 0) {
  964. //重新扫描文件
  965. scanFile();
  966. }
  967. if (m_uploadList->size() == 0) {
  968. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("m_uploadList is 0,wait for 8 min retry scan");
  969. ScheduleTimer(1, 480000);
  970. } else {
  971. PostEventLIFO(new FSMEvent(USER_EVT_JMP_NEW_UPLOAD));//跳到新的上传状态
  972. }
  973. }
  974. return 0;
  975. }
  976. void UploadFSM::s3_on_entry()
  977. {
  978. }
  979. void UploadFSM::s3_on_exit()
  980. {
  981. }
  982. unsigned int UploadFSM::s3_on_event(FSMEvent* event)
  983. {
  984. return 0;
  985. }
  986. void UploadFSM::s4_on_entry()
  987. {
  988. }
  989. void UploadFSM::s4_on_exit()
  990. {
  991. }
  992. unsigned int UploadFSM::s4_on_event(FSMEvent* event)
  993. {
  994. return 0;
  995. }
  996. void UploadFSM::s5_on_entry()
  997. {
  998. }
  999. void UploadFSM::s5_on_exit()
  1000. {
  1001. }
  1002. unsigned int UploadFSM::s5_on_event(FSMEvent* event)
  1003. {
  1004. return 0;
  1005. }
  1006. void UploadFSM::s6_on_entry()
  1007. {
  1008. }
  1009. void UploadFSM::s6_on_exit()
  1010. {
  1011. }
  1012. unsigned int UploadFSM::s6_on_event(FSMEvent* event)
  1013. {
  1014. return 0;
  1015. }
  1016. void UploadFSM::s7_on_entry()
  1017. {
  1018. //新上传模式
  1019. m_uploadReport.sum = m_uploadList->size();
  1020. m_uploadReport.succ = 0;
  1021. m_uploadReport.fail = 0;
  1022. m_uploadReport.uploadFail = 0;
  1023. m_uploadReport.updateState = 0;
  1024. m_uploadReport.decodeFail = 0;
  1025. m_uploadReport.operateFileFail= 0;
  1026. m_uploadReport.queryTempFail =0;
  1027. m_uploadReport.isBreak =false;
  1028. //获取一个新文件,发送上传请求线程
  1029. if(m_uploadList->size()>0){
  1030. m_currUploadFile = *(m_uploadList->begin());//首元素赋值给全局变量
  1031. m_uploadList->pop_front();//去除首元素
  1032. Task::SendFileTask* task = new Task::SendFileTask(this);
  1033. ErrorCodeEnum rc = this->GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  1034. if (rc != Error_Succeed)
  1035. {
  1036. if(m_currUploadFile!=NULL){
  1037. delete m_currUploadFile;
  1038. m_currUploadFile=NULL;
  1039. }
  1040. LogError(Severity_Middle, rc, 0, "Post SendFileTask task to Thread is fail,wait 30s retry");
  1041. ScheduleTimer(7, 30000);
  1042. }
  1043. }
  1044. }
  1045. void UploadFSM::s7_on_exit()
  1046. {
  1047. if(m_currUploadFile!=NULL){
  1048. delete m_currUploadFile;
  1049. m_currUploadFile=NULL;
  1050. }
  1051. CancelTimer(7);
  1052. }
  1053. unsigned int UploadFSM::s7_on_event(FSMEvent* event)
  1054. {
  1055. if (event->iEvt == USER_EVT_UPLOAD_SUCC) {
  1056. m_uploadReport.succ++;//成功计数
  1057. //获取新的上传文件,发送上传请求线程
  1058. //判断是否已经需要退出
  1059. //无文件,跳出此状态
  1060. if(m_isOffLine){
  1061. if(m_uploadList->size()>0){
  1062. if(m_currUploadFile!=NULL){
  1063. delete m_currUploadFile;
  1064. m_currUploadFile=NULL;
  1065. }
  1066. m_currUploadFile = *(m_uploadList->begin());//首元素赋值给全局变量
  1067. m_uploadList->pop_front();//去除首元素
  1068. Task::SendFileTask* task = new Task::SendFileTask(this);
  1069. ErrorCodeEnum rc = this->GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  1070. if (rc != Error_Succeed)
  1071. {
  1072. if(m_currUploadFile!=NULL){
  1073. delete m_currUploadFile;
  1074. m_currUploadFile=NULL;
  1075. }
  1076. m_uploadReport.isBreak =true;
  1077. reportBatchMsg();
  1078. LogError(Severity_Middle, rc, 0, "Post SendFileTask task to Thread is fail,wait 240s retry scan");
  1079. ScheduleTimer(7, 240000);
  1080. }
  1081. }else{
  1082. m_uploadReport.isBreak =false;
  1083. reportBatchMsg();
  1084. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("NewUpload m_uploadList is empty,wait 240s retry scan");
  1085. ScheduleTimer(7, 240000);// goto s2
  1086. }
  1087. }else{
  1088. m_uploadReport.isBreak =true;
  1089. reportBatchMsg();
  1090. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("NewUpload m_isOffLine is false,jump s1");
  1091. PostEventLIFO(new FSMEvent(USER_EVT_JMP_NEW_DISABLE));// goto s1
  1092. }
  1093. }else if (event->iEvt == USER_EVT_UPLOAD_FAIL) {
  1094. m_uploadReport.fail++;//失败计数
  1095. //获取新的上传文件,发送上传请求线程
  1096. //判断是否已经需要退出
  1097. //无文件,跳出此状态
  1098. if(m_isOffLine){
  1099. Sleep(3000);//上传失败,等待3秒再下一个
  1100. if(m_uploadList->size()>0){
  1101. if(m_currUploadFile!=NULL){
  1102. delete m_currUploadFile;
  1103. m_currUploadFile=NULL;
  1104. }
  1105. m_currUploadFile = *(m_uploadList->begin());//首元素赋值给全局变量
  1106. m_uploadList->pop_front();//去除首元素
  1107. Task::SendFileTask* task = new Task::SendFileTask(this);
  1108. ErrorCodeEnum rc = this->GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  1109. if (rc != Error_Succeed)
  1110. {
  1111. if(m_currUploadFile!=NULL){
  1112. delete m_currUploadFile;
  1113. m_currUploadFile=NULL;
  1114. }
  1115. m_uploadReport.isBreak =true;
  1116. reportBatchMsg();
  1117. LogError(Severity_Middle, rc, 0, "Post SendFileTask task to Thread is fail,wait 240s retry scan");
  1118. ScheduleTimer(7, 240000);
  1119. }
  1120. }else{
  1121. m_uploadReport.isBreak =false;
  1122. reportBatchMsg();
  1123. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("NewUpload m_uploadList is empty,wait 240s retry scan");
  1124. ScheduleTimer(7, 240000);// goto s2
  1125. }
  1126. }else{
  1127. m_uploadReport.isBreak =true;
  1128. reportBatchMsg();
  1129. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("NewUpload m_isOffLine is false,jump s1");
  1130. PostEventLIFO(new FSMEvent(USER_EVT_JMP_NEW_DISABLE));// goto s1
  1131. }
  1132. }else if (event->iEvt == EVT_TIMER) {
  1133. // goto s2
  1134. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("NewUpload ,jump to s2");
  1135. }
  1136. return 0;
  1137. }
  1138. //通过
  1139. bool UploadFSM::queryPlan()
  1140. {
  1141. IHttpFunc* client;
  1142. client = create_http(HttpsLogCallBack);
  1143. CSystemStaticInfo si;
  1144. ErrorCodeEnum error = this->GetEntityBase()->GetFunction()->GetSystemStaticInfo(si);
  1145. if(error!=Error_Succeed){
  1146. return false;//获取失败,走旧模式
  1147. }
  1148. UploadQueryPlanReq planReq;
  1149. UploadQueryPlanRet planRet;
  1150. Json::Value rootReq;
  1151. Json::FastWriter writer;
  1152. rootReq["terminal_no"] = si.strTerminalID.GetData();
  1153. #ifdef RVC_OS_WIN
  1154. rootReq["os_type"] = "WIN";
  1155. #else
  1156. rootReq["os_type"] = "UOS";
  1157. #endif
  1158. string jsonReq = writer.write(rootReq);
  1159. planReq.m_reqStr = jsonReq;
  1160. //planReq.m_printDbg = true;
  1161. planReq.m_url = m_centerUrl.queryPlanUrl.c_str();
  1162. PROCESS_LINK_CONTEXT("LR0402104QueryPlan")
  1163. if(!client->Post(planReq, planRet, &nextLink)){
  1164. LogWarn(Severity_Middle, Error_Unexpect, LOG_WARN_UPLOAD_QUERY_PLAN_ERROR, CSimpleStringA::Format("queryPlan http req fail,url is %s, err=%s",m_centerUrl.queryPlanUrl.c_str(),planRet.m_errMsg.c_str()).GetData());
  1165. client->Destory();
  1166. return false;//http错误,走旧模式
  1167. }
  1168. client->Destory();
  1169. //解析回应报文
  1170. Json::Reader reader;
  1171. Json::Value rootRet;
  1172. if (!reader.parse(planRet.m_retStr, rootRet, false))
  1173. {
  1174. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("queryPlan parse resp is fail");
  1175. return false;//解析失败,走旧模式
  1176. }
  1177. bool isSucc = rootRet["success"].asBool();
  1178. if(isSucc){
  1179. if(rootRet.isMember("data")){
  1180. if(rootRet["data"]["mode"].asBool()){
  1181. //新模式
  1182. string branchNO = rootRet["data"]["branch_no"].asString();
  1183. //分行服务器列表:可能为空
  1184. if(rootRet["data"]["upload_address"].isMember("upload_url")){
  1185. for(int i =0;i<rootRet["data"]["upload_address"]["upload_url"].size();i++){
  1186. string bUploadUrl = rootRet["data"]["upload_address"]["upload_url"][i].asString();
  1187. m_branchIpList[i+1]=bUploadUrl;
  1188. if(!bUploadUrl.empty()){
  1189. // DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("queryPlan return upload_url=%s",bUploadUrl.c_str());
  1190. }else{
  1191. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("queryPlan return upload_url=");
  1192. }
  1193. }
  1194. }else{
  1195. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("[data][upload_address][upload_url] is null");
  1196. }
  1197. string env = "";//上传服务器地址属于行内还是行外
  1198. if(rootRet["data"]["upload_address"].isMember("env")){
  1199. env = rootRet["data"]["upload_address"]["env"].asString();
  1200. if(strcmp(env.c_str(),"DMZ")==0||strcmp(env.c_str(),"BIZ")==0){
  1201. }else{
  1202. LogWarn(Severity_Middle, Error_Unexpect, LOG_WARN_UPLOAD_QUERY_PLAN_DATA_ERROR, CSimpleStringA::Format("queryPlan http req fail, return [data][upload_address][env] is invaild [%s]",env.c_str()).GetData());
  1203. return false;//上传服务ip环境不正确,走旧模式
  1204. }
  1205. }else{
  1206. LogWarn(Severity_Middle, Error_Unexpect, LOG_WARN_UPLOAD_QUERY_PLAN_DATA_ERROR, CSimpleStringA::Format("queryPlan http req fail, return [data][upload_address][env] is null").GetData());
  1207. return false;//上传服务ip环境为空,走旧模式
  1208. }
  1209. //扫描策略:可能为空
  1210. for (int i =0;i <rootRet["data"]["plan_list"].size();i++){
  1211. UploadPlan* p = new UploadPlan();
  1212. p->plan_id = rootRet["data"]["plan_list"][i]["plan_id"].asString();
  1213. p->branch_no = branchNO;//分行号
  1214. p->plan_type = rootRet["data"]["plan_list"][i]["plan_type"].asString();
  1215. p->file_type = rootRet["data"]["plan_list"][i]["file_type"].asString();
  1216. p->path_type = rootRet["data"]["plan_list"][i]["path_type"].asString();
  1217. #ifdef RVC_OS_WIN
  1218. p->path_name = rootRet["data"]["plan_list"][i]["path_name"].asString();
  1219. #else
  1220. //转义路径里面windows反斜杠'\'为'/'
  1221. //p->path_name = rootRet["data"]["plan_list"][i]["path_name"].asString();
  1222. string pathName = rootRet["data"]["plan_list"][i]["path_name"].asString();
  1223. std::replace(pathName.begin(), pathName.end(), '\\', SPLIT_SLASH);
  1224. p->path_name = pathName.c_str();
  1225. #endif
  1226. p->file_name = rootRet["data"]["plan_list"][i]["file_name"].asString();
  1227. p->file_regex = rootRet["data"]["plan_list"][i]["file_regex"].asString();
  1228. p->before_deal_type = rootRet["data"]["plan_list"][i]["before_deal_type"].asString();
  1229. p->after_deal_type = rootRet["data"]["plan_list"][i]["after_deal_type"].asString();
  1230. #ifdef RVC_OS_WIN
  1231. p->after_deal_text = rootRet["data"]["plan_list"][i]["after_deal_text"].asString();
  1232. #else
  1233. //转义路径里面windows反斜杠'\'为'/'
  1234. //p->after_deal_text = rootRet["data"]["plan_list"][i]["after_deal_text"].asString();
  1235. string afterDealText = rootRet["data"]["plan_list"][i]["after_deal_text"].asString();
  1236. std::replace(afterDealText.begin(), afterDealText.end(), '\\', SPLIT_SLASH);
  1237. p->after_deal_text = afterDealText.c_str();
  1238. #endif
  1239. p->file_limit = rootRet["data"]["plan_list"][i]["file_limit"].asInt();
  1240. if (p->file_limit <= 0) {
  1241. //默认文件最大扫描个数为1000
  1242. p->file_length_limit = 1000;
  1243. }
  1244. p->file_length_limit = rootRet["data"]["plan_list"][i]["file_length_limit"].asInt();//增加扫描文件最大长度限制
  1245. if(p->file_length_limit==0){
  1246. //默认扫描文件最大长度设置为200m
  1247. p->file_length_limit = 200;
  1248. }
  1249. p->max_silent = rootRet["data"]["plan_list"][i]["max_silent"].asInt();
  1250. if (p->max_silent <= 0) {
  1251. //默认文件流逝时间间隔为900s
  1252. p->file_length_limit = 900;
  1253. }
  1254. p->upload_address_env = env;
  1255. m_uploadPlanList->push_back(p);
  1256. }
  1257. if(m_branchIpList.size()==0){
  1258. LogWarn(Severity_Middle, Error_Unexpect, LOG_WARN_UPLOAD_QUERY_PLAN_DATA_ERROR, CSimpleStringA::Format("queryPlan http req fail, return upload_url count is 0, url is %s",m_centerUrl.queryPlanUrl.c_str()).GetData());
  1259. return false;//上传服务ip为空,走旧模式
  1260. }
  1261. if(m_uploadPlanList->size()==0){
  1262. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("queryPlan return %d plan ",m_uploadPlanList->size());
  1263. return true;//等待下一次请求,走新模式
  1264. }
  1265. return true;//明确走新模式
  1266. }else{
  1267. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("queryPlan return [data].[mode] is false");
  1268. return false;//明确走旧模式
  1269. }
  1270. }else{
  1271. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("queryPlan return data is null");
  1272. return false;//无data字段,走旧模式
  1273. }
  1274. }else{
  1275. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("queryPlan return success is false");
  1276. return false;//服务返回错误,走旧模式
  1277. }
  1278. }
  1279. //通过
  1280. void UploadFSM::scanFile()
  1281. {
  1282. list<UploadPlan*>::iterator iter;
  1283. for(iter = m_uploadPlanList->begin();iter!=m_uploadPlanList->end();++iter){
  1284. UploadPlan* up = *iter;
  1285. //构建初始的扫描根路径
  1286. string path="";
  1287. if(up->path_type=="R"){
  1288. #ifdef RVC_OS_WIN
  1289. path = m_rootPath + "\\" + up->path_name;
  1290. #else
  1291. path = m_rootPath + SPLIT_SLASH_STR + up->path_name;
  1292. #endif
  1293. }else if(up->path_type=="A"){
  1294. path=up->path_name;
  1295. }else{
  1296. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("plan path_type is invalid path_type=%s",up->path_type.c_str());
  1297. continue;
  1298. }
  1299. if(m_printPlan){
  1300. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("planID=[%s], scanDir=[%s], filter=[%s], file_limit=[%d], max_silent=[%d]",up->plan_id.c_str(),path.c_str(),up->file_name.c_str(),up->file_limit,up->max_silent);
  1301. }
  1302. scanDirfresh(up,path.c_str());
  1303. }
  1304. m_printPlan=false;//只打印一次,设置为不打印
  1305. //加入文件超过阈值后告警
  1306. if(m_uploadList->size()>m_uploadMaxNum){
  1307. LogWarn(Severity_Middle, Error_Unexpect, LOG_WARN_UPLOAD_MAX_ERROR, CSimpleStringA::Format("upload list num(%d) is over max num",m_uploadList->size()).GetData());
  1308. }
  1309. }
  1310. //通过
  1311. void UploadFSM::scanDirfresh(UploadPlan* plan,const char *path)
  1312. {
  1313. array_header_t *arr_files = fileutil_get_sub_files2_a(path, plan->file_limit);
  1314. if (arr_files) {
  1315. int i;
  1316. for (i = 0; i < arr_files->nelts; ++i){
  1317. char *file_path = ARRAY_IDX(arr_files, i, char*);
  1318. //得到文件名
  1319. string fileName = _GetFileName(file_path);
  1320. //文件名通配符过滤
  1321. CSimpleStringA strFileFilter = _GetFileName(plan->file_name.c_str());
  1322. if(!IsFileMatch(strFileFilter.GetData(),fileName.c_str())){
  1323. continue;//继续下一个文件
  1324. }
  1325. //正则表达式过滤
  1326. if(!plan->file_regex.empty()){
  1327. regex e(plan->file_regex.c_str());
  1328. if(!regex_match(fileName.c_str(),e,regex_constants::match_default)){
  1329. continue;//继续下一个文件
  1330. }
  1331. }
  1332. #ifdef RVC_OS_WIN
  1333. //最后修改时间间隔过滤
  1334. WIN32_FILE_ATTRIBUTE_DATA attr;
  1335. if (!GetFileAttributesExA(file_path, GetFileExInfoStandard, &attr)) {
  1336. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("get local file attrr fail! file_path=%s",file_path);
  1337. continue;//继续下一个文件
  1338. }
  1339. //判断文件是否超过最大扫描文件长度
  1340. unsigned long limit = plan->file_length_limit*1024*1024;
  1341. if(attr.nFileSizeLow>limit){
  1342. if (!findOverLenWarn(file_path)) {
  1343. //未找到则告警
  1344. CSimpleStringA warnStr = CSimpleStringA::Format("local file len (%u), over file_length_limit (%d)m, file_path=%s", attr.nFileSizeLow, plan->file_length_limit, file_path);
  1345. LogWarn(Severity_Low, Error_Unexpect, LOG_WARN_UPLOAD_QUERY_FILE_OVER_LIMIT, warnStr.GetData());
  1346. }
  1347. continue;//继续下一个文件
  1348. }
  1349. FILETIME fttmp;
  1350. SYSTEMTIME filest;
  1351. SYSTEMTIME st;
  1352. if(!FileTimeToLocalFileTime(&attr.ftLastWriteTime,&fttmp)){
  1353. continue;//继续下一个文件
  1354. }
  1355. if(!FileTimeToSystemTime(&fttmp,&filest)){
  1356. continue;//继续下一个文件
  1357. }
  1358. GetLocalTime(&st);
  1359. int nsecondsInterval = (st.wYear-filest.wYear)*32140800+(st.wMonth-filest.wMonth)*2678400+(st.wDay-filest.wDay)*86400+(st.wHour-filest.wHour)*3600+(st.wMinute-filest.wMinute)*60+(st.wSecond-filest.wSecond);
  1360. if(nsecondsInterval<plan->max_silent){
  1361. continue;//继续下一个文件,时间不够
  1362. }else{
  1363. //时间已够,判断文件是否能独占锁
  1364. if(!test_zero_ref(file_path)){
  1365. continue;//继续下一个文件
  1366. }
  1367. }
  1368. //得到文件长度
  1369. unsigned long filelen = attr.nFileSizeLow;
  1370. #else
  1371. struct stat attr_of_src;
  1372. if (lstat(file_path, &attr_of_src) != 0) {
  1373. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("get local file attrr fail! file_path=%s", file_path);
  1374. continue;//继续下一个文件
  1375. }
  1376. //判断文件是否超过最大扫描文件长度
  1377. unsigned long limit = plan->file_length_limit * 1024 * 1024;
  1378. if (attr_of_src.st_size > limit) {
  1379. CSimpleStringA warnStr = CSimpleStringA::Format("local file len (%u), over file_length_limit (%d)m, file_path=%s", attr_of_src.st_size, plan->file_length_limit, file_path);
  1380. LogWarn(Severity_Low, Error_Unexpect, LOG_WARN_UPLOAD_QUERY_FILE_OVER_LIMIT, warnStr.GetData());
  1381. continue;//继续下一个文件
  1382. }
  1383. time_t nowTime = time((time_t*)NULL);//当前时间
  1384. if (nowTime > attr_of_src.st_mtime)
  1385. {
  1386. long diff = nowTime - attr_of_src.st_mtime;
  1387. if (diff < plan->max_silent)
  1388. {
  1389. continue;//继续下一个文件,时间不够
  1390. }else{
  1391. //时间已够,判断文件是否能独占锁
  1392. if (!test_zero_ref(file_path)) {
  1393. continue;//继续下一个文件
  1394. }
  1395. }
  1396. }else {
  1397. continue;//继续下一个文件,时间不够
  1398. }
  1399. //得到文件长度
  1400. unsigned long filelen = attr_of_src.st_size;
  1401. #endif
  1402. //添加扫描文件
  1403. UploadFileInfo* upFile = new UploadFileInfo();
  1404. upFile->firstMD5Str = "";
  1405. upFile->lastMD5Str = "";
  1406. upFile->fileName = fileName;
  1407. upFile->filePath = file_path;
  1408. if(upFile->filePath.length()>900){
  1409. //路径太长,ECS存储有问题,截取路径,并加入模拟路径前缀:window S:\\ , linux /S/
  1410. #ifdef RVC_OS_WIN
  1411. upFile->fileUploadPath.append("S:\\");
  1412. #else
  1413. upFile->fileUploadPath.append("/S/");
  1414. #endif
  1415. upFile->fileUploadPath.append(fileName.c_str());
  1416. //upFile->fileUploadRelativePath = "S:\\";
  1417. }else{
  1418. //直接赋值
  1419. upFile->fileUploadPath = file_path;
  1420. //upFile->fileUploadRelativePath = upFile->fileUploadPath.substr(0,upFile->fileUploadPath.length()-fileName.length());//截取文件名称的路径
  1421. }
  1422. upFile->BranchFilePath = file_path;
  1423. upFile->fileLen = filelen;
  1424. #ifdef RVC_OS_WIN
  1425. upFile->editTime = CSimpleStringA::Format("%d-%d-%d %d:%d:%d",filest.wYear, filest.wMonth, filest.wDay, filest.wHour, filest.wMinute, filest.wSecond);
  1426. #else
  1427. tm fileTimeTm = { 0 };
  1428. localtime_r(&attr_of_src.st_mtime, &fileTimeTm);
  1429. upFile->editTime = CSimpleStringA::Format("%d-%d-%d %d:%d:%d", fileTimeTm.tm_year+1900, fileTimeTm.tm_mon+1, fileTimeTm.tm_mday, fileTimeTm.tm_hour, fileTimeTm.tm_min, fileTimeTm.tm_sec);
  1430. #endif
  1431. upFile->plan_id = plan->plan_id;
  1432. upFile->branch_no = plan->branch_no;
  1433. upFile->plan_type = plan->plan_type;
  1434. upFile->file_type = plan->file_type;
  1435. upFile->path_type = plan->path_type;
  1436. upFile->path_name = plan->path_name;//因传回路径可能是windows路径斜杠,转义为linux斜杠
  1437. upFile->file_name = plan->file_name;
  1438. upFile->file_regex = plan->file_regex;
  1439. upFile->before_deal_type = plan->before_deal_type;
  1440. upFile->after_deal_type = plan->after_deal_type;
  1441. upFile->after_deal_text = plan->after_deal_text;
  1442. upFile->file_limit = plan->file_limit;
  1443. upFile->file_length_limit = plan->file_length_limit;
  1444. upFile->max_silent = plan->max_silent;
  1445. upFile->upload_address_env = plan->upload_address_env;
  1446. m_uploadList->push_back(upFile);
  1447. //DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("file %s lenth(%d) added!",file_path,filelen);
  1448. }
  1449. toolkit_array_free2(arr_files);
  1450. }
  1451. array_header_t *arr_dir = fileutil_get_sub_dirs_a(path);
  1452. if (arr_dir) {
  1453. int i;
  1454. for (i = 0; i < arr_dir->nelts; ++i) {
  1455. char *dir_path = ARRAY_IDX(arr_dir, i, char*);
  1456. scanDirfresh(plan, dir_path);
  1457. }
  1458. }
  1459. }
  1460. void UploadFSM::HttpsLogCallBack(const char* logtxt)
  1461. {
  1462. if(logtxt!=NULL){
  1463. DbgWithLink(LOG_LEVEL_DEBUG,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("http dbg: %s",logtxt);
  1464. }
  1465. }
  1466. bool UploadFSM::IsFileMatch(const char *pszFilter, const char *pszFileName)
  1467. {
  1468. const char *p1 = pszFilter;
  1469. const char *p2 = pszFileName;
  1470. if (p1 == NULL)
  1471. return true;
  1472. if (p2 == NULL)
  1473. return false;
  1474. if (*p1 ==NULL && *p2 ==NULL)
  1475. return true;
  1476. else if (*p1 == NULL)
  1477. return false;
  1478. else if (*p2 == NULL)
  1479. {
  1480. // 查找*p1是否全是*
  1481. while(*p1 == '*')
  1482. p1++;
  1483. if (*p1 == NULL)
  1484. return true;
  1485. else
  1486. return false;
  1487. }
  1488. if (*p1 != '*')
  1489. {
  1490. if (tolower(*p1) != tolower(*p2))
  1491. return false;
  1492. else
  1493. return IsFileMatch(p1+1, p2+1);
  1494. }
  1495. else
  1496. {
  1497. while(*++p1 == '*');
  1498. if (*p1 == NULL)
  1499. return true;
  1500. while (*p2)
  1501. {
  1502. while(tolower(*p1) != tolower(*p2) && *++p2);
  1503. if (*p2 == NULL)
  1504. return false;
  1505. if(IsFileMatch(p1+1, p2+1))
  1506. return true;
  1507. p2++;
  1508. }
  1509. return false;
  1510. }
  1511. }
  1512. ErrorCodeEnum UploadFSM::SM3FileToStr(CSimpleStringA strFilePath, CSimpleStringA &strSM3,bool isSub)
  1513. {
  1514. if(strFilePath.IsNullOrEmpty()){
  1515. return Error_Null;
  1516. }
  1517. int nlen = strlen(strFilePath.GetData());
  1518. char* pchar = new char[nlen+1];
  1519. strcpy(pchar,strFilePath.GetData());
  1520. BYTE md5[32]={0};
  1521. try
  1522. {
  1523. if(SM3File(pchar,md5)){
  1524. delete pchar;
  1525. //获取16进制的字符串
  1526. if(Error_Succeed!=SM3_Str(strSM3,md5,isSub)){
  1527. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("sm3国密转16进制字符串失败,file=%s",strFilePath.GetData());
  1528. return Error_Unexpect;
  1529. }
  1530. return Error_Succeed;
  1531. }else{
  1532. delete pchar;
  1533. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("sm3国密加密失败,file=%s",strFilePath.GetData());
  1534. return Error_Unexpect;
  1535. }
  1536. }
  1537. catch (...)
  1538. {
  1539. delete pchar;
  1540. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("sm3国密加密异常失败,file=%s",strFilePath.GetData());
  1541. return Error_Exception;
  1542. }
  1543. }
  1544. ErrorCodeEnum UploadFSM::SM3_Str(CSimpleStringA &strSM3,BYTE * SM3Byte,bool isSub)
  1545. {
  1546. if(SM3Byte == NULL){
  1547. return Error_Exception;
  1548. }
  1549. int SM3_len=64;
  1550. if(isSub){
  1551. SM3_len=32;
  1552. }
  1553. int i;
  1554. char* file_SM3 = (char*)malloc((SM3_len + 1) * sizeof(char));
  1555. if(file_SM3 == NULL)
  1556. {
  1557. fprintf(stderr, "SM3 malloc failed.\n");
  1558. return Error_Exception;
  1559. }
  1560. memset(file_SM3, 0, (SM3_len + 1));
  1561. if(SM3_len == 32)
  1562. {
  1563. for(i=0; i<16; i++)
  1564. { //SM3截取中间16位字节,8-24位字节数,小写
  1565. sprintf(&file_SM3[i*2], "%02x", SM3Byte[i+8]);
  1566. }
  1567. }
  1568. else if(SM3_len == 64)
  1569. {
  1570. for(i=0; i<32; i++)
  1571. {
  1572. sprintf(&file_SM3[i*2], "%02x", SM3Byte[i]);
  1573. }
  1574. }
  1575. strSM3=file_SM3;
  1576. free(file_SM3);
  1577. return Error_Succeed;
  1578. }
  1579. bool UploadFSM::getFileContent(FILE* pFile,unsigned char* content,int beginPos, int contentLen)
  1580. {
  1581. if(pFile==NULL||content==NULL){
  1582. return false;
  1583. }
  1584. #ifdef RVC_OS_WIN
  1585. clearerr(pFile);//尝试先复位错误指针
  1586. #endif
  1587. if(fseek(pFile,beginPos,SEEK_SET)!=0){
  1588. #ifdef RVC_OS_WIN
  1589. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("getFileContent fail,fseek beginPos =%d is error =%d",beginPos,(int)GetLastError());
  1590. #else
  1591. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("getFileContent fail,fseek beginPos =%d is error =%d",beginPos, errno);
  1592. #endif
  1593. return false;
  1594. }
  1595. unsigned char* pRead = content;//移动的指针
  1596. int pRemaind = contentLen; //剩余字节数
  1597. int numBytes = 0;
  1598. while(!feof(pFile)&&!ferror(pFile)){
  1599. if(pRemaind<=0){
  1600. break;
  1601. }
  1602. numBytes=(int)fread(pRead,1,pRemaind,pFile);
  1603. if(numBytes>0){
  1604. pRemaind -=numBytes;
  1605. pRead +=numBytes;
  1606. }
  1607. }
  1608. if(pRemaind==0){
  1609. return true;
  1610. }else{
  1611. #ifdef RVC_OS_WIN
  1612. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("getFileContent fail,pRemaind =%d, error=%d",pRemaind,(int)GetLastError());
  1613. #else
  1614. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("getFileContent fail,pRemaind =%d, error=%d",pRemaind, errno);
  1615. #endif
  1616. return false;
  1617. }
  1618. }
  1619. bool UploadFSM::test_zero_ref(const char *path)
  1620. {
  1621. #ifdef RVC_OS_WIN
  1622. HANDLE hFile = CreateFileA(path,
  1623. GENERIC_READ, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); // try open
  1624. if (hFile != INVALID_HANDLE_VALUE) {
  1625. CloseHandle(hFile);
  1626. return TRUE;
  1627. } else {
  1628. //添加获取句柄失败情况
  1629. LogWarn(Severity_Low, Error_Unexpect, LOG_WARN_UPLOAD_SCANFILE_LOCK_ERROR, CSimpleStringA::Format("test_zero_ref is fail:%s",path).GetData());
  1630. DWORD dwRet = GetLastError();
  1631. return FALSE;
  1632. }
  1633. #else
  1634. //后期改为linux真正的文件锁,现在来看,暂时用不着
  1635. FILE* fp = fopen(path, "rb");
  1636. if (fp != NULL) {
  1637. fclose(fp);
  1638. return true;
  1639. }
  1640. else
  1641. {
  1642. LogWarn(Severity_Low, Error_Unexpect, LOG_WARN_UPLOAD_SCANFILE_LOCK_ERROR, CSimpleStringA::Format("check_zero_ref is fail:%s", path).GetData());
  1643. return false;
  1644. }
  1645. #endif // RVC_OS_WIN
  1646. }
  1647. bool UploadFSM::GetFileLength(const char* filePath,long &fileLen)
  1648. {
  1649. FILE* file = fopen(filePath, "rb");
  1650. if (file!=NULL)
  1651. {
  1652. #ifdef RVC_OS_WIN
  1653. fileLen = filelength(fileno(file));
  1654. fclose(file);
  1655. return true;
  1656. #else
  1657. //取得当前文件流的读取位置
  1658. int cur_pos = ftell(file);
  1659. //将文件流的读取位置设为文件末尾
  1660. if (fseek(file, SEEK_SET, SEEK_END)==0) {
  1661. //获取文件末尾的读取位置,即文件大小
  1662. fileLen = ftell(file);
  1663. //将文件流的读取位置还原为原先的值
  1664. fseek(file, cur_pos, SEEK_SET);
  1665. fclose(file);
  1666. return true;
  1667. }
  1668. else {
  1669. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("fseek file=%s is fail, err=%d", filePath,errno);
  1670. fclose(file);
  1671. return false;
  1672. }
  1673. #endif
  1674. } else{
  1675. fileLen = 0;
  1676. return false;
  1677. }
  1678. }
  1679. void UploadFSM::reportBatchMsg()
  1680. {
  1681. CSimpleStringA strReport;
  1682. if(m_uploadReport.fail==0){
  1683. strReport =CSimpleStringA::Format("batch=succ isbreak=%d sum=%d succ=%d fail=%d detail fail: uploadFail=%d updateState=%d operateFileFail=%d (decodeFail=%d queryTempFail=%d)",
  1684. m_uploadReport.isBreak, m_uploadReport.sum, m_uploadReport.succ, m_uploadReport.fail, m_uploadReport.uploadFail, m_uploadReport.updateState,
  1685. m_uploadReport.operateFileFail, m_uploadReport.decodeFail, m_uploadReport.queryTempFail);
  1686. LogWarn(Severity_Low, Error_Unexpect, LOG_WARN_UPLOAD_FILE_REPORT, strReport.GetData());
  1687. }else{
  1688. strReport =CSimpleStringA::Format("batch=fail isbreak=%d sum=%d succ=%d fail=%d detail fail: uploadFail=%d updateState=%d operateFileFail=%d (decodeFail=%d queryTempFail=%d)",
  1689. m_uploadReport.isBreak, m_uploadReport.sum, m_uploadReport.succ, m_uploadReport.fail, m_uploadReport.uploadFail, m_uploadReport.updateState,
  1690. m_uploadReport.operateFileFail, m_uploadReport.decodeFail, m_uploadReport.queryTempFail);
  1691. LogWarn(Severity_Middle, Error_Unexpect, LOG_WARN_UPLOAD_FILE_REPORT, strReport.GetData());
  1692. }
  1693. //LogWarn(Severity_Middle, Error_Unexpect, LOG_WARN_UPLOAD_FILE_REPORT, strReport.GetData());
  1694. }
  1695. bool UploadFSM::findOverLenWarn(const char* fileName) {
  1696. if (m_overLenFileList != NULL) {
  1697. bool isfind = false;
  1698. list<string>::iterator iter;
  1699. for (iter = m_overLenFileList->begin(); iter != m_overLenFileList->end(); ++iter) {
  1700. string fileStr = *iter;
  1701. if (strcmp(fileName, fileStr.c_str()) == 0) {
  1702. isfind = true;
  1703. break;
  1704. }
  1705. }
  1706. if (!isfind) {
  1707. //未找到,加入队列
  1708. m_overLenFileList->push_back(fileName);
  1709. }
  1710. return isfind;
  1711. }
  1712. return false;
  1713. }