autosynczxshdata.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include "autosynczxshdata.h"
  2. #include "respgetzxshtaskinfo.h"
  3. #include "zxshdb.h"
  4. #include "sncdatabase.h"
  5. AutoSyncZxshData::AutoSyncZxshData()
  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. AutoSyncZxshData::~AutoSyncZxshData()
  15. {
  16. m_cubeWs->abort();
  17. delete m_cubeWs;
  18. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  19. <<"FormRiddle.AutoSyncZxshData Destroyed.";
  20. }
  21. void AutoSyncZxshData::setSkip(bool skip)
  22. {
  23. m_skip = skip;
  24. }
  25. void AutoSyncZxshData::abort()
  26. {
  27. m_stop = true;
  28. m_cubeWs->abort();
  29. }
  30. void AutoSyncZxshData::setAccountInfo(QMap<QString, QString> accountInfo)
  31. {
  32. m_account = accountInfo;
  33. m_first = true;
  34. }
  35. void AutoSyncZxshData::sync()
  36. {
  37. QString ssoHash = m_account.value("ssohash");
  38. QString userCode = m_account.value("usercode");
  39. QString indate = "3";
  40. QString src = "mf"+ SNCDataBase::getAppVersion();
  41. if(ssoHash.isEmpty() || userCode.isEmpty())
  42. return ;
  43. if(!checkSynCondition())
  44. return;
  45. QString json = m_cubeWs->getZxshTaskInfo(indate,ssoHash,src);
  46. RespGetZxshTaskInfo resp(json);
  47. QMultiMap<QString,QString> list;
  48. if(resp.getRtnCode()==1)
  49. {
  50. list = resp.getRs();
  51. ZxshDB::updateShkjZxshTaskInfos(list,userCode);
  52. }
  53. else
  54. {
  55. qDebug()<<"AutoSyncZxshData:"<<resp.getRtnMemo();
  56. }
  57. emit dataSync();
  58. }
  59. bool AutoSyncZxshData::checkSynCondition()
  60. {
  61. //从服务器同步的条件
  62. //1、用户还未同步过一次
  63. //2、SHKJ_ZXSH_TASK存在deal_status=0 or 1的记录
  64. //3、SHKJ_ZXSH_TASK_PACKNO没有数据
  65. if(m_first)
  66. {
  67. m_first = false;
  68. return true;
  69. }
  70. QString ssoHash = m_account.value("ssohash");
  71. QString userCode = m_account.value("usercode");
  72. if(ssoHash.isEmpty() || userCode.isEmpty())
  73. return false ;
  74. QMultiMap<QString,QString> list = ZxshDB::getShkjZxshTasksByUser(userCode, "0");
  75. int cols,rows;
  76. cols = list.uniqueKeys().size();
  77. rows = 0;
  78. if(cols!=0)
  79. rows = list.size()/cols;
  80. for(int i=0;i<rows;i++)
  81. {
  82. QString dealstatus = list.values("dealstatus").at(i);
  83. if(dealstatus=="0" || dealstatus=="1" )
  84. {
  85. return true;
  86. }
  87. }
  88. return false;
  89. }
  90. void AutoSyncZxshData::run()
  91. {
  92. if(m_skip)
  93. return ;
  94. m_stop = false;
  95. sync();
  96. }