querysegrealpnum.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "querysegrealpnum.h"
  2. #include "respgetsegrealpnuminfo.h"
  3. #include "unzip.h"
  4. #include "zxshdb.h"
  5. QuerySegRealPnum::QuerySegRealPnum(QObject *parent) :
  6. QThread(parent)
  7. {
  8. m_stop = false;
  9. m_cubeWs = new WSCube2();
  10. }
  11. void QuerySegRealPnum::setAccountInfo(QMap<QString, QString> info)
  12. {
  13. m_account = info;
  14. }
  15. void QuerySegRealPnum::setAreaInfo(QString province, QString city)
  16. {
  17. m_province = province;
  18. m_city = city;
  19. }
  20. void QuerySegRealPnum::abort()
  21. {
  22. m_stop = true;
  23. }
  24. void QuerySegRealPnum::run()
  25. {
  26. if(m_stop)
  27. return ;
  28. QString userhash = m_account.value("ssohash");
  29. QString json = m_cubeWs->getSegRealPnumInfo(m_province,m_city,userhash);
  30. RespGetSegRealPnumInfo resp(json);
  31. if(resp.getRtnCode()!=1)
  32. {
  33. QFile::remove(QDir::tempPath()+"/snc_segRealPnum.zip");
  34. qDebug()<<"RespGetSegRealPnumInfo"<<resp.getRtnMemo();
  35. }
  36. else
  37. {
  38. QString segInfo = resp.getSegInfo();
  39. QByteArray arrayBase = QByteArray::fromBase64(segInfo.toAscii());
  40. QFile file1(QDir::tempPath()+"/snc_segRealPnum.zip");
  41. file1.open(QIODevice::WriteOnly);
  42. file1.write(arrayBase);
  43. file1.close();
  44. if(!m_stop)
  45. {
  46. QString filename = QDir::tempPath()+\
  47. QString("/speednumcube/%1_%2_segtj.csv").arg(m_province).arg(m_city);
  48. if(unzip())
  49. {
  50. ZxshDB::updateSegRealPnum("1",m_city,filename);
  51. }
  52. }
  53. }
  54. emit queryFinished();
  55. }
  56. bool QuerySegRealPnum::unzip()
  57. {
  58. UnZip::ErrorCode ec;
  59. UnZip uz;
  60. QDir dir;
  61. if(!dir.exists(QDir::tempPath()+"/speednumcube"))
  62. {
  63. dir.mkdir(QDir::tempPath()+"/speednumcube");
  64. }
  65. ec = uz.openArchive(QDir::tempPath()+"/snc_segRealPnum.zip");
  66. if (ec != UnZip::Ok) {
  67. qDebug() << "Failed to open archive: " << uz.formatError(ec).toAscii().data() << endl << endl;
  68. return false ;
  69. }
  70. ec = uz.extractAll(QDir::tempPath()+"/speednumcube");
  71. if (ec != UnZip::Ok) {
  72. qDebug() << "Extraction failed: " << uz.formatError(ec).toAscii().data() << endl << endl;
  73. uz.closeArchive();
  74. return false ;
  75. }
  76. return true;
  77. }