mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
feat: 区域销量接店省日汇聚与 overview API
This commit is contained in:
+8
@@ -13,6 +13,7 @@ import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStat
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.repository.BiOrderStatDailyRepository;
|
||||
import top.xyquan.ecomdmbbackend.common.time.BizClock;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.service.BiOrderStatCalcTaskService;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.service.OrderDailyStatComputeService;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
@@ -33,6 +34,7 @@ public class BiStatIncConsumer {
|
||||
private final BiStatProperties biStatProperties;
|
||||
private final DelayedMqRepublisher delayedMqRepublisher;
|
||||
private final BiOrderStatCalcTaskService calcTaskService;
|
||||
private final OrderDailyStatComputeService orderDailyStatComputeService;
|
||||
|
||||
@RabbitListener(
|
||||
queues = OrderMqConstants.QUEUE_BI_STAT_INC,
|
||||
@@ -104,6 +106,12 @@ public class BiStatIncConsumer {
|
||||
message.getShopDelta(),
|
||||
message.getProductDeltas(),
|
||||
message.getSkuDeltas());
|
||||
// INC 消息无省维 delta:同锁内轻量扫单重算 region,避免省分布落后
|
||||
orderDailyStatComputeService.recomputeRegionDay(
|
||||
message.getCompanyId(),
|
||||
message.getShopId(),
|
||||
statDate,
|
||||
message.getPlatformCode());
|
||||
calcTaskService.recordIncAppliedThrottled(
|
||||
message.getCompanyId(), message.getShopId(), statDate, message.getOrderId(), false);
|
||||
log.info("BI inc delta 已累加 shopId={} statDate={} orderId={}",
|
||||
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndex;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndexes;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 店铺×省×日订单汇聚。province 为规范化全称;净销售由读侧 deal − refund 推导。
|
||||
*/
|
||||
@Data
|
||||
@Document(collection = "bi_order_stat_daily_region")
|
||||
@CompoundIndexes({
|
||||
@CompoundIndex(
|
||||
name = "uk_company_shop_province_date",
|
||||
def = "{'companyId':1,'shopId':1,'province':1,'statDate':1}",
|
||||
unique = true),
|
||||
@CompoundIndex(name = "idx_company_date", def = "{'companyId':1,'statDate':1}"),
|
||||
@CompoundIndex(name = "idx_company_shop_date", def = "{'companyId':1,'shopId':1,'statDate':1}")
|
||||
})
|
||||
public class BiOrderStatDailyRegionDoc {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
private Long companyId;
|
||||
private Long shopId;
|
||||
private String platformCode;
|
||||
private LocalDate statDate;
|
||||
|
||||
/** 规范化省名(与 DataV geoJSON 对齐;未知为 {@code __UNKNOWN__}) */
|
||||
private String province;
|
||||
|
||||
private BigDecimal dealAmount = BigDecimal.ZERO;
|
||||
private Integer dealOrderCount = 0;
|
||||
private Integer dealQuantitySum = 0;
|
||||
private BigDecimal refundAmount = BigDecimal.ZERO;
|
||||
private Integer refundOrderCount = 0;
|
||||
private Integer refundQuantitySum = 0;
|
||||
private BigDecimal serviceFee = BigDecimal.ZERO;
|
||||
private BigDecimal productCost = BigDecimal.ZERO;
|
||||
private BigDecimal freightCost = BigDecimal.ZERO;
|
||||
private BigDecimal otherCost = BigDecimal.ZERO;
|
||||
|
||||
private Instant dbSnapshotTime;
|
||||
private Instant computedAt;
|
||||
private String computeMode;
|
||||
}
|
||||
+95
@@ -4,9 +4,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyProductDoc;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyRegionDoc;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyShopDoc;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailySkuDoc;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.repository.BiOrderStatDailyRepository;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.support.BiRegionNormalizer;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.overview.model.agg.OverviewAggRows;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.mapper.ProductMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductPO;
|
||||
@@ -38,6 +40,99 @@ public class BiOrderStatQueryService {
|
||||
return repository.listShopDocs(companyId, shopIds, start, end);
|
||||
}
|
||||
|
||||
/** 区间内区域(省)日文档。 */
|
||||
public List<BiOrderStatDailyRegionDoc> listRegionDocs(Long companyId, List<Long> shopIds,
|
||||
LocalDate start, LocalDate end) {
|
||||
return repository.listRegionDocs(companyId, shopIds, start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* 区域日文档按省合并区间;净销售三件套 = 成交 − 退款。
|
||||
* 默认跳过 {@link BiRegionNormalizer#UNKNOWN}(地图/排行不展示未知省)。
|
||||
*/
|
||||
public List<ProvincePeriodMetrics> sumRegionDocsByProvince(List<BiOrderStatDailyRegionDoc> docs) {
|
||||
return sumRegionDocsByProvince(docs, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param skipUnknown true 时过滤 {@link BiRegionNormalizer#UNKNOWN}
|
||||
*/
|
||||
public List<ProvincePeriodMetrics> sumRegionDocsByProvince(List<BiOrderStatDailyRegionDoc> docs,
|
||||
boolean skipUnknown) {
|
||||
Map<String, ProvincePeriodMetrics> merged = new HashMap<>();
|
||||
if (docs == null) {
|
||||
return List.of();
|
||||
}
|
||||
for (BiOrderStatDailyRegionDoc doc : docs) {
|
||||
if (doc == null) {
|
||||
continue;
|
||||
}
|
||||
String province = doc.getProvince() != null ? doc.getProvince() : BiRegionNormalizer.UNKNOWN;
|
||||
if (skipUnknown && BiRegionNormalizer.isUnknown(province)) {
|
||||
continue;
|
||||
}
|
||||
BigDecimal deal = nz(doc.getDealAmount());
|
||||
BigDecimal refund = nz(doc.getRefundAmount());
|
||||
int dealOrders = nzInt(doc.getDealOrderCount());
|
||||
int refundOrders = nzInt(doc.getRefundOrderCount());
|
||||
int dealQty = nzInt(doc.getDealQuantitySum());
|
||||
int refundQty = nzInt(doc.getRefundQuantitySum());
|
||||
ProvincePeriodMetrics cur = merged.get(province);
|
||||
if (cur == null) {
|
||||
merged.put(province, new ProvincePeriodMetrics(
|
||||
province,
|
||||
netAmount(deal, refund),
|
||||
refund,
|
||||
nz(doc.getProductCost()),
|
||||
nz(doc.getFreightCost()),
|
||||
nz(doc.getOtherCost()),
|
||||
netCount(dealOrders, refundOrders),
|
||||
netCount(dealQty, refundQty),
|
||||
deal, dealOrders, dealQty,
|
||||
refundOrders, refundQty));
|
||||
} else {
|
||||
BigDecimal nextDeal = cur.dealAmount().add(deal);
|
||||
BigDecimal nextRefund = cur.refundAmount().add(refund);
|
||||
int nextDealOrders = cur.dealOrderCount() + dealOrders;
|
||||
int nextRefundOrders = cur.refundOrderCount() + refundOrders;
|
||||
int nextDealQty = cur.dealQuantitySum() + dealQty;
|
||||
int nextRefundQty = cur.refundQuantitySum() + refundQty;
|
||||
merged.put(province, new ProvincePeriodMetrics(
|
||||
province,
|
||||
netAmount(nextDeal, nextRefund),
|
||||
nextRefund,
|
||||
cur.productCost().add(nz(doc.getProductCost())),
|
||||
cur.freightCost().add(nz(doc.getFreightCost())),
|
||||
cur.otherCost().add(nz(doc.getOtherCost())),
|
||||
netCount(nextDealOrders, nextRefundOrders),
|
||||
netCount(nextDealQty, nextRefundQty),
|
||||
nextDeal, nextDealOrders, nextDealQty,
|
||||
nextRefundOrders, nextRefundQty));
|
||||
}
|
||||
}
|
||||
return new ArrayList<>(merged.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* 省区间指标。{@code salesAmount}/{@code salesOrderCount}/{@code salesQuantitySum} 为净销售三件套。
|
||||
*/
|
||||
public record ProvincePeriodMetrics(
|
||||
String province,
|
||||
BigDecimal salesAmount,
|
||||
BigDecimal refundAmount,
|
||||
BigDecimal productCost,
|
||||
BigDecimal freightCost,
|
||||
BigDecimal otherCost,
|
||||
int salesOrderCount,
|
||||
int salesQuantitySum,
|
||||
BigDecimal dealAmount,
|
||||
int dealOrderCount,
|
||||
int dealQuantitySum,
|
||||
int refundOrderCount,
|
||||
int refundQuantitySum
|
||||
) {
|
||||
}
|
||||
|
||||
public List<BiOrderStatDailyProductDoc> listProductDocs(Long companyId, List<Long> shopIds,
|
||||
LocalDate start, LocalDate end) {
|
||||
return repository.listProductDocs(companyId, shopIds, start, end);
|
||||
|
||||
+32
-1
@@ -11,6 +11,7 @@ import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiProductStatDelta;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiSkuStatDelta;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiStatMetricDelta;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyProductDoc;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyRegionDoc;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyShopDoc;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailySkuDoc;
|
||||
|
||||
@@ -45,6 +46,20 @@ public class BiOrderStatDailyRepository {
|
||||
return mongoTemplate.find(q, BiOrderStatDailyShopDoc.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 区间内区域(省)日文档。{@code shopIds} 为空返回空列表。
|
||||
*/
|
||||
public List<BiOrderStatDailyRegionDoc> listRegionDocs(Long companyId, List<Long> shopIds,
|
||||
LocalDate start, LocalDate end) {
|
||||
if (companyId == null || shopIds == null || shopIds.isEmpty() || start == null || end == null) {
|
||||
return List.of();
|
||||
}
|
||||
Query q = Query.query(Criteria.where("companyId").is(companyId)
|
||||
.and("shopId").in(shopIds)
|
||||
.and("statDate").gte(start).lte(end));
|
||||
return mongoTemplate.find(q, BiOrderStatDailyRegionDoc.class);
|
||||
}
|
||||
|
||||
/** 区间内商品日文档(闭区间)。shopIds 为空返回空列表。 */
|
||||
public List<BiOrderStatDailyProductDoc> listProductDocs(Long companyId, List<Long> shopIds,
|
||||
LocalDate start, LocalDate end) {
|
||||
@@ -116,7 +131,8 @@ public class BiOrderStatDailyRepository {
|
||||
|
||||
public void replaceShopDay(BiOrderStatDailyShopDoc shopDoc,
|
||||
List<BiOrderStatDailyProductDoc> products,
|
||||
List<BiOrderStatDailySkuDoc> skus) {
|
||||
List<BiOrderStatDailySkuDoc> skus,
|
||||
List<BiOrderStatDailyRegionDoc> regions) {
|
||||
Long companyId = shopDoc.getCompanyId();
|
||||
Long shopId = shopDoc.getShopId();
|
||||
LocalDate statDate = shopDoc.getStatDate();
|
||||
@@ -141,6 +157,21 @@ public class BiOrderStatDailyRepository {
|
||||
if (skus != null && !skus.isEmpty()) {
|
||||
mongoTemplate.insertAll(skus);
|
||||
}
|
||||
replaceRegionDay(companyId, shopId, statDate, regions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换某店某日全部区域日文档(先删后插)。仅写 region 集合,供 INC 后轻量重算。
|
||||
*/
|
||||
public void replaceRegionDay(Long companyId, Long shopId, LocalDate statDate,
|
||||
List<BiOrderStatDailyRegionDoc> regions) {
|
||||
Query dayQ = Query.query(Criteria.where("companyId").is(companyId)
|
||||
.and("shopId").is(shopId)
|
||||
.and("statDate").is(statDate));
|
||||
mongoTemplate.remove(dayQ, BiOrderStatDailyRegionDoc.class);
|
||||
if (regions != null && !regions.isEmpty()) {
|
||||
mongoTemplate.insertAll(regions);
|
||||
}
|
||||
}
|
||||
|
||||
/** 将转换侧算出的增量累加到日文档(无文档则按 delta 新建)。 */
|
||||
|
||||
+81
-14
@@ -8,9 +8,11 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.infra.lock.BiStatComputeLock;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyProductDoc;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyRegionDoc;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyShopDoc;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailySkuDoc;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.repository.BiOrderStatDailyRepository;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.support.BiRegionNormalizer;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.support.OrderItemCostResolver;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.mapper.OrderItemMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.mapper.OrderMapper;
|
||||
@@ -114,6 +116,19 @@ public class OrderDailyStatComputeService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅重算并替换某店某日的区域日文档(扫单写 region,不动 shop/product/sku)。
|
||||
* 供 INC delta 成功后补齐省维;调用方须已持有同店同日计算锁。
|
||||
*/
|
||||
public void recomputeRegionDay(Long companyId, Long shopId, LocalDate statDate, String platformCode) {
|
||||
DayAgg agg = aggregateDay(companyId, shopId, statDate, platformCode);
|
||||
Instant now = Instant.now();
|
||||
List<BiOrderStatDailyRegionDoc> regions = buildRegionDocs(agg, null, now, "INC");
|
||||
repository.replaceRegionDay(companyId, shopId, statDate, regions);
|
||||
log.info("BI 区域日重算完成 companyId={} shopId={} statDate={} provinces={}",
|
||||
companyId, shopId, statDate, regions.size());
|
||||
}
|
||||
|
||||
private DayAgg aggregateDay(Long companyId, Long shopId, LocalDate statDate, String platformCode) {
|
||||
LocalDateTime start = statDate.atStartOfDay();
|
||||
LocalDateTime end = statDate.plusDays(1).atStartOfDay();
|
||||
@@ -151,6 +166,7 @@ public class OrderDailyStatComputeService {
|
||||
Metric shop = new Metric();
|
||||
Map<String, Metric> productMap = new HashMap<>();
|
||||
Map<String, Metric> skuMap = new HashMap<>();
|
||||
Map<String, Metric> regionMap = new HashMap<>();
|
||||
Map<String, DimKey> productKeys = new HashMap<>();
|
||||
Map<String, DimKey> skuKeys = new HashMap<>();
|
||||
|
||||
@@ -168,17 +184,26 @@ public class OrderDailyStatComputeService {
|
||||
}
|
||||
BigDecimal received = OrderStatusStatSets.receivedAmount(order);
|
||||
BigDecimal fee = deal ? nz(order.getServiceFee()) : BigDecimal.ZERO;
|
||||
String province = BiRegionNormalizer.normalize(order.getProvince());
|
||||
Metric region = regionMap.computeIfAbsent(province, k -> new Metric());
|
||||
|
||||
if (deal) {
|
||||
shop.dealAmount = shop.dealAmount.add(received);
|
||||
shop.dealOrderCount++;
|
||||
shop.dealQuantitySum += qtySum;
|
||||
shop.serviceFee = shop.serviceFee.add(fee);
|
||||
region.dealAmount = region.dealAmount.add(received);
|
||||
region.dealOrderCount++;
|
||||
region.dealQuantitySum += qtySum;
|
||||
region.serviceFee = region.serviceFee.add(fee);
|
||||
}
|
||||
if (refund) {
|
||||
shop.refundAmount = shop.refundAmount.add(received);
|
||||
shop.refundOrderCount++;
|
||||
shop.refundQuantitySum += qtySum;
|
||||
region.refundAmount = region.refundAmount.add(received);
|
||||
region.refundOrderCount++;
|
||||
region.refundQuantitySum += qtySum;
|
||||
}
|
||||
|
||||
Set<String> countedProductDeal = new HashSet<>();
|
||||
@@ -195,6 +220,9 @@ public class OrderDailyStatComputeService {
|
||||
int qty = OrderStatusStatSets.quantity(item);
|
||||
BigDecimal lineReceived = allocateLine(received, item, items);
|
||||
BigDecimal lineFee = deal ? allocateLine(fee, item, items) : BigDecimal.ZERO;
|
||||
BigDecimal linePc = lineProductCost(order, item, stat, unitCostBySku);
|
||||
BigDecimal lineFc = lineFreightCost(order, item, stat, unitCostBySku);
|
||||
BigDecimal lineOc = lineOtherCost(order, item, stat, unitCostBySku);
|
||||
|
||||
String pk = companyId + ":" + shopId + ":" + productId;
|
||||
Metric pm = productMap.computeIfAbsent(pk, k -> new Metric());
|
||||
@@ -214,9 +242,9 @@ public class OrderDailyStatComputeService {
|
||||
pm.refundOrderCount++;
|
||||
}
|
||||
}
|
||||
pm.productCost = pm.productCost.add(lineProductCost(order, item, stat, unitCostBySku));
|
||||
pm.freightCost = pm.freightCost.add(lineFreightCost(order, item, stat, unitCostBySku));
|
||||
pm.otherCost = pm.otherCost.add(lineOtherCost(order, item, stat, unitCostBySku));
|
||||
pm.productCost = pm.productCost.add(linePc);
|
||||
pm.freightCost = pm.freightCost.add(lineFc);
|
||||
pm.otherCost = pm.otherCost.add(lineOc);
|
||||
|
||||
String sk = companyId + ":" + shopId + ":" + skuId;
|
||||
Metric sm = skuMap.computeIfAbsent(sk, k -> new Metric());
|
||||
@@ -236,13 +264,16 @@ public class OrderDailyStatComputeService {
|
||||
sm.refundOrderCount++;
|
||||
}
|
||||
}
|
||||
sm.productCost = sm.productCost.add(lineProductCost(order, item, stat, unitCostBySku));
|
||||
sm.freightCost = sm.freightCost.add(lineFreightCost(order, item, stat, unitCostBySku));
|
||||
sm.otherCost = sm.otherCost.add(lineOtherCost(order, item, stat, unitCostBySku));
|
||||
sm.productCost = sm.productCost.add(linePc);
|
||||
sm.freightCost = sm.freightCost.add(lineFc);
|
||||
sm.otherCost = sm.otherCost.add(lineOc);
|
||||
|
||||
shop.productCost = shop.productCost.add(lineProductCost(order, item, stat, unitCostBySku));
|
||||
shop.freightCost = shop.freightCost.add(lineFreightCost(order, item, stat, unitCostBySku));
|
||||
shop.otherCost = shop.otherCost.add(lineOtherCost(order, item, stat, unitCostBySku));
|
||||
shop.productCost = shop.productCost.add(linePc);
|
||||
shop.freightCost = shop.freightCost.add(lineFc);
|
||||
shop.otherCost = shop.otherCost.add(lineOc);
|
||||
region.productCost = region.productCost.add(linePc);
|
||||
region.freightCost = region.freightCost.add(lineFc);
|
||||
region.otherCost = region.otherCost.add(lineOc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,7 +282,8 @@ public class OrderDailyStatComputeService {
|
||||
platform = orders.get(0).getPlatformCode();
|
||||
}
|
||||
|
||||
return new DayAgg(companyId, shopId, statDate, platform, shop, productMap, productKeys, skuMap, skuKeys);
|
||||
return new DayAgg(companyId, shopId, statDate, platform, shop,
|
||||
productMap, productKeys, skuMap, skuKeys, regionMap);
|
||||
}
|
||||
|
||||
private void persist(DayAgg agg, Instant snapshotTime, String mode) {
|
||||
@@ -297,9 +329,30 @@ public class OrderDailyStatComputeService {
|
||||
skus.add(doc);
|
||||
}
|
||||
|
||||
repository.replaceShopDay(shopDoc, products, skus);
|
||||
log.info("BI 日汇聚完成 mode={} companyId={} shopId={} statDate={} ordersShopDeal={}",
|
||||
mode, agg.companyId(), agg.shopId(), agg.statDate(), agg.shop().dealOrderCount);
|
||||
List<BiOrderStatDailyRegionDoc> regions = buildRegionDocs(agg, snapshotTime, now, mode);
|
||||
repository.replaceShopDay(shopDoc, products, skus, regions);
|
||||
log.info("BI 日汇聚完成 mode={} companyId={} shopId={} statDate={} ordersShopDeal={} provinces={}",
|
||||
mode, agg.companyId(), agg.shopId(), agg.statDate(),
|
||||
agg.shop().dealOrderCount, regions.size());
|
||||
}
|
||||
|
||||
private static List<BiOrderStatDailyRegionDoc> buildRegionDocs(
|
||||
DayAgg agg, Instant snapshotTime, Instant computedAt, String mode) {
|
||||
List<BiOrderStatDailyRegionDoc> regions = new ArrayList<>();
|
||||
for (Map.Entry<String, Metric> e : agg.regionMap().entrySet()) {
|
||||
BiOrderStatDailyRegionDoc doc = new BiOrderStatDailyRegionDoc();
|
||||
doc.setCompanyId(agg.companyId());
|
||||
doc.setShopId(agg.shopId());
|
||||
doc.setPlatformCode(agg.platformCode());
|
||||
doc.setStatDate(agg.statDate());
|
||||
doc.setProvince(e.getKey());
|
||||
applyMetric(doc, e.getValue());
|
||||
doc.setDbSnapshotTime(snapshotTime);
|
||||
doc.setComputedAt(computedAt);
|
||||
doc.setComputeMode(mode);
|
||||
regions.add(doc);
|
||||
}
|
||||
return regions;
|
||||
}
|
||||
|
||||
private static void applyMetric(BiOrderStatDailyShopDoc doc, Metric m) {
|
||||
@@ -341,6 +394,19 @@ public class OrderDailyStatComputeService {
|
||||
doc.setOtherCost(m.otherCost);
|
||||
}
|
||||
|
||||
private static void applyMetric(BiOrderStatDailyRegionDoc doc, Metric m) {
|
||||
doc.setDealAmount(m.dealAmount);
|
||||
doc.setDealOrderCount(m.dealOrderCount);
|
||||
doc.setDealQuantitySum(m.dealQuantitySum);
|
||||
doc.setRefundAmount(m.refundAmount);
|
||||
doc.setRefundOrderCount(m.refundOrderCount);
|
||||
doc.setRefundQuantitySum(m.refundQuantitySum);
|
||||
doc.setServiceFee(m.serviceFee);
|
||||
doc.setProductCost(m.productCost);
|
||||
doc.setFreightCost(m.freightCost);
|
||||
doc.setOtherCost(m.otherCost);
|
||||
}
|
||||
|
||||
/** 按行金额占比分摊订单实收;无行金额则均分。 */
|
||||
private static BigDecimal allocateLine(BigDecimal orderPay, OrderItemPO item, List<OrderItemPO> items) {
|
||||
BigDecimal totalLine = BigDecimal.ZERO;
|
||||
@@ -415,6 +481,7 @@ public class OrderDailyStatComputeService {
|
||||
Map<String, Metric> productMap,
|
||||
Map<String, DimKey> productKeys,
|
||||
Map<String, Metric> skuMap,
|
||||
Map<String, DimKey> skuKeys) {
|
||||
Map<String, DimKey> skuKeys,
|
||||
Map<String, Metric> regionMap) {
|
||||
}
|
||||
}
|
||||
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.orderstat.support;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 订单收货省名规范化:统一为 DataV 省级 geoJSON 全称,供区域日汇聚与地图着色对齐。
|
||||
* <p>
|
||||
* 空/无法识别 → {@link #UNKNOWN}。
|
||||
*/
|
||||
public final class BiRegionNormalizer {
|
||||
|
||||
/** 空或无法映射的省份占位键 */
|
||||
public static final String UNKNOWN = "__UNKNOWN__";
|
||||
|
||||
private static final Map<String, String> ALIAS_TO_FULL = buildAliasMap();
|
||||
|
||||
private BiRegionNormalizer() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 将渠道侧省名规范为地图全称;空白或未知返回 {@link #UNKNOWN}。
|
||||
*/
|
||||
public static String normalize(String raw) {
|
||||
if (raw == null) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
String s = raw.trim();
|
||||
if (s.isEmpty()) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
// 去掉常见空白与全角空格
|
||||
s = s.replace('\u3000', ' ').replace(" ", "");
|
||||
String hit = ALIAS_TO_FULL.get(s);
|
||||
if (hit != null) {
|
||||
return hit;
|
||||
}
|
||||
// 英文忽略大小写再试一次(偶发 HK / Beijing)
|
||||
hit = ALIAS_TO_FULL.get(s.toLowerCase(Locale.ROOT));
|
||||
return hit != null ? hit : UNKNOWN;
|
||||
}
|
||||
|
||||
/** 是否为未知省占位 */
|
||||
public static boolean isUnknown(String province) {
|
||||
return UNKNOWN.equals(province);
|
||||
}
|
||||
|
||||
private static Map<String, String> buildAliasMap() {
|
||||
Map<String, String> m = new LinkedHashMap<>();
|
||||
put(m, "北京市", "北京", "北京省", "beijing");
|
||||
put(m, "天津市", "天津", "天津省", "tianjin");
|
||||
put(m, "河北省", "河北", "hebei");
|
||||
put(m, "山西省", "山西", "shanxi");
|
||||
put(m, "内蒙古自治区", "内蒙古", "内蒙古省", "内蒙", "neimenggu", "inner mongolia");
|
||||
put(m, "辽宁省", "辽宁", "liaoning");
|
||||
put(m, "吉林省", "吉林", "jilin");
|
||||
put(m, "黑龙江省", "黑龙江", "heilongjiang");
|
||||
put(m, "上海市", "上海", "上海省", "shanghai");
|
||||
put(m, "江苏省", "江苏", "jiangsu");
|
||||
put(m, "浙江省", "浙江", "zhejiang");
|
||||
put(m, "安徽省", "安徽", "anhui");
|
||||
put(m, "福建省", "福建", "fujian");
|
||||
put(m, "江西省", "江西", "jiangxi");
|
||||
put(m, "山东省", "山东", "shandong");
|
||||
put(m, "河南省", "河南", "henan");
|
||||
put(m, "湖北省", "湖北", "hubei");
|
||||
put(m, "湖南省", "湖南", "hunan");
|
||||
put(m, "广东省", "广东", "guangdong");
|
||||
put(m, "广西壮族自治区", "广西", "广西省", "广西自治区", "guangxi");
|
||||
put(m, "海南省", "海南", "hainan");
|
||||
put(m, "重庆市", "重庆", "重庆省", "chongqing");
|
||||
put(m, "四川省", "四川", "sichuan");
|
||||
put(m, "贵州省", "贵州", "guizhou");
|
||||
put(m, "云南省", "云南", "yunnan");
|
||||
put(m, "西藏自治区", "西藏", "西藏省", "xizang", "tibet");
|
||||
put(m, "陕西省", "陕西", "shaanxi");
|
||||
put(m, "甘肃省", "甘肃", "gansu");
|
||||
put(m, "青海省", "青海", "qinghai");
|
||||
put(m, "宁夏回族自治区", "宁夏", "宁夏省", "宁夏自治区", "ningxia");
|
||||
put(m, "新疆维吾尔自治区", "新疆", "新疆省", "新疆自治区", "xinjiang");
|
||||
put(m, "台湾省", "台湾", "taiwan");
|
||||
put(m, "香港特别行政区", "香港", "香港特区", "hongkong", "hong kong", "hk");
|
||||
put(m, "澳门特别行政区", "澳门", "澳门特区", "macao", "macau", "mo");
|
||||
return Map.copyOf(m);
|
||||
}
|
||||
|
||||
/** 标准全称自身 + 若干别名都映射到 full */
|
||||
private static void put(Map<String, String> m, String full, String... aliases) {
|
||||
m.put(full, full);
|
||||
if (aliases != null) {
|
||||
for (String a : aliases) {
|
||||
if (a != null && !a.isBlank()) {
|
||||
m.put(a.trim(), full);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.regionoverview.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.regionoverview.model.dto.RegionOverviewQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.regionoverview.model.vo.RegionOverviewVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.regionoverview.service.BiRegionOverviewService;
|
||||
|
||||
/**
|
||||
* 区域销量概览:省级净销售(地图 + 排行)。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/bi/region")
|
||||
public class BiRegionOverviewController {
|
||||
|
||||
private final BiRegionOverviewService biRegionOverviewService;
|
||||
|
||||
public BiRegionOverviewController(BiRegionOverviewService biRegionOverviewService) {
|
||||
this.biRegionOverviewService = biRegionOverviewService;
|
||||
}
|
||||
|
||||
@PostMapping("/overview")
|
||||
@RequirePermission(value = "bi:workbench:read", description = "查询区域销量概览", allowSuper = true)
|
||||
public ApiResponse<RegionOverviewVO> overview(@Valid @RequestBody RegionOverviewQueryDTO queryDTO) {
|
||||
return ApiResponse.success("获取区域销量成功", biRegionOverviewService.overview(queryDTO));
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.regionoverview.model.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 区域销量概览查询:日期 + 可选平台/店铺筛选(与工作台筛选对齐)。
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class RegionOverviewQueryDTO {
|
||||
|
||||
@NotEmpty(message = "日期范围不能为空")
|
||||
@Size(min = 1, max = 2, message = "日期范围必须包含 1~2 个日期")
|
||||
private List<LocalDate> dateRange;
|
||||
|
||||
/** 平台代码,不传表示全平台 */
|
||||
private String platformCode;
|
||||
|
||||
/** 店铺 ID,不传表示当前筛选下全部门店 */
|
||||
private Long shopId;
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.regionoverview.model.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 区域销量概览:省级净销售列表。
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class RegionOverviewVO {
|
||||
|
||||
private List<RegionProvinceRowVO> provinces;
|
||||
|
||||
/** 查询区间开始 */
|
||||
private String startDate;
|
||||
|
||||
/** 查询区间结束 */
|
||||
private String endDate;
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.regionoverview.model.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 省级净销售汇总行(地图色阶 + 排行)。
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class RegionProvinceRowVO {
|
||||
|
||||
/** 规范化省名,与 DataV geoJSON 对齐 */
|
||||
private String province;
|
||||
|
||||
/** 净销售额(元)= 成交 − 退款 */
|
||||
private BigDecimal salesAmount;
|
||||
|
||||
/** 净销量(件) */
|
||||
private Integer salesQuantitySum;
|
||||
|
||||
/** 净销售单量 */
|
||||
private Integer salesOrderCount;
|
||||
|
||||
/** 退款额(元) */
|
||||
private BigDecimal refundAmount;
|
||||
|
||||
/** 成交额(元) */
|
||||
private BigDecimal dealAmount;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.regionoverview.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.regionoverview.model.dto.RegionOverviewQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.regionoverview.model.vo.RegionOverviewVO;
|
||||
|
||||
/**
|
||||
* 区域销量概览:Mongo 省日汇聚按省 rollup。
|
||||
*/
|
||||
public interface BiRegionOverviewService {
|
||||
|
||||
RegionOverviewVO overview(RegionOverviewQueryDTO queryDTO);
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.regionoverview.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.query.BiOrderStatQueryService;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.regionoverview.model.dto.RegionOverviewQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.regionoverview.model.vo.RegionOverviewVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.regionoverview.model.vo.RegionProvinceRowVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.regionoverview.service.BiRegionOverviewService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.po.ShopPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.service.ShopService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 区域销量:按当前公司店铺筛选读 Mongo 省日文档,再按省汇总净销售。
|
||||
*/
|
||||
@Service
|
||||
public class BiRegionOverviewServiceImpl implements BiRegionOverviewService {
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final ShopService shopService;
|
||||
private final BiOrderStatQueryService orderStatQueryService;
|
||||
|
||||
public BiRegionOverviewServiceImpl(CurrentUserContext currentUserContext,
|
||||
ShopService shopService,
|
||||
BiOrderStatQueryService orderStatQueryService) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.shopService = shopService;
|
||||
this.orderStatQueryService = orderStatQueryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegionOverviewVO overview(RegionOverviewQueryDTO queryDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
DateRange range = parseDateRange(queryDTO);
|
||||
List<ShopPO> shops = loadFilteredShops(companyId, queryDTO.getPlatformCode(), queryDTO.getShopId());
|
||||
List<Long> shopIds = shops.stream().map(ShopPO::getId).filter(Objects::nonNull).toList();
|
||||
if (shopIds.isEmpty()) {
|
||||
return empty(range);
|
||||
}
|
||||
|
||||
var docs = orderStatQueryService.listRegionDocs(
|
||||
companyId, shopIds, range.start(), range.end());
|
||||
List<RegionProvinceRowVO> rows = orderStatQueryService.sumRegionDocsByProvince(docs).stream()
|
||||
.map(m -> RegionProvinceRowVO.builder()
|
||||
.province(m.province())
|
||||
.salesAmount(nz(m.salesAmount()))
|
||||
.salesQuantitySum(m.salesQuantitySum())
|
||||
.salesOrderCount(m.salesOrderCount())
|
||||
.refundAmount(nz(m.refundAmount()))
|
||||
.dealAmount(nz(m.dealAmount()))
|
||||
.build())
|
||||
.sorted(Comparator.comparing(RegionProvinceRowVO::getSalesAmount,
|
||||
Comparator.nullsLast(Comparator.reverseOrder())))
|
||||
.toList();
|
||||
|
||||
return RegionOverviewVO.builder()
|
||||
.provinces(rows)
|
||||
.startDate(range.start().toString())
|
||||
.endDate(range.end().toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
private RegionOverviewVO empty(DateRange range) {
|
||||
return RegionOverviewVO.builder()
|
||||
.provinces(List.of())
|
||||
.startDate(range.start().toString())
|
||||
.endDate(range.end().toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
private List<ShopPO> loadFilteredShops(Long companyId, String platformCode, Long shopId) {
|
||||
if (shopId != null) {
|
||||
ShopPO one = shopService.getById(shopId);
|
||||
if (one == null || !companyId.equals(one.getCompanyId())) {
|
||||
throw new BusinessException("店铺不存在");
|
||||
}
|
||||
if (platformCode != null && !platformCode.isBlank()
|
||||
&& one.getPlatformCode() != null && !platformCode.equals(one.getPlatformCode())) {
|
||||
throw new BusinessException("店铺与所选平台不一致");
|
||||
}
|
||||
return List.of(one);
|
||||
}
|
||||
LambdaQueryWrapper<ShopPO> w = new LambdaQueryWrapper<>();
|
||||
w.eq(ShopPO::getCompanyId, companyId);
|
||||
if (platformCode != null && !platformCode.isBlank()) {
|
||||
w.eq(ShopPO::getPlatformCode, platformCode.trim());
|
||||
}
|
||||
return shopService.list(w);
|
||||
}
|
||||
|
||||
private static DateRange parseDateRange(RegionOverviewQueryDTO queryDTO) {
|
||||
List<LocalDate> dates = queryDTO.getDateRange();
|
||||
if (dates == null || dates.isEmpty()) {
|
||||
throw new BusinessException("日期范围不能为空");
|
||||
}
|
||||
LocalDate start = dates.get(0);
|
||||
LocalDate end = dates.size() >= 2 && dates.get(1) != null ? dates.get(1) : start;
|
||||
if (start == null) {
|
||||
throw new BusinessException("开始日期不能为空");
|
||||
}
|
||||
if (end.isBefore(start)) {
|
||||
LocalDate tmp = start;
|
||||
start = end;
|
||||
end = tmp;
|
||||
}
|
||||
return new DateRange(start, end);
|
||||
}
|
||||
|
||||
private static BigDecimal nz(BigDecimal v) {
|
||||
return v != null ? v : BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
private record DateRange(LocalDate start, LocalDate end) {
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.orderstat.support;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class BiRegionNormalizerTest {
|
||||
|
||||
@Test
|
||||
void normalize_aliasesToFullName() {
|
||||
assertEquals("广东省", BiRegionNormalizer.normalize("广东"));
|
||||
assertEquals("广东省", BiRegionNormalizer.normalize("广东省"));
|
||||
assertEquals("内蒙古自治区", BiRegionNormalizer.normalize("内蒙古"));
|
||||
assertEquals("广西壮族自治区", BiRegionNormalizer.normalize("广西"));
|
||||
assertEquals("新疆维吾尔自治区", BiRegionNormalizer.normalize("新疆"));
|
||||
assertEquals("北京市", BiRegionNormalizer.normalize("北京"));
|
||||
assertEquals("香港特别行政区", BiRegionNormalizer.normalize("香港"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void normalize_blankOrUnknown() {
|
||||
assertEquals(BiRegionNormalizer.UNKNOWN, BiRegionNormalizer.normalize(null));
|
||||
assertEquals(BiRegionNormalizer.UNKNOWN, BiRegionNormalizer.normalize(" "));
|
||||
assertEquals(BiRegionNormalizer.UNKNOWN, BiRegionNormalizer.normalize("火星省"));
|
||||
assertTrue(BiRegionNormalizer.isUnknown(BiRegionNormalizer.UNKNOWN));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { RegionOverviewDTO, RegionOverviewVO } from './types';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/** 区域销量:省级净销售列表(地图 + 排行) */
|
||||
export async function getRegionOverviewApi(data: RegionOverviewDTO.Query) {
|
||||
return requestClient.post<RegionOverviewVO.Overview>(
|
||||
'/bi/region/overview',
|
||||
data,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './types.dto';
|
||||
export * from './types.vo';
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 区域销量查询 DTO(与后端 RegionOverviewQueryDTO 对齐)
|
||||
*/
|
||||
export namespace RegionOverviewDTO {
|
||||
export interface Query {
|
||||
/** 日期范围 [开始, 结束],单元素表示当天 */
|
||||
dateRange: string[];
|
||||
/** 平台代码,不传表示全平台 */
|
||||
platformCode?: string;
|
||||
/** 店铺 ID,不传表示当前筛选下全部门店 */
|
||||
shopId?: number;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 区域销量概览 VO(与后端 RegionOverviewVO 对齐)
|
||||
*/
|
||||
export namespace RegionOverviewVO {
|
||||
export interface ProvinceRow {
|
||||
/** 规范化省名,与地图 geoJSON 对齐 */
|
||||
province: string;
|
||||
/** 净销售额(元) */
|
||||
salesAmount: number;
|
||||
/** 净销量(件) */
|
||||
salesQuantitySum: number;
|
||||
/** 净销售单量 */
|
||||
salesOrderCount: number;
|
||||
/** 退款额(元) */
|
||||
refundAmount: number;
|
||||
/** 成交额(元) */
|
||||
dealAmount?: number;
|
||||
}
|
||||
|
||||
export interface Overview {
|
||||
provinces: ProvinceRow[];
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
}
|
||||
}
|
||||
@@ -30,12 +30,14 @@ import { getPlatformListApi } from '#/api/ec/platform/apis';
|
||||
import type { PlatformVO } from '#/api/ec/platform/types';
|
||||
import { getShopPageApi } from '#/api/ec/shop/apis';
|
||||
import type { ShopDTO, ShopVO } from '#/api/ec/shop/types';
|
||||
import { getRegionOverviewApi } from '#/api/bi/region/apis';
|
||||
import {
|
||||
getWorkbenchFinanceApi,
|
||||
getWorkbenchMultiAnalysisApi,
|
||||
getWorkbenchSalesRankApi,
|
||||
} from '#/api/bi/workbench/apis';
|
||||
import type { WorkbenchDTO, WorkbenchVO } from '#/api/bi/workbench/types';
|
||||
import type { RegionSalesPanel } from './tabs/region/types';
|
||||
import { $t } from '#/locales';
|
||||
import {
|
||||
buildOverviewRouteQuery,
|
||||
@@ -75,19 +77,22 @@ const EMPTY_FINANCE: WorkbenchVO.FinancePanel = {
|
||||
};
|
||||
|
||||
/** 需懒加载数据的 Tab(区间对比 Tab 自行请求) */
|
||||
type DataTabKey = 'finance' | 'multi' | 'salesRank';
|
||||
type DataTabKey = 'finance' | 'region' | 'multi' | 'salesRank';
|
||||
|
||||
const financeSlice = ref<WorkbenchVO.FinanceSlice | null>(null);
|
||||
const regionPanel = ref<RegionSalesPanel | null>(null);
|
||||
const multiAnalysisData = ref<WorkbenchVO.MultiPanel | null>(null);
|
||||
const salesRankData = ref<WorkbenchVO.MultiPanel | null>(null);
|
||||
|
||||
const financeLoading = ref(false);
|
||||
const regionLoading = ref(false);
|
||||
const multiLoading = ref(false);
|
||||
const salesRankLoading = ref(false);
|
||||
|
||||
/** Tab 首次激活标记:筛选变更时重置,切换 Tab 时再按需拉数 */
|
||||
const tabLoaded: Record<DataTabKey, boolean> = {
|
||||
finance: false,
|
||||
region: false,
|
||||
multi: false,
|
||||
salesRank: false,
|
||||
};
|
||||
@@ -460,7 +465,21 @@ function buildWorkbenchQuery(): WorkbenchDTO.Query {
|
||||
return query;
|
||||
}
|
||||
|
||||
const DATA_TAB_KEYS: DataTabKey[] = ['finance', 'multi', 'salesRank'];
|
||||
const DATA_TAB_KEYS: DataTabKey[] = ['finance', 'region', 'multi', 'salesRank'];
|
||||
|
||||
function toRegionPanel(
|
||||
overview: Awaited<ReturnType<typeof getRegionOverviewApi>>,
|
||||
): RegionSalesPanel {
|
||||
return {
|
||||
rows: (overview.provinces ?? []).map((p) => ({
|
||||
provinceName: p.province,
|
||||
salesAmount: Number(p.salesAmount ?? 0),
|
||||
salesQty: Number(p.salesQuantitySum ?? 0),
|
||||
orderCount: Number(p.salesOrderCount ?? 0),
|
||||
refundAmount: Number(p.refundAmount ?? 0),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
/** 离开页面超过该时长再自动刷新(visibility) */
|
||||
const AUTO_REFRESH_AWAY_MS = 30_000;
|
||||
@@ -479,6 +498,9 @@ function hasTabData(tab: DataTabKey): boolean {
|
||||
case 'finance': {
|
||||
return financeSlice.value != null;
|
||||
}
|
||||
case 'region': {
|
||||
return regionPanel.value != null;
|
||||
}
|
||||
case 'multi': {
|
||||
return multiAnalysisData.value != null;
|
||||
}
|
||||
@@ -506,6 +528,12 @@ async function loadTabData(tab: DataTabKey, opts?: { force?: boolean }) {
|
||||
tabLoaded.finance = true;
|
||||
break;
|
||||
}
|
||||
case 'region': {
|
||||
if (blocking) regionLoading.value = true;
|
||||
regionPanel.value = toRegionPanel(await getRegionOverviewApi(query));
|
||||
tabLoaded.region = true;
|
||||
break;
|
||||
}
|
||||
case 'multi': {
|
||||
if (blocking) multiLoading.value = true;
|
||||
multiAnalysisData.value = await getWorkbenchMultiAnalysisApi(query);
|
||||
@@ -531,6 +559,13 @@ async function loadTabData(tab: DataTabKey, opts?: { force?: boolean }) {
|
||||
tabLoaded.finance = true;
|
||||
break;
|
||||
}
|
||||
case 'region': {
|
||||
if (!regionPanel.value) {
|
||||
regionPanel.value = { rows: [] };
|
||||
}
|
||||
tabLoaded.region = true;
|
||||
break;
|
||||
}
|
||||
case 'multi': {
|
||||
if (!multiAnalysisData.value) {
|
||||
multiAnalysisData.value = EMPTY_MULTI;
|
||||
@@ -549,6 +584,8 @@ async function loadTabData(tab: DataTabKey, opts?: { force?: boolean }) {
|
||||
} finally {
|
||||
if (tab === 'finance') {
|
||||
financeLoading.value = false;
|
||||
} else if (tab === 'region') {
|
||||
regionLoading.value = false;
|
||||
} else if (tab === 'multi') {
|
||||
multiLoading.value = false;
|
||||
} else {
|
||||
@@ -569,16 +606,11 @@ async function softRefreshActiveTab() {
|
||||
await periodCompareTabRef.value?.refresh?.({ silent: true });
|
||||
softInvalidateDataTabs();
|
||||
})()
|
||||
: activeTab.value === 'region'
|
||||
? (async () => {
|
||||
await regionTabRef.value?.redraw();
|
||||
softInvalidateDataTabs();
|
||||
})()
|
||||
: (async () => {
|
||||
const tab = activeTab.value as DataTabKey;
|
||||
await loadTabData(tab, { force: true });
|
||||
softInvalidateDataTabs(tab);
|
||||
})();
|
||||
: (async () => {
|
||||
const tab = activeTab.value as DataTabKey;
|
||||
await loadTabData(tab, { force: true });
|
||||
softInvalidateDataTabs(tab);
|
||||
})();
|
||||
await Promise.all([dataPromise, refreshBiHealth()]);
|
||||
}
|
||||
|
||||
@@ -597,11 +629,6 @@ async function refreshActiveDataTab(opts?: { force?: boolean }) {
|
||||
await periodCompareTabRef.value?.refresh?.({ silent: !!opts?.force });
|
||||
return;
|
||||
}
|
||||
if (activeTab.value === 'region') {
|
||||
// Mock Tab:随筛选种子变化即可,触发重绘
|
||||
await regionTabRef.value?.redraw();
|
||||
return;
|
||||
}
|
||||
await loadTabData(activeTab.value as DataTabKey, opts);
|
||||
}
|
||||
|
||||
@@ -754,12 +781,6 @@ const periodCompareTabRef = ref<
|
||||
| null
|
||||
>(null);
|
||||
|
||||
/** 区域销量 Mock 随筛选日期变化,便于演示分布变化 */
|
||||
const regionRangeKey = computed(
|
||||
() =>
|
||||
`${dateRange.value[0]?.format('YYYY-MM-DD')}_${dateRange.value[1]?.format('YYYY-MM-DD')}_${selectedPlatformSlug.value}_${selectedShopSlug.value}`,
|
||||
);
|
||||
|
||||
async function redrawActiveTabCharts() {
|
||||
await nextTick();
|
||||
switch (activeTab.value) {
|
||||
@@ -788,7 +809,7 @@ async function redrawActiveTabCharts() {
|
||||
}
|
||||
|
||||
watch(activeTab, (tab) => {
|
||||
if (tab !== 'periodCompare' && tab !== 'region') {
|
||||
if (tab !== 'periodCompare') {
|
||||
void loadTabData(tab as DataTabKey);
|
||||
}
|
||||
void refreshBiHealth();
|
||||
@@ -1104,10 +1125,12 @@ onUnmounted(() => {
|
||||
</Spin>
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane key="region" tab="区域销量">
|
||||
<WorkbenchRegionTab
|
||||
ref="regionTabRef"
|
||||
:range-key="regionRangeKey"
|
||||
/>
|
||||
<Spin :spinning="regionLoading && !regionPanel">
|
||||
<WorkbenchRegionTab
|
||||
ref="regionTabRef"
|
||||
:panel="regionPanel"
|
||||
/>
|
||||
</Spin>
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane key="multi" tab="多维分析">
|
||||
<Spin :spinning="multiLoading && !multiAnalysisData">
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ function onRowClick(name: string) {
|
||||
<div class="min-h-0 flex-1 overflow-y-auto px-2 py-2">
|
||||
<button
|
||||
v-for="row in ranked"
|
||||
:key="row.provinceCode"
|
||||
:key="row.provinceName"
|
||||
type="button"
|
||||
class="flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-2 text-left transition-colors"
|
||||
:class="
|
||||
|
||||
@@ -4,23 +4,22 @@ import type { RegionMetricKey, RegionSalesPanel, RegionSalesRow } from './types'
|
||||
import { computed, nextTick, ref, watch } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import { Segmented } from 'ant-design-vue';
|
||||
import { Empty, Segmented } from 'ant-design-vue';
|
||||
|
||||
import { FINANCE_KPI_CARD_SHELL } from '../finance/constants/finance-ui';
|
||||
import RegionSalesMapChart from './components/RegionSalesMapChart.vue';
|
||||
import RegionSalesRankList from './components/RegionSalesRankList.vue';
|
||||
import { buildMockRegionSalesPanel } from './mock-data';
|
||||
import { REGION_METRIC_OPTIONS } from './types';
|
||||
|
||||
defineOptions({ name: 'WorkbenchRegionTab' });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/** 与工作台筛选同步的区间种子,便于演示时随筛选轻微变化 */
|
||||
rangeKey?: string;
|
||||
/** 后端区域概览面板;未加载时为空壳 */
|
||||
panel?: RegionSalesPanel | null;
|
||||
}>(),
|
||||
{
|
||||
rangeKey: 'default',
|
||||
panel: null,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -33,11 +32,7 @@ const metric = ref<RegionMetricKey>('salesAmount');
|
||||
const selectedProvince = ref<string | null>(null);
|
||||
const mapRef = ref<InstanceType<typeof RegionSalesMapChart> | null>(null);
|
||||
|
||||
const panel = computed<RegionSalesPanel>(() =>
|
||||
buildMockRegionSalesPanel(props.rangeKey),
|
||||
);
|
||||
|
||||
const rows = computed(() => panel.value.rows);
|
||||
const rows = computed(() => props.panel?.rows ?? []);
|
||||
|
||||
function metricValue(row: RegionSalesRow): number {
|
||||
switch (metric.value) {
|
||||
@@ -103,7 +98,7 @@ async function redraw() {
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.rangeKey,
|
||||
() => props.panel,
|
||||
() => {
|
||||
selectedProvince.value = null;
|
||||
},
|
||||
@@ -122,117 +117,125 @@ defineExpose({ redraw });
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-3 md:grid-cols-4">
|
||||
<div :class="[FINANCE_KPI_CARD_SHELL]">
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<span class="text-xs font-medium text-slate-500">全国净销售额</span>
|
||||
<span
|
||||
class="flex size-8 items-center justify-center rounded-lg bg-blue-50 text-blue-500 dark:bg-blue-950/40 dark:text-blue-300"
|
||||
>
|
||||
<CoinsIcon class="size-4" />
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="mt-3 text-[22px] font-bold tabular-nums tracking-tight text-slate-800 dark:text-slate-100"
|
||||
>
|
||||
¥{{ formatWan(kpis.totalAmount) }}
|
||||
</div>
|
||||
</div>
|
||||
<div :class="[FINANCE_KPI_CARD_SHELL]">
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<span class="text-xs font-medium text-slate-500">全国净销量</span>
|
||||
<span
|
||||
class="flex size-8 items-center justify-center rounded-lg bg-emerald-50 text-emerald-500 dark:bg-emerald-950/40 dark:text-emerald-300"
|
||||
>
|
||||
<PackageIcon class="size-4" />
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="mt-3 text-[22px] font-bold tabular-nums tracking-tight text-slate-800 dark:text-slate-100"
|
||||
>
|
||||
{{ kpis.totalQty.toLocaleString('zh-CN') }}
|
||||
</div>
|
||||
</div>
|
||||
<div :class="[FINANCE_KPI_CARD_SHELL]">
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<span class="text-xs font-medium text-slate-500">覆盖省份</span>
|
||||
<span
|
||||
class="flex size-8 items-center justify-center rounded-lg bg-violet-50 text-violet-500 dark:bg-violet-950/40 dark:text-violet-300"
|
||||
>
|
||||
<MapPinIcon class="size-4" />
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="mt-3 text-[22px] font-bold tabular-nums tracking-tight text-slate-800 dark:text-slate-100"
|
||||
>
|
||||
{{ kpis.covered }}
|
||||
<span class="text-sm font-normal text-slate-400">/ {{ rows.length }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div :class="[FINANCE_KPI_CARD_SHELL]">
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<span class="text-xs font-medium text-slate-500">TOP1 占比</span>
|
||||
<span
|
||||
class="flex size-8 items-center justify-center rounded-lg bg-amber-50 text-amber-500 dark:bg-amber-950/40 dark:text-amber-300"
|
||||
>
|
||||
<PercentIcon class="size-4" />
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="mt-3 text-[22px] font-bold tabular-nums tracking-tight text-slate-800 dark:text-slate-100"
|
||||
>
|
||||
{{ kpis.topShare.toFixed(1) }}%
|
||||
</div>
|
||||
<div class="mt-1 truncate text-xs text-slate-500">{{ kpis.topName }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<Empty
|
||||
v-if="panel && rows.length === 0"
|
||||
class="py-16"
|
||||
description="暂无区域销量数据,请先跑店日全量汇聚"
|
||||
/>
|
||||
|
||||
<div
|
||||
v-if="selectedRow"
|
||||
class="flex flex-wrap items-center gap-x-4 gap-y-1 rounded-xl border border-indigo-200/80 bg-indigo-50/60 px-4 py-2.5 text-sm dark:border-indigo-500/30 dark:bg-indigo-950/30"
|
||||
>
|
||||
<span class="font-semibold text-indigo-700 dark:text-indigo-200">
|
||||
{{ selectedRow.provinceName }}
|
||||
</span>
|
||||
<span class="tabular-nums text-slate-700 dark:text-slate-200">
|
||||
净销售额 ¥{{ formatWan(selectedRow.salesAmount) }}
|
||||
</span>
|
||||
<span class="tabular-nums text-slate-600 dark:text-slate-300">
|
||||
净销量 {{ selectedRow.salesQty.toLocaleString('zh-CN') }}
|
||||
</span>
|
||||
<span class="tabular-nums text-slate-600 dark:text-slate-300">
|
||||
单量 {{ selectedRow.orderCount.toLocaleString('zh-CN') }}
|
||||
</span>
|
||||
<span class="tabular-nums text-slate-500">
|
||||
退款 ¥{{ formatWan(selectedRow.refundAmount) }}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
class="ml-auto text-xs text-indigo-600 hover:underline dark:text-indigo-300"
|
||||
@click="selectedProvince = null"
|
||||
<template v-else>
|
||||
<div class="grid grid-cols-2 gap-3 md:grid-cols-4">
|
||||
<div :class="[FINANCE_KPI_CARD_SHELL]">
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<span class="text-xs font-medium text-slate-500">全国净销售额</span>
|
||||
<span
|
||||
class="flex size-8 items-center justify-center rounded-lg bg-blue-50 text-blue-500 dark:bg-blue-950/40 dark:text-blue-300"
|
||||
>
|
||||
<CoinsIcon class="size-4" />
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="mt-3 text-[22px] font-bold tabular-nums tracking-tight text-slate-800 dark:text-slate-100"
|
||||
>
|
||||
¥{{ formatWan(kpis.totalAmount) }}
|
||||
</div>
|
||||
</div>
|
||||
<div :class="[FINANCE_KPI_CARD_SHELL]">
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<span class="text-xs font-medium text-slate-500">全国净销量</span>
|
||||
<span
|
||||
class="flex size-8 items-center justify-center rounded-lg bg-emerald-50 text-emerald-500 dark:bg-emerald-950/40 dark:text-emerald-300"
|
||||
>
|
||||
<PackageIcon class="size-4" />
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="mt-3 text-[22px] font-bold tabular-nums tracking-tight text-slate-800 dark:text-slate-100"
|
||||
>
|
||||
{{ kpis.totalQty.toLocaleString('zh-CN') }}
|
||||
</div>
|
||||
</div>
|
||||
<div :class="[FINANCE_KPI_CARD_SHELL]">
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<span class="text-xs font-medium text-slate-500">覆盖省份</span>
|
||||
<span
|
||||
class="flex size-8 items-center justify-center rounded-lg bg-violet-50 text-violet-500 dark:bg-violet-950/40 dark:text-violet-300"
|
||||
>
|
||||
<MapPinIcon class="size-4" />
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="mt-3 text-[22px] font-bold tabular-nums tracking-tight text-slate-800 dark:text-slate-100"
|
||||
>
|
||||
{{ kpis.covered }}
|
||||
<span class="text-sm font-normal text-slate-400">/ {{ rows.length }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div :class="[FINANCE_KPI_CARD_SHELL]">
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<span class="text-xs font-medium text-slate-500">TOP1 占比</span>
|
||||
<span
|
||||
class="flex size-8 items-center justify-center rounded-lg bg-amber-50 text-amber-500 dark:bg-amber-950/40 dark:text-amber-300"
|
||||
>
|
||||
<PercentIcon class="size-4" />
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="mt-3 text-[22px] font-bold tabular-nums tracking-tight text-slate-800 dark:text-slate-100"
|
||||
>
|
||||
{{ kpis.topShare.toFixed(1) }}%
|
||||
</div>
|
||||
<div class="mt-1 truncate text-xs text-slate-500">{{ kpis.topName }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="selectedRow"
|
||||
class="flex flex-wrap items-center gap-x-4 gap-y-1 rounded-xl border border-indigo-200/80 bg-indigo-50/60 px-4 py-2.5 text-sm dark:border-indigo-500/30 dark:bg-indigo-950/30"
|
||||
>
|
||||
清除选中
|
||||
</button>
|
||||
</div>
|
||||
<span class="font-semibold text-indigo-700 dark:text-indigo-200">
|
||||
{{ selectedRow.provinceName }}
|
||||
</span>
|
||||
<span class="tabular-nums text-slate-700 dark:text-slate-200">
|
||||
净销售额 ¥{{ formatWan(selectedRow.salesAmount) }}
|
||||
</span>
|
||||
<span class="tabular-nums text-slate-600 dark:text-slate-300">
|
||||
净销量 {{ selectedRow.salesQty.toLocaleString('zh-CN') }}
|
||||
</span>
|
||||
<span class="tabular-nums text-slate-600 dark:text-slate-300">
|
||||
单量 {{ selectedRow.orderCount.toLocaleString('zh-CN') }}
|
||||
</span>
|
||||
<span class="tabular-nums text-slate-500">
|
||||
退款 ¥{{ formatWan(selectedRow.refundAmount) }}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
class="ml-auto text-xs text-indigo-600 hover:underline dark:text-indigo-300"
|
||||
@click="selectedProvince = null"
|
||||
>
|
||||
清除选中
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 gap-3 xl:grid-cols-5">
|
||||
<div class="xl:col-span-3">
|
||||
<RegionSalesMapChart
|
||||
ref="mapRef"
|
||||
:rows="rows"
|
||||
:metric="metric"
|
||||
:selected-province="selectedProvince"
|
||||
@select="onSelectProvince"
|
||||
/>
|
||||
<div class="grid grid-cols-1 gap-3 xl:grid-cols-5">
|
||||
<div class="xl:col-span-3">
|
||||
<RegionSalesMapChart
|
||||
ref="mapRef"
|
||||
:rows="rows"
|
||||
:metric="metric"
|
||||
:selected-province="selectedProvince"
|
||||
@select="onSelectProvince"
|
||||
/>
|
||||
</div>
|
||||
<div class="xl:col-span-2">
|
||||
<RegionSalesRankList
|
||||
:rows="rows"
|
||||
:metric="metric"
|
||||
:selected-province="selectedProvince"
|
||||
@select="onSelectProvince"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="xl:col-span-2">
|
||||
<RegionSalesRankList
|
||||
:rows="rows"
|
||||
:metric="metric"
|
||||
:selected-province="selectedProvince"
|
||||
@select="onSelectProvince"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
import type { RegionSalesPanel, RegionSalesRow } from './types';
|
||||
|
||||
/** 与 DataV 省级 geoJSON 名称对齐的省份清单(演示用) */
|
||||
const PROVINCES: Array<{ code: string; name: string; weight: number }> = [
|
||||
{ code: '110000', name: '北京市', weight: 1.15 },
|
||||
{ code: '120000', name: '天津市', weight: 0.55 },
|
||||
{ code: '130000', name: '河北省', weight: 0.85 },
|
||||
{ code: '140000', name: '山西省', weight: 0.45 },
|
||||
{ code: '150000', name: '内蒙古自治区', weight: 0.35 },
|
||||
{ code: '210000', name: '辽宁省', weight: 0.7 },
|
||||
{ code: '220000', name: '吉林省', weight: 0.4 },
|
||||
{ code: '230000', name: '黑龙江省', weight: 0.42 },
|
||||
{ code: '310000', name: '上海市', weight: 1.25 },
|
||||
{ code: '320000', name: '江苏省', weight: 1.35 },
|
||||
{ code: '330000', name: '浙江省', weight: 1.4 },
|
||||
{ code: '340000', name: '安徽省', weight: 0.75 },
|
||||
{ code: '350000', name: '福建省', weight: 0.8 },
|
||||
{ code: '360000', name: '江西省', weight: 0.55 },
|
||||
{ code: '370000', name: '山东省', weight: 1.2 },
|
||||
{ code: '410000', name: '河南省', weight: 0.95 },
|
||||
{ code: '420000', name: '湖北省', weight: 0.85 },
|
||||
{ code: '430000', name: '湖南省', weight: 0.8 },
|
||||
{ code: '440000', name: '广东省', weight: 1.55 },
|
||||
{ code: '450000', name: '广西壮族自治区', weight: 0.5 },
|
||||
{ code: '460000', name: '海南省', weight: 0.28 },
|
||||
{ code: '500000', name: '重庆市', weight: 0.7 },
|
||||
{ code: '510000', name: '四川省', weight: 0.95 },
|
||||
{ code: '520000', name: '贵州省', weight: 0.4 },
|
||||
{ code: '530000', name: '云南省', weight: 0.48 },
|
||||
{ code: '540000', name: '西藏自治区', weight: 0.08 },
|
||||
{ code: '610000', name: '陕西省', weight: 0.65 },
|
||||
{ code: '620000', name: '甘肃省', weight: 0.28 },
|
||||
{ code: '630000', name: '青海省', weight: 0.12 },
|
||||
{ code: '640000', name: '宁夏回族自治区', weight: 0.15 },
|
||||
{ code: '650000', name: '新疆维吾尔自治区', weight: 0.32 },
|
||||
];
|
||||
|
||||
function hashSeed(input: string): number {
|
||||
let h = 2166136261;
|
||||
for (let i = 0; i < input.length; i += 1) {
|
||||
h ^= input.charCodeAt(i);
|
||||
h = Math.imul(h, 16777619);
|
||||
}
|
||||
return h >>> 0;
|
||||
}
|
||||
|
||||
function mulberry32(seed: number) {
|
||||
let t = seed;
|
||||
return () => {
|
||||
t += 0x6d2b79f5;
|
||||
let r = Math.imul(t ^ (t >>> 15), 1 | t);
|
||||
r ^= r + Math.imul(r ^ (r >>> 7), 61 | r);
|
||||
return ((r ^ (r >>> 14)) >>> 0) / 4294967296;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成演示用省级净销售分布(稳定可复现)。
|
||||
* @param rangeKey 可用日期区间字符串作种子,切换筛选时分布略变
|
||||
*/
|
||||
export function buildMockRegionSalesPanel(rangeKey = 'default'): RegionSalesPanel {
|
||||
const rand = mulberry32(hashSeed(`region-sales:${rangeKey}`));
|
||||
const rows: RegionSalesRow[] = PROVINCES.map((p) => {
|
||||
const jitter = 0.65 + rand() * 0.7;
|
||||
const base = 180_000 * p.weight * jitter;
|
||||
const salesAmount = Math.round(base);
|
||||
const avgPrice = 68 + rand() * 90;
|
||||
const salesQty = Math.max(1, Math.round(salesAmount / avgPrice));
|
||||
const orderCount = Math.max(1, Math.round(salesQty / (1.4 + rand() * 1.2)));
|
||||
const refundAmount = Math.round(salesAmount * (0.04 + rand() * 0.1));
|
||||
return {
|
||||
provinceName: p.name,
|
||||
provinceCode: p.code,
|
||||
salesAmount,
|
||||
salesQty,
|
||||
orderCount,
|
||||
refundAmount,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
rows,
|
||||
mock: true,
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/** 区域销量 Tab:省份地理维(口径草案,后端就绪后对齐) */
|
||||
/** 区域销量 Tab:省份地理维 */
|
||||
|
||||
/** 地图着色主指标 */
|
||||
export type RegionMetricKey = 'salesAmount' | 'salesQty' | 'orderCount';
|
||||
@@ -15,12 +15,11 @@ export const REGION_METRIC_OPTIONS: Array<{
|
||||
|
||||
/**
|
||||
* 单省汇总。
|
||||
* 口径建议:收货地址省份;净销售=成交−退款(与经营概览「净销售额/净销量」同口径)。
|
||||
* 口径:收货地址省份;净销售 = 成交 − 退款(与经营概览同口径)。
|
||||
*/
|
||||
export interface RegionSalesRow {
|
||||
/** 与地图 geoJSON properties.name 对齐,如「广东省」 */
|
||||
provinceName: string;
|
||||
provinceCode: string;
|
||||
/** 净销售额(元) */
|
||||
salesAmount: number;
|
||||
/** 净销量(件) */
|
||||
@@ -33,7 +32,4 @@ export interface RegionSalesRow {
|
||||
|
||||
export interface RegionSalesPanel {
|
||||
rows: RegionSalesRow[];
|
||||
/** 演示数据标记 */
|
||||
mock: boolean;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
@@ -135,6 +135,16 @@ const [CreateFullModal, createFullModalApi] = useVbenModal({
|
||||
onConfirm: () => handleCreateTask(),
|
||||
});
|
||||
|
||||
/**
|
||||
* 日期面板挂 body(同商品列表操作列下拉),避免被模态 overflow 裁切;
|
||||
* zIndex 须高于本模态 2100,否则仍会被挡住。
|
||||
*/
|
||||
function getDatePickerPopupContainer() {
|
||||
return document.body;
|
||||
}
|
||||
|
||||
const datePickerPopupStyle = { zIndex: 2300 };
|
||||
|
||||
let pollTimer: null | ReturnType<typeof setInterval> = null;
|
||||
let unsubProgress: (() => void) | null = null;
|
||||
const terminalNotifiedTaskIds = new Set<number>();
|
||||
@@ -1254,6 +1264,8 @@ defineExpose({ open, close: handleClose });
|
||||
:allow-clear="false"
|
||||
:disabled-date="disabledFullSyncDate"
|
||||
format="YYYY-MM-DD"
|
||||
:get-popup-container="getDatePickerPopupContainer"
|
||||
:popup-style="datePickerPopupStyle"
|
||||
/>
|
||||
<Button @click="setCreateRangeToToday">今天</Button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user