|
@@ -994,4 +994,208 @@ public class InterlockDetailHistoryServiceImpl extends ServiceImpl<InterlockDeta
|
|
|
return interlockDetailHistoryMapper.getForExport11(dto);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导出excel 日报表导出
|
|
|
+ * 定时任务导出
|
|
|
+ * 修改
|
|
|
+ */
|
|
|
+ public Workbook exportXlsToFile2(InterlockHistoryQueryDTO dto, List<InterlockHistoryDistinctZZXTVO> zzxtvoList, Class<InterlockSummaryHistoryVO> clazz,String type) throws IOException {
|
|
|
+ SXSSFWorkbook workbook = new SXSSFWorkbook();
|
|
|
+ Map<String,CellStyle> cellStyleMap = getCellStyle(workbook);
|
|
|
+ //判断日报表当天是否存过数据
|
|
|
+// Boolean isSaveDay = summaryDayService.getIsExistDataCurr();
|
|
|
+ if (zzxtvoList != null) {
|
|
|
+ for (InterlockHistoryDistinctZZXTVO zzxtvo : zzxtvoList) {
|
|
|
+ if(dto.getBeginTime()==null && "1".equals(type)){
|
|
|
+ Date minTagTime = interlockDetailHistoryMapper.getMinTagTime(dto);
|
|
|
+ if(minTagTime!=null) dto.setBeginTime(minTagTime);
|
|
|
+ }
|
|
|
+ if(dto.getEndTime()==null && "1".equals(type)){
|
|
|
+ Date maxTagTime = interlockDetailHistoryMapper.getMaxTagTime(dto);
|
|
|
+ if(maxTagTime!=null) dto.setEndTime(maxTagTime);
|
|
|
+ }
|
|
|
+ String sheetName =generateSheetName(zzxtvo) ;
|
|
|
+ processSheet3(workbook, cellStyleMap, sheetName, dto, zzxtvo,type);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return workbook;
|
|
|
+ }
|
|
|
+
|
|
|
+ //该段日报表取的当前时刻数据是从联锁总表中获取的
|
|
|
+ private SXSSFWorkbook processSheet3(SXSSFWorkbook workbook, Map<String,CellStyle> cellStyleMap, String sheetName, InterlockHistoryQueryDTO dto, InterlockHistoryDistinctZZXTVO zzxtvo,String type) throws IOException {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String formattedBeginTime = dto.getBeginTime() != null ? sdf.format(dto.getBeginTime()) : "";
|
|
|
+ String formattedEndTime = dto.getEndTime() != null ? sdf.format(dto.getEndTime()) : "";
|
|
|
+ List<InterlockSummaryHistoryVO> exportList = new ArrayList<InterlockSummaryHistoryVO>();
|
|
|
+ dto.setInterlockSystemId(zzxtvo.getInterlockSystemId()); // 系统id
|
|
|
+ int ty = 0;
|
|
|
+ int wty = 0;
|
|
|
+ //导出当前时刻所有的联锁最新联锁总表详细表数据用于计算投用率
|
|
|
+ InterlockSummaryDayVO interlockSummaryDayVO = new InterlockSummaryDayVO();
|
|
|
+ interlockSummaryDayVO.setInterlockSystemId(zzxtvo.getInterlockSystemId());
|
|
|
+ List<InterlockSummaryDayVO> interlockSummaryDayVOList = interlockDetailMapper.getForExportLast2(interlockSummaryDayVO);//根据系统id查询该系统下所有联锁信息
|
|
|
+ exportList = InterlockSummaryHistoryConvert.INSTANCE.toHistoryDayList(interlockSummaryDayVOList);
|
|
|
+ //计算投用率 数据是按点位时间和联锁名称排序的,当名称不一样时,代表是下一个联锁,查看一下投用
|
|
|
+ String interlockname = "";
|
|
|
+// List<InterlockSummaryDay> interlockSummaryDays = new ArrayList<>();//存放日报表总表数据
|
|
|
+ for(InterlockSummaryHistoryVO interlockSummaryHistoryVO:exportList){
|
|
|
+ if(!interlockname.equals(interlockSummaryHistoryVO.getInterlockname())){
|
|
|
+ interlockname = interlockSummaryHistoryVO.getInterlockname();
|
|
|
+ if(interlockSummaryHistoryVO.getInterlockStatus().equals(interlockSummaryHistoryVO.getInterlockStatusTy())){
|
|
|
+ ty++;
|
|
|
+ }else{
|
|
|
+ wty++;
|
|
|
+ }
|
|
|
+// interlockSummaryDays.add(InterlockSummaryHistoryConvert.INSTANCE.toSummaryDay(interlockSummaryHistoryVO));
|
|
|
+ }
|
|
|
+ }
|
|
|
+// if(interlockSummaryDays.size()!=0 && !isSaveDay) summaryDayService.saveBatch(interlockSummaryDays);
|
|
|
+// //获取所有联锁数据用于写入日报表
|
|
|
+// exportList = this.getForExport00(dto);
|
|
|
+
|
|
|
+ // 计算投用率
|
|
|
+ //计算投用数量和未投用数量
|
|
|
+// ty = summaryHistoryMapper.cocuntTY11(dto);
|
|
|
+// wty = summaryHistoryMapper.cocuntWTY11(dto);
|
|
|
+ int total = ty + wty; // 总数量
|
|
|
+ String tylPercentage = "0.00%";//如果没有历史数据,投用率为0
|
|
|
+ if(total!=0){
|
|
|
+ double tyl = (double) ty / total * 100;
|
|
|
+ tylPercentage = String.format("%.2f%%", tyl); // 将百分比转换为百分数形式,保留两位小数
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println("系统开始-----------------------------------------------------------------------------------"+zzxtvo.getInterlockSystemName());
|
|
|
+
|
|
|
+ Sheet sheet = workbook.createSheet(sheetName);
|
|
|
+
|
|
|
+ // 设置列宽——30或15个字符宽度
|
|
|
+ int[] columnWidths = {30, 30, 30, 15, 15, 15, 15, 15};
|
|
|
+ for (int j = 0; j < columnWidths.length; j++) {
|
|
|
+ sheet.setColumnWidth(j, columnWidths[j] * 256);
|
|
|
+ }
|
|
|
+
|
|
|
+ //第一行:联锁历史数据报表
|
|
|
+ int rowNum = 0;
|
|
|
+ Row titleRow = sheet.createRow(rowNum++);
|
|
|
+ titleRow.setHeightInPoints(19.8f);
|
|
|
+ Cell titleCell = titleRow.createCell(0);
|
|
|
+ titleCell.setCellValue("联锁日报表");
|
|
|
+ titleCell.setCellStyle(cellStyleMap.get("firstStyle")); // 第一行的样式
|
|
|
+ // 合并第一行的前6列
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNum-1, rowNum-1, 0, 5));
|
|
|
+
|
|
|
+ // 第二行:报表生成时间:
|
|
|
+ Row secondTitleRow = sheet.createRow(rowNum++);
|
|
|
+ // 设置第2行数据
|
|
|
+ String[] s2 = {"报表生成时间:",sdf.format(new Date()),"","","",""};
|
|
|
+ createCellOfRowWithValueStyle(secondTitleRow,s2,cellStyleMap.get("centerAlignStyle2"));
|
|
|
+ // 合并第2行的后5列
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNum-1, rowNum-1, 1, 5));
|
|
|
+
|
|
|
+ // 第3行:装置名称
|
|
|
+ Row thirdTitleRow = sheet.createRow(rowNum++);
|
|
|
+ // 设置第3行数据
|
|
|
+ String[] s3 = {"装置名称:",zzxtvo.getInterlockApparatusName(),"","","",""};
|
|
|
+ CellStyle[] style3 = {cellStyleMap.get("centerAlignStyle"),cellStyleMap.get("centerAlignStyle3"),cellStyleMap.get("centerAlignStyle3"),cellStyleMap.get("centerAlignStyle3"),cellStyleMap.get("centerAlignStyle3"),cellStyleMap.get("centerAlignStyle3")};
|
|
|
+ createCellOfRowWithValueStyleName(thirdTitleRow,s3,style3);
|
|
|
+ // 合并第3行的后5列
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNum-1, rowNum-1, 1, 5));
|
|
|
+
|
|
|
+ // 第四行:系统名称
|
|
|
+ Row fourthTitleRow = sheet.createRow(rowNum++);
|
|
|
+ // 设置第4行数据
|
|
|
+ String[] s4 = {"系统名称:",zzxtvo.getInterlockSystemName(),"","","",""};
|
|
|
+ createCellOfRowWithValueStyleName(fourthTitleRow,s4,style3); //与第三行样式相同style3
|
|
|
+ // 合并第4行的后5列
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNum-1, rowNum-1, 1, 5));
|
|
|
+
|
|
|
+ //第五行:连锁数量、未投用联锁数量、投用率统计
|
|
|
+ Row sixTitleRow = sheet.createRow(rowNum++);
|
|
|
+ String[] s6 = {"联锁总数:", String.valueOf(total),"未投用联锁数量:", String.valueOf(wty),"投用率统计:", String.valueOf(tylPercentage)};
|
|
|
+ CellStyle[] style6 = {cellStyleMap.get("centerAlignStyle"),cellStyleMap.get("centerAlignStyle3"),cellStyleMap.get("centerAlignStyle"),cellStyleMap.get("centerAlignStyle3"),cellStyleMap.get("centerAlignStyle"),cellStyleMap.get("centerAlignStyle3")};
|
|
|
+ createCellOfRowWithValueStyleName(sixTitleRow,s6,style6);
|
|
|
+
|
|
|
+ //第六行空白
|
|
|
+ rowNum++;
|
|
|
+
|
|
|
+ //第七行:历史数据
|
|
|
+ Row eightTitleRow = sheet.createRow(rowNum++);
|
|
|
+ //设置第8行数据
|
|
|
+ String[] s8 = {"日报表数据:", "","", "","回路健康级别:A-健康;B-故障;C-严重故障;D-失效", "",""};
|
|
|
+ CellStyle[] style8 = {cellStyleMap.get("centerAlignStyle1"),cellStyleMap.get("centerAlignStyle1"),cellStyleMap.get("centerAlignStyle1"),cellStyleMap.get("centerAlignStyle1"),cellStyleMap.get("centerAlignStyle9"),cellStyleMap.get("centerAlignStyle9"),cellStyleMap.get("centerAlignStyle9")};
|
|
|
+ createCellOfRowWithValueStyleName(eightTitleRow,s8,style8);
|
|
|
+ // 分别合并第5、6、7列
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNum-1, rowNum-1, 4, 6));
|
|
|
+
|
|
|
+ //第9行:列名
|
|
|
+ Row columnRow= sheet.createRow(rowNum++);
|
|
|
+ String[] s9 = {"联锁名称", "联锁条件", "仪表状态", "控制系统状态", "旁路状态", "联锁状态", "回路健康级别"};
|
|
|
+ // 各列索引
|
|
|
+ int interlockNameCol = 1;
|
|
|
+ int interlockStatusCol = 6;
|
|
|
+ int loopHealthLevelCol = 7;
|
|
|
+ createCellOfRowWithValueStyle(columnRow,s9,cellStyleMap.get("centerAlignStyle"));
|
|
|
+
|
|
|
+ //如果有历史数据进行数据合并
|
|
|
+ if(exportList.size()!=0){
|
|
|
+ // 合并单元格的起始行索引
|
|
|
+ int startTagTimeRow = 0;
|
|
|
+ int startInterlockNameRow = 0;
|
|
|
+ int startInterlockStatusRow = 0;
|
|
|
+ int startLoopHealthLevelRow = 0;
|
|
|
+
|
|
|
+ for (int idx = 0; idx < exportList.size(); idx++) {
|
|
|
+ InterlockSummaryHistoryVO record = exportList.get(idx);
|
|
|
+
|
|
|
+ //创建单元格、设置格式、填充数据
|
|
|
+ Row row = sheet.createRow(rowNum);
|
|
|
+ String[] s = {record.getInterlockname(), record.getInterlockConditionTag(), record.getInstrumentStatusName(), record.getControlSystemStatusName(), record.getBypassName(), record.getInterlockStatusName(), record.getLoopHealthLevel()};
|
|
|
+ createCellOfRowWithValueStyle(row,s,cellStyleMap.get("centerAlignStyle3"));
|
|
|
+
|
|
|
+ // 合并 "联锁名称" 列单元格,基于 id
|
|
|
+ if (idx == 0 || !record.getInterlockname().equals(exportList.get(idx - 1).getInterlockname()) || !record.getSummaryid().equals(exportList.get(idx - 1).getSummaryid()) ) {
|
|
|
+ if (idx > 0 && (rowNum - startInterlockNameRow) > 1) {
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(startInterlockNameRow, rowNum - 1, interlockNameCol, interlockNameCol));
|
|
|
+ }
|
|
|
+ startInterlockNameRow = rowNum;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 合并 "联锁状态" 列单元格,基于"联锁名称"
|
|
|
+ if (idx == 0 || !record.getInterlockname().equals(exportList.get(idx - 1).getInterlockname()) || !record.getInterlockStatusName().equals(exportList.get(idx - 1).getInterlockStatusName()) || !record.getSummaryid().equals(exportList.get(idx - 1).getSummaryid()) ) {
|
|
|
+ if (idx > 0 && (rowNum - startInterlockStatusRow) > 1) {
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(startInterlockStatusRow, rowNum - 1, interlockStatusCol, interlockStatusCol));
|
|
|
+ }
|
|
|
+ startInterlockStatusRow = rowNum;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 合并 "回路健康状态" 列单元格,基于 "联锁名称"
|
|
|
+ if (idx == 0 || !record.getInterlockname().equals(exportList.get(idx - 1).getInterlockname()) || !record.getLoopHealthLevel().equals(exportList.get(idx - 1).getLoopHealthLevel()) || !record.getSummaryid().equals(exportList.get(idx - 1).getSummaryid()) ) {
|
|
|
+ if (idx > 0 && (rowNum - startLoopHealthLevelRow) > 1) {
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(startLoopHealthLevelRow, rowNum - 1, loopHealthLevelCol, loopHealthLevelCol));
|
|
|
+ }
|
|
|
+ startLoopHealthLevelRow = rowNum;
|
|
|
+ }
|
|
|
+
|
|
|
+ rowNum++;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 最后一组合并区域的处理
|
|
|
+ // 合并 "联锁名称" 列的最后一组
|
|
|
+ if ((rowNum - startInterlockNameRow) > 1) {
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(startInterlockNameRow, rowNum - 1, interlockNameCol, interlockNameCol));
|
|
|
+ }
|
|
|
+ // 合并 "联锁状态" 列的最后一组
|
|
|
+ if ((rowNum - startInterlockStatusRow) > 1) {
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(startInterlockStatusRow, rowNum - 1, interlockStatusCol, interlockStatusCol));
|
|
|
+ }
|
|
|
+ // 合并 "回路健康状态" 列的最后一组
|
|
|
+ if ((rowNum - startLoopHealthLevelRow) > 1) {
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(startLoopHealthLevelRow, rowNum - 1, loopHealthLevelCol, loopHealthLevelCol));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("系统结束-----------------------------------------------------------------------------------"+zzxtvo.getInterlockSystemName());
|
|
|
+
|
|
|
+ return workbook;
|
|
|
+ }
|
|
|
+
|
|
|
}
|