| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- #include "fileupload.h"
- #include "fileprepare.h"
- #include "wsnumchk.h"
- #include "respsubminpnum.h"
- #include "resppackmerge.h"
- #include "respchkuserfeestatus.h"
- #include "resppacktran.h"
- #include "filesplitter.h"
- #include "sncdatabase.h"
- #include "numberreg.h"
- FileUpload::FileUpload(QString fileName, QString fileType,QString submitWay, QString memo,QString host,QString port, QString userHash)
- {
- this->fileName = fileName;
- this->fileType = fileType;
- this->submitWay = submitWay;
- this->memo = memo;
- this->host = host;
- this->port = port;
- this->userHash = userHash;
- this->stop = false;
- this->isPackTran = true;
- }
- void FileUpload::abort()
- {
- this->stop = true;
- }
- FileUpload::~FileUpload()
- {
- qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
- <<"FormNumcheck.FileUpload Destroyed.";
- }
- void FileUpload::run()
- {
- if(isPackTran)
- submitByPack();
- else
- submit();
- emit uploadFinished();
- }
- void FileUpload::submit()
- {
- emit msgUpdated("正在进行预处理,请稍候","status");
- bool ismulti;
- if(submitWay=="1")
- {
- ismulti = false;
- }
- else
- {
- ismulti = true;
- }
- FilePrepare filePrepare(this->fileName,this->fileType,ismulti);
- if(!filePrepare.prepare())
- {
- emit msgUpdated(filePrepare.getRtnMsg(),"fail");
- return ;
- }
- emit msgUpdated(QString::number(filePrepare.getCount()),"numbercount");
- if(!checkFee(filePrepare.getCount()))
- return;
- emit msgUpdated("正在提交,请稍候","status");
- WSNumChk ws(this->host,this->port);
- QString json = ws.submitPnumFile(filePrepare.getLastUploadFileName(),this->fileType,submitWay,this->memo,this->userHash);
- if(json.isEmpty())
- {
- emit msgUpdated("网络无法连接,请稍候再试!","fail");
- }
- else
- {
- RespSubminPNum response(json);
- if(response.getRtnCode()==2)
- {
- emit msgUpdated("上传成功,号码全部接收","succeed");
- emit msgUpdated(response.getRtnMemo(),"detailok");
- }
- else if(response.getRtnCode()==1)
- {
- emit msgUpdated("上传成功,文件中含有部分非法数据","succeed");
- emit msgUpdated(response.getRtnMemo(),"detailwarning");
- }
- else if(response.getRtnCode()==-1)
- {
- emit msgUpdated("登录超时,请重新登录","fail");
- }
- else
- {
- emit msgUpdated(response.getRtnMemo(),"fail");
- }
- }
- }
- void FileUpload::submitByPack()
- {
- emit msgUpdated("正在进行预处理,请稍候","status");
- bool ismulti;
- if(submitWay=="1")
- {
- ismulti = false;
- }
- else
- {
- ismulti = true;
- }
- FilePrepare filePrepare(this->fileName,this->fileType,ismulti);
- if(!filePrepare.prepare())
- {
- emit msgUpdated(filePrepare.getRtnMsg(),"fail");
- return ;
- }
- qDebug()<<"step1";
- emit msgUpdated(QString::number(filePrepare.getCount()),"numbercount");
- if(stop)
- return ;
- if(!checkFee(filePrepare.getCount()))
- return;
- FileSplitter splitter(filePrepare.getLastUploadFileName(),"");
- QStringList list = splitter.getSplitResult();
- emit msgUpdated("正在提交,请稍候","status");
- WSNumChk ws(this->host,this->port);
- bool allupload = true;
- QString packName;
- for(int i=0;i<list.size();i++)
- {
- if(stop)
- return ;
- packName = list.at(i);
- QString json = ws.PackTran(packName,this->userHash);
- RespPackTran response(json);
- if(response.getRtnCode()==1)
- {
- QFile::remove(packName);
- }
- else
- {
- allupload = false;
- }
- emit msgUpdated(QString::number(3+90*(i+1)/list.size()),"progress");
- }
- if(allupload)
- {
- splitter.cleanup();
- emit msgUpdated(QString::number(94),"progress");
- QString json = ws.PackMerge(packName,this->userHash);
- emit msgUpdated(QString::number(95),"progress");
- RespPackMerge response(json);
- if(response.getRtnCode()==1)
- {
- emit msgUpdated(QString::number(96),"progress");
- json = ws.submitPnumFile(filePrepare.getLastUploadFileName(),response.getFileHash(),fileType,submitWay,memo,userHash);
- RespSubminPNum response(json);
- if(response.getRtnCode()==2)
- {
- emit msgUpdated("上传成功,号码全部接收。","succeed");
- emit msgUpdated(response.getRtnMemo(),"detailok");
- }
- else if(response.getRtnCode()==1)
- {
- emit msgUpdated("上传成功,文件中含有部分非法数据。","succeed");
- emit msgUpdated(response.getRtnMemo(),"detailwarning");
- }
- else if(response.getRtnCode()==-1)
- {
- emit msgUpdated("登录超时,请重新登录","fail");
- }
- else
- {
- emit msgUpdated(response.getRtnMemo(),"fail");
- }
- }
- else
- {
- emit msgUpdated(response.getRtnMemo(),"fail");
- }
- }
- else
- {
- emit msgUpdated("未能提交,请再次尝试上传(支持断点续传)","fail");
- }
- emit msgUpdated(QString::number(100),"progress");
- }
- bool FileUpload::checkFee(int numCount)
- {
- WSNumChk client(this->host,this->port);
- emit msgUpdated("正在检测是否有足够的余额","status");
- QString json = client.chkUserFeeStatus(QString::number(numCount),this->userHash);
- bool pass = false;
- if(!json.isEmpty()){
- RespChkUserFeeStatus response(json);
- if(response.getRtnCode()==1)
- {
- pass = true;
- }
- else if(response.getRtnCode()==-1)
- {
- emit msgUpdated("登录超时,请重新登录!","fail");
- }
- else
- {
- emit msgUpdated(response.getRtnMemo(),"fail");
- }
- }
- else
- {
- emit msgUpdated("网络无法连接,请稍候再试!","fail");
- }
- return pass;
- }
|