新增电表报表、收益报表导出功能

This commit is contained in:
zq
2026-01-28 15:59:30 +08:00
parent 5a86769b40
commit 2b22b70baa
5 changed files with 481 additions and 7 deletions

View File

@ -1,19 +1,31 @@
package com.xzzn.web.controller.ems; package com.xzzn.web.controller.ems;
import com.xzzn.common.annotation.Log;
import com.xzzn.common.core.controller.BaseController; import com.xzzn.common.core.controller.BaseController;
import com.xzzn.common.core.domain.AjaxResult; import com.xzzn.common.core.domain.AjaxResult;
import com.xzzn.common.core.page.TableDataInfo; import com.xzzn.common.core.page.TableDataInfo;
import com.xzzn.common.enums.BusinessType;
import com.xzzn.common.utils.StringUtils; 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 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.ArrayList;
import java.util.List; 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); 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); 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);
}
/** /**
* 概率统计-功率曲线 * 概率统计-功率曲线
*/ */

View File

@ -93,4 +93,6 @@ public interface EmsBatteryStackMapper
public List<BatteryAveTempVo> getBatteryAveTempList(@Param("siteId")String siteId, @Param("startDate")Date yesterday, @Param("endDate") Date today); public List<BatteryAveTempVo> getBatteryAveTempList(@Param("siteId")String siteId, @Param("startDate")Date yesterday, @Param("endDate") Date today);
List<StackPointVo> getStackPointByMinute(DateSearchRequest requestVo); List<StackPointVo> getStackPointByMinute(DateSearchRequest requestVo);
List<StackStatisListVo> getStackDataByMinute(DateSearchRequest requestVo);
} }

View File

@ -5,6 +5,8 @@ import com.xzzn.ems.domain.vo.*;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletResponse;
/** /**
* 统计报表数据Service接口 * 统计报表数据Service接口
* *
@ -31,4 +33,8 @@ public interface IEmsStatsReportService
public List<PowerStatisListVo> getPowerDataList(DateSearchRequest requestVo); public List<PowerStatisListVo> getPowerDataList(DateSearchRequest requestVo);
public List<BatteryDataStatsListVo> getSingleBatteryData(DateSearchRequest requestVo); public List<BatteryDataStatsListVo> getSingleBatteryData(DateSearchRequest requestVo);
void exportAmmeterData(HttpServletResponse response, StatisAmmeterDateRequest requestVo);
void exportAmmeterRevenueData(HttpServletResponse response, StatisAmmeterDateRequest requestVo);
} }

View File

@ -31,6 +31,8 @@ import com.xzzn.ems.service.IEmsStatsReportService;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
@ -40,10 +42,30 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -57,6 +79,8 @@ import org.springframework.util.CollectionUtils;
@Service @Service
public class EmsStatsReportServiceImpl implements IEmsStatsReportService public class EmsStatsReportServiceImpl implements IEmsStatsReportService
{ {
private static final Logger log = LoggerFactory.getLogger(EmsStatsReportServiceImpl.class);
@Autowired @Autowired
private EmsPcsDataMapper emsPcsDataMapper; private EmsPcsDataMapper emsPcsDataMapper;
@Autowired @Autowired
@ -236,11 +260,17 @@ public class EmsStatsReportServiceImpl implements IEmsStatsReportService
Date startDate = requestVo.getStartDate(); Date startDate = requestVo.getStartDate();
Date endDate = requestVo.getEndDate(); 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)){ if (DateUtils.isSameDay(startDate, endDate)){
endDate = DateUtils.addDays(endDate, 1); endDate = DateUtils.addDays(endDate, 1);
requestVo.setEndDate(endDate); requestVo.setEndDate(endDate);
dataList = emsBatteryStackMapper.getStackDataByHour(requestVo); dataList = emsBatteryStackMapper.getStackDataByMinute(requestVo);
} else if (DateUtils.differentDaysByMillisecond(endDate, startDate) >= 1 } else if (DateUtils.differentDaysByMillisecond(endDate, startDate) >= 1
&& DateUtils.differentDaysByMillisecond(endDate, startDate) < 30){ && DateUtils.differentDaysByMillisecond(endDate, startDate) < 30){
endDate = DateUtils.addDays(endDate, 1); endDate = DateUtils.addDays(endDate, 1);
@ -594,4 +624,386 @@ public class EmsStatsReportServiceImpl implements IEmsStatsReportService
dealRequestTime(requestVo); dealRequestTime(requestVo);
return emsBatteryDataDayMapper.getBatteryDayData(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<Cell> row1CellIterator = row1.cellIterator();
while (row1CellIterator.hasNext()) {
int i = row1CellIterator.next().getColumnIndex();
row1.getCell(i).setCellStyle(headerStyle);
}
Iterator<Cell> 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<AmmeterStatisListVo> 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<Cell> row1CellIterator = row1.cellIterator();
while (row1CellIterator.hasNext()) {
int i = row1CellIterator.next().getColumnIndex();
row1.getCell(i).setCellStyle(headerStyle);
}
Iterator<Cell> 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<AmmeterRevenueStatisListVo> 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<Cell> 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);
}
}
} }

View File

@ -531,6 +531,26 @@
GROUP BY t.site_id, t.group_time GROUP BY t.site_id, t.group_time
</select> </select>
<select id="getStackDataByMinute" parameterType="com.xzzn.ems.domain.vo.DateSearchRequest" resultType="com.xzzn.ems.domain.vo.StackStatisListVo">
WITH ranked AS (
SELECT
*,
DATE_FORMAT(DATE_ADD(DATE_FORMAT(p.update_time, '%Y-%m-%d %H:00:00'), INTERVAL CEIL(MINUTE(p.update_time) / 5) * 5 MINUTE)
, '%Y-%m-%d %H:%i:%s') AS group_time,
ROW_NUMBER() OVER (PARTITION BY p.device_id, date_format(p.update_time, '%Y-%m-%d %H:00:00'), CEIL(MINUTE(p.update_time) / 5) ORDER BY p.data_update_time DESC) as rn
FROM
ems_battery_stack p
<include refid="statisCommonFilter"/>
)
SELECT
t.site_id,
DATE_FORMAT(t.group_time, '%Y-%m-%d %H:%i:%s') as statisDate,
<include refid="dataTypeChooseFilter"/>
FROM
ranked as t
where t.rn = 1
</select>
<select id="getAveSocList" resultType="com.xzzn.ems.domain.vo.BatteryAveSOCVo"> <select id="getAveSocList" resultType="com.xzzn.ems.domain.vo.BatteryAveSOCVo">
WITH ranked AS ( WITH ranked AS (
SELECT SELECT