java导出excel动态加载多sheet多复杂表头
实体
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.ToString;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.sql.Date;
@Data
@Accessors(chain = true)
public class CurrentPlanCityTunePowerVo implements Serializable {
private static final long serialVersionUID = 1L;
private String dateTime;
private Double output;
private String id;
private String areaName;
private String type;
}
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
@Data
@Accessors(chain = true)
public class DayPlanArchiveHeadVo implements Serializable {
private static final long serialVersionUID = 1L;
private Map<String, String> rqjhMenuMap;
private Map<String, List<String>> head1Map;
private Map<String, List<String>> waterHead1Map;
}
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
@Data
@Accessors(chain = true)
public class DayPlanArchiveResultVo implements Serializable {
private static final long serialVersionUID = 1L;
private List<DayPlanArchiveVo> dayPlanArchiveVoList;
private List<CurrentPlanCityTunePowerVo> currentPlanCityTunePowerVoList;
}
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
@Data
@Accessors(chain = true)
public class DayPlanArchiveVo implements Serializable {
private static final long serialVersionUID = 1L;
private Date dateTime;
private Double output;
private String stationId;
private String shortName;
private String schedulingLevel;
private String region;
private String stationType;
private String category;
private String vol;
private String tunePower;
}
实现类
@Override
public void export(String date, String txtName, HttpServletResponse response) {
XSSFWorkbook wb = new XSSFWorkbook();
try {
DayPlanArchiveResultVo dayPlanArchiveResultVo = this.listDayPlanArchive(new DayPlanArchiveDto().setTxtName(txtName));
List<DayPlanArchiveVo> dayPlanArchiveVoList = dayPlanArchiveResultVo.getDayPlanArchiveVoList();
double allTypeSum = Math.floor(dayPlanArchiveVoList.stream().mapToDouble(DayPlanArchiveVo::getOutput).sum() / 4);
Map<String, Double> allTypeByTimeSumMap = dayPlanArchiveVoList.stream().collect(Collectors.groupingBy(vo -> SDF.format(vo.getDateTime()), TreeMap::new, Collectors.summingDouble(DayPlanArchiveVo::getOutput)));
List<String> dateList = new ArrayList<>(allTypeByTimeSumMap.keySet());
typeList().forEach(typeStr -> {
XSSFSheet sheet = wb.createSheet(typeStr);
if ("测试数据".equals(typeStr)) {
addHyPowerSheet(typeStr, date, sheet, (List<DayPlanArchiveVo>) SerializationUtils.clone((Serializable) dayPlanArchiveVoList), allTypeSum, allTypeByTimeSumMap, dateList);
} else if ("测试数据".equals(typeStr)) {
addTunePowerSheet(typeStr, date, wb, sheet, dayPlanArchiveResultVo.getCurrentPlanCityTunePowerVoList(), allTypeSum, allTypeByTimeSumMap, dateList);
} else {
addSheet(typeStr, date, sheet, (List<DayPlanArchiveVo>) SerializationUtils.clone((Serializable) dayPlanArchiveVoList), allTypeSum, allTypeByTimeSumMap, dateList);
}
XSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setAlignment(HorizontalAlignment.CENTER);
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
for (int i = 0; i < sheet.getLastRowNum(); i++) {
XSSFRow row = sheet.getRow(i);
if (row != null) {
for (int j = 0; j < row.getLastCellNum(); j++) {
if (row.getCell(j) != null) {
row.getCell(j).setCellStyle(cellStyle);
}
}
}
}
});
String fileName = txtName.substring(0, txtName.indexOf(".")) + ".xlsx";
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8"));
response.flushBuffer();
OutputStream stream = response.getOutputStream();
if (null != stream) {
wb.write(stream);
wb.close();
stream.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(wb);
}
}
sheet方法
private void addSheet(String type, String date, XSSFSheet sheet, List<DayPlanArchiveVo> dayPlanArchiveVoList, double allTypeSum, Map<String, Double> allTypeByTimeSumMap, List<String> dateList) {
String typeName = type;
if ("光伏".equals(typeName)) {
typeName = "太阳能";
}
String finalTypeName = typeName;
List<DayPlanArchiveVo> hyPowerList = dayPlanArchiveVoList.stream().filter(vo -> finalTypeName.equals(vo.getCategory())).collect(Collectors.toList());
Map<String, String> rqjhMenuMap = rqjhMenu(type, date).getRqjhMenuMap();
hyPowerList.forEach(vo -> rqjhMenuMap.entrySet().stream()
.filter(entry -> entry.getKey().equals(vo.getStationId()))
.findFirst()
.ifPresent(entry -> vo.setShortName(entry.getValue())));
Map<String, Double> typeSumMap = hyPowerList.stream().collect(Collectors.groupingBy(vo -> SDF.format(vo.getDateTime()), TreeMap::new, Collectors.summingDouble(DayPlanArchiveVo::getOutput)));
Map<String, Double> hyPowerMap = hyPowerList.stream().collect(Collectors.toMap(vo -> SDF.format(vo.getDateTime()) + vo.getShortName(), DayPlanArchiveVo::getOutput));
Map<String, List<String>> head1Map = rqjhMenu(type, date).getHead1Map();
List<String> sortRegionList = head1Map.keySet().stream().sorted(Comparator.comparingInt(sortList()::indexOf)).collect(Collectors.toList());
List<String> header1StrList = new ArrayList<>();
header1StrList.add("时间");
header1StrList.add("全网");
header1StrList.add(type);
List<String> header2StrList = new ArrayList<>();
header2StrList.add("");
header2StrList.add("测试数据");
header2StrList.add("测试数据");
for (String s : sortRegionList) {
header1StrList.add(s);
List<String> stringList = head1Map.get(s);
for (int i = 0; i < stringList.size(); i++) {
header2StrList.add(stringList.get(i));
header1StrList.add("");
}
header2StrList.add(s + "合计");
}
System.out.println("第一行表头赋值" + header1StrList);
System.out.println("第二行表头赋值" + header2StrList);
int rowNum = 0;
XSSFRow row0 = sheet.createRow(rowNum++);
row0.setHeight((short) 600);
for (int i = 0; i < header1StrList.size(); i++) {
XSSFCell c00 = row0.createCell(i);
c00.setCellValue(header1StrList.get(i));
}
sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
int startCol = 3;
int endCol;
for (String s : sortRegionList) {
List<String> stringList = head1Map.get(s);
endCol = startCol + stringList.size();
sheet.addMergedRegion(new CellRangeAddress(0, 0, startCol, endCol));
System.out.println("第一行表头索引" + startCol + ":" + endCol);
startCol = endCol + 1;
}
XSSFRow row2 = sheet.createRow(rowNum++);
row2.setHeight((short) 700);
for (int i = 0; i < header2StrList.size(); i++) {
XSSFCell tempCell = row2.createCell(i);
tempCell.setCellValue(header2StrList.get(i));
if (i > 0) {
sheet.setColumnWidth(i, header2StrList.get(i).getBytes(StandardCharsets.UTF_8).length * 256);
}
}
Map<String, Double> statisticsMap = hyPowerList.stream().collect(Collectors.groupingBy(DayPlanArchiveVo::getShortName, Collectors.summingDouble(DayPlanArchiveVo::getOutput)));
statisticsMap.replaceAll((key, value) -> Math.floor(value / 4));
double currentTypeSum = Math.floor(hyPowerList.stream().mapToDouble(DayPlanArchiveVo::getOutput).sum() / 4);
List<String> header3StrList = new ArrayList<>();
header3StrList.add("合计");
header3StrList.add(String.valueOf(allTypeSum));
header3StrList.add(String.valueOf(currentTypeSum));
for (String s : sortRegionList) {
Double cityTotal = 0.0;
List<String> stringList = head1Map.get(s);
for (int i = 0; i < stringList.size(); i++) {
Double stationTotal = statisticsMap.get(stringList.get(i));
if (stationTotal == null) {
header3StrList.add("");
cityTotal += 0.0;
} else {
header3StrList.add(String.valueOf(stationTotal));
cityTotal += stationTotal;
}
}
header3StrList.add(String.valueOf(cityTotal));
}
XSSFRow row3 = sheet.createRow(rowNum++);
row3.setHeight((short) 700);
for (int i = 0; i < header3StrList.size(); i++) {
XSSFCell tempCell = row3.createCell(i);
if (i > 0) {
if (StringUtils.isNotEmpty(header3StrList.get(i))) {
tempCell.setCellValue(Double.parseDouble(header3StrList.get(i)));
} else {
tempCell.setCellValue(header3StrList.get(i));
}
} else {
tempCell.setCellValue(header3StrList.get(i));
}
}
List<List<String>> itemList = new ArrayList<>();
dateList.forEach(dateStr -> {
List<String> voList = new ArrayList<>();
voList.add(dateStr);
voList.add(String.valueOf(allTypeByTimeSumMap.get(dateStr)));
voList.add(String.valueOf(typeSumMap.get(dateStr) == null ? "0" : typeSumMap.get(dateStr)));
for (String key : sortRegionList) {
Double totalByTime = 0.0;
List<String> head2List = head1Map.get(key);
for (String shortName : head2List) {
Double output = hyPowerMap.get(dateStr + shortName);
if (output != null) {
Double aDouble = Math.floor(hyPowerMap.get(dateStr + shortName));
totalByTime += aDouble;
voList.add(String.valueOf(aDouble));
} else {
voList.add("");
}
}
voList.add(String.valueOf(totalByTime));
}
itemList.add(voList);
});
for (List<String> stringList : itemList) {
XSSFRow row = sheet.createRow(rowNum++);
row3.setHeight((short) 700);
for (int i = 0; i < stringList.size(); i++) {
XSSFCell tempCell = row.createCell(i);
if (i > 0) {
if (StringUtils.isEmpty(stringList.get(i))) {
tempCell.setCellValue(stringList.get(i));
} else {
tempCell.setCellValue(Double.parseDouble(stringList.get(i)));
}
} else {
tempCell.setCellValue(stringList.get(i));
}
}
}
}
private void addHyPowerSheet(String type, String date, XSSFSheet sheet, List<DayPlanArchiveVo> dayPlanArchiveVoList, double allTypeSum, Map<String, Double> allTypeByTimeSumMap, List<String> dateList) {
List<DayPlanArchiveVo> hyPowerList = dayPlanArchiveVoList.stream().filter(vo -> type.equals(vo.getCategory())).collect(Collectors.toList());
Map<String, String> rqjhMenuMap = rqjhMenu(type, date).getRqjhMenuMap();
hyPowerList.forEach(vo -> rqjhMenuMap.entrySet().stream()
.filter(entry -> entry.getKey().equals(vo.getStationId()))
.findFirst()
.ifPresent(entry -> vo.setShortName(entry.getValue())));
Map<String, Double> typeSumMap = hyPowerList.stream().collect(Collectors.groupingBy(vo -> SDF.format(vo.getDateTime()), TreeMap::new, Collectors.summingDouble(DayPlanArchiveVo::getOutput)));
Map<String, Double> hyPowerMap = hyPowerList.stream().collect(Collectors.toMap(vo -> SDF.format(vo.getDateTime()) + vo.getShortName(), DayPlanArchiveVo::getOutput));
Map<String, List<String>> head1Map = new HashMap<>(rqjhMenu(type, date).getWaterHead1Map());
List<String> sortRegionList = head1Map.keySet().stream().sorted(Comparator.comparingInt(sortList()::indexOf)).collect(Collectors.toList());
List<String> header1StrList = new ArrayList<>();
header1StrList.add("时间");
header1StrList.add("全网");
header1StrList.add(type);
List<String> header2StrList = new ArrayList<>();
header2StrList.add("");
header2StrList.add("测试数据");
header2StrList.add("测试数据");
for (String s : sortRegionList) {
header1StrList.add(s);
List<String> stringList = head1Map.get(s);
for (int i = 0; i < stringList.size(); i++) {
header2StrList.add(stringList.get(i));
header1StrList.add("");
}
header2StrList.add(s + "合计");
}
System.out.println("第一行表头赋值" + header1StrList);
System.out.println("第二行表头赋值" + header2StrList);
int rowNum = 0;
XSSFRow row0 = sheet.createRow(rowNum++);
row0.setHeight((short) 600);
for (int i = 0; i < header1StrList.size(); i++) {
XSSFCell c00 = row0.createCell(i);
c00.setCellValue(header1StrList.get(i));
}
sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
int startCol = 3;
int endCol;
for (String s : sortRegionList) {
List<String> stringList = head1Map.get(s);
endCol = startCol + stringList.size();
sheet.addMergedRegion(new CellRangeAddress(0, 0, startCol, endCol));
System.out.println("第一行表头索引" + startCol + ":" + endCol);
startCol = endCol + 1;
}
XSSFRow row2 = sheet.createRow(rowNum++);
row2.setHeight((short) 700);
for (int i = 0; i < header2StrList.size(); i++) {
XSSFCell tempCell = row2.createCell(i);
tempCell.setCellValue(header2StrList.get(i));
if (i > 0) {
sheet.setColumnWidth(i, header2StrList.get(i).getBytes(StandardCharsets.UTF_8).length * 256);
}
}
Map<String, Double> statisticsMap = hyPowerList.stream().collect(Collectors.groupingBy(DayPlanArchiveVo::getShortName, Collectors.summingDouble(DayPlanArchiveVo::getOutput)));
statisticsMap.replaceAll((key, value) -> Math.floor(value / 4));
double currentTypeSum = Math.floor(hyPowerList.stream().mapToDouble(DayPlanArchiveVo::getOutput).sum() / 4);
List<String> header3StrList = new ArrayList<>();
header3StrList.add("合计");
header3StrList.add(String.valueOf(allTypeSum));
header3StrList.add(String.valueOf(currentTypeSum));
for (String s : sortRegionList) {
Double cityTotal = 0.0;
List<String> stringList = head1Map.get(s);
for (int i = 0; i < stringList.size(); i++) {
Double stationTotal = statisticsMap.get(stringList.get(i));
if (stationTotal == null) {
header3StrList.add("");
cityTotal += 0.0;
} else {
header3StrList.add(String.valueOf(stationTotal));
cityTotal += stationTotal;
}
}
header3StrList.add(String.valueOf(cityTotal));
}
XSSFRow row3 = sheet.createRow(rowNum++);
row3.setHeight((short) 700);
for (int i = 0; i < header3StrList.size(); i++) {
XSSFCell tempCell = row3.createCell(i);
if (i > 0) {
if (StringUtils.isNotEmpty(header3StrList.get(i))) {
tempCell.setCellValue(Double.parseDouble(header3StrList.get(i)));
} else {
tempCell.setCellValue(header3StrList.get(i));
}
} else {
tempCell.setCellValue(header3StrList.get(i));
}
}
List<List<String>> itemList = new ArrayList<>();
dateList.forEach(dateStr -> {
List<String> voList = new ArrayList<>();
voList.add(dateStr);
voList.add(String.valueOf(allTypeByTimeSumMap.get(dateStr)));
voList.add(String.valueOf(typeSumMap.get(dateStr)));
for (String key : sortRegionList) {
Double totalByTime = 0.0;
List<String> head2List = head1Map.get(key);
for (String shortName : head2List) {
Double output = hyPowerMap.get(dateStr + shortName);
if (output != null) {
Double aDouble = Math.floor(hyPowerMap.get(dateStr + shortName));
totalByTime += aDouble;
voList.add(String.valueOf(aDouble));
} else {
voList.add("");
}
}
voList.add(String.valueOf(totalByTime));
}
itemList.add(voList);
});
for (List<String> stringList : itemList) {
XSSFRow row = sheet.createRow(rowNum++);
row3.setHeight((short) 700);
for (int i = 0; i < stringList.size(); i++) {
XSSFCell tempCell = row.createCell(i);
if (i > 0) {
if (StringUtils.isEmpty(stringList.get(i))) {
tempCell.setCellValue(stringList.get(i));
} else {
tempCell.setCellValue(Double.parseDouble(stringList.get(i)));
}
} else {
tempCell.setCellValue(stringList.get(i));
}
}
}
}
private void addTunePowerSheet(String type, String date, XSSFWorkbook wb, XSSFSheet sheet, List<CurrentPlanCityTunePowerVo> dayPlanArchiveVoList, double allTypeSum, Map<String, Double> allTypeByTimeSumMap, List<String> dateList) {
List<CurrentPlanCityTunePowerVo> currentPlanCityTunePowerVoList = (List<CurrentPlanCityTunePowerVo>) SerializationUtils.clone((Serializable) dayPlanArchiveVoList);
List<CurrentPlanCityTunePowerVo> filterList = currentPlanCityTunePowerVoList.stream().filter(vo -> vo.getOutput() != null).collect(Collectors.toList());
Map<String, Double> tunePowerMap = filterList.stream().collect(Collectors.toMap(vo -> vo.getDateTime() + vo.getAreaName() + vo.getType(), CurrentPlanCityTunePowerVo::getOutput));
Map<String, List<String>> head1Map = dayPlanArchiveVoList.stream().filter(vo -> vo.getAreaName() != null).collect(Collectors.groupingBy(CurrentPlanCityTunePowerVo::getAreaName,
Collectors.mapping(CurrentPlanCityTunePowerVo::getType, Collectors.collectingAndThen(Collectors.toList(), values -> values.stream().distinct().collect(Collectors.toList())))));
List<String> sortRegionList = head1Map.keySet().stream().sorted(Comparator.comparingInt(sortList()::indexOf)).collect(Collectors.toList());
List<String> header1StrList = new ArrayList<>();
header1StrList.add("时间");
header1StrList.add("全网");
header1StrList.add(type);
header1StrList.add("测试数据");
header1StrList.add("测试数据");
header1StrList.add("测试数据");
List<String> header2StrList = new ArrayList<>();
header2StrList.add("");
header2StrList.add("测试数据");
header2StrList.add("测试数据");
header2StrList.add("测试数据");
header2StrList.add("测试数据");
header2StrList.add("测试数据");
for (String s : sortRegionList) {
header1StrList.add(s);
List<String> stringList = head1Map.get(s);
for (int i = 0; i < stringList.size(); i++) {
header2StrList.add(s.substring(0, s.length() - 1) + stringList.get(i));
header1StrList.add("");
}
header2StrList.add(s + "合计");
}
System.out.println("第一行表头赋值" + header1StrList);
System.out.println("第二行表头赋值" + header2StrList);
int rowNum = 0;
XSSFRow row0 = sheet.createRow(rowNum++);
row0.setHeight((short) 600);
for (int i = 0; i < header1StrList.size(); i++) {
XSSFCell c00 = row0.createCell(i);
c00.setCellValue(header1StrList.get(i));
}
sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
int startCol = 6;
int endCol;
for (String s : sortRegionList) {
List<String> stringList = head1Map.get(s);
endCol = startCol + stringList.size();
sheet.addMergedRegion(new CellRangeAddress(0, 0, startCol, endCol));
System.out.println("第一行表头索引" + startCol + ":" + endCol);
startCol = endCol + 1;
}
XSSFRow row2 = sheet.createRow(rowNum++);
row2.setHeight((short) 700);
for (int i = 0; i < header2StrList.size(); i++) {
XSSFCell tempCell = row2.createCell(i);
tempCell.setCellValue(header2StrList.get(i));
if (i > 0) {
sheet.setColumnWidth(i, header2StrList.get(i).getBytes(StandardCharsets.UTF_8).length * 256);
}
}
Map<String, Map<String, Double>> cityTypeMap = filterList.stream().filter(vo -> vo.getAreaName() != null).collect(Collectors.groupingBy(CurrentPlanCityTunePowerVo::getAreaName, TreeMap::new, Collectors.groupingBy(CurrentPlanCityTunePowerVo::getType, Collectors.summingDouble(CurrentPlanCityTunePowerVo::getOutput))));
List<String> header3StrList = new ArrayList<>();
header3StrList.add("合计");
header3StrList.add(String.valueOf(allTypeSum));
double currentTypeSum = Math.floor(filterList.stream().mapToDouble(CurrentPlanCityTunePowerVo::getOutput).sum() / 4);
header3StrList.add(String.valueOf(currentTypeSum));
Map<String, Double> perfectrueMap = filterList.stream().filter(vo -> vo.getAreaName() == null).collect(Collectors.groupingBy(CurrentPlanCityTunePowerVo::getType, Collectors.summingDouble(CurrentPlanCityTunePowerVo::getOutput)));
header3StrList.add(String.valueOf(perfectrueMap.get("测试数据")));
header3StrList.add(String.valueOf(perfectrueMap.get("测试数据")));
header3StrList.add(String.valueOf(perfectrueMap.get("测试数据")));
for (String s : sortRegionList) {
Double cityTotal = 0.0;
List<String> stringList = head1Map.get(s);
for (int i = 0; i < stringList.size(); i++) {
Double stationTotal = cityTypeMap.get(s).get(stringList.get(i));
if (stationTotal == null) {
header3StrList.add("0");
cityTotal += 0.0;
} else {
header3StrList.add(String.valueOf(stationTotal));
cityTotal += stationTotal;
}
}
header3StrList.add(String.valueOf(cityTotal));
}
XSSFRow row3 = sheet.createRow(rowNum++);
row3.setHeight((short) 700);
for (int i = 0; i < header3StrList.size(); i++) {
XSSFCell tempCell = row3.createCell(i);
if (i > 0) {
if (StringUtils.isNotEmpty(header3StrList.get(i))) {
tempCell.setCellValue(Double.parseDouble(header3StrList.get(i)));
} else {
tempCell.setCellValue(header3StrList.get(i));
}
} else {
tempCell.setCellValue(header3StrList.get(i));
}
}
Map<String, Double> typeSumMap = filterList.stream().filter(vo -> vo.getAreaName() != null).collect(Collectors.groupingBy(CurrentPlanCityTunePowerVo::getDateTime, TreeMap::new, Collectors.summingDouble(CurrentPlanCityTunePowerVo::getOutput)));
Map<String, Map<String, Double>> tunePreFectureMap = filterList.stream().filter(vo -> vo.getAreaName() == null).collect(Collectors.groupingBy(CurrentPlanCityTunePowerVo::getDateTime, TreeMap::new, Collectors.groupingBy(CurrentPlanCityTunePowerVo::getType, Collectors.summingDouble(CurrentPlanCityTunePowerVo::getOutput))));
List<List<String>> itemList = new ArrayList<>();
dateList.forEach(dateStr -> {
List<String> voList = new ArrayList<>();
voList.add(dateStr);
voList.add(String.valueOf(allTypeByTimeSumMap.get(dateStr)));
voList.add(String.valueOf(typeSumMap.get(dateStr)));
voList.add(String.valueOf(tunePreFectureMap.get(dateStr).get("测试数据")));
voList.add(String.valueOf(tunePreFectureMap.get(dateStr).get("测试数据")));
voList.add(String.valueOf(tunePreFectureMap.get(dateStr).get("测试数据")));
for (String key : sortRegionList) {
Double totalByTime = 0.0;
List<String> head2List = head1Map.get(key);
for (String shortName : head2List) {
Double output = tunePowerMap.get(dateStr + key + shortName);
if (output != null) {
Double aDouble = Math.floor(tunePowerMap.get(dateStr + key + shortName));
totalByTime += aDouble;
voList.add(String.valueOf(aDouble));
} else {
voList.add("");
}
}
voList.add(String.valueOf(totalByTime));
}
itemList.add(voList);
});
for (List<String> stringList : itemList) {
XSSFRow row = sheet.createRow(rowNum++);
row3.setHeight((short) 700);
for (int i = 0; i < stringList.size(); i++) {
XSSFCell tempCell = row.createCell(i);
if (i > 0) {
if (StringUtils.isEmpty(stringList.get(i))) {
tempCell.setCellValue(stringList.get(i));
} else {
tempCell.setCellValue(Double.parseDouble(stringList.get(i)));
}
} else {
tempCell.setCellValue(stringList.get(i));
}
}
}
}
业务工具方法
private List<String> typeList() {
return Arrays.asList("水电", "风电", "光伏", "储能", "小火电", "地调发电");
}
private DayPlanArchiveHeadVo rqjhMenu(String type, String date) {
DayPlanArchiveHeadVo dayPlanArchiveHeadVo = new DayPlanArchiveHeadVo();
List<PowerStationInfo> powerStationInfoList = powerStationWhService.rqjhMenu(jsonObject);
Map<String, List<String>> head1Map = powerStationInfoList.stream()
.collect(Collectors.groupingBy(PowerStationInfo::getDispatchingAgency,
Collectors.mapping(PowerStationInfo::getName, Collectors.collectingAndThen(Collectors.toList(), values -> values.stream().distinct().collect(Collectors.toList())))));
Map<String, String> rqjhMenuMap = powerStationInfoList.stream().collect(Collectors.toMap(PowerStationInfo::getId, PowerStationInfo::getName));
dayPlanArchiveHeadVo.setHead1Map(head1Map);
dayPlanArchiveHeadVo.setRqjhMenuMap(rqjhMenuMap);
if ("水电".equals(type)) {
Map<String, List<String>> waterHead1Map = new HashMap<>();
waterHead1Map.putAll(powerStationInfoList.stream()
.collect(Collectors.groupingBy(PowerStationInfo::getDispatchingAgency,
Collectors.mapping(PowerStationInfo::getName, Collectors.collectingAndThen(Collectors.toList(), values -> values.stream().distinct().collect(Collectors.toList()))))));
dayPlanArchiveHeadVo.setWaterHead1Map(waterHead1Map);
}
return dayPlanArchiveHeadVo;
}
private List<String> sortList() {
return Arrays.asList("网调", "省调", "长沙市", "湘潭市", "益阳市", "株洲市", "岳阳市", "常德市", "湘西州", "张家界市", "娄底市", "邵阳市", "怀化市", "衡阳市", "郴州市", "永州市");
}
实现效果