From 186aef053b2617b0b2650279133eeabe91f70403 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 29 Jan 2026 12:08:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E9=80=BB=E8=BE=91=20-=20=E5=8F=AF=E6=8A=A2=E5=8D=95=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E9=BB=98=E8=AE=A4=E6=8E=92=E5=89=8D=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designhub/service/TaskItemService.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) 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;