Commit fa96ae04 by NitefullWind

1. 完善结算备份重发功能。 2. 修复日志乱码。

parent 244cf599
...@@ -35,7 +35,7 @@ bool FMBackup::connect() ...@@ -35,7 +35,7 @@ bool FMBackup::connect()
if(!QFile::exists(dbname)) { if(!QFile::exists(dbname)) {
isOk = createTable(dbname); isOk = createTable(dbname);
} else { } else {
_db = QSqlDatabase::addDatabase("QSQLITE"); _db = QSqlDatabase::addDatabase("QSQLITE", "fmvipbackupdb");
_db.setDatabaseName(dbname); _db.setDatabaseName(dbname);
isOk =_db.open(); isOk =_db.open();
} }
...@@ -50,7 +50,7 @@ bool FMBackup::connect() ...@@ -50,7 +50,7 @@ bool FMBackup::connect()
bool FMBackup::createTable(const QString &dbname) bool FMBackup::createTable(const QString &dbname)
{ {
_db = QSqlDatabase::addDatabase("QSQLITE"); _db = QSqlDatabase::addDatabase("QSQLITE", "fmvipbackupdb");
_db.setDatabaseName(dbname); _db.setDatabaseName(dbname);
_db.open(); _db.open();
QSqlQuery query(_db); QSqlQuery query(_db);
......
...@@ -33,16 +33,20 @@ void ReSend::trySend() ...@@ -33,16 +33,20 @@ void ReSend::trySend()
break; break;
} else{ } else{
FMBackup::instance()->removeReqData(id); FMBackup::instance()->removeReqData(id);
qDebug() << "重发响应成功:"<< data; qDebug() << "重发响应成功:"<< QString::fromUtf8(data);
} }
} }
} }
void ReSend::run() void ReSend::run()
{ {
int waitTime = 0;
while(true) while(true)
{ {
if(++waitTime > 30) {
trySend(); trySend();
QThread::sleep(5); waitTime = 0;
}
QThread::sleep(1);
} }
} }
#include "fmnetwork.h" #include "fmnetwork.h"
#include "global.h" #include "global.h"
#include "fmsetting.h"
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkReply> #include <QNetworkReply>
#include <QNetworkRequest> #include <QNetworkRequest>
...@@ -48,14 +49,18 @@ QByteArray FMNetwork::send(const QString *url, const QByteArray *data) ...@@ -48,14 +49,18 @@ QByteArray FMNetwork::send(const QString *url, const QByteArray *data)
if(timer.isActive()) if(timer.isActive())
{ {
timer.stop(); timer.stop();
if (reply->error() == QNetworkReply::NoError) { if (reply->error() == QNetworkReply::NoError) {
rspData = reply->readAll(); rspData = reply->readAll();
} else { } else {
int err = reply->error(); int err = reply->error();
setError(FM_API_NETWORERROR, err, netErrInfo(err)); setError(FM_API_NETWORERROR, err, netErrInfo(err));
qDebug() << QString::fromLocal8Bit("Network error: (%1) %2").arg(err).arg(reply->errorString());
qDebug() << QString::fromLocal8Bit("Network reply: %1.").arg(QString::fromUtf8(reply->readAll()));
} }
}else{ }else{
setError(FM_API_TIMEOUT); setError(FM_API_TIMEOUT);
qDebug() << QString::fromLocal8Bit("Timeout.");
} }
return rspData; return rspData;
} }
......
...@@ -47,8 +47,8 @@ QByteArray FMTask::doTask() ...@@ -47,8 +47,8 @@ QByteArray FMTask::doTask()
(this->*fun)(); (this->*fun)();
qDebug() << "Run over function: " << index++; qDebug() << "Run over function: " << index++;
if(error() != FM_API_SUCCESS) { if(error() != FM_API_SUCCESS) {
qDebug() << QString("Task error %1: %2").arg(error()).arg(errorString()); qDebug() << QString::fromLocal8Bit("Task error %1: %2").arg(error()).arg(errorString());
return QString(ErrorMsgJson).arg(error()).arg(errorString()).toUtf8(); return QString::fromLocal8Bit(ErrorMsgJson).arg(error()).arg(errorString()).toLocal8Bit();
} }
} }
......
...@@ -82,7 +82,7 @@ bool TaskFinal::sendToServer(bool isShowMsg) ...@@ -82,7 +82,7 @@ bool TaskFinal::sendToServer(bool isShowMsg)
FMTask::sendToServer(false); FMTask::sendToServer(false);
// 备份 // 备份
if(error() == FM_API_NETWORERROR) { if(error() == FM_API_NETWORERROR || error() == FM_API_TIMEOUT) {
if(searchJsonValue(serverReqJsonObj,ServerProps(PosProps.CodeAmount)).toInt() == 0 && if(searchJsonValue(serverReqJsonObj,ServerProps(PosProps.CodeAmount)).toInt() == 0 &&
searchJsonValue(serverReqJsonObj,ServerProps(PosProps.ScoreAmount)).toInt() == 0 && searchJsonValue(serverReqJsonObj,ServerProps(PosProps.ScoreAmount)).toInt() == 0 &&
...@@ -137,7 +137,7 @@ QString TaskFinal::backup() ...@@ -137,7 +137,7 @@ QString TaskFinal::backup()
.arg(newId, 5, 10, QChar('0')); .arg(newId, 5, 10, QChar('0'));
QJsonDocument json(serverReqJsonObj); QJsonDocument json(serverReqJsonObj);
bool isOk = FMBackup::instance()->updateReqData(newId, this->url, json.toJson(QJsonDocument::Compact)); bool isOk = FMBackup::instance()->updateReqData(newId, this->url, json.toJson(QJsonDocument::Compact));
if(isOk && uuid.length()==20) { if(isOk) {
return uuid; return uuid;
} }
return ""; return "";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment