|
|
@@ -1,6 +1,148 @@
|
|
|
-#include "projectinfomanger.h"
|
|
|
+#include "projectinfomanger.h"
|
|
|
+#include <QTimer>
|
|
|
+#include "globalinfo.h"
|
|
|
+#include <QSet>
|
|
|
+#include <pqQtlib/utils/pqfileutils.h>
|
|
|
+#include <QJsonDocument>
|
|
|
|
|
|
-ProjectInfoManger::ProjectInfoManger(QObject *parent) : QObject(parent)
|
|
|
+ProjectInfoManger::ProjectInfoManger(PackInfoManger *manger, QObject *parent) : QObject(parent),_manger(manger)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+bool ProjectInfoManger::loadServerList()
|
|
|
+{
|
|
|
+ if(_status != IDIL) return false;
|
|
|
+ _serverInfo.clear();
|
|
|
+ _cacheInfo.clear();
|
|
|
+ _oneSyncError = 0;
|
|
|
+ _netErrorCount = 0;
|
|
|
+ QTimer::singleShot(0,this,&ProjectInfoManger::doSendLoad);
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool ProjectInfoManger::syncLocalList()
|
|
|
+{
|
|
|
+ if(_status != IDIL) return false;
|
|
|
+ auto info = GlobalInfo::this_()->cacheInfo();
|
|
|
+ _serverInfo.clear();
|
|
|
+ _cacheInfo.clear();
|
|
|
+ _pushQueue.clear();
|
|
|
+ for(int i = 0; i < info.size(); ++i){
|
|
|
+ _pushQueue.append(info.at(i));
|
|
|
+ }
|
|
|
+ QTimer::singleShot(0,this,&ProjectInfoManger::syncLocalList);
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+void ProjectInfoManger::doSendLoad()
|
|
|
+{
|
|
|
+ //TODO:小宋,请求获取批号列表信息
|
|
|
+ // docs: http://doc.vanlai.net:3001/web/#/1?page_id=60
|
|
|
+}
|
|
|
+
|
|
|
+void ProjectInfoManger::doSendCreate()
|
|
|
+{
|
|
|
+ if(!_pushQueue.isEmpty()){
|
|
|
+ _status = Sync_Local_List;
|
|
|
+ QSharedPointer<ProjectInfo> info = _pushQueue.first();
|
|
|
+ // TODO: 小宋, 调用新建批号的接口
|
|
|
+ // docs: http://doc.vanlai.net:3001/web/#/1?page_id=59
|
|
|
+ } else {
|
|
|
+ _status = IDIL;
|
|
|
+ QTimer::singleShot(0,this,&ProjectInfoManger::doSendLoad);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void ProjectInfoManger::handleList()
|
|
|
+{
|
|
|
+ QSet<QString> remoted;
|
|
|
+ for(int i = 0; i < _serverInfo.size(); ++i){
|
|
|
+ remoted.insert(_serverInfo.at(i)->batch_no);
|
|
|
+ }
|
|
|
+ _cacheInfo.clear();
|
|
|
+ auto list = _manger->getLocalProjectInfo();
|
|
|
+ for(int i = 0; i < list.size(); ++i){
|
|
|
+ auto info = list.at(i);
|
|
|
+ if(!remoted.contains(info->batch_no)){
|
|
|
+ _cacheInfo.append(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void ProjectInfoManger::result(int code, const QJsonObject & body)
|
|
|
+{
|
|
|
+ switch (_status) {
|
|
|
+ case Load_Server_List:
|
|
|
+ handleGetList(code,body);
|
|
|
+ break;
|
|
|
+ case Sync_Local_List:
|
|
|
+ handlSync(code,body);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void ProjectInfoManger::handlSync(int code, const QJsonObject & body)
|
|
|
+{
|
|
|
+ if(code != 200){
|
|
|
+ _netErrorCount ++;
|
|
|
+ if(_netErrorCount > 3) {
|
|
|
+ emit synced(this,false);
|
|
|
+ } else {
|
|
|
+ QTimer::singleShot(500,this,&ProjectInfoManger::syncLocalList);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+// auto error = body.value("code").toInt();
|
|
|
+// if(error == 200){
|
|
|
+ _pushQueue.dequeue();
|
|
|
+ QTimer::singleShot(50,this,&ProjectInfoManger::syncLocalList);
|
|
|
+// } else {
|
|
|
+// _pushQueue.dequeue();
|
|
|
+// QTimer::singleShot(50,this,&ProjectInfoManger::syncLocalList);
|
|
|
+// }
|
|
|
+}
|
|
|
+
|
|
|
+void ProjectInfoManger::handleGetList(int code, const QJsonObject & body)
|
|
|
+{
|
|
|
+ if(code != 200){
|
|
|
+ _netErrorCount ++;
|
|
|
+ if(_netErrorCount > 3) {
|
|
|
+ auto dt = PQ::CacheFile::readFile("ProjectInfoList.cache");
|
|
|
+ auto ary = QJsonDocument::fromJson(dt).array();
|
|
|
+ hanldeServerList(ary,false);
|
|
|
+ } else {
|
|
|
+ QTimer::singleShot(500,this,&ProjectInfoManger::syncLocalList);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ auto error = body.value("code").toInt();
|
|
|
+ if(error == 200){
|
|
|
+ _oneSyncError = 0;
|
|
|
+ auto ary = body.value("data").toArray();
|
|
|
+ hanldeServerList(ary);
|
|
|
+ } else {
|
|
|
+ _oneSyncError ++;
|
|
|
+ if(_oneSyncError > 3) {
|
|
|
+ auto dt = PQ::CacheFile::readFile("ProjectInfoList.cache");
|
|
|
+ auto ary = QJsonDocument::fromJson(dt).array();
|
|
|
+ hanldeServerList(ary,false);
|
|
|
+ } else {
|
|
|
+ QTimer::singleShot(50,this,&ProjectInfoManger::syncLocalList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void ProjectInfoManger::hanldeServerList(QJsonArray & ary,bool inServer)
|
|
|
+{
|
|
|
+ if(inServer){
|
|
|
+ auto dt = QJsonDocument(ary).toJson();
|
|
|
+ PQ::CacheFile::writeFile("ProjectInfoList.cache",dt);
|
|
|
+ }
|
|
|
+
|
|
|
+ //TODO: 小宋 解析返回的到 _serverInfo
|
|
|
+ // docs: http://doc.vanlai.net:3001/web/#/1?page_id=60
|
|
|
+}
|