From f122176369e3bd947b8083cd8efe34240625d756 Mon Sep 17 00:00:00 2001 From: ah-max150 Date: Sat, 5 Sep 2026 14:49:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=93=81=E7=B1=BB?= =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E6=A6=82=E8=A7=88=E9=A1=B5=E5=B9=B6=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=B7=A5=E4=BD=9C=E5=8F=B0=E4=B8=8B=E9=92=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0906c__bi_category_overview_permission.sql | 8 + .../V20260906d__category_overview_menu.sql | 4 + .../BiCategoryOverviewController.java | 32 ++ .../model/dto/CategoryOverviewQueryDTO.java | 37 ++ .../model/vo/CategoryOverviewVO.java | 117 ++++ .../service/BiCategoryOverviewService.java | 12 + .../impl/BiCategoryOverviewServiceImpl.java | 526 ++++++++++++++++++ .../src/main/resources/sql/init/sys_seed.sql | 12 + .../src/api/ec/category/overview/apis.ts | 13 + .../src/api/ec/category/overview/index.ts | 2 + .../api/ec/category/overview/types/index.ts | 2 + .../ec/category/overview/types/types.dto.ts | 7 + .../ec/category/overview/types/types.vo.ts | 118 ++++ .../web-antd/src/views/bi/workbench/index.vue | 9 + .../components/CategorySummaryTable.vue | 12 + .../finance/components/OverviewTables.vue | 5 +- .../views/bi/workbench/tabs/finance/index.vue | 2 + .../components/CategoryHeroBanner.vue | 175 ++++++ .../components/CategoryProductRankStrip.vue | 116 ++++ .../overview/components/TimeRangeBar.vue | 389 +++++++++++++ .../overview/constants/category-ui.ts | 16 + .../src/views/ec/category/overview/index.vue | 482 ++++++++++++++++ 22 files changed, 2095 insertions(+), 1 deletion(-) create mode 100644 ecom-dmb-backend/sql/migration/V20260906c__bi_category_overview_permission.sql create mode 100644 ecom-dmb-backend/sql/migration/V20260906d__category_overview_menu.sql create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/controller/BiCategoryOverviewController.java create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/model/dto/CategoryOverviewQueryDTO.java create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/model/vo/CategoryOverviewVO.java create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/service/BiCategoryOverviewService.java create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/service/impl/BiCategoryOverviewServiceImpl.java create mode 100644 ecom-dmb-frontend/apps/web-antd/src/api/ec/category/overview/apis.ts create mode 100644 ecom-dmb-frontend/apps/web-antd/src/api/ec/category/overview/index.ts create mode 100644 ecom-dmb-frontend/apps/web-antd/src/api/ec/category/overview/types/index.ts create mode 100644 ecom-dmb-frontend/apps/web-antd/src/api/ec/category/overview/types/types.dto.ts create mode 100644 ecom-dmb-frontend/apps/web-antd/src/api/ec/category/overview/types/types.vo.ts create mode 100644 ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/components/CategoryHeroBanner.vue create mode 100644 ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/components/CategoryProductRankStrip.vue create mode 100644 ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/components/TimeRangeBar.vue create mode 100644 ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/constants/category-ui.ts create mode 100644 ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/index.vue diff --git a/ecom-dmb-backend/sql/migration/V20260906c__bi_category_overview_permission.sql b/ecom-dmb-backend/sql/migration/V20260906c__bi_category_overview_permission.sql new file mode 100644 index 00000000..88be2b57 --- /dev/null +++ b/ecom-dmb-backend/sql/migration/V20260906c__bi_category_overview_permission.sql @@ -0,0 +1,8 @@ +-- 品类分析模块权限:bi:category / bi:category:overview +INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`) +SELECT 3727, (SELECT id FROM `sys_permission` WHERE `code` = 'bi' LIMIT 1), 'bi:category', '品类分析', 'module', 1, '', 26 +FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3727 OR `code` = 'bi:category'); + +INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`) +SELECT 3728, (SELECT id FROM `sys_permission` WHERE `code` = 'bi:category' LIMIT 1), 'bi:category:overview', '品类概览', 'api', 1, '', 1 +FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3728 OR `code` = 'bi:category:overview'); diff --git a/ecom-dmb-backend/sql/migration/V20260906d__category_overview_menu.sql b/ecom-dmb-backend/sql/migration/V20260906d__category_overview_menu.sql new file mode 100644 index 00000000..6d5737e6 --- /dev/null +++ b/ecom-dmb-backend/sql/migration/V20260906d__category_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 54, (SELECT id FROM `sys_menu` WHERE `id` = 6 OR `name` = '电商页面' LIMIT 1), 0, '品类概览', 'CategoryOverview', '品类概览', '/ec/category/overview/:id', '/ec/category/overview/index', '', 'lucide:tags', 'embedded', 0, 1, 1, 5 +FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 54 OR `name` = '品类概览' OR `route_name` = 'CategoryOverview'); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/controller/BiCategoryOverviewController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/controller/BiCategoryOverviewController.java new file mode 100644 index 00000000..5513d673 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/controller/BiCategoryOverviewController.java @@ -0,0 +1,32 @@ +package top.xyquan.ecomdmbbackend.modules.bi.categoryoverview.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.categoryoverview.model.dto.CategoryOverviewQueryDTO; +import top.xyquan.ecomdmbbackend.modules.bi.categoryoverview.model.vo.CategoryOverviewVO; +import top.xyquan.ecomdmbbackend.modules.bi.categoryoverview.service.BiCategoryOverviewService; + +/** + * 品类概览 API:公司下指定品类的经营汇总。 + */ +@RestController +@RequestMapping("/api/bi/category") +public class BiCategoryOverviewController { + + private final BiCategoryOverviewService biCategoryOverviewService; + + public BiCategoryOverviewController(BiCategoryOverviewService biCategoryOverviewService) { + this.biCategoryOverviewService = biCategoryOverviewService; + } + + @PostMapping("/overview") + @RequirePermission(value = "bi:category:overview", description = "查询品类概览", allowSuper = true) + public ApiResponse overview(@Valid @RequestBody CategoryOverviewQueryDTO queryDTO) { + return ApiResponse.success("获取品类概览成功", biCategoryOverviewService.getCategoryOverview(queryDTO)); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/model/dto/CategoryOverviewQueryDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/model/dto/CategoryOverviewQueryDTO.java new file mode 100644 index 00000000..8c1e09de --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/model/dto/CategoryOverviewQueryDTO.java @@ -0,0 +1,37 @@ +package top.xyquan.ecomdmbbackend.modules.bi.categoryoverview.model.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import jakarta.validation.constraints.NotNull; +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 CategoryOverviewQueryDTO { + + /** 品类 ID */ + @NotNull(message = "品类ID不能为空") + private Long categoryId; + + /** 开始日期(与 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/categoryoverview/model/vo/CategoryOverviewVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/model/vo/CategoryOverviewVO.java new file mode 100644 index 00000000..bb745a35 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/model/vo/CategoryOverviewVO.java @@ -0,0 +1,117 @@ +package top.xyquan.ecomdmbbackend.modules.bi.categoryoverview.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 CategoryOverviewVO { + + private Long categoryId; + + private String categoryName; + + /** 与工作台经营概览同结构的 KPI 列表 */ + private List kpis; + + /** 成交/净销售/利润日趋势 */ + private List dealTrend; + + /** 品类内各商品净销售额占比(饼图) */ + 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; + + @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 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 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/categoryoverview/service/BiCategoryOverviewService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/service/BiCategoryOverviewService.java new file mode 100644 index 00000000..6804034a --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/service/BiCategoryOverviewService.java @@ -0,0 +1,12 @@ +package top.xyquan.ecomdmbbackend.modules.bi.categoryoverview.service; + +import top.xyquan.ecomdmbbackend.modules.bi.categoryoverview.model.dto.CategoryOverviewQueryDTO; +import top.xyquan.ecomdmbbackend.modules.bi.categoryoverview.model.vo.CategoryOverviewVO; + +/** + * BI 品类概览:按品类汇总;订单读 Mongo 日汇聚,推广/刷单/目标读 MySQL。 + */ +public interface BiCategoryOverviewService { + + CategoryOverviewVO getCategoryOverview(CategoryOverviewQueryDTO queryDTO); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/service/impl/BiCategoryOverviewServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/service/impl/BiCategoryOverviewServiceImpl.java new file mode 100644 index 00000000..f0654ddb --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/service/impl/BiCategoryOverviewServiceImpl.java @@ -0,0 +1,526 @@ +package top.xyquan.ecomdmbbackend.modules.bi.categoryoverview.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.categoryoverview.model.dto.CategoryOverviewQueryDTO; +import top.xyquan.ecomdmbbackend.modules.bi.categoryoverview.model.vo.CategoryOverviewVO; +import top.xyquan.ecomdmbbackend.modules.bi.categoryoverview.service.BiCategoryOverviewService; +import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyProductDoc; +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.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.product.category.model.po.CategoryPO; +import top.xyquan.ecomdmbbackend.modules.ec.product.category.service.CategoryService; +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.HashSet; +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 BiCategoryOverviewServiceImpl implements BiCategoryOverviewService { + + 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 CategoryService categoryService; + 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 BiCategoryOverviewServiceImpl(CurrentUserContext currentUserContext, + CategoryService categoryService, + ShopService shopService, + BiOrderStatQueryService orderStatQueryService, + BiWorkbenchFeeLoader feeLoader, + CompanyOverviewService companyOverviewService, + ShopMonthlyTargetMapper shopMonthlyTargetMapper, + ProductMapper productMapper) { + this.currentUserContext = currentUserContext; + this.categoryService = categoryService; + this.shopService = shopService; + this.orderStatQueryService = orderStatQueryService; + this.feeLoader = feeLoader; + this.companyOverviewService = companyOverviewService; + this.shopMonthlyTargetMapper = shopMonthlyTargetMapper; + this.productMapper = productMapper; + } + + @Override + public CategoryOverviewVO getCategoryOverview(CategoryOverviewQueryDTO 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("开始日期不能晚于结束日期"); + } + + CategoryPO category = categoryService.getById(queryDTO.getCategoryId()); + if (category == null || !Objects.equals(category.getCompanyId(), companyId)) { + throw new BusinessException("品类不存在"); + } + + CategoryOverviewVO vo = new CategoryOverviewVO(); + vo.setCategoryId(category.getId()); + vo.setCategoryName(category.getName()); + + 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()); + + PeriodBundle cur = loadPeriod(companyId, category.getId(), start, end, taxRate); + PeriodBundle prev = loadPeriod(companyId, category.getId(), mom[0], mom[1], taxRate); + PeriodBundle yoyBundle = loadPeriod(companyId, category.getId(), 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.productIds()); + vo.setProductOverview(mapProductOverview(cur.productTable(), products, category.getId())); + vo.setProductSalesShare(buildProductSalesShare(vo.getProductOverview(), curT.totalSales())); + fillProductSalesTop10(vo); + fillLegacyFlatFields(vo, curT, prevT); + fillTargets(vo, companyId, cur.shopIds(), start, end, curT.totalSales(), curT.orderCount()); + fillLegacyTrends(vo, dealTrend); + return vo; + } + + /** + * 加载单区间:涉及店铺全量建表以正确分摊费用,再取本品类行;趋势仅本品类商品日汇聚。 + */ + private PeriodBundle loadPeriod(Long companyId, Long categoryId, + LocalDate start, LocalDate end, BigDecimal taxRate) { + Set categoryProductIds = loadProductIdsInCategory(companyId, categoryId); + + List allShops = shopService.list(new LambdaQueryWrapper() + .eq(ShopPO::getCompanyId, companyId)); + if (allShops.isEmpty()) { + return new PeriodBundle(List.of(), Set.of(), BiFinanceKpiAssembler.Totals.empty(), + List.of(), null); + } + + List allShopIds = allShops.stream().map(ShopPO::getId).filter(Objects::nonNull).toList(); + Map platformByShopId = allShops.stream() + .filter(s -> s.getId() != null) + .collect(Collectors.toMap(ShopPO::getId, + s -> s.getPlatformCode() != null ? s.getPlatformCode() : "", + (a, b) -> a)); + + List allProductDocs = + orderStatQueryService.listProductDocs(companyId, allShopIds, start, end); + + List categoryDocs = allProductDocs.stream() + .filter(d -> d.getProductId() != null && categoryProductIds.contains(d.getProductId())) + .toList(); + + List dailyRows = + orderStatQueryService.toDailyRowsFromProductDocs(categoryDocs); + + List shopIds = categoryDocs.stream() + .map(BiOrderStatDailyProductDoc::getShopId) + .filter(Objects::nonNull) + .distinct() + .collect(Collectors.toList()); + + if (shopIds.isEmpty() || categoryProductIds.isEmpty()) { + return new PeriodBundle(List.of(), categoryProductIds, BiFinanceKpiAssembler.Totals.empty(), + dailyRows, null); + } + + List shops = allShops.stream() + .filter(s -> s.getId() != null && shopIds.contains(s.getId())) + .collect(Collectors.toList()); + + List shopProductDocs = allProductDocs.stream() + .filter(d -> d.getShopId() != null && shopIds.contains(d.getShopId())) + .toList(); + + BiWorkbenchFeeLoader.FeeBundle fees = feeLoader.load(companyId, shopIds, start, end); + List orderRows = + orderStatQueryService.toShopProductRows(shopProductDocs, platformByShopId); + CompanyOverviewVO.WorkbenchTableBundle tables = + companyOverviewService.buildWorkbenchSummaryTablesFromAgg( + taxRate, companyId, shops, orderRows, + fees.promotionRows(), fees.brushRows(), start, end); + + CompanyOverviewVO.CategorySummary categoryRow = + findCategoryRow(tables.getCategoryTable(), categoryId); + BiFinanceKpiAssembler.Totals totals = categoryRow != null + ? BiFinanceKpiAssembler.fromCategorySummary(categoryRow, taxRate) + : BiFinanceKpiAssembler.Totals.empty(); + + return new PeriodBundle(shopIds, categoryProductIds, totals, dailyRows, tables.getProductTable()); + } + + private Set loadProductIdsInCategory(Long companyId, Long categoryId) { + List products = productMapper.selectList(new LambdaQueryWrapper() + .eq(ProductPO::getCompanyId, companyId) + .eq(ProductPO::getCategoryId, categoryId) + .select(ProductPO::getId)); + Set ids = new HashSet<>(); + for (ProductPO p : products) { + if (p != null && p.getId() != null) { + ids.add(p.getId()); + } + } + return ids; + } + + private static LocalDate resolveStart(CategoryOverviewQueryDTO 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(CategoryOverviewQueryDTO 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 fillLegacyFlatFields(CategoryOverviewVO 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(CategoryOverviewVO vo, List dealTrend) { + CategoryOverviewVO.TrendData sales = new CategoryOverviewVO.TrendData(); + CategoryOverviewVO.TrendData orders = new CategoryOverviewVO.TrendData(); + List salesItems = new ArrayList<>(); + List orderItems = new ArrayList<>(); + BigDecimal salesTotal = BigDecimal.ZERO; + BigDecimal orderTotal = BigDecimal.ZERO; + if (dealTrend != null) { + for (WorkbenchTrendPointVO p : dealTrend) { + CategoryOverviewVO.TrendDataItem s = new CategoryOverviewVO.TrendDataItem(); + s.setDate(LocalDate.parse(p.getDate())); + s.setValue(BiFinanceKpiAssembler.nz(p.getSalesYuan())); + salesItems.add(s); + salesTotal = salesTotal.add(s.getValue()); + + CategoryOverviewVO.TrendDataItem o = new CategoryOverviewVO.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(CategoryOverviewVO vo, Long companyId, List shopIds, + LocalDate startDate, LocalDate endDate, + BigDecimal sales, int orderCount) { + if (shopIds == null || shopIds.isEmpty()) { + return; + } + 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() ? 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(CategoryOverviewVO.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(CategoryOverviewVO.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(Set productIds) { + if (productIds == null || productIds.isEmpty()) { + return Map.of(); + } + Map map = new HashMap<>(); + for (ProductPO p : productMapper.selectByIds(productIds)) { + if (p != null && p.getId() != null) { + map.put(p.getId(), p); + } + } + return map; + } + + private static CompanyOverviewVO.CategorySummary findCategoryRow( + CompanyOverviewVO.CategoryOverview table, Long categoryId) { + if (table == null || table.getCategories() == null || categoryId == null) { + return null; + } + return table.getCategories().stream() + .filter(c -> Objects.equals(c.getCategoryId(), categoryId)) + .findFirst() + .orElse(null); + } + + private static CategoryOverviewVO.ProductOverview mapProductOverview( + CompanyOverviewVO.CategoryOverview table, Map products, Long categoryId) { + CategoryOverviewVO.ProductOverview po = new CategoryOverviewVO.ProductOverview(); + if (table == null || table.getCategories() == null) { + po.setProducts(List.of()); + return po; + } + List list = table.getCategories().stream() + .filter(c -> c.getCategoryId() != null && c.getCategoryId() > 0) + .filter(c -> { + ProductPO p = products.get(c.getCategoryId()); + return p != null && Objects.equals(p.getCategoryId(), categoryId); + }) + .map(c -> mapToProductSummary(c, c.getCategoryId(), products)) + .sorted(Comparator.comparing(CategoryOverviewVO.ProductSummary::getSalesAmount, + Comparator.nullsFirst(BigDecimal::compareTo)).reversed()) + .collect(Collectors.toList()); + po.setProducts(list); + po.setTotal(sumProductSummaries(list)); + return po; + } + + private static CategoryOverviewVO.ProductSummary sumProductSummaries( + List list) { + CategoryOverviewVO.ProductSummary t = new CategoryOverviewVO.ProductSummary(); + t.setProductName("合计"); + if (list == null || list.isEmpty()) { + return t; + } + BigDecimal sales = BigDecimal.ZERO; + BigDecimal deal = BigDecimal.ZERO; + BigDecimal refund = BigDecimal.ZERO; + BigDecimal productCost = BigDecimal.ZERO; + BigDecimal shipping = BigDecimal.ZERO; + BigDecimal other = BigDecimal.ZERO; + BigDecimal orderCost = BigDecimal.ZERO; + BigDecimal promo = BigDecimal.ZERO; + BigDecimal brush = BigDecimal.ZERO; + BigDecimal profitBefore = BigDecimal.ZERO; + BigDecimal tax = BigDecimal.ZERO; + BigDecimal profitAfter = BigDecimal.ZERO; + int salesOrders = 0; + int dealOrders = 0; + int salesQty = 0; + int dealQty = 0; + for (CategoryOverviewVO.ProductSummary p : list) { + sales = sales.add(BiFinanceKpiAssembler.nz(p.getSalesAmount())); + deal = deal.add(BiFinanceKpiAssembler.nz(p.getDealAmount())); + refund = refund.add(BiFinanceKpiAssembler.nz(p.getRefundAmount())); + productCost = productCost.add(BiFinanceKpiAssembler.nz(p.getProductCost())); + shipping = shipping.add(BiFinanceKpiAssembler.nz(p.getShippingCost())); + other = other.add(BiFinanceKpiAssembler.nz(p.getOtherCost())); + orderCost = orderCost.add(BiFinanceKpiAssembler.nz(p.getOrderCost())); + promo = promo.add(BiFinanceKpiAssembler.nz(p.getTotalPromotionFee())); + brush = brush.add(BiFinanceKpiAssembler.nz(p.getBrushFee())); + profitBefore = profitBefore.add(BiFinanceKpiAssembler.nz(p.getTotalProfitBeforeTax())); + tax = tax.add(BiFinanceKpiAssembler.nz(p.getSalesTaxAmount())); + profitAfter = profitAfter.add(BiFinanceKpiAssembler.nz(p.getProfitAfterTax())); + salesOrders += p.getSalesOrderCount() != null ? p.getSalesOrderCount() : 0; + dealOrders += p.getDealOrderCount() != null ? p.getDealOrderCount() : 0; + salesQty += p.getSalesQuantitySum() != null ? p.getSalesQuantitySum() : 0; + dealQty += p.getDealQuantitySum() != null ? p.getDealQuantitySum() : 0; + } + t.setSalesAmount(sales); + t.setDealAmount(deal); + t.setRefundAmount(refund); + t.setProductCost(productCost); + t.setShippingCost(shipping); + t.setOtherCost(other); + t.setOrderCost(orderCost); + t.setTotalPromotionFee(promo); + t.setBrushFee(brush); + t.setTotalProfitBeforeTax(profitBefore); + t.setSalesTaxAmount(tax); + t.setProfitAfterTax(profitAfter); + t.setSalesOrderCount(salesOrders); + t.setDealOrderCount(dealOrders); + t.setSalesQuantitySum(salesQty); + t.setDealQuantitySum(dealQty); + t.setSalesAverageOrderValue(salesOrders > 0 + ? sales.divide(BigDecimal.valueOf(salesOrders), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO); + t.setDealAverageOrderValue(dealOrders > 0 + ? deal.divide(BigDecimal.valueOf(dealOrders), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO); + t.setFeeRatio(sales.compareTo(BigDecimal.ZERO) > 0 + ? promo.divide(sales, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO); + t.setRoi(promo.compareTo(BigDecimal.ZERO) > 0 + ? sales.divide(promo, 2, RoundingMode.HALF_UP) : BigDecimal.ZERO); + return t; + } + + private static CategoryOverviewVO.ProductSummary mapToProductSummary( + CompanyOverviewVO.CategorySummary c, Long productId, Map products) { + CategoryOverviewVO.ProductSummary p = new CategoryOverviewVO.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 void fillProductSalesTop10(CategoryOverviewVO vo) { + CategoryOverviewVO.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( + (CategoryOverviewVO.ProductSummary p) -> + p.getSalesOrderCount() != null ? p.getSalesOrderCount() : 0, + Comparator.reverseOrder())) + .limit(10) + .map(p -> { + CategoryOverviewVO.ProductSalesRankItem item = + new CategoryOverviewVO.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(List shopIds, + Set productIds, + BiFinanceKpiAssembler.Totals totals, + List dailyRows, + CompanyOverviewVO.CategoryOverview productTable) { + } +} 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 6d3333eb..be3b0d5f 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 @@ -547,6 +547,14 @@ INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status 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 3727, (SELECT id FROM `sys_permission` WHERE `code` = 'bi' LIMIT 1), 'bi:category', '品类分析', 'module', 1, '', 26 +FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3727 OR `code` = 'bi:category'); + +INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`) +SELECT 3728, (SELECT id FROM `sys_permission` WHERE `code` = 'bi:category' LIMIT 1), 'bi:category:overview', '品类概览', 'api', 1, '', 1 +FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3728 OR `code` = 'bi:category: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'); @@ -799,6 +807,10 @@ INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `name`, `route_name`, `title 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 54, (SELECT id FROM `sys_menu` WHERE `id` = 6 OR `name` = '电商页面' LIMIT 1), 0, '品类概览', 'CategoryOverview', '品类概览', '/ec/category/overview/:id', '/ec/category/overview/index', '', 'lucide:tags', 'embedded', 0, 1, 1, 5 +FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 54 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/category/overview/apis.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ec/category/overview/apis.ts new file mode 100644 index 00000000..8295b730 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ec/category/overview/apis.ts @@ -0,0 +1,13 @@ +import type { CategoryOverviewDTO, CategoryOverviewVO } from './types'; + +import { requestClient } from '#/api/request'; + +/** 获取品类概览统计数据 */ +export async function getCategoryOverviewApi( + params: CategoryOverviewDTO.Query, +) { + return requestClient.post( + '/bi/category/overview', + params, + ); +} diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ec/category/overview/index.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ec/category/overview/index.ts new file mode 100644 index 00000000..daf76d51 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ec/category/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/category/overview/types/index.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ec/category/overview/types/index.ts new file mode 100644 index 00000000..e81e9043 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ec/category/overview/types/index.ts @@ -0,0 +1,2 @@ +export type { CategoryOverviewDTO } from './types.dto'; +export type { CategoryOverviewVO } from './types.vo'; diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ec/category/overview/types/types.dto.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ec/category/overview/types/types.dto.ts new file mode 100644 index 00000000..876337ab --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ec/category/overview/types/types.dto.ts @@ -0,0 +1,7 @@ +export namespace CategoryOverviewDTO { + export interface Query { + categoryId: number; + dateRange: string[]; + taxRate?: number; + } +} diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ec/category/overview/types/types.vo.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ec/category/overview/types/types.vo.ts new file mode 100644 index 00000000..faaca6e7 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ec/category/overview/types/types.vo.ts @@ -0,0 +1,118 @@ +/** 品类概览 VO(与后端 CategoryOverviewVO 对齐) */ +export namespace CategoryOverviewVO { + /** 与工作台经营 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 ProductOverview { + total: ProductSummary; + products: ProductSummary[]; + } + + /** @deprecated */ + export interface TrendDataItem { + date: string; + value: number; + } + + /** @deprecated */ + export interface TrendData { + total: number; + dailyDataList: TrendDataItem[]; + } + + export interface Overview { + categoryId: number; + categoryName: 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; + } +} 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 67088d33..148f1ebb 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 @@ -704,6 +704,14 @@ function handlePlatformNavigate(platformCode: string) { }); } +function handleCategoryNavigate(categoryId: number) { + if (!categoryId || categoryId <= 0) return; + router.push({ + path: `/ec/category/overview/${categoryId}`, + query: buildOverviewRouteQuery(dateRange.value), + }); +} + const financeTabRef = ref | null>( null, ); @@ -1036,6 +1044,7 @@ onUnmounted(() => { @navigate-product="handleProductNavigate" @navigate-shop="handleShopNavigate" @navigate-platform="handlePlatformNavigate" + @navigate-category="handleCategoryNavigate" /> diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/finance/components/CategorySummaryTable.vue b/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/finance/components/CategorySummaryTable.vue index c1f25fa4..a3bc6cbc 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/finance/components/CategorySummaryTable.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/bi/workbench/tabs/finance/components/CategorySummaryTable.vue @@ -35,6 +35,8 @@ interface Props { firstColumnLabel?: string; /** 为 true 时首列名称可点击跳转商品概览(categoryId 即商品 ID) */ productNavigate?: boolean; + /** 为 true 时首列名称可点击跳转品类概览 */ + categoryNavigate?: boolean; columnPrefsKey?: 'category' | 'product'; } @@ -43,6 +45,7 @@ interface Emits { (e: 'toggleCategoryExportMode', enabled: boolean): void; (e: 'export'): void; (e: 'navigate-product', productId: number): void; + (e: 'navigate-category', categoryId: number): void; } const props = withDefaults(defineProps(), { @@ -52,6 +55,7 @@ const props = withDefaults(defineProps(), { headingSubtitle: '包含:规模、成本及最终损益所有维度', firstColumnLabel: '品类', productNavigate: false, + categoryNavigate: false, columnPrefsKey: 'category', }); @@ -345,6 +349,14 @@ const cellRoi = (v: number | null | undefined) => {{ cat.categoryName }} + + {{ cat.categoryName }} + + (); const activeMode = ref<'category' | 'platform' | 'product' | 'shop'>('shop'); @@ -215,7 +216,8 @@ async function handleProductExport() { (); const props = defineProps<{ @@ -171,6 +172,7 @@ defineExpose({ redraw }); @navigate-product="(id: number) => emit('navigate-product', id)" @navigate-shop="(id: number) => emit('navigate-shop', id)" @navigate-platform="(code: string) => emit('navigate-platform', code)" + @navigate-category="(id: number) => emit('navigate-category', id)" /> diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/components/CategoryHeroBanner.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/components/CategoryHeroBanner.vue new file mode 100644 index 00000000..638ca495 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/components/CategoryHeroBanner.vue @@ -0,0 +1,175 @@ + + + diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/components/CategoryProductRankStrip.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/components/CategoryProductRankStrip.vue new file mode 100644 index 00000000..b25b397a --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/components/CategoryProductRankStrip.vue @@ -0,0 +1,116 @@ + + + diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/components/TimeRangeBar.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/components/TimeRangeBar.vue new file mode 100644 index 00000000..db5a5cc3 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/components/TimeRangeBar.vue @@ -0,0 +1,389 @@ + + + + + + diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/constants/category-ui.ts b/ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/constants/category-ui.ts new file mode 100644 index 00000000..b9c1bd3f --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/constants/category-ui.ts @@ -0,0 +1,16 @@ +/** 品类概览:玫红/珊瑚强调,与商品青绿、店铺琥珀、平台紫罗兰、工作台蓝灰区分 */ + +export const CATEGORY_PAGE_BG = + 'bg-[#fbf5f6] dark:bg-[hsl(350deg_18%_8%)]'; + +export const CATEGORY_PANEL_SHELL = + 'overflow-hidden rounded-[16px] border border-rose-200/70 bg-white shadow-[0_1px_2px_rgba(225,29,72,0.04),0_10px_28px_rgba(225,29,72,0.05)] dark:border-rose-900/40 dark:bg-[hsl(350deg_14%_11%)] dark:shadow-none'; + +export const CATEGORY_HERO_SHELL = + 'relative overflow-hidden rounded-[18px] border border-rose-200/80 bg-gradient-to-br from-rose-50 via-white to-orange-50/70 p-5 shadow-[0_1px_2px_rgba(225,29,72,0.05),0_12px_32px_rgba(225,29,72,0.07)] md:p-6 dark:border-rose-900/45 dark:from-rose-950/40 dark:via-[hsl(350deg_14%_11%)] dark:to-orange-950/25 dark:shadow-none'; + +export const CATEGORY_SPOT_CARD = + 'min-w-0 rounded-[14px] border border-rose-100/90 bg-white/80 px-3.5 py-3 backdrop-blur-sm dark:border-rose-900/35 dark:bg-[hsl(350deg_14%_12%/80%)]'; + +export const CATEGORY_SECTION_LABEL = + 'inline-flex items-center gap-1.5 rounded-full border border-rose-200/80 bg-rose-50/80 px-2.5 py-0.5 text-[11px] font-semibold tracking-wide text-rose-800 dark:border-rose-800/50 dark:bg-rose-950/40 dark:text-rose-300'; diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/index.vue new file mode 100644 index 00000000..25f526e0 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ec/category/overview/index.vue @@ -0,0 +1,482 @@ + + + + +