|
|
@ -10,16 +10,16 @@ import java.io.IOException; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.time.temporal.ChronoUnit; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class ExcelExportService { |
|
|
|
|
|
|
|
public void exportDataToExcel(Map<Integer, List<Status>> ipMap, String filePath) { |
|
|
|
public void exportDataToExcel(Map<Integer, List<Status>> ipMap,Map<String, List<Status> >categoryMap, String filePath) { |
|
|
|
Workbook workbook = new XSSFWorkbook(); |
|
|
|
Sheet sheet = workbook.createSheet("设备故障率统计页"); |
|
|
|
Map<Integer, List<Status>> map = new TreeMap<>(ipMap); |
|
|
|
Sheet sheet = workbook.createSheet("设备故障率分时统计页"); |
|
|
|
int rowNum = 0; |
|
|
|
Row row0 = sheet.createRow(0); |
|
|
|
row0.createCell(0).setCellValue("设备名称"); |
|
|
@ -39,7 +39,7 @@ public class ExcelExportService { |
|
|
|
int i=0; |
|
|
|
boolean flag = true; |
|
|
|
Row row1= sheet.createRow(1); |
|
|
|
for (Map.Entry<Integer, List<Status>> entry : ipMap.entrySet()) { |
|
|
|
for (Map.Entry<Integer, List<Status>> entry : map.entrySet()) { |
|
|
|
row0.createCell(2*i+7).setCellValue(entry.getKey()+"时"); |
|
|
|
sheet.addMergedRegion(new CellRangeAddress(0, 0, 2*i+7, 2*i+8)); |
|
|
|
row1.createCell(2*i+7).setCellValue("在线率"); |
|
|
@ -67,12 +67,123 @@ public class ExcelExportService { |
|
|
|
i++; |
|
|
|
flag = false; |
|
|
|
} |
|
|
|
Sheet sheets = workbook.createSheet("设备故障率汇总页"); |
|
|
|
createSheet(sheets,categoryMap); |
|
|
|
Sheet sheet1 = workbook.createSheet("设备故障率分时汇总页"); |
|
|
|
createSheet1(sheet1,ipMap); |
|
|
|
try (FileOutputStream outputStream = new FileOutputStream(filePath)) { |
|
|
|
workbook.write(outputStream); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
System.out.println("excel写入成功!!!!!!"); |
|
|
|
|
|
|
|
} |
|
|
|
public void createSheet1(Sheet sheet,Map<Integer, List<Status>> ipMap){ |
|
|
|
Map<Integer, List<Status>> map = new TreeMap<>(ipMap); |
|
|
|
int rowNum = 0; |
|
|
|
Row row0 = sheet.createRow(rowNum); |
|
|
|
row0.createCell(0).setCellValue("设备分类"); |
|
|
|
sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0)); |
|
|
|
int i=0; |
|
|
|
boolean flag = true; |
|
|
|
Row row1= sheet.createRow(1); |
|
|
|
for (Map.Entry<Integer, List<Status>> entry : map.entrySet()) { |
|
|
|
row0.createCell(3 * i + 1).setCellValue(entry.getKey() + "时"); |
|
|
|
sheet.addMergedRegion(new CellRangeAddress(0, 0, 3 * i + 1, 3 * i + 3)); |
|
|
|
row1.createCell(3 * i + 1).setCellValue("总统计数"); |
|
|
|
row1.createCell(3 * i + 2).setCellValue("在线统计数"); |
|
|
|
row1.createCell(3 * i + 3).setCellValue("在线率"); |
|
|
|
rowNum = 2; |
|
|
|
List<Status> groupItem = entry.getValue(); |
|
|
|
Map<String, List<Status>> maps = groupItem.stream().filter(iteam -> iteam.getType() != null).collect(Collectors.groupingBy(Status::getType)); |
|
|
|
for (Map.Entry<String, List<Status>> entrys : maps.entrySet()) { |
|
|
|
List<Status> groupItems = entrys.getValue(); |
|
|
|
long b = groupItems.stream().filter(iteam -> iteam.getDeviceStatus() == 1).count(); |
|
|
|
// for (Status ignored : groupItems) {
|
|
|
|
int a = rowNum++; |
|
|
|
Row row = sheet.getRow(a); // 获取指定索引的行
|
|
|
|
if (row == null) { // 如果行不存在,则创建新行
|
|
|
|
row = sheet.createRow(a); |
|
|
|
} |
|
|
|
HashMap<String, String> itemTypeMap = new HashMap<>(); |
|
|
|
itemTypeMap.put("1", "高清网络枪型固定摄像机"); |
|
|
|
itemTypeMap.put("2", "高清网络球形摄像机"); |
|
|
|
itemTypeMap.put("3", "桥下高清网络球形摄像机"); |
|
|
|
itemTypeMap.put("4", "360°全景摄像机"); |
|
|
|
itemTypeMap.put("5", "180°全景摄像机"); |
|
|
|
itemTypeMap.put("6", "门架式可变信息标志"); |
|
|
|
itemTypeMap.put("7", "雨棚可变信息标志"); |
|
|
|
itemTypeMap.put("8", "站前悬臂式可变信息标志"); |
|
|
|
itemTypeMap.put("9", "气象检测器"); |
|
|
|
itemTypeMap.put("10", "路段语音广播系统"); |
|
|
|
itemTypeMap.put("11", "护栏碰撞预警系统"); |
|
|
|
itemTypeMap.put("12", "毫米波雷达"); |
|
|
|
itemTypeMap.put("13", "合流区预警系统"); |
|
|
|
itemTypeMap.put("14", "激光疲劳唤醒"); |
|
|
|
itemTypeMap.put("15", "一类交通量调查站"); |
|
|
|
itemTypeMap.put("16", "智能行车诱导系统"); |
|
|
|
itemTypeMap.put("17", "智能设备箱"); |
|
|
|
String type = groupItems.get(0).getType(); |
|
|
|
String description = itemTypeMap.get(type); |
|
|
|
if (flag) { |
|
|
|
row.createCell(0).setCellValue(description); |
|
|
|
} |
|
|
|
row.createCell(3 * i + 1).setCellValue(groupItems.size()); |
|
|
|
row.createCell(3 * i + 2).setCellValue(b); |
|
|
|
row.createCell(3 * i + 3).setCellValue(String.format("%.2f%%", (double) b / groupItems.size() * 100)); |
|
|
|
} |
|
|
|
i++; |
|
|
|
flag = false; |
|
|
|
// }
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void createSheet(Sheet sheet,Map<String, List<Status> >categoryMap){ |
|
|
|
int rowNum = 0; |
|
|
|
Row row = sheet.createRow(rowNum); |
|
|
|
row.createCell(0).setCellValue("设备分类"); |
|
|
|
row.createCell(1).setCellValue("总统计数"); |
|
|
|
row.createCell(2).setCellValue("在线统计数"); |
|
|
|
row.createCell(3).setCellValue("在线率"); |
|
|
|
rowNum = 1; |
|
|
|
for (Map.Entry<String, List<Status>> entry : categoryMap.entrySet()) { |
|
|
|
List<Status> groupItems = entry.getValue(); |
|
|
|
long a=groupItems.stream().filter(iteam->iteam.getDeviceStatus()==1).count(); |
|
|
|
row = sheet.createRow(rowNum++); |
|
|
|
HashMap<String, String> itemTypeMap = new HashMap<>(); |
|
|
|
itemTypeMap.put("1", "高清网络枪型固定摄像机"); |
|
|
|
itemTypeMap.put("2", "高清网络球形摄像机"); |
|
|
|
itemTypeMap.put("3", "桥下高清网络球形摄像机"); |
|
|
|
itemTypeMap.put("4", "360°全景摄像机"); |
|
|
|
itemTypeMap.put("5", "180°全景摄像机"); |
|
|
|
itemTypeMap.put("6", "门架式可变信息标志"); |
|
|
|
itemTypeMap.put("7", "雨棚可变信息标志"); |
|
|
|
itemTypeMap.put("8", "站前悬臂式可变信息标志"); |
|
|
|
itemTypeMap.put("9", "气象检测器"); |
|
|
|
itemTypeMap.put("10", "路段语音广播系统"); |
|
|
|
itemTypeMap.put("11", "护栏碰撞预警系统"); |
|
|
|
itemTypeMap.put("12", "毫米波雷达"); |
|
|
|
itemTypeMap.put("13", "合流区预警系统"); |
|
|
|
itemTypeMap.put("14", "激光疲劳唤醒"); |
|
|
|
itemTypeMap.put("15", "一类交通量调查站"); |
|
|
|
itemTypeMap.put("16", "智能行车诱导系统"); |
|
|
|
itemTypeMap.put("17", "智能设备箱"); |
|
|
|
String type = groupItems.get(0).getType(); |
|
|
|
String description = itemTypeMap.get(type); |
|
|
|
row.createCell(0).setCellValue(description); |
|
|
|
row.createCell(1).setCellValue(groupItems.size()); |
|
|
|
row.createCell(2).setCellValue(a); |
|
|
|
row.createCell(3).setCellValue(String.format("%.2f%%", (double) a / groupItems.size() * 100)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|