whyclxw
2022-01-21 0d110e689cba1eabfe2f20474d7fd84a313e64f9
在线监测-实时监控-A059导出
4个文件已修改
137 ■■■■■ 已修改文件
src/main/java/com/whyc/mapper/FBOTestDataMapper.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/EchartPictureDowloadService.java 126 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/FBOTestDataService.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/FBOTestDataMapper.xml 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/FBOTestDataMapper.java
@@ -8,5 +8,6 @@
    void delete(Integer battGroupId, Integer testRecordCount);
    List<FBOTestData> getList(int battGroupId, int testRecordCount);
    //根据放电记录编号查询这次充放电中有多少
    int getMonCuntBytestRecordCount(int battGroupId, int testRecordCount);
}
src/main/java/com/whyc/service/EchartPictureDowloadService.java
@@ -7,8 +7,10 @@
import com.whyc.util.ActionUtil;
import com.whyc.util.ExcelUtil;
import com.whyc.util.ServletUtils;
import org.apache.ibatis.annotations.Mapper;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.misc.BASE64Decoder;
@@ -31,6 +33,9 @@
    private String excelName = "Echarts";
    private int rowNumAdd=27;
    @Autowired
    private FBOTestDataService fboservice; //aA059的service
    //文件导出
    public void exportExcel( HttpServletRequest req, HttpServletResponse resp) {
        String pageName = req.getParameter("pageName");
@@ -47,6 +52,8 @@
                ExprotCTReport(req,resp);                    //导出CT机类似报表
            }else if("ePrice".equalsIgnoreCase(pageName)){
                ExportElectricityPrice(req,resp);            //电价统计报表
            }else if("A059".equalsIgnoreCase(pageName)){
                ExportA059(req,resp);     //A059一体机导出报表
            }
        }
    }
@@ -89,6 +96,125 @@
        }
    }
    /**
     * A059一体机导出报表
     * @param req
     * @param resp
     */
    private void ExportA059(HttpServletRequest req, HttpServletResponse resp) {
        String ltop_echart = req.getParameter("ltop_echart");            //总电压折线图
        String rtop_echart = req.getParameter("rtop_echart");            //单体电压柱状图
        String lbottom_echart = req.getParameter("lbottom_echart");        //电池电流折线图
        String rbottom_echart = req.getParameter("rbottom_echart");        //单体电压折现图
        bytes=new ArrayList<byte[]>();
        int battGroupId =Integer.valueOf(req.getParameter("battGroupId"));  //电池组编号
        int testRecordCount =Integer.valueOf(req.getParameter("testRecordCount"));  //测试编号
        List<FBOTestData> list=fboservice.getList(battGroupId,testRecordCount);  //查询4059充放电数据
        int monCount= fboservice.getMonCuntBytestRecordCount(battGroupId,testRecordCount); //查询具体一次充放电单体个数
        //处理图片
        try {
            if (ServletUtils.isNotNull(ltop_echart)) {
                String[] url = ltop_echart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }if (ServletUtils.isNotNull(rtop_echart)) {
                String[] url = rtop_echart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }if (ServletUtils.isNotNull(lbottom_echart)) {
                String[] url = ltop_echart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }if (ServletUtils.isNotNull(rbottom_echart)) {
                String[] url = rtop_echart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        //当前日期
        String nowFormat = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        String excelName = "A059一体机-"+nowFormat;
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet("Sheet1");
        //图片元素
        HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
        //字体格式-加粗
        HSSFCellStyle cellStyle = wb.createCellStyle();
        HSSFFont font = wb.createFont();
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        cellStyle.setFont(font);
        //新建行
        //抬头
        int rowNum = 0;
        HSSFRow rowTitle = sheet.createRow(rowNum);
        HSSFCell cellTitle = rowTitle.createCell(0);
        cellTitle.setCellValue("一体机充放电数据");
        cellTitle.setCellStyle(cellStyle);
        rowNum++;
        //属性栏
        HSSFRow row = sheet.createRow(rowNum);
        row.createCell(0).setCellValue("测试时长"); //创建单元格
        row.createCell(1).setCellValue("总电压");
        row.createCell(2).setCellValue("测试电流");
        row.createCell(3).setCellValue("测试容量");
        for(int i=0;i<monCount;i++){
            row.createCell(4+i).setCellValue("#"+i);
        }
        rowNum++;
        //数据栏
        for (int i = 0; i < list.size(); i++) {
            FBOTestData fbo=list.get(i);
            sheet.createRow(rowNum);  //创建行
            sheet.getRow(rowNum).createCell(0).setCellValue(fbo.getRecordTime());
            sheet.getRow(rowNum).createCell(1).setCellValue(fbo.getSumVol());
            sheet.getRow(rowNum).createCell(2).setCellValue(fbo.getTestCurr());
            sheet.getRow(rowNum).createCell(3).setCellValue(fbo.getTestCap());
            for(int j=0;j<monCount;j++){
                FBOTestData fbo1=list.get(i+j);
                sheet.getRow(rowNum).createCell(4+j).setCellValue(fbo1.getMonVol());
            }
            i+=monCount;
            rowNum++;
        }
        //插入图片
        int picNum = 0;
        String[] picName = new String[]{
                "总电压折线图","单体电压柱状图,电池电流折线图,单体电压折现图"
        };
        for(int i=0;i<picName.length;i++){
            sheet.createRow(rowNum-1);
            sheet.getRow(rowNum-1).createCell(0).setCellValue(picName[i]);
            //rowNum++;
            HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 512, 255,(short) 0, rowNum, (short) 10, rowNum+rowNumAdd);
            anchor.setAnchorType(3);
            patriarch.createPicture(anchor,wb.addPicture(bytes.get(picNum),HSSFWorkbook.PICTURE_TYPE_PNG)).resize(1);
            picNum ++;rowNum+=rowNumAdd;
        }
        rowNum++;
        try {
            // 转码防止乱码
            resp.addHeader("Content-Disposition", "attachment;filename="
                    + new String(excelName.getBytes("UTF-8"), "ISO8859-1")
                    + ".xls");
            OutputStream out = resp.getOutputStream();
            wb.write(out);
            out.close();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    /**
     * 导出报表
     * @param req
     * @param resp
src/main/java/com/whyc/service/FBOTestDataService.java
@@ -16,4 +16,9 @@
    public List<FBOTestData> getList(int battGroupId, int testRecordCount) {
        return mapper.getList(battGroupId,testRecordCount);
    }
    //根据放电记录编号查询这次充放电中有多少
    public int getMonCuntBytestRecordCount(int battGroupId, int testRecordCount){
        int monCount=mapper.getMonCuntBytestRecordCount(battGroupId,testRecordCount);
        return monCount;
    }
}
src/main/resources/mapper/FBOTestDataMapper.xml
@@ -24,4 +24,7 @@
    <select id="getList" resultMap="Map_FBOTestData">
        select * from db_fbo_testdata.tb_fbotestdata_${battGroupId} where test_record_count = #{testRecordCount}
    </select>
    <select id="getMonCuntBytestRecordCount" resultType="java.lang.Integer">
        select max(mon_num) as monCount from db_fbo_testdata.tb_fbotestdata_${battGroupId} where test_record_count = #{testRecordCount} limit 1
    </select>
</mapper>