| | |
| | | package com.whyc.service; |
| | | |
| | | import cn.afterturn.easypoi.entity.ImageEntity; |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.TemplateExportParams; |
| | | import com.whyc.dto.Real.ExportTinfDataDto; |
| | | import com.whyc.dto.RealDataStatic.ResRealExportAc; |
| | | import com.whyc.dto.Statistic.BattCompareStic; |
| | | import com.whyc.dto.Statistic.MonStic; |
| | | import com.whyc.dto.Statistic.SticCompare15Res; |
| | | import com.whyc.dto.Statistic.SticMonRes; |
| | | import com.whyc.mapper.CommonMapper; |
| | | import com.whyc.pojo.db_batt_testdata.BatttestdataId; |
| | | import com.whyc.pojo.db_batt_testdata.BatttestdataInf; |
| | | import com.whyc.pojo.db_user.User; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.ServletUtils; |
| | | import org.apache.poi.hssf.usermodel.*; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.apache.poi.ss.usermodel.ClientAnchor; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.core.io.ClassPathResource; |
| | | import org.springframework.stereotype.Service; |
| | | import sun.misc.BASE64Decoder; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | |
| | | import java.net.URLEncoder; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | @Service |
| | | public class ExportService { |
| | | |
| | | @Autowired |
| | | private BatttestdataInfService battTinfService; |
| | | |
| | | @Autowired |
| | | private SubTablePageInfoService subTablePageInfoService; |
| | | |
| | | @Resource |
| | | private CommonMapper commonMapper; |
| | | |
| | | |
| | | //单节数量统计导出(1.2.14) |
| | |
| | | rowNum = rowNum+rowNumAdd+5; |
| | | } |
| | | } |
| | | //历史测试数据导出 |
| | | public void exportTinfDataByTestRecordCount(HttpServletRequest req, HttpServletResponse resp, ExportTinfDataDto dto) throws IOException { |
| | | Map<String,Object> map=new HashMap<>(); |
| | | //历史测试数据导出 |
| | | BatttestdataInf tinf = battTinfService.exportTinfDataByTestRecordCount(dto.getBattgroupId(), dto.getTestRecordCount()); |
| | | String tableName ="db_batt_testdata.tb_batttestdata_"+dto.getBattgroupId(); |
| | | //获取具体的放电数据 |
| | | List<BatttestdataId> dataList= subTablePageInfoService.exportTinfDataByTestRecordCount(dto.getBattgroupId(),dto.getTestRecordCount(),tableName); |
| | | map.put("dataList",dataList); |
| | | BASE64Decoder decoder = new BASE64Decoder(); |
| | | if(!dto.getPicGroupVol().equals("")) { |
| | | ImageEntity volImage = new ImageEntity(); |
| | | volImage.setData(decoder.decodeBuffer(dto.getPicGroupVol().substring(dto.getPicGroupVol().indexOf(",") + 1))); |
| | | volImage.setColspan(6); |
| | | volImage.setRowspan(17); |
| | | map.put("picGroupVol",volImage); |
| | | } |
| | | if(!dto.getPicBattVol().equals("")) { |
| | | ImageEntity volImage = new ImageEntity(); |
| | | volImage.setData(decoder.decodeBuffer(dto.getPicGroupVol().substring(dto.getPicBattVol().indexOf(",") + 1))); |
| | | volImage.setColspan(6); |
| | | volImage.setRowspan(17); |
| | | map.put("picBattVol",volImage); |
| | | } |
| | | if(!dto.getPicGroupCurr().equals("")) { |
| | | ImageEntity volImage = new ImageEntity(); |
| | | volImage.setData(decoder.decodeBuffer(dto.getPicGroupVol().substring(dto.getPicGroupCurr().indexOf(",") + 1))); |
| | | volImage.setColspan(6); |
| | | volImage.setRowspan(17); |
| | | map.put("picGroupCurr",volImage); |
| | | } |
| | | //获取导出模板地址 |
| | | ClassPathResource classPathResource = new ClassPathResource("excel_templates/batt_mon_static_template.xlsx"); |
| | | String path = classPathResource.getPath(); |
| | | TemplateExportParams templateExportParams1 = new TemplateExportParams(path,true); |
| | | Workbook wb = ExcelExportUtil.exportExcel(templateExportParams1, map); |
| | | try { |
| | | String fileName = "历史测试数据表.xls"; |
| | | resp.setContentType("application/vnd.ms-excel"); |
| | | resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8")); |
| | | resp.flushBuffer(); |
| | | wb.write(resp.getOutputStream()); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | //蓄电池组对比分析导出(2.5.1/2/3) |
| | | public void exportBattCompare(HttpServletRequest req, HttpServletResponse resp, BattCompareStic stic) throws IOException { |
| | | Map<String,Object> map=new HashMap<>(); |
| | | map.put("avgCap",stic.getAvgCap()); |
| | | map.put("standCapDiff",stic.getStandCapDiff()); |
| | | //表格数据 |
| | | List<SticCompare15Res> dataList= battTinfService.exportBattCompare(stic); |
| | | map.put("dataList",dataList); |
| | | BASE64Decoder decoder = new BASE64Decoder(); |
| | | if(!stic.getPicCap().equals("")) { |
| | | ImageEntity volImage = new ImageEntity(); |
| | | volImage.setData(decoder.decodeBuffer(stic.getPicCap().substring(stic.getPicCap().indexOf(",") + 1))); |
| | | volImage.setColspan(6); |
| | | volImage.setRowspan(17); |
| | | map.put("picCap",volImage); |
| | | } |
| | | if(!stic.getPicRes().equals("")) { |
| | | ImageEntity volImage = new ImageEntity(); |
| | | volImage.setData(decoder.decodeBuffer(stic.getPicRes().substring(stic.getPicRes().indexOf(",") + 1))); |
| | | volImage.setColspan(6); |
| | | volImage.setRowspan(17); |
| | | map.put("picRes",volImage); |
| | | } |
| | | if(!stic.getPicFlotVol().equals("")) { |
| | | ImageEntity volImage = new ImageEntity(); |
| | | volImage.setData(decoder.decodeBuffer(stic.getPicFlotVol().substring(stic.getPicFlotVol().indexOf(",") + 1))); |
| | | volImage.setColspan(6); |
| | | volImage.setRowspan(17); |
| | | map.put("picFlotVol",volImage); |
| | | } |
| | | //获取导出模板地址 |
| | | ClassPathResource classPathResource = new ClassPathResource("excel_templates/batt_compare_template.xlsx"); |
| | | String path = classPathResource.getPath(); |
| | | TemplateExportParams templateExportParams1 = new TemplateExportParams(path,true); |
| | | Workbook wb = ExcelExportUtil.exportExcel(templateExportParams1, map); |
| | | try { |
| | | String fileName = "蓄电池组对比数据.xls"; |
| | | resp.setContentType("application/vnd.ms-excel"); |
| | | resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8")); |
| | | resp.flushBuffer(); |
| | | wb.write(resp.getOutputStream()); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | //实时数据统计曲线-交流单元导出(2.5.2) |
| | | public void exportRealStaticAc(HttpServletRequest req, HttpServletResponse resp, ResRealExportAc exportAc) throws IOException { |
| | | List<String> picList=exportAc.getPicList(); |
| | | Map<String,Object> map=new HashMap<>(); |
| | | List<ImageEntity> imageList = new ArrayList<>(); |
| | | BASE64Decoder decoder = new BASE64Decoder(); |
| | | if(picList!=null&&picList.size()>0){ |
| | | for(int i=0;i<picList.size();i++){ |
| | | ImageEntity pic = new ImageEntity(); |
| | | pic.setData(decoder.decodeBuffer(picList.get(i).substring(picList.get(i).indexOf(",") + 1))); |
| | | pic.setHeight(1000); // 必须设置高度 |
| | | pic.setColspan(6); |
| | | pic.setRowspan(17); |
| | | imageList.add(pic); |
| | | } |
| | | } |
| | | map.put("imageList", imageList); |
| | | //获取导出模板地址 |
| | | ClassPathResource classPathResource = new ClassPathResource("excel_templates/realstic_ac_template.xls"); |
| | | String path = classPathResource.getPath(); |
| | | TemplateExportParams templateExportParams1 = new TemplateExportParams(path,true); |
| | | Workbook wb = ExcelExportUtil.exportExcel(templateExportParams1, map); |
| | | try { |
| | | String fileName = "实时数据统计曲线-交流单元.xls"; |
| | | resp.setContentType("application/vnd.ms-excel"); |
| | | resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8")); |
| | | resp.flushBuffer(); |
| | | wb.write(resp.getOutputStream()); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |