stream 的排序模式

This commit is contained in:
wangliwen 2022-08-15 16:34:11 +08:00
parent 5b63e648e2
commit a8cd7f8436
1 changed files with 8 additions and 6 deletions

View File

@ -525,16 +525,17 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
resultPage.setRecords(resourceDTOS.stream().sorted(Comparator.comparing(x -> { resultPage.setRecords(resourceDTOS.stream().sorted(Comparator.comparing(x -> {
ResourceDTO index = (ResourceDTO) x; ResourceDTO index = (ResourceDTO) x;
return index.getPinTop() == null ? 0 : index.getPinTop(); return index.getPinTop() == null ? 0 : index.getPinTop();
}, Comparator.reverseOrder()) }).reversed()
.thenComparing(x -> { .thenComparing(x -> {
ResourceDTO index = (ResourceDTO) x; ResourceDTO index = (ResourceDTO) x;
int pinTop = index.getPinTop() == null ? 0 : index.getPinTop(); int pinTop = index.getPinTop() == null ? 0 : index.getPinTop();
if (pinTop > 0) { if (pinTop > 0) {
return index.getPinTopTime() == null ? new Date(0).getTime() : index.getPinTopTime().getTime(); return index.getPinTopTime() == null ? new Date(0).getTime() + pinTop : index.getPinTopTime().getTime() + pinTop;
} else { } else {
return new Date(0).getTime(); return new Date(0).getTime() + pinTop;
} }
}, Comparator.reverseOrder()).thenComparing(x -> { }).reversed()
.thenComparing(x -> {
ResourceDTO index = (ResourceDTO) x; ResourceDTO index = (ResourceDTO) x;
return index.getTotal() == null ? 0L : index.getTotal(); return index.getTotal() == null ? 0L : index.getTotal();
}, Comparator.reverseOrder()) }, Comparator.reverseOrder())
@ -543,7 +544,8 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
resultPage.setRecords(resourceDTOS.stream().sorted(Comparator.comparing(x -> { resultPage.setRecords(resourceDTOS.stream().sorted(Comparator.comparing(x -> {
ResourceDTO index = (ResourceDTO) x; ResourceDTO index = (ResourceDTO) x;
return index.getPinTop() == null ? 0 : index.getPinTop(); return index.getPinTop() == null ? 0 : index.getPinTop();
}, Comparator.reverseOrder()).thenComparing(x -> { }).reversed()
.thenComparing(x -> {
ResourceDTO index = (ResourceDTO) x; ResourceDTO index = (ResourceDTO) x;
int pinTop = index.getPinTop() == null ? 0 : index.getPinTop(); int pinTop = index.getPinTop() == null ? 0 : index.getPinTop();
if (pinTop > 0) { if (pinTop > 0) {
@ -551,7 +553,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
} else { } else {
return new Date(0).getTime(); return new Date(0).getTime();
} }
}, Comparator.reverseOrder()) }).reversed()
.thenComparing(x -> { .thenComparing(x -> {
ResourceDTO index = (ResourceDTO) x; ResourceDTO index = (ResourceDTO) x;
return index.getTotal() == null ? 0L : index.getTotal(); return index.getTotal() == null ? 0L : index.getTotal();