#include "autosyncdata.h" #include "respgetfinishedinfo.h" #include "respgetdealinfo.h" #include "sncdatabase.h" AutoSyncData::AutoSyncData() { m_stop = false; m_moduleID = "bzjc"; m_first = true; m_skip = false; m_numchk = new WSNumChk(); } AutoSyncData::~AutoSyncData() { m_numchk->abort(); delete m_numchk; qDebug()<abort(); } void AutoSyncData::run() { if(m_skip) return ; m_stop = false; sync(); } void AutoSyncData::setClientID(QString clientID) { m_clientID = clientID; } void AutoSyncData::setHost(QString host, QString port) { m_host = host; m_port = port; m_numchk->setHost(m_host,m_port); } void AutoSyncData::setAccountInfo(QMap accountInfo) { m_account = accountInfo; m_first = true; } void AutoSyncData::sync() { QString userHash = m_account.value("userhash"); QString userCode = m_account.value("usercode"); if(userHash.isEmpty() || m_clientID.isEmpty() || userCode.isEmpty()) return ; if(!checkSynCondition()) return; bool isSync1 = false; bool isSync2 = false; QString json = m_numchk->getDealInfo(userHash); // QString fileName = "d:/test/json.txt"; // QFile file(fileName); // if(!file.open(QIODevice::ReadOnly)) // { // return ; // } // QTextStream in(&file); // json = in.readAll(); //qDebug()<<"json:"<=0) { SNCDataBase::updateBzjcCheckDealInfos(response.getRs(),userCode,m_clientID); isSync1 = true; } if(m_stop) return; int indate = 3; json = m_numchk->getFinishedInfo(indate,userHash); RespGetFinishedInfo response2(json); if(response2.getRtnCode()>=0) { QStringList srvids = response2.getRs().values("batchid"); SNCDataBase::deleteBzjcFinishExceptSrvIDs(m_clientID,userCode,srvids); SNCDataBase::updateBzjcCheckFinishInfos(response2.getRs(),userCode,m_clientID); isSync2 = true; } if(isSync1||isSync2) { //QStringList srvids = response.getRs().values("batchid"); //srvids.append(response2.getRs().values("batchid")); //SNCDataBase::updateFileUploadOutdateDataBySrvIDs("bzjc",m_clientID,userCode,srvids); emit dataSync(); } } bool AutoSyncData::checkSynCondition() { //从服务器同步的条件 //1、用户每次登陆时 //2、bzjc_check_dealing表里有数据 //3、bzjc_check_finished表,ispass = 0; //4、upload表里,有upload_state = 3; if(m_first) { m_first = false; return true; } QString userHash = m_account.value("userhash"); QString userCode = m_account.value("usercode"); if(userHash.isEmpty() || m_clientID.isEmpty() || userCode.isEmpty()) return false ; QMultiMap 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;i0) { return true; } list = SNCDataBase::getBzjcCheckFinishInfos(userCode,m_clientID,""); cols = list.uniqueKeys().size(); rows = 0; if(cols!=0) rows = list.size()/cols; for(int i=0;i