diff --git a/backend/src/main/java/com/designhub/service/TaskItemService.java b/backend/src/main/java/com/designhub/service/TaskItemService.java index 2b28872..0412378 100644 --- a/backend/src/main/java/com/designhub/service/TaskItemService.java +++ b/backend/src/main/java/com/designhub/service/TaskItemService.java @@ -134,17 +134,26 @@ public class TaskItemService { if (result.getRecords() != null && !result.getRecords().isEmpty()) { fillUnlockStatusForItems(result.getRecords(), filterDeptId); - // 🔥 按排序方式和解锁状态排序 + // 🔥 按排序方式和解锁状态排序:可抢单的排前面 List sortedRecords = new java.util.ArrayList<>(result.getRecords()); sortedRecords.sort((a, b) -> { - // 首先按解锁状态排序:已解锁的排前面 - boolean aUnlocked = "unlocked".equals(a.getUnlockStatus()) || a.getUnlockStatus() == null; - boolean bUnlocked = "unlocked".equals(b.getUnlockStatus()) || b.getUnlockStatus() == null; - if (aUnlocked != bUnlocked) { - return aUnlocked ? -1 : 1; + // 1. 首先按解锁状态排序:可抢单(unlocked/null)的排前面,排队中(queuing)的排后面 + boolean aCanGrab = a.getCanGrab() != null && a.getCanGrab(); + boolean bCanGrab = b.getCanGrab() != null && b.getCanGrab(); + if (aCanGrab != bCanGrab) { + return aCanGrab ? -1 : 1; } - // 然后按时间排序 + // 2. 如果都是排队中,按队列位置排序(位置小的排前面) + if (!aCanGrab && !bCanGrab) { + Integer posA = a.getQueuePosition(); + Integer posB = b.getQueuePosition(); + if (posA != null && posB != null && !posA.equals(posB)) { + return posA.compareTo(posB); + } + } + + // 3. 最后按时间排序 LocalDateTime timeA = a.getCreateTime(); LocalDateTime timeB = b.getCreateTime(); if (timeA == null && timeB == null) return 0;