whyclxw
1 天以前 add5c816a5281cf6b1df4a0988e8b3a0c2b59bee
src/main/java/com/whyc/service/ExportService.java
@@ -5,7 +5,9 @@
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import com.whyc.dto.Real.ExportTinfDataDto;
import com.whyc.dto.Response;
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;
@@ -229,4 +231,49 @@
            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();
        }
    }
}