| | |
| | | package com.whyc.service; |
| | | |
| | | import com.whyc.charge.Fbs5100DisChargeData; |
| | | import com.whyc.charge.Fbs5100FbsData; |
| | | import com.whyc.charge.*; |
| | | import com.whyc.dto.ServletUtils; |
| | | import org.apache.poi.ss.usermodel.ClientAnchor; |
| | | import org.apache.poi.xssf.usermodel.*; |
| | |
| | | |
| | | @Service |
| | | public class ExcelExportService { |
| | | /* @Autowired |
| | | @Autowired |
| | | private Fbs5100DisChargeDataService disChargeDataService; |
| | | |
| | | @Autowired |
| | |
| | | private Fbs5100AlarmDataService alarmDataService; |
| | | |
| | | //导出放电数据bcp |
| | | public void exportBcp(HttpServletRequest req, HttpServletResponse resp){ |
| | | public void exportBcp(HttpServletRequest req, HttpServletResponse resp) { |
| | | |
| | | String curr_echart = req.getParameter("curr_echart"); //电池电流折线图 |
| | | String groupVol_echart = req.getParameter("groupVol_echart"); //组端电压折线图 |
| | | String cap_echart = req.getParameter("cap_echart"); //测试容量折线图 |
| | | //String actualCap_echart = req.getParameter("actualCap_echart"); //实际容量折线图 |
| | | String vol_echart = req.getParameter("vol_echart"); //单体电压折线图 |
| | | String tempEnvi_echart = req.getParameter("tempEnvi_echart");//环境温度折线图 |
| | | String humiEnvi_echart = req.getParameter("humiEnvi_echart");//环境湿度折线图 |
| | | |
| | | String curr_echart = req.getParameter("curr_echart"); //电池电流折线图 |
| | | String groupVol_echart = req.getParameter("groupVol_echart");//组端电压折线图 |
| | | String cap_echart = req.getParameter("cap_echart"); //测试容量折线图 |
| | | String temp_echart = req.getParameter("temp_echart");//温度折线图 |
| | | |
| | | String filePath = req.getParameter("filePath"); |
| | | Fbs5100DisChargeData data=disChargeDataService.readFboFile(filePath); |
| | | //从文件中获取数据 |
| | | List<Fbs5100FbsData> list = data.fbsDatas; |
| | | Fbs5100DisChargeData data = disChargeDataService.readFboFile(filePath); |
| | | //图片base64后的数据 |
| | | List<byte[]> bytes = new ArrayList<>(); |
| | | try { |
| | |
| | | String[] url = cap_echart.split(","); |
| | | bytes.add(new BASE64Decoder().decodeBuffer(url[1])); |
| | | } |
| | | if (ServletUtils.isNotNull(vol_echart)) { |
| | | String[] url = vol_echart.split(","); |
| | | if (ServletUtils.isNotNull(temp_echart)) { |
| | | String[] url = temp_echart.split(","); |
| | | bytes.add(new BASE64Decoder().decodeBuffer(url[1])); |
| | | } |
| | | if (ServletUtils.isNotNull(tempEnvi_echart)) { |
| | | String[] url = tempEnvi_echart.split(","); |
| | | bytes.add(new BASE64Decoder().decodeBuffer(url[1])); |
| | | } |
| | | if (ServletUtils.isNotNull(humiEnvi_echart)) { |
| | | String[] url = humiEnvi_echart.split(","); |
| | | bytes.add(new BASE64Decoder().decodeBuffer(url[1])); |
| | | } |
| | | }catch (Exception e){ |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | //当前日期 |
| | | String nowFormat = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); |
| | | String excelName = "FBX-"+nowFormat; |
| | | String excelName = "bcp-" + nowFormat; |
| | | |
| | | XSSFWorkbook wb = new XSSFWorkbook(); |
| | | XSSFSheet sheet = wb.createSheet("数据总表"); |
| | | |
| | | XSSFDrawing patriarch = sheet.createDrawingPatriarch(); |
| | | int rowNumSheet = 0; |
| | | FboDataHeadStart start = fboDataInf.fboDataStart; |
| | | FboDataHeadStop stop = fboDataInf.fboDataStop; |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("电池组名称:"+start.battNameStr); |
| | | sheet.getRow(rowNumSheet).createCell(1).setCellValue("电池品牌:"+start.battBrandStr); |
| | | rowNumSheet++; |
| | | sheet.createRow(rowNumSheet); |
| | | //从文件中获取数据 |
| | | List<Fbs5100FbsData> list = data.fbsDatas; |
| | | Fbs5100BattParam battParam = data.battParam; |
| | | Fbs5100TestParam testParam = data.testParam; |
| | | Fbs5100CapState capState = data.capState; |
| | | |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("安装日期:"+start.batt_date_str); |
| | | sheet.getRow(rowNumSheet).createCell(1).setCellValue("单体数量:"+start.batt_mon_num); |
| | | sheet.getRow(rowNumSheet).createCell(2).setCellValue("标称容量:"+start.batt_std_cap+"AH"); |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("电池组数:" + battParam.BattGroupCount); |
| | | sheet.getRow(rowNumSheet).createCell(1).setCellValue("每组单体数:" + battParam.EachGroupBattCount); |
| | | sheet.getRow(rowNumSheet).createCell(2).setCellValue("标称单体电压:" + battParam.MonomerVol + "V"); |
| | | |
| | | rowNumSheet++; |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("测试开始时间:"+formartDate(start.testStartTime,"yyyy-MM-dd HH:mm:ss")); |
| | | sheet.getRow(rowNumSheet).createCell(1).setCellValue("测试时长:"+stop.TestTimeLong.hms()); |
| | | sheet.getRow(rowNumSheet).createCell(2).setCellValue("单体电压:"+start.batt_mon_vol+"V"); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("浮充电流阈值:" + battParam.FloatChargeVol + "A"); |
| | | sheet.getRow(rowNumSheet).createCell(1).setCellValue("在线电压低阈值:" + battParam.OnlineVolLow + "A"); |
| | | sheet.getRow(rowNumSheet).createCell(2).setCellValue("均充电压:" + battParam.JunChargeVol + "A"); |
| | | |
| | | rowNumSheet++; |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("正极绝缘电阻:"+list.get(list.size()-1).PosInsRes+"kΩ"); |
| | | sheet.getRow(rowNumSheet).createCell(1).setCellValue("负极绝缘电阻:"+list.get(list.size()-1).NegInsRes+"kΩ"); |
| | | sheet.getRow(rowNumSheet).createCell(2).setCellValue("标称内阻:"+start.batt_std_res+"mΩ"); |
| | | if(start.DataType==0xFD){ |
| | | rowNumSheet++; |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("预估实际容量:"+list.get(list.size()-1).actualCap+"AH"); |
| | | } |
| | | rowNumSheet+=4; |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("测试开始时间:" + formartDate(capState.StartDT.time,"yyyy-MM-dd HH:mm:ss")); |
| | | sheet.getRow(rowNumSheet).createCell(1).setCellValue("测试时长:" + capState.Test_Time.hour+":"+capState.Test_Time.minute+":"+capState.Test_Time.second); |
| | | |
| | | |
| | | rowNumSheet += 4; |
| | | //插入图片 |
| | | int picNum = 0; |
| | | String[] picName = getPicName(start.DataType); |
| | | if (picName.length==bytes.size()){ |
| | | for(int i=0;i<picName.length;i++){ |
| | | sheet.createRow(rowNumSheet-1); |
| | | sheet.getRow(rowNumSheet-1).createCell(0).setCellValue(picName[i]); |
| | | String[] picName = getPicName("bcp"); |
| | | if (picName.length == bytes.size()) { |
| | | for (int i = 0; i < picName.length; i++) { |
| | | sheet.createRow(rowNumSheet - 1); |
| | | sheet.getRow(rowNumSheet - 1).createCell(0).setCellValue(picName[i]); |
| | | //rowNum++; |
| | | XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 512, 255,(short) 0, rowNumSheet, (short) 10, rowNumSheet+27); |
| | | XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 512, 255, (short) 0, rowNumSheet, (short) 10, rowNumSheet + 27); |
| | | anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE); |
| | | patriarch.createPicture(anchor,wb.addPicture(bytes.get(picNum),XSSFWorkbook.PICTURE_TYPE_PNG)).resize(1); |
| | | picNum ++; |
| | | rowNumSheet+=27; |
| | | patriarch.createPicture(anchor, wb.addPicture(bytes.get(picNum), XSSFWorkbook.PICTURE_TYPE_PNG)).resize(1); |
| | | picNum++; |
| | | rowNumSheet += 27; |
| | | } |
| | | } |
| | | |
| | |
| | | sheet1.createRow(rowNum).createCell(0).setCellValue("测试数据"); |
| | | rowNum++; |
| | | //属性栏 |
| | | String[] rowName = getRowName(start.DataType); |
| | | String[] rowName = getRowName("bcp"); |
| | | XSSFRow row = sheet1.createRow(rowNum); |
| | | for (int i=0;i<rowName.length;i++){ |
| | | for (int i = 0; i < rowName.length; i++) { |
| | | row.createCell(i).setCellValue(rowName[i]); |
| | | } |
| | | for(int i=0;i<list.get(0).SingleVol.length;i++){ |
| | | row.createCell(rowName.length+i).setCellValue("#"+Integer.valueOf(i+1)); |
| | | for (int i = 0; i < battParam.BattGroupCount; i++) { |
| | | row.createCell(rowName.length + i*2).setCellValue("#" + Integer.valueOf(i + 1)+"在线电压"); |
| | | row.createCell(rowName.length + i*2+1).setCellValue("#" + Integer.valueOf(i + 1)+"组端电压"); |
| | | } |
| | | rowNum++; |
| | | //数据栏 |
| | | for (int i = 0; i < list.size(); i++) { |
| | | sheet1.createRow(rowNum); //创建行 |
| | | FboData fbo=list.get(i); |
| | | sheet1.getRow(rowNum).createCell(0).setCellValue(fbo.m_TestTime.hms()); |
| | | sheet1.getRow(rowNum).createCell(1).setCellValue(fbo.SumVoltage); |
| | | sheet1.getRow(rowNum).createCell(2).setCellValue(fbo.SumCurrent); |
| | | sheet1.getRow(rowNum).createCell(3).setCellValue(fbo.Temp_Envi); |
| | | sheet1.getRow(rowNum).createCell(4).setCellValue(fbo.Humi_Envi); |
| | | if (start.DataType!=0xFB){ |
| | | sheet1.getRow(rowNum).createCell(5).setCellValue(fbo.testCap); |
| | | } |
| | | for (int k = 0;k<list.get(0).SingleVol.length;k++){ |
| | | sheet1.getRow(rowNum).createCell(rowName.length+k).setCellValue(fbo.SingleVol[k]); |
| | | Fbs5100FbsData fbsData = list.get(i); |
| | | sheet1.getRow(rowNum).createCell(0).setCellValue(fbsData.testTime.hour+":"+fbsData.testTime.minute+":"+fbsData.testTime.second); |
| | | sheet1.getRow(rowNum).createCell(1).setCellValue(String.valueOf(fbsData.muxianvol_discharge)); |
| | | sheet1.getRow(rowNum).createCell(2).setCellValue(String.valueOf(fbsData.muxianvol_charge)); |
| | | sheet1.getRow(rowNum).createCell(3).setCellValue(String.valueOf(fbsData.boostDCDC_OutVol)); |
| | | sheet1.getRow(rowNum).createCell(4).setCellValue(String.valueOf(fbsData.muxianvol)); |
| | | for (int j = 0; j < battParam.BattGroupCount; j++) { |
| | | sheet1.getRow(rowNum).createCell(rowName.length + j*2).setCellValue(String.valueOf(fbsData.onlinevol[j])); |
| | | sheet1.getRow(rowNum).createCell(rowName.length + j*2+1).setCellValue(String.valueOf(fbsData.groupvol[j])); |
| | | } |
| | | rowNum++; |
| | | } |
| | | |
| | | rowNum++; |
| | | |
| | | try { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | public String[] getRowName(int dateType){ |
| | | if (dateType==0xFB){ |
| | | String[] rowName = {"测试时间","总电压(V)","总电流(A)","环境温度","环境湿度"}; |
| | | return rowName; |
| | | //将日期格式转换成指定的字符串格式 |
| | | public static String formartDate(Date date, String str){ |
| | | return new SimpleDateFormat(str).format(date); |
| | | } |
| | | public String[] getRowName(String bcp){ |
| | | if (bcp.equals("bcp")){ |
| | | String[] rowNameBcp = {"测试时间","放电母线电压(V)","充电母线电压(V)","升压DCDC输出电压","48V母线电压"}; |
| | | return rowNameBcp; |
| | | }else if (bcp.equals("chr")){ |
| | | String[] rowNameChr = {"测试时间","放电母线电压(V)","充电母线电压(V)","升压DCDC输出电压","48V母线电压"}; |
| | | return rowNameChr; |
| | | }else if (bcp.equals("alm")){ |
| | | String[] rowNameAlm = {"测试时间","放电母线电压(V)","充电母线电压(V)","升压DCDC输出电压","48V母线电压"}; |
| | | return rowNameAlm; |
| | | }else{ |
| | | String[] rowName1 = {"测试时间","总电压(V)","总电流(A)","环境温度","环境湿度","测试容量(AH)"}; |
| | | return rowName1; |
| | | } |
| | | } |
| | | |
| | | public String[] getPicName(int dateType){ |
| | | if (dateType==0xFB){ |
| | | String[] picName1 = new String[]{ |
| | | "电池电流折线图","组端电压折线图","单体电压折线图","环境温度折线图","环境湿度折线图" |
| | | public String[] getPicName(String fileType){ |
| | | if (fileType.equals("bcp")){ |
| | | String[] picNameBcp = new String[]{ |
| | | "电池电流折线图","组端电压折线图","测试容量折线图","温度折线图" |
| | | }; |
| | | return picName1; |
| | | }else{ |
| | | String[] picName = new String[]{ |
| | | return picNameBcp; |
| | | }else if(fileType.equals("chr")){ |
| | | String[] picNameChr = new String[]{ |
| | | "电池电流折线图","组端电压折线图","测试容量折线图","单体电压折线图","环境温度折线图","环境湿度折线图" |
| | | }; |
| | | return picName; |
| | | return picNameChr; |
| | | }else if(fileType.equals("alm")){ |
| | | String[] picNameChr = new String[]{ |
| | | "电池电流折线图","组端电压折线图","测试容量折线图","单体电压折线图","环境温度折线图","环境湿度折线图" |
| | | }; |
| | | return picNameChr; |
| | | }else{ |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | //导出充电数据chr |
| | | public void exportChr(HttpServletRequest req, HttpServletResponse resp){ |
| | | /*public void exportChr(HttpServletRequest req, HttpServletResponse resp){ |
| | | String volEchart = req.getParameter("vol_echart"); //单体电压折线图 |
| | | String resEchart = req.getParameter("res_echart"); //单体内阻折线图 |
| | | String tmpEchart = req.getParameter("tmp_echart"); //单体温度折线图 |
| | |
| | | rowNum++; |
| | | } |
| | | |
| | | *//** |
| | | * 将日期格式转换成指定的字符串格式 |
| | | * @param date 日期 |
| | | * @param str 字符串的格式 |
| | | * @return |
| | | *//* |
| | | public static String formartDate(Date date, String str){ |
| | | return new SimpleDateFormat(str).format(date); |
| | | } |
| | | |
| | | |
| | | |
| | | |