feat(production): 修改订单加工位置不一致问题
-创建订单时解除所有占用 -修改数据库位置唯一约束 -严格按照订单起始位置分配 -订单启动时重新初始化位置
This commit is contained in:
@@ -175,6 +175,24 @@ bool TrayRepository::assignSlot(int trayId, int rowNo, int columnNo, int workpie
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TrayRepository::clearAllSlots(int *releasedCount, QString *error)
|
||||
{
|
||||
if (!ensureOpen(error)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QSqlQuery query(DatabaseManager::instance().database());
|
||||
if (!query.exec("update tray_slots set workpiece_id = null, state = 'EMPTY' "
|
||||
"where workpiece_id is not null or state <> 'EMPTY'")) {
|
||||
setError(query, error);
|
||||
return false;
|
||||
}
|
||||
if (releasedCount) {
|
||||
*releasedCount = query.numRowsAffected();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TrayRepository::refreshStats(int trayId, QString *error)
|
||||
{
|
||||
if (!ensureOpen(error)) {
|
||||
@@ -239,18 +257,21 @@ bool TrayRepository::updateSlotState(int trayId, int rowNo, int columnNo, const
|
||||
}
|
||||
|
||||
QSqlQuery query(DatabaseManager::instance().database());
|
||||
query.prepare("insert into tray_slots (tray_id, row_no, column_no, workpiece_id, state) "
|
||||
"values (:tray_id, :row_no, :column_no, :workpiece_id, :state) "
|
||||
"on conflict (tray_id, row_no, column_no) do update set "
|
||||
"workpiece_id = excluded.workpiece_id, state = excluded.state");
|
||||
query.prepare("update tray_slots set state = :state "
|
||||
"where tray_id = :tray_id and row_no = :row_no "
|
||||
"and column_no = :column_no and workpiece_id = :workpiece_id");
|
||||
query.bindValue(":tray_id", trayId);
|
||||
query.bindValue(":row_no", rowNo);
|
||||
query.bindValue(":column_no", columnNo);
|
||||
query.bindValue(":workpiece_id", workpieceId > 0 ? QVariant(workpieceId) : QVariant(QVariant::Int));
|
||||
query.bindValue(":workpiece_id", workpieceId);
|
||||
query.bindValue(":state", state);
|
||||
if (!query.exec()) {
|
||||
setError(query, error);
|
||||
return false;
|
||||
}
|
||||
if (query.numRowsAffected() != 1) {
|
||||
if (error) *error = "Tray slot is no longer assigned to this workpiece";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user