修复bug

This commit is contained in:
lulz1 2024-02-20 09:33:42 +08:00
parent d771a5b068
commit 19775c580e
1 changed files with 27 additions and 3 deletions

View File

@ -221,14 +221,13 @@ public class RouteOrder extends BaseEntity {
} }
public void updateStatus() { public void updateStatus() {
// 首先检查所有项是否都为-1状态
if (allItemsInStatus(-1)) { if (allItemsInStatus(-1)) {
this.orderStatus = -1; this.orderStatus = -1;
} else if (allItemsInStatus(4)) { } else if (allItemsInStatus(4)) {
this.orderStatus = 4; this.orderStatus = 4;
} else if (allItemsInStatus(3)) { } else if (anyItemInStatus(3) && allOtherItemsInStatus(2)) {
this.orderStatus = 3; this.orderStatus = 3;
} else if (allItemsInStatus(2)) { } else if (anyItemInStatus(2) && allOtherItemsInStatus(1)) {
this.orderStatus = 2; this.orderStatus = 2;
} else if (allItemsInStatus(1)) { } else if (allItemsInStatus(1)) {
this.orderStatus = 1; this.orderStatus = 1;
@ -249,6 +248,31 @@ public class RouteOrder extends BaseEntity {
return true; return true;
} }
private boolean anyItemInStatus(int targetStatus) {
for (Leg item : this.legItems) {
if (item.getLegStatus() == targetStatus) {
return true;
}
}
return false;
}
private boolean allOtherItemsInStatus(int targetStatus) {
boolean foundHigherStatus = false;
for (Leg item : this.legItems) {
if (item.getLegStatus() > targetStatus) {
if (foundHigherStatus) {
// 如果已经找到一个更高状态而且又遇到另一个则不符合所有其他项目都处于目标状态的条件
return false;
}
foundHigherStatus = true; // 标记已找到一个更高的状态
} else if (item.getLegStatus() < targetStatus) {
return false; // 如果找到状态低于目标状态的项目则直接返回false
}
}
return true;
}
private String translateOrderStatus(int status) { private String translateOrderStatus(int status) {
return switch (status) { return switch (status) {
case ORDER_STATUS_PREPARE -> ORDER_STATUS_PREPARE_NAME; case ORDER_STATUS_PREPARE -> ORDER_STATUS_PREPARE_NAME;