Browse Source

优化导出

lamphua 2 days ago
parent
commit
47e20aefac

+ 10
- 8
cmc-temperature-back/cmc-monitoring/src/main/java/com/ruoyi/monitoring/controller/CmcTemperatureController.java View File

124
         timeColumn.setNeedMerge(true);
124
         timeColumn.setNeedMerge(true);
125
         timeColumn.setWidth(20);
125
         timeColumn.setWidth(20);
126
         entityList.add(timeColumn);
126
         entityList.add(timeColumn);
127
-        cmcChannelService.listChannel(cmcChannel).forEach(channel -> {
127
+        List<CmcChannel> channelList = cmcChannelService.listChannel(cmcChannel);
128
+        channelList.forEach(channel -> {
128
             ExcelExportEntity entity = new ExcelExportEntity(channel.getInfo(), channel.getSensorNo().toString());
129
             ExcelExportEntity entity = new ExcelExportEntity(channel.getInfo(), channel.getSensorNo().toString());
129
             entityList.add(entity);
130
             entityList.add(entity);
130
         });
131
         });
131
-        List<Map<String, Object>> dataList = prepareData(temperatureList);
132
+        List<Map<String, Object>> dataList = prepareData(channelList, temperatureList);
132
         ExcelUtil.customExport(entityList, dataList);
133
         ExcelUtil.customExport(entityList, dataList);
133
     }
134
     }
134
 
135
 
135
-    private static List<Map<String, Object>> prepareData(List<CmcTemperature> temperatureList) {
136
+    private static List<Map<String, Object>> prepareData(List<CmcChannel> channelList, List<CmcTemperature> temperatureList) {
136
         Map<String, Map<Long, Float>> timeDataMap = new LinkedHashMap<>();
137
         Map<String, Map<Long, Float>> timeDataMap = new LinkedHashMap<>();
137
-        Set<Long> locations = new TreeSet<>();
138
-
138
+        List<Long> sensors = new ArrayList<>();
139
+        channelList.forEach(channel ->  {
140
+            sensors.add(channel.getSensorNo());
141
+        });
139
         for (CmcTemperature cmcTemperature : temperatureList) {
142
         for (CmcTemperature cmcTemperature : temperatureList) {
140
             Date datetime = cmcTemperature.getDatetime();
143
             Date datetime = cmcTemperature.getDatetime();
141
             Long sensorNo = cmcTemperature.getSensorNo();
144
             Long sensorNo = cmcTemperature.getSensorNo();
142
 
145
 
143
-            locations.add(sensorNo);
144
             String dateTme = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(datetime);
146
             String dateTme = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(datetime);
145
             if (!timeDataMap.containsKey(dateTme)) {
147
             if (!timeDataMap.containsKey(dateTme)) {
146
                 timeDataMap.put(dateTme, new HashMap<>());
148
                 timeDataMap.put(dateTme, new HashMap<>());
157
             rowData.put("Datetime", entry.getKey());
159
             rowData.put("Datetime", entry.getKey());
158
 
160
 
159
             Map<Long, Float> locationData = entry.getValue();
161
             Map<Long, Float> locationData = entry.getValue();
160
-            for (Long location : locations) {
161
-                rowData.put(String.valueOf(location), locationData.get(location));
162
+            for (Long sensor : sensors) {
163
+                rowData.put(String.valueOf(sensor), locationData.get(sensor));
162
             }
164
             }
163
 
165
 
164
             exportData.add(rowData);
166
             exportData.add(rowData);

+ 0
- 1
cmc-temperature-back/ruoyi-common/src/main/java/com/ruoyi/common/utils/ExcelUtil.java View File

11
 
11
 
12
 import java.io.IOException;
12
 import java.io.IOException;
13
 import java.util.List;
13
 import java.util.List;
14
-import java.util.Map;
15
 
14
 
16
 /**
15
 /**
17
  * Excel相关处理
16
  * Excel相关处理

Loading…
Cancel
Save