feat(production): 修改订单加工位置不一致问题
-创建订单时解除所有占用 -修改数据库位置唯一约束 -严格按照订单起始位置分配 -订单启动时重新初始化位置
This commit is contained in:
@@ -105,10 +105,15 @@ bool WorkpieceRepository::claimNextPending(int orderId, Workpiece *workpiece,
|
||||
*workpiece = Workpiece();
|
||||
QSqlQuery query(DatabaseManager::instance().database());
|
||||
query.prepare("with candidate as ("
|
||||
"select id from workpieces "
|
||||
"where order_id = :order_id and state = 'PENDING' "
|
||||
"order by tray_id nulls last, tray_pos, id "
|
||||
"for update skip locked limit 1"
|
||||
"select w.id from workpieces w "
|
||||
"join trays t on t.id = w.tray_id "
|
||||
"join tray_slots ts on ts.tray_id = w.tray_id "
|
||||
"and ts.row_no = w.row_no and ts.column_no = w.column_no "
|
||||
"and ts.workpiece_id = w.id and ts.state = 'PENDING' "
|
||||
"where w.order_id = :order_id and w.state = 'PENDING' "
|
||||
"order by t.rack_row nulls last, t.rack_column nulls last, "
|
||||
"w.tray_pos, w.id "
|
||||
"for update of w skip locked limit 1"
|
||||
") "
|
||||
"update workpieces w set state = 'PROCESSING', "
|
||||
"process_step = 'WAITING_DEVICE_READY', updated_at = now() "
|
||||
@@ -120,6 +125,18 @@ bool WorkpieceRepository::claimNextPending(int orderId, Workpiece *workpiece,
|
||||
return false;
|
||||
}
|
||||
if (!query.next()) {
|
||||
QSqlQuery pending(DatabaseManager::instance().database());
|
||||
pending.prepare("select exists (select 1 from workpieces "
|
||||
"where order_id = :order_id and state = 'PENDING')");
|
||||
pending.bindValue(":order_id", orderId);
|
||||
if (!pending.exec() || !pending.next()) {
|
||||
setError(pending, error);
|
||||
return false;
|
||||
}
|
||||
if (pending.value(0).toBool()) {
|
||||
if (error) *error = "待加工工件与当前料位绑定不一致,不能继续生产";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user