feat(bpm): 优化财务支付模块
- 升级 commons-io 版本至 2.16.1 - 修改财务支付相关逻辑: - 调整默认状态值 -优化账目明细表格生成 - 新增 MergeSameRowCellsHandler用于合并相同行单元格 - 移除 easyexcel-core 依赖
This commit is contained in:
parent
c512c25a50
commit
585e2afe5a
@ -73,7 +73,7 @@
|
||||
<!-- 三方云服务相关 -->
|
||||
<okio.version>3.5.0</okio.version>
|
||||
<okhttp3.version>4.11.0</okhttp3.version>
|
||||
<commons-io.version>2.11.0</commons-io.version>
|
||||
<commons-io.version>2.16.1</commons-io.version>
|
||||
<minio.version>8.5.6</minio.version>
|
||||
<aliyun-java-sdk-core.version>4.6.4</aliyun-java-sdk-core.version>
|
||||
<aliyun-java-sdk-dysmsapi.version>2.2.1</aliyun-java-sdk-dysmsapi.version>
|
||||
|
@ -140,12 +140,12 @@
|
||||
<version>2.0.0-jdk8-snapshot</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>easyexcel-core</artifactId>
|
||||
<version>4.0.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.alibaba</groupId>-->
|
||||
<!-- <artifactId>easyexcel-core</artifactId>-->
|
||||
<!-- <version>4.0.3</version>-->
|
||||
<!-- <scope>compile</scope>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.cloud</groupId>
|
||||
<artifactId>yudao-spring-boot-starter-excel</artifactId>
|
||||
|
@ -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()));
|
||||
|
@ -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<WriteCellData<?>> 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user