fix: 修复店铺概览导出汇总表客单价、退款金额、税前盈亏为空的问题

This commit is contained in:
小蟑螂
2026-04-20 01:51:44 +08:00
parent 2c422bed26
commit 3c98347b25
5 changed files with 46 additions and 69 deletions
@@ -99,6 +99,24 @@ public class ShopOverviewStatisticsVO {
@Schema(description = "汇总ROI", example = "1.5")
private BigDecimal totalROI;
/**
* 店铺汇总客单价(销售额÷单量,与前端概览一致)
*/
@Schema(description = "店铺汇总客单价", example = "120.00")
private BigDecimal averageOrderValue;
/**
* 退款状态订单实收合计
*/
@Schema(description = "退款金额合计", example = "500.00")
private BigDecimal refundAmount;
/**
* 店铺税前盈亏(扣「销售额×税率」前的经营结果,与 totalNetProfitAfterTax + totalTaxAmount 一致)
*/
@Schema(description = "店铺税前盈亏", example = "85000.00")
private BigDecimal totalProfitBeforeTax;
/**
* 总税后盈亏
*/
@@ -315,7 +315,7 @@ public class ExportServiceImpl implements ExportService {
setCell(row, 12, objToDouble(data.get("totalPromotionFee")), dataStyle);
setCell(row, 13, objToDouble(data.get("brushFee")), dataStyle);
setCell(row, 14, objToDouble(data.get("feeRatio")), dataStyle);
setCell(row, 15, objToDouble(data.get("profitBeforeTax")), dataStyle);
setCell(row, 15, objToDouble(data.get("totalProfitBeforeTax")), dataStyle);
setCell(row, 16, objToDouble(data.get("salesTaxAmount")), dataStyle);
setCell(row, 17, objToDouble(data.get("roi")), dataStyle);
setCell(row, 18, objToDouble(data.get("profitAfterTax")), dataStyle);
@@ -616,7 +616,7 @@ public class ExportServiceImpl implements ExportService {
Object val = getVOFieldValue(vo, f.key);
if (val != null) {
if (val instanceof BigDecimal) {
int scale = ("feeRatio".equals(f.key) || "totalROI".equals(f.key)) ? 4 : 2;
int scale = ("averageFeeRatio".equals(f.key) || "totalROI".equals(f.key)) ? 4 : 2;
cell.setCellValue(((BigDecimal) val).setScale(scale, RoundingMode.HALF_UP).doubleValue());
} else if (val instanceof Integer) {
cell.setCellValue(((Integer) val).doubleValue());
@@ -643,8 +643,11 @@ public class ExportServiceImpl implements ExportService {
switch (key) {
case "totalSalesAmount": return vo.getTotalSalesAmount();
case "totalOrderCount": return vo.getTotalOrderCount();
case "avgOrderValue": return vo.getAverageOrderValue();
case "totalPromotionFee": return vo.getTotalPromotionFee();
case "averageFeeRatio": return vo.getAverageFeeRatio();
case "refundAmount": return vo.getRefundAmount();
case "profitBeforeTax": return vo.getTotalProfitBeforeTax();
case "totalTaxAmount": return vo.getTotalTaxAmount();
case "totalNetProfitAfterTax": return vo.getTotalNetProfitAfterTax();
case "totalROI": return vo.getTotalROI();
@@ -182,6 +182,22 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
int totalOrderCount = orders.size();
overviewVO.setTotalOrderCount(totalOrderCount);
// 3.1 退款金额、客单价(概览页与导出汇总表共用)
BigDecimal refundAmountAgg = BigDecimal.ZERO;
if (refundStatusId != null) {
refundAmountAgg = orders.stream()
.filter(o -> refundStatusId.equals(o.getStatusId()))
.map(o -> o.getReceivedAmount() != null ? o.getReceivedAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
}
overviewVO.setRefundAmount(refundAmountAgg);
BigDecimal averageOrderValue = BigDecimal.ZERO;
if (totalOrderCount > 0) {
averageOrderValue = totalSalesAmount.divide(
BigDecimal.valueOf(totalOrderCount), 2, RoundingMode.HALF_UP);
}
overviewVO.setAverageOrderValue(averageOrderValue);
// 4. 计算总推广费支出
BigDecimal totalPromotionFee = promotionFees.stream()
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
@@ -197,6 +213,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
// 6. 计算店铺总净利(税后)和总税额
BigDecimal totalProfitBeforeTax = calculateTotalProfit(orders);
overviewVO.setTotalProfitBeforeTax(totalProfitBeforeTax);
BigDecimal totalSalesTaxAmount = totalSalesAmount.multiply(taxRate);
BigDecimal totalNetProfitAfterTax = totalProfitBeforeTax.subtract(totalSalesTaxAmount);
overviewVO.setTotalNetProfitAfterTax(totalNetProfitAfterTax);