| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- #include "autouploadfile.h"
- #include "sncdatabase.h"
- #include "fileprepare.h"
- #include "respsubmitshkjfile.h"
- #include "resppackmerge.h"
- #include "resppacktran.h"
- #include "respuserserviceverify.h"
- #include "filesplitter.h"
- AutoUploadFile::AutoUploadFile()
- {
- m_stop = false;
- m_cubeWs = new WSCube2();
- m_moduleID = "shkj";
- m_clientID = "";
- m_skip = false;
- m_stop = false;
- }
- void AutoUploadFile::abort()
- {
- m_stop = true;
- m_cubeWs->abort();
- }
- void AutoUploadFile::setSkip(bool skip)
- {
- m_skip = skip;
- }
- AutoUploadFile::~AutoUploadFile()
- {
- m_cubeWs->abort();
- delete m_cubeWs;
- qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
- <<"FormRiddle.AutoUpload Destroyed.";
- }
- void AutoUploadFile::setAccountInfo(QMap<QString, QString> accountInfo)
- {
- m_account = accountInfo;
- qDebug()<<m_account;
- }
- void AutoUploadFile::run()
- {
- if(m_skip)
- return ;
- m_stop = false;
- QString userCode = m_account.value("usercode");
- QString ssoHash = m_account.value("ssohash");
- if(ssoHash.isEmpty()||userCode.isEmpty())
- return ;
- QMultiMap<QString,QString> list = SNCDataBase::getAllUpload(m_moduleID,m_clientID,userCode);
- int cols = list.uniqueKeys().size();
- int rows = 0;
- if(cols!=0)
- rows = list.size()/cols;
- for(int i=0;i<rows;i++)
- {
- if(m_stop)
- break;
- int fileid = list.values("fileid").at(i).toInt();
- QString filepath = list.values("filepath").at(i);
- QString filetype = list.values("filetype").at(i);
- QString memo = list.values("memo").at(i);
- int state = list.values("uploadstate").at(i).toInt();
- QString tasktype = list.values("tasktype").at(i);
- if(state==0 || state == 2)
- {
- m_errCode = 0;
- m_errMsg = "";
- m_errDetail = "";
- SNCDataBase::updateFileUploadState(fileid,1,m_errMsg,m_errDetail);
- int ret = upload(fileid,filepath,filetype,tasktype,memo);
- switch(ret)
- {
- case 0:
- SNCDataBase::updateFileUploadState(fileid,2,m_errMsg,m_errDetail);
- break;
- case 1:
- SNCDataBase::updateFileUploadState(fileid,3,m_errMsg,m_errDetail);
- emit uploadSucceed();
- break;
- case -1:
- SNCDataBase::updateFileUploadState(fileid,m_errCode,m_errMsg,m_errDetail);
- emit uploadFailed();
- break;
- }
- }
- }
- }
- int AutoUploadFile::upload(int fileid,QString filePath, QString fileType,QString taskType, QString memo)
- {
- bool multi;
- if(taskType=="1")
- multi = false;
- else
- multi = true;
- FilePrepare filePrepare(filePath,fileType,multi,this->m_moduleID,this->m_clientID);
- if(!filePrepare.prepare())
- {
- m_errCode = -1;
- m_errMsg = filePrepare.getRtnMsg();
- return -1;
- }
- if(m_stop)
- {
- return 0;
- }
- qDebug()<<"sumit"<<filePrepare.getCount();
- QString json = m_cubeWs->userServiceVerify("SubmitShkjFile",QString("%1").arg(filePrepare.getCount()),m_account.value("ssohash"));
- RespUserServiceVerify response(json);
- qDebug()<<json;
- if(response.getRtnCode()<=0)
- {
- m_errMsg = response.getRtnMemo();
- m_errCode = -4;
- if(response.getRtnCode()==RTNCODE_NETWORK_ABORT)
- {
- return 0;
- }
- else if(response.getRtnCode()==RTNCODE_NETWORK_NOTAVAILABLE)
- {
- m_errCode = -2;
- return -1;
- }
- else
- {
- return -1;
- }
- }
- FileSplitter splitter(filePrepare.getLastUploadFileName(),QString::number(fileid));
- QStringList list = splitter.getSplitResult();
- bool allupload = true;
- QString packName;
- for(int i=0;i<list.size();i++)
- {
- if(m_stop)
- {
- return 0;
- }
- packName = list.at(i);
- QString json = m_cubeWs->packTran(packName,m_account.value("ssohash"));
- RespPackTran response(json);
- if(response.getRtnCode()==1)
- {
- QFile::remove(packName);
- }
- else
- {
- m_errMsg = response.getRtnMemo();
- m_errCode = -4;
- if(response.getRtnCode()==RTNCODE_NETWORK_ABORT)
- {
- return 0;
- }
- else if(response.getRtnCode()==RTNCODE_NETWORK_NOTAVAILABLE)
- {
- m_errCode = -2;
- return -1;
- }
- allupload = false;
- break;
- }
- SNCDataBase::updateFileUploadPercent(fileid,(i+1)*100.0/list.size());
- emit uploadProgressUpdated();
- }
- if(allupload)
- {
- splitter.cleanup();
- QString json = m_cubeWs->packMerge(packName,m_account.value("ssohash"));
- qDebug()<<packName;
- RespPackMerge response(json);
- if(response.getRtnCode()==1)
- {
- json = m_cubeWs->submitShkjFile(filePrepare.getLastUploadFileName(),response.getFileHash(),"PackMerge",fileType,memo,m_account.value("ssohash"));
- qDebug()<<filePrepare.getLastUploadFileName()<<response.getFileHash()<<fileType<<memo<<m_account.value("ssohash");
- RespSubmitShkjFile response(json);
- if(response.getRtnCode()==2)
- {
- m_errCode = 1;
- m_errMsg = "上传成功,号码全部接收。";
- m_errDetail = response.getRtnMemo();
- //saveToFile(response.getBatchID(),m_errDetail);
- SNCDataBase::updateFileUploadSrvInfo(fileid,response.getLtfid(),response.getInsertTime());
- }
- else if(response.getRtnCode()==1)
- {
- m_errCode = 1;
- m_errMsg = "上传成功,文件中含有部分非法数据。";
- m_errDetail = response.getRtnMemo();
- saveToFile(response.getLtfid(),m_errDetail);
- SNCDataBase::updateFileUploadSrvInfo(fileid,response.getLtfid(),response.getInsertTime());
- }
- else
- {
- qDebug()<<"AutoUploadFile"<<response.getRtnMemo();
- m_errMsg = response.getRtnMemo();
- m_errCode = -4;
- if(response.getRtnCode()==RTNCODE_NETWORK_ABORT)
- {
- return 0;
- }
- else if(response.getRtnCode()==RTNCODE_NETWORK_NOTAVAILABLE)
- {
- m_errCode = -2;
- return -1;
- }
- }
- }
- else
- {
- m_errMsg = response.getRtnMemo();
- m_errCode = -4;
- if(response.getRtnCode()==RTNCODE_NETWORK_ABORT)
- {
- return 0;
- }
- else if(response.getRtnCode()==RTNCODE_NETWORK_NOTAVAILABLE)
- {
- m_errCode = -2;
- return -1;
- }
- }
- }
- if(m_errCode<0)
- return -1;
- else
- return 1;
- }
- int AutoUploadFile::saveToFile(QString ltfid, QString content)
- {
- QString userCode = m_account.value("usercode");
- QString cachePath = QCoreApplication::applicationDirPath()+\
- QString("/../data/%1/cache/shkj/upload/").arg(userCode);
- QDir dir;
- dir.mkpath(cachePath);
- QString fileName = cachePath + QString("%1.rtn").arg(ltfid);
- QFile file(fileName);
- file.open(QIODevice::WriteOnly);
- QTextStream out(&file);
- out<<content;
- file.close();
- }
|