|
|
|
@ -108,66 +108,61 @@ public class ReportServiceImpl implements ReportService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void exportLatest(List<NSensor> result, OutputStream output) throws Exception {
|
|
|
|
|
public void exportLatest(Map<Integer, List<NSensor>> map, OutputStream output) throws Exception {
|
|
|
|
|
|
|
|
|
|
// 导出Excel
|
|
|
|
|
ExcelWriter excelWriter = EasyExcel.write(output).inMemory(true)
|
|
|
|
|
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).build();
|
|
|
|
|
|
|
|
|
|
Map<Integer, List<NSensor>> map = new HashMap<>();
|
|
|
|
|
for (NSensor nSensor : result) {
|
|
|
|
|
if (map.containsKey(nSensor.getTypeId())) {
|
|
|
|
|
map.get(nSensor.getTypeId()).add(nSensor);
|
|
|
|
|
} else {
|
|
|
|
|
List<NSensor> list = new ArrayList<>();
|
|
|
|
|
list.add(nSensor);
|
|
|
|
|
map.put(nSensor.getTypeId(), list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
int idx = 0;
|
|
|
|
|
for (Integer key : map.keySet()) {
|
|
|
|
|
List<NSensor> nSensors = map.get(key);
|
|
|
|
|
|
|
|
|
|
// 表头
|
|
|
|
|
List<List<String>> heads = new ArrayList<>();
|
|
|
|
|
List<String> head = new ArrayList<>();
|
|
|
|
|
head.add("主设备名称");
|
|
|
|
|
heads.add(head);
|
|
|
|
|
this.writerSheetLatest(excelWriter, idx, nSensors);
|
|
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
excelWriter.finish();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void writerSheetLatest(ExcelWriter excelWriter, int idx, List<NSensor> nSensors) {
|
|
|
|
|
// 表头
|
|
|
|
|
List<List<String>> heads = new ArrayList<>();
|
|
|
|
|
List<String> head = new ArrayList<>();
|
|
|
|
|
head.add("主设备名称");
|
|
|
|
|
heads.add(head);
|
|
|
|
|
head = new ArrayList<>();
|
|
|
|
|
head.add("时间");
|
|
|
|
|
heads.add(head);
|
|
|
|
|
for (ModevTypePoint point : nSensors.get(0).getTypePoints()) {
|
|
|
|
|
head = new ArrayList<>();
|
|
|
|
|
head.add("时间");
|
|
|
|
|
head.add(point.getFieldDesc() + "(" + point.getUnit() + ")");
|
|
|
|
|
heads.add(head);
|
|
|
|
|
for (ModevTypePoint point : nSensors.get(0).getTypePoints()) {
|
|
|
|
|
head = new ArrayList<>();
|
|
|
|
|
head.add(point.getFieldDesc() + "(" + point.getUnit() + ")");
|
|
|
|
|
heads.add(head);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 内容
|
|
|
|
|
List<List<String>> list = new ArrayList<>();
|
|
|
|
|
for (NSensor nSensor : nSensors) {
|
|
|
|
|
List<String> line = new ArrayList<>();
|
|
|
|
|
line.add(nSensor.getZsbName());
|
|
|
|
|
HashMap<String, String> lastData = nSensor.getLastData();
|
|
|
|
|
if (null != lastData) {
|
|
|
|
|
String acquisitionTime = nSensor.getLastData().get("acquisitionTime");
|
|
|
|
|
line.add(acquisitionTime);
|
|
|
|
|
for (ModevTypePoint typePoint : nSensor.getTypePoints()) {
|
|
|
|
|
line.add(lastData.get(typePoint.getField()));
|
|
|
|
|
}
|
|
|
|
|
// 内容
|
|
|
|
|
List<List<String>> list = new ArrayList<>();
|
|
|
|
|
for (NSensor nSensor : nSensors) {
|
|
|
|
|
List<String> line = new ArrayList<>();
|
|
|
|
|
line.add(nSensor.getZsbName());
|
|
|
|
|
HashMap<String, String> lastData = nSensor.getLastData();
|
|
|
|
|
if (null != lastData) {
|
|
|
|
|
String acquisitionTime = nSensor.getLastData().get("acquisitionTime");
|
|
|
|
|
line.add(acquisitionTime);
|
|
|
|
|
for (ModevTypePoint typePoint : nSensor.getTypePoints()) {
|
|
|
|
|
line.add(lastData.get(typePoint.getField()));
|
|
|
|
|
}
|
|
|
|
|
list.add(line);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet(i, key + "")
|
|
|
|
|
.head(heads)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
excelWriter.write(list, writeSheet);
|
|
|
|
|
i++;
|
|
|
|
|
list.add(line);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
excelWriter.finish();
|
|
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet(idx, nSensors.get(0).getTypeName())
|
|
|
|
|
.head(heads)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
excelWriter.write(list, writeSheet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|