From 85cce1ff7ace91e5b031f339407952ff669a5ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=9F=91=E8=9E=82?= Date: Thu, 23 Apr 2026 21:30:48 +0800 Subject: [PATCH] =?UTF-8?q?refactor(ecom-dmb):=20=E5=BA=97=E9=93=BA?= =?UTF-8?q?=E6=A6=82=E8=A7=88=E5=95=86=E5=93=81/=E5=93=81=E7=B1=BB?= =?UTF-8?q?=E5=AF=B9=E6=AF=94=E8=A1=A8=E6=94=B9=E4=B8=BA=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E5=90=AB=E5=90=88=E8=AE=A1=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/vo/ShopOverviewStatisticsVO.java | 32 +++- .../service/impl/ExportServiceImpl.java | 4 +- .../ShopOverviewStatisticsServiceImpl.java | 148 +++++++++++++++++- .../src/api/ecommerce/shop/types/types.vo.ts | 24 ++- .../components/CategoryComparisonTable.vue | 30 +++- .../components/ProductComparisonTable.vue | 25 ++- 6 files changed, 237 insertions(+), 26 deletions(-) diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/vo/ShopOverviewStatisticsVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/vo/ShopOverviewStatisticsVO.java index 52ee2728..7c1a1e07 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/vo/ShopOverviewStatisticsVO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/vo/ShopOverviewStatisticsVO.java @@ -136,16 +136,40 @@ public class ShopOverviewStatisticsVO { private TrendData orderCountTrend; /** - * 多商品数据横向对比 + * 多商品数据横向对比(含合计行) */ @Schema(description = "多商品数据横向对比") - private List productComparisons; + private ProductOverview productOverview; /** - * 品类多维度数据对比 + * 品类多维度数据对比(含合计行) */ @Schema(description = "品类多维度数据对比") - private List categoryComparisons; + private CategoryOverview categoryOverview; + + /** + * 商品概览(含合计行和商品列表) + */ + @Data + @Schema(description = "商品概览") + public static class ProductOverview { + @Schema(description = "合计行") + private ProductComparison total; + @Schema(description = "各商品对比列表") + private List products; + } + + /** + * 品类概览(含合计行和品类列表) + */ + @Data + @Schema(description = "品类概览") + public static class CategoryOverview { + @Schema(description = "合计行") + private CategoryComparison total; + @Schema(description = "各品类对比列表") + private List categories; + } /** * 商品对比数据 diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ExportServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ExportServiceImpl.java index a9d030cf..c52b5744 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ExportServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ExportServiceImpl.java @@ -203,9 +203,9 @@ public class ExportServiceImpl implements ExportService { } if (("product".equals(exportType) || "all".equals(exportType)) - && vo.getProductComparisons() != null && !vo.getProductComparisons().isEmpty()) { + && vo.getProductOverview() != null && vo.getProductOverview().getProducts() != null && !vo.getProductOverview().getProducts().isEmpty()) { Sheet productSheet = workbook.createSheet("商品明细"); - createProductDetailSheetFromVO(productSheet, dateRangeLabel, vo.getProductComparisons(), taxRate); + createProductDetailSheetFromVO(productSheet, dateRangeLabel, vo.getProductOverview().getProducts(), taxRate); } if (("trend".equals(exportType) || "all".equals(exportType)) diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ShopOverviewStatisticsServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ShopOverviewStatisticsServiceImpl.java index b28c0ab3..b85ca467 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ShopOverviewStatisticsServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ShopOverviewStatisticsServiceImpl.java @@ -241,14 +241,14 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics overviewVO.setOrderCountTrend(orderCountTrend); // 10. 多商品数据横向对比 - List productComparisons = calculateProductComparisons( + ShopOverviewStatisticsVO.ProductOverview productOverview = calculateProductComparisons( orders, promotionFees, brushOrders, refundStatusId); - overviewVO.setProductComparisons(productComparisons); + overviewVO.setProductOverview(productOverview); // 11. 品类多维度数据对比 - List categoryComparisons = calculateCategoryComparisons( + ShopOverviewStatisticsVO.CategoryOverview categoryOverview = calculateCategoryComparisons( orders, promotionFees, brushOrders, refundStatusId); - overviewVO.setCategoryComparisons(categoryComparisons); + overviewVO.setCategoryOverview(categoryOverview); return overviewVO; } @@ -366,7 +366,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics /** * 计算多商品数据横向对比 */ - private List calculateProductComparisons( + private ShopOverviewStatisticsVO.ProductOverview calculateProductComparisons( List orders, List promotionFees, List brushOrders, Long refundStatusId) { List comparisons = new ArrayList<>(); @@ -492,7 +492,73 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics // 按销售额降序排序 comparisons.sort(Comparator.comparing(ShopOverviewStatisticsVO.ProductComparison::getSalesAmount).reversed()); - return comparisons; + + // 计算合计行 + ShopOverviewStatisticsVO.ProductComparison total = computeProductTotal(comparisons); + + // 封装为 ProductOverview + ShopOverviewStatisticsVO.ProductOverview overview = new ShopOverviewStatisticsVO.ProductOverview(); + overview.setTotal(total); + overview.setProducts(comparisons); + return overview; + } + + /** + * 计算商品对比的合计行 + */ + private ShopOverviewStatisticsVO.ProductComparison computeProductTotal(List products) { + BigDecimal totalSales = BigDecimal.ZERO; + int totalOrders = 0; + BigDecimal totalProductCost = BigDecimal.ZERO; + BigDecimal totalShippingCost = BigDecimal.ZERO; + BigDecimal totalOtherCost = BigDecimal.ZERO; + BigDecimal totalRefund = BigDecimal.ZERO; + BigDecimal totalPromoFee = BigDecimal.ZERO; + BigDecimal totalBrushFee = BigDecimal.ZERO; + + for (ShopOverviewStatisticsVO.ProductComparison p : products) { + totalSales = totalSales.add(p.getSalesAmount() != null ? p.getSalesAmount() : BigDecimal.ZERO); + totalOrders += p.getOrderCount() != null ? p.getOrderCount() : 0; + totalProductCost = totalProductCost.add(p.getProductCost() != null ? p.getProductCost() : BigDecimal.ZERO); + totalShippingCost = totalShippingCost.add(p.getShippingCost() != null ? p.getShippingCost() : BigDecimal.ZERO); + totalOtherCost = totalOtherCost.add(p.getOtherCost() != null ? p.getOtherCost() : BigDecimal.ZERO); + totalRefund = totalRefund.add(p.getRefundAmount() != null ? p.getRefundAmount() : BigDecimal.ZERO); + totalPromoFee = totalPromoFee.add(p.getTotalPromotionFee() != null ? p.getTotalPromotionFee() : BigDecimal.ZERO); + totalBrushFee = totalBrushFee.add(p.getBrushFee() != null ? p.getBrushFee() : BigDecimal.ZERO); + } + + BigDecimal avgOrderValue = totalOrders > 0 + ? totalSales.divide(new BigDecimal(totalOrders), 2, RoundingMode.HALF_UP) + : BigDecimal.ZERO; + BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost); + BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund); + BigDecimal salesTax = totalSales.multiply(new BigDecimal("0.04")); + BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax); + BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0 + ? totalSales.subtract(totalRefund).divide(totalPromoFee, 4, RoundingMode.HALF_UP) + : BigDecimal.ZERO; + BigDecimal feeRatio = totalSales.compareTo(BigDecimal.ZERO) > 0 + ? totalPromoFee.add(totalBrushFee).divide(totalSales, 4, RoundingMode.HALF_UP) + : BigDecimal.ZERO; + + ShopOverviewStatisticsVO.ProductComparison total = new ShopOverviewStatisticsVO.ProductComparison(); + total.setProductId(0L); + total.setProductName("合计"); + total.setSalesAmount(totalSales); + total.setOrderCount(totalOrders); + total.setAverageOrderValue(avgOrderValue); + total.setProductCost(totalProductCost); + total.setShippingCost(totalShippingCost); + total.setOtherCost(totalOtherCost); + total.setRefundAmount(totalRefund); + total.setTotalPromotionFee(totalPromoFee); + total.setBrushFee(totalBrushFee); + total.setFeeRatio(feeRatio); + total.setTotalProfitBeforeTax(profitBeforeTax); + total.setSalesTaxAmount(salesTax); + total.setRoi(roi); + total.setProfitAfterTax(profitAfterTax); + return total; } /** @@ -619,7 +685,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics /** * 计算品类多维度数据对比 */ - private List calculateCategoryComparisons( + private ShopOverviewStatisticsVO.CategoryOverview calculateCategoryComparisons( List orders, List promotionFees, List brushOrders, Long refundStatusId) { @@ -752,7 +818,73 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics } results.sort(Comparator.comparing(ShopOverviewStatisticsVO.CategoryComparison::getSalesAmount).reversed()); - return results; + + // 计算合计行 + ShopOverviewStatisticsVO.CategoryComparison total = computeCategoryTotalForShop(results); + + // 封装为 CategoryOverview + ShopOverviewStatisticsVO.CategoryOverview overview = new ShopOverviewStatisticsVO.CategoryOverview(); + overview.setTotal(total); + overview.setCategories(results); + return overview; + } + + /** + * 计算店铺视角品类对比的合计行 + */ + private ShopOverviewStatisticsVO.CategoryComparison computeCategoryTotalForShop(List categories) { + BigDecimal totalSales = BigDecimal.ZERO; + int totalOrders = 0; + BigDecimal totalProductCost = BigDecimal.ZERO; + BigDecimal totalShippingCost = BigDecimal.ZERO; + BigDecimal totalOtherCost = BigDecimal.ZERO; + BigDecimal totalRefund = BigDecimal.ZERO; + BigDecimal totalPromoFee = BigDecimal.ZERO; + BigDecimal totalBrushFee = BigDecimal.ZERO; + + for (ShopOverviewStatisticsVO.CategoryComparison c : categories) { + totalSales = totalSales.add(c.getSalesAmount() != null ? c.getSalesAmount() : BigDecimal.ZERO); + totalOrders += c.getOrderCount() != null ? c.getOrderCount() : 0; + totalProductCost = totalProductCost.add(c.getProductCost() != null ? c.getProductCost() : BigDecimal.ZERO); + totalShippingCost = totalShippingCost.add(c.getShippingCost() != null ? c.getShippingCost() : BigDecimal.ZERO); + totalOtherCost = totalOtherCost.add(c.getOtherCost() != null ? c.getOtherCost() : BigDecimal.ZERO); + totalRefund = totalRefund.add(c.getRefundAmount() != null ? c.getRefundAmount() : BigDecimal.ZERO); + totalPromoFee = totalPromoFee.add(c.getTotalPromotionFee() != null ? c.getTotalPromotionFee() : BigDecimal.ZERO); + totalBrushFee = totalBrushFee.add(c.getBrushFee() != null ? c.getBrushFee() : BigDecimal.ZERO); + } + + BigDecimal avgOrderValue = totalOrders > 0 + ? totalSales.divide(new BigDecimal(totalOrders), 2, RoundingMode.HALF_UP) + : BigDecimal.ZERO; + BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost); + BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund); + BigDecimal salesTax = totalSales.multiply(new BigDecimal("0.04")); + BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax); + BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0 + ? totalSales.subtract(totalRefund).divide(totalPromoFee, 4, RoundingMode.HALF_UP) + : BigDecimal.ZERO; + BigDecimal feeRatio = totalSales.compareTo(BigDecimal.ZERO) > 0 + ? totalPromoFee.add(totalBrushFee).divide(totalSales, 4, RoundingMode.HALF_UP) + : BigDecimal.ZERO; + + ShopOverviewStatisticsVO.CategoryComparison total = new ShopOverviewStatisticsVO.CategoryComparison(); + total.setCategoryId(0L); + total.setCategoryName("合计"); + total.setSalesAmount(totalSales); + total.setOrderCount(totalOrders); + total.setAverageOrderValue(avgOrderValue); + total.setProductCost(totalProductCost); + total.setShippingCost(totalShippingCost); + total.setOtherCost(totalOtherCost); + total.setRefundAmount(totalRefund); + total.setTotalPromotionFee(totalPromoFee); + total.setBrushFee(totalBrushFee); + total.setFeeRatio(feeRatio); + total.setTotalProfitBeforeTax(profitBeforeTax); + total.setSalesTaxAmount(salesTax); + total.setRoi(roi); + total.setProfitAfterTax(profitAfterTax); + return total; } } diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.vo.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.vo.ts index c791c972..de0b1271 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.vo.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.vo.ts @@ -149,10 +149,10 @@ export namespace ShopVO { salesAmountTrend?: TrendData; /** 单量趋势分析 */ orderCountTrend?: TrendData; - /** 多商品数据横向对比 */ - productComparisons?: ProductComparison[]; - /** 品类多维度数据对比 */ - categoryComparisons?: CategoryComparison[]; + /** 多商品数据横向对比(含合计行) */ + productOverview?: ProductOverview; + /** 品类多维度数据对比(含合计行) */ + categoryOverview?: CategoryOverview; } /** 商品对比数据 */ @@ -244,4 +244,20 @@ export namespace ShopVO { /** 对应的值 */ value: number; } + + /** 商品概览(含合计行和商品列表) */ + export interface ProductOverview { + /** 合计行 */ + total: ProductComparison; + /** 各商品对比列表 */ + products: ProductComparison[]; + } + + /** 品类概览(含合计行和品类列表) */ + export interface CategoryOverview { + /** 合计行 */ + total: CategoryComparison; + /** 各品类对比列表 */ + categories: CategoryComparison[]; + } } diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/overview/components/CategoryComparisonTable.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/overview/components/CategoryComparisonTable.vue index 80a87f39..032b9be0 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/overview/components/CategoryComparisonTable.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/overview/components/CategoryComparisonTable.vue @@ -80,7 +80,7 @@ const formatPercentPlain = (value: number | undefined) => { -
+
@@ -111,8 +111,8 @@ const formatPercentPlain = (value: number | undefined) => { > @@ -154,7 +154,7 @@ const formatPercentPlain = (value: number | undefined) => { @@ -194,12 +194,32 @@ const formatPercentPlain = (value: number | undefined) => { {{ cat.profitAfterTax ? formatAmount(cat.profitAfterTax) : '-' }} - + + + + + + + + + + + + + + + + + + + + +
暂无数据
合计{{ props.data.categoryOverview.total.salesAmount ? formatAmount(props.data.categoryOverview.total.salesAmount) : '-' }}{{ props.data.categoryOverview.total.orderCount ? props.data.categoryOverview.total.orderCount.toLocaleString() : '-' }}-{{ props.data.categoryOverview.total.productCost ? formatAmount(props.data.categoryOverview.total.productCost) : '-' }}{{ props.data.categoryOverview.total.shippingCost ? formatAmount(props.data.categoryOverview.total.shippingCost) : '-' }}{{ props.data.categoryOverview.total.otherCost ? formatAmount(props.data.categoryOverview.total.otherCost) : '-' }}{{ props.data.categoryOverview.total.refundAmount ? formatAmount(props.data.categoryOverview.total.refundAmount) : '-' }}{{ props.data.categoryOverview.total.totalPromotionFee ? formatAmount(props.data.categoryOverview.total.totalPromotionFee) : '-' }}{{ props.data.categoryOverview.total.brushFee ? formatAmount(props.data.categoryOverview.total.brushFee) : '-' }}{{ props.data.categoryOverview.total.feeRatio !== undefined ? formatPercentPlain(props.data.categoryOverview.total.feeRatio) : '-' }}{{ props.data.categoryOverview.total.totalProfitBeforeTax ? formatAmount(props.data.categoryOverview.total.totalProfitBeforeTax) : '-' }}{{ props.data.categoryOverview.total.salesTaxAmount ? formatAmount(props.data.categoryOverview.total.salesTaxAmount) : '-' }}{{ props.data.categoryOverview.total.roi !== undefined ? props.data.categoryOverview.total.roi.toFixed(2) : '-' }}{{ props.data.categoryOverview.total.profitAfterTax ? formatAmount(props.data.categoryOverview.total.profitAfterTax) : '-' }}
diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/overview/components/ProductComparisonTable.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/overview/components/ProductComparisonTable.vue index 73d747f2..fc20602c 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/overview/components/ProductComparisonTable.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/overview/components/ProductComparisonTable.vue @@ -51,7 +51,7 @@ const formatPercentPlain = (value: number | undefined) => { -
+
@@ -125,7 +125,7 @@ const formatPercentPlain = (value: number | undefined) => { @@ -174,12 +174,31 @@ const formatPercentPlain = (value: number | undefined) => { {{ product.profitAfterTax ? formatAmount(product.profitAfterTax) : '-' }} - + + + + + + + + + + + + + + + + + + + +
暂无数据
合计{{ data.productOverview.total.salesAmount ? formatAmount(data.productOverview.total.salesAmount) : '-' }}{{ data.productOverview.total.orderCount ? data.productOverview.total.orderCount.toLocaleString() : '-' }}-{{ data.productOverview.total.productCost ? formatAmount(data.productOverview.total.productCost) : '-' }}{{ data.productOverview.total.shippingCost ? formatAmount(data.productOverview.total.shippingCost) : '-' }}{{ data.productOverview.total.otherCost ? formatAmount(data.productOverview.total.otherCost) : '-' }}{{ data.productOverview.total.refundAmount ? formatAmount(data.productOverview.total.refundAmount) : '-' }}{{ data.productOverview.total.totalPromotionFee ? formatAmount(data.productOverview.total.totalPromotionFee) : '-' }}{{ data.productOverview.total.brushFee ? formatAmount(data.productOverview.total.brushFee) : '-' }}{{ data.productOverview.total.feeRatio !== undefined ? formatPercentPlain(data.productOverview.total.feeRatio) : '-' }}{{ data.productOverview.total.roi !== undefined ? data.productOverview.total.roi.toFixed(2) : '-' }}{{ data.productOverview.total.totalProfitBeforeTax ? formatAmount(data.productOverview.total.totalProfitBeforeTax) : '-' }}{{ data.productOverview.total.salesTaxAmount ? formatAmount(data.productOverview.total.salesTaxAmount) : '-' }}{{ data.productOverview.total.profitAfterTax ? formatAmount(data.productOverview.total.profitAfterTax) : '-' }}