| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #include "querypackrealpnum.h"
- #include "respgetsegrealpnuminfo.h"
- #include "unzip.h"
- #include "zxshdb.h"
- QueryPackRealPnum::QueryPackRealPnum(QObject *parent) :
- QThread(parent)
- {
- m_stop = false;
- m_cubeWs = new WSCube2();
- }
- void QueryPackRealPnum::setAccountInfo(QMap<QString, QString> info)
- {
- m_account = info;
- }
- void QueryPackRealPnum::setAreaInfo(QString province, QString city)
- {
- m_province = province;
- m_city = city;
- }
- void QueryPackRealPnum::abort()
- {
- m_stop = true;
- }
- void QueryPackRealPnum::run()
- {
- if(m_stop)
- return ;
- QString userhash = m_account.value("ssohash");
- ZxshDB::deletePackRealPnum();//首先删除临时表,解决香港这样的问题 change on 2015-10-25
- QString json = m_cubeWs->getPackRealPnumInfo(m_province,m_city,userhash);
- RespGetSegRealPnumInfo resp(json);
- if(resp.getRtnCode()!=1)
- {
- qDebug()<<"getPackRealPnumInfo:"<<resp.getRtnMemo();
- }
- else
- {
- QString segInfo = resp.getSegInfo();
- QByteArray arrayBase = QByteArray::fromBase64(segInfo.toAscii());
- QFile file1(QDir::tempPath()+"/snc_packRealPnum.zip");
- file1.open(QIODevice::WriteOnly);
- file1.write(arrayBase);
- file1.close();
- if(!m_stop)
- {
- QString filename = QDir::tempPath()+\
- QString("/speednumcube/%1_%2_packtj.csv").arg(m_province).arg(m_city);
- if(unzip())
- {
- ZxshDB::updatePackRealPnum("1",m_city,filename);
- }
- }
- }
- emit queryFinished();
- }
- bool QueryPackRealPnum::unzip()
- {
- UnZip::ErrorCode ec;
- UnZip uz;
- QDir dir;
- if(!dir.exists(QDir::tempPath()+"/speednumcube"))
- {
- dir.mkdir(QDir::tempPath()+"/speednumcube");
- }
- ec = uz.openArchive(QDir::tempPath()+"/snc_packRealPnum.zip");
- if (ec != UnZip::Ok) {
- qDebug() << "Failed to open archive: " << uz.formatError(ec).toAscii().data() << endl << endl;
- return false ;
- }
- ec = uz.extractAll(QDir::tempPath()+"/speednumcube");
- if (ec != UnZip::Ok) {
- qDebug() << "Extraction failed: " << uz.formatError(ec).toAscii().data() << endl << endl;
- uz.closeArchive();
- return false ;
- }
- return true;
- }
|