feat(production): 删除动作记录、释放料位、删除工件及订单等

This commit is contained in:
lidg
2026-11-05 15:33:51 +08:00
parent 6da5622181
commit 753f9c3ed2
7 changed files with 239 additions and 22 deletions
+102 -7
View File
@@ -124,12 +124,58 @@ bool OrderService::createOrder(Order *order, QString *error)
return false;
}
if (!repository.insertOrder(order, &transactionError)
|| !recordLog("新建订单", "创建订单:" + order->no, "成功", &transactionError)
|| !database.commit(&transactionError)) {
WorkpieceRepository workpieceRepository;
TrayRepository trayRepository;
QList<int> affectedTrayIds;
int removedCount = 0;
if (!workpieceRepository.removeUninspected(
0, &affectedTrayIds, &removedCount, &transactionError)) {
database.rollback();
if (error) {
*error = transactionError;
*error = "新建订单前清理未测量工件失败:" + transactionError;
}
return false;
}
for (const int trayId : affectedTrayIds) {
if (!trayRepository.refreshStats(trayId, &transactionError)) {
database.rollback();
if (error) {
*error = "重新统计料盘占用失败:" + transactionError;
}
return false;
}
}
if (!repository.insertOrder(order, &transactionError)) {
database.rollback();
if (error) {
*error = "写入新订单失败:" + transactionError;
}
return false;
}
if (removedCount > 0
&& !recordLog("清理未测量工件",
QString("新建订单前清理 %1 个未测量工件")
.arg(removedCount),
"成功", &transactionError)) {
database.rollback();
if (error) {
*error = "记录清理日志失败:" + transactionError;
}
return false;
}
if (!recordLog("新建订单", "创建订单:" + order->no,
"成功", &transactionError)) {
database.rollback();
if (error) {
*error = "记录新建订单日志失败:" + transactionError;
}
return false;
}
if (!database.commit(&transactionError)) {
database.rollback();
if (error) {
*error = "提交新建订单事务失败:" + transactionError;
}
return false;
}
@@ -454,16 +500,65 @@ bool OrderService::deleteOrder(int id, QString *error)
}
return false;
}
if (order.status == "RUNNING" || order.status == "PAUSED") {
if (order.status == "FINISHED" || order.status == "COMPLETED") {
database.rollback();
if (error) {
*error = "Running or paused orders cannot be deleted";
*error = "已完成订单不能删除";
}
return false;
}
if (order.status != "NOT_START" && order.status != "CANCELED") {
database.rollback();
if (error) {
*error = "当前订单不能直接删除,请先在控制面板安全终止订单";
}
return false;
}
WorkpieceRepository workpieceRepository;
bool hasInspectionRecords = false;
if (!workpieceRepository.orderHasInspectionRecords(
id, &hasInspectionRecords, &transactionError)) {
database.rollback();
if (error) {
*error = transactionError;
}
return false;
}
if (hasInspectionRecords) {
database.rollback();
if (error) {
*error = "订单已有测量记录,必须保留检测追溯,不能删除";
}
return false;
}
QList<int> affectedTrayIds;
int removedCount = 0;
if (!workpieceRepository.removeUninspected(
id, &affectedTrayIds, &removedCount, &transactionError)) {
database.rollback();
if (error) {
*error = transactionError;
}
return false;
}
TrayRepository trayRepository;
for (const int trayId : affectedTrayIds) {
if (!trayRepository.refreshStats(trayId, &transactionError)) {
database.rollback();
if (error) {
*error = transactionError;
}
return false;
}
}
if (!repository.removeOrder(id, &transactionError)
|| !recordLog("删除订单", "删除订单:" + order.no, "成功", &transactionError)
|| !recordLog("删除订单",
QString("删除订单:%1,释放 %2 个未测量工件")
.arg(order.no).arg(removedCount),
"成功", &transactionError)
|| !database.commit(&transactionError)) {
database.rollback();
if (error) {