| | |
| | | package com.whyc.service; |
| | | |
| | | import com.whyc.bts.*; |
| | | import com.whyc.fbo.FboData; |
| | | import com.whyc.fbo.FboDataHeadStart; |
| | | import com.whyc.fbo.FboDataHeadStop; |
| | |
| | | |
| | | @Autowired |
| | | private TestDataInfoService testDataInfoService; |
| | | |
| | | @Autowired |
| | | private BtsDisChargeService disDataService; |
| | | |
| | | @Autowired |
| | | private BtsChargeDataService chargeDataService; |
| | | |
| | | //导出fbx |
| | | public void exportFbx(HttpServletRequest req, HttpServletResponse resp){ |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | //导出bts的放电数据bcp |
| | | public void exportBcp(HttpServletRequest req, HttpServletResponse resp) { |
| | | String volEchart = req.getParameter("vol_echart"); //单体电压折线图 |
| | | String currEchart = req.getParameter("curr_echart"); //电池电流折线图 |
| | | String groupVolEchart = req.getParameter("groupVol_echart"); //组端电压折线图 |
| | | String online_echart = req.getParameter("online_echart"); //在线电压折线图 |
| | | String filePath = req.getParameter("filePath"); |
| | | //图片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(online_echart)) { |
| | | String[] url = online_echart.split(","); |
| | | bytes.add(new BASE64Decoder().decodeBuffer(url[1])); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | //当前日期 |
| | | String nowFormat = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); |
| | | String excelName="BCP-"+nowFormat; |
| | | //数据 |
| | | BTS_DisChargeData disData=disDataService.getDisData(filePath); |
| | | BTS_BattParam btsbattParam = disData.battParam;//电池参数 |
| | | BTS_DischargeParam btsdisParam=disData.dischargeParam;//放电参数 |
| | | BTS_CapState btscapState=disData.capState;//放电时长 |
| | | XSSFWorkbook wb = new XSSFWorkbook(); |
| | | XSSFSheet sheet = wb.createSheet("数据总表"); |
| | | //图片元素 |
| | | XSSFDrawing patriarch = sheet.createDrawingPatriarch(); |
| | | int rowNumSheet = 0; |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("电池参数:"); |
| | | rowNumSheet++; |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("标称容量(1AH):"+btsbattParam.STD_CAP); |
| | | sheet.getRow(rowNumSheet).createCell(1).setCellValue("标称内阻(0.001mΩ):"+btsbattParam.STD_RES); |
| | | sheet.getRow(rowNumSheet).createCell(2).setCellValue("单体标称电压(0.1V):"+btsbattParam.MonomerVol); |
| | | rowNumSheet++; |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("组数:"+btsbattParam.BattGroupCount); |
| | | |
| | | int battNum=btsbattParam.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("放电电流:"+btsdisParam.DisCurr); |
| | | sheet.getRow(rowNumSheet).createCell(1).setCellValue("放电容量:"+btsdisParam.DisCap); |
| | | sheet.getRow(rowNumSheet).createCell(2).setCellValue("放电时长:"+btsdisParam.DisTime); |
| | | sheet.getRow(rowNumSheet).createCell(2).setCellValue("升压上限:"+btsdisParam.DCVolHighLimit); |
| | | sheet.getRow(rowNumSheet).createCell(2).setCellValue("温度上限:"+btsdisParam.MonomerTmp_High); |
| | | rowNumSheet++; |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("组端下限:"+btsdisParam.GroupVol_LOW); |
| | | sheet.getRow(rowNumSheet).createCell(1).setCellValue("单体下限:"+btsdisParam.MonomerVol_LOW); |
| | | sheet.getRow(rowNumSheet).createCell(2).setCellValue("下限个数:"+btsdisParam.MonomerLowCount); |
| | | rowNumSheet++; |
| | | |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("组端状态:"); |
| | | rowNumSheet++; |
| | | sheet.createRow(rowNumSheet); |
| | | sheet.getRow(rowNumSheet).createCell(0).setCellValue("启动放电的日期时间:"+formartDate(btscapState.StartDT.getDateTime(),"yyyy-MM-dd HH:mm:ss")); |
| | | sheet.getRow(rowNumSheet).createCell(1).setCellValue("终止放电的日期时间:"+formartDate(btscapState.StopDT.getDateTime(), "yyyy-MM-dd HH:mm:ss")); |
| | | sheet.getRow(rowNumSheet).createCell(2).setCellValue("已测试时间(HMS):"+btscapState.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<BTS_FbsData> list=disData.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); //创建行 |
| | | BTS_FbsData fbsData= list.get(i); |
| | | sheet1.getRow(rowNum).createCell(0).setCellValue(fbsData.testTime.testTime); |
| | | sheet1.getRow(rowNum).createCell(1).setCellValue(fbsData.onlinevol[0]); |
| | | sheet1.getRow(rowNum).createCell(2).setCellValue(fbsData.groupvol[0]); |
| | | sheet1.getRow(rowNum).createCell(3).setCellValue(fbsData.battcurr[0]); |
| | | sheet1.getRow(rowNum).createCell(4).setCellValue(fbsData.battcap[0]); |
| | | sheet1.getRow(rowNum).createCell(5).setCellValue(fbsData.batttemp[0]); |
| | | double[] datas=fbsData.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(); |
| | | } |
| | | } |
| | | } |