autosyncdata.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #include "autosyncdata.h"
  2. #include "respgetfinishedinfo.h"
  3. #include "respgetdealinfo.h"
  4. #include "sncdatabase.h"
  5. AutoSyncData::AutoSyncData()
  6. {
  7. m_stop = false;
  8. m_moduleID = "bzjc";
  9. m_first = true;
  10. m_skip = false;
  11. m_numchk = new WSNumChk();
  12. }
  13. AutoSyncData::~AutoSyncData()
  14. {
  15. m_numchk->abort();
  16. delete m_numchk;
  17. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  18. <<"FormNumchk.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_numchk->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_numchk->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("userhash");
  54. QString userCode = m_account.value("usercode");
  55. if(userHash.isEmpty() || m_clientID.isEmpty() || userCode.isEmpty())
  56. return ;
  57. if(!checkSynCondition())
  58. return;
  59. bool isSync1 = false;
  60. bool isSync2 = false;
  61. QString json = m_numchk->getDealInfo(userHash);
  62. // QString fileName = "d:/test/json.txt";
  63. // QFile file(fileName);
  64. // if(!file.open(QIODevice::ReadOnly))
  65. // {
  66. // return ;
  67. // }
  68. // QTextStream in(&file);
  69. // json = in.readAll();
  70. //qDebug()<<"json:"<<json;
  71. RespGetDealInfo response(json);
  72. if(response.getRtnCode()>=0)
  73. {
  74. SNCDataBase::updateBzjcCheckDealInfos(response.getRs(),userCode,m_clientID);
  75. isSync1 = true;
  76. }
  77. if(m_stop)
  78. return;
  79. int indate = 3;
  80. json = m_numchk->getFinishedInfo(indate,userHash);
  81. RespGetFinishedInfo response2(json);
  82. if(response2.getRtnCode()>=0)
  83. {
  84. QStringList srvids = response2.getRs().values("batchid");
  85. SNCDataBase::deleteBzjcFinishExceptSrvIDs(m_clientID,userCode,srvids);
  86. SNCDataBase::updateBzjcCheckFinishInfos(response2.getRs(),userCode,m_clientID);
  87. isSync2 = true;
  88. }
  89. if(isSync1||isSync2)
  90. {
  91. //QStringList srvids = response.getRs().values("batchid");
  92. //srvids.append(response2.getRs().values("batchid"));
  93. //SNCDataBase::updateFileUploadOutdateDataBySrvIDs("bzjc",m_clientID,userCode,srvids);
  94. emit dataSync();
  95. }
  96. }
  97. bool AutoSyncData::checkSynCondition()
  98. {
  99. //从服务器同步的条件
  100. //1、用户每次登陆时
  101. //2、bzjc_check_dealing表里有数据
  102. //3、bzjc_check_finished表,ispass = 0;
  103. //4、upload表里,有upload_state = 3;
  104. if(m_first)
  105. {
  106. m_first = false;
  107. return true;
  108. }
  109. QString userHash = m_account.value("userhash");
  110. QString userCode = m_account.value("usercode");
  111. if(userHash.isEmpty() || m_clientID.isEmpty() || userCode.isEmpty())
  112. return false ;
  113. QMultiMap<QString,QString> list = SNCDataBase::getAllUpload(m_moduleID,m_clientID,userCode);
  114. int cols = list.uniqueKeys().size();
  115. int rows = 0;
  116. if(cols!=0)
  117. rows = list.size()/cols;
  118. for(int i=0;i<rows;i++)
  119. {
  120. int state = list.values("uploadstate").at(i).toInt();
  121. if(state==3 )
  122. {
  123. return true;
  124. }
  125. }
  126. list = SNCDataBase::getBzjcCheckDealingInfos(userCode,m_clientID);
  127. if(list.size()>0)
  128. {
  129. return true;
  130. }
  131. list = SNCDataBase::getBzjcCheckFinishInfos(userCode,m_clientID,"");
  132. cols = list.uniqueKeys().size();
  133. rows = 0;
  134. if(cols!=0)
  135. rows = list.size()/cols;
  136. for(int i=0;i<rows;i++)
  137. {
  138. int ispass = list.values("ispass").at(i).toInt();
  139. if(ispass==0)
  140. {
  141. return true;
  142. }
  143. }
  144. return false;
  145. }