From 2b22b70baa103d5048ace610410197f0da809cea Mon Sep 17 00:00:00 2001 From: zq Date: Wed, 28 Jan 2026 15:59:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=B5=E8=A1=A8=E6=8A=A5?= =?UTF-8?q?=E8=A1=A8=E3=80=81=E6=94=B6=E7=9B=8A=E6=8A=A5=E8=A1=A8=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ems/EmsStatisticalReportController.java | 44 +- .../ems/mapper/EmsBatteryStackMapper.java | 2 + .../ems/service/IEmsStatsReportService.java | 6 + .../impl/EmsStatsReportServiceImpl.java | 416 +++++++++++++++++- .../mapper/ems/EmsBatteryStackMapper.xml | 20 + 5 files changed, 481 insertions(+), 7 deletions(-) diff --git a/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsStatisticalReportController.java b/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsStatisticalReportController.java index 5930831..330ecb0 100644 --- a/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsStatisticalReportController.java +++ b/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsStatisticalReportController.java @@ -1,19 +1,31 @@ package com.xzzn.web.controller.ems; +import com.xzzn.common.annotation.Log; import com.xzzn.common.core.controller.BaseController; import com.xzzn.common.core.domain.AjaxResult; import com.xzzn.common.core.page.TableDataInfo; +import com.xzzn.common.enums.BusinessType; import com.xzzn.common.utils.StringUtils; -import com.xzzn.ems.domain.vo.*; +import com.xzzn.ems.domain.vo.AmmeterRevenueStatisListVo; +import com.xzzn.ems.domain.vo.AmmeterStatisListVo; +import com.xzzn.ems.domain.vo.ClusterStatisListVo; +import com.xzzn.ems.domain.vo.DateSearchRequest; +import com.xzzn.ems.domain.vo.StatisAmmeterDateRequest; +import com.xzzn.ems.domain.vo.StatisClusterDateRequest; import com.xzzn.ems.service.IEmsStatsReportService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; import java.util.List; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + /** * 单站监控-统计报表 * @@ -118,6 +130,17 @@ public class EmsStatisticalReportController extends BaseController return getDataTable(dataList); } + /** + * 导出电表报表 + */ + @PreAuthorize("@ss.hasPermi('system:ammeterData:export')") + @Log(title = "电表报表", businessType = BusinessType.EXPORT) + @PostMapping("/exportAmmeterData") + public void exportAmmeterData(HttpServletResponse response, StatisAmmeterDateRequest requestVo) + { + ieEmsStatsReportService.exportAmmeterData(response, requestVo); + } + /** * 概率统计-电表收益报表 */ @@ -129,6 +152,17 @@ public class EmsStatisticalReportController extends BaseController return getDataTable(dataList); } + /** + * 导出收益报表 + */ + @PreAuthorize("@ss.hasPermi('system:ammeterRevenueData:export')") + @Log(title = "收益报表", businessType = BusinessType.EXPORT) + @PostMapping("/exportAmmeterRevenueData") + public void exportAmmeterRevenueData(HttpServletResponse response, StatisAmmeterDateRequest requestVo) + { + ieEmsStatsReportService.exportAmmeterRevenueData(response, requestVo); + } + /** * 概率统计-功率曲线 */ diff --git a/ems-system/src/main/java/com/xzzn/ems/mapper/EmsBatteryStackMapper.java b/ems-system/src/main/java/com/xzzn/ems/mapper/EmsBatteryStackMapper.java index 29601e1..e42041d 100644 --- a/ems-system/src/main/java/com/xzzn/ems/mapper/EmsBatteryStackMapper.java +++ b/ems-system/src/main/java/com/xzzn/ems/mapper/EmsBatteryStackMapper.java @@ -93,4 +93,6 @@ public interface EmsBatteryStackMapper public List getBatteryAveTempList(@Param("siteId")String siteId, @Param("startDate")Date yesterday, @Param("endDate") Date today); List getStackPointByMinute(DateSearchRequest requestVo); + + List getStackDataByMinute(DateSearchRequest requestVo); } diff --git a/ems-system/src/main/java/com/xzzn/ems/service/IEmsStatsReportService.java b/ems-system/src/main/java/com/xzzn/ems/service/IEmsStatsReportService.java index db3e010..3283931 100644 --- a/ems-system/src/main/java/com/xzzn/ems/service/IEmsStatsReportService.java +++ b/ems-system/src/main/java/com/xzzn/ems/service/IEmsStatsReportService.java @@ -5,6 +5,8 @@ import com.xzzn.ems.domain.vo.*; import java.util.List; import java.util.Map; +import javax.servlet.http.HttpServletResponse; + /** * 统计报表数据Service接口 * @@ -31,4 +33,8 @@ public interface IEmsStatsReportService public List getPowerDataList(DateSearchRequest requestVo); public List getSingleBatteryData(DateSearchRequest requestVo); + + void exportAmmeterData(HttpServletResponse response, StatisAmmeterDateRequest requestVo); + + void exportAmmeterRevenueData(HttpServletResponse response, StatisAmmeterDateRequest requestVo); } diff --git a/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsStatsReportServiceImpl.java b/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsStatsReportServiceImpl.java index ac478f8..6efa8ca 100644 --- a/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsStatsReportServiceImpl.java +++ b/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsStatsReportServiceImpl.java @@ -31,6 +31,8 @@ import com.xzzn.ems.service.IEmsStatsReportService; import java.math.BigDecimal; import java.math.RoundingMode; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; @@ -40,10 +42,30 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.UUID; import java.util.stream.Collectors; +import javax.servlet.http.HttpServletResponse; + +import org.apache.poi.ss.usermodel.BorderStyle; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.FillPatternType; +import org.apache.poi.ss.usermodel.Font; +import org.apache.poi.ss.usermodel.HorizontalAlignment; +import org.apache.poi.ss.usermodel.IndexedColors; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.VerticalAlignment; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.util.IOUtils; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -57,6 +79,8 @@ import org.springframework.util.CollectionUtils; @Service public class EmsStatsReportServiceImpl implements IEmsStatsReportService { + private static final Logger log = LoggerFactory.getLogger(EmsStatsReportServiceImpl.class); + @Autowired private EmsPcsDataMapper emsPcsDataMapper; @Autowired @@ -236,11 +260,17 @@ public class EmsStatsReportServiceImpl implements IEmsStatsReportService Date startDate = requestVo.getStartDate(); Date endDate = requestVo.getEndDate(); - // 开始日期和结束日期同一天,展示 0-24 小时数据 +// // 开始日期和结束日期同一天,展示 0-24 小时数据 +// if (DateUtils.isSameDay(startDate, endDate)){ +// endDate = DateUtils.addDays(endDate, 1); +// requestVo.setEndDate(endDate); +// dataList = emsBatteryStackMapper.getStackDataByHour(requestVo); +// } + // 开始日期和结束日期同一天,按5分钟一个数据点展示数据 if (DateUtils.isSameDay(startDate, endDate)){ endDate = DateUtils.addDays(endDate, 1); requestVo.setEndDate(endDate); - dataList = emsBatteryStackMapper.getStackDataByHour(requestVo); + dataList = emsBatteryStackMapper.getStackDataByMinute(requestVo); } else if (DateUtils.differentDaysByMillisecond(endDate, startDate) >= 1 && DateUtils.differentDaysByMillisecond(endDate, startDate) < 30){ endDate = DateUtils.addDays(endDate, 1); @@ -594,4 +624,386 @@ public class EmsStatsReportServiceImpl implements IEmsStatsReportService dealRequestTime(requestVo); return emsBatteryDataDayMapper.getBatteryDayData(requestVo); } + + @Override + public void exportAmmeterData(HttpServletResponse response, StatisAmmeterDateRequest requestVo) { + Workbook workbook = new XSSFWorkbook(); + Sheet sheet = workbook.createSheet("电表报表"); + sheet.setDefaultColumnWidth(10); + sheet.setDefaultRowHeightInPoints(25); + + // 设置第一行 + Row row1 = sheet.createRow(0); + Cell cell1 = row1.createCell(0); + cell1.setCellValue("汇总"); + Cell cell2 = row1.createCell(1); + cell2.setCellValue("充电量"); + Cell cell3 = row1.createCell(6); + cell3.setCellValue("放电量"); + Cell cell4 = row1.createCell(11); + cell4.setCellValue("效率"); + + // 合并充电量列 + CellRangeAddress mergeRegion1 = new CellRangeAddress(0, 0, 1, 5); + sheet.addMergedRegion(mergeRegion1); + + // 合并放电量列 + CellRangeAddress mergeRegion2 = new CellRangeAddress(0, 0, 6, 10); + sheet.addMergedRegion(mergeRegion2); + + // 设置第二行 + Row row2 = sheet.createRow(1); + Cell cell5 = row2.createCell(0); + cell5.setCellValue("日期"); + Cell cell6 = row2.createCell(1); + cell6.setCellValue("尖"); + Cell cell7 = row2.createCell(2); + cell7.setCellValue("峰"); + Cell cell8 = row2.createCell(3); + cell8.setCellValue("平"); + Cell cell9 = row2.createCell(4); + cell9.setCellValue("谷"); + Cell cell10 = row2.createCell(5); + cell10.setCellValue("总"); + Cell cell11 = row2.createCell(6); + cell11.setCellValue("尖"); + Cell cell12 = row2.createCell(7); + cell12.setCellValue("峰"); + Cell cell13 = row2.createCell(8); + cell13.setCellValue("平"); + Cell cell14 = row2.createCell(9); + cell14.setCellValue("谷"); + Cell cell15 = row2.createCell(10); + cell15.setCellValue("总"); + Cell cell16 = row2.createCell(11); + cell16.setCellValue(""); + + // 设置背景颜色 + CellStyle headerStyle = workbook.createCellStyle(); + Font headerFont = workbook.createFont(); + headerFont.setBold(true); + headerStyle.setFont(headerFont); + headerStyle.setAlignment(HorizontalAlignment.CENTER); + headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); + headerStyle.setBorderTop(BorderStyle.THIN); + headerStyle.setBorderBottom(BorderStyle.THIN); + headerStyle.setBorderLeft(BorderStyle.THIN); + headerStyle.setBorderRight(BorderStyle.THIN); + headerStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex()); + headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + + // 应用样式到第一行和第二行 + Iterator row1CellIterator = row1.cellIterator(); + while (row1CellIterator.hasNext()) { + int i = row1CellIterator.next().getColumnIndex(); + row1.getCell(i).setCellStyle(headerStyle); + } + Iterator row2CellIterator = row2.cellIterator(); + while (row2CellIterator.hasNext()) { + int i = row2CellIterator.next().getColumnIndex(); + row2.getCell(i).setCellStyle(headerStyle); + } + + // 设置数据行颜色 + CellStyle row1Style = workbook.createCellStyle(); + row1Style.setAlignment(HorizontalAlignment.CENTER); + row1Style.setVerticalAlignment(VerticalAlignment.CENTER); + row1Style.setBorderTop(BorderStyle.THIN); + row1Style.setBorderBottom(BorderStyle.THIN); + row1Style.setBorderLeft(BorderStyle.THIN); + row1Style.setBorderRight(BorderStyle.THIN); + row1Style.setFillForegroundColor(IndexedColors.WHITE.getIndex()); + row1Style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + + CellStyle row2Style = workbook.createCellStyle(); + row2Style.setAlignment(HorizontalAlignment.CENTER); + row2Style.setVerticalAlignment(VerticalAlignment.CENTER); + row2Style.setBorderTop(BorderStyle.THIN); + row2Style.setBorderBottom(BorderStyle.THIN); + row2Style.setBorderLeft(BorderStyle.THIN); + row2Style.setBorderRight(BorderStyle.THIN); + row2Style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); + row2Style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + + + int rowIndex = 2; + // 查询电量报表数据,添加数据行 + List ammeterDataList = getAmmeterDataResult(requestVo); + for (int i = rowIndex; i < ammeterDataList.size() + rowIndex; i++) { + AmmeterStatisListVo ammeterStatisVo = ammeterDataList.get(i - rowIndex); + Row dataRow = sheet.createRow(i); + Cell dataCell1 = dataRow.createCell(0); + dataCell1.setCellValue(ammeterStatisVo.getDataTime()); + Cell dataCell2 = dataRow.createCell(1); + dataCell2.setCellValue(ammeterStatisVo.getActivePeakKwh().doubleValue()); + Cell dataCell3 = dataRow.createCell(2); + dataCell3.setCellValue(ammeterStatisVo.getActiveHighKwh().doubleValue()); + Cell dataCell4 = dataRow.createCell(3); + dataCell4.setCellValue(ammeterStatisVo.getActiveFlatKwh().doubleValue()); + Cell dataCell5 = dataRow.createCell(4); + dataCell5.setCellValue(ammeterStatisVo.getActiveValleyKwh().doubleValue()); + Cell dataCell6 = dataRow.createCell(5); + dataCell6.setCellValue(ammeterStatisVo.getActiveTotalKwh().doubleValue()); + Cell dataCell7 = dataRow.createCell(6); + dataCell7.setCellValue(ammeterStatisVo.getReActivePeakKwh().doubleValue()); + Cell dataCell8 = dataRow.createCell(7); + dataCell8.setCellValue(ammeterStatisVo.getReActiveHighKwh().doubleValue()); + Cell dataCell9 = dataRow.createCell(8); + dataCell9.setCellValue(ammeterStatisVo.getReActiveFlatKwh().doubleValue()); + Cell dataCell10 = dataRow.createCell(9); + dataCell10.setCellValue(ammeterStatisVo.getReActiveValleyKwh().doubleValue()); + Cell dataCell11 = dataRow.createCell(10); + dataCell11.setCellValue(ammeterStatisVo.getReActiveTotalKwh().doubleValue()); + Cell dataCell12 = dataRow.createCell(11); + dataCell12.setCellValue(ammeterStatisVo.getEffect().doubleValue()); + + // 根据行号设置背景色 + if (i % 2 == 0) { + for (int k = 0; k < dataRow.getLastCellNum(); k++) { + dataRow.getCell(k).setCellStyle(row1Style); + } + } else { + for (int k = 0; k < dataRow.getLastCellNum(); k++) { + dataRow.getCell(k).setCellStyle(row2Style); + } + } + } + + try + { + String fileName = "电表报表" + "_" + UUID.randomUUID() + ".xlsx"; + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8.name())); + workbook.write(response.getOutputStream()); + } + catch (Exception e) + { + log.error("导出电表报表异常{}", e.getMessage()); + } + finally + { + IOUtils.closeQuietly(workbook); + } + } + + @Override + public void exportAmmeterRevenueData(HttpServletResponse response, StatisAmmeterDateRequest requestVo) { + Workbook workbook = new XSSFWorkbook(); + Sheet sheet = workbook.createSheet("收益报表"); + sheet.setDefaultColumnWidth(10); + sheet.setDefaultRowHeightInPoints(25); + + // 设置第一行 + Row row1 = sheet.createRow(0); + Cell cell1 = row1.createCell(0); + cell1.setCellValue("汇总"); + Cell cell2 = row1.createCell(1); + cell2.setCellValue("充电价格"); + Cell cell3 = row1.createCell(6); + cell3.setCellValue("放电价格"); + Cell cell4 = row1.createCell(11); + cell4.setCellValue(""); + + // 合并充电量列 + CellRangeAddress mergeRegion1 = new CellRangeAddress(0, 0, 1, 5); + sheet.addMergedRegion(mergeRegion1); + + // 合并放电量列 + CellRangeAddress mergeRegion2 = new CellRangeAddress(0, 0, 6, 10); + sheet.addMergedRegion(mergeRegion2); + + // 设置第二行 + Row row2 = sheet.createRow(1); + Cell cell5 = row2.createCell(0); + cell5.setCellValue("日期"); + Cell cell6 = row2.createCell(1); + cell6.setCellValue("尖"); + Cell cell7 = row2.createCell(2); + cell7.setCellValue("峰"); + Cell cell8 = row2.createCell(3); + cell8.setCellValue("平"); + Cell cell9 = row2.createCell(4); + cell9.setCellValue("谷"); + Cell cell10 = row2.createCell(5); + cell10.setCellValue("总"); + Cell cell11 = row2.createCell(6); + cell11.setCellValue("尖"); + Cell cell12 = row2.createCell(7); + cell12.setCellValue("峰"); + Cell cell13 = row2.createCell(8); + cell13.setCellValue("平"); + Cell cell14 = row2.createCell(9); + cell14.setCellValue("谷"); + Cell cell15 = row2.createCell(10); + cell15.setCellValue("总"); + Cell cell16 = row2.createCell(11); + cell16.setCellValue("实际收益"); + + // 设置背景颜色 + CellStyle headerStyle = workbook.createCellStyle(); + Font headerFont = workbook.createFont(); + headerFont.setBold(true); + headerStyle.setFont(headerFont); + headerStyle.setAlignment(HorizontalAlignment.CENTER); + headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); + headerStyle.setBorderTop(BorderStyle.THIN); + headerStyle.setBorderBottom(BorderStyle.THIN); + headerStyle.setBorderLeft(BorderStyle.THIN); + headerStyle.setBorderRight(BorderStyle.THIN); + headerStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex()); + headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + + // 应用样式到第一行和第二行 + Iterator row1CellIterator = row1.cellIterator(); + while (row1CellIterator.hasNext()) { + int i = row1CellIterator.next().getColumnIndex(); + row1.getCell(i).setCellStyle(headerStyle); + } + Iterator row2CellIterator = row2.cellIterator(); + while (row2CellIterator.hasNext()) { + int i = row2CellIterator.next().getColumnIndex(); + row2.getCell(i).setCellStyle(headerStyle); + } + + // 设置数据行颜色 + CellStyle row1Style = workbook.createCellStyle(); + row1Style.setAlignment(HorizontalAlignment.CENTER); + row1Style.setVerticalAlignment(VerticalAlignment.CENTER); + row1Style.setBorderTop(BorderStyle.THIN); + row1Style.setBorderBottom(BorderStyle.THIN); + row1Style.setBorderLeft(BorderStyle.THIN); + row1Style.setBorderRight(BorderStyle.THIN); + row1Style.setFillForegroundColor(IndexedColors.WHITE.getIndex()); + row1Style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + + CellStyle row2Style = workbook.createCellStyle(); + row2Style.setAlignment(HorizontalAlignment.CENTER); + row2Style.setVerticalAlignment(VerticalAlignment.CENTER); + row2Style.setBorderTop(BorderStyle.THIN); + row2Style.setBorderBottom(BorderStyle.THIN); + row2Style.setBorderLeft(BorderStyle.THIN); + row2Style.setBorderRight(BorderStyle.THIN); + row2Style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); + row2Style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + + // 查询电量报表数据,添加数据行 + BigDecimal activeTotalPrice = BigDecimal.ZERO; + BigDecimal activePeakPrice = BigDecimal.ZERO; + BigDecimal activeHighPrice = BigDecimal.ZERO; + BigDecimal activeFlatPrice = BigDecimal.ZERO; + BigDecimal activeValleyPrice = BigDecimal.ZERO; + BigDecimal reActiveTotalPrice = BigDecimal.ZERO; + BigDecimal reActivePeakPrice = BigDecimal.ZERO; + BigDecimal reActiveHighPrice = BigDecimal.ZERO; + BigDecimal reActiveFlatPrice = BigDecimal.ZERO; + BigDecimal reActiveValleyPrice = BigDecimal.ZERO; + BigDecimal actualRevenue = BigDecimal.ZERO; + List ammeterRevenueDataList = getAmmeterRevenueDataResult(requestVo); + int rowIndex = 2; + int lastRowIndex = ammeterRevenueDataList.size() + rowIndex; + for (int i = rowIndex; i < lastRowIndex; i++) { + AmmeterRevenueStatisListVo ammeterRevenueStatisVo = ammeterRevenueDataList.get(i - rowIndex); + Row dataRow = sheet.createRow(i); + Cell dataCell1 = dataRow.createCell(0); + dataCell1.setCellValue(ammeterRevenueStatisVo.getDataTime()); + Cell dataCell2 = dataRow.createCell(1); + dataCell2.setCellValue(ammeterRevenueStatisVo.getActivePeakPrice().doubleValue()); + Cell dataCell3 = dataRow.createCell(2); + dataCell3.setCellValue(ammeterRevenueStatisVo.getActiveHighPrice().doubleValue()); + Cell dataCell4 = dataRow.createCell(3); + dataCell4.setCellValue(ammeterRevenueStatisVo.getActiveFlatPrice().doubleValue()); + Cell dataCell5 = dataRow.createCell(4); + dataCell5.setCellValue(ammeterRevenueStatisVo.getActiveValleyPrice().doubleValue()); + Cell dataCell6 = dataRow.createCell(5); + dataCell6.setCellValue(ammeterRevenueStatisVo.getActiveTotalPrice().doubleValue()); + Cell dataCell7 = dataRow.createCell(6); + dataCell7.setCellValue(ammeterRevenueStatisVo.getReActivePeakPrice().doubleValue()); + Cell dataCell8 = dataRow.createCell(7); + dataCell8.setCellValue(ammeterRevenueStatisVo.getReActiveHighPrice().doubleValue()); + Cell dataCell9 = dataRow.createCell(8); + dataCell9.setCellValue(ammeterRevenueStatisVo.getReActiveFlatPrice().doubleValue()); + Cell dataCell10 = dataRow.createCell(9); + dataCell10.setCellValue(ammeterRevenueStatisVo.getReActiveValleyPrice().doubleValue()); + Cell dataCell11 = dataRow.createCell(10); + dataCell11.setCellValue(ammeterRevenueStatisVo.getReActiveValleyPrice().doubleValue()); + Cell dataCell12 = dataRow.createCell(11); + dataCell12.setCellValue(ammeterRevenueStatisVo.getActualRevenue().doubleValue()); + + // 根据行号设置背景色 + if (i % 2 == 0) { + for (int k = 0; k < dataRow.getLastCellNum(); k++) { + dataRow.getCell(k).setCellStyle(row1Style); + } + } else { + for (int k = 0; k < dataRow.getLastCellNum(); k++) { + dataRow.getCell(k).setCellStyle(row2Style); + } + } + + // 最后一行合计 + activePeakPrice = activePeakPrice.add(ammeterRevenueStatisVo.getActivePeakPrice()); + activeHighPrice = activeHighPrice.add(ammeterRevenueStatisVo.getActiveHighPrice()); + activeFlatPrice = activeFlatPrice.add(ammeterRevenueStatisVo.getActiveFlatPrice()); + activeValleyPrice = activeValleyPrice.add(ammeterRevenueStatisVo.getActiveValleyPrice()); + activeTotalPrice = activeTotalPrice.add(ammeterRevenueStatisVo.getActiveTotalPrice()); + reActivePeakPrice = reActivePeakPrice.add(ammeterRevenueStatisVo.getReActivePeakPrice()); + reActiveHighPrice = reActiveHighPrice.add(ammeterRevenueStatisVo.getReActiveHighPrice()); + reActiveFlatPrice = reActiveFlatPrice.add(ammeterRevenueStatisVo.getReActiveFlatPrice()); + reActiveValleyPrice = reActiveValleyPrice.add(ammeterRevenueStatisVo.getReActiveValleyPrice()); + reActiveTotalPrice = reActiveTotalPrice.add(ammeterRevenueStatisVo.getReActiveTotalPrice()); + actualRevenue = actualRevenue.add(ammeterRevenueStatisVo.getActualRevenue()); + } + + if (!CollectionUtils.isEmpty(ammeterRevenueDataList)) { + // 设置第后一行 + Row lastRow = sheet.createRow(lastRowIndex); + Cell lastRowCell1 = lastRow.createCell(0); + lastRowCell1.setCellValue("合计"); + Cell lastRowCell2 = lastRow.createCell(1); + lastRowCell2.setCellValue(activePeakPrice.doubleValue()); + Cell lastRowCell3 = lastRow.createCell(2); + lastRowCell3.setCellValue(activeHighPrice.doubleValue()); + Cell lastRowCell4 = lastRow.createCell(3); + lastRowCell4.setCellValue(activeFlatPrice.doubleValue()); + Cell lastRowCell5 = lastRow.createCell(4); + lastRowCell5.setCellValue(activeValleyPrice.doubleValue()); + Cell lastRowCell6 = lastRow.createCell(5); + lastRowCell6.setCellValue(activeTotalPrice.doubleValue()); + Cell lastRowCell7 = lastRow.createCell(6); + lastRowCell7.setCellValue(reActivePeakPrice.doubleValue()); + Cell lastRowCell8 = lastRow.createCell(7); + lastRowCell8.setCellValue(reActiveHighPrice.doubleValue()); + Cell lastRowCell9 = lastRow.createCell(8); + lastRowCell9.setCellValue(reActiveFlatPrice.doubleValue()); + Cell lastRowCell10 = lastRow.createCell(9); + lastRowCell10.setCellValue(reActiveValleyPrice.doubleValue()); + Cell lastRowCell11 = lastRow.createCell(10); + lastRowCell11.setCellValue(reActiveTotalPrice.doubleValue()); + Cell lastRowCell12 = lastRow.createCell(11); + lastRowCell12.setCellValue(actualRevenue.doubleValue()); + Iterator lastRowCellIterator = lastRow.cellIterator(); + while (lastRowCellIterator.hasNext()) { + int i = lastRowCellIterator.next().getColumnIndex(); + lastRow.getCell(i).setCellStyle(headerStyle); + } + } + + try + { + String fileName = "收益报表" + "_" + UUID.randomUUID() + ".xlsx"; + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8.name())); + workbook.write(response.getOutputStream()); + } + catch (Exception e) + { + log.error("导出收益报表异常{}", e.getMessage()); + } + finally + { + IOUtils.closeQuietly(workbook); + } + } } diff --git a/ems-system/src/main/resources/mapper/ems/EmsBatteryStackMapper.xml b/ems-system/src/main/resources/mapper/ems/EmsBatteryStackMapper.xml index bd83e2e..aa7691f 100644 --- a/ems-system/src/main/resources/mapper/ems/EmsBatteryStackMapper.xml +++ b/ems-system/src/main/resources/mapper/ems/EmsBatteryStackMapper.xml @@ -531,6 +531,26 @@ GROUP BY t.site_id, t.group_time + +