| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- #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()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
- <<"FormNumchk.AutoSyncData Destroyed.";
- }
- void AutoSyncData::setSkip(bool skip)
- {
- m_skip = skip;
- }
- void AutoSyncData::abort()
- {
- m_stop = true;
- m_numchk->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<QString, QString> 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:"<<json;
- RespGetDealInfo response(json);
- if(response.getRtnCode()>=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<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();
- if(state==3 )
- {
- return true;
- }
- }
- list = SNCDataBase::getBzjcCheckDealingInfos(userCode,m_clientID);
- if(list.size()>0)
- {
- 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<rows;i++)
- {
- int ispass = list.values("ispass").at(i).toInt();
- if(ispass==0)
- {
- return true;
- }
- }
- return false;
- }
|