#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()<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;iuserHash); 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; }