From 61bfedc1dcf56e56eea9f63087da08430cab23d7 Mon Sep 17 00:00:00 2001 From: Yann Date: Wed, 1 Mar 2023 10:19:59 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-86430=20AlphaFine=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E4=B8=AD=E5=BF=83tab=E9=A1=B5=E6=98=BE=E7=A4=BA=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E6=9C=89=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manager/impl/PluginSearchManager.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/PluginSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/PluginSearchManager.java index ec5fedbf25..542c3dc05b 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/PluginSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/PluginSearchManager.java @@ -27,6 +27,7 @@ import java.net.URLEncoder; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -204,30 +205,25 @@ public class PluginSearchManager implements AlphaFineSearchProvider { if (!Collections.isEmpty(jsonObjects)) { jsonObjects = jsonObjects.stream() .filter(o -> ((Integer) o.get(version)) == 1) - .sorted(PluginSearchManager::sortPluginByUploadTime) + .sorted(Comparator.comparingLong(PluginSearchManager::parseTime).reversed()) + .limit(DEFAULT_LIST_SIZE) .collect(Collectors.toList()); - int size = Math.min(DEFAULT_LIST_SIZE, jsonObjects.size()); - for (int i = 0; i < size; i++) { - pluginModels.add(getPluginModel(new JSONObject(jsonObjects.get(i)), false)); + for (Map jsonObject : jsonObjects) { + pluginModels.add(getPluginModel(new JSONObject(jsonObject), false)); } } return pluginModels; } - private static int sortPluginByUploadTime(Map v1, Map v2) { + private static long parseTime(Map value) { SimpleDateFormat format = new SimpleDateFormat(TIME_FORMAT); - long t1 = 0L, t2 = 0L; + long t = 0L; try { - t1 = format.parse((String) v1.get(UPLOAD_TIME)).getTime(); + t = format.parse((String) value.get(UPLOAD_TIME)).getTime(); } catch (ParseException e) { FineLoggerFactory.getLogger().error(e, e.getMessage()); } - try { - t2 = format.parse((String) v2.get(UPLOAD_TIME)).getTime(); - } catch (ParseException e) { - FineLoggerFactory.getLogger().error(e, e.getMessage()); - } - return Long.compare(t2, t1); + return t; } }