This commit is contained in:
2026-08-24 14:47:54 +08:00
8 changed files with 55 additions and 2 deletions
@@ -60,7 +60,8 @@ public class InboundMeasurementRepository {
.eq(InboundOrderEntity::getTenantId, inbound.getTenantId()) .eq(InboundOrderEntity::getTenantId, inbound.getTenantId())
.eq(InboundOrderEntity::getId, inbound.getId()) .eq(InboundOrderEntity::getId, inbound.getId())
.set(InboundOrderEntity::getActualGrossWeightKg, inbound.getActualGrossWeightKg()) .set(InboundOrderEntity::getActualGrossWeightKg, inbound.getActualGrossWeightKg())
.set(InboundOrderEntity::getActualNetWeightKg, inbound.getActualNetWeightKg())) == 1; .set(InboundOrderEntity::getActualNetWeightKg, inbound.getActualNetWeightKg())
.set(InboundOrderEntity::getPalletCount, inbound.getPalletCount())) == 1;
} }
public InboundMeasurementEntity findMeasurement(long tenantId, long inboundId, long measurementId) { public InboundMeasurementEntity findMeasurement(long tenantId, long inboundId, long measurementId) {
@@ -15,6 +15,7 @@ import com.baiyue.firstleg.entity.InboundPalletAllocationEntity;
import com.baiyue.firstleg.entity.InboundStatusHistoryEntity; import com.baiyue.firstleg.entity.InboundStatusHistoryEntity;
import com.baiyue.firstleg.entity.InboundTransportSnapshotEntity; import com.baiyue.firstleg.entity.InboundTransportSnapshotEntity;
import com.baiyue.firstleg.entity.InboundPickupSnapshotEntity; import com.baiyue.firstleg.entity.InboundPickupSnapshotEntity;
import com.baiyue.firstleg.entity.InboundWeightResultEntity;
import com.baiyue.firstleg.mapper.InboundFileMapper; import com.baiyue.firstleg.mapper.InboundFileMapper;
import com.baiyue.firstleg.mapper.InboundInternalNoteMapper; import com.baiyue.firstleg.mapper.InboundInternalNoteMapper;
import com.baiyue.firstleg.mapper.InboundOrderMapper; import com.baiyue.firstleg.mapper.InboundOrderMapper;
@@ -22,6 +23,7 @@ import com.baiyue.firstleg.mapper.InboundPalletAllocationMapper;
import com.baiyue.firstleg.mapper.InboundStatusHistoryMapper; import com.baiyue.firstleg.mapper.InboundStatusHistoryMapper;
import com.baiyue.firstleg.mapper.InboundTransportSnapshotMapper; import com.baiyue.firstleg.mapper.InboundTransportSnapshotMapper;
import com.baiyue.firstleg.mapper.InboundPickupSnapshotMapper; import com.baiyue.firstleg.mapper.InboundPickupSnapshotMapper;
import com.baiyue.firstleg.mapper.InboundWeightResultMapper;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@@ -48,6 +50,8 @@ public class InboundOrderRepository {
private InboundInternalNoteMapper notes; private InboundInternalNoteMapper notes;
@Resource @Resource
private InboundStatusHistoryMapper histories; private InboundStatusHistoryMapper histories;
@Resource
private InboundWeightResultMapper weights;
public PageResult<InboundOrderSummary> page(Long tenantId, InboundOrderQuery query) { public PageResult<InboundOrderSummary> page(Long tenantId, InboundOrderQuery query) {
LambdaQueryWrapper<InboundOrderEntity> wrapper = new LambdaQueryWrapper<InboundOrderEntity>() LambdaQueryWrapper<InboundOrderEntity> wrapper = new LambdaQueryWrapper<InboundOrderEntity>()
@@ -287,6 +291,18 @@ public class InboundOrderRepository {
Collectors.joining("、")))); Collectors.joining("、"))));
} }
public Map<Long, Integer> confirmedPalletCountsMap(Long tenantId, Map<Long, Long> tenantByInbound) {
if (tenantByInbound.isEmpty()) return Map.of();
return weights.selectList(new LambdaQueryWrapper<InboundWeightResultEntity>()
.eq(tenantId != null, InboundWeightResultEntity::getTenantId, tenantId)
.in(InboundWeightResultEntity::getInboundId, tenantByInbound.keySet())
.eq(InboundWeightResultEntity::getRecognitionStatus, "CONFIRMED"))
.stream()
.filter(item -> owns(tenantByInbound, item.getInboundId(), item.getTenantId()))
.collect(Collectors.groupingBy(InboundWeightResultEntity::getInboundId,
java.util.LinkedHashMap::new, Collectors.summingInt(item -> 1)));
}
private static boolean owns(Map<Long, Long> tenantByInbound, Long inboundId, Long tenantId) { private static boolean owns(Map<Long, Long> tenantByInbound, Long inboundId, Long tenantId) {
return inboundId != null && tenantId != null && tenantId.equals(tenantByInbound.get(inboundId)); return inboundId != null && tenantId != null && tenantId.equals(tenantByInbound.get(inboundId));
} }
@@ -330,6 +330,7 @@ public class InboundMeasurementService {
repository.listWeights(inbound.getTenantId(), inbound.getId())); repository.listWeights(inbound.getTenantId(), inbound.getId()));
inbound.setActualGrossWeightKg(totals.grossWeightKg()); inbound.setActualGrossWeightKg(totals.grossWeightKg());
inbound.setActualNetWeightKg(totals.netWeightKg()); inbound.setActualNetWeightKg(totals.netWeightKg());
inbound.setPalletCount(totals.palletCount());
if ("WAIT_MEASURE".equals(inbound.getProcessStatus())) { if ("WAIT_MEASURE".equals(inbound.getProcessStatus())) {
inbound.setProcessStatus("MEASURING"); inbound.setProcessStatus("MEASURING");
} }
@@ -56,6 +56,8 @@ public class UnifiedInboundQueryService {
public UnifiedInboundDetail detail(long tenantId, long orderId) { public UnifiedInboundDetail detail(long tenantId, long orderId) {
InboundOrderEntity inbound = inbounds.findByOrderId(tenantId, orderId); InboundOrderEntity inbound = inbounds.findByOrderId(tenantId, orderId);
if (inbound == null) return null; if (inbound == null) return null;
applyConfirmedPalletCount(inbound, inbounds.confirmedPalletCountsMap(tenantId,
Map.of(inbound.getId(), inbound.getTenantId())));
InboundOrderDetail detail = inbounds.detail(tenantId, inbound); InboundOrderDetail detail = inbounds.detail(tenantId, inbound);
String mainStatus = mainStatus(inbound.getProcessStatus()); String mainStatus = mainStatus(inbound.getProcessStatus());
boolean includePhaseThree = requiresPhaseThreeSummary(mainStatus); boolean includePhaseThree = requiresPhaseThreeSummary(mainStatus);
@@ -93,6 +95,8 @@ public class UnifiedInboundQueryService {
var transports = operations.findTransports(phaseThreeOwners); var transports = operations.findTransports(phaseThreeOwners);
Map<Long, Long> owners = records.stream().collect(Collectors.toMap( Map<Long, Long> owners = records.stream().collect(Collectors.toMap(
InboundOrderEntity::getId, InboundOrderEntity::getTenantId, (left, right) -> left)); InboundOrderEntity::getId, InboundOrderEntity::getTenantId, (left, right) -> left));
var confirmedPalletCounts = inbounds.confirmedPalletCountsMap(null, owners);
records.forEach(inbound -> applyConfirmedPalletCount(inbound, confirmedPalletCounts));
var locationCodes = inbounds.locationCodesMap(null, owners); var locationCodes = inbounds.locationCodesMap(null, owners);
var pickups = inbounds.pickupMap(null, owners); var pickups = inbounds.pickupMap(null, owners);
return records.stream().map(inbound -> summary(inbound, null, preloads.get(inbound.getId()), return records.stream().map(inbound -> summary(inbound, null, preloads.get(inbound.getId()),
@@ -101,6 +105,14 @@ public class UnifiedInboundQueryService {
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()))).toList();
} }
private static void applyConfirmedPalletCount(InboundOrderEntity inbound,
Map<Long, Integer> confirmedPalletCounts) {
if ((inbound.getPalletCount() == null || inbound.getPalletCount() <= 0)
&& confirmedPalletCounts.getOrDefault(inbound.getId(), 0) > 0) {
inbound.setPalletCount(confirmedPalletCounts.get(inbound.getId()));
}
}
private UnifiedInboundSummary summary(InboundOrderEntity inbound, InboundOrderDetail detail, private UnifiedInboundSummary summary(InboundOrderEntity inbound, InboundOrderDetail detail,
com.baiyue.firstleg.split.entity.PreloadPlanEntity preload, com.baiyue.firstleg.split.entity.PreloadPlanEntity preload,
com.baiyue.firstleg.loading.entity.InboundLoadingPickTaskEntity pick, com.baiyue.firstleg.loading.entity.InboundLoadingPickTaskEntity pick,
@@ -17,6 +17,7 @@ import com.baiyue.firstleg.mapper.InboundPalletAllocationMapper;
import com.baiyue.firstleg.mapper.InboundStatusHistoryMapper; import com.baiyue.firstleg.mapper.InboundStatusHistoryMapper;
import com.baiyue.firstleg.mapper.InboundTransportSnapshotMapper; import com.baiyue.firstleg.mapper.InboundTransportSnapshotMapper;
import com.baiyue.firstleg.mapper.InboundPickupSnapshotMapper; import com.baiyue.firstleg.mapper.InboundPickupSnapshotMapper;
import com.baiyue.firstleg.mapper.InboundWeightResultMapper;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.apache.ibatis.builder.MapperBuilderAssistant; import org.apache.ibatis.builder.MapperBuilderAssistant;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
@@ -43,6 +44,7 @@ class InboundOrderRepositoryTest {
@MockBean private InboundFileMapper files; @MockBean private InboundFileMapper files;
@MockBean private InboundInternalNoteMapper notes; @MockBean private InboundInternalNoteMapper notes;
@MockBean private InboundStatusHistoryMapper histories; @MockBean private InboundStatusHistoryMapper histories;
@MockBean private InboundWeightResultMapper weights;
@Resource private InboundOrderRepository repository; @Resource private InboundOrderRepository repository;
@Test @Test
@SuppressWarnings({"rawtypes", "unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
@@ -108,7 +108,9 @@ class TenantScopedMutationRepositoryTest {
verify(inboundOrders).update(eq(inbound), wrapper.capture()); verify(inboundOrders).update(eq(inbound), wrapper.capture());
assertTenantAndId(wrapper.getValue()); assertTenantAndId(wrapper.getValue());
assertThat(((LambdaUpdateWrapper<InboundOrderEntity>) wrapper.getValue()).getSqlSet()) assertThat(((LambdaUpdateWrapper<InboundOrderEntity>) wrapper.getValue()).getSqlSet())
.contains("actual_gross_weight_kg"); .contains("actual_gross_weight_kg")
.contains("actual_net_weight_kg")
.contains("pallet_count");
} }
@Test @Test
@@ -123,6 +123,7 @@ class InboundMeasurementServiceTest {
assertThat(weight.getNetWeightKg()).isNull(); assertThat(weight.getNetWeightKg()).isNull();
assertThat(inbound.getActualGrossWeightKg()).isNull(); assertThat(inbound.getActualGrossWeightKg()).isNull();
assertThat(inbound.getActualNetWeightKg()).isNull(); assertThat(inbound.getActualNetWeightKg()).isNull();
assertThat(inbound.getPalletCount()).isZero();
verify(repository).updateInboundWeightSummary(inbound); verify(repository).updateInboundWeightSummary(inbound);
} }
@@ -283,6 +284,7 @@ class InboundMeasurementServiceTest {
assertThat(response.netWeightKg()).isEqualByComparingTo("4.536"); assertThat(response.netWeightKg()).isEqualByComparingTo("4.536");
assertThat(inbound.getActualGrossWeightKg()).isEqualByComparingTo("6.536"); assertThat(inbound.getActualGrossWeightKg()).isEqualByComparingTo("6.536");
assertThat(inbound.getActualNetWeightKg()).isEqualByComparingTo("6.536"); assertThat(inbound.getActualNetWeightKg()).isEqualByComparingTo("6.536");
assertThat(inbound.getPalletCount()).isEqualTo(2);
assertThat(inbound.getProcessStatus()).isEqualTo("MEASURING"); assertThat(inbound.getProcessStatus()).isEqualTo("MEASURING");
verify(repository).insertRevision(any(InboundWeightRevisionEntity.class)); verify(repository).insertRevision(any(InboundWeightRevisionEntity.class));
} }
@@ -630,6 +632,7 @@ class InboundMeasurementServiceTest {
assertThat(inbound.getActualGrossWeightKg()).isNull(); assertThat(inbound.getActualGrossWeightKg()).isNull();
assertThat(inbound.getActualNetWeightKg()).isNull(); assertThat(inbound.getActualNetWeightKg()).isNull();
assertThat(inbound.getPalletCount()).isZero();
verify(repository).updateInboundWeightSummary(inbound); verify(repository).updateInboundWeightSummary(inbound);
} }
@@ -655,6 +658,7 @@ class InboundMeasurementServiceTest {
assertThat(inbound.getActualGrossWeightKg()).isEqualByComparingTo("5.000"); assertThat(inbound.getActualGrossWeightKg()).isEqualByComparingTo("5.000");
assertThat(inbound.getActualNetWeightKg()).isEqualByComparingTo("5.000"); assertThat(inbound.getActualNetWeightKg()).isEqualByComparingTo("5.000");
assertThat(inbound.getPalletCount()).isEqualTo(1);
verify(repository).updateInboundWeightSummary(inbound); verify(repository).updateInboundWeightSummary(inbound);
} }
@@ -13,6 +13,7 @@ import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
import java.util.List; import java.util.List;
import java.util.Map;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.verifyNoInteractions;
@@ -71,6 +72,20 @@ class UnifiedInboundQueryServiceTest {
assertThat(UnifiedInboundQueryService.requiresPhaseThreeSummary("DELIVERED")).isTrue(); assertThat(UnifiedInboundQueryService.requiresPhaseThreeSummary("DELIVERED")).isTrue();
} }
@Test
void completedHistoricalInboundUsesConfirmedWeightCountWhenStoredPalletCountIsZero() throws Exception {
InboundOrderEntity inbound = new InboundOrderEntity();
inbound.setId(88L);
inbound.setPalletCount(0);
var method = UnifiedInboundQueryService.class.getDeclaredMethod(
"applyConfirmedPalletCount", InboundOrderEntity.class, Map.class);
method.setAccessible(true);
method.invoke(null, inbound, Map.of(88L, 2));
assertThat(inbound.getPalletCount()).isEqualTo(2);
}
@ParameterizedTest @ParameterizedTest
@ValueSource(strings = {"WAIT_MEASURE", "WAIT_SPLIT"}) @ValueSource(strings = {"WAIT_MEASURE", "WAIT_SPLIT"})
void phaseTwoDetailDoesNotQueryPhaseThreeTables(String processStatus) { void phaseTwoDetailDoesNotQueryPhaseThreeTables(String processStatus) {