From 5a37e8f230694d8b67871b5e3642cad4c99187f0 Mon Sep 17 00:00:00 2001 From: ah-max150 Date: Sat, 5 Sep 2026 11:31:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BA=97=E9=93=BA=E4=B8=8E=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E7=8B=AC=E7=AB=8B=E6=A6=82=E8=A7=88=E9=A1=B5=E5=B9=B6?= =?UTF-8?q?=E5=AF=B9=E9=BD=90=E7=BB=8F=E8=90=A5=20KPI=20=E5=8F=A3=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60906__bi_platform_overview_permission.sql | 8 + .../V20260906b__platform_overview_menu.sql | 4 + .../BiPlatformOverviewController.java | 32 ++ .../model/dto/PlatformOverviewQueryDTO.java | 37 ++ .../model/vo/PlatformOverviewVO.java | 151 ++++++ .../service/BiPlatformOverviewService.java | 12 + .../impl/BiPlatformOverviewServiceImpl.java | 487 +++++++++++++++++ .../model/vo/ShopOverviewStatisticsVO.java | 103 +--- .../impl/BiShopOverviewServiceImpl.java | 227 +++++--- .../src/main/resources/sql/init/sys_seed.sql | 12 + .../src/api/ec/platform/overview/apis.ts | 13 + .../src/api/ec/platform/overview/index.ts | 2 + .../api/ec/platform/overview/types/index.ts | 2 + .../ec/platform/overview/types/types.dto.ts | 7 + .../ec/platform/overview/types/types.vo.ts | 147 +++++ .../src/api/ec/shop/types/types.vo.ts | 50 +- .../web-antd/src/views/bi/workbench/index.vue | 19 + .../finance/components/OverviewTables.vue | 4 + .../components/PlatformSummaryCard.vue | 33 +- .../finance/components/ShopSummaryTable.vue | 14 + .../views/bi/workbench/tabs/finance/index.vue | 4 + .../components/PlatformHeroBanner.vue | 175 ++++++ .../components/PlatformProductRankStrip.vue | 116 ++++ .../overview/components/TimeRangeBar.vue | 385 ++++++++++++++ .../overview/constants/platform-ui.ts | 16 + .../src/views/ec/platform/overview/index.vue | 502 ++++++++++++++++++ .../overview/components/ShopHeroBanner.vue | 172 ++++++ .../components/ShopProductRankStrip.vue | 119 +++++ .../ec/shop/overview/constants/shop-ui.ts | 16 + .../src/views/ec/shop/overview/index.vue | 239 +++++++-- 30 files changed, 2878 insertions(+), 230 deletions(-) create mode 100644 ecom-dmb-backend/sql/migration/V20260906__bi_platform_overview_permission.sql create mode 100644 ecom-dmb-backend/sql/migration/V20260906b__platform_overview_menu.sql create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/controller/BiPlatformOverviewController.java create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/model/dto/PlatformOverviewQueryDTO.java create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/model/vo/PlatformOverviewVO.java create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/service/BiPlatformOverviewService.java create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/service/impl/BiPlatformOverviewServiceImpl.java create mode 100644 ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/apis.ts create mode 100644 ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/index.ts create mode 100644 ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/types/index.ts create mode 100644 ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/types/types.dto.ts create mode 100644 ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/types/types.vo.ts create mode 100644 ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/components/PlatformHeroBanner.vue create mode 100644 ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/components/PlatformProductRankStrip.vue create mode 100644 ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/components/TimeRangeBar.vue create mode 100644 ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/constants/platform-ui.ts create mode 100644 ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/index.vue create mode 100644 ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/overview/components/ShopHeroBanner.vue create mode 100644 ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/overview/components/ShopProductRankStrip.vue create mode 100644 ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/overview/constants/shop-ui.ts diff --git a/ecom-dmb-backend/sql/migration/V20260906__bi_platform_overview_permission.sql b/ecom-dmb-backend/sql/migration/V20260906__bi_platform_overview_permission.sql new file mode 100644 index 00000000..bc962bc6 --- /dev/null +++ b/ecom-dmb-backend/sql/migration/V20260906__bi_platform_overview_permission.sql @@ -0,0 +1,8 @@ +-- 平台分析模块权限:bi:platform / bi:platform:overview +INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`) +SELECT 3725, (SELECT id FROM `sys_permission` WHERE `code` = 'bi' LIMIT 1), 'bi:platform', '平台分析', 'module', 1, '', 25 +FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3725 OR `code` = 'bi:platform'); + +INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`) +SELECT 3726, (SELECT id FROM `sys_permission` WHERE `code` = 'bi:platform' LIMIT 1), 'bi:platform:overview', '平台概览', 'api', 1, '', 1 +FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3726 OR `code` = 'bi:platform:overview'); diff --git a/ecom-dmb-backend/sql/migration/V20260906b__platform_overview_menu.sql b/ecom-dmb-backend/sql/migration/V20260906b__platform_overview_menu.sql new file mode 100644 index 00000000..b7f9aac4 --- /dev/null +++ b/ecom-dmb-backend/sql/migration/V20260906b__platform_overview_menu.sql @@ -0,0 +1,4 @@ +-- 平台概览嵌入页菜单(hideInMenu,由工作台跳转打开) +INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `name`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`) +SELECT 53, (SELECT id FROM `sys_menu` WHERE `id` = 6 OR `name` = '电商页面' LIMIT 1), 0, '平台概览', 'PlatformOverview', '平台概览', '/ec/platform/overview/:code', '/ec/platform/overview/index', '', 'lucide:layers', 'embedded', 0, 1, 1, 4 +FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 53 OR `name` = '平台概览' OR `route_name` = 'PlatformOverview'); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/controller/BiPlatformOverviewController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/controller/BiPlatformOverviewController.java new file mode 100644 index 00000000..8500aafd --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/controller/BiPlatformOverviewController.java @@ -0,0 +1,32 @@ +package top.xyquan.ecomdmbbackend.modules.bi.platformoverview.controller; + +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; +import top.xyquan.ecomdmbbackend.common.response.ApiResponse; +import top.xyquan.ecomdmbbackend.modules.bi.platformoverview.model.dto.PlatformOverviewQueryDTO; +import top.xyquan.ecomdmbbackend.modules.bi.platformoverview.model.vo.PlatformOverviewVO; +import top.xyquan.ecomdmbbackend.modules.bi.platformoverview.service.BiPlatformOverviewService; + +/** + * 平台概览 API:公司下指定平台全部店铺的经营汇总。 + */ +@RestController +@RequestMapping("/api/bi/platform") +public class BiPlatformOverviewController { + + private final BiPlatformOverviewService biPlatformOverviewService; + + public BiPlatformOverviewController(BiPlatformOverviewService biPlatformOverviewService) { + this.biPlatformOverviewService = biPlatformOverviewService; + } + + @PostMapping("/overview") + @RequirePermission(value = "bi:platform:overview", description = "查询平台概览", allowSuper = true) + public ApiResponse overview(@Valid @RequestBody PlatformOverviewQueryDTO queryDTO) { + return ApiResponse.success("获取平台概览成功", biPlatformOverviewService.getPlatformOverview(queryDTO)); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/model/dto/PlatformOverviewQueryDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/model/dto/PlatformOverviewQueryDTO.java new file mode 100644 index 00000000..305da4fc --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/model/dto/PlatformOverviewQueryDTO.java @@ -0,0 +1,37 @@ +package top.xyquan.ecomdmbbackend.modules.bi.platformoverview.model.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.util.List; + +/** + * 平台概览查询:按公司下某平台全部店铺汇总;日期支持 start/end 或 dateRange(二选一)。 + */ +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class PlatformOverviewQueryDTO { + + /** 平台代码(如 pdd、taobao) */ + @NotBlank(message = "平台代码不能为空") + private String platformCode; + + /** 开始日期(与 endDate 成对;也可改用 dateRange) */ + private LocalDate startDate; + + /** 结束日期 */ + private LocalDate endDate; + + /** + * 日期范围(1 个=当天,2 个=起止);与 startDate/endDate 二选一,优先本字段。 + */ + @Size(min = 1, max = 2, message = "日期范围数组必须包含1-2个日期") + private List dateRange; + + /** 税率(默认 4%) */ + private BigDecimal taxRate = new BigDecimal("0.04"); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/model/vo/PlatformOverviewVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/model/vo/PlatformOverviewVO.java new file mode 100644 index 00000000..cf5c6fd2 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/model/vo/PlatformOverviewVO.java @@ -0,0 +1,151 @@ +package top.xyquan.ecomdmbbackend.modules.bi.platformoverview.model.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchCostSliceVO; +import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchKpiItemVO; +import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchTrendPointVO; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.util.List; + +/** + * 平台概览响应:KPI/趋势与工作台同口径,并附商品/品类表与销量占比。 + */ +@Data +public class PlatformOverviewVO { + + private String platformCode; + + private String platformName; + + /** 与工作台经营概览同结构的 KPI 列表 */ + private List kpis; + + /** 成交/净销售/利润日趋势 */ + private List dealTrend; + + /** 各商品净销售额占比(饼图,按销售额 Top) */ + private List productSalesShare; + + private String momCompareDateStart; + private String momCompareDateEnd; + private String yoyCompareDateStart; + private String yoyCompareDateEnd; + + /** 兼容旧前端:扁平 KPI 摘要 */ + private BigDecimal totalSalesAmount; + private BigDecimal monthOverMonthGrowth; + private Integer totalOrderCount; + private BigDecimal totalPromotionFee; + private BigDecimal averageFeeRatio; + private BigDecimal totalNetProfitAfterTax; + private BigDecimal totalTaxAmount; + private Integer totalTargetOrderCount; + private BigDecimal totalTargetAmount; + private BigDecimal orderCountAchievementRate; + private BigDecimal salesAmountAchievementRate; + private BigDecimal totalROI; + private BigDecimal averageOrderValue; + private BigDecimal refundAmount; + private BigDecimal totalProfitBeforeTax; + + private List productSalesTop10; + + /** @deprecated 使用 dealTrend;保留以免旧客户端空指针 */ + private TrendData salesAmountTrend; + /** @deprecated 使用 dealTrend */ + private TrendData orderCountTrend; + + private ProductOverview productOverview; + + private CategoryOverview categoryOverview; + + @Data + public static class ProductSalesRankItem { + private Long productId; + private String productName; + private String productCode; + private Integer orderCount; + private BigDecimal salesAmount; + } + + @Data + public static class ProductOverview { + private ProductSummary total; + private List products; + } + + @Data + public static class CategoryOverview { + private CategorySummary total; + private List categories; + } + + @Data + public static class ProductSummary { + private Long productId; + private String productName; + private String productCode; + private BigDecimal salesAmount; + private BigDecimal dealAmount; + private Integer salesOrderCount; + private Integer dealOrderCount; + private Integer dealQuantitySum; + private Integer salesQuantitySum; + private BigDecimal salesAverageOrderValue; + private BigDecimal dealAverageOrderValue; + private BigDecimal productCost; + private BigDecimal shippingCost; + private BigDecimal otherCost; + private BigDecimal orderCost; + private BigDecimal refundAmount; + private BigDecimal totalPromotionFee; + private BigDecimal brushFee; + private BigDecimal feeRatio; + private BigDecimal totalProfitBeforeTax; + private BigDecimal salesTaxAmount; + private BigDecimal profitAfterTax; + private BigDecimal roi; + } + + @Data + public static class CategorySummary { + private Long categoryId; + private String categoryName; + private BigDecimal salesAmount; + private BigDecimal dealAmount; + private Integer salesOrderCount; + private Integer dealOrderCount; + private Integer dealQuantitySum; + private Integer salesQuantitySum; + private BigDecimal salesAverageOrderValue; + private BigDecimal dealAverageOrderValue; + private BigDecimal productCost; + private BigDecimal shippingCost; + private BigDecimal otherCost; + private BigDecimal orderCost; + private BigDecimal refundAmount; + private BigDecimal totalPromotionFee; + private BigDecimal brushFee; + private BigDecimal feeRatio; + private BigDecimal totalProfitBeforeTax; + private BigDecimal salesTaxAmount; + private BigDecimal profitAfterTax; + private BigDecimal roi; + } + + @Data + public static class TrendData { + private BigDecimal total; + private List dailyDataList; + } + + @Data + public static class TrendDataItem { + @JsonFormat(pattern = "yyyy-MM-dd") + private LocalDate date; + private BigDecimal value; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/service/BiPlatformOverviewService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/service/BiPlatformOverviewService.java new file mode 100644 index 00000000..f2d2f6c4 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/service/BiPlatformOverviewService.java @@ -0,0 +1,12 @@ +package top.xyquan.ecomdmbbackend.modules.bi.platformoverview.service; + +import top.xyquan.ecomdmbbackend.modules.bi.platformoverview.model.dto.PlatformOverviewQueryDTO; +import top.xyquan.ecomdmbbackend.modules.bi.platformoverview.model.vo.PlatformOverviewVO; + +/** + * BI 平台概览:按平台下全部店铺汇总;订单读 Mongo 日汇聚,推广/刷单/目标读 MySQL。 + */ +public interface BiPlatformOverviewService { + + PlatformOverviewVO getPlatformOverview(PlatformOverviewQueryDTO queryDTO); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/service/impl/BiPlatformOverviewServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/service/impl/BiPlatformOverviewServiceImpl.java new file mode 100644 index 00000000..81417868 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/service/impl/BiPlatformOverviewServiceImpl.java @@ -0,0 +1,487 @@ +package top.xyquan.ecomdmbbackend.modules.bi.platformoverview.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import org.springframework.stereotype.Service; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; +import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyProductDoc; +import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyShopDoc; +import top.xyquan.ecomdmbbackend.modules.bi.orderstat.query.BiOrderStatQueryService; +import top.xyquan.ecomdmbbackend.modules.bi.overview.model.agg.OverviewAggRows; +import top.xyquan.ecomdmbbackend.modules.bi.overview.model.vo.CompanyOverviewVO; +import top.xyquan.ecomdmbbackend.modules.bi.overview.service.CompanyOverviewService; +import top.xyquan.ecomdmbbackend.modules.bi.platformoverview.model.dto.PlatformOverviewQueryDTO; +import top.xyquan.ecomdmbbackend.modules.bi.platformoverview.model.vo.PlatformOverviewVO; +import top.xyquan.ecomdmbbackend.modules.bi.platformoverview.service.BiPlatformOverviewService; +import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchCostSliceVO; +import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchTrendPointVO; +import top.xyquan.ecomdmbbackend.modules.bi.workbench.support.BiFinanceKpiAssembler; +import top.xyquan.ecomdmbbackend.modules.bi.workbench.support.BiWorkbenchFeeLoader; +import top.xyquan.ecomdmbbackend.modules.ec.platform.model.enums.PlatformCode; +import top.xyquan.ecomdmbbackend.modules.ec.product.mapper.ProductMapper; +import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductPO; +import top.xyquan.ecomdmbbackend.modules.ec.shop.model.po.ShopPO; +import top.xyquan.ecomdmbbackend.modules.ec.shop.monthlytarget.mapper.ShopMonthlyTargetMapper; +import top.xyquan.ecomdmbbackend.modules.ec.shop.monthlytarget.model.po.ShopMonthlyTargetPO; +import top.xyquan.ecomdmbbackend.modules.ec.shop.service.ShopService; +import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * 平台概览:公司下该平台全部店铺的 Mongo 日汇聚 + 费用/目标;KPI 与工作台同口径。 + */ +@Service +public class BiPlatformOverviewServiceImpl implements BiPlatformOverviewService { + + private static final BigDecimal DEFAULT_TAX_RATE = new BigDecimal("0.04"); + private static final int PRODUCT_SHARE_LIMIT = 12; + + private final CurrentUserContext currentUserContext; + private final ShopService shopService; + private final BiOrderStatQueryService orderStatQueryService; + private final BiWorkbenchFeeLoader feeLoader; + private final CompanyOverviewService companyOverviewService; + private final ShopMonthlyTargetMapper shopMonthlyTargetMapper; + private final ProductMapper productMapper; + + public BiPlatformOverviewServiceImpl(CurrentUserContext currentUserContext, + ShopService shopService, + BiOrderStatQueryService orderStatQueryService, + BiWorkbenchFeeLoader feeLoader, + CompanyOverviewService companyOverviewService, + ShopMonthlyTargetMapper shopMonthlyTargetMapper, + ProductMapper productMapper) { + this.currentUserContext = currentUserContext; + this.shopService = shopService; + this.orderStatQueryService = orderStatQueryService; + this.feeLoader = feeLoader; + this.companyOverviewService = companyOverviewService; + this.shopMonthlyTargetMapper = shopMonthlyTargetMapper; + this.productMapper = productMapper; + } + + @Override + public PlatformOverviewVO getPlatformOverview(PlatformOverviewQueryDTO queryDTO) { + BigDecimal taxRate = queryDTO.getTaxRate() != null ? queryDTO.getTaxRate() : DEFAULT_TAX_RATE; + Long companyId = currentUserContext.getCurrentCompanyId(); + LocalDate start = resolveStart(queryDTO); + LocalDate end = resolveEnd(queryDTO); + if (start.isAfter(end)) { + throw new BusinessException("开始日期不能晚于结束日期"); + } + + String platformCode = queryDTO.getPlatformCode().trim(); + List shops = loadPlatformShops(companyId, platformCode); + String platformName = PlatformCode.labelOf(platformCode); + + PlatformOverviewVO vo = new PlatformOverviewVO(); + vo.setPlatformCode(platformCode); + vo.setPlatformName(platformName); + + LocalDate[] mom = BiFinanceKpiAssembler.lastMonthSameSpan(start, end); + LocalDate[] yoy = BiFinanceKpiAssembler.yoySameSpan(start, end); + vo.setMomCompareDateStart(mom[0].toString()); + vo.setMomCompareDateEnd(mom[1].toString()); + vo.setYoyCompareDateStart(yoy[0].toString()); + vo.setYoyCompareDateEnd(yoy[1].toString()); + + if (shops.isEmpty()) { + fillEmpty(vo, start, end, taxRate); + return vo; + } + + List shopIds = shops.stream().map(ShopPO::getId).filter(Objects::nonNull).toList(); + PeriodBundle cur = loadPeriod(companyId, shops, shopIds, start, end, taxRate); + PeriodBundle prev = loadPeriodTotalsOnly(companyId, shopIds, mom[0], mom[1], taxRate); + PeriodBundle yoyBundle = loadPeriodTotalsOnly(companyId, shopIds, yoy[0], yoy[1], taxRate); + + BiFinanceKpiAssembler.Totals curT = cur.totals(); + BiFinanceKpiAssembler.Totals prevT = prev.totals(); + BiFinanceKpiAssembler.Totals yoyT = yoyBundle.totals(); + + List dealTrend = + BiFinanceKpiAssembler.buildTrendFromDaily(cur.dailyRows(), start, end, curT); + + vo.setKpis(BiFinanceKpiAssembler.buildKpis(curT, prevT, yoyT, start, end, taxRate)); + vo.setDealTrend(dealTrend); + + Map products = loadProducts(cur.tables().getProductTable()); + vo.setProductOverview(mapProductOverview(cur.tables().getProductTable(), products)); + vo.setCategoryOverview(mapCategoryOverview(cur.tables().getCategoryTable())); + vo.setProductSalesShare(buildProductSalesShare(vo.getProductOverview(), curT.totalSales())); + fillProductSalesTop10(vo); + fillLegacyFlatFields(vo, curT, prevT); + fillTargets(vo, companyId, shopIds, start, end, curT.totalSales(), curT.orderCount()); + fillLegacyTrends(vo, dealTrend); + return vo; + } + + /** 当前区间:店铺合计 + 日趋势 + 商品/品类汇总表。 */ + private PeriodBundle loadPeriod(Long companyId, List shops, List shopIds, + LocalDate start, LocalDate end, BigDecimal taxRate) { + Map platformByShopId = shops.stream() + .filter(s -> s.getId() != null) + .collect(Collectors.toMap(ShopPO::getId, + s -> s.getPlatformCode() != null ? s.getPlatformCode() : "", + (a, b) -> a)); + + List shopDocs = + orderStatQueryService.listShopDocs(companyId, shopIds, start, end); + List productDocs = + orderStatQueryService.listProductDocs(companyId, shopIds, start, end); + BiWorkbenchFeeLoader.FeeBundle fees = feeLoader.load(companyId, shopIds, start, end); + + List orderRows = + orderStatQueryService.toShopProductRows(productDocs, platformByShopId); + CompanyOverviewVO.WorkbenchTableBundle tables = + companyOverviewService.buildWorkbenchSummaryTablesFromAgg( + taxRate, companyId, shops, orderRows, + fees.promotionRows(), fees.brushRows(), start, end); + + BiOrderStatQueryService.ShopPeriodMetrics m = orderStatQueryService.sumShopDocs(shopDocs); + BiFinanceKpiAssembler.Totals totals = BiFinanceKpiAssembler.buildTotals( + m.salesAmount(), m.refundAmount(), + m.productCost(), m.freightCost(), m.otherCost(), + fees.promoTotal(), fees.brushTotal(), taxRate, + m.salesOrderCount(), m.salesQuantitySum(), + m.dealAmount(), m.dealOrderCount(), m.dealQuantitySum()); + + return new PeriodBundle(totals, orderStatQueryService.toDailyRows(shopDocs), tables); + } + + /** 环比/同比区间:只需 Totals,不建表。 */ + private PeriodBundle loadPeriodTotalsOnly(Long companyId, List shopIds, + LocalDate start, LocalDate end, BigDecimal taxRate) { + List shopDocs = + orderStatQueryService.listShopDocs(companyId, shopIds, start, end); + BiWorkbenchFeeLoader.FeeBundle fees = feeLoader.load(companyId, shopIds, start, end); + BiOrderStatQueryService.ShopPeriodMetrics m = orderStatQueryService.sumShopDocs(shopDocs); + BiFinanceKpiAssembler.Totals totals = BiFinanceKpiAssembler.buildTotals( + m.salesAmount(), m.refundAmount(), + m.productCost(), m.freightCost(), m.otherCost(), + fees.promoTotal(), fees.brushTotal(), taxRate, + m.salesOrderCount(), m.salesQuantitySum(), + m.dealAmount(), m.dealOrderCount(), m.dealQuantitySum()); + return new PeriodBundle(totals, List.of(), null); + } + + private List loadPlatformShops(Long companyId, String platformCode) { + return shopService.list(new LambdaQueryWrapper() + .eq(ShopPO::getCompanyId, companyId) + .eq(ShopPO::getPlatformCode, platformCode)); + } + + private static LocalDate resolveStart(PlatformOverviewQueryDTO dto) { + if (dto.getDateRange() != null && !dto.getDateRange().isEmpty()) { + return dto.getDateRange().get(0); + } + if (dto.getStartDate() != null) { + return dto.getStartDate(); + } + throw new BusinessException("日期范围不能为空"); + } + + private static LocalDate resolveEnd(PlatformOverviewQueryDTO dto) { + if (dto.getDateRange() != null && !dto.getDateRange().isEmpty()) { + return dto.getDateRange().size() == 1 + ? dto.getDateRange().get(0) + : dto.getDateRange().get(1); + } + if (dto.getEndDate() != null) { + return dto.getEndDate(); + } + throw new BusinessException("日期范围不能为空"); + } + + private void fillEmpty(PlatformOverviewVO vo, LocalDate start, LocalDate end, BigDecimal taxRate) { + BiFinanceKpiAssembler.Totals empty = BiFinanceKpiAssembler.Totals.empty(); + vo.setKpis(BiFinanceKpiAssembler.buildKpis(empty, empty, empty, start, end, taxRate)); + vo.setDealTrend(BiFinanceKpiAssembler.buildTrendFromDaily(List.of(), start, end, empty)); + vo.setProductSalesShare(Collections.emptyList()); + vo.setProductSalesTop10(Collections.emptyList()); + PlatformOverviewVO.ProductOverview po = new PlatformOverviewVO.ProductOverview(); + po.setProducts(List.of()); + vo.setProductOverview(po); + PlatformOverviewVO.CategoryOverview co = new PlatformOverviewVO.CategoryOverview(); + co.setCategories(List.of()); + vo.setCategoryOverview(co); + fillLegacyFlatFields(vo, empty, empty); + fillLegacyTrends(vo, vo.getDealTrend()); + } + + private void fillLegacyFlatFields(PlatformOverviewVO vo, + BiFinanceKpiAssembler.Totals cur, + BiFinanceKpiAssembler.Totals prev) { + vo.setTotalSalesAmount(BiFinanceKpiAssembler.yuan2(cur.totalSales())); + vo.setTotalOrderCount(cur.orderCount()); + vo.setRefundAmount(BiFinanceKpiAssembler.yuan2(cur.totalRefund())); + vo.setAverageOrderValue(BiFinanceKpiAssembler.yuan2(cur.averageOrderValue())); + vo.setTotalPromotionFee(BiFinanceKpiAssembler.yuan2(cur.promotion())); + vo.setAverageFeeRatio(cur.totalSales().compareTo(BigDecimal.ZERO) > 0 + ? cur.promotion().divide(cur.totalSales(), 4, RoundingMode.HALF_UP) + : BigDecimal.ZERO); + vo.setTotalTaxAmount(BiFinanceKpiAssembler.yuan2(cur.tax())); + vo.setTotalProfitBeforeTax(BiFinanceKpiAssembler.yuan2( + cur.grossOrder().subtract(cur.promotion()).subtract(cur.brush()))); + vo.setTotalNetProfitAfterTax(BiFinanceKpiAssembler.yuan2(cur.netProfit())); + vo.setTotalROI(cur.promotion().compareTo(BigDecimal.ZERO) > 0 + ? cur.totalSales().divide(cur.promotion(), 2, RoundingMode.HALF_UP) + : BigDecimal.ZERO); + vo.setMonthOverMonthGrowth(BiFinanceKpiAssembler.pctChange(cur.totalSales(), prev.totalSales())); + } + + private void fillLegacyTrends(PlatformOverviewVO vo, List dealTrend) { + PlatformOverviewVO.TrendData sales = new PlatformOverviewVO.TrendData(); + PlatformOverviewVO.TrendData orders = new PlatformOverviewVO.TrendData(); + List salesItems = new ArrayList<>(); + List orderItems = new ArrayList<>(); + BigDecimal salesTotal = BigDecimal.ZERO; + BigDecimal orderTotal = BigDecimal.ZERO; + if (dealTrend != null) { + for (WorkbenchTrendPointVO p : dealTrend) { + PlatformOverviewVO.TrendDataItem s = new PlatformOverviewVO.TrendDataItem(); + s.setDate(LocalDate.parse(p.getDate())); + s.setValue(BiFinanceKpiAssembler.nz(p.getSalesYuan())); + salesItems.add(s); + salesTotal = salesTotal.add(s.getValue()); + + PlatformOverviewVO.TrendDataItem o = new PlatformOverviewVO.TrendDataItem(); + o.setDate(s.getDate()); + o.setValue(BigDecimal.valueOf(p.getSalesOrderCount() != null ? p.getSalesOrderCount() : 0)); + orderItems.add(o); + orderTotal = orderTotal.add(o.getValue()); + } + } + sales.setDailyDataList(salesItems); + sales.setTotal(salesTotal); + orders.setDailyDataList(orderItems); + orders.setTotal(orderTotal); + vo.setSalesAmountTrend(sales); + vo.setOrderCountTrend(orders); + } + + private void fillTargets(PlatformOverviewVO vo, Long companyId, List shopIds, + LocalDate startDate, LocalDate endDate, + BigDecimal sales, int orderCount) { + List months = new ArrayList<>(); + LocalDate cur = startDate.withDayOfMonth(1); + LocalDate endMonth = endDate.withDayOfMonth(1); + while (!cur.isAfter(endMonth)) { + months.add(cur); + cur = cur.plusMonths(1); + } + List targets = months.isEmpty() || shopIds.isEmpty() ? List.of() + : shopMonthlyTargetMapper.selectList(new LambdaQueryWrapper() + .eq(ShopMonthlyTargetPO::getCompanyId, companyId) + .in(ShopMonthlyTargetPO::getShopId, shopIds) + .in(ShopMonthlyTargetPO::getTargetMonth, months)); + + BigDecimal targetAmt = targets.stream() + .map(t -> t.getTargetAmount() != null ? t.getTargetAmount() : BigDecimal.ZERO) + .reduce(BigDecimal.ZERO, BigDecimal::add); + int targetOrders = targets.stream() + .mapToInt(t -> t.getTargetOrderCount() != null ? t.getTargetOrderCount() : 0) + .sum(); + vo.setTotalTargetAmount(targetAmt); + vo.setTotalTargetOrderCount(targetOrders); + vo.setSalesAmountAchievementRate(achievement(sales, targetAmt)); + vo.setOrderCountAchievementRate(achievement(BigDecimal.valueOf(orderCount), BigDecimal.valueOf(targetOrders))); + } + + private static BigDecimal achievement(BigDecimal actual, BigDecimal target) { + if (target != null && target.compareTo(BigDecimal.ZERO) > 0) { + return BiFinanceKpiAssembler.nz(actual).divide(target, 4, RoundingMode.HALF_UP) + .multiply(new BigDecimal("100")); + } + return BiFinanceKpiAssembler.nz(actual).compareTo(BigDecimal.ZERO) > 0 + ? new BigDecimal("100") : BigDecimal.ZERO; + } + + private List buildProductSalesShare(PlatformOverviewVO.ProductOverview overview, + BigDecimal salesTotal) { + if (overview == null || overview.getProducts() == null || overview.getProducts().isEmpty()) { + return List.of(); + } + BigDecimal base = BiFinanceKpiAssembler.nz(salesTotal); + return overview.getProducts().stream() + .filter(p -> BiFinanceKpiAssembler.nz(p.getSalesAmount()).compareTo(BigDecimal.ZERO) > 0) + .sorted(Comparator.comparing(PlatformOverviewVO.ProductSummary::getSalesAmount, + Comparator.nullsFirst(BigDecimal::compareTo)).reversed()) + .limit(PRODUCT_SHARE_LIMIT) + .map(p -> { + BigDecimal amt = BiFinanceKpiAssembler.nz(p.getSalesAmount()); + BigDecimal pct = base.compareTo(BigDecimal.ZERO) > 0 + ? amt.multiply(new BigDecimal("100")).divide(base, 2, RoundingMode.HALF_UP) + : BigDecimal.ZERO; + String name = p.getProductName() != null ? p.getProductName() : "商品"; + return WorkbenchCostSliceVO.builder() + .name(name) + .value(BiFinanceKpiAssembler.yuan2(amt)) + .pct(pct) + .build(); + }) + .collect(Collectors.toList()); + } + + private Map loadProducts(CompanyOverviewVO.CategoryOverview productTable) { + if (productTable == null || productTable.getCategories() == null) { + return Map.of(); + } + Set ids = productTable.getCategories().stream() + .map(CompanyOverviewVO.CategorySummary::getCategoryId) + .filter(Objects::nonNull) + .filter(id -> id > 0) + .collect(Collectors.toSet()); + if (ids.isEmpty()) { + return Map.of(); + } + Map map = new HashMap<>(); + for (ProductPO p : productMapper.selectByIds(ids)) { + if (p != null && p.getId() != null) { + map.put(p.getId(), p); + } + } + return map; + } + + private static PlatformOverviewVO.ProductOverview mapProductOverview( + CompanyOverviewVO.CategoryOverview table, Map products) { + PlatformOverviewVO.ProductOverview po = new PlatformOverviewVO.ProductOverview(); + if (table == null) { + po.setProducts(List.of()); + return po; + } + po.setTotal(mapToProductSummary(table.getTotal(), null, products)); + if (table.getCategories() != null) { + po.setProducts(table.getCategories().stream() + .map(c -> mapToProductSummary(c, c.getCategoryId(), products)) + .collect(Collectors.toList())); + } else { + po.setProducts(List.of()); + } + return po; + } + + private static PlatformOverviewVO.ProductSummary mapToProductSummary( + CompanyOverviewVO.CategorySummary c, Long productId, Map products) { + PlatformOverviewVO.ProductSummary p = new PlatformOverviewVO.ProductSummary(); + if (c == null) { + return p; + } + p.setProductId(productId); + ProductPO product = productId != null ? products.get(productId) : null; + p.setProductName(product != null ? product.getName() : c.getCategoryName()); + p.setProductCode(product != null ? product.getProductCode() : null); + p.setSalesAmount(c.getSalesAmount()); + p.setDealAmount(c.getDealAmount()); + p.setSalesOrderCount(c.getSalesOrderCount()); + p.setDealOrderCount(c.getDealOrderCount()); + p.setDealQuantitySum(c.getDealQuantitySum()); + p.setSalesQuantitySum(c.getSalesQuantitySum()); + p.setSalesAverageOrderValue(c.getSalesAverageOrderValue()); + p.setDealAverageOrderValue(c.getDealAverageOrderValue()); + p.setProductCost(c.getProductCost()); + p.setShippingCost(c.getShippingCost()); + p.setOtherCost(c.getOtherCost()); + p.setOrderCost(c.getOrderCost()); + p.setRefundAmount(c.getRefundAmount()); + p.setTotalPromotionFee(c.getTotalPromotionFee()); + p.setBrushFee(c.getBrushFee()); + p.setFeeRatio(c.getFeeRatio()); + p.setTotalProfitBeforeTax(c.getTotalProfitBeforeTax()); + p.setSalesTaxAmount(c.getSalesTaxAmount()); + p.setProfitAfterTax(c.getProfitAfterTax()); + p.setRoi(c.getRoi()); + return p; + } + + private static PlatformOverviewVO.CategoryOverview mapCategoryOverview( + CompanyOverviewVO.CategoryOverview table) { + PlatformOverviewVO.CategoryOverview co = new PlatformOverviewVO.CategoryOverview(); + if (table == null) { + co.setCategories(List.of()); + return co; + } + co.setTotal(mapToCategorySummary(table.getTotal())); + if (table.getCategories() != null) { + co.setCategories(table.getCategories().stream() + .map(BiPlatformOverviewServiceImpl::mapToCategorySummary) + .collect(Collectors.toList())); + } else { + co.setCategories(List.of()); + } + return co; + } + + private static PlatformOverviewVO.CategorySummary mapToCategorySummary( + CompanyOverviewVO.CategorySummary c) { + PlatformOverviewVO.CategorySummary s = new PlatformOverviewVO.CategorySummary(); + if (c == null) { + return s; + } + s.setCategoryId(c.getCategoryId()); + s.setCategoryName(c.getCategoryName()); + s.setSalesAmount(c.getSalesAmount()); + s.setDealAmount(c.getDealAmount()); + s.setSalesOrderCount(c.getSalesOrderCount()); + s.setDealOrderCount(c.getDealOrderCount()); + s.setDealQuantitySum(c.getDealQuantitySum()); + s.setSalesQuantitySum(c.getSalesQuantitySum()); + s.setSalesAverageOrderValue(c.getSalesAverageOrderValue()); + s.setDealAverageOrderValue(c.getDealAverageOrderValue()); + s.setProductCost(c.getProductCost()); + s.setShippingCost(c.getShippingCost()); + s.setOtherCost(c.getOtherCost()); + s.setOrderCost(c.getOrderCost()); + s.setRefundAmount(c.getRefundAmount()); + s.setTotalPromotionFee(c.getTotalPromotionFee()); + s.setBrushFee(c.getBrushFee()); + s.setFeeRatio(c.getFeeRatio()); + s.setTotalProfitBeforeTax(c.getTotalProfitBeforeTax()); + s.setSalesTaxAmount(c.getSalesTaxAmount()); + s.setProfitAfterTax(c.getProfitAfterTax()); + s.setRoi(c.getRoi()); + return s; + } + + private static void fillProductSalesTop10(PlatformOverviewVO vo) { + PlatformOverviewVO.ProductOverview po = vo.getProductOverview(); + if (po == null || po.getProducts() == null || po.getProducts().isEmpty()) { + vo.setProductSalesTop10(Collections.emptyList()); + return; + } + vo.setProductSalesTop10(po.getProducts().stream() + .sorted(Comparator.comparing( + (PlatformOverviewVO.ProductSummary p) -> + p.getSalesOrderCount() != null ? p.getSalesOrderCount() : 0, + Comparator.reverseOrder())) + .limit(10) + .map(p -> { + PlatformOverviewVO.ProductSalesRankItem item = + new PlatformOverviewVO.ProductSalesRankItem(); + item.setProductId(p.getProductId()); + item.setProductName(p.getProductName()); + item.setProductCode(p.getProductCode()); + item.setOrderCount(p.getSalesOrderCount()); + item.setSalesAmount(p.getSalesAmount()); + return item; + }) + .collect(Collectors.toList())); + } + + private record PeriodBundle(BiFinanceKpiAssembler.Totals totals, + List dailyRows, + CompanyOverviewVO.WorkbenchTableBundle tables) { + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/shopoverview/model/vo/ShopOverviewStatisticsVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/shopoverview/model/vo/ShopOverviewStatisticsVO.java index ac8924a7..4fba2494 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/shopoverview/model/vo/ShopOverviewStatisticsVO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/shopoverview/model/vo/ShopOverviewStatisticsVO.java @@ -2,125 +2,62 @@ package top.xyquan.ecomdmbbackend.modules.bi.shopoverview.model.vo; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; +import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchCostSliceVO; +import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchKpiItemVO; +import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchTrendPointVO; import java.math.BigDecimal; import java.time.LocalDate; import java.util.List; /** - * 单店铺概览统计VO + * 单店铺概览:经营 KPI/趋势与工作台同口径,并附商品/品类明细。 */ @Data public class ShopOverviewStatisticsVO { - /** - * 店铺ID - */ private Long shopId; - /** - * 店铺名称 - */ private String shopName; - /** - * 店铺总销售额 - */ + private String platformCode; + + private List kpis; + + private List dealTrend; + + /** 店内商品净销售额占比 */ + private List productSalesShare; + + private String momCompareDateStart; + private String momCompareDateEnd; + private String yoyCompareDateStart; + private String yoyCompareDateEnd; + private BigDecimal totalSalesAmount; - - /** - * 较上月同期增长百分比 - */ private BigDecimal monthOverMonthGrowth; - - /** - * 店铺总单量 - */ private Integer totalOrderCount; - - /** - * 总推广费支出 - */ private BigDecimal totalPromotionFee; - - /** - * 平均费比(推广费/销售额) - */ private BigDecimal averageFeeRatio; - - /** - * 店铺总净利(税后) - */ private BigDecimal totalNetProfitAfterTax; - - /** - * 扣除总税额 - */ private BigDecimal totalTaxAmount; - - /** - * 店铺总销量目标(目标订单数) - */ private Integer totalTargetOrderCount; - - /** - * 店铺总销售额目标 - */ private BigDecimal totalTargetAmount; - - /** - * 销量目标达成率 - */ private BigDecimal orderCountAchievementRate; - - /** - * 销售额目标达成率 - */ private BigDecimal salesAmountAchievementRate; - - /** - * 汇总ROI - */ private BigDecimal totalROI; - - /** - * 店铺汇总客单价(销售额÷单量,与前端概览一致) - */ private BigDecimal averageOrderValue; - - /** - * 退款状态订单实收合计 - */ private BigDecimal refundAmount; - - /** - * 店铺税前盈亏(扣「销售额×税率」前的经营结果,与 totalNetProfitAfterTax + totalTaxAmount 一致) - */ private BigDecimal totalProfitBeforeTax; - /** - * 各商品按单量排序的销量 Top10(与当前筛选时间范围一致) - */ private List productSalesTop10; - /** - * 销售额趋势分析 - */ + /** @deprecated 使用 dealTrend */ private TrendData salesAmountTrend; - - /** - * 单量趋势分析 - */ + /** @deprecated 使用 dealTrend */ private TrendData orderCountTrend; - /** - * 多商品数据横向汇总(含合计行) - */ private ProductOverview productOverview; - - /** - * 品类多维度数据汇总(含合计行) - */ private CategoryOverview categoryOverview; /** diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/shopoverview/service/impl/BiShopOverviewServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/shopoverview/service/impl/BiShopOverviewServiceImpl.java index bda98ee6..820d2fbf 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/shopoverview/service/impl/BiShopOverviewServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/shopoverview/service/impl/BiShopOverviewServiceImpl.java @@ -7,6 +7,9 @@ import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStat import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyShopDoc; import top.xyquan.ecomdmbbackend.modules.bi.orderstat.query.BiOrderStatQueryService; import top.xyquan.ecomdmbbackend.modules.bi.shopoverview.service.BiShopOverviewService; +import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchCostSliceVO; +import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchTrendPointVO; +import top.xyquan.ecomdmbbackend.modules.bi.workbench.support.BiFinanceKpiAssembler; import top.xyquan.ecomdmbbackend.modules.bi.workbench.support.BiWorkbenchFeeLoader; import top.xyquan.ecomdmbbackend.modules.bi.overview.model.agg.OverviewAggRows; import top.xyquan.ecomdmbbackend.modules.bi.shopoverview.model.dto.ShopOverviewQueryDTO; @@ -94,77 +97,162 @@ public class BiShopOverviewServiceImpl implements BiShopOverviewService { Map platformByShopId = Map.of(shop.getId(), shop.getPlatformCode() != null ? shop.getPlatformCode() : ""); + LocalDate[] mom = BiFinanceKpiAssembler.lastMonthSameSpan(startDate, endDate); + LocalDate[] yoy = BiFinanceKpiAssembler.yoySameSpan(startDate, endDate); + + PeriodBundle cur = loadPeriod(companyId, shops, shopIds, platformByShopId, startDate, endDate, taxRate); + PeriodBundle prev = loadPeriodTotalsOnly(companyId, shopIds, mom[0], mom[1], taxRate); + PeriodBundle yoyBundle = loadPeriodTotalsOnly(companyId, shopIds, yoy[0], yoy[1], taxRate); + + BiFinanceKpiAssembler.Totals curT = cur.totals(); + BiFinanceKpiAssembler.Totals prevT = prev.totals(); + BiFinanceKpiAssembler.Totals yoyT = yoyBundle.totals(); + + List dealTrend = + BiFinanceKpiAssembler.buildTrendFromDaily(cur.dailyRows(), startDate, endDate, curT); + + ShopOverviewStatisticsVO vo = new ShopOverviewStatisticsVO(); + vo.setShopId(shop.getId()); + vo.setShopName(shop.getName()); + vo.setPlatformCode(shop.getPlatformCode()); + vo.setKpis(BiFinanceKpiAssembler.buildKpis(curT, prevT, yoyT, startDate, endDate, taxRate)); + vo.setDealTrend(dealTrend); + vo.setMomCompareDateStart(mom[0].toString()); + vo.setMomCompareDateEnd(mom[1].toString()); + vo.setYoyCompareDateStart(yoy[0].toString()); + vo.setYoyCompareDateEnd(yoy[1].toString()); + + Map products = loadProducts(cur.tables().getProductTable()); + vo.setProductOverview(mapProductOverview(cur.tables().getProductTable(), products)); + vo.setCategoryOverview(mapCategoryOverview(cur.tables().getCategoryTable())); + vo.setProductSalesShare(buildProductSalesShare(vo.getProductOverview(), curT.totalSales())); + fillProductSalesTop10(vo); + fillLegacyFlatFields(vo, curT, prevT); + fillTargets(vo, companyId, shop.getId(), startDate, endDate, curT.totalSales(), curT.orderCount()); + fillLegacyTrends(vo, dealTrend); + return vo; + } + + private PeriodBundle loadPeriod(Long companyId, List shops, List shopIds, + Map platformByShopId, + LocalDate start, LocalDate end, BigDecimal taxRate) { List shopDocs = - orderStatQueryService.listShopDocs(companyId, shopIds, startDate, endDate); + orderStatQueryService.listShopDocs(companyId, shopIds, start, end); List productDocs = - orderStatQueryService.listProductDocs(companyId, shopIds, startDate, endDate); - BiWorkbenchFeeLoader.FeeBundle fees = feeLoader.load(companyId, shopIds, startDate, endDate); + orderStatQueryService.listProductDocs(companyId, shopIds, start, end); + BiWorkbenchFeeLoader.FeeBundle fees = feeLoader.load(companyId, shopIds, start, end); List orderRows = orderStatQueryService.toShopProductRows(productDocs, platformByShopId); CompanyOverviewVO.WorkbenchTableBundle tables = companyOverviewService.buildWorkbenchSummaryTablesFromAgg( taxRate, companyId, shops, orderRows, - fees.promotionRows(), fees.brushRows(), startDate, endDate); + fees.promotionRows(), fees.brushRows(), start, end); BiOrderStatQueryService.ShopPeriodMetrics m = orderStatQueryService.sumShopDocs(shopDocs); - BigDecimal promo = fees.promoTotal(); - BigDecimal brush = fees.brushTotal(); - BigDecimal orderCost = nz(m.productCost()).add(nz(m.freightCost())).add(nz(m.otherCost())); - BigDecimal gross = nz(m.salesAmount()).subtract(orderCost); - BigDecimal pbt = gross.subtract(promo).subtract(brush); - BigDecimal tax = salesTaxOnNet(m.salesAmount(), taxRate); - - ShopOverviewStatisticsVO vo = new ShopOverviewStatisticsVO(); - vo.setShopId(shop.getId()); - vo.setShopName(shop.getName()); - vo.setTotalSalesAmount(nz(m.salesAmount()).setScale(2, RoundingMode.HALF_UP)); - vo.setTotalOrderCount(m.salesOrderCount()); - vo.setRefundAmount(nz(m.refundAmount()).setScale(2, RoundingMode.HALF_UP)); - vo.setAverageOrderValue(m.salesOrderCount() > 0 - ? nz(m.salesAmount()).divide(BigDecimal.valueOf(m.salesOrderCount()), 2, RoundingMode.HALF_UP) - : BigDecimal.ZERO); - vo.setTotalPromotionFee(promo.setScale(2, RoundingMode.HALF_UP)); - vo.setAverageFeeRatio(nz(m.salesAmount()).compareTo(BigDecimal.ZERO) > 0 - ? promo.divide(nz(m.salesAmount()), 4, RoundingMode.HALF_UP) - : BigDecimal.ZERO); - vo.setTotalProfitBeforeTax(pbt.setScale(2, RoundingMode.HALF_UP)); - vo.setTotalTaxAmount(tax); - vo.setTotalNetProfitAfterTax(pbt.subtract(tax).setScale(2, RoundingMode.HALF_UP)); - vo.setTotalROI(roi(nz(m.salesAmount()), promo)); - vo.setMonthOverMonthGrowth(calcMomGrowth(companyId, shopIds, startDate, endDate, m.salesAmount())); - - fillTargets(vo, companyId, shop.getId(), startDate, endDate, m.salesAmount(), m.salesOrderCount()); - - Map daily = - orderStatQueryService.toDailyRows(shopDocs).stream() - .filter(d -> d.getStatDate() != null) - .collect(Collectors.toMap(OverviewAggRows.DailyRow::getStatDate, d -> d, (a, b) -> a)); - vo.setSalesAmountTrend(buildTrend(startDate, endDate, daily, true)); - vo.setOrderCountTrend(buildTrend(startDate, endDate, daily, false)); - - Map products = loadProducts(tables.getProductTable()); - vo.setProductOverview(mapProductOverview(tables.getProductTable(), products)); - vo.setCategoryOverview(mapCategoryOverview(tables.getCategoryTable())); - fillProductSalesTop10(vo); - - return vo; + BiFinanceKpiAssembler.Totals totals = BiFinanceKpiAssembler.buildTotals( + m.salesAmount(), m.refundAmount(), + m.productCost(), m.freightCost(), m.otherCost(), + fees.promoTotal(), fees.brushTotal(), taxRate, + m.salesOrderCount(), m.salesQuantitySum(), + m.dealAmount(), m.dealOrderCount(), m.dealQuantitySum()); + return new PeriodBundle(totals, orderStatQueryService.toDailyRows(shopDocs), tables); } - private BigDecimal calcMomGrowth(Long companyId, List shopIds, - LocalDate start, LocalDate end, BigDecimal curSales) { - LocalDate prevStart = start.minusMonths(1); - LocalDate prevEnd = end.minusMonths(1); - BiOrderStatQueryService.ShopPeriodMetrics prev = - orderStatQueryService.sumShopDocs( - orderStatQueryService.listShopDocs(companyId, shopIds, prevStart, prevEnd)); - BigDecimal last = nz(prev.salesAmount()); - if (last.compareTo(BigDecimal.ZERO) > 0) { - return nz(curSales).subtract(last) - .divide(last, 4, RoundingMode.HALF_UP) - .multiply(new BigDecimal("100")); + private PeriodBundle loadPeriodTotalsOnly(Long companyId, List shopIds, + LocalDate start, LocalDate end, BigDecimal taxRate) { + List shopDocs = + orderStatQueryService.listShopDocs(companyId, shopIds, start, end); + BiWorkbenchFeeLoader.FeeBundle fees = feeLoader.load(companyId, shopIds, start, end); + BiOrderStatQueryService.ShopPeriodMetrics m = orderStatQueryService.sumShopDocs(shopDocs); + BiFinanceKpiAssembler.Totals totals = BiFinanceKpiAssembler.buildTotals( + m.salesAmount(), m.refundAmount(), + m.productCost(), m.freightCost(), m.otherCost(), + fees.promoTotal(), fees.brushTotal(), taxRate, + m.salesOrderCount(), m.salesQuantitySum(), + m.dealAmount(), m.dealOrderCount(), m.dealQuantitySum()); + return new PeriodBundle(totals, List.of(), null); + } + + private void fillLegacyFlatFields(ShopOverviewStatisticsVO vo, + BiFinanceKpiAssembler.Totals cur, + BiFinanceKpiAssembler.Totals prev) { + vo.setTotalSalesAmount(BiFinanceKpiAssembler.yuan2(cur.totalSales())); + vo.setTotalOrderCount(cur.orderCount()); + vo.setRefundAmount(BiFinanceKpiAssembler.yuan2(cur.totalRefund())); + vo.setAverageOrderValue(BiFinanceKpiAssembler.yuan2(cur.averageOrderValue())); + vo.setTotalPromotionFee(BiFinanceKpiAssembler.yuan2(cur.promotion())); + vo.setAverageFeeRatio(cur.totalSales().compareTo(BigDecimal.ZERO) > 0 + ? cur.promotion().divide(cur.totalSales(), 4, RoundingMode.HALF_UP) + : BigDecimal.ZERO); + vo.setTotalProfitBeforeTax(BiFinanceKpiAssembler.yuan2( + cur.grossOrder().subtract(cur.promotion()).subtract(cur.brush()))); + vo.setTotalTaxAmount(BiFinanceKpiAssembler.yuan2(cur.tax())); + vo.setTotalNetProfitAfterTax(BiFinanceKpiAssembler.yuan2(cur.netProfit())); + vo.setTotalROI(cur.promotion().compareTo(BigDecimal.ZERO) > 0 + ? cur.totalSales().divide(cur.promotion(), 4, RoundingMode.HALF_UP) + : BigDecimal.ZERO); + vo.setMonthOverMonthGrowth(BiFinanceKpiAssembler.pctChange(cur.totalSales(), prev.totalSales())); + } + + private void fillLegacyTrends(ShopOverviewStatisticsVO vo, List dealTrend) { + ShopOverviewStatisticsVO.TrendData sales = new ShopOverviewStatisticsVO.TrendData(); + ShopOverviewStatisticsVO.TrendData orders = new ShopOverviewStatisticsVO.TrendData(); + List salesItems = new ArrayList<>(); + List orderItems = new ArrayList<>(); + BigDecimal salesTotal = BigDecimal.ZERO; + BigDecimal orderTotal = BigDecimal.ZERO; + if (dealTrend != null) { + for (WorkbenchTrendPointVO p : dealTrend) { + ShopOverviewStatisticsVO.TrendDataItem s = new ShopOverviewStatisticsVO.TrendDataItem(); + s.setDate(LocalDate.parse(p.getDate())); + s.setValue(BiFinanceKpiAssembler.nz(p.getSalesYuan())); + salesItems.add(s); + salesTotal = salesTotal.add(s.getValue()); + + ShopOverviewStatisticsVO.TrendDataItem o = new ShopOverviewStatisticsVO.TrendDataItem(); + o.setDate(s.getDate()); + o.setValue(BigDecimal.valueOf(p.getSalesOrderCount() != null ? p.getSalesOrderCount() : 0)); + orderItems.add(o); + orderTotal = orderTotal.add(o.getValue()); + } } - return nz(curSales).compareTo(BigDecimal.ZERO) > 0 ? new BigDecimal("100") : BigDecimal.ZERO; + sales.setDailyDataList(salesItems); + sales.setTotal(salesTotal); + orders.setDailyDataList(orderItems); + orders.setTotal(orderTotal); + vo.setSalesAmountTrend(sales); + vo.setOrderCountTrend(orders); + } + + private List buildProductSalesShare( + ShopOverviewStatisticsVO.ProductOverview overview, BigDecimal salesTotal) { + if (overview == null || overview.getProducts() == null || overview.getProducts().isEmpty()) { + return List.of(); + } + BigDecimal base = BiFinanceKpiAssembler.nz(salesTotal); + return overview.getProducts().stream() + .filter(p -> BiFinanceKpiAssembler.nz(p.getSalesAmount()).compareTo(BigDecimal.ZERO) > 0) + .sorted(Comparator.comparing(ShopOverviewStatisticsVO.ProductSummary::getSalesAmount, + Comparator.nullsFirst(BigDecimal::compareTo)).reversed()) + .limit(12) + .map(p -> { + BigDecimal amt = BiFinanceKpiAssembler.nz(p.getSalesAmount()); + BigDecimal pct = base.compareTo(BigDecimal.ZERO) > 0 + ? amt.multiply(new BigDecimal("100")).divide(base, 2, RoundingMode.HALF_UP) + : BigDecimal.ZERO; + return WorkbenchCostSliceVO.builder() + .name(p.getProductName() != null ? p.getProductName() : "商品") + .value(BiFinanceKpiAssembler.yuan2(amt)) + .pct(pct) + .build(); + }) + .collect(Collectors.toList()); + } + + private record PeriodBundle(BiFinanceKpiAssembler.Totals totals, + List dailyRows, + CompanyOverviewVO.WorkbenchTableBundle tables) { } private void fillTargets(ShopOverviewStatisticsVO vo, Long companyId, Long shopId, @@ -202,29 +290,6 @@ public class BiShopOverviewServiceImpl implements BiShopOverviewService { return nz(actual).compareTo(BigDecimal.ZERO) > 0 ? new BigDecimal("100") : BigDecimal.ZERO; } - private ShopOverviewStatisticsVO.TrendData buildTrend( - LocalDate start, LocalDate end, - Map daily, - boolean sales) { - List items = new ArrayList<>(); - BigDecimal total = BigDecimal.ZERO; - for (LocalDate d = start; !d.isAfter(end); d = d.plusDays(1)) { - OverviewAggRows.DailyRow row = daily.get(d); - BigDecimal value = sales - ? (row != null ? nz(row.getSalesAmount()) : BigDecimal.ZERO) - : BigDecimal.valueOf(row != null && row.getOrderCount() != null ? row.getOrderCount() : 0L); - ShopOverviewStatisticsVO.TrendDataItem item = new ShopOverviewStatisticsVO.TrendDataItem(); - item.setDate(d); - item.setValue(value); - items.add(item); - total = total.add(value); - } - ShopOverviewStatisticsVO.TrendData trend = new ShopOverviewStatisticsVO.TrendData(); - trend.setTotal(total); - trend.setDailyDataList(items); - return trend; - } - private Map loadProducts(CompanyOverviewVO.CategoryOverview productTable) { if (productTable == null || productTable.getCategories() == null) { return Map.of(); diff --git a/ecom-dmb-backend/src/main/resources/sql/init/sys_seed.sql b/ecom-dmb-backend/src/main/resources/sql/init/sys_seed.sql index 345e09dc..6d3333eb 100644 --- a/ecom-dmb-backend/src/main/resources/sql/init/sys_seed.sql +++ b/ecom-dmb-backend/src/main/resources/sql/init/sys_seed.sql @@ -539,6 +539,14 @@ INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status SELECT 3721, (SELECT id FROM `sys_permission` WHERE `code` = 'bi:shop' LIMIT 1), 'bi:shop:overview', '店铺概览', 'api', 1, '', 1 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3721 OR `code` = 'bi:shop:overview'); +INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`) +SELECT 3725, (SELECT id FROM `sys_permission` WHERE `code` = 'bi' LIMIT 1), 'bi:platform', '平台分析', 'module', 1, '', 25 +FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3725 OR `code` = 'bi:platform'); + +INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`) +SELECT 3726, (SELECT id FROM `sys_permission` WHERE `code` = 'bi:platform' LIMIT 1), 'bi:platform:overview', '平台概览', 'api', 1, '', 1 +FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3726 OR `code` = 'bi:platform:overview'); + INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`) SELECT 3730, (SELECT id FROM `sys_permission` WHERE `code` = 'bi' LIMIT 1), 'bi:product', '商品分析', 'module', 1, '', 30 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3730 OR `code` = 'bi:product'); @@ -787,6 +795,10 @@ INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `name`, `route_name`, `title SELECT 43, (SELECT id FROM `sys_menu` WHERE `id` = 6 OR `name` = '电商页面' LIMIT 1), 0, '商品概览', 'ProductOverview', '商品概览', '/ec/product/overview/:id', '/ec/product/overview/index', '', 'lets-icons:chart', 'embedded', 0, 1, 1, 2 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 43 OR `name` = '商品概览'); +INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `name`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`) +SELECT 53, (SELECT id FROM `sys_menu` WHERE `id` = 6 OR `name` = '电商页面' LIMIT 1), 0, '平台概览', 'PlatformOverview', '平台概览', '/ec/platform/overview/:code', '/ec/platform/overview/index', '', 'lucide:layers', 'embedded', 0, 1, 1, 4 +FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 53 OR `name` = '平台概览'); + INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `name`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`) SELECT 44, (SELECT id FROM `sys_menu` WHERE `id` = 14006 OR `name` = '经营商品' LIMIT 1), 0, '商品类目', 'CategoryConfig', '商品类目', '/ec/product/category', '/ec/product/category/index', '', 'gg:list', 'menu', 1, 1, 1, 2 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 44 OR `name` = '商品类目'); diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/apis.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/apis.ts new file mode 100644 index 00000000..486856dc --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/apis.ts @@ -0,0 +1,13 @@ +import type { PlatformOverviewDTO, PlatformOverviewVO } from './types'; + +import { requestClient } from '#/api/request'; + +/** 获取平台概览统计数据 */ +export async function getPlatformOverviewApi( + params: PlatformOverviewDTO.Query, +) { + return requestClient.post( + '/bi/platform/overview', + params, + ); +} diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/index.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/index.ts new file mode 100644 index 00000000..daf76d51 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/index.ts @@ -0,0 +1,2 @@ +export * from './apis'; +export * from './types'; diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/types/index.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/types/index.ts new file mode 100644 index 00000000..bb6731a0 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/types/index.ts @@ -0,0 +1,2 @@ +export type { PlatformOverviewDTO } from './types.dto'; +export type { PlatformOverviewVO } from './types.vo'; diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/types/types.dto.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/types/types.dto.ts new file mode 100644 index 00000000..142a354b --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/types/types.dto.ts @@ -0,0 +1,7 @@ +export namespace PlatformOverviewDTO { + export interface Query { + platformCode: string; + dateRange: string[]; + taxRate?: number; + } +} diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/types/types.vo.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/types/types.vo.ts new file mode 100644 index 00000000..aa256b50 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ec/platform/overview/types/types.vo.ts @@ -0,0 +1,147 @@ +/** 平台概览 VO(与后端 PlatformOverviewVO 对齐) */ +export namespace PlatformOverviewVO { + /** 与工作台经营 KPI 同形 */ + export interface KpiItem { + label: string; + value: number; + unit: string; + changePct?: number; + up?: boolean; + yoyChangePct?: number | null; + yoyUp?: boolean | null; + sub?: string; + amountYuan?: number | null; + preferWanDisplay?: boolean | null; + } + + export interface TrendPoint { + date: string; + dealYuan?: number; + dealOrderCount?: number; + salesYuan?: number; + salesOrderCount?: number; + profitYuan?: number; + netProfitYuan?: number; + refundYuan?: number; + } + + export interface PieSlice { + name: string; + value?: number; + pct?: number; + } + + export interface ProductSalesRankItem { + productId?: number; + productName?: string; + productCode?: string; + orderCount?: number; + salesAmount?: number; + } + + export interface ProductSummary { + productId: number; + productName: string; + productCode?: string; + salesAmount: number; + dealAmount?: number; + salesOrderCount?: number; + dealOrderCount?: number; + salesAverageOrderValue?: number; + dealAverageOrderValue?: number; + productCost?: number; + shippingCost?: number; + otherCost?: number; + orderCost?: number; + refundAmount?: number; + totalPromotionFee?: number; + brushFee?: number; + feeRatio?: number; + totalProfitBeforeTax?: number; + salesTaxAmount?: number; + profitAfterTax?: number; + roi?: number; + } + + export interface CategorySummary { + categoryId: number; + categoryName: string; + salesAmount: number; + dealAmount?: number; + salesOrderCount?: number; + dealOrderCount?: number; + salesAverageOrderValue?: number; + dealAverageOrderValue?: number; + productCost?: number; + shippingCost?: number; + otherCost?: number; + orderCost?: number; + refundAmount?: number; + totalPromotionFee?: number; + brushFee?: number; + feeRatio?: number; + totalProfitBeforeTax?: number; + salesTaxAmount?: number; + profitAfterTax?: number; + roi?: number; + } + + export interface ProductOverview { + total: ProductSummary; + products: ProductSummary[]; + } + + export interface CategoryOverview { + total: CategorySummary; + categories: CategorySummary[]; + } + + /** @deprecated */ + export interface TrendDataItem { + date: string; + value: number; + } + + /** @deprecated */ + export interface TrendData { + total: number; + dailyDataList: TrendDataItem[]; + } + + export interface Overview { + platformCode: string; + platformName: string; + + kpis?: KpiItem[]; + dealTrend?: TrendPoint[]; + productSalesShare?: PieSlice[]; + momCompareDateStart?: string | null; + momCompareDateEnd?: string | null; + yoyCompareDateStart?: string | null; + yoyCompareDateEnd?: string | null; + + totalSalesAmount?: number; + monthOverMonthGrowth?: number; + totalOrderCount?: number; + totalPromotionFee?: number; + averageFeeRatio?: number; + totalNetProfitAfterTax?: number; + totalTaxAmount?: number; + totalTargetOrderCount?: number; + totalTargetAmount?: number; + orderCountAchievementRate?: number; + salesAmountAchievementRate?: number; + totalROI?: number; + averageOrderValue?: number; + refundAmount?: number; + totalProfitBeforeTax?: number; + + productSalesTop10?: ProductSalesRankItem[]; + /** @deprecated */ + salesAmountTrend?: TrendData; + /** @deprecated */ + orderCountTrend?: TrendData; + productOverview?: ProductOverview; + categoryOverview?: CategoryOverview; + } +} diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ec/shop/types/types.vo.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ec/shop/types/types.vo.ts index 0a996d35..e17e8d47 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/ec/shop/types/types.vo.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ec/shop/types/types.vo.ts @@ -119,13 +119,57 @@ export namespace ShopVO { averageOrderValue: number; } + /** 与工作台经营 KPI 同形 */ + export interface KpiItem { + label: string; + value: number; + unit: string; + changePct?: number; + up?: boolean; + yoyChangePct?: number | null; + yoyUp?: boolean | null; + sub?: string; + amountYuan?: number | null; + preferWanDisplay?: boolean | null; + } + + export interface TrendPoint { + date: string; + dealYuan?: number; + dealOrderCount?: number; + salesYuan?: number; + salesOrderCount?: number; + profitYuan?: number; + netProfitYuan?: number; + refundYuan?: number; + } + + export interface PieSlice { + name: string; + value?: number; + pct?: number; + } + /** 店铺概览统计信息 */ export interface OverviewStatistics { /** 店铺ID */ shopId?: number; /** 店铺名称 */ shopName: string; - /** 店铺总销售额 */ + /** 平台代码 */ + platformCode?: string; + + /** 经营 KPI(与工作台同口径) */ + kpis?: KpiItem[]; + dealTrend?: TrendPoint[]; + /** 店内商品净销售额占比 */ + productSalesShare?: PieSlice[]; + momCompareDateStart?: string | null; + momCompareDateEnd?: string | null; + yoyCompareDateStart?: string | null; + yoyCompareDateEnd?: string | null; + + /** 店铺总销售额(兼容旧扁平字段) */ totalSalesAmount: number; /** 较上月同期增长百分比 */ monthOverMonthGrowth?: number; @@ -157,9 +201,9 @@ export namespace ShopVO { totalProfitBeforeTax?: number; /** 各商品按单量排序的销量 Top10 */ productSalesTop10?: ProductSalesRankItem[]; - /** 销售额趋势分析 */ + /** @deprecated 使用 dealTrend */ salesAmountTrend?: TrendData; - /** 单量趋势分析 */ + /** @deprecated 使用 dealTrend */ orderCountTrend?: TrendData; /** 多商品数据横向汇总(含合计行) */ productOverview?: ProductOverview; 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 90bb6c62..67088d33 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 @@ -687,6 +687,23 @@ function handleProductNavigate(productId: number) { }); } +function handleShopNavigate(shopId: number) { + if (!shopId || shopId <= 0) return; + router.push({ + path: `/ec/shop/overview/${shopId}`, + query: buildOverviewRouteQuery(dateRange.value), + }); +} + +function handlePlatformNavigate(platformCode: string) { + const code = String(platformCode ?? '').trim(); + if (!code) return; + router.push({ + path: `/ec/platform/overview/${encodeURIComponent(code)}`, + query: buildOverviewRouteQuery(dateRange.value), + }); +} + const financeTabRef = ref | null>( null, ); @@ -1017,6 +1034,8 @@ onUnmounted(() => { :multi-analysis="EMPTY_MULTI" :summary-tables="summaryTablesPanel" @navigate-product="handleProductNavigate" + @navigate-shop="handleShopNavigate" + @navigate-platform="handlePlatformNavigate" /> diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/finance/components/OverviewTables.vue b/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/finance/components/OverviewTables.vue index 1dd64ef2..d72471bf 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/finance/components/OverviewTables.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/finance/components/OverviewTables.vue @@ -31,6 +31,8 @@ const props = withDefaults( ); const emit = defineEmits<{ (e: 'navigate-product', productId: number): void; + (e: 'navigate-shop', shopId: number): void; + (e: 'navigate-platform', platformCode: string): void; }>(); const activeMode = ref<'category' | 'platform' | 'product' | 'shop'>('shop'); @@ -193,6 +195,7 @@ async function handleProductExport() { @update:selected-export-shop-ids="selectedExportShopIds = $event" @toggle-shop-export-mode="shopExportMode = $event" @export="handleShopExport" + @navigate-shop="(id: number) => emit('navigate-shop', id)" /> (), { @@ -208,7 +213,9 @@ const sortedData = computed(() => { if ((e.target as HTMLInputElement).checked) { emit( 'update:selectedExportPlatformCodes', - platformData.map((p) => p.platformCode) || [], + platformData + .map((p) => p.platformCode) + .filter((c): c is string => Boolean(c)), ); } else { emit('update:selectedExportPlatformCodes', []); @@ -453,13 +460,18 @@ const sortedData = computed(() => { { - + + {{ p.platformName }} + + + {{ p.platformName }} diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/finance/components/ShopSummaryTable.vue b/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/finance/components/ShopSummaryTable.vue index 974b973c..db868677 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/finance/components/ShopSummaryTable.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/finance/components/ShopSummaryTable.vue @@ -3,6 +3,8 @@ import type { CompanyOverviewVO } from '#/api/bi/overview'; import { computed } from 'vue'; +import { createIconifyIcon } from '@vben/icons'; + import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio'; import { formatIntCell, formatNumberCell } from '#/utils/overview-table-cells'; @@ -21,6 +23,8 @@ import OverviewTableColumnSettings from './OverviewTableColumnSettings.vue'; defineOptions({ name: 'WorkbenchShopSummaryTable' }); +const JumpIcon = createIconifyIcon('tdesign:jump'); + interface Props { shopSummary?: CompanyOverviewVO.ShopOverview; taxRate: number; @@ -36,6 +40,7 @@ interface Emits { (e: 'update:selectedExportShopIds', ids: number[]): void; (e: 'toggleShopExportMode', enabled: boolean): void; (e: 'export'): void; + (e: 'navigate-shop', shopId: number): void; } const props = withDefaults(defineProps(), { @@ -371,6 +376,15 @@ const cellRoi = (v: number | null | undefined) => :class="shopExportMode ? 'border-l-0' : ''" > + {{ shop.shopName }} + + + {{ shop.shopName }} diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/finance/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/finance/index.vue index 070a6896..f6848910 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/finance/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/finance/index.vue @@ -26,6 +26,8 @@ defineOptions({ name: 'WorkbenchFinanceTab' }); const emit = defineEmits<{ (e: 'navigate-product', productId: number): void; + (e: 'navigate-shop', shopId: number): void; + (e: 'navigate-platform', platformCode: string): void; }>(); const props = defineProps<{ @@ -167,6 +169,8 @@ defineExpose({ redraw }); :category-summary="categoryOverview" :product-summary="productOverview" @navigate-product="(id: number) => emit('navigate-product', id)" + @navigate-shop="(id: number) => emit('navigate-shop', id)" + @navigate-platform="(code: string) => emit('navigate-platform', code)" /> diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/components/PlatformHeroBanner.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/components/PlatformHeroBanner.vue new file mode 100644 index 00000000..917b2a73 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/components/PlatformHeroBanner.vue @@ -0,0 +1,175 @@ + + + diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/components/PlatformProductRankStrip.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/components/PlatformProductRankStrip.vue new file mode 100644 index 00000000..c07fc2e2 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/components/PlatformProductRankStrip.vue @@ -0,0 +1,116 @@ + + + diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/components/TimeRangeBar.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/components/TimeRangeBar.vue new file mode 100644 index 00000000..3f220d15 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/components/TimeRangeBar.vue @@ -0,0 +1,385 @@ + + + + + + diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/constants/platform-ui.ts b/ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/constants/platform-ui.ts new file mode 100644 index 00000000..890db79d --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/constants/platform-ui.ts @@ -0,0 +1,16 @@ +/** 平台概览:紫罗兰强调,与商品青绿、店铺琥珀、工作台蓝灰区分 */ + +export const PLATFORM_PAGE_BG = + 'bg-[#f7f5fb] dark:bg-[hsl(265deg_18%_8%)]'; + +export const PLATFORM_PANEL_SHELL = + 'overflow-hidden rounded-[16px] border border-violet-200/70 bg-white shadow-[0_1px_2px_rgba(109,40,217,0.04),0_10px_28px_rgba(109,40,217,0.05)] dark:border-violet-900/40 dark:bg-[hsl(265deg_14%_11%)] dark:shadow-none'; + +export const PLATFORM_HERO_SHELL = + 'relative overflow-hidden rounded-[18px] border border-violet-200/80 bg-gradient-to-br from-violet-50 via-white to-fuchsia-50/70 p-5 shadow-[0_1px_2px_rgba(109,40,217,0.05),0_12px_32px_rgba(109,40,217,0.07)] md:p-6 dark:border-violet-900/45 dark:from-violet-950/40 dark:via-[hsl(265deg_14%_11%)] dark:to-fuchsia-950/25 dark:shadow-none'; + +export const PLATFORM_SPOT_CARD = + 'min-w-0 rounded-[14px] border border-violet-100/90 bg-white/80 px-3.5 py-3 backdrop-blur-sm dark:border-violet-900/35 dark:bg-[hsl(265deg_14%_12%/80%)]'; + +export const PLATFORM_SECTION_LABEL = + 'inline-flex items-center gap-1.5 rounded-full border border-violet-200/80 bg-violet-50/80 px-2.5 py-0.5 text-[11px] font-semibold tracking-wide text-violet-800 dark:border-violet-800/50 dark:bg-violet-950/40 dark:text-violet-300'; diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/index.vue new file mode 100644 index 00000000..b76eb823 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ec/platform/overview/index.vue @@ -0,0 +1,502 @@ + + + + + diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/overview/components/ShopHeroBanner.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/overview/components/ShopHeroBanner.vue new file mode 100644 index 00000000..2e6a440d --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/overview/components/ShopHeroBanner.vue @@ -0,0 +1,172 @@ + + + diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/overview/components/ShopProductRankStrip.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/overview/components/ShopProductRankStrip.vue new file mode 100644 index 00000000..9fece4fa --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/overview/components/ShopProductRankStrip.vue @@ -0,0 +1,119 @@ + + + diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/overview/constants/shop-ui.ts b/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/overview/constants/shop-ui.ts new file mode 100644 index 00000000..b1c8477a --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/overview/constants/shop-ui.ts @@ -0,0 +1,16 @@ +/** 店铺概览:琥珀/橙强调,与商品青绿、工作台蓝灰区分 */ + +export const SHOP_PAGE_BG = + 'bg-[#fbf7f2] dark:bg-[hsl(28deg_18%_8%)]'; + +export const SHOP_PANEL_SHELL = + 'overflow-hidden rounded-[16px] border border-amber-200/70 bg-white shadow-[0_1px_2px_rgba(180,83,9,0.04),0_10px_28px_rgba(180,83,9,0.05)] dark:border-amber-900/40 dark:bg-[hsl(28deg_14%_11%)] dark:shadow-none'; + +export const SHOP_HERO_SHELL = + 'relative overflow-hidden rounded-[18px] border border-amber-200/80 bg-gradient-to-br from-amber-50 via-white to-orange-50/80 p-5 shadow-[0_1px_2px_rgba(180,83,9,0.05),0_12px_32px_rgba(180,83,9,0.07)] md:p-6 dark:border-amber-900/45 dark:from-amber-950/40 dark:via-[hsl(28deg_14%_11%)] dark:to-orange-950/30 dark:shadow-none'; + +export const SHOP_SPOT_CARD = + 'min-w-0 rounded-[14px] border border-amber-100/90 bg-white/80 px-3.5 py-3 backdrop-blur-sm dark:border-amber-900/35 dark:bg-[hsl(28deg_14%_12%/80%)]'; + +export const SHOP_SECTION_LABEL = + 'inline-flex items-center gap-1.5 rounded-full border border-amber-200/80 bg-amber-50/80 px-2.5 py-0.5 text-[11px] font-semibold tracking-wide text-amber-800 dark:border-amber-800/50 dark:bg-amber-950/40 dark:text-amber-300'; diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/overview/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/overview/index.vue index 38dad3f2..18505976 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/overview/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/overview/index.vue @@ -1,9 +1,12 @@