feat(production): 修改订单流程卡死流程问题
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "../db/databasemanager.h"
|
||||
#include "../repositories/logrepository.h"
|
||||
#include "../repositories/orderrepository.h"
|
||||
#include "../repositories/productionrepository.h"
|
||||
#include "../repositories/trayrepository.h"
|
||||
#include "../repositories/workpiecerepository.h"
|
||||
|
||||
@@ -307,7 +308,7 @@ bool OrderService::generateWorkpiecesAndAssign(int orderId, QString *error)
|
||||
continue;
|
||||
}
|
||||
|
||||
const QList<TraySlot> slots =
|
||||
const QList<TraySlot> traySlots =
|
||||
trayRepository.listSlots(tray.id, &transactionError);
|
||||
if (!transactionError.isEmpty()) {
|
||||
database.rollback();
|
||||
@@ -317,7 +318,7 @@ bool OrderService::generateWorkpiecesAndAssign(int orderId, QString *error)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const TraySlot &slot : slots) {
|
||||
for (const TraySlot &slot : traySlots) {
|
||||
const int position = (slot.rowNo - 1) * 7 + slot.columnNo;
|
||||
if (trayIndex == startTrayIndex && position < order.startSlotNo) {
|
||||
continue;
|
||||
@@ -493,21 +494,44 @@ bool OrderService::deleteOrder(int id, QString *error)
|
||||
|
||||
OrderRepository repository;
|
||||
Order order;
|
||||
if (!repository.findOrder(id, &order, &transactionError)) {
|
||||
if (!repository.findOrderForUpdate(id, &order, &transactionError)) {
|
||||
database.rollback();
|
||||
if (error) {
|
||||
*error = transactionError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (order.status == "FINISHED" || order.status == "COMPLETED") {
|
||||
|
||||
QString latestRunState;
|
||||
bool hasActiveRun = false;
|
||||
if (!ProductionRepository().lockOrderRuns(
|
||||
id, &latestRunState, &hasActiveRun, &transactionError)) {
|
||||
database.rollback();
|
||||
if (error) {
|
||||
*error = transactionError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (hasActiveRun) {
|
||||
database.rollback();
|
||||
if (error) {
|
||||
*error = "订单存在活动生产任务,请先在控制面板终止订单,终止完成后再删除";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool manuallyStopped = order.status == "FINISHED"
|
||||
&& latestRunState == "STOPPED";
|
||||
if (order.status == "COMPLETED"
|
||||
|| (order.status == "FINISHED" && !manuallyStopped)) {
|
||||
database.rollback();
|
||||
if (error) {
|
||||
*error = "已完成订单不能删除";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (order.status != "NOT_START" && order.status != "CANCELED") {
|
||||
if (order.status != "NOT_START" && order.status != "CANCELED"
|
||||
&& !manuallyStopped) {
|
||||
database.rollback();
|
||||
if (error) {
|
||||
*error = "当前订单不能直接删除,请先在控制面板安全终止订单";
|
||||
|
||||
Reference in New Issue
Block a user