feat: 工作台SKU汇总列展示商品名/规格名并悬停显示编码

This commit is contained in:
2026-09-06 10:50:52 +08:00
parent 2b5bc02dc8
commit f6803bcdae
5 changed files with 58 additions and 14 deletions
@@ -117,7 +117,7 @@ public class CompanyOverviewVO {
private PlatformOverview platformTable;
private CategoryOverview categoryTable;
private CategoryOverview productTable;
/** SKU 汇总(复用 CategoryOverview;categoryId=skuId,categoryName=sku 名) */
/** SKU 汇总(复用 CategoryOverview;categoryId=skuId,categoryName=商品名/规格名) */
private CategoryOverview skuTable;
}
@@ -289,6 +289,12 @@ public class CompanyOverviewVO {
private String categoryName;
/** SKU 汇总行:所属商品名(展示用) */
private String productName;
/** SKU 汇总行:规格编码(悬停展示) */
private String skuCode;
private BigDecimal salesAmount;
private BigDecimal dealAmount;
@@ -472,7 +472,8 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
}
}
Map<Long, String> skuNames = loadSkuNameMap(bySku.keySet());
Map<Long, SkuLabel> skuLabels = loadSkuLabelMap(bySku.keySet());
Map<Long, String> productNames = loadProductNameMap(new java.util.HashSet<>(skuProductId.values()));
List<CompanyOverviewVO.CategorySummary> list = new ArrayList<>();
for (Map.Entry<Long, AggMetrics> e : bySku.entrySet()) {
Long skuId = e.getKey();
@@ -484,8 +485,22 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
? productPromo.multiply(m.sales).divide(productSkuSalesPool, 4, RoundingMode.HALF_UP)
: BigDecimal.ZERO;
BigDecimal brush = allocBrushShare(skuSalesByShop.get(skuId), brushByShop);
String name = skuId <= 0 ? "未绑定规格" : skuNames.getOrDefault(skuId, "规格" + skuId);
list.add(toCategorySummaryFromAgg(skuId, name, m, promo, brush));
SkuLabel label = skuId != null && skuId > 0 ? skuLabels.get(skuId) : null;
String skuName = skuId == null || skuId <= 0
? "未绑定规格"
: (label != null && label.name() != null && !label.name().isBlank()
? label.name()
: "规格" + skuId);
String productName = productId != null && productId > 0
? productNames.getOrDefault(productId, "商品" + productId)
: null;
String displayName = productName != null ? productName + "/" + skuName : skuName;
CompanyOverviewVO.CategorySummary row = toCategorySummaryFromAgg(skuId, displayName, m, promo, brush);
row.setProductName(productName);
if (label != null && label.code() != null && !label.code().isBlank()) {
row.setSkuCode(label.code());
}
list.add(row);
}
list.sort(Comparator.comparing(CompanyOverviewVO.CategorySummary::getSalesAmount,
Comparator.nullsFirst(BigDecimal::compareTo)).reversed());
@@ -820,13 +835,26 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
.stream().collect(Collectors.toMap(ProductPO::getId, ProductPO::getName, (a, b) -> a));
}
private Map<Long, String> loadSkuNameMap(java.util.Set<Long> skuKeys) {
/** SKU 展示标签:规格名 + 编码 */
private Map<Long, SkuLabel> loadSkuLabelMap(java.util.Set<Long> skuKeys) {
List<Long> ids = skuKeys.stream().filter(id -> id != null && id > 0).distinct().toList();
if (ids.isEmpty()) {
return Map.of();
}
return productSkuMapper.selectList(new LambdaQueryWrapper<ProductSkuPO>().in(ProductSkuPO::getId, ids))
.stream().collect(Collectors.toMap(ProductSkuPO::getId, ProductSkuPO::getName, (a, b) -> a));
Map<Long, SkuLabel> map = new HashMap<>();
for (ProductSkuPO sku : productSkuMapper.selectList(
new LambdaQueryWrapper<ProductSkuPO>().in(ProductSkuPO::getId, ids))) {
if (sku.getId() == null) {
continue;
}
map.put(sku.getId(), new SkuLabel(
sku.getName() != null ? sku.getName() : ("规格" + sku.getId()),
sku.getSkuCode()));
}
return map;
}
private record SkuLabel(String name, String code) {
}
private Map<Long, List<ShopMonthlyTargetPO>> loadTargetsByShop(Long companyId, LocalDate start, LocalDate end) {
@@ -136,6 +136,10 @@ export namespace CompanyOverviewVO {
export interface CategorySummary {
categoryId?: number | null;
categoryName?: string;
/** SKU 汇总:所属商品名 */
productName?: string;
/** SKU 汇总:规格编码(悬停) */
skuCode?: string;
salesAmount?: number;
dealAmount?: number;
salesOrderCount?: number;
@@ -4,6 +4,8 @@ import type { CompanyOverviewVO } from '#/api/bi/overview';
import { createIconifyIcon } from '@vben/icons';
import { computed } from 'vue';
import { Tooltip } from 'ant-design-vue';
import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio';
import { formatIntCell, formatNumberCell } from '#/utils/overview-table-cells';
@@ -361,14 +363,18 @@ const cellRoi = (v: number | null | undefined) =>
{{ cat.categoryName }}
<JumpIcon class="text-xs" />
</span>
<span
<Tooltip
v-else-if="skuNavigate && cat.categoryId != null"
class="inline-flex cursor-pointer items-center gap-1 rounded-full bg-blue-50 px-3 py-1 text-sm font-bold text-blue-600 transition-colors hover:text-blue-300 hover:underline dark:bg-blue-900/30 dark:text-blue-400"
@click="emit('navigate-sku', cat.categoryId!)"
:title="cat.skuCode ? `SKU编码:${cat.skuCode}` : undefined"
>
{{ cat.categoryName }}
<JumpIcon class="text-xs" />
</span>
<span
class="inline-flex max-w-full cursor-pointer items-center gap-1 rounded-full bg-blue-50 px-3 py-1 text-sm font-bold text-blue-600 transition-colors hover:text-blue-300 hover:underline dark:bg-blue-900/30 dark:text-blue-400"
@click="emit('navigate-sku', cat.categoryId!)"
>
<span class="truncate">{{ cat.categoryName || '-' }}</span>
<JumpIcon class="shrink-0 text-xs" />
</span>
</Tooltip>
<span
v-else
class="inline-block rounded-full bg-blue-50 px-3 py-1 text-sm font-bold text-blue-600 dark:bg-blue-900/30 dark:text-blue-400"
@@ -258,7 +258,7 @@ function handleSkuExport() {
v-if="activeMode === 'sku'"
column-prefs-key="sku"
heading-title="各 SKU 多维度经营明细汇总"
heading-subtitle="数据来自 Mongo SKU 日汇聚;推广按所属商品推广占比分摊;点击规格名可跳转 SKU 概览"
heading-subtitle="数据来自 Mongo SKU 日汇聚;推广按所属商品推广占比分摊;列显示为「商品名/规格名」,悬停可看 SKU 编码;点击可跳转 SKU 概览"
first-column-label="SKU"
:sku-navigate="true"
:category-summary="skuSummary ?? undefined"