diff --git a/src/main/java/de/avatic/lcc/calculationmodel/ContainerCalculationResult.java b/src/main/java/de/avatic/lcc/calculationmodel/ContainerCalculationResult.java
index 3d963eb..207a610 100644
--- a/src/main/java/de/avatic/lcc/calculationmodel/ContainerCalculationResult.java
+++ b/src/main/java/de/avatic/lcc/calculationmodel/ContainerCalculationResult.java
@@ -1,9 +1,251 @@
package de.avatic.lcc.calculationmodel;
+import de.avatic.lcc.dto.generic.ContainerType;
+import de.avatic.lcc.model.packaging.PackagingDimension;
+import de.avatic.lcc.model.utils.DimensionUnit;
+import de.avatic.lcc.model.utils.WeightUnit;
+
+/**
+ * Represents the result of a container calculation process, including details
+ * about the utilized packaging dimensions, container type, and various metrics
+ * such as layer count, structural arrangement, and utilization.
+ *
+ * This class provides methods to retrieve metrics related to container
+ * utilization, such as the total number of handling units and whether the
+ * allowed weight limit has been exceeded.
+ */
public class ContainerCalculationResult {
+
+ private Integer maxContainerWeight;
+
+ /**
+ * The dimensions of the handling unit (HU), including weight,
+ * height, width, and length specifications. Includes a tolerance according
+ * to system property
+ */
+ private PackagingDimension hu;
+
+ /**
+ * The number of layers in the container calculation result,
+ * representing the vertical stacking level.
+ */
private int layer;
+
+ /**
+ * The structural arrangement of the handling units within
+ * the container, represented as a descriptive string.
+ */
private String structure;
+
+ /**
+ * Total count of handling units (HU) that are recognized
+ * based on the calculation.
+ */
private int huUnitCount;
+ /**
+ * Indicates whether the calculated weight of the container exceeds
+ * the permitted limit for the container type.
+ */
+ private boolean weightExceeded;
+
+ /**
+ * Type of container used in the calculation, e.g., TEU/FEU.
+ */
+ private ContainerType containerType;
+
+ /**
+ * Constructs a new ContainerCalculationResult with the provided parameters.
+ *
+ * @param huUnitCount The total number of handling units.
+ * @param layers The total number of layers to stack.
+ * @param structure A textual description of the container's arrangement.
+ * @param weightExceeded Boolean indicating if the allowed weight is exceeded.
+ * @param containerType The type of container being used in the process.
+ * @param hu The packaging dimensions of the handling unit (incl. tolerance).
+ */
+ public ContainerCalculationResult(int huUnitCount, int layers, String structure, boolean weightExceeded, ContainerType containerType, PackagingDimension hu, Integer maxContainerWeight) {
+ this.huUnitCount = huUnitCount;
+ this.layer = layers;
+ this.structure = structure;
+ this.weightExceeded = weightExceeded;
+ this.containerType = containerType;
+ this.maxContainerWeight = maxContainerWeight;
+ this.hu = hu;
+ }
+
+ public Integer getMaxContainerWeight() {
+ return maxContainerWeight;
+ }
+
+ public void setMaxContainerWeight(Integer maxContainerWeight) {
+ this.maxContainerWeight = maxContainerWeight;
+ }
+
+ /**
+ * Sets the PackagingDimension object representing the handling unit attributes.
+ *
+ * @param hu A PackagingDimension object containing weight and size information of the handling unit.
+ */
+ public void setHu(PackagingDimension hu) {
+ this.hu = hu;
+ }
+
+ /**
+ * Retrieves the PackagingDimension object representing the handling unit attributes.
+ *
+ * @return A PackagingDimension object containing weight and size information of the handling unit.
+ */
+ public PackagingDimension getHu() {
+ return hu;
+ }
+
+ /**
+ * Default constructor for ContainerCalculationResult.
+ * Initializes an empty object with no predefined values.
+ */
+ public ContainerCalculationResult() {
+ }
+
+ /**
+ * Gets the type of container used in this calculation.
+ *
+ * @return The container type (e.g., TEU, FEU).
+ */
+ public ContainerType getContainerType() {
+ return containerType;
+ }
+
+ /**
+ * Sets the type of container used in this calculation.
+ *
+ * @param containerType The container type (e.g., TEU, FEU).
+ */
+ public void setContainerType(ContainerType containerType) {
+ this.containerType = containerType;
+ }
+
+ /**
+ * Checks if the weight limit is exceeded for the container.
+ *
+ * @return True if the weight limit is exceeded, false otherwise.
+ */
+ public boolean isWeightExceeded() {
+ return weightExceeded;
+ }
+
+ /**
+ * Sets the status of whether the weight limit is exceeded.
+ *
+ * @param weightExceeded A boolean indicating if the weight limit is exceeded.
+ */
+ public void setWeightExceeded(boolean weightExceeded) {
+ this.weightExceeded = weightExceeded;
+ }
+
+ /**
+ * Gets the number of layers in the container.
+ *
+ * @return The number of layers.
+ */
+ public int getLayer() {
+ return layer;
+ }
+
+ /**
+ * Sets the number of layers in the container.
+ *
+ * @param layer The number of layers to set.
+ */
+ public void setLayer(int layer) {
+ this.layer = layer;
+ }
+
+ /**
+ * Gets the structural arrangement of handling units in the container.
+ *
+ * @return A string specifying the arrangement structure.
+ */
+ public String getStructure() {
+ return structure;
+ }
+
+ /**
+ * Sets the structural arrangement of handling units in the container.
+ *
+ * @param structure A string specifying the arrangement structure.
+ */
+ public void setStructure(String structure) {
+ this.structure = structure;
+ }
+
+ /**
+ * Gets the total number of handling units in the container calculation result.
+ *
+ * @return The total count of handling units.
+ */
+ public int getHuUnitCount() {
+ return huUnitCount;
+ }
+
+ /**
+ * Sets the total number of handling units in the container calculation result.
+ *
+ * @param huUnitCount The total count of handling units to set.
+ */
+ public void setHuUnitCount(int huUnitCount) {
+ this.huUnitCount = huUnitCount;
+ }
+
+ /**
+ * Determines the total utilization of the container based on either
+ * weight or volume, depending on whether the weight limit is exceeded.
+ *
+ * @return Total container utilization as a percentage.
+ */
+ public double getTotalUtilization() {
+ return weightExceeded ? getTotalUtilizationByWeight() : getTotalUtilizationByVolume();
+ }
+
+ /**
+ * Calculates the total utilization of the container,
+ * factoring in the HU utilization and count.
+ *
+ * @return The total utilization value for the container.
+ */
+ public double getTotalUtilizationByVolume() {
+ return getHuUtilizationByVolume() * huUnitCount;
+ }
+
+ /**
+ * Calculates the utilization of a single handling unit (HU)
+ * as a proportion of the container volume.
+ *
+ * @return The volume utilization ratio of one HU to container volume.
+ */
+ public double getHuUtilizationByVolume() {
+ return hu.getVolume(DimensionUnit.M) / containerType.getVolume();
+ }
+
+ /**
+ * Calculates the total utilization of the container based on weight,
+ * factoring in the handling unit utilization and count.
+ *
+ * @return Total weight utilization of the container as a percentage.
+ */
+ public double getTotalUtilizationByWeight() {
+ return getHuUtilizationByWeight() * huUnitCount;
+ }
+
+ /**
+ * Calculates the utilization of a single handling unit (HU) as a proportion
+ * of the container weight capacity.
+ *
+ * @return Weight utilization ratio of one HU to the container's maximum weight.
+ */
+ public double getHuUtilizationByWeight() {
+ return WeightUnit.KG.convertFromG(hu.getWeight()).doubleValue() / maxContainerWeight;
+ }
+
}
diff --git a/src/main/java/de/avatic/lcc/controller/calculation/PremiseController.java b/src/main/java/de/avatic/lcc/controller/calculation/PremiseController.java
index 633f356..b8e7ee2 100644
--- a/src/main/java/de/avatic/lcc/controller/calculation/PremiseController.java
+++ b/src/main/java/de/avatic/lcc/controller/calculation/PremiseController.java
@@ -79,7 +79,7 @@ public class PremiseController {
return ResponseEntity.ok(premisesServices.updatePackaging(packagingDTO));
}
- @PutMapping("/material")
+ @PostMapping("/material")
public ResponseEntity> updateMaterial(@RequestBody MaterialUpdateDTO materialUpdateDTO) {
return ResponseEntity.ok(premisesServices.updateMaterial(materialUpdateDTO));
}
diff --git a/src/main/java/de/avatic/lcc/dto/generic/ContainerType.java b/src/main/java/de/avatic/lcc/dto/generic/ContainerType.java
index d225544..7eaf8da 100644
--- a/src/main/java/de/avatic/lcc/dto/generic/ContainerType.java
+++ b/src/main/java/de/avatic/lcc/dto/generic/ContainerType.java
@@ -1,5 +1,40 @@
package de.avatic.lcc.dto.generic;
public enum ContainerType {
- FEU, TEU, HQ
+ FEU(12030, 2350, 2390, 67.7, 24,21), TEU(5890 ,2350,2390, 33.0, 11,10), HQ(12030, 2350, 2690, 76.4, 24,21), TRUCK(13600,2450, 2650, 88.3, 34, 33);
+
+ private final int length;
+ private final int width;
+ private final int height;
+ private final double volume;
+ private final int euroPalletCount;
+ private final int industrialPalletCount;
+
+ ContainerType(int length, int width, int height, double volume, int euroPalletCount, int industrialPalletCount) {
+ this.length = length;
+ this.width = width;
+ this.height = height;
+ this.volume = volume;
+ this.euroPalletCount = euroPalletCount;
+ this.industrialPalletCount = industrialPalletCount;
+
+ }
+ public int getLength() {
+ return length;
+ }
+ public int getWidth() {
+ return width;
+ }
+ public int getHeight() {
+ return height;
+ }
+
+ public double getVolume() {
+ return volume;
+ }
+
+ public int getPalletCount(PalletType palletType) {
+ return palletType == PalletType.EURO_PALLET ? euroPalletCount : industrialPalletCount;
+
+ }
}
diff --git a/src/main/java/de/avatic/lcc/dto/generic/PalletType.java b/src/main/java/de/avatic/lcc/dto/generic/PalletType.java
new file mode 100644
index 0000000..743c4ff
--- /dev/null
+++ b/src/main/java/de/avatic/lcc/dto/generic/PalletType.java
@@ -0,0 +1,29 @@
+package de.avatic.lcc.dto.generic;
+
+import de.avatic.lcc.model.packaging.PackagingDimension;
+
+public enum PalletType {
+ INDUSTRIAL_PALLET(1200,1000), EURO_PALLET(1200,800);
+
+ private final int width;
+ private final int length;
+
+ PalletType(int length, int width) {
+ this.length = length;
+ this.width = width;
+ }
+
+ public int getLength() {
+ return length;
+ }
+ public int getWidth() {
+ return width;
+ }
+
+ public boolean fitsOn(PackagingDimension dimension) {
+ return (dimension.getLength() <= this.length && dimension.getWidth() <= this.width) || (dimension.getLength() <= this.width && dimension.getWidth() <= this.length);
+ }
+
+
+
+}
diff --git a/src/main/java/de/avatic/lcc/model/packaging/PackagingDimension.java b/src/main/java/de/avatic/lcc/model/packaging/PackagingDimension.java
index 2e6e5d3..01d8dbe 100644
--- a/src/main/java/de/avatic/lcc/model/packaging/PackagingDimension.java
+++ b/src/main/java/de/avatic/lcc/model/packaging/PackagingDimension.java
@@ -1,9 +1,10 @@
package de.avatic.lcc.model.packaging;
-import com.fasterxml.jackson.annotation.JsonProperty;
import de.avatic.lcc.model.utils.DimensionUnit;
import de.avatic.lcc.model.utils.WeightUnit;
+import java.math.BigDecimal;
+
public class PackagingDimension {
@@ -122,4 +123,12 @@ public class PackagingDimension {
return dimensions;
}
+
+ public double getVolume(DimensionUnit unit) {
+ var lengthInM = unit.convertFromMM(length);
+ var widthInM = unit.convertFromMM(width);
+ var heightInM = unit.convertFromMM(height);
+
+ return lengthInM.doubleValue() * widthInM.doubleValue() * heightInM.doubleValue();
+ }
}
diff --git a/src/main/java/de/avatic/lcc/model/premises/Premise.java b/src/main/java/de/avatic/lcc/model/premises/Premise.java
index 6916814..5bc37f5 100644
--- a/src/main/java/de/avatic/lcc/model/premises/Premise.java
+++ b/src/main/java/de/avatic/lcc/model/premises/Premise.java
@@ -1,5 +1,6 @@
package de.avatic.lcc.model.premises;
+import de.avatic.lcc.model.nodes.Location;
import de.avatic.lcc.model.utils.DimensionUnit;
import de.avatic.lcc.model.utils.WeightUnit;
import jakarta.validation.constraints.Digits;
@@ -68,10 +69,37 @@ public class Premise {
private Integer userSupplierNodeId;
+ private Location location;
+
+ private Integer countryId;
+
private Integer packagingId;
private Integer userId;
+ public DimensionUnit getHuDisplayedDimensionUnit() {
+ return huDisplayedDimensionUnit;
+ }
+
+ public WeightUnit getHuDisplayedWeightUnit() {
+ return huDisplayedWeightUnit;
+ }
+
+ public Location getLocation() {
+ return location;
+ }
+
+ public void setLocation(Location location) {
+ this.location = location;
+ }
+
+ public Integer getCountryId() {
+ return countryId;
+ }
+
+ public void setCountryId(Integer countryId) {
+ this.countryId = countryId;
+ }
public Integer getId() {
return id;
@@ -177,18 +205,10 @@ public class Premise {
this.individualHuWeight = individualHuWeight;
}
- public DimensionUnit getDimensionUnit() {
- return huDisplayedDimensionUnit;
- }
-
public void setHuDisplayedDimensionUnit(DimensionUnit huDisplayedDimensionUnit) {
this.huDisplayedDimensionUnit = huDisplayedDimensionUnit;
}
- public WeightUnit getWeightUnit() {
- return huDisplayedWeightUnit;
- }
-
public void setHuDisplayedWeightUnit(WeightUnit huDisplayedWeightUnit) {
this.huDisplayedWeightUnit = huDisplayedWeightUnit;
}
diff --git a/src/main/java/de/avatic/lcc/model/premises/route/Destination.java b/src/main/java/de/avatic/lcc/model/premises/route/Destination.java
index d267f5e..75f7004 100644
--- a/src/main/java/de/avatic/lcc/model/premises/route/Destination.java
+++ b/src/main/java/de/avatic/lcc/model/premises/route/Destination.java
@@ -9,7 +9,7 @@ public class Destination {
private Integer premiseId;
- private BigDecimal annualAmount;
+ private Integer annualAmount;
private Integer destinationNodeId;
@@ -27,6 +27,16 @@ public class Destination {
private BigDecimal geoLng;
+ private Integer countryId;
+
+ public Integer getCountryId() {
+ return countryId;
+ }
+
+ public void setCountryId(Integer countryId) {
+ this.countryId = countryId;
+ }
+
public BigDecimal getGeoLat() {
return geoLat;
}
@@ -59,11 +69,11 @@ public class Destination {
this.premiseId = premiseId;
}
- public BigDecimal getAnnualAmount() {
+ public Integer getAnnualAmount() {
return annualAmount;
}
- public void setAnnualAmount(BigDecimal annualAmount) {
+ public void setAnnualAmount(Integer annualAmount) {
this.annualAmount = annualAmount;
}
diff --git a/src/main/java/de/avatic/lcc/model/properties/CountryPropertyMappingId.java b/src/main/java/de/avatic/lcc/model/properties/CountryPropertyMappingId.java
new file mode 100644
index 0000000..3361888
--- /dev/null
+++ b/src/main/java/de/avatic/lcc/model/properties/CountryPropertyMappingId.java
@@ -0,0 +1,24 @@
+package de.avatic.lcc.model.properties;
+
+public enum CountryPropertyMappingId {
+ UNION("Customs Union", "NONE"),
+ SAFETY_STOCK("Safety Stock [working days]", "30"),
+ AIR_SHARE("Air freight share [%]", "2"),
+ WAGE("Wage factor [%]", "100%");
+
+ private final String description;
+ private final String defaultValue;
+
+ CountryPropertyMappingId(String description, String defaultValue) {
+ this.description = description;
+ this.defaultValue = defaultValue;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+}
diff --git a/src/main/java/de/avatic/lcc/model/properties/CustomUnionType.java b/src/main/java/de/avatic/lcc/model/properties/CustomUnionType.java
new file mode 100644
index 0000000..156ca5d
--- /dev/null
+++ b/src/main/java/de/avatic/lcc/model/properties/CustomUnionType.java
@@ -0,0 +1,5 @@
+package de.avatic.lcc.model.properties;
+
+public enum CustomUnionType {
+ EU, NONE
+}
diff --git a/src/main/java/de/avatic/lcc/model/properties/PackagingPropertyMappingId.java b/src/main/java/de/avatic/lcc/model/properties/PackagingPropertyMappingId.java
index 65ac3eb..ce72e41 100644
--- a/src/main/java/de/avatic/lcc/model/properties/PackagingPropertyMappingId.java
+++ b/src/main/java/de/avatic/lcc/model/properties/PackagingPropertyMappingId.java
@@ -1,5 +1,23 @@
package de.avatic.lcc.model.properties;
+import org.springframework.jmx.export.naming.IdentityNamingStrategy;
+
public enum PackagingPropertyMappingId {
- STACKABLE, MIXABLE, RUST_PREVENTION
+ STACKABLE("Stackable", "true"), MIXABLE("Mixable", "true"), RUST_PREVENTION("Needs rust prevention", "false");
+
+ private final String defaultValue;
+ private final String description;
+
+ PackagingPropertyMappingId(String description, String defaultValue) {
+ this.description = description;
+ this.defaultValue = defaultValue;
+ }
+
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ public String getDescription() {
+ return description;
+ }
}
diff --git a/src/main/java/de/avatic/lcc/model/properties/SystemPropertyMappingId.java b/src/main/java/de/avatic/lcc/model/properties/SystemPropertyMappingId.java
index f2a35ec..9d1e68a 100644
--- a/src/main/java/de/avatic/lcc/model/properties/SystemPropertyMappingId.java
+++ b/src/main/java/de/avatic/lcc/model/properties/SystemPropertyMappingId.java
@@ -20,19 +20,21 @@ public enum SystemPropertyMappingId {
TRUCK_UTIL("Truck utilization road transport EMEA [%]", "70%"),
VALID_DAYS("Max validity of container freight rates [days]", "60"),
RADIUS_REGION("Metropolition region size (diameter) [km]", "20"),
- FREQ_MIN("Min delivery frequency / year for containtrer transports", "3"),
- FREQ_MAX("Max delivery frequency / year for containtrer transports", "50"),
+ FREQ_MIN("Min delivery frequency / year for container transports", "3"),
+ FREQ_MAX("Max delivery frequency / year for container transports", "50"),
TEU_LOAD("Max load of 20' container [kg]", "20000"),
FEU_LOAD("Max load of 40' container [kg]", "21000"),
+ TRUCK_LOAD("Maximum truck load [kg]", "25000"),
- AIR_PRECARRIAGE("Pre-carriage [EUR/kg]", "0,10 €"),
- AIR_HANDLING("Pre-carriage handling [EUR]", "80,00 €"),
- AIR_MAINCARRIAGE("Main carriage [EUR/kg]", "3,50 €"),
- AIR_HANDOVER_FEE("Hand over fee [EUR]", "35,00 €"),
- AIR_CUSTOM_FEE("Customs clearance fee [EUR]", "45,00 €"),
+
+ AIR_PRECARRIAGE("Pre-carriage [EUR/kg]", "0,10"),
+ AIR_HANDLING("Pre-carriage handling [EUR]", "80,00"),
+ AIR_MAINCARRIAGE("Main carriage [EUR/kg]", "3,50"),
+ AIR_HANDOVER_FEE("Hand over fee [EUR]", "35,00"),
+ AIR_CUSTOM_FEE("Customs clearance fee [EUR]", "45,00"),
AIR_ONCARRIAGE("On-carriage [EUR/kg]", "0,20 €"),
- AIR_TERMINAL_FEE("Terminal handling fee [EUR/kg]", "0,20 €"),
+ AIR_TERMINAL_FEE("Terminal handling fee [EUR/kg]", "0,20"),
KLT_HANDLING("GR handling KLT [EUR/HU]", "0,71 €"),
@@ -41,7 +43,7 @@ public enum SystemPropertyMappingId {
GLT_RELEASE("GLT release from storage [EUR/GLT release]", "2,23 €"),
KLT_RELEASE("KLT release from storage [EUR/KLT release]", "1,12 €"),
GLT_DISPATCH("GLT dispatch [EUR/GLT dispatch]", "1,61 €"),
- KLT_DISPATCH("KLT dispacth [EUR/KLT dispatch]", "0,33 €"),
+ KLT_DISPATCH("KLT dispatch [EUR/KLT dispatch]", "0,33 €"),
KLT_REPACK_S("Repacking KLT, HU <15kg [EUR/HU]", "2,08 €"),
KLT_REPACK_M("Repacking KLT, HU >=15kg [EUR/HU]", "3,02 €"),
GLT_REPACK_S("Repacking GLT, HU <15kg [EUR/HU]", "3,02 €"),
@@ -50,14 +52,9 @@ public enum SystemPropertyMappingId {
DISPOSAL("GLT disposal [EUR/GLT]", "6,00 €"),
- SPACE_COST("Space costs / m3 per night [EUR/m3]", "0,26 €"),
+ SPACE_COST("Space costs / m3 per night [EUR/m3]", "0,26 €");
- UNION("Customs Union", ""),
- SAFTY_STOCK("Safety Stock [working days]", "30"),
- AIR_SHARE("Air freight share [%]", "2"),
- WAGE("Wage factor [%]", "100%");
-
private final String description;
private final String defaultValue;
diff --git a/src/main/java/de/avatic/lcc/model/rates/ContainerRate.java b/src/main/java/de/avatic/lcc/model/rates/ContainerRate.java
index a407b53..4f2b767 100644
--- a/src/main/java/de/avatic/lcc/model/rates/ContainerRate.java
+++ b/src/main/java/de/avatic/lcc/model/rates/ContainerRate.java
@@ -1,5 +1,6 @@
package de.avatic.lcc.model.rates;
+import de.avatic.lcc.dto.generic.TransportType;
import jakarta.validation.constraints.Digits;
import jdk.jfr.Unsigned;
@@ -10,7 +11,7 @@ public class ContainerRate {
private Integer id;
- private ContainerRateType type;
+ private TransportType type;
@Digits(integer = 15, fraction = 2)
private BigDecimal rateTeu;
@@ -65,11 +66,11 @@ public class ContainerRate {
this.id = id;
}
- public ContainerRateType getType() {
+ public TransportType getType() {
return type;
}
- public void setType(ContainerRateType type) {
+ public void setType(TransportType type) {
this.type = type;
}
diff --git a/src/main/java/de/avatic/lcc/model/rates/ContainerRateType.java b/src/main/java/de/avatic/lcc/model/rates/ContainerRateType.java
deleted file mode 100644
index ab216b9..0000000
--- a/src/main/java/de/avatic/lcc/model/rates/ContainerRateType.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package de.avatic.lcc.model.rates;
-
-public enum ContainerRateType {
- RAIL, SEA, POST_RUN, ROAD
-}
diff --git a/src/main/java/de/avatic/lcc/repositories/country/CountryPropertyRepository.java b/src/main/java/de/avatic/lcc/repositories/country/CountryPropertyRepository.java
index 3b2244f..ccfa754 100644
--- a/src/main/java/de/avatic/lcc/repositories/country/CountryPropertyRepository.java
+++ b/src/main/java/de/avatic/lcc/repositories/country/CountryPropertyRepository.java
@@ -1,12 +1,18 @@
package de.avatic.lcc.repositories.country;
import de.avatic.lcc.dto.generic.PropertyDTO;
+import de.avatic.lcc.model.properties.CountryPropertyMappingId;
+import org.springframework.data.mapping.model.Property;
import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
+import java.util.Optional;
@Repository
public class CountryPropertyRepository {
@@ -29,6 +35,26 @@ public class CountryPropertyRepository {
jdbcTemplate.update(query, value, countryId, typeId, setId, value);
}
+ public Optional getByMappingIdAndCountryId(CountryPropertyMappingId mappingId, Integer countryId) {
+ String query = """
+ SELECT type.name as name, type.data_type as dataType, type.external_mapping_id as externalMappingId, type.validation_rule as validationRule,
+ draft.property_value as draftValue, valid.property_value as validValue
+ FROM country_property_type AS type
+ LEFT JOIN country_property AS draft ON draft.country_property_type_id = type.id
+ LEFT JOIN country_property AS valid ON valid.country_property_type_id = type.id
+ LEFT JOIN property_set AS draftSet ON draftSet.id = draft.property_set_id
+ LEFT JOIN property_set AS validSet ON validSet.id = valid.property_set_id
+ WHERE draftSet.state = 'DRAFT' AND validSet.state = 'VALID' AND draft.country_id = ? AND valid.country_id = ?
+ AND type.external_mapping_id = ?
+ """;
+
+ var property = jdbcTemplate.query(query, new PropertyMapper(), countryId, countryId, mappingId.name());
+
+ if(property.isEmpty())
+ return Optional.empty();
+
+ return Optional.of(property.getFirst());
+ }
private Integer getTypeIdByMappingId(String mappingId) {
String query = "SELECT id FROM country_property_type WHERE external_mapping_id = ?";
@@ -49,19 +75,7 @@ public class CountryPropertyRepository {
WHERE draftSet.state = 'DRAFT' AND validSet.state = 'VALID' AND draft.country_id = ? AND valid.country_id = ?
""";
- return jdbcTemplate.query(query, (rs, rowNum) -> {
- var dto = new PropertyDTO();
-
- dto.setName(rs.getString("name"));
- dto.setDraftValue(rs.getString("draftValue"));
- dto.setCurrentValue(rs.getString("validValue"));
- dto.setValidationRule(rs.getString("validationRule"));
- dto.setExternalMappingId(rs.getString("externalMappingId"));
- dto.setRequired(true);
- dto.setDataType(rs.getString("dataType"));
-
- return dto;
- }, id, id);
+ return jdbcTemplate.query(query, new PropertyMapper(), id, id);
}
public Collection listPropertiesByCountryIdAndPropertySetId(Integer id, Integer propertySetId) {
@@ -75,19 +89,7 @@ public class CountryPropertyRepository {
WHERE propertySet.state = 'EXPIRED' AND property.country_id = ? AND propertySet.id = ?
""";
- return jdbcTemplate.query(query, (rs, rowNum) -> {
- var dto = new PropertyDTO();
-
- dto.setName(rs.getString("name"));
- dto.setDraftValue(rs.getString("draftValue"));
- dto.setCurrentValue(rs.getString("validValue"));
- dto.setValidationRule(rs.getString("validationRule"));
- dto.setExternalMappingId(rs.getString("externalMappingId"));
- dto.setRequired(true);
- dto.setDataType(rs.getString("dataType"));
-
- return dto;
- }, id, propertySetId);
+ return jdbcTemplate.query(query, new PropertyMapper(), id, propertySetId);
}
public void fillDraft(Integer setId) {
@@ -105,4 +107,23 @@ public class CountryPropertyRepository {
}
+
+ private static class PropertyMapper implements RowMapper
+ {
+
+ @Override
+ public PropertyDTO mapRow(ResultSet rs, int rowNum) throws SQLException {
+ var dto = new PropertyDTO();
+
+ dto.setName(rs.getString("name"));
+ dto.setDraftValue(rs.getString("draftValue"));
+ dto.setCurrentValue(rs.getString("validValue"));
+ dto.setValidationRule(rs.getString("validationRule"));
+ dto.setExternalMappingId(rs.getString("externalMappingId"));
+ dto.setRequired(true);
+ dto.setDataType(rs.getString("dataType"));
+
+ return dto;
+ }
+ }
}
diff --git a/src/main/java/de/avatic/lcc/repositories/premise/DestinationRepository.java b/src/main/java/de/avatic/lcc/repositories/premise/DestinationRepository.java
index 3521cc7..d2f61cc 100644
--- a/src/main/java/de/avatic/lcc/repositories/premise/DestinationRepository.java
+++ b/src/main/java/de/avatic/lcc/repositories/premise/DestinationRepository.java
@@ -87,7 +87,7 @@ public class DestinationRepository {
jdbcTemplate.update(connection -> {
var ps = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
- ps.setBigDecimal(1, destination.getAnnualAmount());
+ ps.setInt(1, destination.getAnnualAmount());
ps.setInt(2, destination.getPremiseId());
ps.setInt(3, destination.getDestinationNodeId());
ps.setBigDecimal(4, destination.getRateD2d());
@@ -112,7 +112,7 @@ public class DestinationRepository {
Destination entity = new Destination();
entity.setId(rs.getInt("id"));
- entity.setAnnualAmount(rs.getBigDecimal("annual_amount"));
+ entity.setAnnualAmount(rs.getInt("annual_amount"));
entity.setPremiseId(rs.getInt("premise_id"));
entity.setDestinationNodeId(rs.getInt("destination_node_id"));
entity.setRateD2d(rs.getBigDecimal("rate_d2d"));
@@ -122,6 +122,7 @@ public class DestinationRepository {
entity.setDisposalCost(rs.getBigDecimal("disposal_cost"));
entity.setGeoLat(rs.getBigDecimal("geo_lat"));
entity.setGeoLng(rs.getBigDecimal("geo_lng"));
+ entity.setCountryId(rs.getInt("country_id"));
return entity;
}
diff --git a/src/main/java/de/avatic/lcc/repositories/premise/PremiseRepository.java b/src/main/java/de/avatic/lcc/repositories/premise/PremiseRepository.java
index 9c4e8a0..a8bc2d9 100644
--- a/src/main/java/de/avatic/lcc/repositories/premise/PremiseRepository.java
+++ b/src/main/java/de/avatic/lcc/repositories/premise/PremiseRepository.java
@@ -1,6 +1,8 @@
package de.avatic.lcc.repositories.premise;
import de.avatic.lcc.model.materials.Material;
+import de.avatic.lcc.model.nodes.Location;
+import de.avatic.lcc.model.nodes.Node;
import de.avatic.lcc.model.packaging.PackagingDimension;
import de.avatic.lcc.model.premises.Premise;
import de.avatic.lcc.model.premises.PremiseListEntry;
@@ -301,14 +303,14 @@ public class PremiseRepository {
}
@Transactional
- public void setSupplierId(List premiseId, Integer supplierId, boolean userSupplierNode) {
+ public void setSupplierId(List premiseId, Node supplier, boolean userSupplierNode) {
String placeholders = String.join(",", Collections.nCopies(premiseId.size(), "?"));
- String sql = "UPDATE premise SET supplier_node_id = ?, user_supplier_node_id = ? WHERE id IN ("+placeholders+")";
+ String sql = "UPDATE premise SET supplier_node_id = ?, user_supplier_node_id = ?, geo_lat = ?, geo_lng = ?, country_id = ? WHERE id IN ("+placeholders+")";
if(userSupplierNode) {
- jdbcTemplate.update(sql, 0, supplierId, premiseId.toArray());
+ jdbcTemplate.update(sql, 0, supplier.getId(), supplier.getGeoLat(), supplier.getGeoLng(), supplier.getCountryId(), premiseId.toArray());
} else {
- jdbcTemplate.update(sql, supplierId, 0, premiseId.toArray());
+ jdbcTemplate.update(sql, supplier.getId(), 0, supplier.getGeoLat(), supplier.getGeoLng(), supplier.getCountryId(), premiseId.toArray());
}
}
@@ -375,7 +377,7 @@ public class PremiseRepository {
jdbcTemplate.update(connection -> {
PreparedStatement ps = connection.prepareStatement(
- "INSERT INTO premise (material_id, supplier_node_id, user_supplier_node_id, user_id, state, createdAt, updatedAt)" +
+ "INSERT INTO premise (material_id, supplier_node_id, user_supplier_node_id, user_id, state, created_at, updated_at)" +
" VALUES (?, ?, ?, ?, 'DRAFT', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)",
Statement.RETURN_GENERATED_KEYS);
@@ -576,6 +578,9 @@ public class PremiseRepository {
entity.setSupplierNodeId(rs.getInt("supplier_node_id"));
entity.setUserSupplierNodeId(rs.getInt("user_supplier_node_id"));
+ entity.setLocation(new Location(rs.getBigDecimal("geo_lng").doubleValue(), rs.getBigDecimal("geo_lat").doubleValue()));
+ entity.setCountryId(rs.getInt("country_id"));
+
entity.setUserId(rs.getInt("user_id"));
entity.setMaterialCost(rs.getBigDecimal("material_cost"));
diff --git a/src/main/java/de/avatic/lcc/repositories/premise/RouteRepository.java b/src/main/java/de/avatic/lcc/repositories/premise/RouteRepository.java
index 595c6d6..d604a7e 100644
--- a/src/main/java/de/avatic/lcc/repositories/premise/RouteRepository.java
+++ b/src/main/java/de/avatic/lcc/repositories/premise/RouteRepository.java
@@ -7,6 +7,7 @@ import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Repository;
+import javax.swing.text.html.Option;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -14,6 +15,7 @@ import java.sql.Statement;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
+import java.util.Optional;
@Repository
public class RouteRepository {
@@ -29,6 +31,21 @@ public class RouteRepository {
return jdbcTemplate.query(query, new RouteMapper(), id);
}
+ public Optional getSelectedByDestinationId(Integer id) {
+ String query = "SELECT * FROM premise_route WHERE premise_destination_id = ?";
+ var route = jdbcTemplate.query(query, new RouteMapper(), id);
+
+ if(route.isEmpty()) {
+ return Optional.empty();
+ }
+
+/* if(1 < route.size())
+ TODO throw something */
+
+
+ return Optional.of(route.getFirst());
+ }
+
public void deleteAllById(List ids) {
if (ids == null || ids.isEmpty()) {
return;
diff --git a/src/main/java/de/avatic/lcc/repositories/rates/ContainerRateRepository.java b/src/main/java/de/avatic/lcc/repositories/rates/ContainerRateRepository.java
index 10d251c..4279922 100644
--- a/src/main/java/de/avatic/lcc/repositories/rates/ContainerRateRepository.java
+++ b/src/main/java/de/avatic/lcc/repositories/rates/ContainerRateRepository.java
@@ -1,7 +1,7 @@
package de.avatic.lcc.repositories.rates;
+import de.avatic.lcc.dto.generic.TransportType;
import de.avatic.lcc.model.rates.ContainerRate;
-import de.avatic.lcc.model.rates.ContainerRateType;
import de.avatic.lcc.model.rates.ValidityPeriodState;
import de.avatic.lcc.repositories.pagination.SearchQueryPagination;
import de.avatic.lcc.repositories.pagination.SearchQueryResult;
@@ -78,8 +78,8 @@ public class ContainerRateRepository {
List