mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
fix: 修复全量bi计算问题
This commit is contained in:
+26
-7
@@ -45,6 +45,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@@ -71,23 +73,40 @@ public class PddOrderConvertService {
|
||||
def.setIsolationLevel(TransactionDefinition.ISOLATION_REPEATABLE_READ);
|
||||
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
|
||||
TransactionTemplate tt = new TransactionTemplate(transactionManager, def);
|
||||
tt.executeWithoutResult(status -> convertFullDay(message));
|
||||
// 必须等转换事务提交后再投递 BI full,否则消费者可能读到未提交快照(漏单)
|
||||
Set<LocalDate> biDates = tt.execute(status -> convertFullDay(message));
|
||||
if (biDates != null) {
|
||||
for (LocalDate d : biDates) {
|
||||
biCalcPublisher.publishFull(
|
||||
message.getCompanyId(), message.getShopId(), d, message.getSyncBatchId());
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
convertInc(message);
|
||||
}
|
||||
|
||||
private void convertFullDay(OrderConvertMessage message) {
|
||||
/**
|
||||
* 仅做库写入;返回需全量重算的 BI 统计日(成交日 + 本批订单 order_time/created_time 涉及日)。
|
||||
*/
|
||||
private Set<LocalDate> convertFullDay(OrderConvertMessage message) {
|
||||
List<PddOrderPO> channelOrders = loadChannelOrders(message);
|
||||
LocalDateTime mappedAt = LocalDateTime.now(ZONE);
|
||||
Set<LocalDate> biDates = new TreeSet<>();
|
||||
if (message.getStatDate() != null) {
|
||||
biDates.add(LocalDate.parse(message.getStatDate()));
|
||||
}
|
||||
for (PddOrderPO channel : channelOrders) {
|
||||
upsertInternalOrder(channel, mappedAt);
|
||||
// BI 日键是 ec_order.order_time = 渠道 created_time
|
||||
if (channel.getCreatedTime() != null) {
|
||||
biDates.add(channel.getCreatedTime().toLocalDate());
|
||||
}
|
||||
}
|
||||
LocalDate statDate = message.getStatDate() != null
|
||||
? LocalDate.parse(message.getStatDate())
|
||||
: LocalDate.now(ZONE);
|
||||
biCalcPublisher.publishFull(
|
||||
message.getCompanyId(), message.getShopId(), statDate, message.getSyncBatchId());
|
||||
if (biDates.isEmpty()) {
|
||||
biDates.add(LocalDate.now(ZONE));
|
||||
}
|
||||
return biDates;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user