订单流程添加修改
This commit is contained in:
+129
-9
@@ -11,6 +11,51 @@ namespace {
|
||||
|
||||
const int FeedbackPollIntervalMs = 50;
|
||||
|
||||
bool actionAddresses(DeviceService::ProductionAction action,
|
||||
const ModbusAddressMap &addresses,
|
||||
int *commandAddress, int *feedbackAddress)
|
||||
{
|
||||
if (!commandAddress || !feedbackAddress) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case DeviceService::RackPick:
|
||||
*commandAddress = addresses.rackPickCommand;
|
||||
*feedbackAddress = addresses.rackPickFeedback;
|
||||
return true;
|
||||
case DeviceService::FrontLoad:
|
||||
*commandAddress = addresses.frontLoadCommand;
|
||||
*feedbackAddress = addresses.frontLoadFeedback;
|
||||
return true;
|
||||
case DeviceService::Inspect:
|
||||
*commandAddress = addresses.inspectionCommand;
|
||||
*feedbackAddress = addresses.inspectionFeedback;
|
||||
return true;
|
||||
case DeviceService::FrontUnload:
|
||||
*commandAddress = addresses.frontUnloadCommand;
|
||||
*feedbackAddress = addresses.frontUnloadFeedback;
|
||||
return true;
|
||||
case DeviceService::Flip:
|
||||
*commandAddress = addresses.flipCommand;
|
||||
*feedbackAddress = addresses.flipFeedback;
|
||||
return true;
|
||||
case DeviceService::BackLoad:
|
||||
*commandAddress = addresses.backLoadCommand;
|
||||
*feedbackAddress = addresses.backLoadFeedback;
|
||||
return true;
|
||||
case DeviceService::BackUnload:
|
||||
*commandAddress = addresses.backUnloadCommand;
|
||||
*feedbackAddress = addresses.backUnloadFeedback;
|
||||
return true;
|
||||
case DeviceService::RackPlace:
|
||||
*commandAddress = addresses.rackPlaceCommand;
|
||||
*feedbackAddress = addresses.rackPlaceFeedback;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DeviceService &DeviceService::instance()
|
||||
@@ -188,6 +233,75 @@ bool DeviceService::clearAlarm(QString *error)
|
||||
return executeCommand(addresses.clearAlarmCommand, addresses.clearAlarmFeedback, error);
|
||||
}
|
||||
|
||||
bool DeviceService::setInspectionMode(const QString &mode, QString *error)
|
||||
{
|
||||
if (mode != "BEFORE_PLATING" && mode != "AFTER_PLATING") {
|
||||
if (error) {
|
||||
*error = "Inspection mode must be BEFORE_PLATING or AFTER_PLATING";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (ConfigManager::instance().simulationMode()) {
|
||||
return true;
|
||||
}
|
||||
if (!ConfigManager::instance().productionEnabled()) {
|
||||
if (error) {
|
||||
*error = "Production control is disabled by configuration";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool afterPlating = mode == "AFTER_PLATING";
|
||||
const ModbusAddressMap &addresses = ModbusTcpManager::instance().config().addressMap;
|
||||
if (!ModbusTcpManager::instance().writeCoil(
|
||||
addresses.inspectionMode, afterPlating, error)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeviceService::executeProductionAction(ProductionAction action,
|
||||
int trayNo, int slotNo,
|
||||
QString *error)
|
||||
{
|
||||
if (ConfigManager::instance().simulationMode()) {
|
||||
return true;
|
||||
}
|
||||
if (!ConfigManager::instance().productionEnabled()) {
|
||||
if (error) {
|
||||
*error = "Production control is disabled by configuration";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (trayNo <= 0 || slotNo < 1 || slotNo > 49) {
|
||||
if (error) {
|
||||
*error = "PLC tray or slot position is invalid";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const ModbusAddressMap &addresses = ModbusTcpManager::instance().config().addressMap;
|
||||
if (action == RackPick || action == RackPlace) {
|
||||
ModbusTcpManager &modbus = ModbusTcpManager::instance();
|
||||
if (!modbus.writeHoldingRegister(
|
||||
addresses.trayNumber, static_cast<quint16>(trayNo), error)
|
||||
|| !modbus.writeHoldingRegister(
|
||||
addresses.slotNumber, static_cast<quint16>(slotNo), error)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int commandAddress = -1;
|
||||
int feedbackAddress = -1;
|
||||
if (!actionAddresses(action, addresses, &commandAddress, &feedbackAddress)) {
|
||||
if (error) {
|
||||
*error = "Unknown PLC production action";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return executeCommand(commandAddress, feedbackAddress, error);
|
||||
}
|
||||
|
||||
bool DeviceService::connectWithRetry(QString *error)
|
||||
{
|
||||
ModbusTcpManager &modbus = ModbusTcpManager::instance();
|
||||
@@ -260,17 +374,22 @@ bool DeviceService::executeCommand(int commandAddress, int feedbackAddress, QStr
|
||||
continue;
|
||||
}
|
||||
|
||||
QThread::msleep(qMax(1, config.commandPulseMs));
|
||||
if (!modbus.writeCoil(commandAddress, false, &lastError)) {
|
||||
if (!waitForFeedback(feedbackAddress, &lastError)) {
|
||||
modbus.writeCoil(commandAddress, false);
|
||||
modbus.disconnectDevice();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (waitForFeedback(feedbackAddress, &lastError)) {
|
||||
return true;
|
||||
if (!modbus.writeCoil(commandAddress, false, &lastError)) {
|
||||
modbus.disconnectDevice();
|
||||
continue;
|
||||
}
|
||||
if (!modbus.writeCoil(feedbackAddress, false, &lastError)) {
|
||||
modbus.disconnectDevice();
|
||||
continue;
|
||||
}
|
||||
|
||||
modbus.disconnectDevice();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
@@ -282,11 +401,12 @@ bool DeviceService::executeCommand(int commandAddress, int feedbackAddress, QStr
|
||||
bool DeviceService::waitForFeedback(int address, QString *error)
|
||||
{
|
||||
ModbusTcpManager &modbus = ModbusTcpManager::instance();
|
||||
const int timeoutMs = qMax(1, modbus.config().feedbackTimeoutMs);
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
// const int timeoutMs = qMax(1, modbus.config().feedbackTimeoutMs);
|
||||
// QElapsedTimer timer;
|
||||
// timer.start();
|
||||
|
||||
while (timer.elapsed() < timeoutMs) {
|
||||
//while (timer.elapsed() < timeoutMs) {
|
||||
while (true) {
|
||||
bool feedback = false;
|
||||
if (!modbus.readCoil(address, &feedback, error)) {
|
||||
return false;
|
||||
|
||||
@@ -26,6 +26,18 @@ class DeviceService : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum ProductionAction
|
||||
{
|
||||
RackPick,
|
||||
FrontLoad,
|
||||
Inspect,
|
||||
FrontUnload,
|
||||
Flip,
|
||||
BackLoad,
|
||||
BackUnload,
|
||||
RackPlace
|
||||
};
|
||||
|
||||
static DeviceService &instance();
|
||||
|
||||
void startPolling();
|
||||
@@ -37,6 +49,9 @@ public:
|
||||
bool pause(QString *error = nullptr);
|
||||
bool reset(QString *error = nullptr);
|
||||
bool clearAlarm(QString *error = nullptr);
|
||||
bool setInspectionMode(const QString &mode, QString *error = nullptr);
|
||||
bool executeProductionAction(ProductionAction action, int trayNo,
|
||||
int slotNo, QString *error = nullptr);
|
||||
|
||||
signals:
|
||||
void statusChanged(const DeviceStatus &status);
|
||||
|
||||
@@ -72,6 +72,20 @@ bool OrderService::createOrder(Order *order, QString *error)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (order->inspectionMode != "BEFORE_PLATING"
|
||||
&& order->inspectionMode != "AFTER_PLATING") {
|
||||
if (error) {
|
||||
*error = "Inspection mode must be BEFORE_PLATING or AFTER_PLATING";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (order->startTrayNo <= 0
|
||||
|| order->startSlotNo < 1 || order->startSlotNo > 49) {
|
||||
if (error) {
|
||||
*error = "Start tray or slot is invalid";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
order->no = order->no.trimmed();
|
||||
order->status = "NOT_START";
|
||||
@@ -88,6 +102,23 @@ bool OrderService::createOrder(Order *order, QString *error)
|
||||
}
|
||||
|
||||
OrderRepository repository;
|
||||
Order unfinishedOrder;
|
||||
if (!repository.findUnfinishedOrder(&unfinishedOrder, &transactionError)) {
|
||||
database.rollback();
|
||||
if (error) {
|
||||
*error = transactionError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (unfinishedOrder.id > 0) {
|
||||
database.rollback();
|
||||
if (error) {
|
||||
*error = QString("Unfinished order already exists: %1")
|
||||
.arg(unfinishedOrder.no);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!repository.insertOrder(order, &transactionError)
|
||||
|| !recordLog("新建订单", "创建订单:" + order->no, "成功", &transactionError)
|
||||
|| !database.commit(&transactionError)) {
|
||||
@@ -205,9 +236,50 @@ bool OrderService::generateWorkpiecesAndAssign(int orderId, QString *error)
|
||||
}
|
||||
|
||||
const int requiredSlotCount = order.planNum - assignedCount;
|
||||
const QList<TraySlot> emptySlots = requiredSlotCount > 0
|
||||
? trayRepository.listEmptySlotsForAllocation(&transactionError)
|
||||
: QList<TraySlot>();
|
||||
QList<TraySlot> emptySlots;
|
||||
if (requiredSlotCount > 0) {
|
||||
const int startTrayIndex = order.startTrayNo - 1;
|
||||
if (startTrayIndex < 0 || startTrayIndex >= trays.size()) {
|
||||
database.rollback();
|
||||
if (error) {
|
||||
*error = QString("Start tray %1 is outside the configured tray range")
|
||||
.arg(order.startTrayNo);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int trayIndex = startTrayIndex;
|
||||
trayIndex < trays.size() && emptySlots.size() < requiredSlotCount;
|
||||
++trayIndex) {
|
||||
const Tray &tray = trays.at(trayIndex);
|
||||
if (!tray.present) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const QList<TraySlot> slots =
|
||||
trayRepository.listSlots(tray.id, &transactionError);
|
||||
if (!transactionError.isEmpty()) {
|
||||
database.rollback();
|
||||
if (error) {
|
||||
*error = transactionError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const TraySlot &slot : slots) {
|
||||
const int position = (slot.rowNo - 1) * 7 + slot.columnNo;
|
||||
if (trayIndex == startTrayIndex && position < order.startSlotNo) {
|
||||
continue;
|
||||
}
|
||||
if (slot.workpieceId == 0 && slot.state == "EMPTY") {
|
||||
emptySlots.append(slot);
|
||||
if (emptySlots.size() >= requiredSlotCount) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!transactionError.isEmpty()) {
|
||||
database.rollback();
|
||||
if (error) {
|
||||
|
||||
+256
-106
@@ -3,6 +3,7 @@
|
||||
#include "../config/configmanager.h"
|
||||
#include "../repositories/productionrepository.h"
|
||||
#include "orderservice.h"
|
||||
#include "trayservice.h"
|
||||
#include "workpieceservice.h"
|
||||
|
||||
#include <QDebug>
|
||||
@@ -24,6 +25,9 @@ ProductionService::ProductionService(QObject *parent)
|
||||
, m_deviceStatusValid(false)
|
||||
, m_recoveryRetryCount(0)
|
||||
, m_processElapsedMs(0)
|
||||
, m_currentTrayNo(0)
|
||||
, m_currentSlotNo(0)
|
||||
, m_frontRawResult(0)
|
||||
{
|
||||
connect(m_timer, &QTimer::timeout, this, &ProductionService::tick);
|
||||
connect(&DeviceService::instance(), &DeviceService::statusChanged,
|
||||
@@ -48,9 +52,16 @@ QString ProductionService::stateNameForState(State state) const
|
||||
case Idle: return "IDLE";
|
||||
case Preparing: return "PREPARING";
|
||||
case WaitingDeviceReady: return "WAITING_DEVICE_READY";
|
||||
case RackPicking: return "RACK_PICKING";
|
||||
case FrontLoading: return "FRONT_LOADING";
|
||||
case Loading: return "LOADING";
|
||||
case FrontChecking: return "FRONT_CHECKING";
|
||||
case FrontUnloading: return "FRONT_UNLOADING";
|
||||
case Flipping: return "FLIPPING";
|
||||
case BackLoading: return "BACK_LOADING";
|
||||
case BackChecking: return "BACK_CHECKING";
|
||||
case BackUnloading: return "BACK_UNLOADING";
|
||||
case RackPlacing: return "RACK_PLACING";
|
||||
case Judging: return "JUDGING";
|
||||
case Unloading: return "UNLOADING";
|
||||
case Paused: return "PAUSED";
|
||||
@@ -70,6 +81,21 @@ int ProductionService::orderId() const
|
||||
return m_orderId;
|
||||
}
|
||||
|
||||
int ProductionService::currentTrayNo() const
|
||||
{
|
||||
return m_currentTrayNo;
|
||||
}
|
||||
|
||||
int ProductionService::currentSlotNo() const
|
||||
{
|
||||
return m_currentSlotNo;
|
||||
}
|
||||
|
||||
QString ProductionService::inspectionMode() const
|
||||
{
|
||||
return m_inspectionMode;
|
||||
}
|
||||
|
||||
Workpiece ProductionService::currentWorkpiece() const
|
||||
{
|
||||
return m_currentWorkpiece;
|
||||
@@ -101,6 +127,16 @@ bool ProductionService::start(int orderId, QString *error)
|
||||
return false;
|
||||
}
|
||||
|
||||
m_inspectionMode = order.inspectionMode;
|
||||
m_currentTrayNo = 0;
|
||||
m_currentSlotNo = 0;
|
||||
m_frontRawResult = 0;
|
||||
m_frontResultState.clear();
|
||||
|
||||
if (!DeviceService::instance().setInspectionMode(
|
||||
m_inspectionMode, error)) {
|
||||
return false;
|
||||
}
|
||||
if (!DeviceService::instance().start(error)
|
||||
|| !OrderService::instance().startOrder(orderId, error)) {
|
||||
return false;
|
||||
@@ -115,7 +151,9 @@ bool ProductionService::start(int orderId, QString *error)
|
||||
|
||||
QString persistenceError;
|
||||
m_runId = ProductionRepository().createRun(
|
||||
m_orderId, "PREPARING", "PREPARING", &persistenceError);
|
||||
m_orderId, "PREPARING", "PREPARING", order.inspectionMode,
|
||||
order.startTrayNo, order.startSlotNo, order.planNum,
|
||||
&persistenceError);
|
||||
if (m_runId <= 0) {
|
||||
DeviceService::instance().pause();
|
||||
OrderService::instance().pauseOrder(m_orderId);
|
||||
@@ -168,6 +206,8 @@ bool ProductionService::resume(QString *error)
|
||||
}
|
||||
|
||||
if (!checkRecoverySafety(error)
|
||||
|| !DeviceService::instance().setInspectionMode(
|
||||
m_inspectionMode, error)
|
||||
|| !DeviceService::instance().start(error)
|
||||
|| !OrderService::instance().resumeOrder(m_orderId, error)) {
|
||||
return false;
|
||||
@@ -235,6 +275,8 @@ bool ProductionService::stop(QString *error)
|
||||
m_currentWorkpiece = Workpiece();
|
||||
clearProcessTimer();
|
||||
emit currentWorkpieceChanged(0, QString());
|
||||
emit currentWorkpieceSnapshotChanged(m_currentWorkpiece);
|
||||
emit currentPositionChanged(0, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -298,6 +340,7 @@ bool ProductionService::restoreActiveRun(QString *error)
|
||||
|
||||
m_runId = run.id;
|
||||
m_orderId = run.orderId;
|
||||
m_inspectionMode = run.inspectionMode;
|
||||
m_recoveryRetryCount = run.recoveryRetryCount;
|
||||
m_lastError = run.lastError;
|
||||
|
||||
@@ -312,6 +355,8 @@ bool ProductionService::restoreActiveRun(QString *error)
|
||||
}
|
||||
emit currentWorkpieceChanged(m_currentWorkpiece.id,
|
||||
m_currentWorkpiece.barcode);
|
||||
emit currentWorkpieceSnapshotChanged(m_currentWorkpiece);
|
||||
emit currentPositionChanged(m_currentTrayNo, m_currentSlotNo);
|
||||
startProcessTimer(m_currentWorkpiece.processStep);
|
||||
emitProcessElapsed();
|
||||
}
|
||||
@@ -351,6 +396,8 @@ bool ProductionService::recover(QString *error)
|
||||
|
||||
QString operationError;
|
||||
if (!ensureOrderRunning(&operationError)
|
||||
|| !DeviceService::instance().setInspectionMode(
|
||||
m_inspectionMode, &operationError)
|
||||
|| !DeviceService::instance().start(&operationError)) {
|
||||
if (error) {
|
||||
*error = operationError;
|
||||
@@ -392,6 +439,8 @@ bool ProductionService::retry(QString *error)
|
||||
|
||||
QString operationError;
|
||||
if (!ensureOrderRunning(&operationError)
|
||||
|| !DeviceService::instance().setInspectionMode(
|
||||
m_inspectionMode, &operationError)
|
||||
|| !DeviceService::instance().start(&operationError)) {
|
||||
if (error) {
|
||||
*error = operationError;
|
||||
@@ -454,7 +503,8 @@ bool ProductionService::markCurrentWorkpieceNg(QString *error)
|
||||
const QString previousProcessStep = m_currentWorkpiece.processStep;
|
||||
if (!WorkpieceService::instance().completeWithInspection(
|
||||
m_currentWorkpiece.id, "NG", "COMPLETE", previousProcessStep,
|
||||
durationMs, -1, "NG", m_deviceStatus.currentStep, "MANUAL",
|
||||
durationMs, -1, "NG", m_deviceStatus.currentStep,
|
||||
m_inspectionMode, "MANUAL",
|
||||
&operationError)) {
|
||||
if (error) {
|
||||
*error = operationError;
|
||||
@@ -471,6 +521,8 @@ bool ProductionService::markCurrentWorkpieceNg(QString *error)
|
||||
m_recoveryRetryCount = 0;
|
||||
m_lastError.clear();
|
||||
emit currentWorkpieceChanged(0, QString());
|
||||
emit currentWorkpieceSnapshotChanged(m_currentWorkpiece);
|
||||
emit currentPositionChanged(0, 0);
|
||||
setState(Preparing);
|
||||
const int interval = qMax(100, ConfigManager::instance()
|
||||
.modbusConfig().pollIntervalMs);
|
||||
@@ -525,12 +577,35 @@ bool ProductionService::claimNextWorkpiece(QString *error)
|
||||
|
||||
m_currentWorkpiece = workpiece;
|
||||
m_recoveryRetryCount = 0;
|
||||
m_currentTrayNo = 0;
|
||||
m_currentSlotNo = workpiece.trayPos;
|
||||
QString trayError;
|
||||
const QList<Tray> trays = TrayService::instance().listTrays(&trayError);
|
||||
if (!trayError.isEmpty()) {
|
||||
if (error) {
|
||||
*error = trayError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
for (int index = 0; index < trays.size(); ++index) {
|
||||
if (trays.at(index).id == workpiece.trayId) {
|
||||
m_currentTrayNo = index + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (m_currentTrayNo <= 0 || m_currentSlotNo < 1 || m_currentSlotNo > 49) {
|
||||
if (error) {
|
||||
*error = "Current workpiece tray position cannot be mapped to PLC";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QString persistenceError;
|
||||
const QString source = ConfigManager::instance().simulationMode()
|
||||
? "SIMULATION" : "PLC";
|
||||
if (!ProductionRepository().startWorkpieceProcess(
|
||||
m_orderId, workpiece.id, workpiece.processStep,
|
||||
m_deviceStatus.currentStep,
|
||||
m_inspectionMode, m_deviceStatus.currentStep,
|
||||
source, &persistenceError)) {
|
||||
if (error) {
|
||||
*error = persistenceError;
|
||||
@@ -539,6 +614,8 @@ bool ProductionService::claimNextWorkpiece(QString *error)
|
||||
}
|
||||
startProcessTimer(workpiece.processStep);
|
||||
emit currentWorkpieceChanged(workpiece.id, workpiece.barcode);
|
||||
emit currentWorkpieceSnapshotChanged(m_currentWorkpiece);
|
||||
emit currentPositionChanged(m_currentTrayNo, m_currentSlotNo);
|
||||
emitProcessElapsed();
|
||||
setState(WaitingDeviceReady);
|
||||
return true;
|
||||
@@ -559,8 +636,9 @@ bool ProductionService::updateCurrentProcessStep(const QString &processStep,
|
||||
? "SIMULATION" : "PLC";
|
||||
const int durationMs = currentProcessElapsedMs();
|
||||
if (!WorkpieceService::instance().updateProcessStepWithRecord(
|
||||
m_currentWorkpiece.id, processStep, m_deviceStatus.currentStep,
|
||||
source, durationMs, error, forceRestart)) {
|
||||
m_currentWorkpiece.id, processStep, m_inspectionMode,
|
||||
m_deviceStatus.currentStep, source, durationMs, error,
|
||||
forceRestart)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -570,6 +648,55 @@ bool ProductionService::updateCurrentProcessStep(const QString &processStep,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProductionService::executeCurrentAction(
|
||||
DeviceService::ProductionAction action,
|
||||
const QString &nextProcessStep, State nextState, QString *error)
|
||||
{
|
||||
if (m_currentWorkpiece.id <= 0) {
|
||||
if (error) {
|
||||
*error = "No current workpiece";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!DeviceService::instance().executeProductionAction(
|
||||
action, m_currentTrayNo, m_currentSlotNo, error)) {
|
||||
return false;
|
||||
}
|
||||
if (!updateCurrentProcessStep(nextProcessStep, error)) {
|
||||
return false;
|
||||
}
|
||||
setState(nextState);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProductionService::recordInspection(const QString &side, int rawResult,
|
||||
const QString &resultState,
|
||||
QString *error)
|
||||
{
|
||||
const QString source = ConfigManager::instance().simulationMode()
|
||||
? "SIMULATION" : "PLC";
|
||||
return WorkpieceService::instance().recordInspection(
|
||||
m_currentWorkpiece.id, side, rawResult, resultState,
|
||||
m_deviceStatus.currentStep, m_inspectionMode, source,
|
||||
QString("%1 inspection result").arg(side), error);
|
||||
}
|
||||
|
||||
QString ProductionService::resultStateForRawResult(int rawResult) const
|
||||
{
|
||||
const ProductionConfig config = ConfigManager::instance().productionConfig();
|
||||
if (rawResult == config.okResult) {
|
||||
return "OK";
|
||||
}
|
||||
if (rawResult == config.ngResult) {
|
||||
return "NG";
|
||||
}
|
||||
if (rawResult == config.errorResult) {
|
||||
return "ERROR";
|
||||
}
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
void ProductionService::startProcessTimer(const QString &processStep)
|
||||
{
|
||||
m_currentProcessStep = processStep;
|
||||
@@ -751,17 +878,18 @@ bool ProductionService::finishCurrentWorkpiece(const QString &state,
|
||||
const QString source = ConfigManager::instance().simulationMode()
|
||||
? "SIMULATION" : "PLC";
|
||||
|
||||
setState(Unloading);
|
||||
if (!WorkpieceService::instance().completeWithInspection(
|
||||
m_currentWorkpiece.id, state, processStep,
|
||||
previousProcessStep, processDurationMs, rawResult, state,
|
||||
m_deviceStatus.currentStep, source, error)) {
|
||||
m_deviceStatus.currentStep, m_inspectionMode, source, error)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
clearProcessTimer();
|
||||
m_currentWorkpiece = Workpiece();
|
||||
emit currentWorkpieceChanged(0, QString());
|
||||
emit currentWorkpieceSnapshotChanged(m_currentWorkpiece);
|
||||
emit currentPositionChanged(0, 0);
|
||||
setState(Preparing);
|
||||
return true;
|
||||
}
|
||||
@@ -842,10 +970,10 @@ void ProductionService::tick()
|
||||
if (m_state == WaitingDeviceReady) {
|
||||
if (m_deviceStatus.plcReady && m_deviceStatus.robotReady) {
|
||||
QString error;
|
||||
if (!updateCurrentProcessStep("LOADING", &error)) {
|
||||
if (!updateCurrentProcessStep("RACK_PICKING", &error)) {
|
||||
fail(error);
|
||||
} else {
|
||||
setState(Loading);
|
||||
setState(RackPicking);
|
||||
}
|
||||
}
|
||||
emitProcessElapsed();
|
||||
@@ -871,65 +999,14 @@ void ProductionService::tickSimulation()
|
||||
return;
|
||||
}
|
||||
|
||||
switch (m_state) {
|
||||
case Loading: {
|
||||
QString error;
|
||||
if (!updateCurrentProcessStep("FRONT_CHECKING", &error)) {
|
||||
fail(error);
|
||||
} else {
|
||||
setState(FrontChecking);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FrontChecking: {
|
||||
QString error;
|
||||
if (!updateCurrentProcessStep("BACK_CHECKING", &error)) {
|
||||
fail(error);
|
||||
} else {
|
||||
setState(BackChecking);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BackChecking: {
|
||||
QString error;
|
||||
if (!updateCurrentProcessStep("JUDGING", &error)) {
|
||||
fail(error);
|
||||
} else {
|
||||
setState(Judging);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Judging: {
|
||||
const ProductionConfig config = ConfigManager::instance().productionConfig();
|
||||
QString resultState;
|
||||
if (config.simulationResult == config.okResult) {
|
||||
resultState = "OK";
|
||||
} else if (config.simulationResult == config.ngResult) {
|
||||
resultState = "NG";
|
||||
}
|
||||
QString error;
|
||||
if (resultState.isEmpty()) {
|
||||
fail("Invalid simulation inspection result");
|
||||
} else if (!finishCurrentWorkpiece(resultState, "COMPLETE", &error)) {
|
||||
fail(error);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
QString error;
|
||||
if (!processProductionStep(m_state, &error) && !error.isEmpty()) {
|
||||
fail(error);
|
||||
}
|
||||
}
|
||||
|
||||
void ProductionService::tickProduction()
|
||||
{
|
||||
if (m_state == TimeoutWarning) {
|
||||
QString error;
|
||||
if (!processProductionStep(m_timeoutState, &error) && !error.isEmpty()) {
|
||||
fail(error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_state == RecoveryChecking) {
|
||||
QString error;
|
||||
if (!recoverFromPlcStep(&error) && !error.isEmpty()) {
|
||||
@@ -951,62 +1028,117 @@ void ProductionService::tickProduction()
|
||||
|
||||
bool ProductionService::processProductionStep(State state, QString *error)
|
||||
{
|
||||
const ProductionConfig config = ConfigManager::instance().productionConfig();
|
||||
QString resultState;
|
||||
switch (state) {
|
||||
case Loading:
|
||||
if (m_deviceStatus.currentStep == config.frontCheckStep) {
|
||||
if (!updateCurrentProcessStep("FRONT_CHECKING", error)) {
|
||||
case RackPicking:
|
||||
return executeCurrentAction(DeviceService::RackPick,
|
||||
"FRONT_LOADING", FrontLoading, error);
|
||||
case FrontLoading:
|
||||
return executeCurrentAction(DeviceService::FrontLoad,
|
||||
"FRONT_CHECKING", FrontChecking, error);
|
||||
case FrontChecking: {
|
||||
if (!DeviceService::instance().executeProductionAction(
|
||||
DeviceService::Inspect, m_currentTrayNo, m_currentSlotNo, error)) {
|
||||
return false;
|
||||
}
|
||||
if (!ConfigManager::instance().simulationMode()) {
|
||||
DeviceStatus status;
|
||||
if (!DeviceService::instance().readStatus(&status, error)) {
|
||||
return false;
|
||||
} else {
|
||||
setState(FrontChecking);
|
||||
}
|
||||
onDeviceStatusChanged(status);
|
||||
}
|
||||
break;
|
||||
case FrontChecking:
|
||||
if (m_deviceStatus.currentStep == config.backCheckStep) {
|
||||
if (!updateCurrentProcessStep("BACK_CHECKING", error)) {
|
||||
return false;
|
||||
} else {
|
||||
setState(BackChecking);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BackChecking:
|
||||
if (m_deviceStatus.currentStep == config.unloadStep) {
|
||||
if (!updateCurrentProcessStep("JUDGING", error)) {
|
||||
return false;
|
||||
} else {
|
||||
setState(Judging);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Judging:
|
||||
if (m_deviceStatus.currentStep != config.cycleCompleteStep) {
|
||||
return true;
|
||||
}
|
||||
if (m_deviceStatus.checkResult == config.okResult) {
|
||||
resultState = "OK";
|
||||
} else if (m_deviceStatus.checkResult == config.ngResult) {
|
||||
resultState = "NG";
|
||||
} else if (m_deviceStatus.checkResult == config.errorResult) {
|
||||
const int frontRawResult = ConfigManager::instance().simulationMode()
|
||||
? ConfigManager::instance().productionConfig().simulationResult
|
||||
: static_cast<int>(m_deviceStatus.checkResult);
|
||||
const QString frontResultState =
|
||||
resultStateForRawResult(frontRawResult);
|
||||
if (frontResultState == "UNKNOWN" || frontResultState == "ERROR") {
|
||||
if (error) {
|
||||
*error = QString("PLC inspection error result: %1")
|
||||
.arg(m_deviceStatus.checkResult);
|
||||
*error = QString("Invalid front inspection result: %1")
|
||||
.arg(frontRawResult);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
}
|
||||
if (!recordInspection("FRONT", frontRawResult,
|
||||
frontResultState, error)) {
|
||||
return false;
|
||||
}
|
||||
m_frontRawResult = frontRawResult;
|
||||
m_frontResultState = frontResultState;
|
||||
if (!updateCurrentProcessStep("FRONT_UNLOADING", error)) {
|
||||
return false;
|
||||
}
|
||||
setState(FrontUnloading);
|
||||
return true;
|
||||
}
|
||||
case FrontUnloading:
|
||||
return executeCurrentAction(
|
||||
DeviceService::FrontUnload,
|
||||
m_inspectionMode == "AFTER_PLATING" ? "RACK_PLACING" : "FLIPPING",
|
||||
m_inspectionMode == "AFTER_PLATING" ? RackPlacing : Flipping,
|
||||
error);
|
||||
case Flipping:
|
||||
return executeCurrentAction(DeviceService::Flip,
|
||||
"BACK_LOADING", BackLoading, error);
|
||||
case BackLoading:
|
||||
return executeCurrentAction(DeviceService::BackLoad,
|
||||
"BACK_CHECKING", BackChecking, error);
|
||||
case BackChecking: {
|
||||
if (!DeviceService::instance().executeProductionAction(
|
||||
DeviceService::Inspect, m_currentTrayNo, m_currentSlotNo, error)) {
|
||||
return false;
|
||||
}
|
||||
if (!ConfigManager::instance().simulationMode()) {
|
||||
DeviceStatus status;
|
||||
if (!DeviceService::instance().readStatus(&status, error)) {
|
||||
return false;
|
||||
}
|
||||
onDeviceStatusChanged(status);
|
||||
}
|
||||
const int backRawResult = ConfigManager::instance().simulationMode()
|
||||
? ConfigManager::instance().productionConfig().simulationResult
|
||||
: static_cast<int>(m_deviceStatus.checkResult);
|
||||
const QString backResultState =
|
||||
resultStateForRawResult(backRawResult);
|
||||
if (backResultState == "UNKNOWN" || backResultState == "ERROR") {
|
||||
if (error) {
|
||||
*error = QString("Unknown PLC inspection result: %1")
|
||||
.arg(m_deviceStatus.checkResult);
|
||||
*error = QString("Invalid back inspection result: %1")
|
||||
.arg(backRawResult);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!finishCurrentWorkpiece(resultState, "COMPLETE", error)) {
|
||||
if (!recordInspection("BACK", backRawResult,
|
||||
backResultState, error)) {
|
||||
return false;
|
||||
}
|
||||
const QString finalState =
|
||||
m_frontResultState == "OK" && backResultState == "OK"
|
||||
? "OK" : "NG";
|
||||
if (!updateCurrentProcessStep("BACK_UNLOADING", error)) {
|
||||
return false;
|
||||
}
|
||||
m_frontResultState = finalState;
|
||||
setState(BackUnloading);
|
||||
break;
|
||||
}
|
||||
case BackUnloading:
|
||||
return executeCurrentAction(DeviceService::BackUnload,
|
||||
"RACK_PLACING", RackPlacing, error);
|
||||
case RackPlacing: {
|
||||
if (!DeviceService::instance().executeProductionAction(
|
||||
DeviceService::RackPlace, m_currentTrayNo, m_currentSlotNo,
|
||||
error)) {
|
||||
return false;
|
||||
}
|
||||
QString finalState = m_frontResultState;
|
||||
if (finalState != "OK" && finalState != "NG") {
|
||||
if (error) {
|
||||
*error = "Final inspection result is not available";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return finishCurrentWorkpiece(finalState, "COMPLETE", error);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -1075,8 +1207,12 @@ bool ProductionService::recoverFromPlcStep(QString *error)
|
||||
bool ProductionService::isTimedState(State state) const
|
||||
{
|
||||
return state == Preparing || state == WaitingDeviceReady
|
||||
|| state == RackPicking || state == FrontLoading
|
||||
|| state == Loading || state == FrontChecking
|
||||
|| state == BackChecking || state == Judging;
|
||||
|| state == FrontUnloading || state == Flipping
|
||||
|| state == BackLoading || state == BackChecking
|
||||
|| state == BackUnloading || state == RackPlacing
|
||||
|| state == Judging;
|
||||
}
|
||||
|
||||
QString ProductionService::processStepForState(State state) const
|
||||
@@ -1084,9 +1220,16 @@ QString ProductionService::processStepForState(State state) const
|
||||
switch (state) {
|
||||
case Preparing: return "PREPARING";
|
||||
case WaitingDeviceReady: return "WAITING_DEVICE_READY";
|
||||
case RackPicking: return "RACK_PICKING";
|
||||
case FrontLoading: return "FRONT_LOADING";
|
||||
case Loading: return "LOADING";
|
||||
case FrontChecking: return "FRONT_CHECKING";
|
||||
case FrontUnloading: return "FRONT_UNLOADING";
|
||||
case Flipping: return "FLIPPING";
|
||||
case BackLoading: return "BACK_LOADING";
|
||||
case BackChecking: return "BACK_CHECKING";
|
||||
case BackUnloading: return "BACK_UNLOADING";
|
||||
case RackPlacing: return "RACK_PLACING";
|
||||
case Judging: return "JUDGING";
|
||||
default: return QString();
|
||||
}
|
||||
@@ -1117,9 +1260,16 @@ ProductionService::State ProductionService::stateFromName(const QString &name) c
|
||||
{
|
||||
if (name == "PREPARING") return Preparing;
|
||||
if (name == "WAITING_DEVICE_READY") return WaitingDeviceReady;
|
||||
if (name == "RACK_PICKING") return RackPicking;
|
||||
if (name == "FRONT_LOADING") return FrontLoading;
|
||||
if (name == "LOADING") return Loading;
|
||||
if (name == "FRONT_CHECKING") return FrontChecking;
|
||||
if (name == "FRONT_UNLOADING") return FrontUnloading;
|
||||
if (name == "FLIPPING") return Flipping;
|
||||
if (name == "BACK_LOADING") return BackLoading;
|
||||
if (name == "BACK_CHECKING") return BackChecking;
|
||||
if (name == "BACK_UNLOADING") return BackUnloading;
|
||||
if (name == "RACK_PLACING") return RackPlacing;
|
||||
if (name == "JUDGING") return Judging;
|
||||
if (name == "UNLOADING") return Unloading;
|
||||
if (name == "PAUSED") return Paused;
|
||||
|
||||
@@ -20,9 +20,16 @@ public:
|
||||
Idle,
|
||||
Preparing,
|
||||
WaitingDeviceReady,
|
||||
RackPicking,
|
||||
FrontLoading,
|
||||
Loading,
|
||||
FrontChecking,
|
||||
FrontUnloading,
|
||||
Flipping,
|
||||
BackLoading,
|
||||
BackChecking,
|
||||
BackUnloading,
|
||||
RackPlacing,
|
||||
Judging,
|
||||
Unloading,
|
||||
Paused,
|
||||
@@ -41,6 +48,9 @@ public:
|
||||
State state() const;
|
||||
QString stateName() const;
|
||||
int orderId() const;
|
||||
int currentTrayNo() const;
|
||||
int currentSlotNo() const;
|
||||
QString inspectionMode() const;
|
||||
Workpiece currentWorkpiece() const;
|
||||
|
||||
bool start(int orderId, QString *error = nullptr);
|
||||
@@ -56,6 +66,8 @@ public:
|
||||
signals:
|
||||
void stateChanged(ProductionService::State state, const QString &name);
|
||||
void currentWorkpieceChanged(int workpieceId, const QString &barcode);
|
||||
void currentWorkpieceSnapshotChanged(const Workpiece &workpiece);
|
||||
void currentPositionChanged(int trayNo, int slotNo);
|
||||
void productionFinished(int orderId);
|
||||
void productionError(const QString &error);
|
||||
void alarmRaised(const QString &code, const QString &message);
|
||||
@@ -69,8 +81,10 @@ private slots:
|
||||
void onDeviceStatusChanged(const DeviceStatus &status);
|
||||
void onCommunicationError(const QString &error);
|
||||
|
||||
private:
|
||||
public:
|
||||
explicit ProductionService(QObject *parent = nullptr);
|
||||
|
||||
private:
|
||||
ProductionService(const ProductionService &) = delete;
|
||||
ProductionService &operator=(const ProductionService &) = delete;
|
||||
|
||||
@@ -85,6 +99,12 @@ private:
|
||||
void tickProduction();
|
||||
bool processProductionStep(State state, QString *error);
|
||||
bool recoverFromPlcStep(QString *error);
|
||||
bool executeCurrentAction(DeviceService::ProductionAction action,
|
||||
const QString &nextProcessStep,
|
||||
State nextState, QString *error);
|
||||
bool recordInspection(const QString &side, int rawResult,
|
||||
const QString &resultState, QString *error);
|
||||
QString resultStateForRawResult(int rawResult) const;
|
||||
bool ensureOrderRunning(QString *error);
|
||||
bool checkRecoverySafety(QString *error) const;
|
||||
bool mapPlcStepToState(State *state, QString *processStep) const;
|
||||
@@ -118,8 +138,16 @@ private:
|
||||
bool m_deviceStatusValid;
|
||||
int m_recoveryRetryCount;
|
||||
int m_processElapsedMs;
|
||||
int m_currentTrayNo;
|
||||
int m_currentSlotNo;
|
||||
int m_frontRawResult;
|
||||
QString m_inspectionMode;
|
||||
QString m_frontResultState;
|
||||
QString m_currentProcessStep;
|
||||
QString m_lastError;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(ProductionService::State)
|
||||
Q_DECLARE_METATYPE(Workpiece)
|
||||
|
||||
#endif // PRODUCTIONSERVICE_H
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
#include "productionworker.h"
|
||||
|
||||
ProductionWorker::ProductionWorker(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_service(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void ProductionWorker::ensureService()
|
||||
{
|
||||
if (m_service) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_service = new ProductionService(this);
|
||||
connect(m_service, &ProductionService::stateChanged,
|
||||
this, &ProductionWorker::stateChanged);
|
||||
connect(m_service, &ProductionService::currentWorkpieceChanged,
|
||||
this, &ProductionWorker::currentWorkpieceChanged);
|
||||
connect(m_service, &ProductionService::currentWorkpieceSnapshotChanged,
|
||||
this, &ProductionWorker::currentWorkpieceSnapshotChanged);
|
||||
connect(m_service, &ProductionService::currentPositionChanged,
|
||||
this, &ProductionWorker::currentPositionChanged);
|
||||
connect(m_service, &ProductionService::productionFinished,
|
||||
this, &ProductionWorker::productionFinished);
|
||||
connect(m_service, &ProductionService::productionError,
|
||||
this, &ProductionWorker::productionError);
|
||||
connect(m_service, &ProductionService::alarmRaised,
|
||||
this, &ProductionWorker::alarmRaised);
|
||||
connect(m_service, &ProductionService::processElapsedChanged,
|
||||
this, &ProductionWorker::processElapsedChanged);
|
||||
connect(m_service, &ProductionService::timeoutWarning,
|
||||
this, &ProductionWorker::timeoutWarning);
|
||||
connect(m_service, &ProductionService::timeoutRecoveryRequired,
|
||||
this, &ProductionWorker::timeoutRecoveryRequired);
|
||||
connect(m_service, &ProductionService::recoveryCompleted,
|
||||
this, &ProductionWorker::recoveryCompleted);
|
||||
}
|
||||
|
||||
void ProductionWorker::reportFailure(bool success, const QString &error)
|
||||
{
|
||||
if (!success && !error.isEmpty()) {
|
||||
emit productionError(error);
|
||||
}
|
||||
}
|
||||
|
||||
void ProductionWorker::requestStart(int orderId)
|
||||
{
|
||||
ensureService();
|
||||
QString error;
|
||||
reportFailure(m_service->start(orderId, &error), error);
|
||||
}
|
||||
|
||||
void ProductionWorker::requestPause()
|
||||
{
|
||||
ensureService();
|
||||
QString error;
|
||||
reportFailure(m_service->pause(&error), error);
|
||||
}
|
||||
|
||||
void ProductionWorker::requestResume()
|
||||
{
|
||||
ensureService();
|
||||
QString error;
|
||||
reportFailure(m_service->resume(&error), error);
|
||||
}
|
||||
|
||||
void ProductionWorker::requestStop()
|
||||
{
|
||||
ensureService();
|
||||
QString error;
|
||||
reportFailure(m_service->stop(&error), error);
|
||||
}
|
||||
|
||||
void ProductionWorker::requestReset()
|
||||
{
|
||||
ensureService();
|
||||
QString error;
|
||||
reportFailure(m_service->reset(&error), error);
|
||||
}
|
||||
|
||||
void ProductionWorker::requestRecover()
|
||||
{
|
||||
ensureService();
|
||||
QString error;
|
||||
reportFailure(m_service->recover(&error), error);
|
||||
}
|
||||
|
||||
void ProductionWorker::requestRetry()
|
||||
{
|
||||
ensureService();
|
||||
QString error;
|
||||
reportFailure(m_service->retry(&error), error);
|
||||
}
|
||||
|
||||
void ProductionWorker::requestMarkNg()
|
||||
{
|
||||
ensureService();
|
||||
QString error;
|
||||
reportFailure(m_service->markCurrentWorkpieceNg(&error), error);
|
||||
}
|
||||
|
||||
void ProductionWorker::requestRestore()
|
||||
{
|
||||
ensureService();
|
||||
QString error;
|
||||
reportFailure(m_service->restoreActiveRun(&error), error);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#ifndef PRODUCTIONWORKER_H
|
||||
#define PRODUCTIONWORKER_H
|
||||
|
||||
#include "productionservice.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class ProductionWorker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ProductionWorker(QObject *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void requestStart(int orderId);
|
||||
void requestPause();
|
||||
void requestResume();
|
||||
void requestStop();
|
||||
void requestReset();
|
||||
void requestRecover();
|
||||
void requestRetry();
|
||||
void requestMarkNg();
|
||||
void requestRestore();
|
||||
|
||||
signals:
|
||||
void stateChanged(ProductionService::State state, const QString &name);
|
||||
void currentWorkpieceChanged(int workpieceId, const QString &barcode);
|
||||
void currentWorkpieceSnapshotChanged(const Workpiece &workpiece);
|
||||
void currentPositionChanged(int trayNo, int slotNo);
|
||||
void productionFinished(int orderId);
|
||||
void productionError(const QString &error);
|
||||
void alarmRaised(const QString &code, const QString &message);
|
||||
void processElapsedChanged(const QString &processStep, int elapsedMs);
|
||||
void timeoutWarning(const QString &state, int elapsedMs, int timeoutMs);
|
||||
void timeoutRecoveryRequired(const QString &state, const QString &message);
|
||||
void recoveryCompleted(const QString &mode);
|
||||
|
||||
private:
|
||||
void ensureService();
|
||||
void reportFailure(bool success, const QString &error);
|
||||
|
||||
ProductionService *m_service;
|
||||
};
|
||||
|
||||
#endif // PRODUCTIONWORKER_H
|
||||
@@ -278,8 +278,9 @@ bool WorkpieceService::updateState(int id, const QString &state,
|
||||
}
|
||||
|
||||
bool WorkpieceService::updateProcessStepWithRecord(
|
||||
int id, const QString &processStep, int plcStep, const QString &source,
|
||||
int durationMs, QString *error, bool forceRestart)
|
||||
int id, const QString &processStep, const QString &inspectionMode,
|
||||
int plcStep, const QString &source, int durationMs, QString *error,
|
||||
bool forceRestart)
|
||||
{
|
||||
if (id <= 0 || processStep.trimmed().isEmpty()) {
|
||||
if (error) {
|
||||
@@ -336,7 +337,8 @@ bool WorkpieceService::updateProcessStepWithRecord(
|
||||
workpiece.orderId, &transactionError))
|
||||
|| (!sameProcess
|
||||
&& !ProductionRepository().startWorkpieceProcess(
|
||||
workpiece.orderId, id, processStep, plcStep, source,
|
||||
workpiece.orderId, id, processStep, inspectionMode,
|
||||
plcStep, source,
|
||||
&transactionError))
|
||||
|| !recordLog("更新工件工序",
|
||||
QString("工件 %1 工序更新为 %2")
|
||||
@@ -355,8 +357,8 @@ bool WorkpieceService::updateProcessStepWithRecord(
|
||||
bool WorkpieceService::completeWithInspection(
|
||||
int id, const QString &state, const QString &processStep,
|
||||
const QString &previousProcessStep, int durationMs, int rawResult,
|
||||
const QString &resultState, int plcStep, const QString &source,
|
||||
QString *error)
|
||||
const QString &resultState, int plcStep, const QString &inspectionMode,
|
||||
const QString &source, QString *error)
|
||||
{
|
||||
if (id <= 0) {
|
||||
if (error) {
|
||||
@@ -400,7 +402,8 @@ bool WorkpieceService::completeWithInspection(
|
||||
&transactionError))
|
||||
|| !ProductionRepository().insertInspection(
|
||||
workpiece.orderId, id, "FINAL", rawResult, resultState,
|
||||
plcStep, source, "Final production result", &transactionError)
|
||||
inspectionMode, plcStep, source, "Final production result",
|
||||
&transactionError)
|
||||
|| !recordLog("完成工件检测",
|
||||
QString("工件 %1 检测结果为 %2")
|
||||
.arg(workpiece.barcode, resultState),
|
||||
@@ -415,6 +418,47 @@ bool WorkpieceService::completeWithInspection(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WorkpieceService::recordInspection(
|
||||
int id, const QString &side, int rawResult, const QString &resultState,
|
||||
int plcStep, const QString &inspectionMode, const QString &source,
|
||||
const QString &message, QString *error)
|
||||
{
|
||||
if (id <= 0 || side.trimmed().isEmpty()) {
|
||||
if (error) {
|
||||
*error = id <= 0 ? "Workpiece id must be greater than 0"
|
||||
: "Inspection side cannot be empty";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
DatabaseManager &database = DatabaseManager::instance();
|
||||
QString transactionError;
|
||||
if (!database.transaction(&transactionError)) {
|
||||
if (error) {
|
||||
*error = transactionError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Workpiece workpiece;
|
||||
if (!WorkpieceRepository().findWorkpiece(id, &workpiece, &transactionError)
|
||||
|| !ProductionRepository().insertInspection(
|
||||
workpiece.orderId, id, side, rawResult, resultState,
|
||||
inspectionMode, plcStep, source, message, &transactionError)
|
||||
|| !recordLog("RECORD_INSPECTION",
|
||||
QString("Workpiece %1 %2 result %3")
|
||||
.arg(workpiece.barcode, side, resultState),
|
||||
&transactionError)
|
||||
|| !database.commit(&transactionError)) {
|
||||
database.rollback();
|
||||
if (error) {
|
||||
*error = transactionError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WorkpieceService::isValidState(const QString &state) const
|
||||
{
|
||||
return state == "PENDING" || state == "PROCESSING"
|
||||
|
||||
@@ -21,15 +21,22 @@ public:
|
||||
bool updateState(int id, const QString &state, const QString &processStep,
|
||||
QString *error = nullptr);
|
||||
bool updateProcessStepWithRecord(int id, const QString &processStep,
|
||||
int plcStep, const QString &source,
|
||||
const QString &inspectionMode, int plcStep,
|
||||
const QString &source,
|
||||
int durationMs,
|
||||
QString *error = nullptr,
|
||||
bool forceRestart = false);
|
||||
bool recordInspection(int id, const QString &side, int rawResult,
|
||||
const QString &resultState, int plcStep,
|
||||
const QString &inspectionMode, const QString &source,
|
||||
const QString &message,
|
||||
QString *error = nullptr);
|
||||
bool completeWithInspection(int id, const QString &state,
|
||||
const QString &processStep,
|
||||
const QString &previousProcessStep,
|
||||
int durationMs, int rawResult,
|
||||
const QString &resultState, int plcStep,
|
||||
const QString &inspectionMode,
|
||||
const QString &source,
|
||||
QString *error = nullptr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user