querypackrealpnum.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "querypackrealpnum.h"
  2. #include "respgetsegrealpnuminfo.h"
  3. #include "unzip.h"
  4. #include "zxshdb.h"
  5. QueryPackRealPnum::QueryPackRealPnum(QObject *parent) :
  6. QThread(parent)
  7. {
  8. m_stop = false;
  9. m_cubeWs = new WSCube2();
  10. }
  11. void QueryPackRealPnum::setAccountInfo(QMap<QString, QString> info)
  12. {
  13. m_account = info;
  14. }
  15. void QueryPackRealPnum::setAreaInfo(QString province, QString city)
  16. {
  17. m_province = province;
  18. m_city = city;
  19. }
  20. void QueryPackRealPnum::abort()
  21. {
  22. m_stop = true;
  23. }
  24. void QueryPackRealPnum::run()
  25. {
  26. if(m_stop)
  27. return ;
  28. QString userhash = m_account.value("ssohash");
  29. ZxshDB::deletePackRealPnum();//首先删除临时表,解决香港这样的问题 change on 2015-10-25
  30. QString json = m_cubeWs->getPackRealPnumInfo(m_province,m_city,userhash);
  31. RespGetSegRealPnumInfo resp(json);
  32. if(resp.getRtnCode()!=1)
  33. {
  34. qDebug()<<"getPackRealPnumInfo:"<<resp.getRtnMemo();
  35. }
  36. else
  37. {
  38. QString segInfo = resp.getSegInfo();
  39. QByteArray arrayBase = QByteArray::fromBase64(segInfo.toAscii());
  40. QFile file1(QDir::tempPath()+"/snc_packRealPnum.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_packtj.csv").arg(m_province).arg(m_city);
  48. if(unzip())
  49. {
  50. ZxshDB::updatePackRealPnum("1",m_city,filename);
  51. }
  52. }
  53. }
  54. emit queryFinished();
  55. }
  56. bool QueryPackRealPnum::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_packRealPnum.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. }