#include "autosyncdata.h" #include "respgetfhymht.h" #include "respgetfhymtask.h" #include "sncdatabase.h" AutoSyncData::AutoSyncData() { m_stop = false; m_moduleID = "wool"; m_first = true; m_skip = false; m_wool = new WSWool(); } AutoSyncData::~AutoSyncData() { m_wool->abort(); delete m_wool; 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_wool->setHost(m_host,m_port); } void AutoSyncData::setAccountInfo(QMap accountInfo) { m_account = accountInfo; m_first = true; } void AutoSyncData::sync() { QString userHash = m_account.value("ssohash"); QString userCode = m_account.value("usercode"); if(userHash.isEmpty() || userCode.isEmpty()) return ; if(!checkSynCondition()) return; bool isSync1 = false; bool isSync2 = false; QString json = m_wool->GetfhymTask(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::updateWoolCheckDealInfos(response.getRs(), userCode); isSync1 = true; } if(m_stop) return; int indate = 3; json = m_wool->GetfhymHt(indate, userHash); RespGetFhymHt response2(json); if(response2.getRtnCode()>=0) { QStringList srvids = response2.getRs().values("taskid"); SNCDataBase::deleteWoolFinishExceptSrvIDs(userCode, srvids); SNCDataBase::updateWoolCheckFinishInfos(response2.getRs(), userCode); isSync2 = true; } if(isSync1 || isSync2) { //QStringList srvids = response.getRs().values("batchid"); //srvids.append(response2.getRs().values("batchid")); //SNCDataBase::updateFileUploadOutdateDataBySrvIDs("Wool",m_clientID,userCode,srvids); emit dataSync(); } } bool AutoSyncData::checkSynCondition() { //从服务器同步的条件 //1、用户每次登陆时 //2、Wool_check_dealing表里有数据 //3、Wool_check_finished表,ispass = 0; //4、upload表里,有upload_state = 3; if(m_first) { m_first = false; return true; } QString userHash = m_account.value("ssohash"); QString userCode = m_account.value("usercode"); if(userHash.isEmpty() || userCode.isEmpty()) return false ; QMultiMap list = SNCDataBase::getAllUpload(m_moduleID,"",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::getWoolCheckFinishInfos(userCode,""); cols = list.uniqueKeys().size(); rows = 0; if(cols!=0) rows = list.size()/cols; for(int i=0;i