Commit f0fb3195 by ss.dai

Add:新增备用网络地址,当地一个地址连续出错则切换到另外一个

parent a48e7694
......@@ -249,8 +249,8 @@ bool FlowControl::_PullOrder()
if(bWrite)
{
QLOG_INFO() << QString("will entry %1").arg(orderObject->order_id);
//QTimer::singleShot(1000*60*120, [orderObject, this](){
QTimer::singleShot(1000*20, [orderObject,this](){
QTimer::singleShot(1000*60*120, [orderObject, this](){
//QTimer::singleShot(1000*20, [orderObject,this](){
if(orderObject->status == 6 || orderObject->status == 200)
{
QString error;
......
......@@ -43,7 +43,11 @@ void ConfigManger::SetSqlConnectInfo(const ConfigManger::SqlConnectInfo &info)
QUrl ConfigManger::GetServerUrl()
{
return m_config->value(INI_SERVER).toUrl();
QLOG_INFO()<<m_config->value(INI_SERVER).toUrl();
}
QUrl ConfigManger::GetServerUrl1()
{
return m_config->value(INI_SERVER1).toUrl();
}
QString ConfigManger::GetPrinterName()
......
......@@ -35,6 +35,11 @@ public:
* 返回:服务器地址
* */
QUrl GetServerUrl();
/* 功能:读取服务器备用地址
* 参数:NULL
* 返回:服务器备用地址
* */
QUrl GetServerUrl1();
/* 功能:读取打印机名称
* 参数:NULL
* 返回:服务器地址
......
......@@ -23,8 +23,9 @@ BillSocket::BillSocket(QObject *parent)
// {
// m_networkManger.setProxy(proxy);
// }
m_errorNum = 0;
m_alternateUrl = ConfigManger::GetInstance().GetServerUrl1();
m_networkRequest.setUrl(ConfigManger::GetInstance().GetServerUrl());
QLOG_INFO()<<ConfigManger::GetInstance().GetServerUrl();
m_networkRequest.setRawHeader("Content-Type","text/json");
}
......@@ -39,6 +40,12 @@ bool BillSocket::Request(const QJsonObject &requestJson, QJsonObject &recvJson,
{
m_networkManger.setNetworkAccessible(QNetworkAccessManager::Accessible);
}
if(m_errorNum >= 2)
{
m_networkRequest.setUrl(m_alternateUrl);
QLOG_INFO() << QString("change url to [%1]").arg(m_alternateUrl.toString());
m_alternateUrl = ConfigManger::GetInstance().GetServerUrl();
}
QByteArray sendArray = QJsonDocument(requestJson).toJson(QJsonDocument::Compact);
QEventLoop eventLoop;
......@@ -52,6 +59,7 @@ bool BillSocket::Request(const QJsonObject &requestJson, QJsonObject &recvJson,
if(reply->error() != QNetworkReply::NoError)
{
m_errorNum++;
error = reply->errorString();
return false;
}
......@@ -59,11 +67,13 @@ bool BillSocket::Request(const QJsonObject &requestJson, QJsonObject &recvJson,
QByteArray recvArray = reply->readAll();
if(recvArray.size() == 0)
{
m_errorNum++;
error = "nothing recved";
return false;
}
recvJson = QJsonDocument::fromJson(recvArray).object();
reply->deleteLater();
m_errorNum = 0;
return true;
}
......@@ -16,6 +16,8 @@ public:
bool Request(const QJsonObject& requestJson, QJsonObject& recvJson, QString& error);
private:
int m_errorNum;
QUrl m_alternateUrl;
QNetworkAccessManager m_networkManger;
QNetworkRequest m_networkRequest;
};
......
......@@ -20,6 +20,7 @@
#define INI_PASSWORD "SqlServer/password"
#define INI_DATABASE "SqlServer/database"
#define INI_SERVER "FmServer/url"
#define INI_SERVER1 "FmServer/url1"
#define INI_PRINTERNAME "Printer/name"
#define INI_FLOATPOSTION "Float/postion"
#define INI_FLOATOPACITY "Float/opacity"
......
[FmServer]
url=http://waimaiapi.freemudorder.com/api
url=http://192.168.1.65:8083
url1=http://wmpos.sandload.cn/api
[RefundListener]
port=34953
......
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