From fe26987e7e18b57d43b096631d1b1534d2fe86ec Mon Sep 17 00:00:00 2001 From: kaiyu <404897439@qq.com> Date: Sat, 09 Oct 2021 17:21:18 +0800 Subject: [PATCH] screen-aqi 监测因子对比图对时间进行排序 --- screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java | 38 ++++++++++++++++++++++++++++++++++---- 1 files changed, 34 insertions(+), 4 deletions(-) diff --git a/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java index c22f67e..4443a4f 100644 --- a/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java +++ b/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java @@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; +import org.yaml.snakeyaml.nodes.CollectionNode; import java.util.*; @@ -136,8 +137,8 @@ time = time + " 0" + i; else time = time + " " + i; - if(timeValueMap.get(time)==null) - timeValueMap.put(time,null); + if (timeValueMap.get(time) == null) + timeValueMap.put(time, null); } } //������������������ @@ -158,11 +159,13 @@ time = time + "-0" + i; else time = time + "-" + i; - if(timeValueMap.get(time)==null) - timeValueMap.put(time,null); + if (timeValueMap.get(time) == null) + timeValueMap.put(time, null); } } else return null; + //������������ + timeValueMap = sortMapByTime(timeValueMap, reportType); //������������������ List<SensorComparisonDisplayDTO> dtos = new ArrayList<>(); for (String sensor : sensors) { @@ -209,6 +212,33 @@ return dtos; } + private Map<String, String> sortMapByTime(Map<String, String> timeValueMap, String reportType) { + List<Map.Entry<String, String>> entries = new ArrayList(timeValueMap.entrySet()); + Collections.sort(entries, new Comparator<Map.Entry<String, String>>() { + @Override + public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) { + if (Constants.DAILY_REPORT.equals(reportType)) { + String atime = o1.getKey(); + String btime = o2.getKey(); + atime = atime.substring(11, 13); + btime = btime.substring(11, 13); + return Integer.parseInt(atime) - Integer.parseInt(btime); + } else if (Constants.MONTHLY_REPORT.equals(reportType)) { + String atime = o1.getKey(); + String btime = o2.getKey(); + atime = atime.substring(8, 10); + btime = btime.substring(8, 10); + return Integer.parseInt(atime) - Integer.parseInt(btime); + } + return 0; + } + }); + Map<String, String> sortedMap = new LinkedHashMap<>(); + for (Map.Entry<String, String> entry : entries) { + sortedMap.put(entry.getKey(), entry.getValue()); + } + return sortedMap; + } /** * @Description: ������������������������������ -- Gitblit v1.8.0