1、解决获取Token时,返回数据的格式异常问题
2、解决上传失败且获取授权失败后,形成死循环问题
This commit is contained in:
Mr.V 2024-02-29 19:35:22 +08:00
parent 616af867e3
commit 2c6517030f
1 changed files with 21 additions and 30 deletions

View File

@ -82,34 +82,34 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
this->logInfo("-- 程序退出 --"); this->logInfo("-- 程序退出 --");
this->recvLog.close(); this->initParam();
this->vecTrain.clear();
this->needIdentify = false;
this->rnameRfidLog();
this->queue_.clear();
delete ui; delete ui;
} }
void MainWindow::logDebug(const QString& message) { void MainWindow::logDebug(const QString& message) {
LogDebug << message.toStdString(); LogDebug << message.toStdString();
ui->textBrowser->append(QString("[Debug] [") + this->getSystemTime() + QString::fromStdString("] ") + message);
ui->textBrowser->append(QString("[Debug] [") + this->currentTime_.toString("yyyy-MM-dd hh:mm:ss") + QString::fromStdString("] ") + message);
} }
void MainWindow::logInfo(const QString& message) { void MainWindow::logInfo(const QString& message) {
LogInfo << message.toStdString(); LogInfo << message.toStdString();
ui->textBrowser->append(QString("[Info] [") + this->currentTime_.toString("yyyy-MM-dd hh:mm:ss") + QString::fromStdString("] ") + message); ui->textBrowser->append(QString("[Info] [") + this->getSystemTime() + QString::fromStdString("] ") + message);
} }
void MainWindow::logWarn(const QString& message) { void MainWindow::logWarn(const QString& message) {
LogWarn << message.toStdString(); LogWarn << message.toStdString();
ui->textBrowser->append(QString("[Warn] [") + this->currentTime_.toString("yyyy-MM-dd hh:mm:ss") + QString::fromStdString("] ") + message); ui->textBrowser->append(QString("[Warn] [") + this->getSystemTime() + QString::fromStdString("] ") + message);
} }
void MainWindow::logError(const QString& message) { void MainWindow::logError(const QString& message) {
LogError << message.toStdString(); LogError << message.toStdString();
ui->textBrowser->append(QString("[Error] [") + this->currentTime_.toString("yyyy-MM-dd hh:mm:ss") + QString::fromStdString("] ") + message); ui->textBrowser->append(QString("[Error] [") + this->getSystemTime() + QString::fromStdString("] ") + message);
} }
void MainWindow::initParam() { void MainWindow::initParam() {
this->trainTime = ""; this->trainTime = "";
this->recvLog.close();
this->vecTrain.clear();
this->needIdentify = false;
this->rnameRfidLog();
this->queue_.clear();
} }
/** /**
@ -316,7 +316,7 @@ bool MainWindow::upWeb(std::string &carriageType, std::string &carriageNumber, s
if (root["msg"].asString() == "请求未授权") { if (root["msg"].asString() == "请求未授权") {
this->logWarn("因请求未授权而上传识别结果失败重新请求token。"); this->logWarn("因请求未授权而上传识别结果失败重新请求token。");
this->getToken(); if (!this->getToken()) return false;
return this->upWeb(carriageType, carriageNumber, carriageOrder, time); return this->upWeb(carriageType, carriageNumber, carriageOrder, time);
} }
this->logError("识别结果上传失败,原因:" + QString::fromStdString(root.asString())); this->logError("识别结果上传失败,原因:" + QString::fromStdString(root.asString()));
@ -382,7 +382,7 @@ bool MainWindow::getToken()
if (parsingSuccessful) if (parsingSuccessful)
{ {
if (root["success"].asBool()) if (!root.get("token_type", "").asString().empty())
{ {
this->webToken = root["token_type"].asString(); this->webToken = root["token_type"].asString();
this->webToken.append(" "); this->webToken.append(" ");
@ -448,11 +448,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
// 验证账号和密码是否正确 // 验证账号和密码是否正确
if (password == "matrix") { if (password == "matrix") {
this->recvLog.close(); this->initParam();
this->vecTrain.clear();
this->needIdentify = false;
this->rnameRfidLog();
this->queue_.clear();
event->accept(); // 关闭窗口 event->accept(); // 关闭窗口
exit(0); exit(0);
} else { } else {
@ -567,11 +563,7 @@ void MainWindow::openComClicked()
if (this->needIdentify == true) this->needIdentify = false; if (this->needIdentify == true) this->needIdentify = false;
this->isOpenCom = false; this->isOpenCom = false;
this->logInfo("串口已关闭!"); this->logInfo("串口已关闭!");
this->recvLog.close(); this->initParam();
this->vecTrain.clear();
this->needIdentify = false;
this->rnameRfidLog();
this->queue_.clear();
this->ui->openComButton->setText("打开串口"); this->ui->openComButton->setText("打开串口");
this->ui->LEDlabel->setStyleSheet("border-radius: 16px;\ " this->ui->LEDlabel->setStyleSheet("border-radius: 16px;\ "
"background-color: red;\ " "background-color: red;\ "
@ -645,6 +637,9 @@ void MainWindow::getQueueDataThread()
QString strTrainInfo = i.left(14); QString strTrainInfo = i.left(14);
if (vecTrain.empty() || !vecTrain.contains(strTrainInfo)) if (vecTrain.empty() || !vecTrain.contains(strTrainInfo))
{ {
bool isCarriage = false;
strTrainInfo.mid(3, 2).toInt(&isCarriage);
if (isCarriage) continue;
vecTrain.append(strTrainInfo); vecTrain.append(strTrainInfo);
this->resultTableModel_->setItem(vecTrain.size()-1, 0, new QStandardItem(strTrainInfo)); this->resultTableModel_->setItem(vecTrain.size()-1, 0, new QStandardItem(strTrainInfo));
emit upRfid_signals(); emit upRfid_signals();
@ -661,10 +656,7 @@ void MainWindow::getQueueDataThread()
{ {
// 关功放信号 // 关功放信号
// TODO: 需要结合 “来车状态”广播消息,确认是否真的车离开了 没有真离开,则向串口发送 @on& 避免关功放 // TODO: 需要结合 “来车状态”广播消息,确认是否真的车离开了 没有真离开,则向串口发送 @on& 避免关功放
this->vecTrain.clear(); this->initParam();
this->needIdentify = false;
this->rnameRfidLog();
this->queue_.clear();
this->logInfo("功放关闭"); this->logInfo("功放关闭");
} }
else else
@ -677,6 +669,7 @@ void MainWindow::getQueueDataThread()
this->logInfo("来车了"); this->logInfo("来车了");
this->mkRfidLog(); this->mkRfidLog();
this->needIdentify = true; this->needIdentify = true;
this->trainTime = this->getSystemTime();
this->resultTableModel_->clear(); this->resultTableModel_->clear();
this->resultTableModel_ = this->getStandardItemModel(); this->resultTableModel_ = this->getStandardItemModel();
} }
@ -705,12 +698,10 @@ void MainWindow::upRfid()
int order = this->vecTrain.size(); int order = this->vecTrain.size();
info = info.mid(1,info.size() - 1); info = info.mid(1,info.size() - 1);
bool isCarriage = false;
info.mid(2, 2).toInt(&isCarriage);
if (isCarriage) return;
std::string carriageType = info.left(7).toStdString(); std::string carriageType = info.left(7).toStdString();
std::string carriageNum = info.mid(7, info.size() - 7).toStdString(); std::string carriageNum = info.mid(7, info.size() - 7).toStdString();
std::string nowTime = this->getSystemTime().toStdString(); std::string nowTime = this->trainTime.toStdString();
std::string strOrder = QString::number(order).toStdString(); std::string strOrder = QString::number(order).toStdString();
if (!this->upWeb(carriageType, carriageNum, strOrder, nowTime)) if (!this->upWeb(carriageType, carriageNum, strOrder, nowTime))
{ {