From f94d9b2db4156fc9709779c560660d321209c1bf Mon Sep 17 00:00:00 2001 From: ah-max150 Date: Mon, 7 Sep 2026 17:23:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A7=BB=E9=99=A4=20BI=20Overview=20?= =?UTF-8?q?=E6=97=A7=E8=B6=8B=E5=8A=BF=E5=AD=97=E6=AE=B5=EF=BC=8C=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E4=BD=BF=E7=94=A8=20dealTrend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecom-dmb-backend/docs/订单统计读模型方案.md | 4 +- .../model/vo/CategoryOverviewVO.java | 20 - .../impl/BiCategoryOverviewServiceImpl.java | 31 - .../overview/model/vo/CompanyOverviewVO.java | 31 - .../impl/CategoryExportExcelServiceImpl.java | 59 +- .../model/vo/PlatformOverviewVO.java | 20 - .../impl/BiPlatformOverviewServiceImpl.java | 32 - .../model/vo/ProductOverviewVO.java | 20 - .../impl/BiProductOverviewServiceImpl.java | 31 - .../model/vo/ShopOverviewStatisticsVO.java | 40 - .../service/impl/BiShopExportServiceImpl.java | 50 +- .../impl/BiShopOverviewServiceImpl.java | 47 - .../skuoverview/model/vo/SkuOverviewVO.java | 20 - .../impl/BiSkuOverviewServiceImpl.java | 32 - .../service/impl/ProductSpecServiceImpl.java | 7 +- .../src/api/bi/overview/types/types.vo.ts | 13 - .../ec/category/overview/types/types.vo.ts | 16 - .../ec/platform/overview/types/types.vo.ts | 16 - .../api/ec/product/overview/types/types.vo.ts | 16 - .../src/api/ec/shop/types/types.vo.ts | 20 - .../src/api/ec/sku/overview/types/types.vo.ts | 17 - .../goods/components/PddGoodsPublishModal.vue | 953 +++++++++++++----- .../overview/components/SalesTrendChart.vue | 176 ---- 23 files changed, 769 insertions(+), 902 deletions(-) delete mode 100644 ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/overview/components/SalesTrendChart.vue diff --git a/ecom-dmb-backend/docs/订单统计读模型方案.md b/ecom-dmb-backend/docs/订单统计读模型方案.md index 59c98c00..45193e51 100644 --- a/ecom-dmb-backend/docs/订单统计读模型方案.md +++ b/ecom-dmb-backend/docs/订单统计读模型方案.md @@ -302,7 +302,7 @@ CREATE TABLE ec_order_stat_daily_product ( - `specSummaries`:按规格行的销售额/成本/推广费分摊 - `specSalesTop10`:规格销量排行 -- `salesAmountTrend` / `orderCountTrend`:可按商品日表;规格明细走本表 +- 日趋势:现用 `dealTrend`(`WorkbenchTrendPointVO`);旧 `salesAmountTrend` / `orderCountTrend` 已弃用删除;规格明细走本表 ```sql CREATE TABLE ec_order_stat_daily_spec ( @@ -628,7 +628,7 @@ RefreshWorker 循环: | 单店 `selectList` ×2(当前+上月) | `sumShopMetrics(company, [shopId], range)` ×2 | | `calculateProductOverview(orders)` 逐单按 product 分组 | `sumProductMetricsByProduct` 过滤 `shop_id` | | `calculateCategoryOverview(orders)` | `sumProductMetricsByCategory` 过滤 `shop_id` | -| 销售额/订单量趋势 `buildTrendData(orders)` | `sumShopMetricsByDay` 单店 | +| 销售额/订单量趋势(现 `dealTrend`) | `sumShopMetricsByDay` 单店 | | `productSalesTop10` 逐单排序 | `sumProductMetricsByProduct` + ORDER BY sales LIMIT 10 | **不再加载** `List orders`;规格/商品名称仍批量查 `ec_product` / `ec_category` 主数据(行数 = SKU 数,非订单数)。 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 index bb745a35..e5f10d56 100644 --- 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 @@ -1,13 +1,11 @@ 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; /** @@ -53,11 +51,6 @@ public class CategoryOverviewVO { private List productSalesTop10; - /** @deprecated 使用 dealTrend */ - private TrendData salesAmountTrend; - /** @deprecated 使用 dealTrend */ - private TrendData orderCountTrend; - private ProductOverview productOverview; @Data @@ -101,17 +94,4 @@ public class CategoryOverviewVO { 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/impl/BiCategoryOverviewServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/categoryoverview/service/impl/BiCategoryOverviewServiceImpl.java index f0654ddb..fc0d5537 100644 --- 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 @@ -121,7 +121,6 @@ public class BiCategoryOverviewServiceImpl implements BiCategoryOverviewService fillProductSalesTop10(vo); fillLegacyFlatFields(vo, curT, prevT); fillTargets(vo, companyId, cur.shopIds(), start, end, curT.totalSales(), curT.orderCount()); - fillLegacyTrends(vo, dealTrend); return vo; } @@ -249,36 +248,6 @@ public class BiCategoryOverviewServiceImpl implements BiCategoryOverviewService 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) { diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/overview/model/vo/CompanyOverviewVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/overview/model/vo/CompanyOverviewVO.java index 7d319e3b..925fb739 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/overview/model/vo/CompanyOverviewVO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/overview/model/vo/CompanyOverviewVO.java @@ -1,10 +1,8 @@ package top.xyquan.ecomdmbbackend.modules.bi.overview.model.vo; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import java.math.BigDecimal; -import java.time.LocalDate; import java.util.List; /** @@ -58,16 +56,6 @@ public class CompanyOverviewVO { */ private List shopEfficiencyQuadrants; - /** - * 销售额趋势分析 - */ - private TrendData salesAmountTrend; - - /** - * 单量趋势分析 - */ - private TrendData orderCountTrend; - /** * 多店铺数据横向汇总(包含合计行和店铺列表) */ @@ -156,25 +144,6 @@ public class CompanyOverviewVO { */ private BigDecimal salesAmountAchievementRate; - /** - * 趋势数据 - */ - @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/overview/service/impl/CategoryExportExcelServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/overview/service/impl/CategoryExportExcelServiceImpl.java index 413c170d..2cd3dc1b 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/overview/service/impl/CategoryExportExcelServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/overview/service/impl/CategoryExportExcelServiceImpl.java @@ -11,6 +11,7 @@ import top.xyquan.ecomdmbbackend.modules.bi.shopoverview.service.BiShopOverviewS import top.xyquan.ecomdmbbackend.modules.bi.overview.model.dto.CategoryExportDTO; import top.xyquan.ecomdmbbackend.modules.bi.overview.model.vo.CompanyOverviewVO; import top.xyquan.ecomdmbbackend.modules.bi.overview.service.CategoryExportExcelService; +import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchTrendPointVO; import java.io.ByteArrayOutputStream; import java.math.BigDecimal; @@ -18,7 +19,7 @@ import java.math.RoundingMode; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.ArrayList; -import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -145,9 +146,7 @@ public class CategoryExportExcelServiceImpl implements CategoryExportExcelServic try (Workbook workbook = new XSSFWorkbook()) { Sheet sheet = workbook.createSheet("品类汇总"); writeCategoryMultidimensionalSheet(sheet, shopTitle, dateRangeLabel, rows, totalRow, taxRate, "品类名称"); - if (vo.getSalesAmountTrend() != null - && vo.getSalesAmountTrend().getDailyDataList() != null - && !vo.getSalesAmountTrend().getDailyDataList().isEmpty()) { + if (vo.getDealTrend() != null && !vo.getDealTrend().isEmpty()) { Sheet trendSheet = workbook.createSheet("销量趋势"); writeShopSalesTrendSheet(trendSheet, shopTitle, dateRangeLabel, vo); } @@ -160,7 +159,7 @@ public class CategoryExportExcelServiceImpl implements CategoryExportExcelServic } } - /** 与店铺概览销量趋势同源({@link ShopOverviewStatisticsVO} 日销售额、日单量)。 */ + /** 与店铺概览销量趋势同源:从 {@link ShopOverviewStatisticsVO#getDealTrend()} 取日销售额/单量。 */ private void writeShopSalesTrendSheet( Sheet sheet, String shopContextTitle, String dateRangeLabel, ShopOverviewStatisticsVO vo) { Workbook wb = sheet.getWorkbook(); @@ -181,32 +180,32 @@ public class CategoryExportExcelServiceImpl implements CategoryExportExcelServic cell.setCellStyle(headerStyle); } - List dailySales = vo.getSalesAmountTrend().getDailyDataList(); - List dailyOrders = vo.getOrderCountTrend() != null - ? vo.getOrderCountTrend().getDailyDataList() - : null; + List dealTrend = vo.getDealTrend(); + if (dealTrend == null || dealTrend.isEmpty()) { + sheet.setColumnWidth(0, 3200); + sheet.setColumnWidth(1, 3200); + sheet.setColumnWidth(2, 3200); + return; + } - Map salesMap = dailySales.stream() - .collect(Collectors.toMap( - ShopOverviewStatisticsVO.TrendDataItem::getDate, - ShopOverviewStatisticsVO.TrendDataItem::getValue, - (a, b) -> a)); - Map ordersMap = dailyOrders != null - ? dailyOrders.stream() - .collect(Collectors.toMap( - ShopOverviewStatisticsVO.TrendDataItem::getDate, - ShopOverviewStatisticsVO.TrendDataItem::getValue, - (a, b) -> a)) - : Collections.emptyMap(); - - LocalDate startDate = dailySales.stream() - .map(ShopOverviewStatisticsVO.TrendDataItem::getDate) - .min(LocalDate::compareTo) - .orElse(null); - LocalDate endDate = dailySales.stream() - .map(ShopOverviewStatisticsVO.TrendDataItem::getDate) - .max(LocalDate::compareTo) - .orElse(null); + Map salesMap = new HashMap<>(); + Map ordersMap = new HashMap<>(); + LocalDate startDate = null; + LocalDate endDate = null; + for (WorkbenchTrendPointVO p : dealTrend) { + if (p == null || p.getDate() == null || p.getDate().isBlank()) { + continue; + } + LocalDate d = LocalDate.parse(p.getDate()); + salesMap.put(d, p.getSalesYuan() != null ? p.getSalesYuan() : BigDecimal.ZERO); + ordersMap.put(d, BigDecimal.valueOf(p.getSalesOrderCount() != null ? p.getSalesOrderCount() : 0)); + if (startDate == null || d.isBefore(startDate)) { + startDate = d; + } + if (endDate == null || d.isAfter(endDate)) { + endDate = d; + } + } int rowIdx = 2; if (startDate != null && endDate != null) { 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 index cf5c6fd2..3a15c5a3 100644 --- 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 @@ -1,13 +1,11 @@ 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; /** @@ -53,11 +51,6 @@ public class PlatformOverviewVO { private List productSalesTop10; - /** @deprecated 使用 dealTrend;保留以免旧客户端空指针 */ - private TrendData salesAmountTrend; - /** @deprecated 使用 dealTrend */ - private TrendData orderCountTrend; - private ProductOverview productOverview; private CategoryOverview categoryOverview; @@ -135,17 +128,4 @@ public class PlatformOverviewVO { 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/impl/BiPlatformOverviewServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/platformoverview/service/impl/BiPlatformOverviewServiceImpl.java index 81417868..49190b7a 100644 --- 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 @@ -123,7 +123,6 @@ public class BiPlatformOverviewServiceImpl implements BiPlatformOverviewService fillProductSalesTop10(vo); fillLegacyFlatFields(vo, curT, prevT); fillTargets(vo, companyId, shopIds, start, end, curT.totalSales(), curT.orderCount()); - fillLegacyTrends(vo, dealTrend); return vo; } @@ -217,7 +216,6 @@ public class BiPlatformOverviewServiceImpl implements BiPlatformOverviewService co.setCategories(List.of()); vo.setCategoryOverview(co); fillLegacyFlatFields(vo, empty, empty); - fillLegacyTrends(vo, vo.getDealTrend()); } private void fillLegacyFlatFields(PlatformOverviewVO vo, @@ -241,36 +239,6 @@ public class BiPlatformOverviewServiceImpl implements BiPlatformOverviewService 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) { diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/productoverview/model/vo/ProductOverviewVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/productoverview/model/vo/ProductOverviewVO.java index 2fd15b7b..3279c618 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/productoverview/model/vo/ProductOverviewVO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/productoverview/model/vo/ProductOverviewVO.java @@ -1,13 +1,11 @@ package top.xyquan.ecomdmbbackend.modules.bi.productoverview.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; /** @@ -47,26 +45,8 @@ public class ProductOverviewVO { private List specSalesTop10; - /** @deprecated 使用 dealTrend;保留以免旧客户端空指针 */ - private TrendData salesAmountTrend; - /** @deprecated 使用 dealTrend */ - private TrendData orderCountTrend; - private SpecSummary specSummaries; - @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; - } - @Data public static class SpecSummary { private List list; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/productoverview/service/impl/BiProductOverviewServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/productoverview/service/impl/BiProductOverviewServiceImpl.java index 2ca3a106..46fc6973 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/productoverview/service/impl/BiProductOverviewServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/productoverview/service/impl/BiProductOverviewServiceImpl.java @@ -132,7 +132,6 @@ public class BiProductOverviewServiceImpl implements BiProductOverviewService { vo.setSpecSalesTop10(buildSpecTop10(specSummaries)); fillLegacyFlatFields(vo, curT, prevT); fillTargets(vo, companyId, cur.shopIds(), start, end, curT.totalSales(), curT.orderCount()); - fillLegacyTrends(vo, dealTrend); return vo; } @@ -204,36 +203,6 @@ public class BiProductOverviewServiceImpl implements BiProductOverviewService { vo.setMonthOverMonthGrowth(BiFinanceKpiAssembler.pctChange(cur.totalSales(), prev.totalSales())); } - private void fillLegacyTrends(ProductOverviewVO vo, List dealTrend) { - ProductOverviewVO.TrendData sales = new ProductOverviewVO.TrendData(); - ProductOverviewVO.TrendData orders = new ProductOverviewVO.TrendData(); - List salesItems = new ArrayList<>(); - List orderItems = new ArrayList<>(); - BigDecimal salesTotal = BigDecimal.ZERO; - BigDecimal orderTotal = BigDecimal.ZERO; - if (dealTrend != null) { - for (WorkbenchTrendPointVO p : dealTrend) { - ProductOverviewVO.TrendDataItem s = new ProductOverviewVO.TrendDataItem(); - s.setDate(LocalDate.parse(p.getDate())); - s.setValue(BiFinanceKpiAssembler.nz(p.getSalesYuan())); - salesItems.add(s); - salesTotal = salesTotal.add(s.getValue()); - - ProductOverviewVO.TrendDataItem o = new ProductOverviewVO.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(ProductOverviewVO vo, Long companyId, List shopIds, LocalDate start, LocalDate end, BigDecimal sales, int orderCount) { if (shopIds == null || shopIds.isEmpty()) { 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 4fba2494..5fd7f7ad 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 @@ -1,13 +1,11 @@ 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; /** @@ -52,11 +50,6 @@ public class ShopOverviewStatisticsVO { private List productSalesTop10; - /** @deprecated 使用 dealTrend */ - private TrendData salesAmountTrend; - /** @deprecated 使用 dealTrend */ - private TrendData orderCountTrend; - private ProductOverview productOverview; private CategoryOverview categoryOverview; @@ -207,38 +200,5 @@ public class ShopOverviewStatisticsVO { 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/shopoverview/service/impl/BiShopExportServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/shopoverview/service/impl/BiShopExportServiceImpl.java index 755ee5b9..e60d35db 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/shopoverview/service/impl/BiShopExportServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/shopoverview/service/impl/BiShopExportServiceImpl.java @@ -12,6 +12,7 @@ import top.xyquan.ecomdmbbackend.modules.bi.shopoverview.model.vo.ShopOverviewSt import top.xyquan.ecomdmbbackend.modules.bi.shopoverview.service.BiShopOverviewService; import top.xyquan.ecomdmbbackend.modules.bi.overview.service.CategoryExportExcelService; import top.xyquan.ecomdmbbackend.modules.bi.shopoverview.service.BiShopExportService; +import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchTrendPointVO; import java.io.ByteArrayOutputStream; import java.math.BigDecimal; @@ -19,9 +20,9 @@ import java.math.RoundingMode; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; @Service public class BiShopExportServiceImpl implements BiShopExportService { @@ -81,9 +82,8 @@ public class BiShopExportServiceImpl implements BiShopExportService { } if (("trend".equals(exportType) || "all".equals(exportType) || "summary".equals(exportType)) - && vo.getSalesAmountTrend() != null - && vo.getSalesAmountTrend().getDailyDataList() != null - && !vo.getSalesAmountTrend().getDailyDataList().isEmpty()) { + && vo.getDealTrend() != null + && !vo.getDealTrend().isEmpty()) { Sheet trendSheet = workbook.createSheet("销量趋势"); createTrendSheetFromVO(trendSheet, dateRangeLabel, vo); } @@ -194,6 +194,7 @@ public class BiShopExportServiceImpl implements BiShopExportService { setCell(row, 18, profitAfterTax.doubleValue(), style); } + /** 从 dealTrend 写日销售额/单量;date 为 String,需 LocalDate.parse。 */ private void createTrendSheetFromVO(Sheet sheet, String dateRangeLabel, ShopOverviewStatisticsVO vo) { CellStyle headerStyle = createHeaderStyle(sheet.getWorkbook()); CellStyle dataStyle = createDataStyle(sheet.getWorkbook()); @@ -212,23 +213,32 @@ public class BiShopExportServiceImpl implements BiShopExportService { cell.setCellStyle(headerStyle); } - List dailySales = vo.getSalesAmountTrend().getDailyDataList(); - List dailyOrders = vo.getOrderCountTrend() != null - ? vo.getOrderCountTrend().getDailyDataList() : null; + List dealTrend = vo.getDealTrend(); + if (dealTrend == null || dealTrend.isEmpty()) { + sheet.setColumnWidth(0, 3200); + sheet.setColumnWidth(1, 3200); + sheet.setColumnWidth(2, 3200); + return; + } - Map salesMap = dailySales.stream() - .collect(Collectors.toMap(ShopOverviewStatisticsVO.TrendDataItem::getDate, - ShopOverviewStatisticsVO.TrendDataItem::getValue, (a, b) -> a)); - Map ordersMap = dailyOrders != null - ? dailyOrders.stream().collect(Collectors.toMap( - ShopOverviewStatisticsVO.TrendDataItem::getDate, - ShopOverviewStatisticsVO.TrendDataItem::getValue, (a, b) -> a)) - : Collections.emptyMap(); - - LocalDate startDate = vo.getSalesAmountTrend().getDailyDataList().stream() - .map(ShopOverviewStatisticsVO.TrendDataItem::getDate).min(LocalDate::compareTo).orElse(null); - LocalDate endDate = vo.getSalesAmountTrend().getDailyDataList().stream() - .map(ShopOverviewStatisticsVO.TrendDataItem::getDate).max(LocalDate::compareTo).orElse(null); + Map salesMap = new HashMap<>(); + Map ordersMap = new HashMap<>(); + LocalDate startDate = null; + LocalDate endDate = null; + for (WorkbenchTrendPointVO p : dealTrend) { + if (p == null || p.getDate() == null || p.getDate().isBlank()) { + continue; + } + LocalDate d = LocalDate.parse(p.getDate()); + salesMap.put(d, p.getSalesYuan() != null ? p.getSalesYuan() : BigDecimal.ZERO); + ordersMap.put(d, BigDecimal.valueOf(p.getSalesOrderCount() != null ? p.getSalesOrderCount() : 0)); + if (startDate == null || d.isBefore(startDate)) { + startDate = d; + } + if (endDate == null || d.isAfter(endDate)) { + endDate = d; + } + } int rowIdx = 2; if (startDate != null && endDate != null) { 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 820d2fbf..43c1206c 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 @@ -129,7 +129,6 @@ public class BiShopOverviewServiceImpl implements BiShopOverviewService { fillProductSalesTop10(vo); fillLegacyFlatFields(vo, curT, prevT); fillTargets(vo, companyId, shop.getId(), startDate, endDate, curT.totalSales(), curT.orderCount()); - fillLegacyTrends(vo, dealTrend); return vo; } @@ -195,36 +194,6 @@ public class BiShopOverviewServiceImpl implements BiShopOverviewService { 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()); - } - } - 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()) { @@ -439,22 +408,6 @@ public class BiShopOverviewServiceImpl implements BiShopOverviewService { .collect(Collectors.toList())); } - /** 税额 = 净销售额 × 税率 */ - private static BigDecimal salesTaxOnNet(BigDecimal sales, BigDecimal taxRate) { - BigDecimal base = nz(sales); - if (base.compareTo(BigDecimal.ZERO) < 0) { - base = BigDecimal.ZERO; - } - return base.multiply(taxRate != null ? taxRate : DEFAULT_TAX_RATE).setScale(2, RoundingMode.HALF_UP); - } - - private static BigDecimal roi(BigDecimal netSales, BigDecimal promo) { - if (promo == null || promo.compareTo(BigDecimal.ZERO) <= 0) { - return BigDecimal.ZERO; - } - return nz(netSales).divide(promo, 2, RoundingMode.HALF_UP); - } - private static BigDecimal nz(BigDecimal v) { return v != null ? v : BigDecimal.ZERO; } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/skuoverview/model/vo/SkuOverviewVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/skuoverview/model/vo/SkuOverviewVO.java index 8d4a6bd6..18a3009d 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/skuoverview/model/vo/SkuOverviewVO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/skuoverview/model/vo/SkuOverviewVO.java @@ -1,12 +1,10 @@ package top.xyquan.ecomdmbbackend.modules.bi.skuoverview.model.vo; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; 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; /** @@ -44,22 +42,4 @@ public class SkuOverviewVO { private BigDecimal refundAmount; private BigDecimal averageOrderValue; private BigDecimal totalProfitBeforeTax; - - /** @deprecated 使用 dealTrend */ - private TrendData salesAmountTrend; - /** @deprecated 使用 dealTrend */ - private TrendData orderCountTrend; - - @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/skuoverview/service/impl/BiSkuOverviewServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/skuoverview/service/impl/BiSkuOverviewServiceImpl.java index 07bb2deb..f4b1c95e 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/skuoverview/service/impl/BiSkuOverviewServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/skuoverview/service/impl/BiSkuOverviewServiceImpl.java @@ -25,7 +25,6 @@ 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.List; import java.util.Map; import java.util.Objects; @@ -122,7 +121,6 @@ public class BiSkuOverviewServiceImpl implements BiSkuOverviewService { vo.setYoyCompareDateStart(yoy[0].toString()); vo.setYoyCompareDateEnd(yoy[1].toString()); fillLegacyFlatFields(vo, curT, prevT); - fillLegacyTrends(vo, dealTrend); return vo; } @@ -267,36 +265,6 @@ public class BiSkuOverviewServiceImpl implements BiSkuOverviewService { vo.setMonthOverMonthGrowth(BiFinanceKpiAssembler.pctChange(cur.totalSales(), prev.totalSales())); } - private void fillLegacyTrends(SkuOverviewVO vo, List dealTrend) { - SkuOverviewVO.TrendData sales = new SkuOverviewVO.TrendData(); - SkuOverviewVO.TrendData orders = new SkuOverviewVO.TrendData(); - List salesItems = new ArrayList<>(); - List orderItems = new ArrayList<>(); - BigDecimal salesTotal = BigDecimal.ZERO; - BigDecimal orderTotal = BigDecimal.ZERO; - if (dealTrend != null) { - for (WorkbenchTrendPointVO p : dealTrend) { - SkuOverviewVO.TrendDataItem s = new SkuOverviewVO.TrendDataItem(); - s.setDate(LocalDate.parse(p.getDate())); - s.setValue(BiFinanceKpiAssembler.nz(p.getSalesYuan())); - salesItems.add(s); - salesTotal = salesTotal.add(s.getValue()); - - SkuOverviewVO.TrendDataItem o = new SkuOverviewVO.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 record PeriodBundle(List shopIds, BiFinanceKpiAssembler.Totals totals, List dailyRows) { diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/product/spec/service/impl/ProductSpecServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/product/spec/service/impl/ProductSpecServiceImpl.java index 19e37029..f892d247 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/product/spec/service/impl/ProductSpecServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/product/spec/service/impl/ProductSpecServiceImpl.java @@ -83,7 +83,6 @@ public class ProductSpecServiceImpl implements ProductSpecService { @Transactional(rollbackFor = Exception.class) public List replaceSpecs(Long productId, ReplaceProductSpecsDTO dto) { ProductPO product = requireProduct(productId); - Long companyId = product.getCompanyId(); Long userId = currentUserContext.getCurrentUserId(); List items = dto.getSpecs() == null ? List.of() : dto.getSpecs(); @@ -368,7 +367,7 @@ public class ProductSpecServiceImpl implements ProductSpecService { if (valueIds.isEmpty()) { throw new BusinessException("请至少选择一个规格值"); } - List values = valueMapper.selectBatchIds(valueIds); + List values = valueMapper.selectByIds(valueIds); if (values.size() != valueIds.size()) { throw new BusinessException("存在无效的规格值"); } @@ -383,7 +382,7 @@ public class ProductSpecServiceImpl implements ProductSpecService { throw new BusinessException("同一规格维只能选择一个规格值"); } } - Map specById = specMapper.selectBatchIds(specIds).stream() + Map specById = specMapper.selectByIds(specIds).stream() .collect(Collectors.toMap(ProductSpecPO::getId, s -> s, (a, b) -> a)); return new ResolvedSpecValues(values, specById); } @@ -432,7 +431,7 @@ public class ProductSpecServiceImpl implements ProductSpecService { return Map.of(); } Set valueIds = rels.stream().map(ProductSkuSpecValuePO::getSpecValueId).collect(Collectors.toSet()); - Map valueMap = valueMapper.selectBatchIds(valueIds).stream() + Map valueMap = valueMapper.selectByIds(valueIds).stream() .collect(Collectors.toMap(ProductSpecValuePO::getId, v -> v, (a, b) -> a)); Map> result = new HashMap<>(); for (ProductSkuSpecValuePO rel : rels) { diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/bi/overview/types/types.vo.ts b/ecom-dmb-frontend/apps/web-antd/src/api/bi/overview/types/types.vo.ts index 0c35d049..5f4b8915 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/bi/overview/types/types.vo.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/bi/overview/types/types.vo.ts @@ -16,8 +16,6 @@ export namespace CompanyOverviewVO { totalTaxAmount?: number; shopSalesRatios?: ShopSalesRatio[]; shopEfficiencyQuadrants?: ShopEfficiencyQuadrant[]; - salesAmountTrend?: TrendData; - orderCountTrend?: TrendData; shopSummary?: ShopOverview; categorySummary?: CategoryOverview; platformSummary?: PlatformOverview; @@ -29,17 +27,6 @@ export namespace CompanyOverviewVO { salesAmountAchievementRate?: number; } - export interface TrendData { - total?: number; - dailyDataList?: TrendDataItem[]; - } - - export interface TrendDataItem { - /** yyyy-MM-dd */ - date?: string; - value?: number; - } - export interface ShopSalesRatio { shopId?: number; shopName?: string; 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 index faaca6e7..7928f8ad 100644 --- 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 @@ -68,18 +68,6 @@ export namespace CategoryOverviewVO { 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; @@ -109,10 +97,6 @@ export namespace CategoryOverviewVO { totalProfitBeforeTax?: number; productSalesTop10?: ProductSalesRankItem[]; - /** @deprecated */ - salesAmountTrend?: TrendData; - /** @deprecated */ - orderCountTrend?: TrendData; productOverview?: ProductOverview; } } 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 index aa256b50..df2d5af2 100644 --- 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 @@ -96,18 +96,6 @@ export namespace PlatformOverviewVO { 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; @@ -137,10 +125,6 @@ export namespace PlatformOverviewVO { 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/product/overview/types/types.vo.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ec/product/overview/types/types.vo.ts index 43044e58..eb2a0e0e 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/ec/product/overview/types/types.vo.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ec/product/overview/types/types.vo.ts @@ -30,18 +30,6 @@ export namespace ProductOverviewVO { pct?: number; } - /** @deprecated 旧趋势结构,优先用 dealTrend */ - export interface TrendDataItem { - date: string; - value: number; - } - - /** @deprecated */ - export interface TrendData { - total: number; - dailyDataList: TrendDataItem[]; - } - export interface SkuSalesRankItem { skuId?: number; skuName?: string; @@ -118,10 +106,6 @@ export namespace ProductOverviewVO { totalROI?: number; specSalesTop10?: SkuSalesRankItem[]; - /** @deprecated */ - salesAmountTrend?: TrendData; - /** @deprecated */ - orderCountTrend?: TrendData; specSummaries?: SkuSummary; } } 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 e17e8d47..e228c552 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 @@ -201,10 +201,6 @@ export namespace ShopVO { totalProfitBeforeTax?: number; /** 各商品按单量排序的销量 Top10 */ productSalesTop10?: ProductSalesRankItem[]; - /** @deprecated 使用 dealTrend */ - salesAmountTrend?: TrendData; - /** @deprecated 使用 dealTrend */ - orderCountTrend?: TrendData; /** 多商品数据横向汇总(含合计行) */ productOverview?: ProductOverview; /** 品类多维度数据汇总(含合计行) */ @@ -310,22 +306,6 @@ export namespace ShopVO { roi?: number; } - /** 趋势数据 */ - export interface TrendData { - /** 时间范围的总值 */ - total: number; - /** 每日数据列表 */ - dailyDataList: TrendDataItem[]; - } - - /** 趋势数据项 */ - export interface TrendDataItem { - /** 日期 */ - date: string; - /** 对应的值 */ - value: number; - } - /** 商品概览(含合计行和商品列表) */ export interface ProductOverview { /** 合计行 */ diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ec/sku/overview/types/types.vo.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ec/sku/overview/types/types.vo.ts index b34b6e3e..1c41229a 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/ec/sku/overview/types/types.vo.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ec/sku/overview/types/types.vo.ts @@ -24,18 +24,6 @@ export namespace SkuOverviewVO { refundYuan?: number; } - /** @deprecated */ - export interface TrendDataItem { - date: string; - value: number; - } - - /** @deprecated */ - export interface TrendData { - total: number; - dailyDataList: TrendDataItem[]; - } - export interface Overview { skuId: number; skuName?: string; @@ -61,10 +49,5 @@ export namespace SkuOverviewVO { refundAmount?: number; averageOrderValue?: number; totalProfitBeforeTax?: number; - - /** @deprecated */ - salesAmountTrend?: TrendData; - /** @deprecated */ - orderCountTrend?: TrendData; } } diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishModal.vue b/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishModal.vue index 5c68be1c..73e8fefe 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishModal.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishModal.vue @@ -10,7 +10,7 @@ import type { CascaderProps, UploadFile, UploadProps } from 'ant-design-vue'; import { computed, nextTick, onBeforeUnmount, reactive, ref, watch } from 'vue'; import { useVbenModal } from '@vben/common-ui'; -import { PlusOutlined, DeleteOutlined, MinusOutlined } from '@ant-design/icons-vue'; +import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue'; import { Alert, @@ -144,13 +144,14 @@ function handleClose() { modalApi.close(); } -const pickInternalSkuId = ref(undefined); const submitting = ref(false); let skuRowSeq = 1; let uploadUidSeq = 1; type SkuRow = { key: number; + /** 规格组合稳定键,用于重建时保留价格/编码等 */ + comboKey: string; internalSkuId?: number; productName?: string; skuName: string; @@ -159,11 +160,40 @@ type SkuRow = { multiPriceYuan?: number; quantity: number; weight: number; - /** picture-card 单图,悬停预览/删除 */ thumbFileList: UploadFile[]; saleValues: Record; }; +/** 类目可选父规格(下拉候选);用户手动添加进编辑区 */ +type SpecCatalogItem = { + catalogKey: string; + name: string; + parentSpecId: number; + refPid?: number; + templatePid?: number; + valueUnit?: string; + presetOptions: { + label: string; + value: string; + vid?: number; + specId?: number; + }[]; +}; + +/** 已添加的规格轴:默认仅「款式」一条,其余手动添加 */ +type SpecAxis = { + rowId: number; + catalogKey: string; + key: string; + name: string; + parentSpecId?: number; + refPid?: number; + templatePid?: number; + valueUnit?: string; + presetOptions: SpecCatalogItem['presetOptions']; + selectedValues: string[]; +}; + const form = reactive({ pddShopId: undefined as number | undefined, primaryProductId: undefined as number | undefined, @@ -191,9 +221,79 @@ const productOptions = ref<{ label: string; value: number; name: string }[]>( ); const skuOptions = ref([]); const skuRows = ref([]); +/** 类目下全部可选父规格 */ +const specCatalog = ref([]); +/** 用户已添加的规格轴(默认一条「款式」) */ +const specAxes = ref([]); +/** 各规格行「输入规格值」草稿 */ +const specValueDraftByRow = ref>({}); +let specAxisRowSeq = 1; /** 规格表容器:新增后滚到表体底部 */ const skuTableWrapRef = ref(null); +const canAddSpecAxis = computed(() => { + const maxAxes = Math.min(2, specCatalog.value.length); + return ( + specCatalog.value.length > 0 && specAxes.value.length < maxAxes + ); +}); + +/** 规格列行合并:前缀规格值相同则合并(笛卡尔积顺序下连续) */ +const skuSpecRowSpans = computed(() => { + const rows = skuRows.value; + const axes = specAxes.value; + const spansByAxisKey = new Map(); + for (const axis of axes) { + spansByAxisKey.set(axis.key, Array.from({ length: rows.length }, () => 1)); + } + if (rows.length === 0 || axes.length === 0) return spansByAxisKey; + + for (let axisIdx = 0; axisIdx < axes.length; axisIdx++) { + const prefixKeys = axes.slice(0, axisIdx + 1).map((a) => a.key); + const spans = spansByAxisKey.get(axes[axisIdx]!.key)!; + let i = 0; + while (i < rows.length) { + let j = i + 1; + while ( + j < rows.length && + prefixKeys.every( + (k) => rows[j]!.saleValues[k] === rows[i]!.saleValues[k], + ) + ) { + j++; + } + spans[i] = j - i; + for (let k = i + 1; k < j; k++) { + spans[k] = 0; + } + i = j; + } + } + return spansByAxisKey; +}); + +/** SKU 表列:每种规格单独一列,相同规格值合并单元格 */ +const skuTableColumns = computed(() => [ + ...specAxes.value.map((axis) => ({ + title: axis.name, + key: `spec_${axis.key}`, + width: 120, + customCell: (_record: SkuRow, rowIndex?: number) => ({ + rowSpan: skuSpecRowSpans.value.get(axis.key)?.[rowIndex ?? 0] ?? 1, + }), + })), + { title: '商家编码', key: 'code', width: 300 }, + { title: '单买价', key: 'price', width: 120 }, + { title: '团购价', key: 'multi', width: 120 }, + { title: '库存', key: 'qty', width: 100 }, + { title: '重量g', key: 'weight', width: 100 }, + { title: '缩略图', key: 'thumb', width: 100 }, +]); + +const skuTableScrollX = computed( + () => 740 + specAxes.value.length * 120, +); + const logisticsOptions = ref<{ label: string; value: number }[]>([]); const costTemplateDetail = ref( null, @@ -471,6 +571,10 @@ async function applyCatSelection(catId: number, pathIds?: string, pathLabel?: st catTemplate.value = null; parentSpecs.value = []; form.goodsPropValues = {}; + clearSkuRows(); + specAxes.value = []; + specCatalog.value = []; + specValueDraftByRow.value = {}; if (!form.pddShopId || !form.catId) return; try { const [tpl, specs] = await Promise.all([ @@ -485,6 +589,7 @@ async function applyCatSelection(catId: number, pathIds?: string, pathLabel?: st ]); catTemplate.value = tpl; parentSpecs.value = specs ?? []; + rebuildSpecCatalogAndSeed(); } catch (e: any) { message.error(e?.message || '加载类目模板失败'); } @@ -575,6 +680,10 @@ watch( costTemplateDetail.value = null; catTemplate.value = null; parentSpecs.value = []; + clearSkuRows(); + specAxes.value = []; + specCatalog.value = []; + specValueDraftByRow.value = {}; logisticsOptions.value = []; form.goodsPropValues = {}; catSearchHitOptions.value = []; @@ -588,27 +697,335 @@ watch( }, ); -function emptySkuRow(): SkuRow { +function clearSkuRows() { + for (const row of skuRows.value) { + revokeUploadFiles(row.thumbFileList); + } + skuRows.value = []; +} + +/** 从类目销售属性 / 父规格构建可选规格目录 */ +function buildSpecCatalog(): SpecCatalogItem[] { + const sales = saleProps.value; + const parents = parentSpecs.value; + if (parents.length > 0) { + return parents.map((ps) => { + const matchedSale = sales.find((s) => s.name === ps.parentSpecName); + return { + catalogKey: `ps_${ps.parentSpecId}`, + name: ps.parentSpecName || `规格${ps.parentSpecId}`, + parentSpecId: ps.parentSpecId, + refPid: matchedSale?.refPid, + templatePid: matchedSale?.templatePid, + valueUnit: matchedSale?.valueUnit, + presetOptions: (matchedSale?.values || []).map((v) => ({ + label: v.value || String(v.vid), + value: String(v.vid ?? v.value), + vid: v.vid, + specId: v.specId, + })), + }; + }); + } + const items: SpecCatalogItem[] = []; + for (const sp of sales) { + const parentSpecId = sp.specId; + if (parentSpecId == null) continue; + items.push({ + catalogKey: String(sp.refPid ?? sp.templatePid ?? parentSpecId), + name: sp.name || String(parentSpecId), + parentSpecId, + refPid: sp.refPid, + templatePid: sp.templatePid, + valueUnit: sp.valueUnit, + presetOptions: (sp.values || []).map((v) => ({ + label: v.value || String(v.vid), + value: String(v.vid ?? v.value), + vid: v.vid, + specId: v.specId, + })), + }); + } + return items; +} + +function createAxisFromCatalog(item: SpecCatalogItem): SpecAxis { return { - key: skuRowSeq++, - skuName: '', - outSkuSn: '', - quantity: 100, - weight: 1, - thumbFileList: [], - saleValues: {}, + rowId: specAxisRowSeq++, + catalogKey: item.catalogKey, + key: item.catalogKey, + name: item.name, + parentSpecId: item.parentSpecId, + refPid: item.refPid, + templatePid: item.templatePid, + valueUnit: item.valueUnit, + presetOptions: item.presetOptions.map((o) => ({ ...o })), + selectedValues: [], }; } -function addBlankSkuRow() { - skuRows.value.push(emptySkuRow()); +function findDefaultCatalogItem(catalog: SpecCatalogItem[]) { + return ( + catalog.find((c) => c.name === '款式') || + catalog.find((c) => c.name.includes('款式')) || + catalog[0] + ); +} + +/** 重建可选规格,并默认种子一条「款式」 */ +function rebuildSpecCatalogAndSeed() { + const catalog = buildSpecCatalog(); + specCatalog.value = catalog; + specValueDraftByRow.value = {}; + const def = findDefaultCatalogItem(catalog); + specAxes.value = def ? [createAxisFromCatalog(def)] : []; + syncSkuRowsFromSpecs(); +} + +/** 某行可选的父规格(排除已被其他行占用) */ +function catalogOptionsForAxis(rowId: number) { + const used = new Set( + specAxes.value + .filter((a) => a.rowId !== rowId) + .map((a) => a.catalogKey), + ); + return specCatalog.value + .filter((c) => !used.has(c.catalogKey)) + .map((c) => ({ label: c.name, value: c.catalogKey })); +} + +function applyCatalogToAxis(axis: SpecAxis, catalogKey: string) { + const item = specCatalog.value.find((c) => c.catalogKey === catalogKey); + if (!item) return; + axis.catalogKey = item.catalogKey; + axis.key = item.catalogKey; + axis.name = item.name; + axis.parentSpecId = item.parentSpecId; + axis.refPid = item.refPid; + axis.templatePid = item.templatePid; + axis.valueUnit = item.valueUnit; + axis.presetOptions = item.presetOptions.map((o) => ({ ...o })); + axis.selectedValues = []; +} + +function onAxisCatalogChange(rowId: number, catalogKey: string) { + const axis = specAxes.value.find((a) => a.rowId === rowId); + if (!axis || !catalogKey) return; + applyCatalogToAxis(axis, catalogKey); + syncSkuRowsFromSpecs(); +} + +function addSpecAxis() { + if (specAxes.value.length >= 2) { + message.warning('最多添加两种规格'); + return; + } + const used = new Set(specAxes.value.map((a) => a.catalogKey)); + const next = specCatalog.value.find((c) => !used.has(c.catalogKey)); + if (!next) { + message.warning('没有可添加的规格了'); + return; + } + specAxes.value.push(createAxisFromCatalog(next)); + syncSkuRowsFromSpecs(); +} + +function removeSpecAxis(rowId: number) { + if (specAxes.value.length <= 1) { + message.warning('至少保留一个规格'); + return; + } + const axis = specAxes.value.find((a) => a.rowId === rowId); + AntModal.confirm({ + title: '确认删除规格?', + content: `确定删除规格「${axis?.name || ''}」及其全部取值吗?相关 SKU 组合将重新生成。`, + okText: '删除', + okType: 'danger', + cancelText: '取消', + centered: true, + zIndex: 2100, + onOk() { + specAxes.value = specAxes.value.filter((a) => a.rowId !== rowId); + const drafts = { ...specValueDraftByRow.value }; + delete drafts[rowId]; + specValueDraftByRow.value = drafts; + syncSkuRowsFromSpecs(); + }, + }); +} + +function unusedPresetOptions(axis: SpecAxis) { + const selected = new Set(axis.selectedValues); + return axis.presetOptions + .filter((o) => !selected.has(o.value)) + .map((o) => ({ label: o.label, value: o.value })); +} + +function addSpecValue(rowId: number, raw: string) { + const axis = specAxes.value.find((a) => a.rowId === rowId); + if (!axis) return; + const text = raw.trim(); + if (!text) return; + const matched = axis.presetOptions.find( + (o) => o.value === text || o.label === text, + ); + const value = matched?.value ?? text; + if (axis.selectedValues.includes(value)) { + message.warning('该规格值已添加'); + return; + } + axis.selectedValues.push(value); + specValueDraftByRow.value = { + ...specValueDraftByRow.value, + [rowId]: '', + }; + syncSkuRowsFromSpecs(); +} + +function commitSpecValueDraft(rowId: number) { + addSpecValue(rowId, specValueDraftByRow.value[rowId] || ''); +} + +function setSpecValueDraft(rowId: number, value: string) { + specValueDraftByRow.value = { + ...specValueDraftByRow.value, + [rowId]: value, + }; +} + +function removeSpecValue(rowId: number, index: number) { + const axis = specAxes.value.find((a) => a.rowId === rowId); + if (!axis) return; + const raw = axis.selectedValues[index]; + if (raw == null) return; + const label = labelOfAxisValue(axis, raw); + AntModal.confirm({ + title: '确认删除规格值?', + content: `确定删除「${axis.name}」的取值「${label}」吗?相关 SKU 组合将重新生成。`, + okText: '删除', + okType: 'danger', + cancelText: '取消', + centered: true, + zIndex: 2100, + onOk() { + const current = specAxes.value.find((a) => a.rowId === rowId); + if (!current) return; + // 确认期间取值可能已变,按当时值定位删除 + const idx = current.selectedValues.indexOf(raw); + if (idx < 0) return; + current.selectedValues.splice(idx, 1); + syncSkuRowsFromSpecs(); + }, + }); +} + +function cartesianProduct(lists: string[][]): string[][] { + if (lists.length === 0) return []; + return lists.reduce( + (acc, curr) => acc.flatMap((prefix) => curr.map((item) => [...prefix, item])), + [[]], + ); +} + +function comboKeyOf(values: string[]) { + return values.join('\u0001'); +} + +function labelOfAxisValue(axis: SpecAxis, value: string) { + return axis.presetOptions.find((o) => o.value === value)?.label ?? value; +} + +/** SKU 行某规格列展示文案(Table bodyCell 的 record 类型较宽) */ +function skuSpecColumnLabel( + record: { saleValues?: Record }, + columnKey: string, +) { + const axisKey = columnKey.replace(/^spec_/, ''); + const axis = specAxes.value.find((a) => a.key === axisKey); + const raw = record.saleValues?.[axisKey]; + if (!axis || raw == null || raw === '') return '—'; + return labelOfAxisValue(axis, raw); +} + +/** + * 规格取值变化后按笛卡尔积生成 SKU;同组合键保留已填价格/编码/图。 + */ +function syncSkuRowsFromSpecs() { + const axes = specAxes.value; + if (axes.length === 0) { + clearSkuRows(); + return; + } + if (axes.some((a) => a.selectedValues.length === 0)) { + clearSkuRows(); + return; + } + + const combos = cartesianProduct(axes.map((a) => a.selectedValues)); + const maxSku = Number(catTemplate.value?.maxSkuNum ?? 0); + if (maxSku > 0 && combos.length > maxSku) { + message.warning( + `规格组合共 ${combos.length} 个,超过类目上限 ${maxSku},请减少规格值`, + ); + } + + const prevByKey = new Map(skuRows.value.map((r) => [r.comboKey, r])); + const next: SkuRow[] = []; + const usedKeys = new Set(); + + for (const combo of combos) { + const key = comboKeyOf(combo); + usedKeys.add(key); + const saleValues: Record = {}; + const labels: string[] = []; + axes.forEach((axis, i) => { + const v = combo[i]!; + saleValues[axis.key] = v; + labels.push(labelOfAxisValue(axis, v)); + }); + const skuName = labels.join(' / '); + const prev = prevByKey.get(key); + if (prev) { + prev.skuName = skuName; + prev.saleValues = saleValues; + next.push(prev); + prevByKey.delete(key); + } else { + next.push({ + key: skuRowSeq++, + comboKey: key, + skuName, + outSkuSn: '', + quantity: 100, + weight: 1, + thumbFileList: [], + saleValues, + }); + } + } + + for (const orphan of prevByKey.values()) { + revokeUploadFiles(orphan.thumbFileList); + } + skuRows.value = next; void scrollSkuTableToBottom(); } -function addInternalSku(skuId?: number) { - if (skuId == null) return; - if (skuRows.value.some((r) => r.internalSkuId === skuId)) { - message.warning('该内部 SKU 已在列表中'); +/** 将内部 SKU 绑定到某一组合行(只填编码,不新增行) */ +function bindInternalSku(rowKey: number, skuId?: number) { + const row = skuRows.value.find((r) => r.key === rowKey); + if (!row) return; + if (skuId == null) { + row.internalSkuId = undefined; + row.productName = undefined; + return; + } + if ( + skuRows.value.some( + (r) => r.key !== row.key && r.internalSkuId === skuId, + ) + ) { + message.warning('该内部 SKU 已绑定到其他规格组合'); return; } const sku = skuOptions.value.find((s) => s.id === skuId); @@ -616,18 +1033,11 @@ function addInternalSku(skuId?: number) { message.warning('未找到该 SKU,请先搜索'); return; } - skuRows.value.push({ - key: skuRowSeq++, - internalSkuId: sku.id, - productName: sku.productName, - skuName: sku.name, - outSkuSn: sku.skuCode || '', - quantity: 100, - weight: 1, - thumbFileList: [], - saleValues: {}, - }); - void scrollSkuTableToBottom(); + row.internalSkuId = sku.id; + row.productName = sku.productName; + if (sku.skuCode) { + row.outSkuSn = sku.skuCode; + } } /** 新增规格后滚到表体底部,方便继续编辑新行 */ @@ -641,19 +1051,6 @@ async function scrollSkuTableToBottom() { body.scrollTo({ top: body.scrollHeight, behavior: 'smooth' }); } -function onPickInternalSku(skuId?: number) { - addInternalSku(skuId); - pickInternalSkuId.value = undefined; -} - -function removeSkuRow(key: number) { - const row = skuRows.value.find((r) => r.key === key); - if (row) { - revokeUploadFiles(row.thumbFileList); - } - skuRows.value = skuRows.value.filter((r) => r.key !== key); -} - async function onCatChange(path: number[]) { if (!path?.length) { form.catPath = []; @@ -663,6 +1060,10 @@ async function onCatChange(path: number[]) { catTemplate.value = null; parentSpecs.value = []; form.goodsPropValues = {}; + clearSkuRows(); + specAxes.value = []; + specCatalog.value = []; + specValueDraftByRow.value = {}; return; } const searching = @@ -678,6 +1079,10 @@ async function onCatChange(path: number[]) { pinnedSelectedCat.value = null; catTemplate.value = null; parentSpecs.value = []; + clearSkuRows(); + specAxes.value = []; + specCatalog.value = []; + specValueDraftByRow.value = {}; return; } const catId = path[path.length - 1]!; @@ -928,13 +1333,25 @@ function validateForm(): boolean { message.warning('请选择详情图'); return false; } + if (specAxes.value.length === 0) { + message.warning('当前类目无可用规格,请更换类目或联系运营'); + return false; + } + for (const axis of specAxes.value) { + if (axis.selectedValues.length === 0) { + message.warning(`请为规格「${axis.name}」选择或填写至少一个取值`); + return false; + } + } if (skuRows.value.length === 0) { - message.warning('请至少添加一个规格 SKU'); + message.warning('请先完成规格取值以生成 SKU'); return false; } for (const row of skuRows.value) { if (!row.outSkuSn.trim()) { - message.warning('每个 SKU 需填写商家编码,或选择内部 SKU'); + message.warning( + `请为规格组合「${row.skuName || '未命名'}」填写商家编码,或关联内部 SKU`, + ); return false; } if (row.priceYuan == null || row.multiPriceYuan == null) { @@ -945,15 +1362,6 @@ function validateForm(): boolean { message.warning(`请为 SKU「${row.skuName || row.outSkuSn}」选择缩略图`); return false; } - for (const sp of saleProps.value) { - const key = String(sp.refPid ?? sp.templatePid); - if (!row.saleValues[key]) { - message.warning( - `请为 SKU「${row.skuName || row.outSkuSn}」填写规格「${sp.name || key}」`, - ); - return false; - } - } } return true; } @@ -963,6 +1371,7 @@ async function buildPublishPayload( detailFileIds: number[], thumbFileIdBySkuKey: Map, ): Promise { + // 非销售属性 → goods_properties(不传 parent_spec_id / spec_id) const goodsProperties: PddGoodsPublishDTO.GoodsProperty[] = []; for (const p of nonSaleProps.value) { const key = String(p.templatePid ?? p.refPid); @@ -977,10 +1386,17 @@ async function buildPublishPayload( valueUnit: p.valueUnit, vid: matched?.vid, value: matched?.value ?? raw, - specId: matched?.specId, }); } + /** + * 销售规格:goods.add 要求 + * 1) goods_properties 带 parent_spec_id + spec_id(规格值去重) + * 2) sku.spec_id_list 为该 SKU 的规格组合 + * 3) sku.sku_properties 为销售属性 ref_pid/vid/value(有 refPid 时) + */ + const saleSpecSeen = new Set(); + const skus: PddGoodsPublishDTO.PublishSku[] = []; for (const row of skuRows.value) { const thumbFileId = thumbFileIdBySkuKey.get(row.key); @@ -989,41 +1405,61 @@ async function buildPublishPayload( } const specIds: number[] = []; const skuProperties: PddGoodsPublishDTO.SkuProperty[] = []; - for (const sp of saleProps.value) { - const key = String(sp.refPid ?? sp.templatePid); - const raw = row.saleValues[key]; - if (!raw) continue; - const matched = sp.values?.find( - (v) => String(v.vid) === raw || v.value === raw, - ); + + for (const axis of specAxes.value) { + const raw = row.saleValues[axis.key]; + if (!raw) { + throw new Error( + `SKU「${row.skuName || row.outSkuSn}」缺少规格「${axis.name}」`, + ); + } + const matched = axis.presetOptions.find((o) => o.value === raw); let specId = matched?.specId; - const valueText = matched?.value ?? raw; - const parentSpecId = - sp.specId ?? - parentSpecs.value.find((x) => x.parentSpecName === sp.name) - ?.parentSpecId; - if (!specId && parentSpecId != null && valueText) { + const valueText = matched?.label ?? raw; + const parentSpecId = axis.parentSpecId; + if (parentSpecId == null) { + throw new Error( + `规格「${axis.name}」缺少 parent_spec_id,请重新选择类目`, + ); + } + if (!specId && valueText) { specId = await resolveSpecId(parentSpecId, valueText); } - if (specId != null) { - specIds.push(specId); + if (specId == null) { + throw new Error( + `SKU「${row.skuName || row.outSkuSn}」规格「${axis.name}」无法生成 spec_id`, + ); } - if (sp.refPid != null && (matched?.vid != null || valueText)) { + specIds.push(specId); + + const dedupeKey = `${parentSpecId}:${specId}`; + if (!saleSpecSeen.has(dedupeKey)) { + saleSpecSeen.add(dedupeKey); + goodsProperties.push({ + refPid: axis.refPid, + templatePid: axis.templatePid, + valueUnit: axis.valueUnit, + vid: matched?.vid, + value: valueText, + parentSpecId, + specId, + }); + } + + if (axis.refPid != null) { skuProperties.push({ - refPid: sp.refPid, + refPid: axis.refPid, vid: matched?.vid ?? 0, value: valueText, - punit: sp.valueUnit || '', + punit: axis.valueUnit || '', }); } } - if (saleProps.value.length === 0 && parentSpecs.value.length > 0) { - const label = row.skuName || row.outSkuSn; - for (const ps of parentSpecs.value) { - const specId = await resolveSpecId(ps.parentSpecId, label); - specIds.push(specId); - } + if (specIds.length === 0) { + throw new Error( + `SKU「${row.skuName || row.outSkuSn}」未生成规格列表`, + ); } skus.push({ @@ -1116,7 +1552,10 @@ function resetAll() { form.secondHand = false; clearLocalImages(); form.goodsPropValues = {}; - skuRows.value = []; + clearSkuRows(); + specAxes.value = []; + specCatalog.value = []; + specValueDraftByRow.value = {}; catTemplate.value = null; parentSpecs.value = []; rootCatOptions.value = []; @@ -1451,182 +1890,200 @@ onBeforeUnmount(() => { -
-
-
- 规格 SKU - - ({{ skuRows.length }}) - -
- -