订单流程添加修改
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user