fileupload.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #include "fileupload.h"
  2. #include "fileprepare.h"
  3. #include "respsubmitjsjcfile.h"
  4. #include "resppackmerge.h"
  5. #include "resppacktran.h"
  6. #include "respgetuserjsjcserviceinfo.h"
  7. #include "respuserserviceverify.h"
  8. #include "filesplitter.h"
  9. #include "sncdatabase.h"
  10. #include "numberreg.h"
  11. FileUpload::FileUpload(QString fileName, QString fileType, QString memo,QString userHash)
  12. {
  13. this->fileName = fileName;
  14. this->fileType = fileType;
  15. this->memo = memo;
  16. this->userHash = userHash;
  17. this->isBatchTran = true;
  18. this->isMulti = false;
  19. this->monthLimit = 0;
  20. this->monthSum = 0;
  21. this->stop = false;
  22. m_cubeWs = new WSCube();
  23. }
  24. void FileUpload::abort()
  25. {
  26. this->stop = true;
  27. m_cubeWs->abort();
  28. }
  29. FileUpload::~FileUpload()
  30. {
  31. m_cubeWs->abort();
  32. delete m_cubeWs;
  33. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  34. <<"FormRiddle.FileUpload Destroyed.";
  35. }
  36. void FileUpload::run()
  37. {
  38. if(isBatchTran)
  39. submitByPack();
  40. else
  41. submit();
  42. emit uploadFinished();
  43. }
  44. void FileUpload::submit()
  45. {
  46. emit msgUpdated("正在进行预处理,请稍候","status");
  47. FilePrepare filePrepare(this->fileName,this->fileType,isMulti);
  48. if(!filePrepare.prepare())
  49. {
  50. emit msgUpdated(filePrepare.getRtnMsg(),"fail");
  51. return ;
  52. }
  53. emit msgUpdated(QString::number(filePrepare.getCount()),"numbercount");
  54. if(!checkUserAccount(filePrepare.getCount()))
  55. return ;
  56. emit msgUpdated("正在提交,请稍候","status");
  57. QString json = m_cubeWs->submitJSJCfile(filePrepare.getLastUploadFileName(),this->fileType,this->memo,this->userHash);
  58. if(json.isEmpty())
  59. {
  60. emit msgUpdated("网络无法连接,请稍候再试!","fail");
  61. }
  62. else
  63. {
  64. RespSubmitJSJCfile response(json);
  65. if(response.getRtnCode()==2)
  66. {
  67. emit msgUpdated("上传成功,号码全部接收","succeed");
  68. emit msgUpdated(response.getRtnMemo(),"detailok");
  69. }
  70. else if(response.getRtnCode()==1)
  71. {
  72. emit msgUpdated("上传成功,文件中含有部分非法数据","succeed");
  73. emit msgUpdated(response.getRtnMemo(),"detailwarning");
  74. }
  75. else if(response.getRtnCode()==-1)
  76. {
  77. emit msgUpdated("登录超时,请重新登录","fail");
  78. }
  79. else
  80. {
  81. emit msgUpdated(response.getRtnMemo(),"fail");
  82. }
  83. }
  84. }
  85. void FileUpload::submitByPack()
  86. {
  87. emit msgUpdated("正在进行预处理,请稍候","status");
  88. FilePrepare filePrepare(this->fileName,this->fileType,isMulti);
  89. if(!filePrepare.prepare())
  90. {
  91. emit msgUpdated(filePrepare.getRtnMsg(),"fail");
  92. return ;
  93. }
  94. emit msgUpdated(QString::number(filePrepare.getCount()),"numbercount");
  95. if(stop)
  96. {
  97. emit msgUpdated("用户中止","fail");
  98. return ;
  99. }
  100. if(!checkUserAccount(filePrepare.getCount()))
  101. return ;
  102. if(stop)
  103. {
  104. emit msgUpdated("用户中止","fail");
  105. return ;
  106. }
  107. emit msgUpdated("正在提交,请稍候","status");
  108. FileSplitter splitter(filePrepare.getLastUploadFileName(),"");
  109. QStringList list = splitter.getSplitResult();
  110. bool allupload = true;
  111. QString packName;
  112. for(int i=0;i<list.size();i++)
  113. {
  114. if(stop)
  115. {
  116. emit msgUpdated("用户中止","fail");
  117. return ;
  118. }
  119. packName = list.at(i);
  120. QString json = m_cubeWs->packTran(packName,this->userHash);
  121. RespPackTran response(json);
  122. if(response.getRtnCode()==1)
  123. {
  124. QFile::remove(packName);
  125. }
  126. else
  127. {
  128. qDebug()<<response.getRtnMemo();
  129. allupload = false;
  130. }
  131. emit msgUpdated(QString::number(3+90*(i+1)/list.size()),"progress");
  132. }
  133. if(allupload)
  134. {
  135. splitter.cleanup();
  136. emit msgUpdated(QString::number(94),"progress");
  137. QString json = m_cubeWs->packMerge(packName,this->userHash);
  138. emit msgUpdated(QString::number(95),"progress");
  139. RespPackMerge response(json);
  140. if(response.getRtnCode()==1)
  141. {
  142. emit msgUpdated(QString::number(96),"progress");
  143. json = m_cubeWs->submitJSJCfile(filePrepare.getLastUploadFileName(),response.getFileHash(),fileType,memo,userHash);
  144. RespSubmitJSJCfile response(json);
  145. if(response.getRtnCode()==2)
  146. {
  147. emit msgUpdated("上传成功,号码全部接收。","succeed");
  148. emit msgUpdated(response.getRtnMemo(),"detailok");
  149. }
  150. else if(response.getRtnCode()==1)
  151. {
  152. emit msgUpdated("上传成功,文件中含有部分非法数据。","succeed");
  153. emit msgUpdated(response.getRtnMemo(),"detailwarning");
  154. }
  155. else if(response.getRtnCode()==-1)
  156. {
  157. emit msgUpdated(response.getRtnMemo(),"fail");
  158. }
  159. else
  160. {
  161. emit msgUpdated(response.getRtnMemo(),"fail");
  162. }
  163. }
  164. else
  165. {
  166. emit msgUpdated(response.getRtnMemo(),"fail");
  167. }
  168. }
  169. else
  170. {
  171. emit msgUpdated("未能提交,请再次尝试上传(支持断点续传)","fail");
  172. }
  173. emit msgUpdated(QString::number(100),"progress");
  174. }
  175. bool FileUpload::checkUserAccount(int nums)
  176. {
  177. emit msgUpdated(QString("正在验证用户信息"),"status");
  178. bool rtn = false;
  179. QString json = m_cubeWs->userServiceVerify("SubmitJSJCfile",QString("%1").arg(nums),this->userHash);
  180. if(!json.isEmpty())
  181. {
  182. RespUserServiceVerify response(json);
  183. if(response.getRtnCode()==1)
  184. {
  185. rtn = true;
  186. }
  187. else
  188. {
  189. emit msgUpdated(response.getRtnMemo(),"fail");
  190. }
  191. }
  192. else
  193. {
  194. emit msgUpdated(QString("无法验证用户信息"),"fail");
  195. }
  196. return rtn;
  197. }