归并为一个排序

This commit is contained in:
wangliwen 2022-08-15 18:01:09 +08:00
parent a75dc249c9
commit d7b4075e7f
1 changed files with 34 additions and 50 deletions

View File

@ -472,19 +472,15 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
ids = customThreadPool.submit(() -> { ids = customThreadPool.submit(() -> {
List<Long> temp = selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast) List<Long> temp = selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast)
.sorted(Comparator.comparing(x -> { .sorted(Comparator.comparing(x -> {
Map index = (Map) x; Map index = (Map) x;
int pingTOp_ = (index.get("pin_top") == null) ? 0 : Integer.parseInt(index.get("pin_top").toString()); int pingTOp_ = (index.get("pin_top") == null) ? 0 : Integer.parseInt(index.get("pin_top").toString());
if (pingTOp_ <= 0) { String string = (index.get("total") == null) ? "0" : index.get("total").toString();
return 0l; if (pingTOp_ <= 0) {
} return 0l + Long.valueOf(string);
long pingTOp = (index.get("pin_top_time") == null) ? 0 : Long.parseLong(index.get("pin_top_time").toString()); }
return pingTOp; long pingTOp = (index.get("pin_top_time") == null) ? 0 + Long.valueOf(string) : Long.parseLong(index.get("pin_top_time").toString()) + Long.valueOf(string);
}).reversed() return pingTOp;
.thenComparing(x -> { }).reversed()
Map index = (Map) x;
String string = (index.get("total") == null) ? "0" : index.get("total").toString();
return Long.valueOf(string);
}, Comparator.reverseOrder())
).skip((long) (pageNum - 1) * pageSize).limit(pageSize).map(x -> Long.valueOf(x.get("id").toString())).limit(pageSize).collect(Collectors.toList()); ).skip((long) (pageNum - 1) * pageSize).limit(pageSize).map(x -> Long.valueOf(x.get("id").toString())).limit(pageSize).collect(Collectors.toList());
return temp; return temp;
}).get(); }).get();
@ -493,19 +489,15 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
ids = customThreadPool.submit(() -> { ids = customThreadPool.submit(() -> {
List<Long> temp = selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast) List<Long> temp = selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast)
.sorted(Comparator.comparing(x -> { .sorted(Comparator.comparing(x -> {
Map index = (Map) x; Map index = (Map) x;
String string = (index.get("total") == null) ? "0" : index.get("total").toString(); int pingTOp_ = (index.get("pin_top") == null) ? 0 : Integer.parseInt(index.get("pin_top").toString());
return Long.valueOf(string); String string = (index.get("total") == null) ? "0" : index.get("total").toString();
}) if (pingTOp_ <= 0) {
.thenComparing(x -> { return 0l + Long.valueOf(string);
Map index = (Map) x; }
int pingTOp_ = (index.get("pin_top") == null) ? 0 : Integer.parseInt(index.get("pin_top").toString()); long pingTOp = (index.get("pin_top_time") == null) ? 0 + Long.valueOf(string) : Long.parseLong(index.get("pin_top_time").toString()) + Long.valueOf(string);
if (pingTOp_ <= 0) { return pingTOp;
return 0l; })).skip((pageNum - 1) * pageSize).limit(pageSize).map(x -> Long.valueOf(x.get("id").toString())).limit(pageSize).collect(Collectors.toList());
}
long pingTOp = (index.get("pin_top_time") == null) ? 0 : Long.parseLong(index.get("pin_top_time").toString());
return pingTOp;
}).reversed()).skip((pageNum - 1) * pageSize).limit(pageSize).map(x -> Long.valueOf(x.get("id").toString())).limit(pageSize).collect(Collectors.toList());
return temp; return temp;
}).get(); }).get();
break; break;
@ -513,33 +505,25 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
resourceDTOS = resourceDao.selectDTOPage(resourceDTO, null, null, null, null, ids); resourceDTOS = resourceDao.selectDTOPage(resourceDTO, null, null, null, null, ids);
if ("DESC".equals(orderType)) { if ("DESC".equals(orderType)) {
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.getTotal() == null ? 0L : index.getTotal(); int pinTop = index.getPinTop() == null ? 0 : index.getPinTop();
}).reversed() if (pinTop > 0) {
.thenComparing(x -> { return index.getPinTopTime() == null ? new Date(0).getTime() + index.getTotal() : index.getPinTopTime().getTime() + index.getTotal();
ResourceDTO index = (ResourceDTO) x; } else {
int pinTop = index.getPinTop() == null ? 0 : index.getPinTop(); return new Date(0).getTime() + index.getTotal();
if (pinTop > 0) { }
return index.getPinTopTime() == null ? new Date(0).getTime() + pinTop : index.getPinTopTime().getTime() + pinTop; }).reversed()
} else {
return new Date(0).getTime() + pinTop;
}
}).reversed()
).collect(Collectors.toList())); ).collect(Collectors.toList()));
} else { } else {
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.getTotal() == null ? 0L : index.getTotal(); int pinTop = index.getPinTop() == null ? 0 : index.getPinTop();
}, Comparator.reverseOrder()) if (pinTop > 0) {
.thenComparing(x -> { return index.getPinTopTime() == null ? new Date(0).getTime() + index.getTotal() : index.getPinTopTime().getTime() + index.getTotal();
ResourceDTO index = (ResourceDTO) x; } else {
int pinTop = index.getPinTop() == null ? 0 : index.getPinTop(); return new Date(0).getTime() + index.getTotal();
if (pinTop > 0) { }
return index.getPinTopTime() == null ? new Date(0).getTime() + pinTop : index.getPinTopTime().getTime() + pinTop; })
} else {
return new Date(0).getTime() + pinTop;
}
}, Comparator.reverseOrder())
).collect(Collectors.toList())); ).collect(Collectors.toList()));
} }
customThreadPool.shutdown(); customThreadPool.shutdown();