Bugfix: if hu amount is less than min shipping frequency, fix total utilization accordingly
This commit is contained in:
parent
1be35b5a8d
commit
9ac3cb7815
3 changed files with 34 additions and 23 deletions
|
|
@ -37,17 +37,6 @@ public class CustomCostCalculationService {
|
||||||
this.shippingFrequencyCalculationService = shippingFrequencyCalculationService;
|
this.shippingFrequencyCalculationService = shippingFrequencyCalculationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BigDecimal getContainerShare(Premise premise, ContainerCalculationResult containerCalculationResult) {
|
|
||||||
var weightExceeded = containerCalculationResult.isWeightExceeded();
|
|
||||||
var mixable = premise.getHuMixable();
|
|
||||||
|
|
||||||
if (mixable) {
|
|
||||||
return BigDecimal.valueOf(weightExceeded ? containerCalculationResult.getHuUtilizationByWeight() : containerCalculationResult.getHuUtilizationByVolume());
|
|
||||||
} else {
|
|
||||||
return BigDecimal.ONE.divide(BigDecimal.valueOf(containerCalculationResult.getHuUnitCount()), 10, RoundingMode.HALF_UP);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CustomResult doCalculation(Integer setId, Premise premise, Destination destination, List<SectionInfo> sections) {
|
public CustomResult doCalculation(Integer setId, Premise premise, Destination destination, List<SectionInfo> sections) {
|
||||||
|
|
||||||
var destUnion = countryPropertyRepository.getByMappingIdAndCountryId(CountryPropertyMappingId.UNION, setId, destination.getCountryId()).orElseThrow();
|
var destUnion = countryPropertyRepository.getByMappingIdAndCountryId(CountryPropertyMappingId.UNION, setId, destination.getCountryId()).orElseThrow();
|
||||||
|
|
@ -64,13 +53,13 @@ public class CustomCostCalculationService {
|
||||||
|
|
||||||
double huAnnualAmount = BigDecimal.valueOf(destination.getAnnualAmount()).divide(BigDecimal.valueOf(premise.getHuUnitCount()),0, RoundingMode.CEILING).doubleValue();
|
double huAnnualAmount = BigDecimal.valueOf(destination.getAnnualAmount()).divide(BigDecimal.valueOf(premise.getHuUnitCount()),0, RoundingMode.CEILING).doubleValue();
|
||||||
|
|
||||||
return getCustomCalculationResult(setId, premise, destination, getContainerShare(premise, relevantSections.getFirst().containerResult()), huAnnualAmount, transportationCost, transportationChanceCost, transportationRiskCost);
|
return getCustomCalculationResult(setId, premise, destination, huAnnualAmount, transportationCost, transportationChanceCost, transportationRiskCost);
|
||||||
}
|
}
|
||||||
|
|
||||||
return CustomResult.EMPTY;
|
return CustomResult.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CustomResult getCustomCalculationResult(Integer setId, Premise premise, Destination destination, BigDecimal containerShare, double huAnnualAmount, BigDecimal transportationCost, BigDecimal transportationChanceCost, BigDecimal transportationRiskCost) {
|
private CustomResult getCustomCalculationResult(Integer setId, Premise premise, Destination destination, double huAnnualAmount, BigDecimal transportationCost, BigDecimal transportationChanceCost, BigDecimal transportationRiskCost) {
|
||||||
var shippingFrequency = shippingFrequencyCalculationService.doCalculation(setId, huAnnualAmount);
|
var shippingFrequency = shippingFrequencyCalculationService.doCalculation(setId, huAnnualAmount);
|
||||||
var customFee = Double.parseDouble(propertyRepository.getPropertyByMappingId(SystemPropertyMappingId.CUSTOM_FEE, setId).orElseThrow().getCurrentValue());
|
var customFee = Double.parseDouble(propertyRepository.getPropertyByMappingId(SystemPropertyMappingId.CUSTOM_FEE, setId).orElseThrow().getCurrentValue());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,9 @@ public class RouteSectionCostCalculationService {
|
||||||
private final ChangeRiskFactorCalculationService changeRiskFactorCalculationService;
|
private final ChangeRiskFactorCalculationService changeRiskFactorCalculationService;
|
||||||
private final NodeRepository nodeRepository;
|
private final NodeRepository nodeRepository;
|
||||||
private final UserNodeRepository userNodeRepository;
|
private final UserNodeRepository userNodeRepository;
|
||||||
|
private final ShippingFrequencyCalculationService shippingFrequencyCalculationService;
|
||||||
|
|
||||||
public RouteSectionCostCalculationService(ContainerRateRepository containerRateRepository, MatrixRateRepository matrixRateRepository, RouteNodeRepository routeNodeRepository, DistanceService distanceService, PropertyRepository propertyRepository, ChangeRiskFactorCalculationService changeRiskFactorCalculationService, NodeRepository nodeRepository, UserNodeRepository userNodeRepository) {
|
public RouteSectionCostCalculationService(ContainerRateRepository containerRateRepository, MatrixRateRepository matrixRateRepository, RouteNodeRepository routeNodeRepository, DistanceService distanceService, PropertyRepository propertyRepository, ChangeRiskFactorCalculationService changeRiskFactorCalculationService, NodeRepository nodeRepository, UserNodeRepository userNodeRepository, ShippingFrequencyCalculationService shippingFrequencyCalculationService) {
|
||||||
this.containerRateRepository = containerRateRepository;
|
this.containerRateRepository = containerRateRepository;
|
||||||
this.matrixRateRepository = matrixRateRepository;
|
this.matrixRateRepository = matrixRateRepository;
|
||||||
this.routeNodeRepository = routeNodeRepository;
|
this.routeNodeRepository = routeNodeRepository;
|
||||||
|
|
@ -50,6 +51,7 @@ public class RouteSectionCostCalculationService {
|
||||||
this.changeRiskFactorCalculationService = changeRiskFactorCalculationService;
|
this.changeRiskFactorCalculationService = changeRiskFactorCalculationService;
|
||||||
this.nodeRepository = nodeRepository;
|
this.nodeRepository = nodeRepository;
|
||||||
this.userNodeRepository = userNodeRepository;
|
this.userNodeRepository = userNodeRepository;
|
||||||
|
this.shippingFrequencyCalculationService = shippingFrequencyCalculationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CalculationJobRouteSection doD2dCalculation(Integer setId, Integer periodId, Premise premise, Destination destination, ContainerCalculationResult containerCalculation) {
|
public CalculationJobRouteSection doD2dCalculation(Integer setId, Integer periodId, Premise premise, Destination destination, ContainerCalculationResult containerCalculation) {
|
||||||
|
|
@ -94,7 +96,10 @@ public class RouteSectionCostCalculationService {
|
||||||
containerCalculation.getMaxContainerWeight(),
|
containerCalculation.getMaxContainerWeight(),
|
||||||
BigDecimal.valueOf(containerCalculation.getTotalUtilizationByVolume()),
|
BigDecimal.valueOf(containerCalculation.getTotalUtilizationByVolume()),
|
||||||
BigDecimal.valueOf(containerCalculation.getHuUtilizationByWeight()),
|
BigDecimal.valueOf(containerCalculation.getHuUtilizationByWeight()),
|
||||||
utilization);
|
utilization,
|
||||||
|
shippingFrequencyCalculationService.doCalculation(setId, huAnnualAmount.doubleValue()),
|
||||||
|
huAnnualAmount.doubleValue(),
|
||||||
|
containerCalculation);
|
||||||
|
|
||||||
result.setCbmPrice(!containerCalculation.isWeightExceeded());
|
result.setCbmPrice(!containerCalculation.isWeightExceeded());
|
||||||
result.setWeightPrice(containerCalculation.isWeightExceeded());
|
result.setWeightPrice(containerCalculation.isWeightExceeded());
|
||||||
|
|
@ -177,7 +182,10 @@ public class RouteSectionCostCalculationService {
|
||||||
containerCalculation.getMaxContainerWeight(),
|
containerCalculation.getMaxContainerWeight(),
|
||||||
BigDecimal.valueOf(containerCalculation.getTotalUtilizationByVolume()),
|
BigDecimal.valueOf(containerCalculation.getTotalUtilizationByVolume()),
|
||||||
BigDecimal.valueOf(containerCalculation.getTotalUtilizationByWeight()),
|
BigDecimal.valueOf(containerCalculation.getTotalUtilizationByWeight()),
|
||||||
utilization);
|
utilization,
|
||||||
|
shippingFrequencyCalculationService.doCalculation(setId, huAnnualAmount.doubleValue()),
|
||||||
|
huAnnualAmount.doubleValue(),
|
||||||
|
containerCalculation);
|
||||||
|
|
||||||
result.setCbmPrice(!containerCalculation.isWeightExceeded());
|
result.setCbmPrice(!containerCalculation.isWeightExceeded());
|
||||||
result.setWeightPrice(containerCalculation.isWeightExceeded());
|
result.setWeightPrice(containerCalculation.isWeightExceeded());
|
||||||
|
|
@ -211,7 +219,11 @@ public class RouteSectionCostCalculationService {
|
||||||
int maxContainerWeight,
|
int maxContainerWeight,
|
||||||
BigDecimal totalVolumeUtilization,
|
BigDecimal totalVolumeUtilization,
|
||||||
BigDecimal totalWeightUtilization,
|
BigDecimal totalWeightUtilization,
|
||||||
BigDecimal propertyUtilization) {
|
BigDecimal propertyUtilization,
|
||||||
|
double shippingFrequency,
|
||||||
|
double annualHuAmount,
|
||||||
|
ContainerCalculationResult containerCalculationResult
|
||||||
|
) {
|
||||||
|
|
||||||
|
|
||||||
BigDecimal utilization;
|
BigDecimal utilization;
|
||||||
|
|
@ -221,16 +233,26 @@ public class RouteSectionCostCalculationService {
|
||||||
BigDecimal cbmRate = rate.divide(BigDecimal.valueOf(containerType.getVolume()), 10, RoundingMode.HALF_UP);
|
BigDecimal cbmRate = rate.divide(BigDecimal.valueOf(containerType.getVolume()), 10, RoundingMode.HALF_UP);
|
||||||
BigDecimal weightRate = rate.divide(BigDecimal.valueOf(maxContainerWeight), 10, RoundingMode.HALF_UP);
|
BigDecimal weightRate = rate.divide(BigDecimal.valueOf(maxContainerWeight), 10, RoundingMode.HALF_UP);
|
||||||
|
|
||||||
|
|
||||||
if (huMixable) {
|
if (huMixable) {
|
||||||
volumePrice = cbmRate.divide(propertyUtilization, 10, RoundingMode.HALF_UP);
|
volumePrice = cbmRate.divide(propertyUtilization, 10, RoundingMode.HALF_UP);
|
||||||
weightPrice = weightRate.divide(BigDecimal.valueOf(1), 10, RoundingMode.HALF_UP);
|
weightPrice = weightRate.divide(BigDecimal.valueOf(1), 10, RoundingMode.HALF_UP);
|
||||||
utilization = weightExceeded ? BigDecimal.ONE : propertyUtilization;
|
utilization = weightExceeded ? BigDecimal.ONE : propertyUtilization;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
double huPerContainer = annualHuAmount / shippingFrequency;
|
||||||
|
|
||||||
|
// if the shipping frequency is bigger than the annual amount the "totalXXUtilization" cannot be used.
|
||||||
|
if(huPerContainer < (containerCalculationResult.getHuUnitCount() * containerCalculationResult.getLayer())) {
|
||||||
|
|
||||||
|
totalVolumeUtilization = BigDecimal.valueOf(huPerContainer * containerCalculationResult.getHu().getVolume(DimensionUnit.M)).divide(BigDecimal.valueOf(containerCalculationResult.getContainerType().getVolume()), 20, RoundingMode.HALF_UP);
|
||||||
|
totalWeightUtilization = BigDecimal.valueOf(huPerContainer * containerCalculationResult.getHu().getWeight(WeightUnit.KG)).divide(BigDecimal.valueOf(containerCalculationResult.getMaxContainerWeight()), 20, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
volumePrice = cbmRate.divide(totalVolumeUtilization, 10, RoundingMode.HALF_UP);
|
volumePrice = cbmRate.divide(totalVolumeUtilization, 10, RoundingMode.HALF_UP);
|
||||||
weightPrice = weightRate.divide(totalWeightUtilization, 10, RoundingMode.HALF_UP);
|
weightPrice = weightRate.divide(totalWeightUtilization, 10, RoundingMode.HALF_UP);
|
||||||
utilization = weightExceeded ? totalWeightUtilization : totalVolumeUtilization;
|
utilization = weightExceeded ? totalWeightUtilization : totalVolumeUtilization;
|
||||||
//TODO: wenn shippingfreq > annual hu -> shippingfreq * containerprice.
|
|
||||||
// gleiches für containercalculation * shippingfreq < annual hu ammount.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new PriceCalculationResult(volumePrice, weightPrice, utilization);
|
return new PriceCalculationResult(volumePrice, weightPrice, utilization);
|
||||||
|
|
|
||||||
|
|
@ -25,13 +25,13 @@ public class ShippingFrequencyCalculationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public double doCalculation(Integer setId, double huAnnualAmount) {
|
public double doCalculation(Integer setId, double huAnnualAmount) {
|
||||||
Integer minAnnualFrequency = Integer.parseInt(propertyRepository.getPropertyByMappingId(SystemPropertyMappingId.FREQ_MIN, setId).orElseThrow().getCurrentValue());
|
int minAnnualFrequency = Integer.parseInt(propertyRepository.getPropertyByMappingId(SystemPropertyMappingId.FREQ_MIN, setId).orElseThrow().getCurrentValue());
|
||||||
Integer maxAnnualFrequency = Integer.parseInt(propertyRepository.getPropertyByMappingId(SystemPropertyMappingId.FREQ_MAX, setId).orElseThrow().getCurrentValue());
|
int maxAnnualFrequency = Integer.parseInt(propertyRepository.getPropertyByMappingId(SystemPropertyMappingId.FREQ_MAX, setId).orElseThrow().getCurrentValue());
|
||||||
|
|
||||||
if (huAnnualAmount > maxAnnualFrequency.doubleValue())
|
if (huAnnualAmount > (double) maxAnnualFrequency)
|
||||||
return maxAnnualFrequency;
|
return maxAnnualFrequency;
|
||||||
|
|
||||||
return Math.max(huAnnualAmount, minAnnualFrequency.doubleValue());
|
return Math.max(huAnnualAmount, (double) minAnnualFrequency);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue