From c1cd6de9e34acb9776649ac9ff02ef89a25d4b37 Mon Sep 17 00:00:00 2001 From: wangliwen Date: Mon, 8 Aug 2022 09:58:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ResourceServiceImpl.java | 63 +++++-------------- 1 file changed, 15 insertions(+), 48 deletions(-) diff --git a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java index 002e3006..527bdd45 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java @@ -459,60 +459,27 @@ public class ResourceServiceImpl extends CrudServiceImpl resourceDTOS; if (orderField.equals("total")) { // 对总体评价特殊处理 List ids = new ArrayList<>(); - ForkJoinPool customThreadPool = new ForkJoinPool(CPU_NUM * 2); switch (orderType.toUpperCase()) { case "DESC": // total 倒序 - try { - ids = (List) customThreadPool.submit(() -> { - selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast).sorted(Comparator.comparing(x -> { - Map index = (Map) x; - String string = (index.get("total") == null) ? "0" : index.get("total").toString(); - return Long.valueOf(string); - } - ).reversed()).skip((long) (pageNum - 1) * pageSize).limit(pageSize).map(x -> - Long.valueOf(x.get("id").toString()) - ).limit(pageSize).collect(Collectors.toList()); - }).get(); - } catch (InterruptedException e) { - logger.error("InterruptedException", e); - } catch (ExecutionException e) { - logger.error("ExecutionException", e); - } -// ids = selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast).sorted(Comparator.comparing(x -> { -// Map index = (Map) x; -// String string = (index.get("total") == null) ? "0" : index.get("total").toString(); -// return Long.valueOf(string); -// } -// ).reversed()).skip((long) (pageNum - 1) * pageSize).limit(pageSize).map(x -> -// Long.valueOf(x.get("id").toString()) -// ).limit(pageSize).collect(Collectors.toList()); + ids = selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast).sorted(Comparator.comparing(x -> { + Map index = (Map) x; + String string = (index.get("total") == null) ? "0" : index.get("total").toString(); + return Long.valueOf(string); + } + ).reversed()).skip((long) (pageNum - 1) * pageSize).limit(pageSize).map(x -> + Long.valueOf(x.get("id").toString()) + ).limit(pageSize).collect(Collectors.toList()); break; case "ASC": // total 升序 - try { - ids = (List) customThreadPool.submit(() -> { - selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast).sorted(Comparator.comparing(x -> { - String string = (x.get("total") == null) ? "0" : x.get("total").toString(); - return Long.valueOf(string); - } - )).skip((pageNum - 1) * pageSize).limit(pageSize).map(x -> - Long.valueOf(x.get("id").toString()) - ).limit(pageSize).collect(Collectors.toList()); - }).get(); - } catch (InterruptedException e) { - logger.error("InterruptedException", e); - } catch (ExecutionException e) { - logger.error("ExecutionException", e); - } -// ids = selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast).sorted(Comparator.comparing(x -> { -// String string = (x.get("total") == null) ? "0" : x.get("total").toString(); -// return Long.valueOf(string); -// } -// )).skip((pageNum - 1) * pageSize).limit(pageSize).map(x -> -// Long.valueOf(x.get("id").toString()) -// ).limit(pageSize).collect(Collectors.toList()); + ids = selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast).sorted(Comparator.comparing(x -> { + String string = (x.get("total") == null) ? "0" : x.get("total").toString(); + return Long.valueOf(string); + } + )).skip((pageNum - 1) * pageSize).limit(pageSize).map(x -> + Long.valueOf(x.get("id").toString()) + ).limit(pageSize).collect(Collectors.toList()); break; } - customThreadPool.shutdown(); resourceDTOS = resourceDao.selectDTOPage(resourceDTO, null, null, null, null, ids); if ("DESC".equals(orderType)) { resultPage.setRecords(resourceDTOS.stream().sorted(Comparator.comparing(x -> {