|
@@ -9,13 +9,18 @@ import com.ims.eval.dao.PerformanceBenchmarkInfoMapper;
|
|
|
import com.ims.eval.entity.*;
|
|
|
import com.ims.eval.service.*;
|
|
|
import lombok.Data;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -68,6 +73,89 @@ public class PerformanceBenchmarkInfoServiceImpl extends ServiceImpl<Performance
|
|
|
return baseMapper.selectListPage(page, manageCategory, checkCycle, degreeYear, quarterlyMonth, isBg, isDb, isCb);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void exportExcel(String toolCategory, String manageCategory, String checkCycle, Integer degreeYear, Integer quarterlyMonth, HttpServletResponse response) throws IOException {
|
|
|
+ // 设置响应头信息,以附件形式下载
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=performance_benchmark_data.xlsx");
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+
|
|
|
+ // 创建新的Excel工作簿
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
+
|
|
|
+ // 创建新的工作表
|
|
|
+ Sheet sheet = workbook.createSheet("Sheet1");
|
|
|
+
|
|
|
+ // 创建表头
|
|
|
+ Row headerRow = sheet.createRow(0);
|
|
|
+ List<String> headers = Arrays.asList("ID", "序号", "单位", "装机容量", "指标", "计划值", "实际完成值", "推荐值", "定标值", "是否标杆");
|
|
|
+ for (int i = 0; i < headers.size(); i++) {
|
|
|
+ Cell cell = headerRow.createCell(i);
|
|
|
+ cell.setCellValue(headers.get(i));
|
|
|
+ }
|
|
|
+
|
|
|
+ //行数据
|
|
|
+ int isBg = 0;
|
|
|
+ int isDb = 0;
|
|
|
+ int isCb = 0;
|
|
|
+ if ("标杆".equals(toolCategory)) {
|
|
|
+ isBg = 1;
|
|
|
+ } else if ("达标".equals(toolCategory)) {
|
|
|
+ isDb = 2;
|
|
|
+ } else if ("超标".equals(toolCategory)) {
|
|
|
+ isCb = 3;
|
|
|
+ }
|
|
|
+ List<PerformanceBenchmarkInfo> performanceBenchmarkInfoList = baseMapper.getExportExcelData(manageCategory, checkCycle, degreeYear, quarterlyMonth, isBg, isDb, isCb);
|
|
|
+
|
|
|
+ // 填充数据到工作表
|
|
|
+ int rowIndex = 1; // 从第二行开始填充数据(第一行是表头)
|
|
|
+ for (PerformanceBenchmarkInfo performanceBenchmarkInfo : performanceBenchmarkInfoList) {
|
|
|
+ Row row = sheet.createRow(rowIndex++);
|
|
|
+
|
|
|
+ // 设置ID
|
|
|
+ row.createCell(0).setCellValue(performanceBenchmarkInfo.getId());
|
|
|
+
|
|
|
+ // 设置序号
|
|
|
+ row.createCell(1).setCellValue(rowIndex - 1);
|
|
|
+
|
|
|
+ // 设置其他数据
|
|
|
+ row.createCell(2).setCellValue(performanceBenchmarkInfo.getCompanyShort());
|
|
|
+ if (null != performanceBenchmarkInfo.getInstallCapacity()) {
|
|
|
+ row.createCell(3).setCellValue(performanceBenchmarkInfo.getInstallCapacity());
|
|
|
+ }
|
|
|
+ row.createCell(4).setCellValue(performanceBenchmarkInfo.getIndexName());
|
|
|
+ if (null != performanceBenchmarkInfo.getPlannedValue()) {
|
|
|
+ row.createCell(5).setCellValue(performanceBenchmarkInfo.getPlannedValue());
|
|
|
+ }
|
|
|
+ if (null != performanceBenchmarkInfo.getCompleteValue()) {
|
|
|
+ row.createCell(6).setCellValue(performanceBenchmarkInfo.getCompleteValue());
|
|
|
+ }
|
|
|
+ if (null != performanceBenchmarkInfo.getRecommendedValue()) {
|
|
|
+ row.createCell(7).setCellValue(performanceBenchmarkInfo.getRecommendedValue());
|
|
|
+ }
|
|
|
+ if (null != performanceBenchmarkInfo.getScalingValue()) {
|
|
|
+ row.createCell(8).setCellValue(performanceBenchmarkInfo.getScalingValue());
|
|
|
+ }
|
|
|
+ if (1 == performanceBenchmarkInfo.getIsBg()) {
|
|
|
+ row.createCell(9).setCellValue("是");
|
|
|
+ } else if (0 == performanceBenchmarkInfo.getIsBg()) {
|
|
|
+ row.createCell(9).setCellValue("否");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 隐藏第一列(ID列)
|
|
|
+ sheet.setColumnHidden(0, true);
|
|
|
+
|
|
|
+ // 将工作簿写入到输出流
|
|
|
+ try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
|
|
+ workbook.write(outputStream);
|
|
|
+ response.getOutputStream().write(outputStream.toByteArray());
|
|
|
+ response.getOutputStream().flush();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关闭工作簿
|
|
|
+ workbook.close();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 寻标
|
|
|
*
|