| | |
| | | import com.whyc.fbo.FboDataHeadStart; |
| | | import com.whyc.fbo.FboDataHeadStop; |
| | | import com.whyc.fbo.FboDataInf; |
| | | import com.whyc.mcp.*; |
| | | import com.whyc.res.RESData; |
| | | import com.whyc.res.RESDataInfo; |
| | | import com.whyc.util.ServletUtils; |
| | |
| | | @Autowired |
| | | private RESDataInfoService resService; |
| | | |
| | | @Autowired |
| | | private TestDataInfoService testDataInfoService; |
| | | |
| | | //导出fbx |
| | | public void exportFbx(HttpServletRequest req, HttpServletResponse resp){ |
| | | |
| | |
| | | |
| | | String filePath = req.getParameter("filePath"); |
| | | FboDataInf fboDataInf=fboService.readFboFile(filePath); |
| | | // if (fboDataInf==null){ |
| | | // fboDataInf = new FboDataInf(); |
| | | // if (filePath==null || "".equals(filePath)){ |
| | | // filePath = fileUrl; |
| | | // } |
| | | // fboDataInf.readFboFile(filePath); |
| | | // } |
| | | //从文件中获取数据 |
| | | List<FboData> list = fboDataInf.fboData; |
| | | //图片base64后的数据 |
| | |
| | | String[] url = cap_echart.split(","); |
| | | bytes.add(new BASE64Decoder().decodeBuffer(url[1])); |
| | | } |
| | | //if (ServletUtils.isNotNull(actualCap_echart)) { |
| | | // String[] url = actualCap_echart.split(","); |
| | | // bytes.add(new BASE64Decoder().decodeBuffer(url[1])); |
| | | //} |
| | | if (ServletUtils.isNotNull(vol_echart)) { |
| | | String[] url = vol_echart.split(","); |
| | | bytes.add(new BASE64Decoder().decodeBuffer(url[1])); |
| | |
| | | //当前日期 |
| | | String nowFormat = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); |
| | | String excelName = "FBX-"+nowFormat; |
| | | //HSSFWorkbook wb = new HSSFWorkbook(); |
| | | //HSSFSheet sheet = wb.createSheet("数据总表"); |
| | | |
| | | XSSFWorkbook wb = new XSSFWorkbook(); |
| | | XSSFSheet sheet = wb.createSheet("数据总表"); |
| | | //图片元素 |
| | | //HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); |
| | | XSSFDrawing patriarch = sheet.createDrawingPatriarch(); |
| | | ////字体格式-加粗 |
| | | //HSSFCellStyle cellStyle = wb.createCellStyle(); |
| | | //HSSFFont font = wb.createFont(); |
| | | //font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); |
| | | //cellStyle.setFont(font); |
| | | |
| | | XSSFDrawing patriarch = sheet.createDrawingPatriarch(); |
| | | int rowNumSheet = 0; |
| | | FboDataHeadStart start = fboDataInf.fboDataStart; |
| | | FboDataHeadStop stop = fboDataInf.fboDataStop; |
| | |
| | | } |
| | | |
| | | XSSFSheet sheet1 = wb.createSheet("数据"); |
| | | //新建行 |
| | | |
| | | //抬头 |
| | | int rowNum = 0; |
| | | sheet1.createRow(rowNum).createCell(0).setCellValue("测试数据"); |
| | | rowNum++; |
| | | |
| | | |
| | | |
| | | |
| | | //属性栏 |
| | | String[] rowName = getRowName(start.DataType); |
| | | XSSFRow row = sheet1.createRow(rowNum); |
| | |
| | | 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; |
| | | rowNumSheet+=30; |
| | | } |
| | | } |
| | | //数据 |
| | |
| | | } |
| | | sheet1.getRow(rowNum).createCell(0).setCellValue(formartDate(resData.getData_Time(),"yyyy-MM-dd HH:mm:ss")); |
| | | for (int k = 0;k<battNum;k++){ |
| | | sheet1.getRow(rowNum).createCell(k+1).setCellValue(datas[i]); |
| | | sheet1.getRow(rowNum).createCell(k+1).setCellValue(datas[k]); |
| | | } |
| | | rowNum++; |
| | | } |
| | |
| | | return new SimpleDateFormat(str).format(date); |
| | | } |
| | | |
| | | |
| | | |
| | | //导出mch,mcp |
| | | public void exportMcph(HttpServletRequest req, HttpServletResponse resp){ |
| | | String volEchart = req.getParameter("vol_echart"); //单体电压折线图 |
| | | String currEchart = req.getParameter("curr_echart"); //电池电流折线图 |
| | | String groupVolEchart = req.getParameter("groupVol_echart"); //组端电压折线图 |
| | | String capEchart = req.getParameter("cap_echart"); //测试容量折线图 |
| | | String filePath = req.getParameter("filePath"); |
| | | //数据 |
| | | TestDataInfo testDataInfoMcp=testDataInfoService.readFileData(filePath); |
| | | MonitorDataInfo info = testDataInfoMcp.monitorDataInfo;//组端数据 |
| | | |
| | | //图片base64后的数据 |
| | | List<byte[]> bytes = new ArrayList<>(); |
| | | try { |
| | | if (ServletUtils.isNotNull(volEchart)) { |
| | | String[] url = volEchart.split(","); |
| | | bytes.add(new BASE64Decoder().decodeBuffer(url[1])); |
| | | } |
| | | if (ServletUtils.isNotNull(currEchart)) { |
| | | String[] url = currEchart.split(","); |
| | | bytes.add(new BASE64Decoder().decodeBuffer(url[1])); |
| | | } |
| | | if (ServletUtils.isNotNull(groupVolEchart)) { |
| | | String[] url = groupVolEchart.split(","); |
| | | bytes.add(new BASE64Decoder().decodeBuffer(url[1])); |
| | | } |
| | | if (ServletUtils.isNotNull(capEchart)) { |
| | | String[] url = capEchart.split(","); |
| | | bytes.add(new BASE64Decoder().decodeBuffer(url[1])); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | //当前日期 |
| | | String nowFormat = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); |
| | | String excelName =""; |
| | | int fileType=testDataInfoMcp.getFile_type(); |
| | | if(fileType==0xFA){ |
| | | excelName="MCP-"+nowFormat; |
| | | }else{ |
| | | excelName="MCH-"+nowFormat; |
| | | } |
| | | XSSFWorkbook wb = new XSSFWorkbook(); |
| | | XSSFSheet sheet = wb.createSheet("数据总表"); |
| | | //图片元素 |
| | | XSSFDrawing patriarch = sheet.createDrawingPatriarch(); |
| | | BattParam battParam=info.battparam;//电池参数 |
| | | SYSMonitorParam sysParam=info.monitorparam;//组端参数 |
| | | SYSMonitorState sysState=info.monitorstate;//组端状态 |
| | | int rowNumSheet = 0; |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("电池参数:"); |
| | | rowNumSheet++; |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("标称容量(1AH):"+battParam.STD_CAP); |
| | | sheet.getRow(rowNumSheet).createCell(1).setCellValue("标称内阻(0.001mΩ):"+battParam.STD_RES); |
| | | sheet.getRow(rowNumSheet).createCell(2).setCellValue("单体标称电压(0.1V):"+battParam.monomerVol); |
| | | rowNumSheet++; |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("组数:"+battParam.battGroupCount); |
| | | |
| | | int battNum=battParam.eachGroupBattCount;//单体个数 |
| | | sheet.getRow(rowNumSheet).createCell(1).setCellValue("每组单体个数:"+battNum); |
| | | rowNumSheet++; |
| | | |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("组端参数:"); |
| | | rowNumSheet++; |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("放电电流:"+sysParam.disCurr); |
| | | sheet.getRow(rowNumSheet).createCell(1).setCellValue("放电容量:"+sysParam.disCap); |
| | | sheet.getRow(rowNumSheet).createCell(2).setCellValue("放电时长:"+sysParam.disTime); |
| | | rowNumSheet++; |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("组端下限:"+sysParam.groupVol_LOW); |
| | | sheet.getRow(rowNumSheet).createCell(1).setCellValue("单体下限:"+sysParam.monomerVol_LOW); |
| | | sheet.getRow(rowNumSheet).createCell(2).setCellValue("下限个数:"+sysParam.monomerLowCount); |
| | | rowNumSheet++; |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("充电电流:"+sysParam.chrCurr); |
| | | sheet.getRow(rowNumSheet).createCell(1).setCellValue("充电容量:"+sysParam.chrCap); |
| | | sheet.getRow(rowNumSheet).createCell(2).setCellValue("充电时长:"+sysParam.chrTime); |
| | | rowNumSheet++; |
| | | |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("组端状态:"); |
| | | rowNumSheet++; |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("启动放电的日期时间:"+formartDate(sysState.startDT.time,"yyyy-MM-dd HH:mm:ss")); |
| | | sheet.getRow(rowNumSheet).createCell(1).setCellValue("终止放电的日期时间:"+formartDate(sysState.stopDT.time,"yyyy-MM-dd HH:mm:ss")); |
| | | sheet.getRow(rowNumSheet).createCell(2).setCellValue("已测试时间(HMS):"+sysState.test_Time.testTime); |
| | | |
| | | rowNumSheet+=4; |
| | | //插入图片 |
| | | int picNum = 0; |
| | | String[] picName =new String[]{"单体电压折线图","电池电流折线图","组端电压折线图","测试容量折线图"}; |
| | | 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); |
| | | anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE); |
| | | patriarch.createPicture(anchor,wb.addPicture(bytes.get(picNum),XSSFWorkbook.PICTURE_TYPE_PNG)).resize(1); |
| | | picNum ++; |
| | | rowNumSheet+=30; |
| | | } |
| | | } |
| | | |
| | | //从文件中获取数据 |
| | | List<FBSData> list=testDataInfoMcp.fbsDatas;//充放电数据 |
| | | String sheetName="放电数据"; |
| | | String testName="测试数据"; |
| | | XSSFSheet sheet1 = wb.createSheet(sheetName); |
| | | //抬头 |
| | | int rowNum = 0; |
| | | sheet1.createRow(rowNum).createCell(0).setCellValue(testName); |
| | | rowNum++; |
| | | |
| | | XSSFRow row = sheet1.createRow(rowNum); |
| | | //属性栏 |
| | | String[] rowName =new String[]{"测试时间","在线电压","组端电压","电池电流","电池容量","电池温度"}; |
| | | for (int i=0;i<rowName.length;i++){ |
| | | row.createCell(i).setCellValue(rowName[i]); |
| | | } |
| | | for(int i=0;i<battNum;i++){ |
| | | row.createCell(6+i).setCellValue("#"+Integer.valueOf(i+1)); |
| | | } |
| | | rowNum++; |
| | | //数据栏 |
| | | for (int i = 0; i < list.size(); i++) { |
| | | sheet1.createRow(rowNum); //创建行 |
| | | FBSData fbsData= list.get(i); |
| | | sheet1.getRow(rowNum).createCell(0).setCellValue(fbsData.testTime.testTime); |
| | | sheet1.getRow(rowNum).createCell(1).setCellValue(fbsData.vcData.onlinevol[0]); |
| | | sheet1.getRow(rowNum).createCell(2).setCellValue(fbsData.vcData.groupvol[0]); |
| | | sheet1.getRow(rowNum).createCell(3).setCellValue(fbsData.vcData.battcurr[0]); |
| | | sheet1.getRow(rowNum).createCell(4).setCellValue(fbsData.vcData.battcap[0]); |
| | | sheet1.getRow(rowNum).createCell(5).setCellValue(fbsData.vcData.batttemp[0]); |
| | | float[] datas=fbsData.mvol.vol; |
| | | for (int k = 0;k<battNum;k++){ |
| | | sheet1.getRow(rowNum).createCell(k+6).setCellValue(datas[k]); |
| | | } |
| | | rowNum++; |
| | | } |
| | | rowNum++; |
| | | |
| | | try { |
| | | // 转码防止乱码 |
| | | resp.addHeader("Content-Disposition", "attachment;filename=" |
| | | + new String(excelName.getBytes("UTF-8"), "ISO8859-1") |
| | | + ".xlsx"); |
| | | OutputStream out = resp.getOutputStream(); |
| | | wb.write(out); |
| | | out.close(); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |