| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- #include "querysegrealpnum.h"
- #include "respgetsegrealpnuminfo.h"
- #include "unzip.h"
- #include "zxshdb.h"
- QuerySegRealPnum::QuerySegRealPnum(QObject *parent) :
- QThread(parent)
- {
- m_stop = false;
- m_cubeWs = new WSCube2();
- }
- void QuerySegRealPnum::setAccountInfo(QMap<QString, QString> info)
- {
- m_account = info;
- }
- void QuerySegRealPnum::setAreaInfo(QString province, QString city)
- {
- m_province = province;
- m_city = city;
- }
- void QuerySegRealPnum::abort()
- {
- m_stop = true;
- }
- void QuerySegRealPnum::run()
- {
- if(m_stop)
- return ;
- QString userhash = m_account.value("ssohash");
- QString json = m_cubeWs->getSegRealPnumInfo(m_province,m_city,userhash);
- RespGetSegRealPnumInfo resp(json);
- if(resp.getRtnCode()!=1)
- {
- QFile::remove(QDir::tempPath()+"/snc_segRealPnum.zip");
- qDebug()<<"RespGetSegRealPnumInfo"<<resp.getRtnMemo();
- }
- else
- {
- QString segInfo = resp.getSegInfo();
- QByteArray arrayBase = QByteArray::fromBase64(segInfo.toAscii());
- QFile file1(QDir::tempPath()+"/snc_segRealPnum.zip");
- file1.open(QIODevice::WriteOnly);
- file1.write(arrayBase);
- file1.close();
- if(!m_stop)
- {
- QString filename = QDir::tempPath()+\
- QString("/speednumcube/%1_%2_segtj.csv").arg(m_province).arg(m_city);
- if(unzip())
- {
- ZxshDB::updateSegRealPnum("1",m_city,filename);
- }
- }
- }
- emit queryFinished();
- }
- bool QuerySegRealPnum::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_segRealPnum.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;
- }
|