autosyncdata.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #include "autosyncdata.h"
  2. #include "respgetfhymht.h"
  3. #include "respgetfhymtask.h"
  4. #include "sncdatabase.h"
  5. AutoSyncData::AutoSyncData()
  6. {
  7. m_stop = false;
  8. m_moduleID = "wool";
  9. m_first = true;
  10. m_skip = false;
  11. m_wool = new WSWool();
  12. }
  13. AutoSyncData::~AutoSyncData()
  14. {
  15. m_wool->abort();
  16. delete m_wool;
  17. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  18. <<"FormWool.AutoSyncData Destroyed.";
  19. }
  20. void AutoSyncData::setSkip(bool skip)
  21. {
  22. m_skip = skip;
  23. }
  24. void AutoSyncData::abort()
  25. {
  26. m_stop = true;
  27. m_wool->abort();
  28. }
  29. void AutoSyncData::run()
  30. {
  31. if(m_skip)
  32. return ;
  33. m_stop = false;
  34. sync();
  35. }
  36. void AutoSyncData::setClientID(QString clientID)
  37. {
  38. m_clientID = clientID;
  39. }
  40. void AutoSyncData::setHost(QString host, QString port)
  41. {
  42. m_host = host;
  43. m_port = port;
  44. // m_wool->setHost(m_host,m_port);
  45. }
  46. void AutoSyncData::setAccountInfo(QMap<QString, QString> accountInfo)
  47. {
  48. m_account = accountInfo;
  49. m_first = true;
  50. }
  51. void AutoSyncData::sync()
  52. {
  53. QString userHash = m_account.value("ssohash");
  54. QString userCode = m_account.value("usercode");
  55. if(userHash.isEmpty() || userCode.isEmpty())
  56. return ;
  57. if(!checkSynCondition())
  58. return;
  59. bool isSync1 = false;
  60. bool isSync2 = false;
  61. QString json = m_wool->GetfhymTask(userHash);
  62. RespGetFhymTask response(json);
  63. if(response.getRtnCode()>=0)
  64. {
  65. SNCDataBase::updateWoolCheckDealInfos(response.getRs(), userCode);
  66. isSync1 = true;
  67. }
  68. if(m_stop)
  69. return;
  70. int indate = 3;
  71. json = m_wool->GetfhymHt(indate, userHash);
  72. RespGetFhymHt response2(json);
  73. if(response2.getRtnCode()>=0)
  74. {
  75. QStringList srvids = response2.getRs().values("taskid");
  76. SNCDataBase::deleteWoolFinishExceptSrvIDs(userCode, srvids);
  77. SNCDataBase::updateWoolCheckFinishInfos(response2.getRs(), userCode);
  78. isSync2 = true;
  79. }
  80. if(isSync1 || isSync2)
  81. {
  82. //QStringList srvids = response.getRs().values("batchid");
  83. //srvids.append(response2.getRs().values("batchid"));
  84. //SNCDataBase::updateFileUploadOutdateDataBySrvIDs("Wool",m_clientID,userCode,srvids);
  85. emit dataSync();
  86. }
  87. }
  88. bool AutoSyncData::checkSynCondition()
  89. {
  90. //从服务器同步的条件
  91. //1、用户每次登陆时
  92. //2、Wool_check_dealing表里有数据
  93. //3、Wool_check_finished表,ispass = 0;
  94. //4、upload表里,有upload_state = 3;
  95. if(m_first)
  96. {
  97. m_first = false;
  98. return true;
  99. }
  100. QString userHash = m_account.value("ssohash");
  101. QString userCode = m_account.value("usercode");
  102. if(userHash.isEmpty() || userCode.isEmpty())
  103. return false ;
  104. QMultiMap<QString,QString> list = SNCDataBase::getAllUpload(m_moduleID,"",userCode);
  105. int cols = list.uniqueKeys().size();
  106. int rows = 0;
  107. if(cols!=0)
  108. rows = list.size()/cols;
  109. for(int i=0;i<rows;i++)
  110. {
  111. int state = list.values("uploadstate").at(i).toInt();
  112. if(state==3 )
  113. {
  114. return true;
  115. }
  116. }
  117. list = SNCDataBase::getWoolCheckDealingInfos(userCode);
  118. if(list.size()>0)
  119. {
  120. return true;
  121. }
  122. list = SNCDataBase::getWoolCheckFinishInfos(userCode,"");
  123. cols = list.uniqueKeys().size();
  124. rows = 0;
  125. if(cols!=0)
  126. rows = list.size()/cols;
  127. for(int i=0;i<rows;i++)
  128. {
  129. int isdeliver = list.values("isdeliver").at(i).toInt();
  130. if(isdeliver == 0)
  131. {
  132. return true;
  133. }
  134. }
  135. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  136. <<"AutoSyncData::checkSynCondition() return false ";
  137. return false;
  138. }