| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | |
| | | * |
| | | * @throws IOException |
| | | */ |
| | | public void dcReport(int battGroupId,int testRecordCount) throws IOException { |
| | | String filePath = "C:\\Users\\29550\\Desktop\\当前项目\\2023\\0乌东德系统\\测试.xlsx"; |
| | | public void dcReport(int battGroupId, int testRecordCount, HttpServletResponse response) throws IOException { |
| | | //String filePath = "C:\\Users\\29550\\Desktop\\当前项目\\2023\\0乌东德系统\\测试.xlsx"; |
| | | //创建一个工作簿 |
| | | XSSFWorkbook workbook = new XSSFWorkbook(); |
| | | //创建sheet1 |
| | | createSheet1(workbook,battGroupId,testRecordCount); |
| | | PowerInf battInfo = createSheet1(workbook, battGroupId, testRecordCount); |
| | | //创建sheet2 -- 每月电压,12个月,取每月1号零点零分 |
| | | //创建sheet3 -- 每月内阻, 12个月,取每月1号零点零分 |
| | | //createSheet2And3(workbook,battGroupId); |
| | | createSheet2And3(workbook,battGroupId); |
| | | //创建sheet4 -- 每天温度, 30天, 取每天零点零分 |
| | | //createSheet4(workbook,battGroupId); |
| | | createSheet4(workbook,battGroupId); |
| | | |
| | | // 将工作簿写入文件 |
| | | /*// 将工作簿写入文件 |
| | | FileOutputStream fileOut = new FileOutputStream(filePath); |
| | | workbook.write(fileOut); |
| | | workbook.write(fileOut);*/ |
| | | String filename ="直流报表_"+battInfo.getPowerName()+"_"+battInfo.getBattGroupName()+".xlsx"; |
| | | // 根据浏览器客户端做不同编码,兼容性更好 |
| | | String encodedFilename = java.net.URLEncoder.encode(filename, String.valueOf(StandardCharsets.UTF_8)); |
| | | boolean isMSBrowser = false; |
| | | String ua = response.getHeader("User-Agent"); |
| | | if (ua != null) { |
| | | ua = ua.toLowerCase(); |
| | | if (ua.contains("msie") || ua.contains("edge") || ua.contains("trident")) { |
| | | isMSBrowser = true; |
| | | } |
| | | } |
| | | |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | if (isMSBrowser) { |
| | | // IE/Edge 使用 UTF-8 编码并用 URLEncoder |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + encodedFilename + ";filename*=utf-8''" + encodedFilename); |
| | | } else { |
| | | // Chrome/Firefox 等使用 RFC 5987 编码方式 |
| | | response.setHeader("Content-Disposition", "attachment;filename*=UTF-8''" + encodedFilename); |
| | | } |
| | | |
| | | |
| | | workbook.write(response.getOutputStream()); |
| | | // 关闭工作簿 |
| | | workbook.close(); |
| | | |
| | |
| | | XSSFCellStyle cellStyleOriginal2 = cellOfSheet3.getCellStyle(); |
| | | XSSFCellStyle cellStyleNew2 = getCellStyleFont(cellStyleOriginal2,workbook, true, 15); |
| | | cellOfSheet3.setCellStyle(cellStyleNew2); |
| | | |
| | | //设置数值类型保留位数 |
| | | setDateFormat(workbook,sheet2,3,110,1,columnCount-2, "0.0000"); |
| | | setDateFormat(workbook,sheet3,3,110,1,columnCount-2, "0.0000"); |
| | | |
| | | |
| | | // 创建绘图工具 |
| | |
| | | cell.setCellStyle(cellStyle); |
| | | } |
| | | |
| | | //设置数值类型单元格保留位数 |
| | | setDateFormat(workbook,sheet4,3,110,1,columnCount-2, "0.0000"); |
| | | createChart(sheet4, columnCount,3,"温度折线图"); |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | //private static void createSheet1(XSSFWorkbook workbook, int battGroupId, int testRecordCount) { |
| | | private void createSheet1(XSSFWorkbook workbook, int battGroupId, int testRecordCount) { |
| | | private PowerInf createSheet1(XSSFWorkbook workbook, int battGroupId, int testRecordCount) { |
| | | XSSFSheet sheet = workbook.createSheet("放电充电电压数据报表"); |
| | | //总的列数根据 放电时长和充电时长决定 |
| | | //数据准备 |
| | |
| | | CellRangeAddress region = new CellRangeAddress(0, 0, 0, columnCount-1); |
| | | sheet.addMergedRegion(region); |
| | | |
| | | //TODO 第二行的合并列是根据变动的,后续调整 |
| | | CellRangeAddress region21 = new CellRangeAddress(1, 1, 0, 1); |
| | | sheet.addMergedRegion(region21); |
| | | //第三行,第五行,第六行的合并列,前两个单元模块是固定的,其中1个合并单元 |
| | | CellRangeAddress region31 = new CellRangeAddress(2, 2, 1, 2); |
| | | CellRangeAddress region32 = new CellRangeAddress(2, 2, 3, 4); |
| | | CellRangeAddress region51 = new CellRangeAddress(4, 4, 1, 2); |
| | | CellRangeAddress region52 = new CellRangeAddress(4, 4, 3, 4); |
| | | CellRangeAddress region61 = new CellRangeAddress(5, 5, 1, 2); |
| | | CellRangeAddress region62 = new CellRangeAddress(5, 5, 3, 4); |
| | | |
| | | CellRangeAddress region22 = new CellRangeAddress(1, 1, 3, 9); |
| | | sheet.addMergedRegion(region22); |
| | | |
| | | CellRangeAddress region23 = new CellRangeAddress(1, 1, 10, 13); |
| | | sheet.addMergedRegion(region23); |
| | | |
| | | CellRangeAddress region24 = new CellRangeAddress(1, 1, 14, 17); |
| | | sheet.addMergedRegion(region24); |
| | | |
| | | CellRangeAddress region25 = new CellRangeAddress(1, 1, 18, 24); |
| | | sheet.addMergedRegion(region25); |
| | | |
| | | //第三行的合并列,前两个单元模块是固定的,其中1个合并单元 |
| | | CellRangeAddress region31 = new CellRangeAddress(2, 2, 2, 3); |
| | | sheet.addMergedRegion(region31); |
| | | |
| | | sheet.addMergedRegion(region32); |
| | | sheet.addMergedRegion(region51); |
| | | sheet.addMergedRegion(region52); |
| | | sheet.addMergedRegion(region61); |
| | | sheet.addMergedRegion(region62); |
| | | |
| | | // 创建居中样式 |
| | | CellStyle style = workbook.createCellStyle(); |
| | |
| | | cellRow1.setCellStyle(style); |
| | | |
| | | //第二行是放电基本信息 |
| | | //因为是动态的,没办法像模板一样. |
| | | //蓄电池组号:第一列 |
| | | //工作票信息:二三列 |
| | | //放电日期:第四列起步-放电结束静置0.5h |
| | | //放电电流,时长,容量:放电结束后静置0.5h起到充满电 |
| | | //环境温湿度:备注 |
| | | XSSFRow row1 = sheet.createRow(1); |
| | | XSSFCell cell1Row2 = row1.createCell(0); |
| | | cell1Row2.setCellValue("蓄电池组号:" + battInfo.getBattGroupName()); |
| | | |
| | | XSSFCell cell2Row2 = row1.createCell(2); |
| | | cell2Row2.setCellValue(""); |
| | | |
| | | XSSFCell cell3Row2 = row1.createCell(3); |
| | | cell3Row2.setCellValue("工作票号:2273925\n" + |
| | | XSSFCell cell2Row2 = row1.createCell(1); |
| | | cell2Row2.setCellValue("工作票号:2273925\n" + |
| | | "工作负责人:马云燕\n" + |
| | | "工作成员:周素文、李志标、王月灿等"); |
| | | |
| | | XSSFCell cell4Row2 = row1.createCell(10); |
| | | cell4Row2.setCellValue("放电日期:2021.10.30\n" + |
| | | "放电开始时间:10:00\n" + |
| | | "放电结束时间:19:47"); |
| | | XSSFCell cell3Row2 = row1.createCell(3); |
| | | cell3Row2.setCellValue("放电日期:"+ DateUtil.YYYY_DOT_MM_DOT_DD.format(dischargeStartTime) +"\n" + |
| | | "放电开始时间:"+ DateUtil.YYYY_MM_DD_HH_MM.format(dischargeStartTime) +"\n" + |
| | | "放电结束时间:"+ DateUtil.YYYY_MM_DD_HH_MM.format(dischargeEndTime.getTime())); |
| | | |
| | | XSSFCell cell5Row2 = row1.createCell(14); |
| | | cell5Row2.setCellValue("放电电流(A):35\n" + |
| | | "放电时长(时.分):600min\n" + |
| | | "放电容量(Ah):300"); |
| | | XSSFCell cell4Row2 = row1.createCell(5); |
| | | cell4Row2.setCellValue("放电电流(A):"+ Math.abs(battTestInf.getTestCurr())+"\n" + |
| | | "放电时长(时.分):"+testTimeMinutes+"\n" + |
| | | "放电容量(Ah):"+Math.abs(battTestInf.getTestCap())); |
| | | |
| | | XSSFCell cell6Row2 = row1.createCell(18); |
| | | cell6Row2.setCellValue("环境温度(℃):24.5\n" + |
| | | XSSFCell cell5Row2 = row1.createCell(columnCount-1); |
| | | cell5Row2.setCellValue("环境温度(℃):24.5\n" + |
| | | "环境湿度(%):46.7"); |
| | | //第二行设置加粗 |
| | | //setRowStyle(sheet.getRow(1),cellStyleFontBold); |
| | | |
| | | //二行的合并列是根据变动的 |
| | | row1.setHeightInPoints(57); |
| | | sheet.getRow(0).setHeightInPoints(42); |
| | | CellRangeAddress region22 = new CellRangeAddress(1, 1, 1, 2); |
| | | sheet.addMergedRegion(region22); |
| | | |
| | | CellRangeAddress region23 = new CellRangeAddress(1, 1, 3, 4); |
| | | sheet.addMergedRegion(region23); |
| | | |
| | | CellRangeAddress region24 = new CellRangeAddress(1, 1, 5, columnCount-2); |
| | | sheet.addMergedRegion(region24); |
| | | |
| | | //第三行是电池号和电压等相关抬头 |
| | | //第四行是电压列和温度列标识 |
| | | XSSFRow row2 = sheet.createRow(2); |
| | | XSSFRow row3 = sheet.createRow(3); |
| | | |
| | | row2.createCell(0).setCellValue("蓄电池号(#)"); |
| | | row2.createCell(1).setCellValue("蓄电池浮充电压值(V)"); |
| | | row2.createCell(2).setCellValue("放电前蓄电池开路电压值(V)"); |
| | | row2.createCell(3).setCellValue("放电前蓄电池开路电压值(V)"); |
| | | |
| | | row3.createCell(0).setCellValue("项目"); |
| | | row3.createCell(1).setCellValue("-1(电压)"); |
| | | row3.createCell(2).setCellValue("0(电压)"); |
| | | row3.createCell(3).setCellValue("0(温度)"); |
| | | row3.createCell(2).setCellValue("-1(温度)"); |
| | | row3.createCell(3).setCellValue("0(电压)"); |
| | | row3.createCell(4).setCellValue("0(温度)"); |
| | | |
| | | //放电特定电压值 |
| | | int columnIndex = 3; |
| | | int columnIndex = 5; |
| | | if(dischargeColumnCount > 0){ |
| | | row2.createCell(5).setCellValue("放电0.5h蓄电池电压值(V)"); |
| | | CellRangeAddress region33 = new CellRangeAddress(2, 2, 4, 5); |
| | | //row2.createCell(5).setCellValue("放电0.5h蓄电池电压值(V)"); |
| | | row2.createCell(columnCount).setCellValue("放电0.5h蓄电池电压值(V)"); |
| | | CellRangeAddress region33 = new CellRangeAddress(2, 2, 5, 6); |
| | | CellRangeAddress region53 = new CellRangeAddress(4, 4, 5, 6); |
| | | CellRangeAddress region63 = new CellRangeAddress(5, 5, 5, 6); |
| | | |
| | | sheet.addMergedRegion(region33); |
| | | row3.createCell(4).setCellValue("0.5(电压)"); |
| | | row3.createCell(5).setCellValue("0.5(温度)"); |
| | | sheet.addMergedRegion(region53); |
| | | sheet.addMergedRegion(region63); |
| | | |
| | | row3.createCell(5).setCellValue("0.5(电压)"); |
| | | row3.createCell(6).setCellValue("0.5(温度)"); |
| | | columnIndex+=2; |
| | | if(dischargeColumnCount > 2){ //合并单元格了,所以索引+2 |
| | | row2.createCell(7).setCellValue("放电1h蓄电池电压值(V)"); |
| | | CellRangeAddress region34 = new CellRangeAddress(2, 2, 6, 7); |
| | | //row2.createCell(7).setCellValue("放电1h蓄电池电压值(V)"); |
| | | row2.createCell(columnCount).setCellValue("放电1h蓄电池电压值(V)"); |
| | | CellRangeAddress region34 = new CellRangeAddress(2, 2, 7, 8); |
| | | CellRangeAddress region54 = new CellRangeAddress(4, 4, 7, 8); |
| | | CellRangeAddress region64 = new CellRangeAddress(5, 5, 7, 8); |
| | | |
| | | sheet.addMergedRegion(region34); |
| | | row3.createCell(6).setCellValue("1(电压)"); |
| | | row3.createCell(7).setCellValue("1(温度)"); |
| | | sheet.addMergedRegion(region54); |
| | | sheet.addMergedRegion(region64); |
| | | |
| | | row3.createCell(7).setCellValue("1(电压)"); |
| | | row3.createCell(8).setCellValue("1(温度)"); |
| | | columnIndex+=2; |
| | | if(dischargeColumnCount > 4){ |
| | | columnIndex++; |
| | | //放电nh蓄电池电压值(V),n从2开始 |
| | | for(int i = 4;i < dischargeColumnCount;i++){ |
| | | row2.createCell(i+5).setCellValue("放电" + (i-2) + "h蓄电池电压值(V)"); |
| | |
| | | } |
| | | |
| | | //充电特定电压值 |
| | | row2.createCell(++columnIndex).setCellValue("放电结束0.5h后蓄电池开路电压值(V)"); |
| | | row2.createCell(columnIndex).setCellValue("放电结束0.5h后蓄电池开路电压值(V)"); |
| | | row3.createCell(columnIndex).setCellValue("10.5"); |
| | | columnIndex++; |
| | | if(chargeColumnCount > 0){ |
| | | columnIndex++; |
| | | row2.createCell(columnIndex).setCellValue("充电0.5h"); |
| | | |
| | | columnIndex++; |
| | | if(chargeColumnCount > 1){ |
| | | //充电nh,n从1开始 |
| | | for(int i = 1;i < chargeColumnCount;i++){ |
| | | columnIndex++; |
| | | row2.createCell(columnIndex).setCellValue("充电" + (i) + "h蓄电池电压值(V)"); |
| | | row3.createCell(columnIndex);//填充单元格的作用 |
| | | columnIndex++; |
| | | } |
| | | |
| | | } |
| | | } |
| | | row2.createCell(++columnIndex).setCellValue("充满后蓄电池电压值(V)(电流为0)"); |
| | | row2.createCell(columnIndex).setCellValue("充满后蓄电池电压值(V)(电流为0)"); |
| | | row3.createCell(columnIndex).setCellValue("11"); |
| | | row2.createCell(++columnIndex).setCellValue("备注"); |
| | | columnIndex++; |
| | | row2.createCell(columnIndex).setCellValue("备注"); |
| | | row3.createCell(columnIndex);//填充单元格的作用 |
| | | |
| | | |
| | | |
| | | //从rowIndex=6开始 |
| | | int rowIndex = 6; |
| | | //从rowIndex=4开始 |
| | | int rowIndex = 4; |
| | | // 共104节单体,104行. 进行遍历,填充 |
| | | //蓄电池浮充电压值列表 |
| | | List<BattRealTimeDataHistory> fcVolList = new ArrayList<>(); |
| | | fcVolList = battRTDataHisService.getFcVolList(battGroupId,dischargeStartTime); |
| | | List<BattRealTimeDataHistory> fcVolListOriginal = battRTDataHisService.getFcVolList(battGroupId,dischargeStartTime); |
| | | //按单体编号排序,按编号升序 |
| | | fcVolList.sort(Comparator.comparingInt(BattRealTimeDataHistory::getMonNum)); |
| | | fcVolListOriginal.sort(Comparator.comparingInt(BattRealTimeDataHistory::getMonNum)); |
| | | addStatistics(fcVolListOriginal,"vol","tmp"); |
| | | //总电流总电压列入 |
| | | Float fcGroupVol = fcVolListOriginal.get(0).getGroupVol(); |
| | | Float fcGroupCurr = fcVolListOriginal.get(0).getGroupCurr(); |
| | | |
| | | BattRealTimeDataHistory fcGroupVolData = new BattRealTimeDataHistory(); |
| | | fcGroupVolData.setMonNum(-2); |
| | | fcGroupVolData.setGroupVol(fcGroupVol); |
| | | |
| | | BattRealTimeDataHistory fcGroupCurrData = new BattRealTimeDataHistory(); |
| | | fcGroupCurrData.setMonNum(-1); |
| | | fcGroupCurrData.setGroupCurr(fcGroupCurr); |
| | | |
| | | fcVolList.add(fcGroupVolData); |
| | | fcVolList.add(fcGroupCurrData); |
| | | fcVolList.addAll(fcVolListOriginal); |
| | | |
| | | //放点前蓄电池开路电压值 |
| | | List<BattRealTimeDataHistory> preVolList = new ArrayList<>(); |
| | | preVolList = battRTDataHisService.getPreVolList(battGroupId,dischargeStartTime); |
| | | List<BattRealTimeDataHistory> preVolListOriginal = battRTDataHisService.getPreVolList(battGroupId,dischargeStartTime); |
| | | addStatistics(preVolListOriginal,"vol","tmp"); |
| | | //总电流总电压列入 |
| | | Float preGroupVol = preVolListOriginal.get(0).getGroupVol(); |
| | | Float preGroupCurr = preVolListOriginal.get(0).getGroupCurr(); |
| | | |
| | | addStatistics(fcVolList,"vol"); |
| | | addStatistics(preVolList,"vol","tmp"); |
| | | BattRealTimeDataHistory preGroupVolData = new BattRealTimeDataHistory(); |
| | | preGroupVolData.setMonNum(-2); |
| | | preGroupVolData.setGroupVol(preGroupVol); |
| | | |
| | | BattRealTimeDataHistory preGroupCurrData = new BattRealTimeDataHistory(); |
| | | preGroupCurrData.setMonNum(-1); |
| | | preGroupCurrData.setGroupCurr(preGroupCurr); |
| | | |
| | | preVolList.add(preGroupVolData); |
| | | preVolList.add(preGroupCurrData); |
| | | preVolList.addAll(preVolListOriginal); |
| | | |
| | | //放电结束0.5h后蓄电池开路电压值 |
| | | Calendar dischargeEndCalendar = Calendar.getInstance(); |
| | | dischargeEndCalendar.setTime(dischargeEndTime.getTime()); |
| | | dischargeEndCalendar.add(Calendar.MINUTE,30); |
| | | List<BattRealTimeDataHistory> dischargeSetVolListOne = battRTDataHisService.getRecordList(battGroupId, dischargeEndCalendar.getTime()); |
| | | dischargeSetVolListOne.sort(Comparator.comparingInt(BattRealTimeDataHistory::getMonNum)); |
| | | addStatistics(dischargeSetVolListOne,"vol","tmp"); |
| | | List<BattRealTimeDataHistory> dischargeSetVolListOne = new ArrayList<>(); |
| | | List<BattRealTimeDataHistory> dischargeSetVolListOneOriginal = battRTDataHisService.getRecordList(battGroupId, dischargeEndCalendar.getTime()); |
| | | dischargeSetVolListOneOriginal.sort(Comparator.comparingInt(BattRealTimeDataHistory::getMonNum)); |
| | | addStatistics(dischargeSetVolListOneOriginal,"vol","tmp"); |
| | | //总电流总电压列入 |
| | | Float groupVolOne = dischargeSetVolListOneOriginal.get(0).getGroupVol(); |
| | | Float groupCurrOne = dischargeSetVolListOneOriginal.get(0).getGroupCurr(); |
| | | |
| | | BattRealTimeDataHistory groupVolDataOne = new BattRealTimeDataHistory(); |
| | | groupVolDataOne.setMonNum(-2); |
| | | groupVolDataOne.setGroupVol(groupVolOne); |
| | | |
| | | BattRealTimeDataHistory groupCurrDataOne = new BattRealTimeDataHistory(); |
| | | groupCurrDataOne.setMonNum(-1); |
| | | groupCurrDataOne.setGroupCurr(groupCurrOne); |
| | | |
| | | dischargeSetVolListOne.add(groupVolDataOne); |
| | | dischargeSetVolListOne.add(groupCurrDataOne); |
| | | dischargeSetVolListOne.addAll(dischargeSetVolListOneOriginal); |
| | | |
| | | //定位到充电开始时间,状态变为充电的记录时间 |
| | | Date chargeStartTime = battRTDataHisService.getChargeStartTime(battGroupId, dischargeEndTime.getTime()); |
| | | //充满后蓄电池的电压 |
| | | Calendar chargeCalendar = Calendar.getInstance(); |
| | | chargeCalendar.setTime(chargeStartTime); |
| | | List<BattRealTimeDataHistory> fcVolListAfter = battRTDataHisService.getFcVolListAfter(battGroupId, chargeCalendar.getTime()); |
| | | fcVolListAfter.sort(Comparator.comparingInt(BattRealTimeDataHistory::getMonNum)); |
| | | addStatistics(fcVolListAfter,"vol","tmp"); |
| | | List<BattRealTimeDataHistory> fcVolListAfter = new ArrayList<>(); |
| | | List<BattRealTimeDataHistory> fcVolListAfterOriginal = battRTDataHisService.getFcVolListAfter(battGroupId, chargeCalendar.getTime()); |
| | | fcVolListAfterOriginal.sort(Comparator.comparingInt(BattRealTimeDataHistory::getMonNum)); |
| | | addStatistics(fcVolListAfterOriginal,"vol","tmp"); |
| | | //总电流总电压列入 |
| | | if(fcVolListAfterOriginal.size()>0) { |
| | | Float groupVolAfter = fcVolListAfterOriginal.get(0).getGroupVol(); |
| | | Float groupCurrAfter = fcVolListAfterOriginal.get(0).getGroupCurr(); |
| | | |
| | | //一共104节单体,再加上统计数据4列,一共108 |
| | | for(int j = 0; j < 108; j++){ |
| | | BattRealTimeDataHistory groupVolDataAfter = new BattRealTimeDataHistory(); |
| | | groupVolDataAfter.setMonNum(-2); |
| | | groupVolDataAfter.setGroupVol(groupVolAfter); |
| | | |
| | | BattRealTimeDataHistory groupCurrDataAfter = new BattRealTimeDataHistory(); |
| | | groupCurrDataAfter.setMonNum(-1); |
| | | groupCurrDataAfter.setGroupCurr(groupCurrAfter); |
| | | |
| | | fcVolListAfter.add(groupVolDataAfter); |
| | | fcVolListAfter.add(groupCurrDataAfter); |
| | | fcVolListAfter.addAll(fcVolListAfterOriginal); |
| | | } |
| | | |
| | | //一共104节单体,再加上前面总电压和总电流2列,后面统计数据4列,一共110 |
| | | for(int j = 0; j < 110; j++){ |
| | | XSSFRow rowTemp = sheet.createRow(rowIndex++); |
| | | if(j<104) { |
| | | rowTemp.createCell(0).setCellValue((j + 1) + "#"); |
| | | if(j == 0){ |
| | | rowTemp.createCell(0).setCellValue("总电压"); |
| | | }else if(j == 1){ |
| | | rowTemp.createCell(0).setCellValue("总电流"); |
| | | } |
| | | else if(j<106) { |
| | | rowTemp.createCell(0).setCellValue((j - 1) + "#"); |
| | | }else{ |
| | | if(j == 104){ |
| | | if(j == 106){ |
| | | rowTemp.createCell(0).setCellValue("单节平均电压"); |
| | | }else if (j == 105){ |
| | | }else if (j == 107){ |
| | | rowTemp.createCell(0).setCellValue("单节最大电压"); |
| | | }else if (j == 106){ |
| | | }else if (j == 108){ |
| | | rowTemp.createCell(0).setCellValue("单节最小电压"); |
| | | }else{ |
| | | rowTemp.createCell(0).setCellValue("单节最大差值"); |
| | |
| | | //rowTemp.createCell(2).setCellValue("蓄电池浮充温度值:"+(j+1)+"#"); |
| | | //rowTemp.createCell(3).setCellValue("放电前蓄电池开路电压值(V):"+(j+1)+"#"); |
| | | //rowTemp.createCell(4).setCellValue("放电前蓄电池开路温度值:"+(j+1)+"#"); |
| | | rowTemp.createCell(1).setCellValue(fcVolList.get(j).getMonVol()); |
| | | |
| | | rowTemp.createCell(2).setCellValue(preVolList.get(j).getMonVol()); |
| | | rowTemp.createCell(3).setCellValue(preVolList.get(j).getMonTmp()); |
| | | if(j == 0){ |
| | | rowTemp.createCell(1).setCellValue(fcVolList.get(j).getGroupVol()); |
| | | rowTemp.createCell(3).setCellValue(preVolList.get(j).getGroupVol()); |
| | | }else if (j == 1){ |
| | | rowTemp.createCell(1).setCellValue(fcVolList.get(j).getGroupCurr()); |
| | | rowTemp.createCell(3).setCellValue(preVolList.get(j).getGroupCurr()); |
| | | }else { |
| | | rowTemp.createCell(1).setCellValue(fcVolList.get(j).getMonVol()); |
| | | rowTemp.createCell(2).setCellValue(fcVolList.get(j).getMonTmp()); |
| | | rowTemp.createCell(3).setCellValue(preVolList.get(j).getMonVol()); |
| | | rowTemp.createCell(4).setCellValue(preVolList.get(j).getMonTmp()); |
| | | } |
| | | |
| | | |
| | | //放电特定电压值 |
| | | int columnIndexTemp = 3; |
| | | int columnIndexTemp = 5; |
| | | Calendar dischargeCalendar = Calendar.getInstance(); |
| | | dischargeCalendar.setTime(dischargeStartTime); |
| | | if(dischargeColumnCount > 0){ |
| | | //时间在测试开始时间+0.5h |
| | | dischargeCalendar.add(Calendar.MINUTE,30); |
| | | Date recordTime = dischargeCalendar.getTime(); |
| | | List<BattRealTimeDataHistory> dischargeListOne = battRTDataHisService.getRecordList(battGroupId,recordTime); |
| | | List<BattRealTimeDataHistory> dischargeListOne = new ArrayList<>(); |
| | | List<BattRealTimeDataHistory> dischargeListOneOriginal = battRTDataHisService.getRecordList(battGroupId,recordTime); |
| | | //按单体编号排序,按编号升序 |
| | | dischargeListOne.sort(Comparator.comparingInt(BattRealTimeDataHistory::getMonNum)); |
| | | addStatistics(dischargeListOne,"vol"); |
| | | dischargeListOneOriginal.sort(Comparator.comparingInt(BattRealTimeDataHistory::getMonNum)); |
| | | addStatistics(dischargeListOneOriginal,"vol"); |
| | | //总电流总电压列入 |
| | | Float groupVolDisOne = dischargeListOneOriginal.get(0).getGroupVol(); |
| | | Float groupCurrDisOne = dischargeListOneOriginal.get(0).getGroupCurr(); |
| | | |
| | | BattRealTimeDataHistory groupVolDataDisOne = new BattRealTimeDataHistory(); |
| | | groupVolDataDisOne.setMonNum(-2); |
| | | groupVolDataDisOne.setGroupVol(groupVolDisOne); |
| | | |
| | | BattRealTimeDataHistory groupCurrDataDisOne = new BattRealTimeDataHistory(); |
| | | groupCurrDataDisOne.setMonNum(-1); |
| | | groupCurrDataDisOne.setGroupCurr(groupCurrDisOne); |
| | | |
| | | dischargeListOne.add(groupVolDataDisOne); |
| | | dischargeListOne.add(groupCurrDataDisOne); |
| | | dischargeListOne.addAll(dischargeListOneOriginal); |
| | | |
| | | //rowTemp.createCell(5).setCellValue("放电0.5h电压值(V):"+(j+1)+"#"); |
| | | //rowTemp.createCell(6).setCellValue("放电0.5h温度值:"+(j+1)+"#"); |
| | | rowTemp.createCell(4).setCellValue(dischargeListOne.get(j).getMonVol()); |
| | | rowTemp.createCell(5).setCellValue(dischargeListOne.get(j).getMonTmp()); |
| | | if(j==0){ |
| | | //rowTemp.createCell(5).setCellValue(dischargeListOne.get(j).getGroupVol()); |
| | | rowTemp.createCell(columnIndexTemp).setCellValue(dischargeListOne.get(j).getGroupVol()); |
| | | }else if (j==1){ |
| | | rowTemp.createCell(columnIndexTemp).setCellValue(dischargeListOne.get(j).getGroupCurr()); |
| | | }else { |
| | | rowTemp.createCell(columnIndexTemp).setCellValue(dischargeListOne.get(j).getMonVol()); |
| | | rowTemp.createCell(columnIndexTemp+1).setCellValue(dischargeListOne.get(j).getMonTmp()); |
| | | } |
| | | columnIndexTemp+=2; |
| | | if(dischargeColumnCount > 2){ //合并单元格了,所以索引+2 |
| | | //时间在测试开始时间+1h |
| | | dischargeCalendar.setTime(dischargeStartTime); |
| | | dischargeCalendar.add(Calendar.HOUR,1); |
| | | Date recordTimeTwo = dischargeCalendar.getTime(); |
| | | List<BattRealTimeDataHistory> dischargeListTwo = battRTDataHisService.getRecordList(battGroupId,recordTimeTwo); |
| | | dischargeListTwo.sort(Comparator.comparingInt(BattRealTimeDataHistory::getMonNum)); |
| | | addStatistics(dischargeListTwo,"vol"); |
| | | List<BattRealTimeDataHistory> dischargeListTwo = new ArrayList<>(); |
| | | List<BattRealTimeDataHistory> dischargeListTwoOriginal = battRTDataHisService.getRecordList(battGroupId,recordTimeTwo); |
| | | dischargeListTwoOriginal.sort(Comparator.comparingInt(BattRealTimeDataHistory::getMonNum)); |
| | | addStatistics(dischargeListTwoOriginal,"vol"); |
| | | //总电流总电压列入 |
| | | Float groupVolDisTwo = dischargeListTwoOriginal.get(0).getGroupVol(); |
| | | Float groupCurrDisTwo = dischargeListTwoOriginal.get(0).getGroupCurr(); |
| | | |
| | | BattRealTimeDataHistory groupVolDataDisTwo = new BattRealTimeDataHistory(); |
| | | groupVolDataDisTwo.setMonNum(-2); |
| | | groupVolDataDisTwo.setGroupVol(groupVolDisTwo); |
| | | |
| | | BattRealTimeDataHistory groupCurrDataDisTwo = new BattRealTimeDataHistory(); |
| | | groupCurrDataDisTwo.setMonNum(-1); |
| | | groupCurrDataDisTwo.setGroupCurr(groupCurrDisTwo); |
| | | |
| | | dischargeListTwo.add(groupVolDataDisTwo); |
| | | dischargeListTwo.add(groupCurrDataDisTwo); |
| | | dischargeListTwo.addAll(dischargeListTwoOriginal); |
| | | |
| | | //rowTemp.createCell(7).setCellValue("放电1h电压值(V):"+(j+1)+"#"); |
| | | //rowTemp.createCell(8).setCellValue("放电1h温度值:"+(j+1)+"#"); |
| | | rowTemp.createCell(6).setCellValue(dischargeListTwo.get(j).getMonVol()); |
| | | rowTemp.createCell(7).setCellValue(dischargeListTwo.get(j).getMonTmp()); |
| | | if (j==0) { |
| | | rowTemp.createCell(columnIndexTemp).setCellValue(dischargeListTwo.get(j).getGroupVol()); |
| | | }else if (j==1){ |
| | | rowTemp.createCell(columnIndexTemp).setCellValue(dischargeListTwo.get(j).getGroupCurr()); |
| | | }else { |
| | | rowTemp.createCell(columnIndexTemp).setCellValue(dischargeListTwo.get(j).getMonVol()); |
| | | rowTemp.createCell(columnIndexTemp+1).setCellValue(dischargeListTwo.get(j).getMonTmp()); |
| | | } |
| | | columnIndexTemp+=2; |
| | | if(dischargeColumnCount > 4){ |
| | | columnIndexTemp++; |
| | | //放电nh蓄电池电压值(V),n从2开始 |
| | | for(int i = 4;i < dischargeColumnCount;i++){ |
| | | int dischargeHour = i-2; |
| | |
| | | dischargeCalendar.setTime(dischargeStartTime); |
| | | dischargeCalendar.add(Calendar.HOUR,dischargeHour); |
| | | Date recordTimeN = dischargeCalendar.getTime(); |
| | | List<BattRealTimeDataHistory> dischargeListN = battRTDataHisService.getRecordList(battGroupId,recordTimeN); |
| | | dischargeListN.sort(Comparator.comparingInt(BattRealTimeDataHistory::getMonNum)); |
| | | addStatistics(dischargeListN,"vol"); |
| | | List<BattRealTimeDataHistory> dischargeListN = new ArrayList<>(); |
| | | List<BattRealTimeDataHistory> dischargeListNOriginal = battRTDataHisService.getRecordList(battGroupId,recordTimeN); |
| | | dischargeListNOriginal.sort(Comparator.comparingInt(BattRealTimeDataHistory::getMonNum)); |
| | | addStatistics(dischargeListNOriginal,"vol"); |
| | | //总电流总电压列入 |
| | | Float groupVolDisN = dischargeListNOriginal.get(0).getGroupVol(); |
| | | Float groupCurrDisN = dischargeListNOriginal.get(0).getGroupCurr(); |
| | | |
| | | BattRealTimeDataHistory groupVolDataDisN = new BattRealTimeDataHistory(); |
| | | groupVolDataDisN.setMonNum(-2); |
| | | groupVolDataDisN.setGroupVol(groupVolDisN); |
| | | |
| | | BattRealTimeDataHistory groupCurrDataDisN = new BattRealTimeDataHistory(); |
| | | groupCurrDataDisN.setMonNum(-1); |
| | | groupCurrDataDisN.setGroupCurr(groupCurrDisN); |
| | | |
| | | dischargeListN.add(groupVolDataDisN); |
| | | dischargeListN.add(groupCurrDataDisN); |
| | | dischargeListN.addAll(dischargeListNOriginal); |
| | | //rowTemp.createCell(i+5).setCellValue("放电" + dischargeHour + "h蓄电池电压值(V)"); |
| | | rowTemp.createCell(i+5).setCellValue(dischargeListN.get(j).getMonVol()); |
| | | if(j==0){ |
| | | rowTemp.createCell(columnIndexTemp).setCellValue(dischargeListN.get(j).getGroupVol()); |
| | | }else if (j==1){ |
| | | rowTemp.createCell(columnIndexTemp).setCellValue(dischargeListN.get(j).getGroupCurr()); |
| | | }else { |
| | | rowTemp.createCell(columnIndexTemp).setCellValue(dischargeListN.get(j).getMonVol()); |
| | | } |
| | | columnIndexTemp++; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | //填充放电0.5h后开路电压值 |
| | | rowTemp.createCell(++columnIndexTemp).setCellValue(dischargeSetVolListOne.get(j).getMonVol()); |
| | | |
| | | if(j == 0){ |
| | | rowTemp.createCell(columnIndexTemp).setCellValue(dischargeSetVolListOne.get(j).getGroupVol()); |
| | | }else if(j == 1){ |
| | | rowTemp.createCell(columnIndexTemp).setCellValue(dischargeSetVolListOne.get(j).getGroupCurr()); |
| | | }else { |
| | | rowTemp.createCell(columnIndexTemp).setCellValue(dischargeSetVolListOne.get(j).getMonVol()); |
| | | } |
| | | columnIndexTemp++; |
| | | |
| | | if(chargeColumnCount > 0){ |
| | | chargeCalendar = Calendar.getInstance(); |
| | | chargeCalendar.setTime(chargeStartTime); |
| | | chargeCalendar.add(Calendar.MINUTE,30); |
| | | List<BattRealTimeDataHistory> chargeVolListOne = battRTDataHisService.getRecordList(battGroupId, chargeCalendar.getTime()); |
| | | chargeVolListOne.sort(Comparator.comparingInt(BattRealTimeDataHistory::getMonNum)); |
| | | addStatistics(chargeVolListOne,"vol"); |
| | | columnIndexTemp++; |
| | | List<BattRealTimeDataHistory> chargeVolListOne = new ArrayList<>(); |
| | | List<BattRealTimeDataHistory> chargeVolListOneOriginal = battRTDataHisService.getRecordList(battGroupId, chargeCalendar.getTime()); |
| | | chargeVolListOneOriginal.sort(Comparator.comparingInt(BattRealTimeDataHistory::getMonNum)); |
| | | addStatistics(chargeVolListOneOriginal,"vol"); |
| | | //总电流总电压列入 |
| | | Float groupVolChargeOne = chargeVolListOneOriginal.get(0).getGroupVol(); |
| | | Float groupCurrChargeOne = chargeVolListOneOriginal.get(0).getGroupCurr(); |
| | | |
| | | BattRealTimeDataHistory groupVolDataChargeOne = new BattRealTimeDataHistory(); |
| | | groupVolDataChargeOne.setMonNum(-2); |
| | | groupVolDataChargeOne.setGroupVol(groupVolChargeOne); |
| | | |
| | | BattRealTimeDataHistory groupCurrDataChargeOne = new BattRealTimeDataHistory(); |
| | | groupCurrDataChargeOne.setMonNum(-1); |
| | | groupCurrDataChargeOne.setGroupCurr(groupCurrChargeOne); |
| | | |
| | | chargeVolListOne.add(groupVolDataChargeOne); |
| | | chargeVolListOne.add(groupCurrDataChargeOne); |
| | | chargeVolListOne.addAll(chargeVolListOneOriginal); |
| | | //rowTemp.createCell(columnIndexTemp).setCellValue("充电0.5h"); |
| | | rowTemp.createCell(columnIndexTemp).setCellValue(chargeVolListOne.get(j).getMonVol()); |
| | | columnIndexTemp++; |
| | | |
| | | if(chargeColumnCount > 1){ |
| | | //充电nh,n从1开始 |
| | | for(int i = 1;i < chargeColumnCount;i++){ |
| | | columnIndexTemp++; |
| | | |
| | | chargeCalendar.setTime(chargeStartTime); |
| | | chargeCalendar.add(Calendar.HOUR,i); |
| | | List<BattRealTimeDataHistory> chargeVolListN = battRTDataHisService.getRecordList(battGroupId, chargeCalendar.getTime()); |
| | | chargeVolListN.sort(Comparator.comparingInt(BattRealTimeDataHistory::getMonNum)); |
| | | addStatistics(chargeVolListN,"vol"); |
| | | List<BattRealTimeDataHistory> chargeVolListN = new ArrayList<>(); |
| | | List<BattRealTimeDataHistory> chargeVolListNOriginal = battRTDataHisService.getRecordList(battGroupId, chargeCalendar.getTime()); |
| | | chargeVolListNOriginal.sort(Comparator.comparingInt(BattRealTimeDataHistory::getMonNum)); |
| | | addStatistics(chargeVolListNOriginal,"vol"); |
| | | //总电流总电压列入 |
| | | Float groupVolChargeN = chargeVolListNOriginal.get(0).getGroupVol(); |
| | | Float groupCurrChargeN = chargeVolListNOriginal.get(0).getGroupCurr(); |
| | | |
| | | BattRealTimeDataHistory groupVolDataChargeN = new BattRealTimeDataHistory(); |
| | | groupVolDataChargeN.setMonNum(-2); |
| | | groupVolDataChargeN.setGroupVol(groupVolChargeN); |
| | | |
| | | BattRealTimeDataHistory groupCurrDataChargeN = new BattRealTimeDataHistory(); |
| | | groupCurrDataChargeN.setMonNum(-1); |
| | | groupCurrDataChargeN.setGroupCurr(groupCurrChargeN); |
| | | |
| | | chargeVolListN.add(groupVolDataChargeN); |
| | | chargeVolListN.add(groupCurrDataChargeN); |
| | | chargeVolListN.addAll(chargeVolListNOriginal); |
| | | //rowTemp.createCell(columnIndexTemp).setCellValue("充电" + (i) + "h蓄电池电压值(V)"); |
| | | rowTemp.createCell(columnIndexTemp).setCellValue(chargeVolListN.get(j).getMonVol()); |
| | | columnIndexTemp++; |
| | | } |
| | | |
| | | } |
| | |
| | | //填充充满后蓄电池电压 |
| | | //rowTemp.createCell(++columnIndexTemp).setCellValue("充满后蓄电池电压值(V)(电流为0)"); |
| | | if (fcVolListAfter.size() > 0){ |
| | | rowTemp.createCell(++columnIndexTemp).setCellValue(fcVolListAfter.get(j).getMonVol()); |
| | | if(j == 0){ |
| | | rowTemp.createCell(columnIndexTemp).setCellValue(fcVolListAfter.get(j).getGroupVol()); |
| | | }else if(j == 1){ |
| | | rowTemp.createCell(columnIndexTemp).setCellValue(fcVolListAfter.get(j).getGroupCurr()); |
| | | }else { |
| | | rowTemp.createCell(columnIndexTemp).setCellValue(fcVolListAfter.get(j).getMonVol()); |
| | | } |
| | | }else { |
| | | rowTemp.createCell(++columnIndexTemp).setCellValue("-"); |
| | | rowTemp.createCell(columnIndexTemp).setCellValue("-"); |
| | | } |
| | | rowTemp.createCell(++columnIndexTemp).setCellValue("-"); |
| | | columnIndexTemp++; |
| | | rowTemp.createCell(columnIndexTemp); |
| | | } |
| | | |
| | | //设置前6行所有的表格创建,避免出现无边框 |
| | | for (int i = 0; i < 6; i++) { |
| | | XSSFRow rowTmp = sheet.getRow(i); |
| | | for (int j = 0; j < columnCount; j++) { |
| | | if(rowTmp.getCell(j) == null){ |
| | | rowTmp.createCell(j); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //=====================格式设置=====================// |
| | |
| | | addGlobalStylesToAllCells(sheet, workbook); |
| | | |
| | | //创建第一行是标题行 |
| | | setRowStyle(workbook,sheet.getRow(0),true,15); |
| | | setRowStyle(workbook,sheet.getRow(0),true,20); |
| | | //第二行设置加粗 |
| | | setRowStyle(workbook,sheet.getRow(1),true,15); |
| | | |
| | | setRowStyle(workbook,sheet.getRow(1),true,11,HorizontalAlignment.LEFT); |
| | | //第四行设置字体颜色 |
| | | setRowStyle(workbook,sheet.getRow(3),false,9,IndexedColors.GREY_40_PERCENT.getIndex()); |
| | | //第5行到最后一行,设置数值的小数点为4位 |
| | | setDateFormat(workbook,sheet,4,113,1,columnCount-1,"0.0000"); |
| | | //生成图表 |
| | | createChart(sheet, columnCount, 6,""); |
| | | |
| | | return battInfo; |
| | | } |
| | | |
| | | private void setDateFormat(Workbook workbook,XSSFSheet sheet, int rowIndexStart, int rowIndexEnd,int columnIndexStart,int columnIndexEnd, String formatStr) { |
| | | CellStyle decimalStyle = workbook.createCellStyle(); |
| | | DataFormat format = workbook.createDataFormat(); |
| | | decimalStyle.setDataFormat(format.getFormat(formatStr)); |
| | | for (int i = rowIndexStart; i <= rowIndexEnd; i++) { |
| | | XSSFRow row = sheet.getRow(i); |
| | | for (int j = columnIndexStart; j <= columnIndexEnd; j++) { |
| | | XSSFCell cell = row.getCell(j); |
| | | if(cell.getCellType() == CellType.NUMERIC) { |
| | | cell.getCellStyle().setDataFormat(format.getFormat(formatStr)); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | private XSSFCellStyle getCellStyleFont(XSSFCellStyle cellStyleOriginal, XSSFWorkbook workbook, boolean isFontBold, int fontSize) { |
| | |
| | | //设置字体和加粗 |
| | | Font font = workbook.createFont(); |
| | | font.setFontHeightInPoints((short) (fontSize)); |
| | | font.setFontName("宋体"); |
| | | font.setBold(isFontBold); |
| | | |
| | | cellStyleNew.setFont(font); |
| | |
| | | } |
| | | } |
| | | |
| | | public void setRowStyle(Workbook workbook,Row row,boolean isFontBold,int fontSize,HorizontalAlignment horizontalAlignment) { |
| | | for (Cell cell : row) { |
| | | //先克隆原来的属性 |
| | | CellStyle cellStyleNew = workbook.createCellStyle(); |
| | | cellStyleNew.cloneStyleFrom(cell.getCellStyle()); |
| | | |
| | | //设置字体和加粗 |
| | | Font font = workbook.createFont(); |
| | | font.setFontHeightInPoints((short) (fontSize)); |
| | | font.setBold(isFontBold); |
| | | font.setFontName("宋体"); |
| | | |
| | | //设置水平对齐方式 |
| | | cellStyleNew.setAlignment(horizontalAlignment); |
| | | |
| | | cellStyleNew.setFont(font); |
| | | cell.setCellStyle(cellStyleNew); |
| | | } |
| | | } |
| | | |
| | | public void setRowStyle(Workbook workbook,Row row,boolean isFontBold,int fontSize,short color) { |
| | | for (Cell cell : row) { |
| | | //跳过第一列 |
| | | if(cell.getColumnIndex() == 0) { |
| | | continue; |
| | | } |
| | | //先克隆原来的属性 |
| | | CellStyle cellStyleNew = workbook.createCellStyle(); |
| | | cellStyleNew.cloneStyleFrom(cell.getCellStyle()); |
| | | |
| | | //设置字体和加粗 |
| | | Font font = workbook.createFont(); |
| | | font.setFontHeightInPoints((short) (fontSize)); |
| | | font.setBold(isFontBold); |
| | | font.setFontName("宋体"); |
| | | font.setColor(color); |
| | | |
| | | cellStyleNew.setFont(font); |
| | | cell.setCellStyle(cellStyleNew); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 这个方法最后执行,用于对已被创建的行内的所有单元格添加边框.能自动识别被创建的所有列和所有单元格 |
| | | * 设置全局的属性.这个方法在所有单元格创建后调用 |
| | | * 用于对已被创建的行内的所有单元格添加边框.能自动识别被创建的所有列和所有单元格 |
| | | * @param sheet |
| | | * @param workbook |
| | | */ |
| | |
| | | borderedStyle.setBorderBottom(BorderStyle.THIN); |
| | | borderedStyle.setBorderLeft(BorderStyle.THIN); |
| | | borderedStyle.setBorderRight(BorderStyle.THIN); |
| | | |
| | | Font font = workbook.createFont(); |
| | | //默认字体大小为9,宋体 |
| | | font.setFontHeightInPoints((short) 9); |
| | | font.setFontName("宋体"); |
| | | borderedStyle.setFont(font); |
| | | //默认横竖居中 |
| | | borderedStyle.setAlignment(HorizontalAlignment.CENTER); |
| | | borderedStyle.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | //默认自动换行 |
| | | borderedStyle.setWrapText(true); |
| | | for (Row row : sheet) { |
| | | for (Cell cell : row) { |
| | | cell.setCellStyle(borderedStyle); |