From ad5a97ec7441862f26b86a2696d4380cdd1da888 Mon Sep 17 00:00:00 2001 From: Jan Date: Sat, 13 Sep 2025 21:35:46 +0200 Subject: [PATCH] BACKEND: fixed near_by routing bug FRONTEND: added bulk menu --- src/frontend/src/backend.js | 2 +- .../components/layout/config/BulkOperations.vue | 1 + .../de/avatic/lcc/dto/generic/RateType.java | 2 +- .../CalculationJobRouteSectionRepository.java | 1 + .../lcc/service/access/PremisesService.java | 2 +- .../lcc/service/calculation/RoutingService.java | 13 +++++++------ .../RouteSectionCostCalculationService.java | 17 ++++++++++------- src/main/resources/schema.sql | 2 +- 8 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/frontend/src/backend.js b/src/frontend/src/backend.js index 55bfcfb..5f77966 100644 --- a/src/frontend/src/backend.js +++ b/src/frontend/src/backend.js @@ -23,7 +23,7 @@ const performRequest = async (requestingStore, method, url, body, expectResponse return data; } -const performDownload = async (requestingStore, url, expectResponse = true, expectedException = null) => { +const performDownload = async (url, expectResponse = true, expectedException = null) => { const params = { method: 'GET', diff --git a/src/frontend/src/components/layout/config/BulkOperations.vue b/src/frontend/src/components/layout/config/BulkOperations.vue index dbe3ac5..5fa2fc8 100644 --- a/src/frontend/src/components/layout/config/BulkOperations.vue +++ b/src/frontend/src/components/layout/config/BulkOperations.vue @@ -96,6 +96,7 @@ export default { methods: { async downloadFile() { const url = `${config.backendUrl}/bulk/upload/${this.exportDataset}/${this.exportType}/` + this.processId = await performDownload(url); }, inputFile(event) { diff --git a/src/main/java/de/avatic/lcc/dto/generic/RateType.java b/src/main/java/de/avatic/lcc/dto/generic/RateType.java index b501d74..4efb9fc 100644 --- a/src/main/java/de/avatic/lcc/dto/generic/RateType.java +++ b/src/main/java/de/avatic/lcc/dto/generic/RateType.java @@ -1,5 +1,5 @@ package de.avatic.lcc.dto.generic; public enum RateType { - MATRIX, CONTAINER, D2D + MATRIX, CONTAINER, D2D, NEAR_BY } diff --git a/src/main/java/de/avatic/lcc/repositories/calculation/CalculationJobRouteSectionRepository.java b/src/main/java/de/avatic/lcc/repositories/calculation/CalculationJobRouteSectionRepository.java index 81378b6..c3b0029 100644 --- a/src/main/java/de/avatic/lcc/repositories/calculation/CalculationJobRouteSectionRepository.java +++ b/src/main/java/de/avatic/lcc/repositories/calculation/CalculationJobRouteSectionRepository.java @@ -84,6 +84,7 @@ public class CalculationJobRouteSectionRepository { } return switch (rateType) { + case NEAR_BY -> RateType.MATRIX.name(); case MATRIX, D2D -> rateType.name(); case CONTAINER -> transportType == null ? null : transportType.name(); }; diff --git a/src/main/java/de/avatic/lcc/service/access/PremisesService.java b/src/main/java/de/avatic/lcc/service/access/PremisesService.java index b4e6069..d1d6139 100644 --- a/src/main/java/de/avatic/lcc/service/access/PremisesService.java +++ b/src/main/java/de/avatic/lcc/service/access/PremisesService.java @@ -136,7 +136,7 @@ public class PremisesService { var jobResult = future.get(); if (jobResult.getState().equals(CalculationJobState.EXCEPTION)) { calculationJobRepository.setStateTo(jobResult.getJobId(), CalculationJobState.EXCEPTION); - throw new InternalErrorException("Execution of calculation was not successful. Please contact Administrator.", new Exception(jobResult.getException())); + throw new InternalErrorException("Execution of calculation was not successful. Please contact Administrator.",jobResult.getException().getMessage(), new Exception(jobResult.getException())); } else { postCalculationCheckService.doPostcheck(jobResult); diff --git a/src/main/java/de/avatic/lcc/service/calculation/RoutingService.java b/src/main/java/de/avatic/lcc/service/calculation/RoutingService.java index c34fde4..61f8230 100644 --- a/src/main/java/de/avatic/lcc/service/calculation/RoutingService.java +++ b/src/main/java/de/avatic/lcc/service/calculation/RoutingService.java @@ -220,8 +220,9 @@ public class RoutingService { private RateType mapRateType(TemporaryRateObject rate) { - if (Objects.requireNonNull(rate.getType()) == TemporaryRateObject.TemporaryRateObjectType.MATRIX - || Objects.requireNonNull(rate.getType()) == TemporaryRateObject.TemporaryRateObjectType.NEAR_BY) { + if (Objects.requireNonNull(rate.getType()) == TemporaryRateObject.TemporaryRateObjectType.NEAR_BY) { + return RateType.NEAR_BY; + } else if (Objects.requireNonNull(rate.getType()) == TemporaryRateObject.TemporaryRateObjectType.MATRIX) { return RateType.MATRIX; } return RateType.CONTAINER; @@ -237,7 +238,7 @@ public class RoutingService { return TransportType.POST_RUN; } case MAIN_RUN -> { - return TransportType.valueOf(rate.getContainerRateTye().name()); + return TransportType.valueOf(rate.getContainerRateType().name()); } } @@ -498,13 +499,13 @@ public class RoutingService { same = otherSection.hasSameNodes(section); - if(!same && hasNearByRouting && iter.hasNext()) { + if (!same && hasNearByRouting && iter.hasNext()) { lastSection = section; section = iter.next(); same = section.getType().equals(TemporaryRateObject.TemporaryRateObjectType.NEAR_BY) && otherSection.hasSameNodes(section, lastSection); } - if(!same) { + if (!same) { break; } } @@ -1007,7 +1008,7 @@ public class RoutingService { return type; } - public TransportType getContainerRateTye() { + public TransportType getContainerRateType() { return containerRate.getType(); } diff --git a/src/main/java/de/avatic/lcc/service/calculation/execution/steps/RouteSectionCostCalculationService.java b/src/main/java/de/avatic/lcc/service/calculation/execution/steps/RouteSectionCostCalculationService.java index 199d7d9..d0bd341 100644 --- a/src/main/java/de/avatic/lcc/service/calculation/execution/steps/RouteSectionCostCalculationService.java +++ b/src/main/java/de/avatic/lcc/service/calculation/execution/steps/RouteSectionCostCalculationService.java @@ -142,6 +142,9 @@ public class RouteSectionCostCalculationService { MatrixRate matrixRate = findMatrixRate(fromNode, toNode); rate = matrixRate.getRate().multiply(BigDecimal.valueOf(distance)); transitTime = 3; // Default transit time for matrix rate + } else if (RateType.NEAR_BY == section.getRateType()) { + rate = BigDecimal.ZERO; + transitTime = 0; } else { throw new IllegalArgumentException("Unsupported rate type: " + section.getRateType()); } @@ -169,7 +172,7 @@ public class RouteSectionCostCalculationService { result.setWeightPrice(containerCalculation.isWeightExceeded()); result.setCbmPrice(prices.volumePrice); result.setWeightPrice(prices.weightPrice); - result.setUtilization(!containerCalculation.isWeightExceeded() || !premise.getHuMixable() ? prices.utilization : BigDecimal.valueOf(1.0)); + result.setUtilization(!containerCalculation.isWeightExceeded() || !premise.getHuMixable() ? prices.utilization : BigDecimal.valueOf(1.0)); var chanceRiskFactors = changeRiskFactorCalculationService.getChanceRiskFactors(); @@ -236,10 +239,11 @@ public class RouteSectionCostCalculationService { private BigDecimal getUtilization(RateType rateType) { BigDecimal utilization; - if (rateType == RateType.CONTAINER) { + if (rateType == RateType.NEAR_BY) { utilization = BigDecimal.valueOf(Double.parseDouble(propertyRepository.getPropertyByMappingId(SystemPropertyMappingId.CONTAINER_UTIL).orElseThrow().getCurrentValue())); - } - else if (rateType == RateType.MATRIX) { + } else if (rateType == RateType.CONTAINER) { + utilization = BigDecimal.valueOf(Double.parseDouble(propertyRepository.getPropertyByMappingId(SystemPropertyMappingId.CONTAINER_UTIL).orElseThrow().getCurrentValue())); + } else if (rateType == RateType.MATRIX) { utilization = BigDecimal.valueOf(Double.parseDouble(propertyRepository.getPropertyByMappingId(SystemPropertyMappingId.TRUCK_UTIL).orElseThrow().getCurrentValue())); } else throw new IllegalArgumentException("Unknown rate type"); @@ -272,11 +276,10 @@ public class RouteSectionCostCalculationService { } - - /** * Simple data class to hold volume and weight price results */ - private record PriceCalculationResult(BigDecimal volumePrice, BigDecimal weightPrice, BigDecimal utilization) {} + private record PriceCalculationResult(BigDecimal volumePrice, BigDecimal weightPrice, BigDecimal utilization) { + } } diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index fd8d7fa..16afb82 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -441,7 +441,7 @@ CREATE TABLE IF NOT EXISTS premise_route_section transport_type CHAR(16) CHECK (transport_type IN ('RAIL', 'SEA', 'ROAD', 'POST_RUN')), rate_type CHAR(16) CHECK (rate_type IN - ('CONTAINER', 'MATRIX')), + ('CONTAINER', 'MATRIX', 'NEAR_BY')), is_pre_run BOOLEAN DEFAULT FALSE, is_main_run BOOLEAN DEFAULT FALSE, is_post_run BOOLEAN DEFAULT FALSE,