feat: 优化排序逻辑 - 可抢单任务默认排前面
This commit is contained in:
parent
bf2f720fe7
commit
186aef053b
@ -134,17 +134,26 @@ public class TaskItemService {
|
||||
if (result.getRecords() != null && !result.getRecords().isEmpty()) {
|
||||
fillUnlockStatusForItems(result.getRecords(), filterDeptId);
|
||||
|
||||
// 🔥 按排序方式和解锁状态排序
|
||||
// 🔥 按排序方式和解锁状态排序:可抢单的排前面
|
||||
List<TaskItem> 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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user