| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #include "autosynczxshdata.h"
- #include "respgetzxshtaskinfo.h"
- #include "zxshdb.h"
- #include "sncdatabase.h"
- AutoSyncZxshData::AutoSyncZxshData()
- {
- m_stop = false;
- m_skip = false;
- m_cubeWs = new WSCube2();
- m_first = true;
- m_clientID = "";
- m_moduleID = "shkj";
- }
- AutoSyncZxshData::~AutoSyncZxshData()
- {
- m_cubeWs->abort();
- delete m_cubeWs;
- qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
- <<"FormRiddle.AutoSyncZxshData Destroyed.";
- }
- void AutoSyncZxshData::setSkip(bool skip)
- {
- m_skip = skip;
- }
- void AutoSyncZxshData::abort()
- {
- m_stop = true;
- m_cubeWs->abort();
- }
- void AutoSyncZxshData::setAccountInfo(QMap<QString, QString> accountInfo)
- {
- m_account = accountInfo;
- m_first = true;
- }
- void AutoSyncZxshData::sync()
- {
- QString ssoHash = m_account.value("ssohash");
- QString userCode = m_account.value("usercode");
- QString indate = "3";
- QString src = "mf"+ SNCDataBase::getAppVersion();
- if(ssoHash.isEmpty() || userCode.isEmpty())
- return ;
- if(!checkSynCondition())
- return;
- QString json = m_cubeWs->getZxshTaskInfo(indate,ssoHash,src);
- RespGetZxshTaskInfo resp(json);
- QMultiMap<QString,QString> list;
- if(resp.getRtnCode()==1)
- {
- list = resp.getRs();
- ZxshDB::updateShkjZxshTaskInfos(list,userCode);
- }
- else
- {
- qDebug()<<"AutoSyncZxshData:"<<resp.getRtnMemo();
- }
- emit dataSync();
- }
- bool AutoSyncZxshData::checkSynCondition()
- {
- //从服务器同步的条件
- //1、用户还未同步过一次
- //2、SHKJ_ZXSH_TASK存在deal_status=0 or 1的记录
- //3、SHKJ_ZXSH_TASK_PACKNO没有数据
- if(m_first)
- {
- m_first = false;
- return true;
- }
- QString ssoHash = m_account.value("ssohash");
- QString userCode = m_account.value("usercode");
- if(ssoHash.isEmpty() || userCode.isEmpty())
- return false ;
- QMultiMap<QString,QString> list = ZxshDB::getShkjZxshTasksByUser(userCode, "0");
- int cols,rows;
- cols = list.uniqueKeys().size();
- rows = 0;
- if(cols!=0)
- rows = list.size()/cols;
- for(int i=0;i<rows;i++)
- {
- QString dealstatus = list.values("dealstatus").at(i);
- if(dealstatus=="0" || dealstatus=="1" )
- {
- return true;
- }
- }
- return false;
- }
- void AutoSyncZxshData::run()
- {
- if(m_skip)
- return ;
- m_stop = false;
- sync();
- }
|