|
|
|
@ -5,6 +5,7 @@ import com.alibaba.excel.ExcelWriter;
|
|
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
|
|
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
|
|
|
|
import com.xydl.cac.entity.ModevTypePoint;
|
|
|
|
|
import com.xydl.cac.entity.NSensor;
|
|
|
|
|
import com.xydl.cac.excel.CacExcelListener;
|
|
|
|
|
import com.xydl.cac.excel.CacLine;
|
|
|
|
|
import com.xydl.cac.model.SensorDetail;
|
|
|
|
@ -21,6 +22,7 @@ import javax.annotation.Resource;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
@ -104,4 +106,68 @@ public class ReportServiceImpl implements ReportService {
|
|
|
|
|
.sheet(0)
|
|
|
|
|
.doRead();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void exportLatest(List<NSensor> result, 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;
|
|
|
|
|
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);
|
|
|
|
|
head = new ArrayList<>();
|
|
|
|
|
head.add("时间");
|
|
|
|
|
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.add(line);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet(i, key + "")
|
|
|
|
|
.head(heads)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
excelWriter.write(list, writeSheet);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
excelWriter.finish();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|