| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- #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()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
- <<"FormWool.AutoSyncData Destroyed.";
- }
- void AutoSyncData::setSkip(bool skip)
- {
- m_skip = skip;
- }
- void AutoSyncData::abort()
- {
- m_stop = true;
- m_wool->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<QString, QString> 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:"<<json;
- RespGetFhymTask response(json);
- if(response.getRtnCode()>=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<QString,QString> 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;i<rows;i++)
- {
- int state = list.values("uploadstate").at(i).toInt();
- if(state==3 )
- {
- return true;
- }
- }
- list = SNCDataBase::getWoolCheckDealingInfos(userCode);
- if(list.size()>0)
- {
- return true;
- }
- /*
- list = SNCDataBase::getWoolCheckFinishInfos(userCode,"");
- cols = list.uniqueKeys().size();
- rows = 0;
- if(cols!=0)
- rows = list.size()/cols;
- for(int i=0;i<rows;i++)
- {
- int ispass = list.values("ispass").at(i).toInt();
- if(ispass==0)
- {
- return true;
- }
- }
- */
- qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
- <<"AutoSyncData::checkSynCondition() return false ";
- return false;
- }
|