124 lines
4.8 KiB
C++
124 lines
4.8 KiB
C++
#ifndef PRODUCTIONREPOSITORY_H
|
|
#define PRODUCTIONREPOSITORY_H
|
|
|
|
#include <QDateTime>
|
|
#include <QList>
|
|
#include <QString>
|
|
#include <QVariant>
|
|
|
|
struct ProductionActionCheckpoint
|
|
{
|
|
QString token;
|
|
QString type;
|
|
QString phase;
|
|
QString nextStep;
|
|
int attempt = 0;
|
|
int version = 0;
|
|
QVariant command;
|
|
QVariant feedback;
|
|
QString manualDecision;
|
|
QString manualOperator;
|
|
QDateTime manualDecidedAt;
|
|
};
|
|
|
|
struct ProductionRunSnapshot
|
|
{
|
|
int id = 0;
|
|
int orderId = 0;
|
|
int currentWorkpieceId = 0;
|
|
int planNum = 0;
|
|
int startTrayNo = 1;
|
|
int startSlotNo = 1;
|
|
QString inspectionMode;
|
|
QString runState;
|
|
QString productionState;
|
|
QString processStep;
|
|
QString timeoutState;
|
|
int recoveryRetryCount = 0;
|
|
QString lastError;
|
|
ProductionActionCheckpoint action;
|
|
};
|
|
|
|
struct WorkpieceProcessRecord
|
|
{
|
|
QString processStep;
|
|
int attemptNo = 0;
|
|
QString processState;
|
|
QString resultState;
|
|
int durationMs = -1;
|
|
QDateTime startedAt;
|
|
QDateTime completedAt;
|
|
};
|
|
|
|
class ProductionRepository
|
|
{
|
|
public:
|
|
int createRun(int orderId, const QString &productionState,
|
|
const QString &processStep, const QString &inspectionMode,
|
|
int startTrayNo, int startSlotNo, int planNum,
|
|
QString *error = nullptr);
|
|
bool updateRun(int runId, const QString &runState,
|
|
const QString &productionState, const QString &processStep,
|
|
int currentWorkpieceId, const QString &timeoutState,
|
|
int recoveryRetryCount, const QString &lastError,
|
|
QString *error = nullptr);
|
|
bool finishRun(int runId, const QString &runState,
|
|
const QString &lastError = QString(),
|
|
QString *error = nullptr);
|
|
bool heartbeatRun(int runId, QString *error = nullptr);
|
|
bool findActiveRun(ProductionRunSnapshot *run, QString *error = nullptr);
|
|
bool findRun(int runId, ProductionRunSnapshot *run, QString *error = nullptr);
|
|
bool lockOrderRuns(int orderId, QString *latestRunState,
|
|
bool *hasActiveRun, QString *error = nullptr);
|
|
bool checkActionSchema(QString *error = nullptr);
|
|
bool saveActionCheckpoint(int runId, int orderId, int workpieceId,
|
|
ProductionActionCheckpoint *action,
|
|
QString *error = nullptr);
|
|
bool findInspectionResult(int workpieceId, const QString &side,
|
|
int *rawResult, QString *resultState,
|
|
QString *error = nullptr,
|
|
const QString &actionToken = QString(),
|
|
int actionAttempt = 0);
|
|
|
|
bool insertStateHistory(int runId, int orderId, int workpieceId,
|
|
const QString &fromState, const QString &toState,
|
|
const QString &processStep, const QString &source,
|
|
const QString &reason, const QString &message,
|
|
QString *error = nullptr,
|
|
const QString &operatorName = QString());
|
|
|
|
bool startWorkpieceProcess(int orderId, int workpieceId,
|
|
const QString &processStep,
|
|
const QString &inspectionMode, int plcStep,
|
|
const QString &source, QString *error = nullptr);
|
|
bool finishWorkpieceProcess(int workpieceId, const QString &processStep,
|
|
const QString &resultState, int durationMs,
|
|
QString *error = nullptr);
|
|
QList<WorkpieceProcessRecord> listProcessRecords(
|
|
int workpieceId, QString *error = nullptr);
|
|
|
|
bool insertInspection(int orderId, int workpieceId,
|
|
const QString &side, int rawResult,
|
|
const QString &resultState,
|
|
const QString &inspectionMode, int plcStep,
|
|
const QString &source, const QString &message,
|
|
QString *error = nullptr);
|
|
|
|
bool insertAlarm(const QString &code, const QString &message,
|
|
int orderId, int workpieceId,
|
|
const QString &fallbackLevel,
|
|
const QString &fallbackSource,
|
|
QString *error = nullptr);
|
|
bool clearActiveAlarms(const QString &code = QString(),
|
|
const QString &clearedBy = "OPERATOR",
|
|
QString *error = nullptr);
|
|
|
|
bool insertDeviceStatus(const QString &deviceCode, bool plcConnected,
|
|
bool plcReady, bool robotReady,
|
|
bool safetyDoorClosed, bool emergencyStop,
|
|
int currentStep, int checkResult, int errorCode,
|
|
QString *error = nullptr);
|
|
};
|
|
|
|
#endif // PRODUCTIONREPOSITORY_H
|