From 8f5416a1e507fe24c151648982e391fead13ffdd Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Tue, 02 Nov 2021 15:57:22 +0800
Subject: [PATCH] 省内倒数排名增加time字段

---
 screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java |   42 ++++++++++++++++++++++++++++++++++++------
 1 files changed, 36 insertions(+), 6 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..67408e5 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
@@ -136,8 +136,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 +158,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) {
@@ -171,7 +173,7 @@
             dto.setSensorCode(sensor);
             timeValueMap.forEach((time, valueJson) -> {
                 Map<String, Object> listMap = new HashMap<>();
-                //������������������������������
+                //���������������������������������������������
                 if (valueJson == null) {
                     listMap.put("time", time);
                     listMap.put("value", "");
@@ -180,7 +182,7 @@
                 }
                 Map<String, Object> valueMap = JSON.parseObject(valueJson, Map.class);
                 Object sensorValueObject = valueMap.get(sensor);
-                //������������������������������������������null
+                //���������������������������������������������
                 if (sensorValueObject == null) {
                     listMap.put("time", time);
                     listMap.put("value", "");
@@ -189,6 +191,7 @@
                 }
                 //������������������������������������������
                 if (reportType.equals(Constants.DAILY_REPORT)) {
+                    //���������������������N���������������
                     if (!Constants.NORMAL_FLAG.equals(valueMap.get(sensor + "-Flag"))) {
                         listMap.put("time", time);
                         listMap.put("value", "");
@@ -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