autosynczxshsltpackno.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "autosynczxshsltpackno.h"
  2. #include "respgetusrslfsltpacksltinfo.h"
  3. #include "zxshdb.h"
  4. #include "sncdatabase.h"
  5. AutoSyncZxshSltPackno::AutoSyncZxshSltPackno()
  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. AutoSyncZxshSltPackno::~AutoSyncZxshSltPackno()
  15. {
  16. m_cubeWs->abort();
  17. delete m_cubeWs;
  18. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  19. <<"FormRiddle.AutoSyncZxshSltPackno Destroyed.";
  20. }
  21. void AutoSyncZxshSltPackno::setSkip(bool skip)
  22. {
  23. m_skip = skip;
  24. }
  25. void AutoSyncZxshSltPackno::abort()
  26. {
  27. m_stop = true;
  28. m_cubeWs->abort();
  29. }
  30. void AutoSyncZxshSltPackno::setAccountInfo(QMap<QString, QString> accountInfo)
  31. {
  32. m_account = accountInfo;
  33. m_first = true;
  34. }
  35. void AutoSyncZxshSltPackno::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 json = m_cubeWs->getUsrSlfSltPackSltInfo(ssoHash);
  44. RespGetUsrSlfSltPackSltInfo resp(json);
  45. QMultiMap<QString,QString> list;
  46. if(resp.getRtnCode()==1)
  47. {
  48. list = resp.getRs();
  49. //qDebug()<<"RespGetUsrSlfSltPackSltInfo"<<list;
  50. ZxshDB::updateShkjZxshSltPacknos(list,userCode);
  51. }
  52. else
  53. {
  54. qDebug()<<"AutoSyncZxshSltPackno:"<<resp.getRtnMemo();
  55. }
  56. }
  57. bool AutoSyncZxshSltPackno::checkSynCondition()
  58. {
  59. //从服务器同步的条件
  60. //1、用户登录后
  61. //3、并且SHKJ_ZXSH_TASK_PACKNO没有数据
  62. if(m_first)
  63. {
  64. m_first = false;
  65. }
  66. else
  67. {
  68. return false;
  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. return !ZxshDB::validateExistUserPackno(userCode);
  75. }
  76. void AutoSyncZxshSltPackno::run()
  77. {
  78. if(m_skip)
  79. return ;
  80. m_stop = false;
  81. sync();
  82. }