demand: TMS系统 - 客户账单管理 - 收款明细查询 - 按财务要求增加定制导出功能

committer: heyu
This commit is contained in:
aike 2025-09-09 10:34:49 +08:00
parent 2ceb092cb7
commit db9ca601c9
4 changed files with 496 additions and 14 deletions

View File

@ -1,11 +1,11 @@
/**
/**
* @Project: emis
* @Title: EmisSettlePayRecordController.java
* @author linfso
* @date 2024-07-21 13:31:24
* @Copyright: ShangHai Duta 2022 All rights reserved.
* @version v1.0
* @version v1.0
* @Description: <p> 账单收退款记录 控制器 </p>
*/
@ -17,9 +17,6 @@ import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import cn.hutool.core.map.MapUtil;
import com.alibaba.fastjson.JSONObject;
import com.xdadan.erp.emis.domain.EmisSettleBill;
import com.xdadan.erp.emis.domain.EmisWaybill;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
import com.xdadan.erp.emis.domain.stat.PayBackRecordDtl;
import com.xdadan.erp.emis.utils.WaybillHelper;
@ -48,7 +45,7 @@ import com.xdadan.erp.emis.service.IEmisSettlePayRecordService;
/**
* 账单收退款记录Controller
*
*
* @author linfso
* @date 2024-07-21 13:31:24
*/
@ -119,8 +116,8 @@ public class EmisSettlePayRecordController extends BaseController
}
}
Map rstMap = emisSettlePayRecordService.getSettlePayStatInfoMap(emisSettlePayRecord);
return AjaxResult.success("查询成功",rstMap);
Map<String, Object> rstMap = emisSettlePayRecordService.getSettlePayStatInfoMap(emisSettlePayRecord);
return AjaxResult.success("查询成功", rstMap);
}
@GetMapping("/queryPayBackRecordList")
@ -147,8 +144,8 @@ public class EmisSettlePayRecordController extends BaseController
/**
* 检查是否重复
*
* @param emisSettlePayRecord
*
* @param emisSettlePayRecord
* @return 数量
*/
// @PreAuthorize("@ss.hasPermi('emis:emisSettlePayRecord:list')")
@ -173,6 +170,17 @@ public class EmisSettlePayRecordController extends BaseController
util.exportExcel(response, list, "账单收退款记录数据");
}
/**
* 定制导出账单收退款记录列表
*/
// @PreAuthorize("@ss.hasPermi('emis:emisSettlePayRecord:export')")
@Log(title = "账单收退款记录定制导出", businessType = BusinessType.EXPORT)
@PostMapping("/customExport")
public void customExport(HttpServletResponse response, EmisSettlePayRecord emisSettlePayRecord) {
setPrivParams(emisSettlePayRecord);
emisSettlePayRecordService.customExport(response, emisSettlePayRecord);
}
/**
* 获取账单收退款记录详细信息
*/

View File

@ -12,7 +12,8 @@ package com.xdadan.erp.emis.service;
import java.util.List;
import java.util.Map;
import com.xdadan.erp.emis.domain.EmisSettleBill;
import javax.servlet.http.HttpServletResponse;
import com.xdadan.erp.emis.domain.EmisSettlePayRecord;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
import com.xdadan.erp.emis.domain.stat.PayBackRecordDtl;
@ -86,14 +87,20 @@ public interface IEmisSettlePayRecordService
*/
public int deleteEmisSettlePayRecordById(Long id);
/**
* 账单退款
*
* @param id
* @return
*/
public int payRecordReturn(Long id) throws EmisBizError;
/**
* 定制导出账单收退款记录
*
* @param response HTTP响应
* @param emisSettlePayRecord 查询条件
*/
public void customExport(HttpServletResponse response, EmisSettlePayRecord emisSettlePayRecord);
}

View File

