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/BatttestdataInfService.java | 8 ++ src/main/java/com/whyc/service/ExportService.java | 68 +++++++++++++++++++++- src/main/resources/excel_templates/batt_mon_static_template.xlsx | 0 src/main/java/com/whyc/service/SubTablePageInfoService.java | 36 ++++++++++++ src/main/java/com/whyc/controller/ExportFileController.java | 8 ++ src/main/java/com/whyc/pojo/db_pwrdev_alarm/PwrdevAlarmParamStand.java | 2 src/main/java/com/whyc/dto/Real/ExportTinfDataDto.java | 12 ++++ pom.xml | 15 +++++ 8 files changed, 144 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 2a1ccf4..b808b65 100644 --- a/pom.xml +++ b/pom.xml @@ -148,6 +148,21 @@ <artifactId>poi-ooxml</artifactId> <version>3.10.1</version> </dependency> + <dependency> + <groupId>cn.afterturn</groupId> + <artifactId>easypoi-spring-boot-starter</artifactId> + <version>4.1.2</version> + <exclusions> + <exclusion> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.poi</groupId> + <artifactId>poi-ooxml-schemas</artifactId> + </exclusion> + </exclusions> + </dependency> <!--<dependency> <groupId>org.springframework.plugin</groupId> diff --git a/src/main/java/com/whyc/controller/ExportFileController.java b/src/main/java/com/whyc/controller/ExportFileController.java index 00e6f84..9decf30 100644 --- a/src/main/java/com/whyc/controller/ExportFileController.java +++ b/src/main/java/com/whyc/controller/ExportFileController.java @@ -1,5 +1,6 @@ package com.whyc.controller; +import com.whyc.dto.Real.ExportTinfDataDto; import com.whyc.dto.Statistic.MonStic; import com.whyc.service.ExportService; import io.swagger.annotations.Api; @@ -9,6 +10,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.text.ParseException; @RestController @@ -23,4 +25,10 @@ public void exportBattTinfStatistic(HttpServletRequest req, HttpServletResponse resp ,@RequestBody MonStic stic) throws ParseException { service.exportBattTinfStatistic(req,resp,stic); } + + @PostMapping("exportTinfDataByTestRecordCount") + @ApiOperation(value = "鍘嗗彶娴嬭瘯鏁版嵁瀵煎嚭") + public void exportTinfDataByTestRecordCount(HttpServletRequest req, HttpServletResponse resp ,@RequestBody ExportTinfDataDto dto) throws ParseException, IOException { + service.exportTinfDataByTestRecordCount(req,resp,dto); + } } \ No newline at end of file diff --git a/src/main/java/com/whyc/dto/Real/ExportTinfDataDto.java b/src/main/java/com/whyc/dto/Real/ExportTinfDataDto.java new file mode 100644 index 0000000..6b1be9e --- /dev/null +++ b/src/main/java/com/whyc/dto/Real/ExportTinfDataDto.java @@ -0,0 +1,12 @@ +package com.whyc.dto.Real; + +import lombok.Data; + +@Data +public class ExportTinfDataDto { + private Integer battgroupId; + private Integer testRecordCount; + private String picGroupVol; + private String picBattVol; + private String picGroupCurr; +} \ No newline at end of file diff --git a/src/main/java/com/whyc/pojo/db_pwrdev_alarm/PwrdevAlarmParamStand.java b/src/main/java/com/whyc/pojo/db_pwrdev_alarm/PwrdevAlarmParamStand.java index 2f76d30..d029919 100644 --- a/src/main/java/com/whyc/pojo/db_pwrdev_alarm/PwrdevAlarmParamStand.java +++ b/src/main/java/com/whyc/pojo/db_pwrdev_alarm/PwrdevAlarmParamStand.java @@ -42,7 +42,7 @@ private Integer paramType; @ApiModelProperty(value = "鏍囧噯鍙傛暟瀵瑰簲鏁版嵁鍚嶇О") - private Integer paramName; + private String paramName; @ApiModelProperty(value = "鍩哄噯鍊�") private Float basisVal; diff --git a/src/main/java/com/whyc/service/BatttestdataInfService.java b/src/main/java/com/whyc/service/BatttestdataInfService.java index e288db4..f763f91 100644 --- a/src/main/java/com/whyc/service/BatttestdataInfService.java +++ b/src/main/java/com/whyc/service/BatttestdataInfService.java @@ -1005,4 +1005,12 @@ wrapper.last(" limit 1"); return mapper.selectOne(wrapper); } + //鍘嗗彶娴嬭瘯鏁版嵁瀵煎嚭 + public BatttestdataInf exportTinfDataByTestRecordCount(Integer battgroupId, Integer testRecordCount) { + QueryWrapper wrapper =new QueryWrapper(); + wrapper.eq("battgroup_id",battgroupId); + wrapper.eq("test_record_count",testRecordCount); + wrapper.last(" limit 1"); + return mapper.selectOne(wrapper); + } } \ No newline at end of file diff --git a/src/main/java/com/whyc/service/ExportService.java b/src/main/java/com/whyc/service/ExportService.java index 5bf94b5..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,16 +31,19 @@ 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锛� @@ -169,4 +183,50 @@ 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); + 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 diff --git a/src/main/java/com/whyc/service/SubTablePageInfoService.java b/src/main/java/com/whyc/service/SubTablePageInfoService.java index a8b2dd5..b071132 100644 --- a/src/main/java/com/whyc/service/SubTablePageInfoService.java +++ b/src/main/java/com/whyc/service/SubTablePageInfoService.java @@ -950,4 +950,40 @@ }); return list; } + //鑾峰彇鍏蜂綋鐨勬斁鐢垫暟鎹� + public List<BatttestdataId> exportTinfDataByTestRecordCount(Integer battgroupId, Integer testRecordCount, String tableName) { + String sql="select distinct * from "+tableName+" "+ + " where test_record_count="+testRecordCount; + sql+=" order by record_time asc"; + List<BatttestdataId> list = sqlExecuteService.executeQuery_call(sql, new CallBack() { + @Override + public List getResults(ResultSet rs) throws SQLException { + List<BatttestdataId> list=new ArrayList<>(); + while (rs.next()){ + BatttestdataId data=new BatttestdataId(); + data.setNum(rs.getInt("num")); + data.setBattgroupId(rs.getInt("battgroup_id")); + data.setTestRecordCount(rs.getInt("test_record_count")); + data.setTestType(rs.getInt("test_type")); + data.setRecordNum(rs.getInt("record_num")); + data.setDataNew(rs.getInt("data_new")); + data.setDataAvailable(rs.getInt("data_available")); + data.setTestTimelong(rs.getInt("test_timelong")); + data.setTestCurr(rs.getFloat("test_curr")); + data.setTestCap(rs.getFloat("test_cap")); + data.setMonNum(rs.getInt("mon_num")); + data.setMonVol(rs.getFloat("mon_vol")); + data.setMonTmp(rs.getFloat("mon_tmp")); + data.setMonRes(rs.getFloat("mon_res")); + data.setTestStarttime(rs.getTimestamp("test_starttime")); + data.setRecordTime(rs.getTimestamp("record_time")); + data.setGroupVol(rs.getFloat("group_vol")); + data.setOnlineVol(rs.getFloat("online_vol")); + list.add(data); + } + return list; + } + }); + return list; + } } diff --git a/src/main/resources/excel_templates/batt_mon_static_template.xlsx b/src/main/resources/excel_templates/batt_mon_static_template.xlsx new file mode 100644 index 0000000..2229fa0 --- /dev/null +++ b/src/main/resources/excel_templates/batt_mon_static_template.xlsx Binary files differ -- Gitblit v1.9.1