From 585e2afe5a3d8584a4f1a1563f5b65e71534be76 Mon Sep 17 00:00:00 2001
From: furongxin <419481438@qq.com>
Date: Fri, 20 Jun 2025 17:29:28 +0800
Subject: [PATCH] =?UTF-8?q?feat(bpm):=20=E4=BC=98=E5=8C=96=E8=B4=A2?=
=?UTF-8?q?=E5=8A=A1=E6=94=AF=E4=BB=98=E6=A8=A1=E5=9D=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 升级 commons-io 版本至 2.16.1
- 修改财务支付相关逻辑:
- 调整默认状态值
-优化账目明细表格生成
- 新增 MergeSameRowCellsHandler用于合并相同行单元格
- 移除 easyexcel-core 依赖
---
yudao-dependencies/pom.xml | 2 +-
yudao-module-bpm/yudao-module-bpm-biz/pom.xml | 12 +-
.../FinancialPaymentServiceImpl.java | 22 ++-
.../MergeSameRowCellsHandler.java | 141 ++++++++++++++++++
4 files changed, 162 insertions(+), 15 deletions(-)
create mode 100644 yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/financialpayment/MergeSameRowCellsHandler.java
diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml
index 63f88aa3..cbc22b85 100644
--- a/yudao-dependencies/pom.xml
+++ b/yudao-dependencies/pom.xml
@@ -73,7 +73,7 @@
3.5.0
4.11.0
- 2.11.0
+ 2.16.1
8.5.6
4.6.4
2.2.1
diff --git a/yudao-module-bpm/yudao-module-bpm-biz/pom.xml b/yudao-module-bpm/yudao-module-bpm-biz/pom.xml
index 06a59fd9..c9f8694a 100644
--- a/yudao-module-bpm/yudao-module-bpm-biz/pom.xml
+++ b/yudao-module-bpm/yudao-module-bpm-biz/pom.xml
@@ -140,12 +140,12 @@
2.0.0-jdk8-snapshot
compile
-
- com.alibaba
- easyexcel-core
- 4.0.3
- compile
-
+
+
+
+
+
+
cn.iocoder.cloud
yudao-spring-boot-starter-excel
diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/financialpayment/FinancialPaymentServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/financialpayment/FinancialPaymentServiceImpl.java
index f33ba542..1a8eb244 100644
--- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/financialpayment/FinancialPaymentServiceImpl.java
+++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/financialpayment/FinancialPaymentServiceImpl.java
@@ -32,6 +32,7 @@ import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.loan.LoanApi;
import cn.iocoder.yudao.module.system.api.loan.dto.LoanDTO;
import cn.iocoder.yudao.module.system.api.subscribe.SubscribeMessageSendApi;
+import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -296,7 +297,7 @@ public class FinancialPaymentServiceImpl implements FinancialPaymentService {
try {
if (pageReqVO.getStatus() == null) {
- pageReqVO.setStatus(2);
+ pageReqVO.setStatus(0);
}
// 获取支付信息数据
@@ -311,7 +312,7 @@ public class FinancialPaymentServiceImpl implements FinancialPaymentService {
// 设置表头
data.add(Arrays.asList(entry.getValue().get(0).getCompanyName(), entry.getValue().get(0).getCompanyName(), entry.getValue().get(0).getCompanyName(),
- entry.getValue().get(0).getCompanyName(), entry.getValue().get(0).getCompanyName(), entry.getValue().get(0).getCompanyName()));
+ entry.getValue().get(0).getCompanyName(), entry.getValue().get(0).getCompanyName(), entry.getValue().get(0).getCompanyName(), entry.getValue().get(0).getCompanyName()));
data.add(this.setTitle());
// 提取所有公账 支付信息
@@ -344,9 +345,11 @@ public class FinancialPaymentServiceImpl implements FinancialPaymentService {
data.add(row);
}
- // 添加公账合计数据
- BigDecimal publicAccountTotal = publicAccount.stream().map(FinancialPaymentDO::getActualPayment).reduce(BigDecimal.ZERO, BigDecimal::add);
- data.add(Arrays.asList("公账总计", "公账总计", "公账总计", publicAccountTotal.toString(), "", "公账"));
+ if (CollUtil.isNotEmpty(publicAccount)) {
+ // 添加公账合计数据
+ BigDecimal publicAccountTotal = publicAccount.stream().map(FinancialPaymentDO::getActualPayment).reduce(BigDecimal.ZERO, BigDecimal::add);
+ data.add(Arrays.asList("公账总计", "公账总计", "公账总计", publicAccountTotal.toString(), "", "公账"));
+ }
// 遍历私账信息
for (FinancialPaymentDO financialPaymentDO : privateAccount) {
@@ -369,9 +372,11 @@ public class FinancialPaymentServiceImpl implements FinancialPaymentService {
data.add(row);
}
- // 添加私账合计数据
- BigDecimal privateAccountTotal = privateAccount.stream().map(FinancialPaymentDO::getActualPayment).reduce(BigDecimal.ZERO, BigDecimal::add);
- data.add(Arrays.asList("私账总计", "私账总计", "私账总计", privateAccountTotal.toString(), "", "私账"));
+ if (CollUtil.isNotEmpty(privateAccount)) {
+ // 添加私账合计数据
+ BigDecimal privateAccountTotal = privateAccount.stream().map(FinancialPaymentDO::getActualPayment).reduce(BigDecimal.ZERO, BigDecimal::add);
+ data.add(Arrays.asList("私账总计", "私账总计", "私账总计", privateAccountTotal.toString(), "", "私账"));
+ }
}
EasyExcel.write(response.getOutputStream())
@@ -379,6 +384,7 @@ public class FinancialPaymentServiceImpl implements FinancialPaymentService {
.excelType(ExcelTypeEnum.XLSX)
.sheet("账目明细")
.registerWriteHandler(new CustomCellStyleHandler())
+ .registerWriteHandler(new MergeSameRowCellsHandler())
.doWrite(data);
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("账目", StandardCharsets.UTF_8.name()));
diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/financialpayment/MergeSameRowCellsHandler.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/financialpayment/MergeSameRowCellsHandler.java
new file mode 100644
index 00000000..a64b7b47
--- /dev/null
+++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/financialpayment/MergeSameRowCellsHandler.java
@@ -0,0 +1,141 @@
+package cn.iocoder.yudao.module.bpm.service.financialpayment;
+
+import com.alibaba.excel.metadata.Head;
+import com.alibaba.excel.metadata.data.WriteCellData;
+import com.alibaba.excel.write.handler.CellWriteHandler;
+import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
+import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddress;
+
+import java.util.List;
+
+public class MergeSameRowCellsHandler implements CellWriteHandler {
+
+ private int currentRowIndex = -1;
+ private Object lastValue = null;
+ private int startMergeColumnIndex = 0;
+
+ @Override
+ public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Head head, Integer columnIndex, Integer relativeRowIndex, Boolean isHead) {
+ if (relativeRowIndex != null && relativeRowIndex != currentRowIndex) {
+ flushLastMerge(writeSheetHolder); // 处理上一行最后未合并的列
+ reset();
+ currentRowIndex = relativeRowIndex;
+ }
+ }
+
+ @Override
+ public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
+ if (isHead != null && isHead) {
+ return;
+ }
+
+ Workbook workbook = writeSheetHolder.getSheet().getWorkbook();
+ Sheet sheet = writeSheetHolder.getSheet();
+
+ Object currentValue = getCellValue(cell);
+
+ // 确保是当前行才处理
+ if (relativeRowIndex != currentRowIndex) {
+ flushLastMerge(writeSheetHolder);
+ reset();
+ currentRowIndex = relativeRowIndex;
+ }
+
+ if (lastValue == null) {
+ startMergeColumnIndex = cell.getColumnIndex();
+ } else if (!currentValue.equals(lastValue)) {
+ int endMergeColumnIndex = cell.getColumnIndex() - 1;
+ if (startMergeColumnIndex < endMergeColumnIndex) {
+ try {
+ sheet.addMergedRegion(new CellRangeAddress(
+ currentRowIndex, currentRowIndex,
+ startMergeColumnIndex, endMergeColumnIndex
+ ));
+ setCellStyle(workbook, sheet, currentRowIndex, startMergeColumnIndex, endMergeColumnIndex);
+ } catch (Exception ignored) {}
+ }
+ startMergeColumnIndex = cell.getColumnIndex();
+ }
+
+ lastValue = currentValue;
+ }
+
+ @Override
+ public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
+ flushLastMerge(writeSheetHolder);
+ }
+
+ private void flushLastMerge(WriteSheetHolder writeSheetHolder) {
+ Sheet sheet = writeSheetHolder.getSheet();
+ Row row = sheet.getRow(currentRowIndex);
+ if (row == null || currentRowIndex < 0) {
+ return;
+ }
+
+ int lastCellNum = row.getLastCellNum();
+ if (lastCellNum <= 0) {
+ return;
+ }
+
+ int endMergeColumnIndex = lastCellNum - 1;
+ if (startMergeColumnIndex < endMergeColumnIndex) {
+ try {
+ sheet.addMergedRegion(new CellRangeAddress(
+ currentRowIndex, currentRowIndex,
+ startMergeColumnIndex, endMergeColumnIndex
+ ));
+ setCellStyle(writeSheetHolder.getSheet().getWorkbook(), sheet, currentRowIndex, startMergeColumnIndex, endMergeColumnIndex);
+ } catch (Exception ignored) {}
+ }
+ }
+
+ private void setCellStyle(Workbook workbook, Sheet sheet, int rowIndex, int startCol, int endCol) {
+ CellStyle style = createMergedCellStyle(workbook);
+ Row row = sheet.getRow(rowIndex);
+ if (row != null) {
+ Cell firstCell = row.getCell(startCol);
+ if (firstCell != null) {
+ firstCell.setCellStyle(style);
+ }
+ }
+ }
+
+ private Object getCellValue(Cell cell) {
+ if (cell == null) {
+ return null;
+ }
+ switch (cell.getCellType()) {
+ case STRING:
+ return cell.getStringCellValue();
+ case NUMERIC:
+ if (DateUtil.isCellDateFormatted(cell)) {
+ return cell.getDateCellValue();
+ } else {
+ double value = cell.getNumericCellValue();
+ return value == (long) value ? (long) value : value;
+ }
+ case BOOLEAN:
+ return cell.getBooleanCellValue();
+ case FORMULA:
+ return cell.getCellFormula();
+ case BLANK:
+ return "";
+ default:
+ return null;
+ }
+ }
+
+ private CellStyle createMergedCellStyle(Workbook workbook) {
+ CellStyle style = workbook.createCellStyle();
+ style.setAlignment(HorizontalAlignment.CENTER);
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
+ return style;
+ }
+
+ private void reset() {
+ lastValue = null;
+ startMergeColumnIndex = 0;
+ }
+}