优化
This commit is contained in:
+7
@@ -55,6 +55,13 @@ public class InboundMeasurementRepository {
|
||||
.eq(InboundOrderEntity::getId, inbound.getId())) == 1;
|
||||
}
|
||||
|
||||
public boolean updateInboundWeightSummary(InboundOrderEntity inbound) {
|
||||
return inboundOrders.update(inbound, new LambdaUpdateWrapper<InboundOrderEntity>()
|
||||
.eq(InboundOrderEntity::getTenantId, inbound.getTenantId())
|
||||
.eq(InboundOrderEntity::getId, inbound.getId())
|
||||
.set(InboundOrderEntity::getActualGrossWeightKg, inbound.getActualGrossWeightKg())) == 1;
|
||||
}
|
||||
|
||||
public InboundMeasurementEntity findMeasurement(long tenantId, long inboundId, long measurementId) {
|
||||
return measurements.selectOne(new LambdaQueryWrapper<InboundMeasurementEntity>()
|
||||
.eq(InboundMeasurementEntity::getTenantId, tenantId)
|
||||
|
||||
@@ -292,7 +292,7 @@ public class InboundMeasurementService {
|
||||
inbound.setProcessStatus("MEASURING");
|
||||
}
|
||||
inbound.setUpdatedBy(operatorId);
|
||||
if (!repository.updateInbound(inbound)) {
|
||||
if (!repository.updateInboundWeightSummary(inbound)) {
|
||||
throw concurrentModification();
|
||||
}
|
||||
}
|
||||
|
||||
+20
@@ -2,6 +2,7 @@ package com.baiyue.firstleg.repository;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.baiyue.firstleg.entity.FeeItemEntity;
|
||||
@@ -57,6 +58,7 @@ class TenantScopedMutationRepositoryTest {
|
||||
static void initializeMetadata() {
|
||||
initialize(FulfillmentTaskEntity.class);
|
||||
initialize(InboundWeightResultEntity.class);
|
||||
initialize(InboundOrderEntity.class);
|
||||
initialize(InboundFeeDetailEntity.class);
|
||||
}
|
||||
|
||||
@@ -90,6 +92,24 @@ class TenantScopedMutationRepositoryTest {
|
||||
assertTenantAndId(wrapper.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
void weightSummaryUpdateExplicitlyClearsNullGrossWeight() {
|
||||
InboundOrderEntity inbound = new InboundOrderEntity();
|
||||
inbound.setTenantId(TENANT);
|
||||
inbound.setId(ID);
|
||||
inbound.setActualGrossWeightKg(null);
|
||||
when(inboundOrders.update(any(), any(Wrapper.class))).thenReturn(1);
|
||||
|
||||
assertThat(measurementRepository.updateInboundWeightSummary(inbound)).isTrue();
|
||||
|
||||
ArgumentCaptor<Wrapper<InboundOrderEntity>> wrapper = ArgumentCaptor.forClass(Wrapper.class);
|
||||
verify(inboundOrders).update(eq(inbound), wrapper.capture());
|
||||
assertTenantAndId(wrapper.getValue());
|
||||
assertThat(((LambdaUpdateWrapper<InboundOrderEntity>) wrapper.getValue()).getSqlSet())
|
||||
.contains("actual_gross_weight_kg");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
void feeDetailDeleteMatchesTenantAndId() {
|
||||
|
||||
+34
-12
@@ -125,7 +125,7 @@ class InboundMeasurementServiceTest {
|
||||
when(repository.findWeight(1L, 10L, 20L)).thenReturn(current);
|
||||
when(repository.updateWeight(current)).thenReturn(true);
|
||||
when(repository.listWeights(1L, 10L)).thenReturn(List.of(current, previous));
|
||||
when(repository.updateInbound(inbound)).thenReturn(true);
|
||||
when(repository.updateInboundWeightSummary(inbound)).thenReturn(true);
|
||||
|
||||
InboundMeasurementResponses.WeightResult response = service.confirmWeightResult(
|
||||
1L, 10L, 20L, 9L, "操作员",
|
||||
@@ -152,7 +152,7 @@ class InboundMeasurementServiceTest {
|
||||
when(repository.findWeight(1L, 10L, 20L)).thenReturn(weight);
|
||||
when(repository.updateWeight(weight)).thenReturn(true);
|
||||
when(repository.listWeights(1L, 10L)).thenReturn(List.of(weight));
|
||||
when(repository.updateInbound(inbound)).thenReturn(true);
|
||||
when(repository.updateInboundWeightSummary(inbound)).thenReturn(true);
|
||||
|
||||
InboundMeasurementResponses.WeightResult response = service.confirmWeightResult(
|
||||
1L, 10L, 20L, 9L, "操作员",
|
||||
@@ -173,7 +173,7 @@ class InboundMeasurementServiceTest {
|
||||
when(repository.findWeight(1L, 10L, 20L)).thenReturn(weight);
|
||||
when(repository.updateWeight(weight)).thenReturn(true);
|
||||
when(repository.listWeights(1L, 10L)).thenReturn(List.of(weight));
|
||||
when(repository.updateInbound(inbound)).thenReturn(true);
|
||||
when(repository.updateInboundWeightSummary(inbound)).thenReturn(true);
|
||||
|
||||
InboundMeasurementResponses.WeightResult response = service.confirmWeightResult(
|
||||
1L, 10L, 20L, 9L, "操作员",
|
||||
@@ -199,7 +199,7 @@ class InboundMeasurementServiceTest {
|
||||
|
||||
verify(repository, never()).updateWeight(any());
|
||||
verify(repository, never()).insertRevision(any());
|
||||
verify(repository, never()).updateInbound(any());
|
||||
verify(repository, never()).updateInboundWeightSummary(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -217,7 +217,7 @@ class InboundMeasurementServiceTest {
|
||||
|
||||
verify(repository, never()).updateWeight(any());
|
||||
verify(repository, never()).insertRevision(any());
|
||||
verify(repository, never()).updateInbound(any());
|
||||
verify(repository, never()).updateInboundWeightSummary(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -246,7 +246,7 @@ class InboundMeasurementServiceTest {
|
||||
when(repository.findWeight(1L, 10L, 20L)).thenReturn(weight);
|
||||
when(repository.updateWeight(weight)).thenReturn(true);
|
||||
when(repository.listWeights(1L, 10L)).thenReturn(List.of(weight));
|
||||
when(repository.updateInbound(inbound)).thenReturn(true);
|
||||
when(repository.updateInboundWeightSummary(inbound)).thenReturn(true);
|
||||
|
||||
InboundMeasurementResponses.WeightResult response = service.confirmWeightResult(
|
||||
1L, 10L, 20L, 9L, "操作员",
|
||||
@@ -308,7 +308,7 @@ class InboundMeasurementServiceTest {
|
||||
|
||||
verify(repository, never()).updateWeight(any());
|
||||
verify(repository, never()).insertRevision(any());
|
||||
verify(repository, never()).updateInbound(any());
|
||||
verify(repository, never()).updateInboundWeightSummary(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -327,7 +327,7 @@ class InboundMeasurementServiceTest {
|
||||
assertThat(response.version()).isEqualTo(2);
|
||||
verify(repository, never()).updateWeight(any());
|
||||
verify(repository, never()).insertRevision(any());
|
||||
verify(repository, never()).updateInbound(any());
|
||||
verify(repository, never()).updateInboundWeightSummary(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -366,7 +366,7 @@ class InboundMeasurementServiceTest {
|
||||
verify(repository, times(2)).updateWeight(weight);
|
||||
verify(repository, times(1)).insertRevision(any(InboundWeightRevisionEntity.class));
|
||||
verify(repository, never()).listWeights(anyLong(), anyLong());
|
||||
verify(repository, never()).updateInbound(any());
|
||||
verify(repository, never()).updateInboundWeightSummary(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -383,7 +383,7 @@ class InboundMeasurementServiceTest {
|
||||
|
||||
verify(repository).deleteWeight(1L, 10L, 20L, 1);
|
||||
verify(imageClient).delete("internal-token", 9L, 1L, 10L, 120L);
|
||||
verify(repository, never()).updateInbound(any());
|
||||
verify(repository, never()).updateInboundWeightSummary(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -396,14 +396,36 @@ class InboundMeasurementServiceTest {
|
||||
when(repository.findWeight(1L, 10L, 20L)).thenReturn(weight);
|
||||
when(repository.deleteWeight(1L, 10L, 20L, 2)).thenReturn(true);
|
||||
when(repository.listWeights(1L, 10L)).thenReturn(List.of());
|
||||
when(repository.updateInbound(inbound)).thenReturn(true);
|
||||
when(repository.updateInboundWeightSummary(inbound)).thenReturn(true);
|
||||
when(imageClient.delete("internal-token", 9L, 1L, 10L, 120L))
|
||||
.thenReturn(ApiResponse.success(null));
|
||||
|
||||
service.deleteWeightResult(1L, 10L, 20L, 2, 9L);
|
||||
|
||||
assertThat(inbound.getActualGrossWeightKg()).isNull();
|
||||
verify(repository).updateInbound(inbound);
|
||||
verify(repository).updateInboundWeightSummary(inbound);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletingConfirmedWeightRecalculatesTotalFromRemainingHistory() {
|
||||
InboundOrderEntity inbound = inbound("MEASURING");
|
||||
inbound.setActualGrossWeightKg(new BigDecimal("15.000"));
|
||||
InboundWeightResultEntity deleted = weight(20L, "10.000", "KG", "CONFIRMED", 2);
|
||||
deleted.setFinalWeightKg(new BigDecimal("10.000"));
|
||||
InboundWeightResultEntity remaining = weight(21L, "5.000", "KG", "CONFIRMED", 1);
|
||||
remaining.setFinalWeightKg(new BigDecimal("5.000"));
|
||||
when(repository.findInbound(1L, 10L)).thenReturn(inbound);
|
||||
when(repository.findWeight(1L, 10L, 20L)).thenReturn(deleted);
|
||||
when(repository.deleteWeight(1L, 10L, 20L, 2)).thenReturn(true);
|
||||
when(repository.listWeights(1L, 10L)).thenReturn(List.of(remaining));
|
||||
when(repository.updateInboundWeightSummary(inbound)).thenReturn(true);
|
||||
when(imageClient.delete("internal-token", 9L, 1L, 10L, 120L))
|
||||
.thenReturn(ApiResponse.success(null));
|
||||
|
||||
service.deleteWeightResult(1L, 10L, 20L, 2, 9L);
|
||||
|
||||
assertThat(inbound.getActualGrossWeightKg()).isEqualByComparingTo("5.000");
|
||||
verify(repository).updateInboundWeightSummary(inbound);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user