From 093d23d3b1a48db807e052352b390307e8e3fed5 Mon Sep 17 00:00:00 2001 From: ah-max150 Date: Tue, 25 Aug 2026 20:38:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E5=8F=B0=E5=8A=A8=E7=94=BB=E4=BA=A4=E4=BA=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mcp/adapter/bi/model/BiKpiSlimVO.java | 4 +- .../model/vo/WorkbenchKpiItemVO.java | 9 +- .../service/impl/BiWorkbenchServiceImpl.java | 57 ++--- .../src/api/bi/workbench/types/types.vo.ts | 3 +- .../components/AnimatedMoneyCell.vue | 23 ++ .../components/AnimatedNumberText.vue | 64 ++++++ .../web-antd/src/views/bi/workbench/index.vue | 213 ++++++++++++++---- .../views/bi/workbench/tabs/compare/index.vue | 53 ++++- .../components/CategorySummaryTable.vue | 63 +++--- .../components/FinanceCostPieChart.vue | 6 +- .../finance/components/FinanceKpiGrid.vue | 113 ++++++++-- .../finance/components/FinanceTrendChart.vue | 6 +- .../components/PlatformSummaryCard.vue | 67 +++--- .../finance/components/ShopSummaryTable.vue | 67 +++--- .../components/WorkbenchDimChartsCard.vue | 18 +- 15 files changed, 545 insertions(+), 221 deletions(-) create mode 100644 ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/components/AnimatedMoneyCell.vue create mode 100644 ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/components/AnimatedNumberText.vue diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/agent/mcp/adapter/bi/model/BiKpiSlimVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/agent/mcp/adapter/bi/model/BiKpiSlimVO.java index d66e2467..cdc441e9 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/agent/mcp/adapter/bi/model/BiKpiSlimVO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/agent/mcp/adapter/bi/model/BiKpiSlimVO.java @@ -5,12 +5,12 @@ import lombok.Data; import java.math.BigDecimal; -/** 工作台 KPI 瘦项。 */ +/** 工作台 KPI 瘦项(value 为原始数值,展示格式化由调用方负责)。 */ @Data @Builder public class BiKpiSlimVO { private String label; - private String value; + private BigDecimal value; private String unit; private BigDecimal changePct; private BigDecimal yoyChangePct; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/workbench/model/vo/WorkbenchKpiItemVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/workbench/model/vo/WorkbenchKpiItemVO.java index a246ec9c..d89ddc74 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/workbench/model/vo/WorkbenchKpiItemVO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/workbench/model/vo/WorkbenchKpiItemVO.java @@ -7,6 +7,9 @@ import lombok.NoArgsConstructor; import java.math.BigDecimal; +/** + * 工作台 KPI 项:value 为原始数值,千分位等展示由前端负责。 + */ @Data @Builder @NoArgsConstructor @@ -15,7 +18,11 @@ public class WorkbenchKpiItemVO { private String label; - private String value; + /** + * 主指标原始值(金额为元、单量为笔、销量为件、比率为百分数、ROI 为倍数)。 + * 不含千分位格式化。 + */ + private BigDecimal value; private String unit; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/workbench/service/impl/BiWorkbenchServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/workbench/service/impl/BiWorkbenchServiceImpl.java index 28c3eb3c..7667e543 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/workbench/service/impl/BiWorkbenchServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/workbench/service/impl/BiWorkbenchServiceImpl.java @@ -32,8 +32,6 @@ import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; import java.math.BigDecimal; import java.math.RoundingMode; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.ArrayList; @@ -42,7 +40,6 @@ import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Set; @@ -657,77 +654,76 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService { List list = new ArrayList<>(); // —— 成交口径(不含已取消/未知)—— - list.add(kpi("成交金额", formatYuanComma(cur.totalDealAmount()), "元", cur.totalDealAmount(), prev.totalDealAmount(), yoy.totalDealAmount(), + list.add(kpi("成交金额", yuan2(cur.totalDealAmount()), "元", cur.totalDealAmount(), prev.totalDealAmount(), yoy.totalDealAmount(), "成交状态实收", cur.totalDealAmount(), true)); list.add(kpiCount("成交单量", cur.dealOrderCount(), prev.dealOrderCount(), yoy.dealOrderCount(), "单", "日均 " + avgDailyDealOrders.stripTrailingZeros().toPlainString() + " 单")); list.add(kpiCount("成交销量", cur.dealQuantitySum(), prev.dealQuantitySum(), yoy.dealQuantitySum(), "件", "成交状态件数")); - list.add(kpi("成交客单价", formatYuanComma(cur.dealAverageOrderValue()), "元", + list.add(kpi("成交客单价", yuan2(cur.dealAverageOrderValue()), "元", cur.dealAverageOrderValue(), prev.dealAverageOrderValue(), yoy.dealAverageOrderValue(), "成交金额/成交单量", cur.dealAverageOrderValue(), false)); // —— 净销售口径(成交 − 退款)—— - list.add(kpi("净销售额", formatYuanComma(cur.totalSales()), "元", cur.totalSales(), prev.totalSales(), yoy.totalSales(), + list.add(kpi("净销售额", yuan2(cur.totalSales()), "元", cur.totalSales(), prev.totalSales(), yoy.totalSales(), "成交−退款", cur.totalSales(), true)); list.add(kpiCount("净销售单量", cur.orderCount(), prev.orderCount(), yoy.orderCount(), "单", "日均 " + avgDailySalesOrders.stripTrailingZeros().toPlainString() + " 单")); list.add(kpiCount("净销量", cur.salesQuantitySum(), prev.salesQuantitySum(), yoy.salesQuantitySum(), "件", "成交件数−退款件数")); - list.add(kpi("净销售客单价", formatYuanComma(cur.averageOrderValue()), "元", + list.add(kpi("净销售客单价", yuan2(cur.averageOrderValue()), "元", cur.averageOrderValue(), prev.averageOrderValue(), yoy.averageOrderValue(), "净销售额/净销售单量", cur.averageOrderValue(), false)); // —— 退款 —— - list.add(kpi("退款额", formatYuanComma(cur.totalRefund()), "元", cur.totalRefund(), prev.totalRefund(), yoy.totalRefund(), + list.add(kpi("退款额", yuan2(cur.totalRefund()), "元", cur.totalRefund(), prev.totalRefund(), yoy.totalRefund(), "计入退款状态", cur.totalRefund(), true)); - list.add(kpi("退款率", refundRate.setScale(2, RoundingMode.HALF_UP).toPlainString(), "%", + list.add(kpi("退款率", refundRate.setScale(2, RoundingMode.HALF_UP), "%", refundRate, safePct(prev.totalRefund(), prev.totalSales()), safePct(yoy.totalRefund(), yoy.totalSales()), "退款/净销售额", null, null)); // —— 成本 —— - list.add(kpi("订单成本", formatYuanComma(cur.totalCost()), "元", cur.totalCost(), prev.totalCost(), yoy.totalCost(), + list.add(kpi("订单成本", yuan2(cur.totalCost()), "元", cur.totalCost(), prev.totalCost(), yoy.totalCost(), "成本率 " + costRate.stripTrailingZeros().toPlainString() + "%", cur.totalCost(), true)); - list.add(kpi("商品成本", formatYuanComma(cur.productCost()), "元", cur.productCost(), prev.productCost(), yoy.productCost(), + list.add(kpi("商品成本", yuan2(cur.productCost()), "元", cur.productCost(), prev.productCost(), yoy.productCost(), null, cur.productCost(), true)); - list.add(kpi("运费成本", formatYuanComma(cur.freightCost()), "元", cur.freightCost(), prev.freightCost(), yoy.freightCost(), + list.add(kpi("运费成本", yuan2(cur.freightCost()), "元", cur.freightCost(), prev.freightCost(), yoy.freightCost(), null, cur.freightCost(), true)); - list.add(kpi("其他成本", formatYuanComma(cur.otherCost()), "元", cur.otherCost(), prev.otherCost(), yoy.otherCost(), + list.add(kpi("其他成本", yuan2(cur.otherCost()), "元", cur.otherCost(), prev.otherCost(), yoy.otherCost(), null, cur.otherCost(), true)); // —— 利润与费用 —— - list.add(kpi("毛利润", formatYuanComma(cur.grossOrder()), "元", cur.grossOrder(), prev.grossOrder(), yoy.grossOrder(), + list.add(kpi("毛利润", yuan2(cur.grossOrder()), "元", cur.grossOrder(), prev.grossOrder(), yoy.grossOrder(), "毛利率 " + grossMarginPct.stripTrailingZeros().toPlainString() + "%", cur.grossOrder(), true)); - list.add(kpi("推广费", formatYuanComma(cur.promotion()), "元", cur.promotion(), prev.promotion(), yoy.promotion(), + list.add(kpi("推广费", yuan2(cur.promotion()), "元", cur.promotion(), prev.promotion(), yoy.promotion(), null, cur.promotion(), true)); - list.add(kpi("刷单费", formatYuanComma(cur.brush()), "元", cur.brush(), prev.brush(), yoy.brush(), + list.add(kpi("刷单费", yuan2(cur.brush()), "元", cur.brush(), prev.brush(), yoy.brush(), null, cur.brush(), true)); - list.add(kpi("税额", formatYuanComma(cur.tax()), "元", cur.tax(), prev.tax(), yoy.tax(), + list.add(kpi("税额", yuan2(cur.tax()), "元", cur.tax(), prev.tax(), yoy.tax(), "税率 " + taxRate.multiply(new BigDecimal("100")).stripTrailingZeros().toPlainString() + "%", cur.tax(), true)); - list.add(kpi("净利润", formatYuanComma(cur.netProfit()), "元", cur.netProfit(), prev.netProfit(), yoy.netProfit(), + list.add(kpi("净利润", yuan2(cur.netProfit()), "元", cur.netProfit(), prev.netProfit(), yoy.netProfit(), "净利率 " + netMarginPct.stripTrailingZeros().toPlainString() + "%", cur.netProfit(), true)); // —— 运营效率 —— - list.add(kpi("广告ROI", roi.stripTrailingZeros().toPlainString(), ":1", roi, prevRoi, yoyRoi, + list.add(kpi("广告ROI", roi.setScale(2, RoundingMode.HALF_UP).stripTrailingZeros(), ":1", roi, prevRoi, yoyRoi, "净销售额/推广费", null, null)); return list; } - /** 非金额类 KPI(单量、件数等) */ + /** 非金额类 KPI(单量、件数等):value 为原始整数 */ private WorkbenchKpiItemVO kpiCount(String label, int cur, int prev, int yoy, String unit, String sub) { - DecimalFormat df = new DecimalFormat("#,###", DecimalFormatSymbols.getInstance(Locale.CHINA)); - return kpi(label, df.format(cur), unit, + return kpi(label, BigDecimal.valueOf(cur), unit, BigDecimal.valueOf(cur), BigDecimal.valueOf(prev), BigDecimal.valueOf(yoy), sub, null, null); } /** - * 单张 KPI:展示格式化主值 + 环比/同比变化率;{@code amountYuan} 供前端换算「万」; - * {@code preferWanDisplay} 为 true 时建议主数字用万展示。 + * 单张 KPI:原始数值 + 环比/同比变化率;{@code amountYuan} 供前端换算「万」; + * {@code preferWanDisplay} 为 true 时建议主数字用万展示。千分位由前端格式化。 */ - private WorkbenchKpiItemVO kpi(String label, String value, String unit, + private WorkbenchKpiItemVO kpi(String label, BigDecimal value, String unit, BigDecimal curAmt, BigDecimal prevAmt, BigDecimal yoyAmt, String sub, BigDecimal amountYuan, Boolean preferWanDisplay) { BigDecimal change = pctChange(curAmt, prevAmt); @@ -799,7 +795,7 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService { return new DateRange(range.startDate().minusMonths(1), range.endDate().minusMonths(1)); } - /** 金额统一保留两位小数(输出 VO 与前端展示) */ + /** 金额统一保留两位小数(输出 VO) */ private static BigDecimal yuan2(BigDecimal yuan) { if (yuan == null) { return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP); @@ -807,15 +803,6 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService { return yuan.setScale(2, RoundingMode.HALF_UP); } - /** KPI 主数字:千分位 + 两位小数的字符串 */ - private static String formatYuanComma(BigDecimal yuan) { - if (yuan == null) { - return "0.00"; - } - BigDecimal v = yuan.setScale(2, RoundingMode.HALF_UP); - return new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(Locale.CHINA)).format(v); - } - /** 计算 num/den*100,分母无效时返回 0 */ private static BigDecimal safePct(BigDecimal num, BigDecimal den) { if (den == null || den.compareTo(BigDecimal.ZERO) <= 0) { diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/bi/workbench/types/types.vo.ts b/ecom-dmb-frontend/apps/web-antd/src/api/bi/workbench/types/types.vo.ts index 247e28d8..86bb72e7 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/bi/workbench/types/types.vo.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/bi/workbench/types/types.vo.ts @@ -18,7 +18,8 @@ export namespace WorkbenchVO { export interface KpiItem { label: string; - value: string; + /** 主指标原始数值(金额为元;不含千分位) */ + value: number; unit: string; changePct?: number; up?: boolean; diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/components/AnimatedMoneyCell.vue b/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/components/AnimatedMoneyCell.vue new file mode 100644 index 00000000..f76f8ca3 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/components/AnimatedMoneyCell.vue @@ -0,0 +1,23 @@ + + + diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/components/AnimatedNumberText.vue b/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/components/AnimatedNumberText.vue new file mode 100644 index 00000000..eaa6f396 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/components/AnimatedNumberText.vue @@ -0,0 +1,64 @@ + + + diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/index.vue index d14e1646..da12237f 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/index.vue @@ -1,5 +1,14 @@ @@ -301,7 +298,7 @@ const cellRoi = (v: number | null | undefined) => }} - {{ cellMoney(shop.targetAmount) }} + {{ @@ -312,48 +309,48 @@ const cellRoi = (v: number | null | undefined) => - {{ formatAmount(shop.salesAmount as number) }} + - {{ formatAmount(shop.dealAmount as number ) }} + {{ formatIntCell(shop.orderCount) }} - {{ cellMoney(shop.averageOrderValue) }} + - {{ cellMoney(shop.productCost) }} + - {{ cellMoney(shop.shippingCost) }} + - {{ cellMoney(shop.otherCost) }} + - {{ cellMoney(shop.orderCost) }} + - {{ cellMoney(shop.refundAmount) }} + - {{ cellMoney(shop.salesTaxAmount) }} + - {{ cellMoney(shop.totalPromotionFee) }} + - {{ cellMoney(shop.brushFee) }} + - {{ cellMoney(shop.grossProfit) }} + - {{ cellMoney(shop.totalProfitBeforeTax) }} + {{ @@ -366,7 +363,7 @@ const cellRoi = (v: number | null | undefined) => {{ cellRoi(shop.roi) }} - {{ cellMoney(shop.profitAfterTax) }} + @@ -393,7 +390,7 @@ const cellRoi = (v: number | null | undefined) => : '-' }} - {{ cellMoney(shopSummary?.total?.targetAmount) }} + {{ shopSummary?.total?.salesAmountAchievementRate !== undefined @@ -402,30 +399,30 @@ const cellRoi = (v: number | null | undefined) => }} - {{ cellMoney(shopSummary?.total?.salesAmount) }} - {{ cellMoney(shopSummary?.total?.dealAmount) }} + + {{ formatIntCell(shopSummary?.total?.orderCount) }} - {{ cellMoney(shopSummary?.total?.averageOrderValue) }} + - {{ cellMoney(shopSummary?.total?.productCost) }} - {{ cellMoney(shopSummary?.total?.shippingCost) }} - {{ cellMoney(shopSummary?.total?.otherCost) }} - {{ cellMoney(shopSummary?.total?.orderCost) }} - {{ cellMoney(shopSummary?.total?.refundAmount) }} - {{ cellMoney(shopSummary?.total?.salesTaxAmount) }} - {{ cellMoney(shopSummary?.total?.totalPromotionFee) }} - {{ cellMoney(shopSummary?.total?.brushFee) }} + + + + + + + + - {{ cellMoney(shopSummary?.total?.grossProfit) }} - {{ cellMoney(shopSummary?.total?.totalProfitBeforeTax) }} + + {{ shopSummary?.total?.feeRatio !== undefined ? formatFeeRatioPercent(shopSummary?.total?.feeRatio) : '-' }} {{ cellRoi(shopSummary?.total?.roi) }} {{ cellMoney(shopSummary?.total?.profitAfterTax) }} + > diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/multi/components/WorkbenchDimChartsCard.vue b/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/multi/components/WorkbenchDimChartsCard.vue index daf666f2..45865217 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/multi/components/WorkbenchDimChartsCard.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/multi/components/WorkbenchDimChartsCard.vue @@ -95,6 +95,10 @@ const drawMultiBarChart = () => { const bottomPad = multiChartGridBottomPx(r.length, rotateLabels); renderMultiBar({ + animation: true, + animationDuration: 500, + animationDurationUpdate: 650, + animationEasingUpdate: 'cubicOut', tooltip: { trigger: 'axis', backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff', @@ -176,7 +180,7 @@ const drawMultiBarChart = () => { itemStyle: { color: isDark ? '#fb7185' : '#e11d48' }, }, ], - }); + }, false); }; const drawMultiLineChart = () => { @@ -191,6 +195,10 @@ const drawMultiLineChart = () => { const bottomPad = multiChartGridBottomPx(r.length, rotateLabels); renderMultiLine({ + animation: true, + animationDuration: 500, + animationDurationUpdate: 650, + animationEasingUpdate: 'cubicOut', tooltip: { trigger: 'axis', backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff', @@ -250,7 +258,7 @@ const drawMultiLineChart = () => { itemStyle: { color: isDark ? '#fbbf24' : '#d97706' }, }, ], - }); + }, false); }; const drawRankBarChart = () => { @@ -265,6 +273,10 @@ const drawRankBarChart = () => { ); renderRankBar({ + animation: true, + animationDuration: 500, + animationDurationUpdate: 650, + animationEasingUpdate: 'cubicOut', tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' }, @@ -332,7 +344,7 @@ const drawRankBarChart = () => { }, }, ], - }); + }, false); }; const redraw = async () => {