@ -0,0 +1,443 @@
package com.xdadan.erp.emis.service.excelCellStrategy;
import com.xdadan.erp.emis.domain.EmisSettlePayRecord;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.List;
/**
* 账单收退款记录定制导出Excel工具类
*
* @author heyu
* @date 2025-09-09
*/
public class EmisSettlePayRecordCustomExcelUtil {
private static final String[] HEADERS = {
"交易时间", "收款来源", "收款账户", "支付类型", "缴款客户", "微信昵称", "运单号", "开票状态",
"账单金额", "开票金额", "支付金额", "理赔金额", "折让金额", "抵扣金额", "其他收费",
"理赔原因", "折让原因", "抵扣原因", "其他原因", "备注"
};
private static final int[] COLUMN_WIDTHS = {
20, 15, 15, 12, 20, 15, 20, 10,
12, 12, 12, 12, 12, 12, 12,
20, 20, 20, 20, 30
};
/**
* 导出定制Excel
*
* @param response HTTP响应
* @param dataList 数据列表
* @param sheetName 工作表名称
*/
public static void exportCustomExcel(HttpServletResponse response, List<EmisSettlePayRecord> dataList,
String sheetName) {
try {
// 创建工作簿
SXSSFWorkbook workbook = new SXSSFWorkbook(100);
Sheet sheet = workbook.createSheet(sheetName);
// 创建样式
CellStyle headerStyle = createHeaderStyle(workbook);
CellStyle dataStyle = createDataStyle(workbook);
CellStyle numberStyle = createNumberStyle(workbook);
CellStyle sumStyle = createSumStyle(workbook);
// 创建表头
createHeader(sheet, headerStyle);
// 填充数据
int rowIndex = 1;
BigDecimal totalBillAmount = BigDecimal.ZERO;
BigDecimal totalInvoiceAmount = BigDecimal.ZERO;
BigDecimal totalPayMoney = BigDecimal.ZERO;
BigDecimal totalSatisfyMoney = BigDecimal.ZERO;
BigDecimal totalAllowanceMoney = BigDecimal.ZERO;
BigDecimal totalDeductionMoney = BigDecimal.ZERO;
BigDecimal totalOtherMoney = BigDecimal.ZERO;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (EmisSettlePayRecord data : dataList) {
Row row = sheet.createRow(rowIndex++);
// 交易时间
createCell(row, 0, data.getTradeDate() != null ? dateFormat.format(data.getTradeDate()) : "",
dataStyle);
// 收款来源
String paySource = getPaySourceDesc(data.getPayType());
createCell(row, 1, paySource, dataStyle);
// 收款账户(写死为1704378299)
createCell(row, 2, "1704378299", dataStyle);
// 支付类型
String payTypeDesc = getPayTypeDesc(data.getSettleType());
createCell(row, 3, payTypeDesc, dataStyle);
// 缴款客户
createCell(row, 4, data.getPayMan() != null ? data.getPayMan() : "", dataStyle);
// 微信昵称(空)
createCell(row, 5, "", dataStyle);
// 运单号
createCell(row, 6, data.getBillCodes() != null ? data.getBillCodes() : "", dataStyle);
// 开票状态
// String invoiceStatusDesc = getInvoiceStatusDesc(data.getInvoiceStatus());
createCell(row, 7, data.getInvoiceStatus(), dataStyle);
// 账单金额
BigDecimal billAmount = data.getBillAmount() != null ? data.getBillAmount() : BigDecimal.ZERO;
createCell(row, 8, billAmount, numberStyle);
totalBillAmount = totalBillAmount.add(billAmount);
// 开票金额
BigDecimal invoiceAmount = data.getInvoiceAmount() != null ? data.getInvoiceAmount() : BigDecimal.ZERO;
createCell(row, 9, invoiceAmount, numberStyle);
totalInvoiceAmount = totalInvoiceAmount.add(invoiceAmount);
// 支付金额
BigDecimal payMoney = data.getPayMoney() != null ? data.getPayMoney() : BigDecimal.ZERO;
createCell(row, 10, payMoney, numberStyle);
totalPayMoney = totalPayMoney.add(payMoney);
// 理赔金额
BigDecimal satisfyMoney = data.getSatisfyMoney() != null ? data.getSatisfyMoney() : BigDecimal.ZERO;
createCell(row, 11, satisfyMoney, numberStyle);
totalSatisfyMoney = totalSatisfyMoney.add(satisfyMoney);
// 折让金额
BigDecimal allowanceMoney = data.getAllowanceMoney() != null ? data.getAllowanceMoney()
: BigDecimal.ZERO;
createCell(row, 12, allowanceMoney, numberStyle);
totalAllowanceMoney = totalAllowanceMoney.add(allowanceMoney);
// 抵扣金额
BigDecimal deductionMoney = data.getDeductionMoney() != null ? data.getDeductionMoney()
: BigDecimal.ZERO;
createCell(row, 13, deductionMoney, numberStyle);
totalDeductionMoney = totalDeductionMoney.add(deductionMoney);
// 其他收费
BigDecimal otherMoney = data.getOtherMoney() != null ? data.getOtherMoney() : BigDecimal.ZERO;
createCell(row, 14, otherMoney, numberStyle);
totalOtherMoney = totalOtherMoney.add(otherMoney);
// 理赔原因
createCell(row, 15, data.getSatisfyReason() != null ? data.getSatisfyReason() : "", dataStyle);
// 折让原因
createCell(row, 16, data.getAllowanceReason() != null ? data.getAllowanceReason() : "", dataStyle);
// 抵扣原因
createCell(row, 17, data.getDeductionReason() != null ? data.getDeductionReason() : "", dataStyle);
// 其他原因
createCell(row, 18, data.getOtherReason() != null ? data.getOtherReason() : "", dataStyle);
// 备注
createCell(row, 19, data.getRemark() != null ? data.getRemark() : "", dataStyle);
}
// 创建合计行
createSumRow(sheet, rowIndex, sumStyle, totalBillAmount, totalInvoiceAmount, totalPayMoney,
totalSatisfyMoney, totalAllowanceMoney, totalDeductionMoney, totalOtherMoney);
// 设置列宽
setColumnWidths(sheet);
// 输出文件
outputFile(response, workbook, sheetName);
} catch (Exception e) {
throw new RuntimeException("导出Excel失败:" + e.getMessage(), e);
}
}
/**
* 获取收款来源描述
*/
private static String getPaySourceDesc(String payType) {
if (payType == null)
return "";
switch (payType) {
case "1":
return "企业微信收款";
case "2":
return "工行汇款3890";
case "3":
return "微信支付";
case "4":
return "支付宝";
case "5":
return "其他";
case "6":
return "招行付款";
case "7":
return "在线支付(微信)";
default:
return "其他";
}
}
/**
* 获取支付类型描述
*/
private static String getPayTypeDesc(String settleType) {
if (settleType == null)
return "";
switch (settleType) {
case "1":
return "现金账单";
case "2":
return "月结账单";
default:
return "其他";
}
}
/**
* 获取开票状态描述
*/
private static String getInvoiceStatusDesc(String invoiceStatus) {
if (invoiceStatus == null)
return "未开票";
switch (invoiceStatus) {
case "0":
return "待开票";
case "1":
return "已开票";
case "2":
return "已开票";
default:
return "未开票";
}
}
/**
* 创建表头样式
*/
private static CellStyle createHeaderStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
// 设置字体
Font font = workbook.createFont();
font.setFontName("宋体");
font.setFontHeightInPoints((short) 12);
font.setBold(true);
style.setFont(font);
// 设置背景色(绿色)
style.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// 设置边框
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
// 设置对齐方式
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
return style;
}
/**
* 创建数据样式
*/
private static CellStyle createDataStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
// 设置字体
Font font = workbook.createFont();
font.setFontName("宋体");
font.setFontHeightInPoints((short) 12);
style.setFont(font);
// 设置边框
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
// 设置对齐方式
style.setAlignment(HorizontalAlignment.LEFT);
style.setVerticalAlignment(VerticalAlignment.CENTER);
return style;
}
/**
* 创建数字样式
*/
private static CellStyle createNumberStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
// 设置字体
Font font = workbook.createFont();
font.setFontName("宋体");
font.setFontHeightInPoints((short) 12);
style.setFont(font);
// 设置边框
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
// 设置数字格式
style.setDataFormat(workbook.createDataFormat().getFormat("#,##0.00"));
// 设置对齐方式
style.setAlignment(HorizontalAlignment.RIGHT);
style.setVerticalAlignment(VerticalAlignment.CENTER);
return style;
}
/**
* 创建合计行样式
*/
private static CellStyle createSumStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
// 设置字体
Font font = workbook.createFont();
font.setFontName("宋体");
font.setFontHeightInPoints((short) 12);
font.setBold(true);
style.setFont(font);
// 设置背景色
style.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// 设置边框
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
// 设置数字格式
style.setDataFormat(workbook.createDataFormat().getFormat("#,##0.00"));
// 设置对齐方式
style.setAlignment(HorizontalAlignment.RIGHT);
style.setVerticalAlignment(VerticalAlignment.CENTER);
return style;
}
/**
* 创建表头
*/
private static void createHeader(Sheet sheet, CellStyle headerStyle) {
Row headerRow = sheet.createRow(0);
headerRow.setHeightInPoints(25);
for (int i = 0; i < HEADERS.length; i++) {
Cell cell = headerRow.createCell(i);
cell.setCellValue(HEADERS[i]);
cell.setCellStyle(headerStyle);
}
}
/**
* 创建单元格
*/
private static void createCell(Row row, int columnIndex, String value, CellStyle style) {
Cell cell = row.createCell(columnIndex);
cell.setCellValue(value != null ? value : "");
cell.setCellStyle(style);
}
/**
* 创建数字单元格
*/
private static void createCell(Row row, int columnIndex, BigDecimal value, CellStyle style) {
Cell cell = row.createCell(columnIndex);
cell.setCellValue(value != null ? value.doubleValue() : 0.0);
cell.setCellStyle(style);
}
/**
* 创建合计行
*/
private static void createSumRow(Sheet sheet, int rowIndex, CellStyle sumStyle,
BigDecimal totalBillAmount, BigDecimal totalInvoiceAmount, BigDecimal totalPayMoney,
BigDecimal totalSatisfyMoney, BigDecimal totalAllowanceMoney,
BigDecimal totalDeductionMoney, BigDecimal totalOtherMoney) {
Row sumRow = sheet.createRow(rowIndex);
sumRow.setHeightInPoints(25);
// 合计标签
Cell sumLabelCell = sumRow.createCell(7);
sumLabelCell.setCellValue("合计");
CellStyle labelStyle = sheet.getWorkbook().createCellStyle();
Font font = sheet.getWorkbook().createFont();
font.setFontName("宋体");
font.setFontHeightInPoints((short) 12);
font.setBold(true);
labelStyle.setFont(font);
labelStyle.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());
labelStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
labelStyle.setBorderTop(BorderStyle.THIN);
labelStyle.setBorderBottom(BorderStyle.THIN);
labelStyle.setBorderLeft(BorderStyle.THIN);
labelStyle.setBorderRight(BorderStyle.THIN);
labelStyle.setAlignment(HorizontalAlignment.CENTER);
labelStyle.setVerticalAlignment(VerticalAlignment.CENTER);
sumLabelCell.setCellStyle(labelStyle);
// 合计金额
createCell(sumRow, 8, totalBillAmount, sumStyle);
createCell(sumRow, 9, totalInvoiceAmount, sumStyle);
createCell(sumRow, 10, totalPayMoney, sumStyle);
createCell(sumRow, 11, totalSatisfyMoney, sumStyle);
createCell(sumRow, 12, totalAllowanceMoney, sumStyle);
createCell(sumRow, 13, totalDeductionMoney, sumStyle);
createCell(sumRow, 14, totalOtherMoney, sumStyle);
}
/**
* 设置列宽
*/
private static void setColumnWidths(Sheet sheet) {
for (int i = 0; i < COLUMN_WIDTHS.length; i++) {
sheet.setColumnWidth(i, COLUMN_WIDTHS[i] * 256);
}
}
/**
* 输出文件
*/
private static void outputFile(HttpServletResponse response, Workbook workbook, String sheetName)
throws IOException {
// 设置响应头
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
String fileName = URLEncoder.encode(sheetName + ".xlsx", "UTF-8").replaceAll("\\+", "%20");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName);
// 输出文件
try (OutputStream outputStream = response.getOutputStream()) {
workbook.write(outputStream);
workbook.close();
}
}
}

