feat(production): 修改订单流程卡死流程问题

This commit is contained in:
lidg
2026-11-06 15:49:33 +08:00
parent 753f9c3ed2
commit 81313e61b0
24 changed files with 949 additions and 261 deletions
+69 -15
View File
@@ -48,6 +48,7 @@ QString displayState(const QString &state)
if (state == "FRONT_CHECKING") return "正面检测";
if (state == "FRONT_UNLOADING") return "正面下料";
if (state == "FLIPPING") return "翻面";
if (state == "REVERSE_FLIPPING") return "反向翻面";
if (state == "BACK_LOADING") return "反面上料";
if (state == "BACK_CHECKING") return "反面检测";
if (state == "BACK_UNLOADING") return "反面下料";
@@ -80,6 +81,7 @@ QString displayRecoveryAction(const QString &action)
if (action == "INSPECT") return "检测";
if (action == "FRONT_UNLOAD") return "正面下料";
if (action == "FLIP") return "翻面";
if (action == "REVERSE_FLIP") return "反向翻面";
if (action == "BACK_LOAD") return "反面上料";
if (action == "BACK_UNLOAD") return "反面下料";
if (action == "RACK_PLACE") return "料架放料";
@@ -287,8 +289,8 @@ DashboardPage::DashboardPage(QWidget *parent)
this, &DashboardPage::clearAlarm);
connect(markNgButton, &QPushButton::clicked,
this, &DashboardPage::markWorkpieceNg);
connect(productionWorker, &ProductionWorker::stateChanged,
this, &DashboardPage::onProductionStateChanged);
connect(productionWorker, &ProductionWorker::snapshotChanged,
this, &DashboardPage::onProductionSnapshot);
connect(productionWorker, &ProductionWorker::currentWorkpieceChanged,
this, &DashboardPage::onCurrentWorkpieceChanged);
connect(productionWorker, &ProductionWorker::currentWorkpieceSnapshotChanged,
@@ -424,6 +426,7 @@ void DashboardPage::updateRackSize()
void DashboardPage::startProduction()
{
if (!productionSnapshot.initialized) return;
if (recoveryBusy || visionRecoveryRequired) return;
if (productionState == ProductionService::Paused) {
if (!currentOrderResumable) return;
@@ -449,7 +452,7 @@ void DashboardPage::startProduction()
ui->startButton->setEnabled(false);
if (!QMetaObject::invokeMethod(
productionWorker, "requestStart", Qt::QueuedConnection,
Q_ARG(int, currentOrderId))) {
Q_ARG(int, selectedOrderId))) {
updateRecoveryButtons();
QMessageBox::warning(this, "启动生产",
"提交生产启动请求失败。");
@@ -466,11 +469,17 @@ void DashboardPage::pauseProduction()
void DashboardPage::stopProduction()
{
if (!productionSnapshot.initialized) return;
const bool active = productionState != ProductionService::Idle
&& productionState != ProductionService::Completed;
const int confirmedRunId = active ? productionSnapshot.runId : 0;
const int confirmedOrderId = active ? productionSnapshot.orderId : selectedOrderId;
if (!stopButton->isEnabled()
|| !confirmControlOperation("终止订单", "将当前订单标记为已完成,保留实际加工数量及记录,剩余工件不再执行。此操作不是机器人急停。")) return;
if (recoveryDialog) recoveryDialog->reject();
QMetaObject::invokeMethod(productionWorker, "requestStopOrder",
Qt::QueuedConnection, Q_ARG(int, currentOrderId));
Qt::QueuedConnection, Q_ARG(int, confirmedRunId),
Q_ARG(int, confirmedOrderId));
}
void DashboardPage::clearAlarm()
@@ -490,7 +499,12 @@ QString DashboardPage::controlOperationContext(QString *identity) const
ProductionRunSnapshot run;
if (currentOrderId > 0
&& !OrderService::instance().findOrder(currentOrderId, &order, &error)) return QString();
if (!ProductionRepository().findActiveRun(&run, &error)) return QString();
const bool active = productionState != ProductionService::Idle
&& productionState != ProductionService::Completed;
if (active && productionSnapshot.runId > 0) {
if (!ProductionRepository().findRun(productionSnapshot.runId, &run, &error))
return QString();
} else if (!ProductionRepository().findActiveRun(&run, &error)) return QString();
if (run.id > 0 && run.orderId != currentOrderId) return QString();
Workpiece piece;
@@ -575,6 +589,19 @@ bool DashboardPage::confirmControlOperation(const QString &title, const QString
return true;
}
void DashboardPage::onProductionSnapshot(const ProductionService::Snapshot &snapshot)
{
productionSnapshot = snapshot;
visionRecoveryRequired = snapshot.visionRecoveryRequired;
onProductionStateChanged(snapshot.state, snapshot.stateName);
if (!snapshot.initialized) {
ui->actionLabel->setText(snapshot.error.isEmpty()
? "正在检查上次生产状态..." : "初始化失败:" + snapshot.error);
} else if (!snapshot.error.isEmpty()) {
ui->actionLabel->setText("生产状态:" + snapshot.error);
}
}
void DashboardPage::onProductionStateChanged(ProductionService::State state,
const QString &name)
{
@@ -670,6 +697,11 @@ void DashboardPage::onRecoveryCompleted(const QString &mode)
void DashboardPage::recoverProduction()
{
if (recoveryBusy || !ui->recoveryButton->isEnabled()) return;
if (!productionSnapshot.initialized) {
onRecoveryBusyChanged(true);
QMetaObject::invokeMethod(productionWorker, "requestRestore", Qt::QueuedConnection);
return;
}
if (!confirmControlOperation("恢复/重试", "先读取设备及动作记录,检查能否安全恢复;状态不明确时再由人工选择。本次确认不保证立即继续生产。")) return;
onRecoveryBusyChanged(true);
ui->actionLabel->setText("正在检查设备状态和动作记录...");
@@ -819,6 +851,16 @@ void DashboardPage::markWorkpieceNg()
void DashboardPage::updateRecoveryButtons()
{
if (!productionSnapshot.initialized) {
ui->startButton->setEnabled(false);
ui->pauseButton->setEnabled(false);
stopButton->setEnabled(false);
ui->clearAlarmButton->setEnabled(false);
markNgButton->setEnabled(false);
ui->recoveryButton->setEnabled(!productionSnapshot.error.isEmpty() && !recoveryBusy);
ui->recoveryButton->setText("重新检查生产状态");
return;
}
const ProductionService::State state = productionState;
const bool recoveryRequired = state == ProductionService::TimeoutPaused
|| state == ProductionService::ManualConfirm
@@ -833,18 +875,24 @@ void DashboardPage::updateRecoveryButtons()
&& currentOrderResumable))
&& !visionRecoveryRequired && !recoveryBusy;
ui->startButton->setEnabled(canStart);
ui->startButton->setToolTip(visionRecoveryRequired
? "上次视觉任务尚未清理,请先解除视觉遗留锁或恢复/终止当前任务" : QString());
ui->startButton->setText(state == ProductionService::Paused
? "继续" : "启动");
ui->recoveryButton->setVisible(true);
ui->recoveryButton->setEnabled(recoveryRequired && !terminating && !recoveryBusy);
ui->recoveryButton->setText(recoveryBusy ? "恢复检查中..." : "恢复/重试");
ui->recoveryButton->setEnabled(recoveryRequired && !terminating && !recoveryBusy
&& !productionSnapshot.terminationRequired);
ui->recoveryButton->setText(recoveryBusy ? "恢复检查中..."
: state == ProductionService::Idle && visionRecoveryRequired
? "解除视觉遗留锁" : "恢复/重试");
ui->pauseButton->setEnabled(running && !recoveryRequired
&& state != ProductionService::Paused
&& !recoveryBusy && !terminating);
ui->clearAlarmButton->setEnabled(!recoveryBusy && !terminating);
markNgButton->setVisible(recoveryRequired
&& productionWorkpiece.id > 0 && !visionRecoveryRequired);
markNgButton->setEnabled(!recoveryBusy && !terminating);
markNgButton->setEnabled(!recoveryBusy && !terminating
&& !productionSnapshot.terminationRequired);
stopButton->setVisible(true);
stopButton->setEnabled(currentOrderId > 0 && !terminating);
stopButton->setText(terminating ? "终止中..." : "终止");
@@ -1071,16 +1119,21 @@ void DashboardPage::loadCurrentOrder()
{
QString error;
Order order;
ProductionRunSnapshot run;
const bool loaded = ProductionRepository().findActiveRun(&run, &error)
&& (run.id > 0
? OrderService::instance().findOrder(run.orderId, &order, &error)
: OrderService::instance().findUnfinishedOrder(&order, &error));
const bool active = productionSnapshot.orderId > 0
&& productionState != ProductionService::Idle
&& productionState != ProductionService::Completed;
const bool loaded = active
? OrderService::instance().findOrder(productionSnapshot.orderId, &order, &error)
: OrderService::instance().findUnfinishedOrder(&order, &error);
if (!loaded) {
currentOrderId = 0;
currentOrderId = active ? productionSnapshot.orderId : 0;
selectedOrderId = 0;
currentOrderStartable = false;
currentOrderResumable = false;
ui->orderLabel->setText("当前订单:读取失败");
ui->orderLabel->setText(active
? QString("当前生产订单 %1:记录缺失或读取失败,请核对").arg(currentOrderId)
: QString("当前订单:读取失败"));
updateRecoveryButtons();
updateProductionStats();
updateRackSummary();
emit logRequested("操作日志", "控制面板", "加载订单",
@@ -1089,6 +1142,7 @@ void DashboardPage::loadCurrentOrder()
}
currentOrderId = order.id;
selectedOrderId = active ? 0 : order.id;
currentOrderStartable = false;
currentOrderResumable = false;
if (order.id <= 0) {