From 10613f0fe047752f23d83a567d46dca609b04447 Mon Sep 17 00:00:00 2001 From: whyclxw <810412026@qq.com> Date: 星期五, 20 六月 2025 17:29:19 +0800 Subject: [PATCH] 模板导出和标准化修改 --- src/main/java/com/whyc/service/ExportService.java | 92 +++++++++++++++++++++++++++++++++++++-------- 1 files changed, 75 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/whyc/service/ExportService.java b/src/main/java/com/whyc/service/ExportService.java index 1c790f9..7ea50e0 100644 --- a/src/main/java/com/whyc/service/ExportService.java +++ b/src/main/java/com/whyc/service/ExportService.java @@ -1,17 +1,28 @@ 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.Response; import com.whyc.dto.Statistic.MonStic; 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; @@ -20,10 +31,7 @@ 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 { @@ -31,17 +39,22 @@ @Autowired private BatttestdataInfService battTinfService; + @Autowired + private SubTablePageInfoService subTablePageInfoService; + + @Resource + private CommonMapper commonMapper; + //鍗曡妭鏁伴噺缁熻瀵煎嚭锛�1.2.14锛� - public void exportBattTinfStatistic(HttpServletRequest req, HttpServletResponse resp) throws ParseException { - String topPic = req.getParameter("topPic"); //澶撮儴鏌辩姸鍥� - String goodVolPic = req.getParameter("goodVolPic"); //浼樼鐢靛帇鍥� - String goodResPic = req.getParameter("goodResPic"); //浼樼鍐呴樆 - String badVolPic = req.getParameter("badVolPic"); //鍔e寲鐢靛帇鍥� - String badResPic = req.getParameter("badResPic"); //鍔e寲鍐呴樆 - String damageVolPic = req.getParameter("damageVolPic"); //鎹熷潖鐢靛帇鍥� - String damageResPic = req.getParameter("damageResPic"); //鎹熷潖鍐呴樆 - MonStic stic=ActionUtil.getGson("yyyy-MM-dd").fromJson(req.getParameter("stic"), MonStic.class); + public void exportBattTinfStatistic(HttpServletRequest req, HttpServletResponse resp, MonStic stic) throws ParseException { + String topPic = stic.getTopPic(); //澶撮儴鏌辩姸鍥� + String goodVolPic = stic.getGoodVolPic(); //浼樼鐢靛帇鍥� + String goodResPic = stic.getGoodResPic(); //浼樼鍐呴樆 + String badVolPic = stic.getBadVolPic(); //鍔e寲鐢靛帇鍥� + String badResPic = stic.getBadResPic(); //鍔e寲鍐呴樆 + String damageVolPic = stic.getDamageVolPic(); //鎹熷潖鐢靛帇鍥� + String damageResPic = stic.getDamageResPic(); //鎹熷潖鍐呴樆 User uinf= ActionUtil.getUser(); stic.setUid(uinf.getId()); Map<String,Object> map= battTinfService.getMonStatistic(stic); @@ -154,7 +167,7 @@ //鍥剧墖鍏冪礌 HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); int rowNum = 1; - int rowNumAdd=27; + int rowNumAdd=25; //鎻掑叆鍥剧墖 int picNum = 0; String[] picName = new String[]{ @@ -164,11 +177,56 @@ sheet.createRow(rowNum - 1); sheet.getRow(rowNum - 1).createCell(0).setCellValue(picName[i]); HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 512, 255, (short) 0, rowNum, (short) 10, rowNum + rowNumAdd); - anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE); + anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_DONT_RESIZE); patriarch.createPicture(anchor, wb.addPicture(bytes.get(picNum), HSSFWorkbook.PICTURE_TYPE_PNG)).resize(1); picNum++; - rowNum += rowNumAdd; + rowNum = rowNum+rowNumAdd+5; } - rowNum++; + } + //鍘嗗彶娴嬭瘯鏁版嵁瀵煎嚭 + 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); + 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(); + } } } \ No newline at end of file -- Gitblit v1.9.1