autosyncdata.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include "autosyncdata.h"
  2. #include "respgetshkjinfo.h"
  3. #include "shkjdb.h"
  4. #include "sncdatabase.h"
  5. AutoSyncData::AutoSyncData()
  6. {
  7. m_stop = false;
  8. m_skip = false;
  9. m_cubeWs = new WSCube2();
  10. m_first = true;
  11. m_clientID = "";
  12. m_moduleID = "shkj";
  13. }
  14. AutoSyncData::~AutoSyncData()
  15. {
  16. m_cubeWs->abort();
  17. delete m_cubeWs;
  18. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  19. <<"FormRiddle.AutoSyncData Destroyed.";
  20. }
  21. void AutoSyncData::setSkip(bool skip)
  22. {
  23. m_skip = skip;
  24. }
  25. void AutoSyncData::abort()
  26. {
  27. m_stop = true;
  28. m_cubeWs->abort();
  29. }
  30. void AutoSyncData::setAccountInfo(QMap<QString, QString> accountInfo)
  31. {
  32. m_account = accountInfo;
  33. m_first = true;
  34. }
  35. void AutoSyncData::sync()
  36. {
  37. QString ssoHash = m_account.value("ssohash");
  38. QString userCode = m_account.value("usercode");
  39. if(ssoHash.isEmpty() || userCode.isEmpty())
  40. return ;
  41. if(!checkSynCondition())
  42. return;
  43. QString indate = "3";
  44. QString src = "mf-"+SNCDataBase::getAppVersion();
  45. QString json = m_cubeWs->getShkjInfo(indate,ssoHash,src);
  46. RespGetShkjInfo response(json);
  47. if(response.getRtnCode()>=0)
  48. {
  49. //qDebug()<<response.getRs();
  50. ShkjDB::updateShkjCheckInfos(response.getRs(),userCode);
  51. //QStringList srvids = response.getRs().values("ltfid");
  52. //SNCDataBase::updateFileUploadOutdateDataBySrvIDs("shkj","",userCode,srvids);
  53. emit dataSync();
  54. }
  55. }
  56. bool AutoSyncData::checkSynCondition()
  57. {
  58. //从服务器同步的条件
  59. //1、用户还未同步过一次
  60. //2、file_upload存在file_state=3的记录
  61. //3、shkj_check表存在dealstatus=0 1 的记录
  62. if(m_first)
  63. {
  64. m_first = false;
  65. return true;
  66. }
  67. QString ssoHash = m_account.value("ssohash");
  68. QString userCode = m_account.value("usercode");
  69. if(ssoHash.isEmpty() || userCode.isEmpty())
  70. return false ;
  71. QMultiMap<QString,QString> list = SNCDataBase::getAllUpload(m_moduleID,m_clientID,userCode);
  72. int cols = list.uniqueKeys().size();
  73. int rows = 0;
  74. if(cols!=0)
  75. rows = list.size()/cols;
  76. for(int i=0;i<rows;i++)
  77. {
  78. int state = list.values("uploadstate").at(i).toInt();
  79. int optstatus = list.values("optstatus").at(i).toInt();
  80. if(state==3 && optstatus>=0)
  81. {
  82. return true;
  83. }
  84. }
  85. list = ShkjDB::getShkjCheckInfos(userCode);
  86. cols = list.uniqueKeys().size();
  87. rows = 0;
  88. if(cols!=0)
  89. rows = list.size()/cols;
  90. for(int i=0;i<rows;i++)
  91. {
  92. QString dealstatus = list.values("dealstatus").at(i);
  93. if(dealstatus=="0" || dealstatus=="1" )
  94. {
  95. return true;
  96. }
  97. }
  98. return false;
  99. }
  100. void AutoSyncData::run()
  101. {
  102. if(m_skip)
  103. return ;
  104. m_stop = false;
  105. sync();
  106. }