|
@@ -6,6 +6,7 @@ import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -997,13 +998,13 @@ public class SubInfoExportController extends BaseController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 导出重点项目明细表
|
|
|
+ * 导出重点项目新建明细表
|
|
|
*
|
|
|
* @param response
|
|
|
* @param vo
|
|
|
*/
|
|
|
- @PostMapping("/exportFixDetailExcel")
|
|
|
- public void exportFixDetailExcel(HttpServletResponse response, @RequestBody SubInfoQueryTzVO vo) throws IOException {
|
|
|
+ @PostMapping("/exportFixXjDetailExcel")
|
|
|
+ public void exportFixXjDetailExcel(HttpServletResponse response, @RequestBody SubInfoQueryTzVO vo) throws IOException {
|
|
|
try (cn.hutool.poi.excel.ExcelWriter writer = ExcelUtil.getBigWriter();
|
|
|
ServletOutputStream out = response.getOutputStream()) {
|
|
|
|
|
@@ -1013,15 +1014,12 @@ public class SubInfoExportController extends BaseController {
|
|
|
subInfoTotalExcel = CollUtil.newArrayList();
|
|
|
}
|
|
|
|
|
|
- //遍历subInfoTotalExcel将万元转换为亿元
|
|
|
- subInfoTotalExcel.forEach(item -> {
|
|
|
- item.setAmtTotal(item.getAmtTotal().divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP));
|
|
|
- });
|
|
|
-
|
|
|
// 写入标题行
|
|
|
- List<String> titleRow = CollUtil.newArrayList("四个一批工业项目表");
|
|
|
- writer.writeHeadRow(titleRow);
|
|
|
- writer.merge(0, 0, 0, 7, null, true);
|
|
|
+ writer.writeHeadRow(CollUtil.newArrayList("四个一批工业项目表"));
|
|
|
+ writer.merge(0, 0, 0, 6, "“四个一批”工业项目表(新建项目库)", true);
|
|
|
+
|
|
|
+ // 写入子标题行
|
|
|
+ writer.writeHeadRow(CollUtil.newArrayList("序号", "项目名称", "项目所在地", "项目建设内容", "计划总投资(亿元)", "预计开工时间", "前期手续办理情况", "备注"));
|
|
|
|
|
|
// 设置每列的默认宽度
|
|
|
SXSSFSheet sheet = ((SXSSFWorkbook) writer.getWorkbook()).getSheetAt(0);
|
|
@@ -1030,27 +1028,71 @@ public class SubInfoExportController extends BaseController {
|
|
|
sheet.setColumnWidth(i, defaultColumnWidth * 256); // 其他列保持默认宽度
|
|
|
}
|
|
|
|
|
|
- //写入合计行数据
|
|
|
- String total = "合计(" + subInfoTotalExcel.size() + ")";
|
|
|
- //计算总金额
|
|
|
- BigDecimal totalAmt = subInfoTotalExcel.stream().map(SubInfoFixDetail::getAmtTotal).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- List<String> totalRow = CollUtil.newArrayList(total,total,total,total,totalAmt.toString(),"","","","");
|
|
|
- writer.write(totalRow, true);
|
|
|
- writer.merge(1, 1, 0, 7, null, true);
|
|
|
+ // 写入合计行
|
|
|
+ BigDecimal totalAmt = subInfoTotalExcel.stream()
|
|
|
+ .map(SubInfoFixDetail::getAmtTotal)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ writer.writeRow(CollUtil.newArrayList(
|
|
|
+ "合计(" + subInfoTotalExcel.size() + "个)", "", "", "", totalAmt.toString(), "", "", ""));
|
|
|
+ writer.merge(2, 2, 0, 3, null, true);
|
|
|
|
|
|
|
|
|
- // 自定义标题别名
|
|
|
- writer.addHeaderAlias("id", "序号");
|
|
|
- writer.addHeaderAlias("subName", "项目名称");
|
|
|
- writer.addHeaderAlias("subjectId", "项目所在地");
|
|
|
- writer.addHeaderAlias("content", "项目建设内容");
|
|
|
- writer.addHeaderAlias("amtTotal", "计划总投资(亿元)");
|
|
|
- writer.addHeaderAlias("beginDate", "预计开工时间");
|
|
|
- writer.addHeaderAlias("Formalities", "前期手续办理情况");
|
|
|
- writer.addHeaderAlias("remark", "备注");
|
|
|
+ //对数据根据行业进行分组
|
|
|
+ Map<String, List<SubInfoFixDetail>> hyflGroupData = subInfoTotalExcel.stream().collect(Collectors.groupingBy(SubInfoFixDetail::getIndusKind));
|
|
|
+ int startRow = 3;
|
|
|
+ int titleNumber = 1;
|
|
|
+ //初始化值
|
|
|
+ List<List<String>> valueList = new ArrayList<>();
|
|
|
+ //需要合并行的集合
|
|
|
+ List<Integer> mergeRowList = new ArrayList<>();
|
|
|
+ for (Map.Entry<String, List<SubInfoFixDetail>> entry : hyflGroupData.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ List<SubInfoFixDetail> value = entry.getValue();
|
|
|
|
|
|
- // 写入数据
|
|
|
- writer.write(subInfoTotalExcel, true);
|
|
|
+ //我需要将key进行拼接,例如这是第1个key,前面就加一个中文一
|
|
|
+ String newKey = StringUtils.toChineseNumber(titleNumber++) + "、" + key + "(" + value.size() + "个)";
|
|
|
+
|
|
|
+ //遍历value将id设置为从1开始的值,并计算总金额
|
|
|
+ BigDecimal hyflTotalAmt = BigDecimal.ZERO;
|
|
|
+ for (int i = 0; i < value.size(); i++) {
|
|
|
+ value.get(i).setId(String.valueOf(i + 1));
|
|
|
+ hyflTotalAmt = hyflTotalAmt.add(value.get(i).getAmtTotal());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //写入行业标题行
|
|
|
+ List<String> hyflTitleRow = CollUtil.newArrayList(newKey,newKey,newKey,newKey,hyflTotalAmt.toString(),"","","");
|
|
|
+ valueList.add(hyflTitleRow);
|
|
|
+ mergeRowList.add(startRow);
|
|
|
+ startRow++;
|
|
|
+
|
|
|
+
|
|
|
+ //将value转换为列表
|
|
|
+ // 日期格式化器
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月");
|
|
|
+ List<List<String>> data = value.stream().map(e -> {
|
|
|
+ List<String> row = new ArrayList<>();
|
|
|
+ row.add(e.getId());
|
|
|
+ row.add(e.getSubName());
|
|
|
+ row.add(e.getSubjectId());
|
|
|
+ row.add(e.getContent());
|
|
|
+ row.add(e.getAmtTotal() != null ? e.getAmtTotal().toString() : ""); // 处理空值
|
|
|
+ row.add(e.getBeginDate() != null ? formatter.format(e.getBeginDate()) : ""); // 日期格式化
|
|
|
+ row.add(e.getFormalities());
|
|
|
+ row.add(e.getRemark());
|
|
|
+ return row;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ valueList.addAll(data);
|
|
|
+ startRow += value.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据合并行进行合并
|
|
|
+ for (int i = 0; i < mergeRowList.size(); i++) {
|
|
|
+ writer.merge(mergeRowList.get(i), mergeRowList.get(i), 0, 3, null, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ //写入行业明细行
|
|
|
+ writer.write(valueList, true);
|
|
|
|
|
|
// 设置响应头
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
|
@@ -1106,7 +1148,7 @@ public class SubInfoExportController extends BaseController {
|
|
|
.map(SubInfoFixCbDetail::getAmtTotal)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
writer.writeRow(CollUtil.newArrayList(
|
|
|
- "合计(" + subInfoTotalExcel.size() + ")", "", "", "", totalAmt.toString(), "", ""));
|
|
|
+ "合计(" + subInfoTotalExcel.size() + "个)", "", "", "", totalAmt.toString(), "", ""));
|
|
|
writer.merge(2, 2, 0, 3, null, true);
|
|
|
|
|
|
|
|
@@ -1123,7 +1165,7 @@ public class SubInfoExportController extends BaseController {
|
|
|
List<SubInfoFixCbDetail> value = entry.getValue();
|
|
|
|
|
|
//我需要将key进行拼接,例如这是第1个key,前面就加一个中文一
|
|
|
- String newKey = StringUtils.toChineseNumber(titleNumber++) + "、" + key + "(" + value.size() + ")";
|
|
|
+ String newKey = StringUtils.toChineseNumber(titleNumber++) + "、" + key + "(" + value.size() + "个)";
|
|
|
|
|
|
//遍历value将id设置为从1开始的值,并计算总金额
|
|
|
BigDecimal hyflTotalAmt = BigDecimal.ZERO;
|
|
@@ -1166,6 +1208,226 @@ public class SubInfoExportController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导出重点项目储备明细表
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @param vo
|
|
|
+ */
|
|
|
+ @PostMapping("/exportFixZjDetailExcel")
|
|
|
+ public void exportFixZjDetailExcel(HttpServletResponse response, @RequestBody SubInfoQueryTzVO vo) throws IOException {
|
|
|
+
|
|
|
+ // 设置响应头
|
|
|
+ response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("重点项目调度-项目数据.xlsx", "UTF-8"));
|
|
|
+
|
|
|
+ try (cn.hutool.poi.excel.ExcelWriter writer = ExcelUtil.getBigWriter();
|
|
|
+ ServletOutputStream out = response.getOutputStream()) {
|
|
|
+
|
|
|
+ // 获取数据
|
|
|
+ List<SubInfoFixZjDetail> subInfoTotalExcel = subInfoService.exportFixZjDetailExcel(vo);
|
|
|
+
|
|
|
+ // 写入标题行
|
|
|
+ writer.writeHeadRow(CollUtil.newArrayList("四个一批工业项目表"));
|
|
|
+ writer.merge(0, 0, 0, 8, "“四个一批”工业项目表(在建项目库)", true);
|
|
|
+
|
|
|
+ // 写入子标题行
|
|
|
+ writer.writeHeadRow(CollUtil.newArrayList("序号", "项目名称", "项目所在地", "项目建设内容", "计划总投资(亿元)", "建成投产时间","年度投资(亿元)","进展情况", "备注"));
|
|
|
+
|
|
|
+ // 设置每列的默认宽度
|
|
|
+ SXSSFSheet sheet = ((SXSSFWorkbook) writer.getWorkbook()).getSheetAt(0);
|
|
|
+ int defaultColumnWidth = 40; // 默认宽度为20个字符
|
|
|
+ for (int i = 0; i < 9; i++) {
|
|
|
+ sheet.setColumnWidth(i, defaultColumnWidth * 256); // 其他列保持默认宽度
|
|
|
+ }
|
|
|
+
|
|
|
+ // 写入合计行
|
|
|
+ BigDecimal totalAmt = subInfoTotalExcel.stream()
|
|
|
+ .map(SubInfoFixZjDetail::getAmtTotal)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ writer.writeRow(CollUtil.newArrayList(
|
|
|
+ "合计(" + subInfoTotalExcel.size() + "个)", "", "", "", totalAmt.toString(), "", ""));
|
|
|
+ writer.merge(2, 2, 0, 3, null, true);
|
|
|
+
|
|
|
+
|
|
|
+ //对数据根据行业进行分组
|
|
|
+ Map<String, List<SubInfoFixZjDetail>> hyflGroupData = subInfoTotalExcel.stream().collect(Collectors.groupingBy(SubInfoFixZjDetail::getIndusKind));
|
|
|
+ int startRow = 3;
|
|
|
+ int titleNumber = 1;
|
|
|
+ //初始化值
|
|
|
+ List<List<String>> valueList = new ArrayList<>();
|
|
|
+ //需要合并行的集合
|
|
|
+ List<Integer> mergeRowList = new ArrayList<>();
|
|
|
+ for (Map.Entry<String, List<SubInfoFixZjDetail>> entry : hyflGroupData.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ List<SubInfoFixZjDetail> value = entry.getValue();
|
|
|
+
|
|
|
+ //我需要将key进行拼接,例如这是第1个key,前面就加一个中文一
|
|
|
+ String newKey = StringUtils.toChineseNumber(titleNumber++) + "、" + key + "(" + value.size() + "个)";
|
|
|
+
|
|
|
+ //遍历value将id设置为从1开始的值,并计算总金额
|
|
|
+ BigDecimal hyflTotalAmt = BigDecimal.ZERO;
|
|
|
+ for (int i = 0; i < value.size(); i++) {
|
|
|
+ value.get(i).setId(String.valueOf(i + 1));
|
|
|
+ hyflTotalAmt = hyflTotalAmt.add(value.get(i).getAmtTotal());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //写入行业标题行
|
|
|
+ List<String> hyflTitleRow = CollUtil.newArrayList(newKey,newKey,newKey,newKey,hyflTotalAmt.toString(),"","");
|
|
|
+ valueList.add(hyflTitleRow);
|
|
|
+ mergeRowList.add(startRow);
|
|
|
+ startRow++;
|
|
|
+
|
|
|
+ //将value转换为列表
|
|
|
+ // 日期格式化器
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月");
|
|
|
+ List<List<String>> data = value.stream().map(e -> {
|
|
|
+ List<String> row = new ArrayList<>();
|
|
|
+ row.add(e.getId());
|
|
|
+ row.add(e.getSubName());
|
|
|
+ row.add(e.getSubjectId());
|
|
|
+ row.add(e.getContent());
|
|
|
+ row.add(e.getAmtTotal() != null ? e.getAmtTotal().toString() : ""); // 处理空值
|
|
|
+ try {
|
|
|
+ row.add(e.getDate() != null ? formatter.format(e.getDate()) : ""); // 处理空值
|
|
|
+ } catch (Exception ex) {
|
|
|
+ row.add(""); // 处理日期格式化异常
|
|
|
+ }
|
|
|
+ row.add(e.getYearMoneyTotal() != null ? e.getYearMoneyTotal().toString() : ""); // 处理空值
|
|
|
+ row.add(e.getProgress());
|
|
|
+ row.add(e.getRemark());
|
|
|
+ return row;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ valueList.addAll(data);
|
|
|
+ startRow += value.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据合并行进行合并
|
|
|
+ for (int i = 0; i < mergeRowList.size(); i++) {
|
|
|
+ writer.merge(mergeRowList.get(i), mergeRowList.get(i), 0, 3, null, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ //写入行业明细行
|
|
|
+ writer.write(valueList, true);
|
|
|
+ // 输出到客户端
|
|
|
+ writer.flush(out, true);
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ // 处理 IO 异常
|
|
|
+ handleErrorResponse(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "导出 Excel 文件时出现错误:" + e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 处理其他异常
|
|
|
+ handleErrorResponse(response, HttpServletResponse.SC_BAD_REQUEST, "请求参数错误或发生其他错误:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出重点项目储备明细表
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @param vo
|
|
|
+ */
|
|
|
+ @PostMapping("/exportFixTcDetailExcel")
|
|
|
+ public void exportFixTcDetailExcel(HttpServletResponse response, @RequestBody SubInfoQueryTzVO vo) throws IOException {
|
|
|
+
|
|
|
+ // 设置响应头
|
|
|
+ response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("重点项目调度-项目数据.xlsx", "UTF-8"));
|
|
|
+
|
|
|
+ try (cn.hutool.poi.excel.ExcelWriter writer = ExcelUtil.getBigWriter();
|
|
|
+ ServletOutputStream out = response.getOutputStream()) {
|
|
|
+
|
|
|
+ // 获取数据
|
|
|
+ List<SubInfoFixTcDetail> subInfoTotalExcel = subInfoService.exportFixTcDetailExcel(vo);
|
|
|
+
|
|
|
+ // 写入标题行
|
|
|
+ writer.writeHeadRow(CollUtil.newArrayList("四个一批工业项目表"));
|
|
|
+ writer.merge(0, 0, 0, 6, "“四个一批”工业项目表(投产项目库)", true);
|
|
|
+
|
|
|
+ // 写入子标题行
|
|
|
+ writer.writeHeadRow(CollUtil.newArrayList("序号", "项目名称", "项目所在地", "项目基本情况", "升规入统时间","进展情况", "备注"));
|
|
|
+
|
|
|
+ // 设置每列的默认宽度
|
|
|
+ SXSSFSheet sheet = ((SXSSFWorkbook) writer.getWorkbook()).getSheetAt(0);
|
|
|
+ int defaultColumnWidth = 40; // 默认宽度为20个字符
|
|
|
+ for (int i = 0; i < 7; i++) {
|
|
|
+ sheet.setColumnWidth(i, defaultColumnWidth * 256); // 其他列保持默认宽度
|
|
|
+ }
|
|
|
+
|
|
|
+ // 写入合计行
|
|
|
+ writer.writeRow(CollUtil.newArrayList(
|
|
|
+ "合计(" + subInfoTotalExcel.size() + "个)", "", "", "", "", "", ""));
|
|
|
+ writer.merge(2, 2, 0, 3, null, true);
|
|
|
+
|
|
|
+
|
|
|
+ //对数据根据行业进行分组
|
|
|
+ Map<String, List<SubInfoFixTcDetail>> hyflGroupData = subInfoTotalExcel.stream().collect(Collectors.groupingBy(SubInfoFixTcDetail::getIndusKind));
|
|
|
+ int startRow = 3;
|
|
|
+ int titleNumber = 1;
|
|
|
+ //初始化值
|
|
|
+ List<List<String>> valueList = new ArrayList<>();
|
|
|
+ //需要合并行的集合
|
|
|
+ List<Integer> mergeRowList = new ArrayList<>();
|
|
|
+ for (Map.Entry<String, List<SubInfoFixTcDetail>> entry : hyflGroupData.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ List<SubInfoFixTcDetail> value = entry.getValue();
|
|
|
+
|
|
|
+ //我需要将key进行拼接,例如这是第1个key,前面就加一个中文一
|
|
|
+ String newKey = StringUtils.toChineseNumber(titleNumber++) + "、" + key + "(" + value.size() + "个)";
|
|
|
+
|
|
|
+ //遍历value将id设置为从1开始的值,并计算总金额
|
|
|
+ for (int i = 0; i < value.size(); i++) {
|
|
|
+ value.get(i).setId(String.valueOf(i + 1));
|
|
|
+ }
|
|
|
+
|
|
|
+ //写入行业标题行
|
|
|
+ List<String> hyflTitleRow = CollUtil.newArrayList(newKey,newKey,newKey,newKey,"","","");
|
|
|
+ valueList.add(hyflTitleRow);
|
|
|
+ mergeRowList.add(startRow);
|
|
|
+ startRow++;
|
|
|
+
|
|
|
+ //将value转换为列表
|
|
|
+ // 日期格式化器
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月");
|
|
|
+ List<List<String>> data = value.stream().map(e -> {
|
|
|
+ List<String> row = new ArrayList<>();
|
|
|
+ row.add(e.getId());
|
|
|
+ row.add(e.getSubName());
|
|
|
+ row.add(e.getSubjectId());
|
|
|
+ row.add(e.getContent());
|
|
|
+ try {
|
|
|
+ row.add(e.getRgDate() != null ? formatter.format(e.getRgDate()) : ""); // 处理空值
|
|
|
+ } catch (Exception ex) {
|
|
|
+ row.add(""); // 处理日期格式化异常
|
|
|
+ }
|
|
|
+ row.add(e.getProgress());
|
|
|
+ row.add(e.getRemark());
|
|
|
+ return row;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ valueList.addAll(data);
|
|
|
+ startRow += value.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据合并行进行合并
|
|
|
+ for (int i = 0; i < mergeRowList.size(); i++) {
|
|
|
+ writer.merge(mergeRowList.get(i), mergeRowList.get(i), 0, 3, null, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ //写入行业明细行
|
|
|
+ writer.write(valueList, true);
|
|
|
+ // 输出到客户端
|
|
|
+ writer.flush(out, true);
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ // 处理 IO 异常
|
|
|
+ handleErrorResponse(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "导出 Excel 文件时出现错误:" + e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 处理其他异常
|
|
|
+ handleErrorResponse(response, HttpServletResponse.SC_BAD_REQUEST, "请求参数错误或发生其他错误:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void handleErrorResponse(HttpServletResponse response, int statusCode, String errorMessage) throws IOException {
|
|
|
response.setStatus(statusCode);
|
|
|
response.setContentType("text/plain;charset=UTF-8");
|