订单流程添加修改

This commit is contained in:
lidg
2026-08-20 11:22:55 +08:00
parent 0c4fd6844c
commit 4e99071ce1
31 changed files with 1359 additions and 241 deletions
+73 -69
View File
@@ -18,10 +18,12 @@
#include <QSignalBlocker>
#include <QtGlobal>
#include <QPushButton>
#include <QMetaObject>
#include <QResizeEvent>
#include <QSizePolicy>
#include <QTableWidgetItem>
#include <QTimer>
#include <QThread>
#include <QVBoxLayout>
DashboardPage::DashboardPage(QWidget *parent)
@@ -41,9 +43,18 @@ DashboardPage::DashboardPage(QWidget *parent)
, processTable(new QTableWidget(processBox))
, processRefreshTimer(new QTimer(this))
, currentProcessElapsedMs(0)
, productionThread(new QThread(this))
, productionWorker(new ProductionWorker)
, productionState(ProductionService::Idle)
, productionTrayNo(0)
, productionSlotNo(0)
{
ui->setupUi(this);
productionWorker->moveToThread(productionThread);
connect(productionThread, &QThread::finished,
productionWorker, &QObject::deleteLater);
const QList<QLabel *> values = QList<QLabel *>()
<< ui->planValue << ui->pendingValue << ui->frontValue
<< ui->backValue << ui->okValue << ui->ngValue;
@@ -155,29 +166,30 @@ DashboardPage::DashboardPage(QWidget *parent)
connect(orderCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &DashboardPage::onOrderChanged);
ProductionService &production = ProductionService::instance();
connect(&production, &ProductionService::stateChanged,
connect(productionWorker, &ProductionWorker::stateChanged,
this, &DashboardPage::onProductionStateChanged);
connect(&production, &ProductionService::currentWorkpieceChanged,
connect(productionWorker, &ProductionWorker::currentWorkpieceChanged,
this, &DashboardPage::onCurrentWorkpieceChanged);
connect(&production, &ProductionService::productionError,
connect(productionWorker, &ProductionWorker::currentWorkpieceSnapshotChanged,
this, &DashboardPage::onCurrentWorkpieceSnapshotChanged);
connect(productionWorker, &ProductionWorker::currentPositionChanged,
this, &DashboardPage::onCurrentPositionChanged);
connect(productionWorker, &ProductionWorker::productionError,
this, &DashboardPage::onProductionError);
connect(&production, &ProductionService::productionFinished,
connect(productionWorker, &ProductionWorker::productionFinished,
this, &DashboardPage::onProductionFinished);
connect(&production, &ProductionService::processElapsedChanged,
connect(productionWorker, &ProductionWorker::processElapsedChanged,
this, &DashboardPage::onProcessElapsedChanged);
connect(&production, &ProductionService::timeoutRecoveryRequired,
connect(productionWorker, &ProductionWorker::timeoutRecoveryRequired,
this, &DashboardPage::onTimeoutRecoveryRequired);
connect(&production, &ProductionService::recoveryCompleted,
connect(productionWorker, &ProductionWorker::recoveryCompleted,
this, &DashboardPage::onRecoveryCompleted);
connect(&DeviceService::instance(), &DeviceService::statusChanged,
this, &DashboardPage::onDeviceStatusChanged);
QString restoreError;
if (!production.restoreActiveRun(&restoreError)) {
emit logRequested("Alarm log", "Production", "Restore production",
restoreError, "Failed");
}
productionThread->start();
QMetaObject::invokeMethod(productionWorker, "requestRestore",
Qt::QueuedConnection);
loadOrderOptions();
DeviceService::instance().startPolling();
@@ -190,6 +202,10 @@ DashboardPage::DashboardPage(QWidget *parent)
DashboardPage::~DashboardPage()
{
if (productionThread->isRunning()) {
productionThread->quit();
productionThread->wait();
}
delete ui;
}
@@ -251,46 +267,32 @@ void DashboardPage::startProduction()
return;
}
QString error;
const bool success = ProductionService::instance().state()
== ProductionService::Paused
? ProductionService::instance().resume(&error)
: ProductionService::instance().start(selectedOrderId, &error);
if (!success) {
QMessageBox::warning(this, "Start production failed", error);
emit logRequested("Operation log", "Dashboard", "Start production",
error, "Failed");
if (productionState == ProductionService::Paused) {
QMetaObject::invokeMethod(productionWorker, "requestResume",
Qt::QueuedConnection);
} else {
QMetaObject::invokeMethod(
productionWorker, "requestStart", Qt::QueuedConnection,
Q_ARG(int, selectedOrderId));
}
}
void DashboardPage::pauseProduction()
{
QString error;
if (!ProductionService::instance().pause(&error)) {
QMessageBox::warning(this, "Pause production failed", error);
emit logRequested("Operation log", "Dashboard", "Pause production",
error, "Failed");
}
QMetaObject::invokeMethod(productionWorker, "requestPause",
Qt::QueuedConnection);
}
void DashboardPage::stopProduction()
{
QString error;
if (!ProductionService::instance().stop(&error)) {
QMessageBox::warning(this, "Stop production failed", error);
emit logRequested("Operation log", "Dashboard", "Stop production",
error, "Failed");
}
QMetaObject::invokeMethod(productionWorker, "requestStop",
Qt::QueuedConnection);
}
void DashboardPage::resetProduction()
{
QString error;
if (!ProductionService::instance().reset(&error)) {
QMessageBox::warning(this, "Reset production failed", error);
emit logRequested("Operation log", "Dashboard", "Reset production",
error, "Failed");
}
QMetaObject::invokeMethod(productionWorker, "requestReset",
Qt::QueuedConnection);
}
void DashboardPage::clearAlarm()
@@ -318,12 +320,11 @@ void DashboardPage::onOrderChanged(int)
updateOrderSummary();
}
void DashboardPage::onProductionStateChanged(ProductionService::State,
void DashboardPage::onProductionStateChanged(ProductionService::State state,
const QString &name)
{
productionState = state;
ui->actionLabel->setText("Production state: " + name);
const ProductionService::State state = ProductionService::instance().state();
Q_UNUSED(state);
updateRecoveryButtons();
emit systemStateChanged(name);
emit currentStepChanged(name);
@@ -336,6 +337,7 @@ void DashboardPage::onCurrentWorkpieceChanged(int workpieceId,
{
if (workpieceId <= 0) {
ui->workpieceLabel->setText("Current workpiece: -");
ui->trayLabel->setText("Current tray: -");
currentProcessElapsedMs = 0;
} else {
ui->workpieceLabel->setText(
@@ -346,6 +348,23 @@ void DashboardPage::onCurrentWorkpieceChanged(int workpieceId,
updateProductionStats();
}
void DashboardPage::onCurrentWorkpieceSnapshotChanged(
const Workpiece &workpiece)
{
productionWorkpiece = workpiece;
refreshProcessRecords();
updateProductionStats();
}
void DashboardPage::onCurrentPositionChanged(int trayNo, int slotNo)
{
productionTrayNo = trayNo;
productionSlotNo = slotNo;
ui->trayLabel->setText(trayNo > 0
? QString("Current tray: %1 / slot: %2").arg(trayNo).arg(slotNo)
: "Current tray: -");
}
void DashboardPage::onProductionError(const QString &error)
{
ui->actionLabel->setText("Production error: " + error);
@@ -387,9 +406,7 @@ void DashboardPage::onRecoveryCompleted(const QString &mode)
void DashboardPage::recoverProduction()
{
ProductionService &production = ProductionService::instance();
QString error;
if (production.state() == ProductionService::ManualConfirm
if (productionState == ProductionService::ManualConfirm
&& QMessageBox::question(
this, "Continue production",
"Continue only after confirming the equipment and current PLC step are safe?",
@@ -398,22 +415,14 @@ void DashboardPage::recoverProduction()
return;
}
const bool success = production.recover(&error);
if (!success) {
QMessageBox::warning(this, "Recovery failed", error);
emit logRequested("Operation log", "Production", "Manual recovery",
error, "Failed");
}
QMetaObject::invokeMethod(productionWorker, "requestRecover",
Qt::QueuedConnection);
}
void DashboardPage::retryRecovery()
{
QString error;
if (!ProductionService::instance().retry(&error)) {
QMessageBox::warning(this, "Retry failed", error);
emit logRequested("Alarm log", "Production", "Retry production step",
error, "Failed");
}
QMetaObject::invokeMethod(productionWorker, "requestRetry",
Qt::QueuedConnection);
}
void DashboardPage::markWorkpieceNg()
@@ -426,17 +435,13 @@ void DashboardPage::markWorkpieceNg()
return;
}
QString error;
if (!ProductionService::instance().markCurrentWorkpieceNg(&error)) {
QMessageBox::warning(this, "Mark NG failed", error);
emit logRequested("Alarm log", "Production", "Mark workpiece NG",
error, "Failed");
}
QMetaObject::invokeMethod(productionWorker, "requestMarkNg",
Qt::QueuedConnection);
}
void DashboardPage::updateRecoveryButtons()
{
const ProductionService::State state = ProductionService::instance().state();
const ProductionService::State state = productionState;
const bool recoveryRequired = state == ProductionService::TimeoutPaused
|| state == ProductionService::ManualConfirm;
const bool running = state != ProductionService::Idle
@@ -444,8 +449,7 @@ void DashboardPage::updateRecoveryButtons()
recoverButton->setVisible(recoveryRequired);
retryButton->setVisible(recoveryRequired);
markNgButton->setVisible(recoveryRequired
&& ProductionService::instance()
.currentWorkpiece().id > 0);
&& productionWorkpiece.id > 0);
stopButton->setVisible(running);
recoverButton->setText(state == ProductionService::ManualConfirm
? "Continue" : "Recover");
@@ -467,7 +471,7 @@ QString DashboardPage::formatDuration(int elapsedMs)
void DashboardPage::refreshProcessRecords()
{
const Workpiece workpiece = ProductionService::instance().currentWorkpiece();
const Workpiece workpiece = productionWorkpiece;
if (workpiece.id <= 0) {
currentProcessLabel->setText("-");
processElapsedLabel->setText(formatDuration(0));
@@ -527,7 +531,7 @@ void DashboardPage::refreshProcessRecords()
void DashboardPage::updateCurrentProcessDuration(int elapsedMs)
{
const Workpiece workpiece = ProductionService::instance().currentWorkpiece();
const Workpiece workpiece = productionWorkpiece;
if (workpiece.id <= 0) {
return;
}