| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #include "autosyncdata.h"
- #include "respgetshkjinfo.h"
- #include "shkjdb.h"
- #include "sncdatabase.h"
- AutoSyncData::AutoSyncData()
- {
- m_stop = false;
- m_skip = false;
- m_cubeWs = new WSCube2();
- m_first = true;
- m_clientID = "";
- m_moduleID = "shkj";
- }
- AutoSyncData::~AutoSyncData()
- {
- m_cubeWs->abort();
- delete m_cubeWs;
- qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
- <<"FormRiddle.AutoSyncData Destroyed.";
- }
- void AutoSyncData::setSkip(bool skip)
- {
- m_skip = skip;
- }
- void AutoSyncData::abort()
- {
- m_stop = true;
- m_cubeWs->abort();
- }
- void AutoSyncData::setAccountInfo(QMap<QString, QString> accountInfo)
- {
- m_account = accountInfo;
- m_first = true;
- }
- void AutoSyncData::sync()
- {
- QString ssoHash = m_account.value("ssohash");
- QString userCode = m_account.value("usercode");
- if(ssoHash.isEmpty() || userCode.isEmpty())
- return ;
- if(!checkSynCondition())
- return;
- QString indate = "3";
- QString src = "mf-"+SNCDataBase::getAppVersion();
- QString json = m_cubeWs->getShkjInfo(indate,ssoHash,src);
- RespGetShkjInfo response(json);
- if(response.getRtnCode()>=0)
- {
- //qDebug()<<response.getRs();
- ShkjDB::updateShkjCheckInfos(response.getRs(),userCode);
- //QStringList srvids = response.getRs().values("ltfid");
- //SNCDataBase::updateFileUploadOutdateDataBySrvIDs("shkj","",userCode,srvids);
- emit dataSync();
- }
- }
- bool AutoSyncData::checkSynCondition()
- {
- //从服务器同步的条件
- //1、用户还未同步过一次
- //2、file_upload存在file_state=3的记录
- //3、shkj_check表存在dealstatus=0 1 的记录
- 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 = SNCDataBase::getAllUpload(m_moduleID,m_clientID,userCode);
- int cols = list.uniqueKeys().size();
- int rows = 0;
- if(cols!=0)
- rows = list.size()/cols;
- for(int i=0;i<rows;i++)
- {
- int state = list.values("uploadstate").at(i).toInt();
- int optstatus = list.values("optstatus").at(i).toInt();
- if(state==3 && optstatus>=0)
- {
- return true;
- }
- }
- list = ShkjDB::getShkjCheckInfos(userCode);
- 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 AutoSyncData::run()
- {
- if(m_skip)
- return ;
- m_stop = false;
- sync();
- }
|