Bugfix: annualCost in d2d routing (Issue #79)
This commit is contained in:
parent
bce745e458
commit
adc1ee0d04
4 changed files with 9 additions and 5 deletions
|
|
@ -75,6 +75,7 @@ public class MaterialRepository {
|
||||||
return jdbcTemplate.query(query, new MaterialMapper(), params.toArray());
|
return jdbcTemplate.query(query, new MaterialMapper(), params.toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public Optional<Material> getByPartNumber(String partNumber) {
|
public Optional<Material> getByPartNumber(String partNumber) {
|
||||||
if (partNumber == null) {
|
if (partNumber == null) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ public class DistanceApiService {
|
||||||
Optional<Distance> cachedDistance = distanceMatrixRepository.getDistance(from, isUsrFrom, to, isUsrTo);
|
Optional<Distance> cachedDistance = distanceMatrixRepository.getDistance(from, isUsrFrom, to, isUsrTo);
|
||||||
|
|
||||||
if (cachedDistance.isPresent() && cachedDistance.get().getState() == DistanceMatrixState.VALID) {
|
if (cachedDistance.isPresent() && cachedDistance.get().getState() == DistanceMatrixState.VALID) {
|
||||||
logger.info("Found cached distance from node {} to node {}", from.getExternalMappingId(), to.getExternalMappingId());
|
logger.info("Found cached distance from node {} (user: {}) to node {} (user {})", from.getExternalMappingId(), isUsrFrom, to.getExternalMappingId(), isUsrTo);
|
||||||
return cachedDistance;
|
return cachedDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ public class MaterialBulkImportService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void updateMaterial(Material material) {
|
private void updateMaterial(Material material) {
|
||||||
var foundMaterial = materialRepository.getByPartNumber(material.getNormalizedPartNumber());
|
var foundMaterial = materialRepository.getByPartNumber(material.getNormalizedPartNumber());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ public class RouteSectionCostCalculationService {
|
||||||
|
|
||||||
// Set premise metadata
|
// Set premise metadata
|
||||||
result.setStacked(premise.getHuStackable());
|
result.setStacked(premise.getHuStackable());
|
||||||
result.setUnmixedPrice(premise.getHuMixable());
|
result.setUnmixedPrice(!premise.getHuMixable());
|
||||||
|
|
||||||
// Get nodes and distance
|
// Get nodes and distance
|
||||||
Node fromNode = premise.getSupplierNodeId() != null ? nodeRepository.getById(premise.getSupplierNodeId()).orElseThrow() : userNodeRepository.getById(premise.getUserSupplierNodeId()).orElseThrow();
|
Node fromNode = premise.getSupplierNodeId() != null ? nodeRepository.getById(premise.getSupplierNodeId()).orElseThrow() : userNodeRepository.getById(premise.getUserSupplierNodeId()).orElseThrow();
|
||||||
|
|
@ -81,8 +81,10 @@ public class RouteSectionCostCalculationService {
|
||||||
result.setTransitTime(transitTime);
|
result.setTransitTime(transitTime);
|
||||||
|
|
||||||
// Calculate price and annual cost
|
// Calculate price and annual cost
|
||||||
|
BigDecimal huAnnualAmount = BigDecimal.valueOf(destination.getAnnualAmount()).divide(BigDecimal.valueOf(containerCalculation.getHu().getContentUnitCount()), 2, RoundingMode.HALF_UP);
|
||||||
BigDecimal utilization = getUtilization(setId, RateType.CONTAINER); /* D2D is always 40ft container */
|
BigDecimal utilization = getUtilization(setId, RateType.CONTAINER); /* D2D is always 40ft container */
|
||||||
double annualVolume = destination.getAnnualAmount() * containerCalculation.getHu().getVolume(DimensionUnit.M);
|
BigDecimal annualVolume =huAnnualAmount.multiply(BigDecimal.valueOf(containerCalculation.getHu().getVolume(DimensionUnit.M)));
|
||||||
|
BigDecimal annualWeight = huAnnualAmount.multiply(BigDecimal.valueOf(containerCalculation.getHu().getWeight(WeightUnit.KG)));
|
||||||
|
|
||||||
PriceCalculationResult prices = calculatePrices(
|
PriceCalculationResult prices = calculatePrices(
|
||||||
premise.getHuMixable(),
|
premise.getHuMixable(),
|
||||||
|
|
@ -102,7 +104,7 @@ public class RouteSectionCostCalculationService {
|
||||||
|
|
||||||
var chanceRiskFactors = changeRiskFactorCalculationService.getChanceRiskFactors(setId, periodId);
|
var chanceRiskFactors = changeRiskFactorCalculationService.getChanceRiskFactors(setId, periodId);
|
||||||
|
|
||||||
BigDecimal annualCost = (containerCalculation.isWeightExceeded() ? prices.weightPrice : prices.volumePrice).multiply(BigDecimal.valueOf(annualVolume));
|
BigDecimal annualCost = (containerCalculation.isWeightExceeded() ? prices.weightPrice.multiply(annualWeight) : prices.volumePrice.multiply(annualVolume));
|
||||||
BigDecimal annualRiskCost = annualCost.multiply(chanceRiskFactors.getRiskFactor());
|
BigDecimal annualRiskCost = annualCost.multiply(chanceRiskFactors.getRiskFactor());
|
||||||
BigDecimal annualChanceCost = annualCost.multiply(chanceRiskFactors.getChanceFactor());
|
BigDecimal annualChanceCost = annualCost.multiply(chanceRiskFactors.getChanceFactor());
|
||||||
|
|
||||||
|
|
@ -300,7 +302,7 @@ public class RouteSectionCostCalculationService {
|
||||||
throw new NoSuchElementException("Destination node not found for route section" + toNode.getName());
|
throw new NoSuchElementException("Destination node not found for route section" + toNode.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return distanceService.getDistanceForNode(optSrcNode.get(), optDestNode.get(), false);
|
return distanceService.getDistanceForNode(optSrcNode.get(), optDestNode.get());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue