mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 07:09:20 +08:00
refactor: 重构bi统计改规格统计成sku统计
This commit is contained in:
@@ -261,8 +261,8 @@ RoutingKey:
|
|||||||
"productDeltas": [
|
"productDeltas": [
|
||||||
{ "productId": 1, "categoryId": 2, "metrics": { "salesAmount": 12.3 } }
|
{ "productId": 1, "categoryId": 2, "metrics": { "salesAmount": 12.3 } }
|
||||||
],
|
],
|
||||||
"specDeltas": [
|
"skuDeltas": [
|
||||||
{ "productId": 1, "productSpecId": 9, "metrics": { "salesAmount": 12.3 } }
|
{ "productId": 1, "productSkuId": 9, "metrics": { "salesAmount": 12.3 } }
|
||||||
],
|
],
|
||||||
"occurredAt": "2026-07-28T16:01:30+08:00"
|
"occurredAt": "2026-07-28T16:01:30+08:00"
|
||||||
}
|
}
|
||||||
@@ -272,7 +272,7 @@ RoutingKey:
|
|||||||
|------|------|
|
|------|------|
|
||||||
| `statDate` | 受影响自然日 = `DATE(ec_order.order_time)`(Asia/Shanghai) |
|
| `statDate` | 受影响自然日 = `DATE(ec_order.order_time)`(Asia/Shanghai) |
|
||||||
| `internalOrderUpdateTime` | 转换完成时内部订单更新时间(与文档/会话 `dbSnapshotTime` 比较) |
|
| `internalOrderUpdateTime` | 转换完成时内部订单更新时间(与文档/会话 `dbSnapshotTime` 比较) |
|
||||||
| `shopDelta` / `productDeltas` / `specDeltas` | 转换侧算出的各聚合字段加减量(可正可负) |
|
| `shopDelta` / `productDeltas` / `skuDeltas` | 转换侧算出的各聚合字段加减量(可正可负) |
|
||||||
| `orderId` / `channelOrderId` | 排查用 |
|
| `orderId` / `channelOrderId` | 排查用 |
|
||||||
|
|
||||||
一笔增量订单按受影响 `statDate` 各发一条;跨日改单会发多条。BI 侧只做跳过判断与 `$inc` 累加,不再按日重算。
|
一笔增量订单按受影响 `statDate` 各发一条;跨日改单会发多条。BI 侧只做跳过判断与 `$inc` 累加,不再按日重算。
|
||||||
@@ -335,22 +335,22 @@ RoutingKey:
|
|||||||
|
|
||||||
### 6.1 集合与维度
|
### 6.1 集合与维度
|
||||||
|
|
||||||
仅日维度,三张集合(对齐旧 `ec_order_stat_daily_shop` / `_product` / `_spec`,**无**月/年):
|
仅日维度,三张集合(对齐旧 `ec_order_stat_daily_shop` / `_product` / `_spec`,**无**月/年;Mongo 侧第三维已改为 SKU):
|
||||||
|
|
||||||
| 集合名 | 唯一键 |
|
| 集合名 | 唯一键 |
|
||||||
|--------|--------|
|
|--------|--------|
|
||||||
| `bi_order_stat_daily_shop` | `(companyId, shopId, statDate)` |
|
| `bi_order_stat_daily_shop` | `(companyId, shopId, statDate)` |
|
||||||
| `bi_order_stat_daily_product` | `(companyId, shopId, productId, categoryId, statDate)` |
|
| `bi_order_stat_daily_product` | `(companyId, shopId, productId, categoryId, statDate)` |
|
||||||
| `bi_order_stat_daily_spec` | `(companyId, shopId, productSpecId, statDate)` |
|
| `bi_order_stat_daily_sku` | `(companyId, shopId, productSkuId, statDate)` |
|
||||||
|
|
||||||
`productId=0` 表示未匹配商品;`categoryId=0` 表示未分类;`productSpecId=0` 表示未绑定规格。
|
`productId=0` 表示未匹配商品;`categoryId=0` 表示未分类;`productSkuId=0` 表示未绑定 SKU。
|
||||||
`categoryId` 为订单写入时快照,商品改类目不回算历史(与旧设计一致)。
|
`categoryId` 为订单写入时快照,商品改类目不回算历史(与旧设计一致)。
|
||||||
|
|
||||||
建议索引:
|
建议索引:
|
||||||
|
|
||||||
- shop:`{ companyId: 1, shopId: 1, statDate: 1 }` unique;`{ companyId: 1, statDate: 1 }`;`{ companyId: 1, platformCode: 1, statDate: 1 }`
|
- shop:`{ companyId: 1, shopId: 1, statDate: 1 }` unique;`{ companyId: 1, statDate: 1 }`;`{ companyId: 1, platformCode: 1, statDate: 1 }`
|
||||||
- product:unique 复合键如上;`{ companyId: 1, categoryId: 1, statDate: 1 }`;`{ companyId: 1, productId: 1, statDate: 1 }`
|
- product:unique 复合键如上;`{ companyId: 1, categoryId: 1, statDate: 1 }`;`{ companyId: 1, productId: 1, statDate: 1 }`
|
||||||
- spec:unique 复合键如上;`{ companyId: 1, productId: 1, statDate: 1 }`
|
- sku:unique 复合键如上;`{ companyId: 1, productId: 1, statDate: 1 }`
|
||||||
|
|
||||||
`spring.data.mongodb.auto-index-creation=false`,索引由迁移脚本或启动显式创建。
|
`spring.data.mongodb.auto-index-creation=false`,索引由迁移脚本或启动显式创建。
|
||||||
|
|
||||||
@@ -401,9 +401,9 @@ RoutingKey:
|
|||||||
|
|
||||||
`productId`, `categoryId`(其余指标字段同上)。
|
`productId`, `categoryId`(其余指标字段同上)。
|
||||||
|
|
||||||
#### 规格日文档额外键
|
#### SKU 日文档额外键
|
||||||
|
|
||||||
`productId`, `productSpecId`(其余指标字段同上)。
|
`productId`, `productSkuId`(其余指标字段同上)。
|
||||||
|
|
||||||
#### 元数据字段(本管线新增)
|
#### 元数据字段(本管线新增)
|
||||||
|
|
||||||
@@ -423,7 +423,7 @@ RoutingKey:
|
|||||||
1. 获取 Redis 计算锁:`bi:stat:lock:{companyId}:{shopId}:{statDate}`(TTL 需覆盖最坏重算时间)
|
1. 获取 Redis 计算锁:`bi:stat:lock:{companyId}:{shopId}:{statDate}`(TTL 需覆盖最坏重算时间)
|
||||||
2. MySQL:`START TRANSACTION WITH CONSISTENT SNAPSHOT`(或等价一致读),记录 **`dbSnapshotTime = now(会话开启时刻)`**
|
2. MySQL:`START TRANSACTION WITH CONSISTENT SNAPSHOT`(或等价一致读),记录 **`dbSnapshotTime = now(会话开启时刻)`**
|
||||||
3. 在快照内按 `order_time` 落在该自然日、限定 `shop_id`,读取 `ec_order` / `ec_order_item`,用 `OrderStatusStatSets` 口径聚合三维
|
3. 在快照内按 `order_time` 落在该自然日、限定 `shop_id`,读取 `ec_order` / `ec_order_item`,用 `OrderStatusStatSets` 口径聚合三维
|
||||||
4. **覆盖写** Mongo 三集合该日该店相关文档(先删该店该日旧 product/spec 再插入,或 bulk upsert;shop 单文档 replace)
|
4. **覆盖写** Mongo 三集合该日该店相关文档(先删该店该日旧 product/sku 再插入,或 bulk upsert;shop 单文档 replace)
|
||||||
5. 所有文档写入相同的 `dbSnapshotTime`、`computeMode=FULL`
|
5. 所有文档写入相同的 `dbSnapshotTime`、`computeMode=FULL`
|
||||||
6. 提交/结束快照事务,释放锁
|
6. 提交/结束快照事务,释放锁
|
||||||
|
|
||||||
@@ -439,7 +439,7 @@ RoutingKey:
|
|||||||
| 存在进行中的全量锁,且已暴露会话 `snapshotTime`,`internalOrderUpdateTime <= snapshotTime` | **ack 跳过** |
|
| 存在进行中的全量锁,且已暴露会话 `snapshotTime`,`internalOrderUpdateTime <= snapshotTime` | **ack 跳过** |
|
||||||
| 存在进行中的全量锁,且 `internalOrderUpdateTime > snapshotTime` | **延后重试**,等全量写完后再比文档 `dbSnapshotTime` |
|
| 存在进行中的全量锁,且 `internalOrderUpdateTime > snapshotTime` | **延后重试**,等全量写完后再比文档 `dbSnapshotTime` |
|
||||||
| 无进行中全量;文档存在且 `internalOrderUpdateTime <= dbSnapshotTime` | **ack 跳过** |
|
| 无进行中全量;文档存在且 `internalOrderUpdateTime <= dbSnapshotTime` | **ack 跳过** |
|
||||||
| 无进行中全量;文档不存在,或 `internalOrderUpdateTime > dbSnapshotTime` | 对 shop/product/spec **`$inc` 累加消息 delta**,`computeMode=INC`,**不更新** `dbSnapshotTime`(无文档时新建,`dbSnapshotTime` 为空,仅全量填充) |
|
| 无进行中全量;文档不存在,或 `internalOrderUpdateTime > dbSnapshotTime` | 对 shop/product/sku **`$inc` 累加消息 delta**,`computeMode=INC`,**不更新** `dbSnapshotTime`(无文档时新建,`dbSnapshotTime` 为空,仅全量填充) |
|
||||||
|
|
||||||
说明:
|
说明:
|
||||||
|
|
||||||
@@ -603,7 +603,7 @@ ecom:
|
|||||||
| 文档路径 | `docs/订单同步转换与BI日汇聚设计.md` |
|
| 文档路径 | `docs/订单同步转换与BI日汇聚设计.md` |
|
||||||
| BI 包结构 | 写侧子域划分 + 域内分层;禁止 `modules/bi` 根目录平铺 |
|
| BI 包结构 | 写侧子域划分 + 域内分层;禁止 `modules/bi` 根目录平铺 |
|
||||||
| 分析查看接口 | 日后迁 `bi`;**本文不预设目录名**;现仍留 `ec` |
|
| 分析查看接口 | 日后迁 `bi`;**本文不预设目录名**;现仍留 `ec` |
|
||||||
| 日维度 | shop + product + spec;无月/年;无推广费/刷单 |
|
| 日维度 | shop + product + sku;无月/年;无推广费/刷单 |
|
||||||
| 转换队列 | 全量日与增量**共用**(按平台分队列) |
|
| 转换队列 | 全量日与增量**共用**(按平台分队列) |
|
||||||
| BI 队列 | 全量 / 增量**分两个队列** |
|
| BI 队列 | 全量 / 增量**分两个队列** |
|
||||||
| 全量计算 | MySQL consistent snapshot + 按日重算覆盖写 Mongo,写入 `dbSnapshotTime` |
|
| 全量计算 | MySQL consistent snapshot + 按日重算覆盖写 Mongo,写入 `dbSnapshotTime` |
|
||||||
|
|||||||
+1
-1
@@ -32,7 +32,7 @@ public class BiIncCalcMessage {
|
|||||||
private Long channelOrderId;
|
private Long channelOrderId;
|
||||||
private BiStatMetricDelta shopDelta;
|
private BiStatMetricDelta shopDelta;
|
||||||
private List<BiProductStatDelta> productDeltas;
|
private List<BiProductStatDelta> productDeltas;
|
||||||
private List<BiSpecStatDelta> specDeltas;
|
private List<BiSkuStatDelta> skuDeltas;
|
||||||
private OffsetDateTime occurredAt;
|
private OffsetDateTime occurredAt;
|
||||||
private Integer retryCount;
|
private Integer retryCount;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -9,9 +9,10 @@ import lombok.NoArgsConstructor;
|
|||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class BiSpecStatDelta {
|
public class BiSkuStatDelta {
|
||||||
|
|
||||||
private Long productId;
|
private Long productId;
|
||||||
private Long productSpecId;
|
/** 内部 SKU 主键(ec_product_sku.id);未绑定为 0 */
|
||||||
|
private Long productSkuId;
|
||||||
private BiStatMetricDelta metrics;
|
private BiStatMetricDelta metrics;
|
||||||
}
|
}
|
||||||
+1
-1
@@ -83,7 +83,7 @@ public class BiStatIncConsumer {
|
|||||||
statDate,
|
statDate,
|
||||||
message.getShopDelta(),
|
message.getShopDelta(),
|
||||||
message.getProductDeltas(),
|
message.getProductDeltas(),
|
||||||
message.getSpecDeltas());
|
message.getSkuDeltas());
|
||||||
log.info("BI inc delta 已累加 shopId={} statDate={} orderId={}",
|
log.info("BI inc delta 已累加 shopId={} statDate={} orderId={}",
|
||||||
message.getShopId(), statDate, message.getOrderId());
|
message.getShopId(), statDate, message.getOrderId());
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
+6
-5
@@ -11,14 +11,14 @@ import java.time.Instant;
|
|||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Document(collection = "bi_order_stat_daily_spec")
|
@Document(collection = "bi_order_stat_daily_sku")
|
||||||
@CompoundIndexes({
|
@CompoundIndexes({
|
||||||
@CompoundIndex(
|
@CompoundIndex(
|
||||||
name = "uk_company_shop_spec_date",
|
name = "uk_company_shop_sku_date",
|
||||||
def = "{'companyId':1,'shopId':1,'productSpecId':1,'statDate':1}",
|
def = "{'companyId':1,'shopId':1,'productSkuId':1,'statDate':1}",
|
||||||
unique = true)
|
unique = true)
|
||||||
})
|
})
|
||||||
public class BiOrderStatDailySpecDoc {
|
public class BiOrderStatDailySkuDoc {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
private String id;
|
private String id;
|
||||||
@@ -26,7 +26,8 @@ public class BiOrderStatDailySpecDoc {
|
|||||||
private Long companyId;
|
private Long companyId;
|
||||||
private Long shopId;
|
private Long shopId;
|
||||||
private Long productId;
|
private Long productId;
|
||||||
private Long productSpecId;
|
/** 内部 SKU 主键;未绑定为 0 */
|
||||||
|
private Long productSkuId;
|
||||||
private LocalDate statDate;
|
private LocalDate statDate;
|
||||||
|
|
||||||
private BigDecimal salesAmount = BigDecimal.ZERO;
|
private BigDecimal salesAmount = BigDecimal.ZERO;
|
||||||
+17
-17
@@ -8,11 +8,11 @@ import org.springframework.data.mongodb.core.query.Query;
|
|||||||
import org.springframework.data.mongodb.core.query.Update;
|
import org.springframework.data.mongodb.core.query.Update;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiProductStatDelta;
|
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiProductStatDelta;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiSpecStatDelta;
|
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiSkuStatDelta;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiStatMetricDelta;
|
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.BiOrderStatDailyProductDoc;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyShopDoc;
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyShopDoc;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailySpecDoc;
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailySkuDoc;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
@@ -35,7 +35,7 @@ public class BiOrderStatDailyRepository {
|
|||||||
|
|
||||||
public void replaceShopDay(BiOrderStatDailyShopDoc shopDoc,
|
public void replaceShopDay(BiOrderStatDailyShopDoc shopDoc,
|
||||||
List<BiOrderStatDailyProductDoc> products,
|
List<BiOrderStatDailyProductDoc> products,
|
||||||
List<BiOrderStatDailySpecDoc> specs) {
|
List<BiOrderStatDailySkuDoc> skus) {
|
||||||
Long companyId = shopDoc.getCompanyId();
|
Long companyId = shopDoc.getCompanyId();
|
||||||
Long shopId = shopDoc.getShopId();
|
Long shopId = shopDoc.getShopId();
|
||||||
LocalDate statDate = shopDoc.getStatDate();
|
LocalDate statDate = shopDoc.getStatDate();
|
||||||
@@ -53,12 +53,12 @@ public class BiOrderStatDailyRepository {
|
|||||||
}, () -> mongoTemplate.insert(shopDoc));
|
}, () -> mongoTemplate.insert(shopDoc));
|
||||||
|
|
||||||
mongoTemplate.remove(dayQ, BiOrderStatDailyProductDoc.class);
|
mongoTemplate.remove(dayQ, BiOrderStatDailyProductDoc.class);
|
||||||
mongoTemplate.remove(dayQ, BiOrderStatDailySpecDoc.class);
|
mongoTemplate.remove(dayQ, BiOrderStatDailySkuDoc.class);
|
||||||
if (products != null && !products.isEmpty()) {
|
if (products != null && !products.isEmpty()) {
|
||||||
mongoTemplate.insertAll(products);
|
mongoTemplate.insertAll(products);
|
||||||
}
|
}
|
||||||
if (specs != null && !specs.isEmpty()) {
|
if (skus != null && !skus.isEmpty()) {
|
||||||
mongoTemplate.insertAll(specs);
|
mongoTemplate.insertAll(skus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ public class BiOrderStatDailyRepository {
|
|||||||
public void applyIncDeltas(Long companyId, Long shopId, String platformCode, LocalDate statDate,
|
public void applyIncDeltas(Long companyId, Long shopId, String platformCode, LocalDate statDate,
|
||||||
BiStatMetricDelta shopDelta,
|
BiStatMetricDelta shopDelta,
|
||||||
List<BiProductStatDelta> productDeltas,
|
List<BiProductStatDelta> productDeltas,
|
||||||
List<BiSpecStatDelta> specDeltas) {
|
List<BiSkuStatDelta> skuDeltas) {
|
||||||
Instant now = Instant.now();
|
Instant now = Instant.now();
|
||||||
Optional<BiOrderStatDailyShopDoc> existing = findShop(companyId, shopId, statDate);
|
Optional<BiOrderStatDailyShopDoc> existing = findShop(companyId, shopId, statDate);
|
||||||
if (existing.isEmpty()) {
|
if (existing.isEmpty()) {
|
||||||
@@ -122,33 +122,33 @@ public class BiOrderStatDailyRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (specDeltas != null) {
|
if (skuDeltas != null) {
|
||||||
for (BiSpecStatDelta sd : specDeltas) {
|
for (BiSkuStatDelta sd : skuDeltas) {
|
||||||
if (sd.getMetrics() == null || sd.getMetrics().isAllZero()) {
|
if (sd.getMetrics() == null || sd.getMetrics().isAllZero()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
long productId = sd.getProductId() != null ? sd.getProductId() : 0L;
|
long productId = sd.getProductId() != null ? sd.getProductId() : 0L;
|
||||||
long specId = sd.getProductSpecId() != null ? sd.getProductSpecId() : 0L;
|
long skuId = sd.getProductSkuId() != null ? sd.getProductSkuId() : 0L;
|
||||||
Query sq = Query.query(Criteria.where("companyId").is(companyId)
|
Query sq = Query.query(Criteria.where("companyId").is(companyId)
|
||||||
.and("shopId").is(shopId)
|
.and("shopId").is(shopId)
|
||||||
.and("productSpecId").is(specId)
|
.and("productSkuId").is(skuId)
|
||||||
.and("statDate").is(statDate));
|
.and("statDate").is(statDate));
|
||||||
BiOrderStatDailySpecDoc found = mongoTemplate.findOne(sq, BiOrderStatDailySpecDoc.class);
|
BiOrderStatDailySkuDoc found = mongoTemplate.findOne(sq, BiOrderStatDailySkuDoc.class);
|
||||||
if (found == null) {
|
if (found == null) {
|
||||||
BiOrderStatDailySpecDoc doc = new BiOrderStatDailySpecDoc();
|
BiOrderStatDailySkuDoc doc = new BiOrderStatDailySkuDoc();
|
||||||
doc.setCompanyId(companyId);
|
doc.setCompanyId(companyId);
|
||||||
doc.setShopId(shopId);
|
doc.setShopId(shopId);
|
||||||
doc.setProductId(productId);
|
doc.setProductId(productId);
|
||||||
doc.setProductSpecId(specId);
|
doc.setProductSkuId(skuId);
|
||||||
doc.setStatDate(statDate);
|
doc.setStatDate(statDate);
|
||||||
applyMetricToSpec(doc, sd.getMetrics());
|
applyMetricToSku(doc, sd.getMetrics());
|
||||||
doc.setComputeMode("INC");
|
doc.setComputeMode("INC");
|
||||||
doc.setComputedAt(now);
|
doc.setComputedAt(now);
|
||||||
mongoTemplate.insert(doc);
|
mongoTemplate.insert(doc);
|
||||||
} else {
|
} else {
|
||||||
Update u = metricIncUpdate(sd.getMetrics());
|
Update u = metricIncUpdate(sd.getMetrics());
|
||||||
u.set("computedAt", now).set("computeMode", "INC");
|
u.set("computedAt", now).set("computeMode", "INC");
|
||||||
mongoTemplate.updateFirst(sq, u, BiOrderStatDailySpecDoc.class);
|
mongoTemplate.updateFirst(sq, u, BiOrderStatDailySkuDoc.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,7 +221,7 @@ public class BiOrderStatDailyRepository {
|
|||||||
doc.setOtherCost(nz(d.getOtherCost()));
|
doc.setOtherCost(nz(d.getOtherCost()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void applyMetricToSpec(BiOrderStatDailySpecDoc doc, BiStatMetricDelta d) {
|
private static void applyMetricToSku(BiOrderStatDailySkuDoc doc, BiStatMetricDelta d) {
|
||||||
if (d == null) {
|
if (d == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-23
@@ -9,7 +9,7 @@ import org.springframework.transaction.support.TransactionTemplate;
|
|||||||
import top.xyquan.ecomdmbbackend.modules.bi.infra.lock.BiStatComputeLock;
|
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.BiOrderStatDailyProductDoc;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyShopDoc;
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyShopDoc;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailySpecDoc;
|
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.repository.BiOrderStatDailyRepository;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.order.mapper.OrderItemMapper;
|
import top.xyquan.ecomdmbbackend.modules.ec.order.mapper.OrderItemMapper;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.order.mapper.OrderMapper;
|
import top.xyquan.ecomdmbbackend.modules.ec.order.mapper.OrderMapper;
|
||||||
@@ -145,9 +145,9 @@ public class OrderDailyStatComputeService {
|
|||||||
|
|
||||||
Metric shop = new Metric();
|
Metric shop = new Metric();
|
||||||
Map<String, Metric> productMap = new HashMap<>();
|
Map<String, Metric> productMap = new HashMap<>();
|
||||||
Map<String, Metric> specMap = new HashMap<>();
|
Map<String, Metric> skuMap = new HashMap<>();
|
||||||
Map<String, DimKey> productKeys = new HashMap<>();
|
Map<String, DimKey> productKeys = new HashMap<>();
|
||||||
Map<String, DimKey> specKeys = new HashMap<>();
|
Map<String, DimKey> skuKeys = new HashMap<>();
|
||||||
|
|
||||||
for (OrderPO order : orders) {
|
for (OrderPO order : orders) {
|
||||||
List<OrderItemPO> items = itemsByOrder.getOrDefault(order.getId(), List.of());
|
List<OrderItemPO> items = itemsByOrder.getOrDefault(order.getId(), List.of());
|
||||||
@@ -173,8 +173,8 @@ public class OrderDailyStatComputeService {
|
|||||||
|
|
||||||
Set<String> countedProductSales = new HashSet<>();
|
Set<String> countedProductSales = new HashSet<>();
|
||||||
Set<String> countedProductGmv = new HashSet<>();
|
Set<String> countedProductGmv = new HashSet<>();
|
||||||
Set<String> countedSpecSales = new HashSet<>();
|
Set<String> countedSkuSales = new HashSet<>();
|
||||||
Set<String> countedSpecGmv = new HashSet<>();
|
Set<String> countedSkuGmv = new HashSet<>();
|
||||||
|
|
||||||
if (items.isEmpty()) {
|
if (items.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
@@ -182,7 +182,7 @@ public class OrderDailyStatComputeService {
|
|||||||
for (OrderItemPO item : items) {
|
for (OrderItemPO item : items) {
|
||||||
long productId = item.getProductId() != null ? item.getProductId() : 0L;
|
long productId = item.getProductId() != null ? item.getProductId() : 0L;
|
||||||
long categoryId = categoryByProduct.getOrDefault(productId, 0L);
|
long categoryId = categoryByProduct.getOrDefault(productId, 0L);
|
||||||
long specId = item.getProductSkuId() != null ? item.getProductSkuId() : 0L;
|
long skuId = item.getProductSkuId() != null ? item.getProductSkuId() : 0L;
|
||||||
int qty = OrderStatusStatSets.quantity(item);
|
int qty = OrderStatusStatSets.quantity(item);
|
||||||
BigDecimal linePay = allocateLine(pay, item, items);
|
BigDecimal linePay = allocateLine(pay, item, items);
|
||||||
|
|
||||||
@@ -208,18 +208,18 @@ public class OrderDailyStatComputeService {
|
|||||||
pm.freightCost = pm.freightCost.add(stat.freightCostForStats(order, item));
|
pm.freightCost = pm.freightCost.add(stat.freightCostForStats(order, item));
|
||||||
pm.otherCost = pm.otherCost.add(stat.otherCostForStats(order, item));
|
pm.otherCost = pm.otherCost.add(stat.otherCostForStats(order, item));
|
||||||
|
|
||||||
String sk = companyId + ":" + shopId + ":" + specId;
|
String sk = companyId + ":" + shopId + ":" + skuId;
|
||||||
Metric sm = specMap.computeIfAbsent(sk, k -> new Metric());
|
Metric sm = skuMap.computeIfAbsent(sk, k -> new Metric());
|
||||||
specKeys.putIfAbsent(sk, new DimKey(productId, 0L, specId));
|
skuKeys.putIfAbsent(sk, new DimKey(productId, 0L, skuId));
|
||||||
sm.gmvAmount = sm.gmvAmount.add(linePay);
|
sm.gmvAmount = sm.gmvAmount.add(linePay);
|
||||||
sm.gmvQuantitySum += qty;
|
sm.gmvQuantitySum += qty;
|
||||||
if (countedSpecGmv.add(sk)) {
|
if (countedSkuGmv.add(sk)) {
|
||||||
sm.gmvOrderCount++;
|
sm.gmvOrderCount++;
|
||||||
}
|
}
|
||||||
if (sales) {
|
if (sales) {
|
||||||
sm.salesAmount = sm.salesAmount.add(linePay);
|
sm.salesAmount = sm.salesAmount.add(linePay);
|
||||||
sm.salesQuantitySum += qty;
|
sm.salesQuantitySum += qty;
|
||||||
if (countedSpecSales.add(sk)) {
|
if (countedSkuSales.add(sk)) {
|
||||||
sm.salesOrderCount++;
|
sm.salesOrderCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -241,7 +241,7 @@ public class OrderDailyStatComputeService {
|
|||||||
platform = orders.get(0).getPlatformCode();
|
platform = orders.get(0).getPlatformCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DayAgg(companyId, shopId, statDate, platform, shop, productMap, productKeys, specMap, specKeys);
|
return new DayAgg(companyId, shopId, statDate, platform, shop, productMap, productKeys, skuMap, skuKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void persist(DayAgg agg, Instant snapshotTime, String mode) {
|
private void persist(DayAgg agg, Instant snapshotTime, String mode) {
|
||||||
@@ -272,23 +272,23 @@ public class OrderDailyStatComputeService {
|
|||||||
products.add(doc);
|
products.add(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BiOrderStatDailySpecDoc> specs = new ArrayList<>();
|
List<BiOrderStatDailySkuDoc> skus = new ArrayList<>();
|
||||||
for (Map.Entry<String, Metric> e : agg.specMap().entrySet()) {
|
for (Map.Entry<String, Metric> e : agg.skuMap().entrySet()) {
|
||||||
DimKey key = agg.specKeys().get(e.getKey());
|
DimKey key = agg.skuKeys().get(e.getKey());
|
||||||
BiOrderStatDailySpecDoc doc = new BiOrderStatDailySpecDoc();
|
BiOrderStatDailySkuDoc doc = new BiOrderStatDailySkuDoc();
|
||||||
doc.setCompanyId(agg.companyId());
|
doc.setCompanyId(agg.companyId());
|
||||||
doc.setShopId(agg.shopId());
|
doc.setShopId(agg.shopId());
|
||||||
doc.setProductId(key.productId());
|
doc.setProductId(key.productId());
|
||||||
doc.setProductSpecId(key.specId());
|
doc.setProductSkuId(key.skuId());
|
||||||
doc.setStatDate(agg.statDate());
|
doc.setStatDate(agg.statDate());
|
||||||
applyMetric(doc, e.getValue());
|
applyMetric(doc, e.getValue());
|
||||||
doc.setDbSnapshotTime(snapshotTime);
|
doc.setDbSnapshotTime(snapshotTime);
|
||||||
doc.setComputedAt(now);
|
doc.setComputedAt(now);
|
||||||
doc.setComputeMode(mode);
|
doc.setComputeMode(mode);
|
||||||
specs.add(doc);
|
skus.add(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
repository.replaceShopDay(shopDoc, products, specs);
|
repository.replaceShopDay(shopDoc, products, skus);
|
||||||
log.info("BI 日汇聚完成 mode={} companyId={} shopId={} statDate={} ordersShopGmv={}",
|
log.info("BI 日汇聚完成 mode={} companyId={} shopId={} statDate={} ordersShopGmv={}",
|
||||||
mode, agg.companyId(), agg.shopId(), agg.statDate(), agg.shop().gmvOrderCount);
|
mode, agg.companyId(), agg.shopId(), agg.statDate(), agg.shop().gmvOrderCount);
|
||||||
}
|
}
|
||||||
@@ -319,7 +319,7 @@ public class OrderDailyStatComputeService {
|
|||||||
doc.setOtherCost(m.otherCost);
|
doc.setOtherCost(m.otherCost);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void applyMetric(BiOrderStatDailySpecDoc doc, Metric m) {
|
private static void applyMetric(BiOrderStatDailySkuDoc doc, Metric m) {
|
||||||
doc.setSalesAmount(m.salesAmount);
|
doc.setSalesAmount(m.salesAmount);
|
||||||
doc.setSalesOrderCount(m.salesOrderCount);
|
doc.setSalesOrderCount(m.salesOrderCount);
|
||||||
doc.setSalesQuantitySum(m.salesQuantitySum);
|
doc.setSalesQuantitySum(m.salesQuantitySum);
|
||||||
@@ -364,7 +364,7 @@ public class OrderDailyStatComputeService {
|
|||||||
BigDecimal otherCost = BigDecimal.ZERO;
|
BigDecimal otherCost = BigDecimal.ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
private record DimKey(long productId, long categoryId, long specId) {
|
private record DimKey(long productId, long categoryId, long skuId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private record DayAgg(
|
private record DayAgg(
|
||||||
@@ -375,7 +375,7 @@ public class OrderDailyStatComputeService {
|
|||||||
Metric shop,
|
Metric shop,
|
||||||
Map<String, Metric> productMap,
|
Map<String, Metric> productMap,
|
||||||
Map<String, DimKey> productKeys,
|
Map<String, DimKey> productKeys,
|
||||||
Map<String, Metric> specMap,
|
Map<String, Metric> skuMap,
|
||||||
Map<String, DimKey> specKeys) {
|
Map<String, DimKey> skuKeys) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-16
@@ -3,7 +3,7 @@ package top.xyquan.ecomdmbbackend.modules.bi.orderstat.support;
|
|||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiProductStatDelta;
|
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiProductStatDelta;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiSpecStatDelta;
|
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiSkuStatDelta;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiStatMetricDelta;
|
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiStatMetricDelta;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.order.model.po.OrderItemPO;
|
import top.xyquan.ecomdmbbackend.modules.ec.order.model.po.OrderItemPO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.order.model.po.OrderPO;
|
import top.xyquan.ecomdmbbackend.modules.ec.order.model.po.OrderPO;
|
||||||
@@ -62,15 +62,15 @@ public class OrderStatContributionCalculator {
|
|||||||
|
|
||||||
Map<String, BiStatMetricDelta> productMap = new HashMap<>();
|
Map<String, BiStatMetricDelta> productMap = new HashMap<>();
|
||||||
Map<String, long[]> productKeys = new HashMap<>();
|
Map<String, long[]> productKeys = new HashMap<>();
|
||||||
Map<String, BiStatMetricDelta> specMap = new HashMap<>();
|
Map<String, BiStatMetricDelta> skuMap = new HashMap<>();
|
||||||
Map<String, long[]> specKeys = new HashMap<>();
|
Map<String, long[]> skuKeys = new HashMap<>();
|
||||||
|
|
||||||
Map<Long, Long> categoryByProduct = loadCategories(safeItems);
|
Map<Long, Long> categoryByProduct = loadCategories(safeItems);
|
||||||
|
|
||||||
for (OrderItemPO item : safeItems) {
|
for (OrderItemPO item : safeItems) {
|
||||||
long productId = item.getProductId() != null ? item.getProductId() : 0L;
|
long productId = item.getProductId() != null ? item.getProductId() : 0L;
|
||||||
long categoryId = categoryByProduct.getOrDefault(productId, 0L);
|
long categoryId = categoryByProduct.getOrDefault(productId, 0L);
|
||||||
long specId = item.getProductSkuId() != null ? item.getProductSkuId() : 0L;
|
long skuId = item.getProductSkuId() != null ? item.getProductSkuId() : 0L;
|
||||||
int qty = OrderStatusStatSets.quantity(item);
|
int qty = OrderStatusStatSets.quantity(item);
|
||||||
BigDecimal linePay = allocateLine(pay, item, safeItems);
|
BigDecimal linePay = allocateLine(pay, item, safeItems);
|
||||||
|
|
||||||
@@ -93,9 +93,9 @@ public class OrderStatContributionCalculator {
|
|||||||
pm.setFreightCost(nz(pm.getFreightCost()).add(fc));
|
pm.setFreightCost(nz(pm.getFreightCost()).add(fc));
|
||||||
pm.setOtherCost(nz(pm.getOtherCost()).add(oc));
|
pm.setOtherCost(nz(pm.getOtherCost()).add(oc));
|
||||||
|
|
||||||
String sk = String.valueOf(specId);
|
String sk = String.valueOf(skuId);
|
||||||
BiStatMetricDelta sm = specMap.computeIfAbsent(sk, k -> BiStatMetricDelta.zeros());
|
BiStatMetricDelta sm = skuMap.computeIfAbsent(sk, k -> BiStatMetricDelta.zeros());
|
||||||
specKeys.putIfAbsent(sk, new long[]{productId, specId});
|
skuKeys.putIfAbsent(sk, new long[]{productId, skuId});
|
||||||
sm.setGmvAmount(nz(sm.getGmvAmount()).add(linePay));
|
sm.setGmvAmount(nz(sm.getGmvAmount()).add(linePay));
|
||||||
sm.setGmvQuantitySum(nzi(sm.getGmvQuantitySum()) + qty);
|
sm.setGmvQuantitySum(nzi(sm.getGmvQuantitySum()) + qty);
|
||||||
if (sales) {
|
if (sales) {
|
||||||
@@ -114,7 +114,7 @@ public class OrderStatContributionCalculator {
|
|||||||
shop.setOtherCost(nz(shop.getOtherCost()).add(oc));
|
shop.setOtherCost(nz(shop.getOtherCost()).add(oc));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 订单计数:商品/规格维度每单计 1 次(有明细时)
|
// 订单计数:商品/SKU 维度每单计 1 次(有明细时)
|
||||||
if (!safeItems.isEmpty()) {
|
if (!safeItems.isEmpty()) {
|
||||||
for (BiStatMetricDelta pm : productMap.values()) {
|
for (BiStatMetricDelta pm : productMap.values()) {
|
||||||
pm.setGmvOrderCount(1);
|
pm.setGmvOrderCount(1);
|
||||||
@@ -122,7 +122,7 @@ public class OrderStatContributionCalculator {
|
|||||||
pm.setSalesOrderCount(1);
|
pm.setSalesOrderCount(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (BiStatMetricDelta sm : specMap.values()) {
|
for (BiStatMetricDelta sm : skuMap.values()) {
|
||||||
sm.setGmvOrderCount(1);
|
sm.setGmvOrderCount(1);
|
||||||
if (sales) {
|
if (sales) {
|
||||||
sm.setSalesOrderCount(1);
|
sm.setSalesOrderCount(1);
|
||||||
@@ -139,12 +139,12 @@ public class OrderStatContributionCalculator {
|
|||||||
.metrics(e.getValue())
|
.metrics(e.getValue())
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
List<BiSpecStatDelta> specs = new ArrayList<>();
|
List<BiSkuStatDelta> skus = new ArrayList<>();
|
||||||
for (Map.Entry<String, BiStatMetricDelta> e : specMap.entrySet()) {
|
for (Map.Entry<String, BiStatMetricDelta> e : skuMap.entrySet()) {
|
||||||
long[] k = specKeys.get(e.getKey());
|
long[] k = skuKeys.get(e.getKey());
|
||||||
specs.add(BiSpecStatDelta.builder()
|
skus.add(BiSkuStatDelta.builder()
|
||||||
.productId(k[0])
|
.productId(k[0])
|
||||||
.productSpecId(k[1])
|
.productSkuId(k[1])
|
||||||
.metrics(e.getValue())
|
.metrics(e.getValue())
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
@@ -153,7 +153,7 @@ public class OrderStatContributionCalculator {
|
|||||||
.statDate(statDate)
|
.statDate(statDate)
|
||||||
.shop(shop)
|
.shop(shop)
|
||||||
.products(products)
|
.products(products)
|
||||||
.specs(specs)
|
.skus(skus)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,6 +201,6 @@ public class OrderStatContributionCalculator {
|
|||||||
private LocalDate statDate;
|
private LocalDate statDate;
|
||||||
private BiStatMetricDelta shop;
|
private BiStatMetricDelta shop;
|
||||||
private List<BiProductStatDelta> products;
|
private List<BiProductStatDelta> products;
|
||||||
private List<BiSpecStatDelta> specs;
|
private List<BiSkuStatDelta> skus;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -8,7 +8,7 @@ import top.xyquan.ecomdmbbackend.common.mq.OrderMqConstants;
|
|||||||
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiFullCalcMessage;
|
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiFullCalcMessage;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiIncCalcMessage;
|
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiIncCalcMessage;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiProductStatDelta;
|
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiProductStatDelta;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiSpecStatDelta;
|
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiSkuStatDelta;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiStatMetricDelta;
|
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiStatMetricDelta;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.platform.model.enums.PlatformCode;
|
import top.xyquan.ecomdmbbackend.modules.ec.platform.model.enums.PlatformCode;
|
||||||
|
|
||||||
@@ -45,10 +45,10 @@ public class PddBiCalcPublisher {
|
|||||||
OffsetDateTime internalOrderUpdateTime, Long orderId, Long channelOrderId,
|
OffsetDateTime internalOrderUpdateTime, Long orderId, Long channelOrderId,
|
||||||
BiStatMetricDelta shopDelta,
|
BiStatMetricDelta shopDelta,
|
||||||
List<BiProductStatDelta> productDeltas,
|
List<BiProductStatDelta> productDeltas,
|
||||||
List<BiSpecStatDelta> specDeltas) {
|
List<BiSkuStatDelta> skuDeltas) {
|
||||||
if (shopDelta != null && shopDelta.isAllZero()
|
if (shopDelta != null && shopDelta.isAllZero()
|
||||||
&& (productDeltas == null || productDeltas.isEmpty())
|
&& (productDeltas == null || productDeltas.isEmpty())
|
||||||
&& (specDeltas == null || specDeltas.isEmpty())) {
|
&& (skuDeltas == null || skuDeltas.isEmpty())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BiIncCalcMessage msg = BiIncCalcMessage.builder()
|
BiIncCalcMessage msg = BiIncCalcMessage.builder()
|
||||||
@@ -62,7 +62,7 @@ public class PddBiCalcPublisher {
|
|||||||
.channelOrderId(channelOrderId)
|
.channelOrderId(channelOrderId)
|
||||||
.shopDelta(shopDelta)
|
.shopDelta(shopDelta)
|
||||||
.productDeltas(productDeltas)
|
.productDeltas(productDeltas)
|
||||||
.specDeltas(specDeltas)
|
.skuDeltas(skuDeltas)
|
||||||
.occurredAt(OffsetDateTime.now(ZONE))
|
.occurredAt(OffsetDateTime.now(ZONE))
|
||||||
.retryCount(0)
|
.retryCount(0)
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
+17
-17
@@ -13,7 +13,7 @@ import top.xyquan.ecomdmbbackend.common.mq.ChannelOrderRef;
|
|||||||
import top.xyquan.ecomdmbbackend.common.mq.OrderConvertMessage;
|
import top.xyquan.ecomdmbbackend.common.mq.OrderConvertMessage;
|
||||||
import top.xyquan.ecomdmbbackend.common.mq.OrderConvertMode;
|
import top.xyquan.ecomdmbbackend.common.mq.OrderConvertMode;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiProductStatDelta;
|
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiProductStatDelta;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiSpecStatDelta;
|
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiSkuStatDelta;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiStatMetricDelta;
|
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiStatMetricDelta;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.support.OrderStatContributionCalculator;
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.support.OrderStatContributionCalculator;
|
||||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.messaging.PddBiCalcPublisher;
|
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.messaging.PddBiCalcPublisher;
|
||||||
@@ -170,28 +170,28 @@ public class PddOrderConvertService {
|
|||||||
OrderStatContributionCalculator.OrderContribution newC) {
|
OrderStatContributionCalculator.OrderContribution newC) {
|
||||||
Map<LocalDate, BiStatMetricDelta> shopByDate = new HashMap<>();
|
Map<LocalDate, BiStatMetricDelta> shopByDate = new HashMap<>();
|
||||||
Map<LocalDate, Map<String, BiProductStatDelta>> prodByDate = new HashMap<>();
|
Map<LocalDate, Map<String, BiProductStatDelta>> prodByDate = new HashMap<>();
|
||||||
Map<LocalDate, Map<String, BiSpecStatDelta>> specByDate = new HashMap<>();
|
Map<LocalDate, Map<String, BiSkuStatDelta>> skuByDate = new HashMap<>();
|
||||||
|
|
||||||
applyContrib(shopByDate, prodByDate, specByDate, oldC, true);
|
applyContrib(shopByDate, prodByDate, skuByDate, oldC, true);
|
||||||
applyContrib(shopByDate, prodByDate, specByDate, newC, false);
|
applyContrib(shopByDate, prodByDate, skuByDate, newC, false);
|
||||||
|
|
||||||
for (LocalDate date : shopByDate.keySet()) {
|
for (LocalDate date : shopByDate.keySet()) {
|
||||||
BiStatMetricDelta shopDelta = shopByDate.getOrDefault(date, BiStatMetricDelta.zeros());
|
BiStatMetricDelta shopDelta = shopByDate.getOrDefault(date, BiStatMetricDelta.zeros());
|
||||||
List<BiProductStatDelta> products = new ArrayList<>(
|
List<BiProductStatDelta> products = new ArrayList<>(
|
||||||
prodByDate.getOrDefault(date, Map.of()).values());
|
prodByDate.getOrDefault(date, Map.of()).values());
|
||||||
products.removeIf(p -> p.getMetrics() == null || p.getMetrics().isAllZero());
|
products.removeIf(p -> p.getMetrics() == null || p.getMetrics().isAllZero());
|
||||||
List<BiSpecStatDelta> specs = new ArrayList<>(
|
List<BiSkuStatDelta> skus = new ArrayList<>(
|
||||||
specByDate.getOrDefault(date, Map.of()).values());
|
skuByDate.getOrDefault(date, Map.of()).values());
|
||||||
specs.removeIf(s -> s.getMetrics() == null || s.getMetrics().isAllZero());
|
skus.removeIf(s -> s.getMetrics() == null || s.getMetrics().isAllZero());
|
||||||
biCalcPublisher.publishIncDelta(
|
biCalcPublisher.publishIncDelta(
|
||||||
message.getCompanyId(), message.getShopId(), date, internalOrderUpdateTime,
|
message.getCompanyId(), message.getShopId(), date, internalOrderUpdateTime,
|
||||||
orderId, channelOrderId, shopDelta, products, specs);
|
orderId, channelOrderId, shopDelta, products, skus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyContrib(Map<LocalDate, BiStatMetricDelta> shopByDate,
|
private void applyContrib(Map<LocalDate, BiStatMetricDelta> shopByDate,
|
||||||
Map<LocalDate, Map<String, BiProductStatDelta>> prodByDate,
|
Map<LocalDate, Map<String, BiProductStatDelta>> prodByDate,
|
||||||
Map<LocalDate, Map<String, BiSpecStatDelta>> specByDate,
|
Map<LocalDate, Map<String, BiSkuStatDelta>> skuByDate,
|
||||||
OrderStatContributionCalculator.OrderContribution c,
|
OrderStatContributionCalculator.OrderContribution c,
|
||||||
boolean subtract) {
|
boolean subtract) {
|
||||||
if (c == null || c.getStatDate() == null) {
|
if (c == null || c.getStatDate() == null) {
|
||||||
@@ -219,20 +219,20 @@ public class PddOrderConvertService {
|
|||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Map<String, BiSpecStatDelta> sm = specByDate.computeIfAbsent(d, k -> new HashMap<>());
|
Map<String, BiSkuStatDelta> sm = skuByDate.computeIfAbsent(d, k -> new HashMap<>());
|
||||||
if (c.getSpecs() != null) {
|
if (c.getSkus() != null) {
|
||||||
for (BiSpecStatDelta s : c.getSpecs()) {
|
for (BiSkuStatDelta s : c.getSkus()) {
|
||||||
String key = String.valueOf(s.getProductSpecId());
|
String key = String.valueOf(s.getProductSkuId());
|
||||||
BiStatMetricDelta m = s.getMetrics() != null ? s.getMetrics() : BiStatMetricDelta.zeros();
|
BiStatMetricDelta m = s.getMetrics() != null ? s.getMetrics() : BiStatMetricDelta.zeros();
|
||||||
BiStatMetricDelta delta = subtract ? m.negate() : m;
|
BiStatMetricDelta delta = subtract ? m.negate() : m;
|
||||||
sm.merge(key, BiSpecStatDelta.builder()
|
sm.merge(key, BiSkuStatDelta.builder()
|
||||||
.productId(s.getProductId())
|
.productId(s.getProductId())
|
||||||
.productSpecId(s.getProductSpecId())
|
.productSkuId(s.getProductSkuId())
|
||||||
.metrics(delta)
|
.metrics(delta)
|
||||||
.build(),
|
.build(),
|
||||||
(a, b) -> BiSpecStatDelta.builder()
|
(a, b) -> BiSkuStatDelta.builder()
|
||||||
.productId(a.getProductId())
|
.productId(a.getProductId())
|
||||||
.productSpecId(a.getProductSpecId())
|
.productSkuId(a.getProductSkuId())
|
||||||
.metrics(a.getMetrics().plus(b.getMetrics()))
|
.metrics(a.getMetrics().plus(b.getMetrics()))
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user