优化
This commit is contained in:
@@ -5,6 +5,7 @@ import jakarta.annotation.Resource;
|
||||
import com.baiyue.common.core.api.ResultCode;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.firstleg.dto.FbaPricingDtos.FeeSnapshotResponse;
|
||||
import com.baiyue.firstleg.entity.CarrierFbaRateEntity;
|
||||
import com.baiyue.firstleg.dto.FbaPricingDtos.AdjustFeeRequest;
|
||||
import com.baiyue.firstleg.domain.PricingDestinationType;
|
||||
import com.baiyue.firstleg.domain.PricingTaxMode;
|
||||
@@ -278,29 +279,33 @@ public class FbaPricingService {
|
||||
if ("COMPLETED".equals(token.getStatus())) {
|
||||
return new ContainerFeeRecalculationResult(ContainerFeeRecalculationStatus.REPLAYED, 0);
|
||||
}
|
||||
BigDecimal aggregate = members.stream().map(ContainerFeeMember::chargeableQuantity)
|
||||
List<ContainerFeeMember> regionalMembers = members.stream()
|
||||
.filter(member -> priceModel(member.current()) == PriceModel.REGION_WEIGHT_TIER)
|
||||
.toList();
|
||||
List<ContainerFeeMember> unlockedRegionalMembers = regionalMembers.stream()
|
||||
.filter(member -> !member.locked()).toList();
|
||||
if (unlockedRegionalMembers.isEmpty()) {
|
||||
complete(token, containerBookingId, now);
|
||||
return new ContainerFeeRecalculationResult(ContainerFeeRecalculationStatus.NOT_APPLICABLE, 0);
|
||||
}
|
||||
BigDecimal aggregate = regionalMembers.stream().map(ContainerFeeMember::chargeableQuantity)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
List<ContainerTierAmountAllocator.Member> allocationMembers = members.stream()
|
||||
List<ContainerTierAmountAllocator.Member> allocationMembers = regionalMembers.stream()
|
||||
.map(member -> new ContainerTierAmountAllocator.Member(member.inbound().getId(), member.chargeableQuantity()))
|
||||
.toList();
|
||||
List<ContainerFeeQuote> quotes = new ArrayList<>();
|
||||
for (ContainerFeeMember member : unlockedMembers) {
|
||||
for (ContainerFeeMember member : unlockedRegionalMembers) {
|
||||
PricingPolicy policy = pricingPolicy(member.inbound(), now);
|
||||
ActivePriceBookEstimator.Estimate estimate = priceBookEstimator.estimate(tenantId, new EstimateRequest(
|
||||
member.inbound().getWarehouseId(), member.inbound().getChannelCode(), member.inbound().getDestinationCode(),
|
||||
destinationType(member.inbound()), member.inbound().getDestinationWarehouseId(),
|
||||
member.inbound().getDestinationName(), null, pricingTaxMode(member.inbound()), policy.chargeMode(),
|
||||
aggregate, BigDecimal.ZERO));
|
||||
if (estimate.priceModel() != PriceModel.REGION_WEIGHT_TIER) {
|
||||
throw conflict("柜内区域阶梯报价模型已变化,请重新试算费用后重试");
|
||||
}
|
||||
quotes.add(new ContainerFeeQuote(member, policy, estimate));
|
||||
}
|
||||
boolean regionalTier = quotes.stream().anyMatch(quote -> quote.estimate().priceModel() == PriceModel.REGION_WEIGHT_TIER);
|
||||
if (!regionalTier) {
|
||||
complete(token, containerBookingId, now);
|
||||
return new ContainerFeeRecalculationResult(ContainerFeeRecalculationStatus.NOT_APPLICABLE, 0);
|
||||
}
|
||||
if (quotes.stream().anyMatch(quote -> quote.estimate().priceModel() != PriceModel.REGION_WEIGHT_TIER)) {
|
||||
throw conflict("柜内客户费用报价模型不一致,不能重算阶梯费用");
|
||||
}
|
||||
for (ContainerFeeQuote quote : quotes) {
|
||||
ContainerTierAmountAllocator.Allocation allocation = containerTierAllocator.allocate(
|
||||
allocationMembers, quote.estimate().unitPrice());
|
||||
@@ -312,6 +317,18 @@ public class FbaPricingService {
|
||||
return new ContainerFeeRecalculationResult(ContainerFeeRecalculationStatus.RECALCULATED, quotes.size());
|
||||
}
|
||||
|
||||
private PriceModel priceModel(InboundFeeEntity fee) {
|
||||
CarrierFbaRateEntity rate = repository.findRate(fee.getCarrierRateId());
|
||||
if (rate == null || !StringUtils.hasText(rate.getPriceModel())) {
|
||||
throw conflict("费用快照引用的报价模型不存在,不能重算阶梯费用");
|
||||
}
|
||||
try {
|
||||
return PriceModel.valueOf(rate.getPriceModel());
|
||||
} catch (IllegalArgumentException exception) {
|
||||
throw conflict("费用快照引用的报价模型无效,不能重算阶梯费用");
|
||||
}
|
||||
}
|
||||
|
||||
private void persistContainerRecalculation(long tenantId, ContainerFeeQuote quote,
|
||||
BigDecimal subtotal, LocalDateTime now) {
|
||||
ContainerFeeMember member = quote.member();
|
||||
|
||||
Reference in New Issue
Block a user