numbercheck.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. #include "numbercheck.h"
  2. #include "wsnumchk.h"
  3. #include "numberreg.h"
  4. #include "unzip.h"
  5. #include "zip.h"
  6. #include "filesplitter.h"
  7. #include "resppackmerge.h"
  8. #include "resppacktran.h"
  9. #include "respforecastseg.h"
  10. #include "respsubminpnum.h"
  11. #include "respchkuserfeestatus.h"
  12. #include "respchkuserfcfeestatus.h"
  13. #include "sncdatabase.h"
  14. NumberCheck::NumberCheck(QString fileName, QString fileType,QString submitWay, QString memo,
  15. NumberCheckMethod method,QString host,QString port, QString userHash)
  16. {
  17. this->fileName = fileName;
  18. this->fileType = fileType;
  19. this->submitWay = submitWay;
  20. this->memo = memo;
  21. this->method = method;
  22. this->host = host;
  23. this->port = port;
  24. this->userHash = userHash;
  25. this->submitOK = false;
  26. this->forecastOK = false;
  27. }
  28. NumberCheck::~NumberCheck()
  29. {
  30. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  31. <<"NumberCheck Destroyed.";
  32. }
  33. void NumberCheck::run()
  34. {
  35. QTime time;
  36. time.start();
  37. emit msgUpdated("N/A","numbercount");
  38. emit msgUpdated("N/A","rtnmsg");
  39. emit msgUpdated("实号N/A,空号N/A,停机N/A,关机N/A","chkresult");
  40. switch(this->method)
  41. {
  42. case JustForeCast:
  43. forecast();
  44. break;
  45. case JustSubmit:
  46. submit();
  47. break;
  48. case SubmitByPack:
  49. submitPack();
  50. break;
  51. default:
  52. break;
  53. }
  54. emit chkFinished();
  55. this->segments.clear();
  56. this->numbers.clear();
  57. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  58. <<"number chk elapse time:"<<time.elapsed();
  59. }
  60. bool NumberCheck::preChkFile()
  61. {
  62. emit msgUpdated("正在验证文件有效性","label");
  63. if(!chkFileInfo())
  64. return false;
  65. return chkNumCount();
  66. }
  67. bool NumberCheck::chkFileInfo()
  68. {
  69. QTime time;
  70. time.start();
  71. QString msg;
  72. int txtFileSize = 13;
  73. int zipFileSize = 4;
  74. QFileInfo fileInfo(this->fileName);
  75. QString suffix = fileInfo.suffix().toLower();
  76. int fileSize = fileInfo.size()/1024/1024;
  77. bool isPass = true;
  78. if(this->fileType == "1")
  79. {
  80. if(suffix!="txt"&&suffix!="zip"&&suffix!="7z"&&suffix!="rar")
  81. {
  82. msg = QString("<font color=red>号码文件必须是压缩包格式或者TXT格式</font>");
  83. isPass = false;
  84. }
  85. }
  86. else
  87. {
  88. if(suffix!="txt")
  89. {
  90. msg = QString("<font color=red>号段文件必须是TXT格式</font>");
  91. isPass = false;
  92. }
  93. }
  94. if(!isPass)
  95. {
  96. emit msgUpdated(msg,"rtnmsg");
  97. return isPass;
  98. }
  99. if(suffix=="txt")
  100. {
  101. if(fileSize>txtFileSize)
  102. {
  103. isPass = false;
  104. msg = QString("<font color=red>TXT格式的文件大小不能大于%1M</font>").arg(txtFileSize);
  105. }
  106. }
  107. else if(suffix=="zip" || suffix=="7z" || suffix=="rar")
  108. {
  109. if(fileSize>zipFileSize)
  110. {
  111. isPass = false;
  112. msg = QString("<font color=red>压缩包格式的文件大小不能大于%1M</font>").arg(zipFileSize);
  113. }
  114. }
  115. if(!isPass)
  116. {
  117. emit msgUpdated(msg,"rtnmsg");
  118. }
  119. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  120. <<"chkFileInfo time is " <<time.elapsed();
  121. return isPass;
  122. }
  123. bool NumberCheck::chkNumCount()
  124. {
  125. QTime time;
  126. time.start();
  127. QString msg;
  128. int minNumbers = 1000;
  129. int maxNumbers = 500000;
  130. bool isPass = true;
  131. if(this->fileType=="1")// "单子类型:号码文件" ;
  132. {
  133. QFileInfo fileinfo(this->fileName);
  134. QString suffix = fileinfo.suffix().toLower();
  135. this->isSegment = false;
  136. if(suffix == "txt" )
  137. {
  138. QStringList fileList;
  139. fileList << this->fileName;
  140. QMap<int,int> map = extractNumberFromTxtFile(fileList);
  141. if(map.size()==0)
  142. {
  143. numCount = 0;
  144. }
  145. else
  146. {
  147. numCount = map.value(0);
  148. }
  149. }
  150. else if(suffix == "zip" || suffix=="7z" || suffix=="rar")
  151. {
  152. QMap<int,int> map = extractTxtFileFromZip(fileName);
  153. if(map.size()==0)
  154. {
  155. this->numCount = 0;
  156. }
  157. else
  158. {
  159. int total = 0;
  160. foreach(int key,map.keys())
  161. {
  162. total += map.value(key);
  163. if(map.value(key)<minNumbers || map.value(key)>maxNumbers)
  164. {
  165. isPass = false;
  166. }
  167. }
  168. this->numCount = total;
  169. }
  170. }
  171. }
  172. else// "单子类型:号段文件" ;
  173. {
  174. this->isSegment = true;
  175. int size = extractSegmentFromTxtFile(this->fileName);
  176. this->numCount = size*10000;
  177. }
  178. if(this->numCount<minNumbers || this->numCount>maxNumbers)
  179. {
  180. msg = QString("<font color=red>文件中的号码总数最少要包含%1个号码,最多包含%2个号码。</font>").arg(minNumbers).arg(maxNumbers);
  181. isPass = false;
  182. }
  183. emit msgUpdated(QString::number(this->numCount),"numbercount");
  184. if(!isPass)
  185. emit msgUpdated(msg,"rtnmsg");
  186. else
  187. {
  188. emit msgUpdated("文件有效性通过验证","rtnmsg");
  189. }
  190. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  191. <<"chkNumCount time is " <<time.elapsed();
  192. return isPass;
  193. }
  194. bool NumberCheck::chkFee()
  195. {
  196. QTime time;
  197. time.start();
  198. WSNumChk *client = new WSNumChk(this->host,this->port);
  199. emit msgUpdated("正在检测是否有足够的余额","label");
  200. QString json = client->chkUserFeeStatus(QString::number(numCount),this->userHash);
  201. qDebug()<<json;
  202. bool pass = false;
  203. if(!json.isEmpty()){
  204. RespChkUserFeeStatus *response = new RespChkUserFeeStatus(json);
  205. if(response->getRtnCode()==1)
  206. {
  207. emit msgUpdated(response->getRtnMemo(),"rtnmsg");
  208. pass = true;
  209. }
  210. else if(response->getRtnCode()==-1)
  211. {
  212. emit msgUpdated("<font color=red>登录超时,请重新登录!</font>","rtnmsg");
  213. }
  214. else
  215. {
  216. emit msgUpdated("<font color=red>"+response->getRtnMemo()+"</font>","rtnmsg");
  217. }
  218. delete response;
  219. }
  220. else
  221. {
  222. emit msgUpdated("网络无法连接,请稍候再试!","rtnmsg");
  223. }
  224. delete client;
  225. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  226. <<"chkFee time is"<<time.elapsed();
  227. return pass;
  228. }
  229. bool NumberCheck::chkFcFee()
  230. {
  231. QTime time;
  232. time.start();
  233. WSNumChk *client = new WSNumChk(this->host,this->port);
  234. emit msgUpdated("正在检测是否有足够的余额","label");
  235. QString json = client->chkUserFcFeeStatus(QString::number(numCount),this->userHash);
  236. bool pass = false;
  237. if(!json.isEmpty()){
  238. RespChkUserFcFeeStatus *response = new RespChkUserFcFeeStatus(json);
  239. if(response->getRtnCode()==1)
  240. {
  241. emit msgUpdated(response->getRtnMemo(),"rtnmsg");
  242. pass = true;
  243. }
  244. else if(response->getRtnCode()==-1)
  245. {
  246. emit msgUpdated("<font color=red>登录超时,请重新登录!</font>","rtnmsg");
  247. }
  248. else
  249. {
  250. emit msgUpdated("<font color=red>"+response->getRtnMemo()+"</font>","rtnmsg");
  251. }
  252. delete response;
  253. }
  254. else
  255. {
  256. emit msgUpdated("网络无法连接,请稍候再试!","rtnmsg");
  257. }
  258. delete client;
  259. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  260. <<"chkFcFee time is "<<time.elapsed();
  261. return pass;
  262. }
  263. void NumberCheck::forecast()
  264. {
  265. this->submitOK = false;
  266. this->forecastOK = false;
  267. if(!preChkFile())
  268. return ;
  269. if(!chkFcFee())
  270. return ;
  271. QTime time;
  272. time.start();
  273. emit msgUpdated("正在进行预检测","label");
  274. QString segdata="";
  275. int segLen = 0;
  276. if(isSegment)
  277. {
  278. for(int i=0;i<segments.size();i++)
  279. {
  280. segdata += segments.at(i)+",10000;";
  281. }
  282. segdata += "END";
  283. segLen = 7;
  284. }
  285. else
  286. {
  287. QString str;
  288. for(int i=7;i>=3;i--)
  289. {
  290. str = createSegData(i);
  291. if(str.isEmpty())
  292. {
  293. continue;
  294. }
  295. else
  296. {
  297. segLen = i;
  298. break;
  299. }
  300. }
  301. if(!str.isEmpty())
  302. {
  303. segdata = str + "END";
  304. }
  305. }
  306. if(segdata.isEmpty())
  307. {
  308. emit msgUpdated("<font color=red>号码数量太少,无法预测。</font>","rtnmsg");
  309. return ;
  310. }
  311. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  312. <<"segdata get time is "<<time.elapsed();
  313. time.start();
  314. WSNumChk *client = new WSNumChk(this->host,this->port);
  315. QString json = client->forecastSeg(segdata,QString::number(segLen),"BASE64",this->userHash);
  316. if(!json.isEmpty()){
  317. RespForeCastSeg *response = new RespForeCastSeg(json);
  318. if(response->getRtnCode()==1)
  319. {
  320. emit msgUpdated(response->getRtnMemo(),"rtnmsg");
  321. QStringList list = response->getFcResult().split(",");
  322. QString str ;
  323. str += "实号" + list.at(0);
  324. str += ",空号" + list.at(1);
  325. str += ",停机" + list.at(2);
  326. str += ",关机" + list.at(3);
  327. str += "。<font color=\"#af0000\">参考度" + list.at(4) + "</font>";
  328. this->forecastOK = true;
  329. emit msgUpdated(str,"chkresult");
  330. }
  331. else if(response->getRtnCode()==-1)
  332. {
  333. emit msgUpdated("<font color=red>登录超时,请重新登录!</font>","rtnmsg");
  334. }
  335. else
  336. {
  337. emit msgUpdated("<font color=red>"+response->getRtnMemo()+"</font>","rtnmsg");
  338. }
  339. delete response;
  340. }
  341. else
  342. {
  343. emit msgUpdated("网络无法连接,请稍候再试!","rtnmsg");
  344. }
  345. delete client;
  346. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  347. <<"forecast time is "<<time.elapsed();
  348. }
  349. QString NumberCheck::createSegData(int len)
  350. {
  351. QString lastseg;
  352. QString data;
  353. int total = 0;
  354. int count = 0;
  355. for(int i=0;i<model.getSegments().size();i++)
  356. {
  357. QString segment = model.getSegments().at(i);
  358. for(int j=0;j<model.getNumbers().at(i).size();j++)
  359. {
  360. QString num = segment+model.getNumbers().at(i).at(j);
  361. QString curseg = num.left(len);
  362. if(lastseg.isEmpty())
  363. {
  364. lastseg = curseg;
  365. count = 1;
  366. }
  367. else
  368. {
  369. if(curseg != lastseg)
  370. {
  371. if(count>=500)
  372. {
  373. data += lastseg + "," + QString::number(count) + ";";
  374. total += count;
  375. }
  376. lastseg = curseg;
  377. count = 1;
  378. }
  379. else
  380. {
  381. count++;
  382. }
  383. if((i == model.getSegments().size()-1) && j == model.getNumbers().at(i).size() - 1)
  384. {
  385. if(count>=500)
  386. {
  387. data += lastseg + "," + QString::number(count) + ";";
  388. total += count;
  389. }
  390. }
  391. }
  392. }
  393. }
  394. //qDebug()<<data;
  395. if(total < model.getCount()*0.7)
  396. data = "";
  397. return data;
  398. }
  399. void NumberCheck::submit()
  400. {
  401. this->submitOK = false;
  402. this->forecastOK = false;
  403. if(!preChkFile())
  404. return ;
  405. if(!chkFee())
  406. return ;
  407. QString zip = zipTxtFile(this->fileName);
  408. if(!zip.isEmpty())
  409. {
  410. this->fileName = zip;
  411. this->zipFileName = zip;
  412. }
  413. else
  414. {
  415. if(!this->zipFileName.isEmpty())
  416. this->fileName = this->zipFileName;
  417. }
  418. QTime time;
  419. time.start();
  420. WSNumChk *client = new WSNumChk(this->host,this->port);
  421. emit msgUpdated("正在提交,请稍候","label");
  422. QString json = client->submitPnumFile(this->fileName,this->fileType,this->submitWay,this->memo,this->userHash);
  423. if(!json.isEmpty()){
  424. RespSubminPNum *response = new RespSubminPNum(json);
  425. if(response->getRtnCode()==2)
  426. {
  427. emit msgUpdated("上传成功,号码全部接收。","rtnmsg");
  428. emit msgUpdated(response->getRtnMemo(),"tooltipok");
  429. this->submitOK = true;
  430. }
  431. else if(response->getRtnCode()==1)
  432. {
  433. emit msgUpdated("上传成功,文件中含有部分非法数据。","rtnmsg");
  434. emit msgUpdated(response->getRtnMemo(),"tooltipwarning");
  435. this->submitOK = true;
  436. }
  437. else if(response->getRtnCode()==-1)
  438. {
  439. emit msgUpdated("<font color=red>登录超时,请重新登录。</font>","rtnmsg");
  440. }
  441. else
  442. {
  443. emit msgUpdated("<font color=red>"+response->getRtnMemo()+"</font>","rtnmsg");
  444. }
  445. delete response;
  446. }
  447. else
  448. {
  449. emit msgUpdated("网络无法连接,请稍候再试!","rtnmsg");
  450. }
  451. delete client;
  452. // if(!this->zipFileName.isEmpty())
  453. // QFile::remove(this->zipFileName);
  454. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  455. <<"upload time "<<time.elapsed();
  456. }
  457. void NumberCheck::submitPack()
  458. {
  459. this->submitOK = false;
  460. this->forecastOK = false;
  461. if(!preChkFile())
  462. return ;
  463. emit msgUpdated("1","progress");
  464. if(!chkFee())
  465. return ;
  466. emit msgUpdated("2","progress");
  467. QString zip = zipTxtFile(this->fileName);
  468. if(!zip.isEmpty())
  469. {
  470. this->fileName = zip;
  471. this->zipFileName = zip;
  472. }
  473. else
  474. {
  475. if(!this->zipFileName.isEmpty())
  476. this->fileName = this->zipFileName;
  477. }
  478. QTime time;
  479. time.start();
  480. emit msgUpdated("3","progress");
  481. emit msgUpdated("正在分批提交,请稍候","label");
  482. FileSplitter splitter(fileName);
  483. QStringList list = splitter.getSplitResult();
  484. WSNumChk numchk(this->host,this->port);
  485. bool allupload = true;
  486. QString packName;
  487. for(int i=0;i<list.size();i++)
  488. {
  489. //emit msgUpdated(QString("第%1/%2正在提交").arg(i+1).arg(list.size()),"label");
  490. packName = list.at(i);
  491. QString json = numchk.PackTran(packName,this->userHash);
  492. RespPackTran response(json);
  493. if(response.getRtnCode()==1)
  494. {
  495. //emit msgUpdated(QString("第%1/%2提交成功").arg(i+1).arg(list.size()),"label");
  496. QFile::remove(packName);
  497. }
  498. else
  499. {
  500. allupload = false;
  501. //emit msgUpdated(QString("第%1/%2提交失败,请稍候重试").arg(i+1).arg(list.size()),"label");
  502. }
  503. emit msgUpdated(QString::number(3+90*(i+1)/list.size()),"progress");
  504. }
  505. if(allupload)
  506. {
  507. splitter.cleanup();
  508. emit msgUpdated(QString::number(94),"progress");
  509. QString json = numchk.PackMerge(packName,this->userHash);
  510. emit msgUpdated(QString::number(95),"progress");
  511. RespPackMerge response(json);
  512. if(response.getRtnCode()==1)
  513. {
  514. QFileInfo fileinfo(fileName);
  515. emit msgUpdated(QString::number(96),"progress");
  516. json = numchk.submitPnumFile(fileinfo.fileName(),response.getFileHash(),fileType,submitWay,memo,userHash);
  517. RespSubminPNum response(json);
  518. if(response.getRtnCode()==2)
  519. {
  520. emit msgUpdated("上传成功,号码全部接收。","rtnmsg");
  521. emit msgUpdated(response.getRtnMemo(),"tooltipok");
  522. this->submitOK = true;
  523. }
  524. else if(response.getRtnCode()==1)
  525. {
  526. emit msgUpdated("上传成功,文件中含有部分非法数据。","rtnmsg");
  527. emit msgUpdated(response.getRtnMemo(),"tooltipwarning");
  528. this->submitOK = true;
  529. }
  530. else if(response.getRtnCode()==-1)
  531. {
  532. emit msgUpdated("<font color=red>登录超时,请重新登录。</font>","rtnmsg");
  533. }
  534. else
  535. {
  536. emit msgUpdated("<font color=red>"+response.getRtnMemo()+"</font>","rtnmsg");
  537. }
  538. }
  539. else
  540. {
  541. emit msgUpdated("<font color=red>"+response.getRtnMemo()+"</font>","rtnmsg");
  542. }
  543. }
  544. else
  545. {
  546. emit msgUpdated("<font color=red>未能提交,请再次尝试上传(支持断点续传)。</font>","rtnmsg");
  547. }
  548. emit msgUpdated(QString::number(100),"progress");
  549. msleep(500);
  550. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  551. <<"upload time "<<time.elapsed();
  552. }
  553. int NumberCheck::extractSegmentFromTxtFile(QString fileName)
  554. {
  555. QFile file(fileName);
  556. if(!file.open(QIODevice::ReadOnly))
  557. {
  558. return -1;
  559. }
  560. QTextStream in(&file);
  561. segments.clear();
  562. while(!in.atEnd())
  563. {
  564. QString line = in.readLine().trimmed();
  565. if(NumberReg::getSegmentReg().exactMatch(line))
  566. segments<<line;
  567. }
  568. file.close();
  569. return segments.size();
  570. }
  571. //QMap<int,int> NumberCheck::extractTxtFileFromZip(QString zipFile)
  572. //{
  573. // UnZip::ErrorCode ec;
  574. // UnZip uz;
  575. // QDir dir;
  576. // QMap<int,int> map;
  577. // QStringList fileList;
  578. // if(!dir.exists(QDir::tempPath()+"/SNCUnzipFile"))
  579. // {
  580. // dir.mkdir(QDir::tempPath()+"/SNCUnzipFile");
  581. // }
  582. // ec = uz.openArchive(zipFile);
  583. // if (ec != UnZip::Ok) {
  584. // qDebug() << "openArchive:zip包文件格式损坏!";
  585. // return map ;
  586. // }
  587. // QDir d(QDir::tempPath()+"/SNCUnzipFile");
  588. // QFileInfoList list = d.entryInfoList();
  589. // for(int i=0;i<list.size();i++)
  590. // {
  591. // if(list.at(i).isFile())
  592. // QFile::remove(list.at(i).absoluteFilePath());
  593. // }
  594. // ec = uz.extractAll(QDir::tempPath()+"/SNCUnzipFile");
  595. // if (ec != UnZip::Ok) {
  596. // qDebug() << "extractAll:zip包文件格式损坏!";
  597. // uz.closeArchive();
  598. // return map ;
  599. // }
  600. //// QTime dieTime = QTime::currentTime().addMSecs(6000);
  601. //// while( QTime::currentTime() < dieTime )
  602. //// QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
  603. // QDir d2(QDir::tempPath()+"/SNCUnzipFile");
  604. // list = d2.entryInfoList();
  605. // for(int i=0;i<list.size();i++)
  606. // {
  607. // if(list.at(i).isFile())
  608. // {
  609. // if(list.at(i).suffix().toLower()=="txt")
  610. // fileList<<list.at(i).absoluteFilePath();
  611. // }
  612. // }
  613. // map = extractNumberFromTxtFile(fileList);
  614. // return map;
  615. //}
  616. QMap<int,int> NumberCheck::extractTxtFileFromZip(QString zipFile)
  617. {
  618. QDir dir;
  619. QMap<int,int> map;
  620. QStringList fileList;
  621. if(!dir.exists(QDir::tempPath()+"/SNCUnzipFile"))
  622. {
  623. dir.mkdir(QDir::tempPath()+"/SNCUnzipFile");
  624. }
  625. QDir d(QDir::tempPath()+"/SNCUnzipFile");
  626. QFileInfoList list = d.entryInfoList();
  627. for(int i=0;i<list.size();i++)
  628. {
  629. if(list.at(i).isFile())
  630. QFile::remove(list.at(i).absoluteFilePath());
  631. }
  632. QProcess process;
  633. process.setStandardOutputFile(QDir::tempPath()+"/SNCUnzipFile/output.log");
  634. process.setWorkingDirectory(QCoreApplication::applicationDirPath());
  635. process.start("\"" + QCoreApplication::applicationDirPath() + "/7ze.exe\" e \"" + zipFile + "\" -o\"" + QDir::tempPath()+"/SNCUnzipFile\" ");
  636. process.waitForFinished();
  637. QDir d2(QDir::tempPath()+"/SNCUnzipFile");
  638. list = d2.entryInfoList();
  639. for(int i=0;i<list.size();i++)
  640. {
  641. if(list.at(i).isFile())
  642. {
  643. if(list.at(i).suffix().toLower()=="txt")
  644. fileList<<list.at(i).absoluteFilePath();
  645. }
  646. }
  647. map = extractNumberFromTxtFile(fileList);
  648. QFileInfo fileinfo(zipFile);
  649. QString newZipfiles = QDir::tempPath()+"/SNCUnzipFile/" + fileinfo.baseName() + ".zip";
  650. QProcess process2;
  651. process2.setWorkingDirectory(QCoreApplication::applicationDirPath());
  652. process2.start("\"" + QCoreApplication::applicationDirPath() + "/7ze.exe\" a \"" + newZipfiles + "\" \"" + QDir::tempPath()+"/SNCUnzipFile/*.txt\"");
  653. process2.waitForFinished();
  654. this->zipFileName = newZipfiles;
  655. return map;
  656. }
  657. QMap<int,int> NumberCheck::extractNumberFromTxtFile(QStringList fileNames)
  658. {
  659. QMap<int,int> map;
  660. segments.clear();
  661. numbers.clear();
  662. for(int i=0;i<fileNames.size();i++)
  663. {
  664. QString fileName = fileNames.at(i);
  665. QFile file(fileName);
  666. if(!file.open(QIODevice::ReadOnly))
  667. {
  668. map.clear();
  669. return map;
  670. }
  671. QTextStream in(&file);
  672. QStringList nums;
  673. while(!in.atEnd())
  674. {
  675. QString line = in.readLine().trimmed();
  676. if(NumberReg::getCellPhoneReg().exactMatch(line))
  677. {
  678. nums<<line;
  679. QString segment = line.left(7);
  680. QString tail = line.mid(7,4);
  681. QStringList list;
  682. list<<tail;
  683. segments.append(segment);
  684. numbers.append(list);
  685. }
  686. }
  687. map.insert(i,nums.size());
  688. }
  689. model.setNumberList(segments,numbers);
  690. model.mergeSegment();
  691. return map;
  692. }
  693. QString NumberCheck::zipTxtFile(QString fileName)
  694. {
  695. Zip::ErrorCode ec;
  696. Zip uz;
  697. QDir dir;
  698. QFileInfo fileInfo(fileName);
  699. if(fileInfo.suffix().toLower()!="txt")
  700. return "";
  701. if(fileType=="2")
  702. return "";
  703. if(!dir.exists(QDir::tempPath()+"/speednumcube"))
  704. {
  705. dir.mkdir(QDir::tempPath()+"/speednumcube");
  706. }
  707. if(!dir.exists(QDir::tempPath()+"/speednumcube/tmpzip"))
  708. {
  709. dir.mkdir(QDir::tempPath()+"/speednumcube/tmpzip");
  710. }
  711. QString path = QDir::tempPath()+"/speednumcube/tmpzip";
  712. QString zip = path+"/"+fileInfo.completeBaseName()+".zip";
  713. QFile file(zip);
  714. if(!file.open(QIODevice::WriteOnly)){
  715. return "" ;
  716. }
  717. file.close();
  718. ec = uz.createArchive(zip);
  719. if (ec != Zip::Ok) {
  720. qDebug() << "Unable to create archive: " << uz.formatError(ec).toAscii().data() << endl << endl;
  721. return "";
  722. }
  723. ec = uz.addFile(fileName);
  724. if (ec != Zip::Ok) {
  725. qDebug() << "Unable to add directory: " << uz.formatError(ec).toAscii().data() << endl << endl;
  726. return "";
  727. }
  728. if (uz.closeArchive() != Zip::Ok) {
  729. qDebug() << "Unable to close the archive: " << uz.formatError(ec).toAscii().data() << endl << endl;
  730. return "";
  731. }
  732. return zip;
  733. }