View File

@ -20,6 +20,8 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.servlet.http.HttpServletResponse;
import com.xdadan.erp.emis.domain.*;
import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
@ -27,6 +29,7 @@ import com.xdadan.erp.emis.domain.stat.PayBackRecordDtl;
import com.xdadan.erp.emis.mapper.*;
import com.xdadan.erp.emis.service.EmisBaseService;
import com.xdadan.erp.emis.service.IEmisSettleBillService;
import com.xdadan.erp.emis.service.excelCellStrategy.EmisSettlePayRecordCustomExcelUtil;
import com.xdadan.erp.emis.utils.WaybillHelper;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
@ -466,6 +469,7 @@ public class EmisSettlePayRecordServiceImpl extends EmisBaseService implements I
/**
* 收款退款
*
* @param id
* @return
*/
@ -486,7 +490,6 @@ public class EmisSettlePayRecordServiceImpl extends EmisBaseService implements I
return 1;
}
/**
* 修改账单收退款记录
*
@ -523,4 +526,25 @@ public class EmisSettlePayRecordServiceImpl extends EmisBaseService implements I
return emisSettlePayRecordMapper.deleteEmisSettlePayRecordById(id);
}
/**
* 定制导出账单收退款记录
*
* @param response HTTP响应
* @param emisSettlePayRecord 查询条件
*/
@Override
public void customExport(HttpServletResponse response, EmisSettlePayRecord emisSettlePayRecord) {
try {
// 查询数据列表
List<EmisSettlePayRecord> exportList = selectEmisSettlePayRecordList(emisSettlePayRecord);
// 使用定制Excel工具类导出
EmisSettlePayRecordCustomExcelUtil.exportCustomExcel(response, exportList, "收款明细定制导出_" + System.currentTimeMillis());
} catch (Exception e) {
log.error("定制导出收款明细失败", e);
throw new RuntimeException("导出失败:" + e.getMessage());
}
}
}