fix(order): align FBA submit and fee confirmation

This commit is contained in:
2026-09-14 17:19:06 +08:00
parent e0af45db02
commit 8a1e587ee4
13 changed files with 103 additions and 12 deletions
@@ -7,6 +7,7 @@ public record UnifiedInboundSummary(
InboundOrderSummary inbound,
String mainStatus,
String nextAction,
Boolean customerFeeConfirmationRequired,
PreloadSummary preload,
LoadingSummary loading,
DeliverySummary delivery
@@ -22,7 +22,9 @@ import com.baiyue.firstleg.mapper.ContainerTierPricingMapper;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/** FBA 计费仓储;平台基础资料列表可跨企业读取,其他业务操作强制带租户条件。 */
@Repository
@@ -250,6 +252,24 @@ public class FbaPricingRepository {
.orderByDesc(InboundFeeEntity::getFeeVersion).last("LIMIT 1"));
}
public Map<Long, Boolean> customerFeeConfirmationRequiredMap(
Long tenantId, Map<Long, Long> tenantByInbound) {
if (tenantByInbound == null || tenantByInbound.isEmpty()) return Map.of();
var query = new LambdaQueryWrapper<InboundFeeEntity>()
.in(InboundFeeEntity::getInboundId, tenantByInbound.keySet());
if (tenantId != null) query.eq(InboundFeeEntity::getTenantId, tenantId);
query.orderByDesc(InboundFeeEntity::getFeeVersion)
.orderByDesc(InboundFeeEntity::getId);
Map<Long, Boolean> result = new LinkedHashMap<>();
for (InboundFeeEntity fee : fees.selectList(query)) {
Long expectedTenantId = tenantByInbound.get(fee.getInboundId());
if (expectedTenantId == null || !expectedTenantId.equals(fee.getTenantId())) continue;
result.putIfAbsent(fee.getInboundId(),
"SENT".equals(fee.getFeeStatus()) && fee.getCustomerConfirmedAt() == null);
}
return result;
}
public InboundFeeEntity findLatestFeeForUpdate(long tenantId, long inboundId) {
return fees.selectOne(new LambdaQueryWrapper<InboundFeeEntity>()
.eq(InboundFeeEntity::getTenantId, tenantId)
@@ -9,6 +9,7 @@ import com.baiyue.firstleg.dto.UnifiedInboundSummary;
import com.baiyue.firstleg.entity.InboundOrderEntity;
import com.baiyue.firstleg.dto.CurrentContainerTransport;
import com.baiyue.firstleg.loading.entity.CabinetLoadingEvidenceEntity;
import com.baiyue.firstleg.repository.FbaPricingRepository;
import com.baiyue.firstleg.repository.InboundOrderRepository;
import com.baiyue.firstleg.repository.UnifiedInboundReadRepository;
import com.fasterxml.jackson.databind.JsonNode;
@@ -32,6 +33,7 @@ public class UnifiedInboundQueryService {
private static final Set<String> REVIEW_STATUSES = Set.of("UNRECORDED", "PENDING", "APPROVED", "REJECTED");
@Resource private InboundOrderRepository inbounds;
@Resource private FbaPricingRepository pricing;
@Resource private UnifiedInboundReadRepository operations;
@Resource private ObjectMapper json;
@@ -79,8 +81,10 @@ public class UnifiedInboundQueryService {
}
CurrentContainerTransport transport = includePhaseThree
? operations.findTransport(tenantId, inbound.getId()) : null;
boolean customerFeeConfirmationRequired = pricing.customerFeeConfirmationRequiredMap(
tenantId, Map.of(inbound.getId(), inbound.getTenantId())).getOrDefault(inbound.getId(), false);
return new UnifiedInboundDetail(summary(inbound, detail, preload, pick, evidence, deliveryAt,
transport, null, null), timeline);
transport, null, null, customerFeeConfirmationRequired), timeline);
}
private List<UnifiedInboundSummary> summaries(List<InboundOrderEntity> records) {
@@ -99,10 +103,12 @@ public class UnifiedInboundQueryService {
records.forEach(inbound -> applyConfirmedPalletCount(inbound, confirmedPalletCounts));
var locationCodes = inbounds.locationCodesMap(null, owners);
var pickups = inbounds.pickupMap(null, owners);
var customerFeeConfirmations = pricing.customerFeeConfirmationRequiredMap(null, owners);
return records.stream().map(inbound -> summary(inbound, null, preloads.get(inbound.getId()),
picks.get(inbound.getId()), evidences.getOrDefault(inbound.getId(), List.of()),
deliveries.get(inbound.getId()) == null ? null : deliveries.get(inbound.getId()).getOccurredAt(),
transports.get(inbound.getId()), locationCodes.get(inbound.getId()), pickups.get(inbound.getId()))).toList();
transports.get(inbound.getId()), locationCodes.get(inbound.getId()), pickups.get(inbound.getId()),
customerFeeConfirmations.getOrDefault(inbound.getId(), false))).toList();
}
private static void applyConfirmedPalletCount(InboundOrderEntity inbound,
@@ -118,7 +124,8 @@ public class UnifiedInboundQueryService {
com.baiyue.firstleg.loading.entity.InboundLoadingPickTaskEntity pick,
List<CabinetLoadingEvidenceEntity> evidence, LocalDateTime deliveryAt,
CurrentContainerTransport transport, String locationCodes,
com.baiyue.firstleg.entity.InboundPickupSnapshotEntity pickup) {
com.baiyue.firstleg.entity.InboundPickupSnapshotEntity pickup,
boolean customerFeeConfirmationRequired) {
String mainStatus = mainStatus(inbound.getProcessStatus());
List<CabinetLoadingEvidenceEntity> activeEvidence = evidence.stream()
.filter(item -> item.getStatus() == null || "ACTIVE".equals(item.getStatus())).toList();
@@ -143,6 +150,7 @@ public class UnifiedInboundQueryService {
locationCodes == null && baseSummary != null ? baseSummary.locationCodes() : locationCodes);
return new UnifiedInboundSummary(inboundSummary, mainStatus,
nextAction(mainStatus, inbound.getProcessStatus(), preload == null ? null : preload.getStatus()),
customerFeeConfirmationRequired,
preloadSummary, loadingSummary, deliverySummary);
}