Remove unused DTOs and entities in Premise handling.

Deleted unused classes and entities like `AllUpdateDTO`, `MasterDataUpdateDTO`, and `PremissRoute`. Updated `PremisesService` and repository structure for improved functionality and maintainability, including refactoring queries and adding mappers.
This commit is contained in:
Jan 2025-04-18 22:09:00 +02:00
parent c0fc174510
commit 11bdf3b948
56 changed files with 1842 additions and 716 deletions

View file

@ -1,12 +1,15 @@
package de.avatic.lcc.controller.calculation; package de.avatic.lcc.controller.calculation;
import de.avatic.lcc.dto.calculation.edit.SetSupplierDTO; import de.avatic.lcc.dto.calculation.edit.SetDataDTO;
import de.avatic.lcc.dto.calculation.create.PremiseSearchResultDTO; import de.avatic.lcc.dto.calculation.create.PremiseSearchResultDTO;
import de.avatic.lcc.dto.calculation.edit.*; import de.avatic.lcc.dto.calculation.edit.*;
import de.avatic.lcc.dto.calculation.edit.update.MasterDataUpdateDTO; import de.avatic.lcc.dto.calculation.edit.destination.DestinationCreateDTO;
import de.avatic.lcc.dto.calculation.edit.update.MasterDataUpdateType; import de.avatic.lcc.dto.calculation.DestinationDTO;
import de.avatic.lcc.dto.calculation.view.PremiseViewDTO; import de.avatic.lcc.dto.calculation.edit.destination.DestinationUpdateDTO;
import de.avatic.lcc.dto.calculation.edit.masterData.*;
import de.avatic.lcc.dto.calculation.PremiseDTO;
import de.avatic.lcc.service.calculation.DestinationService;
import de.avatic.lcc.service.calculation.PremiseSearchStringAnalyzerService; import de.avatic.lcc.service.calculation.PremiseSearchStringAnalyzerService;
import de.avatic.lcc.service.calculation.PremiseCreationService; import de.avatic.lcc.service.calculation.PremiseCreationService;
import de.avatic.lcc.service.calculation.PremisesService; import de.avatic.lcc.service.calculation.PremisesService;
@ -23,16 +26,24 @@ public class CalculationController {
private final PremiseSearchStringAnalyzerService premiseSearchStringAnalyzerService; private final PremiseSearchStringAnalyzerService premiseSearchStringAnalyzerService;
private final PremisesService premisesServices; private final PremisesService premisesServices;
private final PremiseCreationService premiseCreationService; private final PremiseCreationService premiseCreationService;
private final DestinationService destinationService;
public CalculationController(PremiseSearchStringAnalyzerService premiseSearchStringAnalyzerService, PremisesService premisesServices, PremiseCreationService premiseCreationService) { public CalculationController(PremiseSearchStringAnalyzerService premiseSearchStringAnalyzerService, PremisesService premisesServices, PremiseCreationService premiseCreationService, DestinationService destinationService) {
this.premiseSearchStringAnalyzerService = premiseSearchStringAnalyzerService; this.premiseSearchStringAnalyzerService = premiseSearchStringAnalyzerService;
this.premisesServices = premisesServices; this.premisesServices = premisesServices;
this.premiseCreationService = premiseCreationService; this.premiseCreationService = premiseCreationService;
this.destinationService = destinationService;
} }
@GetMapping("/view") @GetMapping("/view")
public ResponseEntity<List<PremiseViewDTO>> listPremises(@RequestParam String filter, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer limit, @RequestParam(name = "user", required = false) Integer userId, @RequestParam(required = false) Boolean deleted, @RequestParam(required = false) Boolean archived, @RequestParam(required = false) Boolean done) { public ResponseEntity<List<PremiseDTO>> listPremises(@RequestParam String filter, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer limit, @RequestParam(name = "user", required = false) Integer userId, @RequestParam(required = false) Boolean deleted, @RequestParam(required = false) Boolean archived, @RequestParam(required = false) Boolean done) {
return ResponseEntity.ok(premisesServices.listPremises(filter, page, limit, userId, deleted, archived, done)); var premises = premisesServices.listPremises(filter, page, limit, userId, deleted, archived, done);
return ResponseEntity.ok()
.header("X-Total-Count", String.valueOf(premises.getTotalElements()))
.header("X-Page-Count", String.valueOf(premises.getTotalPages()))
.header("X-Current-Page", String.valueOf(page))
.body(premises.toList());
} }
@GetMapping("/search") @GetMapping("/search")
@ -56,37 +67,51 @@ public class CalculationController {
return ResponseEntity.ok(premisesServices.startCalculation(premiseIds)); return ResponseEntity.ok(premisesServices.startCalculation(premiseIds));
} }
@PutMapping("/{type}") @PutMapping("/packaging")
public ResponseEntity<HashMap<String, String>> updateMasterData(@PathVariable MasterDataUpdateType type, MasterDataUpdateDTO masterDataDTO) { public ResponseEntity<HashMap<String, String>> updatePackaging(PackagingUpdateDTO packagingDTO) {
return ResponseEntity.ok(premisesServices.updateMasterData(type, masterDataDTO)); return ResponseEntity.ok(premisesServices.updatePackaging(packagingDTO));
}
@PutMapping("/material")
public ResponseEntity<HashMap<String, String>> updateMaterial(MaterialUpdateDTO materialUpdateDTO) {
return ResponseEntity.ok(premisesServices.updateMaterial(materialUpdateDTO));
}
@PutMapping("/price")
public ResponseEntity<HashMap<String, String>> updatePrice(PriceUpdateDTO priceUpdateDTO) {
return ResponseEntity.ok(premisesServices.updatePrice(priceUpdateDTO));
} }
@PostMapping("/destination") @PostMapping("/destination")
public ResponseEntity<HashMap<Integer, DestinationDTO>> createDestination(CreateDestinationDTO createDestinationDTO) { public ResponseEntity<HashMap<Integer, DestinationDTO>> createDestination(DestinationCreateDTO destinationCreateDTO) {
return ResponseEntity.ok(premisesServices.createDestination(createDestinationDTO)); return ResponseEntity.ok(destinationService.createDestination(destinationCreateDTO));
} }
@GetMapping("/destination({id}") @GetMapping("/destination({id}")
public ResponseEntity<DestinationDTO> getDestination(@PathVariable Integer id) { public ResponseEntity<DestinationDTO> getDestination(@PathVariable Integer id) {
return ResponseEntity.ok(premisesServices.getDestination(id)); return ResponseEntity.ok(destinationService.getDestination(id));
} }
@PutMapping("/destination({id}") @PutMapping("/destination({id}")
public ResponseEntity<Void> updateDestination(@PathVariable Integer id) { public ResponseEntity<Void> updateDestination(@PathVariable Integer id, @RequestParam DestinationUpdateDTO destinationUpdateDTO) {
premisesServices.updateDestination(id); destinationService.updateDestination(id, destinationUpdateDTO);
return ResponseEntity.ok().build(); return ResponseEntity.ok().build();
} }
@DeleteMapping("/destination({id}") @DeleteMapping("/destination({id}")
public ResponseEntity<Void> deleteDestination(@PathVariable Integer id) { public ResponseEntity<Void> deleteDestination(@PathVariable Integer id) {
premisesServices.deleteDestination(id); destinationService.deleteDestination(id);
return ResponseEntity.ok().build(); return ResponseEntity.ok().build();
} }
@PutMapping("/supplier") @PutMapping("/supplier")
public ResponseEntity<List<PremiseDetailDTO>> setSupplier(SetSupplierDTO setSupplierDTO) { public ResponseEntity<List<PremiseDetailDTO>> setSupplier(SetDataDTO setSupplierDTO) {
return ResponseEntity.ok(premisesServices.setSupplier(setSupplierDTO)); return ResponseEntity.ok(premisesServices.setSupplier(setSupplierDTO));
} }
@PutMapping("/material")
public ResponseEntity<List<PremiseDetailDTO>> setMaterial(SetDataDTO setMaterialDTO) {
return ResponseEntity.ok(premisesServices.setMaterial(setMaterialDTO));
}
} }

View file

@ -0,0 +1,73 @@
package de.avatic.lcc.dto.calculation;
import com.fasterxml.jackson.annotation.JsonProperty;
import de.avatic.lcc.dto.generic.NodeDTO;
import java.util.List;
public class DestinationDTO {
private Integer id;
@JsonProperty("repackaging_costs")
private Number repackingCosts;
@JsonProperty("handling_costs")
private Number handlingCosts;
@JsonProperty("disposal_costs")
private Number disposalCosts;
@JsonProperty("destination_node")
private NodeDTO destinationNode;
private List<RouteDTO> routes;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Number getRepackingCosts() {
return repackingCosts;
}
public void setRepackingCosts(Number repackingCosts) {
this.repackingCosts = repackingCosts;
}
public Number getHandlingCosts() {
return handlingCosts;
}
public void setHandlingCosts(Number handlingCosts) {
this.handlingCosts = handlingCosts;
}
public Number getDisposalCosts() {
return disposalCosts;
}
public void setDisposalCosts(Number disposalCosts) {
this.disposalCosts = disposalCosts;
}
public NodeDTO getDestinationNode() {
return destinationNode;
}
public void setDestinationNode(NodeDTO destinationNode) {
this.destinationNode = destinationNode;
}
public List<RouteDTO> getRoutes() {
return routes;
}
public void setRoutes(List<RouteDTO> routes) {
this.routes = routes;
}
}

View file

@ -1,10 +1,10 @@
package de.avatic.lcc.dto.calculation.view; package de.avatic.lcc.dto.calculation;
import de.avatic.lcc.dto.calculation.PremiseState;
import de.avatic.lcc.dto.generic.MaterialDTO; import de.avatic.lcc.dto.generic.MaterialDTO;
import de.avatic.lcc.dto.generic.NodeDTO; import de.avatic.lcc.dto.generic.NodeDTO;
import de.avatic.lcc.model.users.User;
public class PremiseViewDTO { public class PremiseDTO {
private int id; private int id;
@ -14,6 +14,18 @@ public class PremiseViewDTO {
private PremiseState state; private PremiseState state;
//TODO premise calculation result here
// add owner information here (for superuser)
private User owner;
public User getOwner() {
return owner;
}
public void setOwner(User owner) {
this.owner = owner;
}
public int getId() { public int getId() {
return id; return id;

View file

@ -24,4 +24,51 @@ public class RouteDTO {
@JsonProperty("transit_nodes") @JsonProperty("transit_nodes")
private List<NodeDTO> transitNodes; private List<NodeDTO> transitNodes;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public RouteType getType() {
return type;
}
public void setType(RouteType type) {
this.type = type;
}
public Boolean getSelected() {
return isSelected;
}
public void setSelected(Boolean selected) {
isSelected = selected;
}
public Boolean getCheapest() {
return isCheapest;
}
public void setCheapest(Boolean cheapest) {
isCheapest = cheapest;
}
public Boolean getFastest() {
return isFastest;
}
public void setFastest(Boolean fastest) {
isFastest = fastest;
}
public List<NodeDTO> getTransitNodes() {
return transitNodes;
}
public void setTransitNodes(List<NodeDTO> transitNodes) {
this.transitNodes = transitNodes;
}
} }

View file

@ -0,0 +1,8 @@
package de.avatic.lcc.dto.calculation;
public class TransitNodeDTO {
private Integer id;
}

View file

@ -1,27 +0,0 @@
package de.avatic.lcc.dto.calculation.edit;
import com.fasterxml.jackson.annotation.JsonProperty;
import de.avatic.lcc.dto.generic.NodeDTO;
import de.avatic.lcc.dto.calculation.RouteDTO;
import java.util.List;
public class DestinationDTO {
private Integer id;
@JsonProperty("repackaging_costs")
private Number repackingCosts;
@JsonProperty("handling_costs")
private Number handlingCosts;
@JsonProperty("disposal_costs")
private Number disposalCosts;
@JsonProperty("destination_node")
private NodeDTO destinationNode;
private List<RouteDTO> routes;
}

View file

@ -1,6 +1,7 @@
package de.avatic.lcc.dto.calculation.edit; package de.avatic.lcc.dto.calculation.edit;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import de.avatic.lcc.dto.calculation.DestinationDTO;
import de.avatic.lcc.dto.generic.DimensionDTO; import de.avatic.lcc.dto.generic.DimensionDTO;
import de.avatic.lcc.dto.generic.MaterialDTO; import de.avatic.lcc.dto.generic.MaterialDTO;
import de.avatic.lcc.dto.generic.NodeDTO; import de.avatic.lcc.dto.generic.NodeDTO;

View file

@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List; import java.util.List;
public class SetSupplierDTO { public class SetDataDTO {
@JsonProperty("premise_id") @JsonProperty("premise_id")
List<Integer> premiseId; List<Integer> premiseId;
@ -12,9 +12,21 @@ public class SetSupplierDTO {
@JsonProperty("update_master_data") @JsonProperty("update_master_data")
boolean updateMasterData; boolean updateMasterData;
@JsonProperty("supplier_node_id") @JsonProperty("supplier_node_id", required = false)
Integer supplierNodeId; Integer supplierNodeId;
@JsonProperty(value = "material_id", required = false)
Integer materialId;
public Integer getMaterialId() {
return materialId;
}
public void setMaterialId(Integer materialId) {
this.materialId = materialId;
}
public List<Integer> getPremiseId() { public List<Integer> getPremiseId() {
return premiseId; return premiseId;
} }

View file

@ -1,10 +1,10 @@
package de.avatic.lcc.dto.calculation.edit; package de.avatic.lcc.dto.calculation.edit.destination;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List; import java.util.List;
public class CreateDestinationDTO { public class DestinationCreateDTO {
@JsonProperty("premise_id") @JsonProperty("premise_id")
List<Integer> premiseId; List<Integer> premiseId;

View file

@ -0,0 +1,4 @@
package de.avatic.lcc.dto.calculation.edit.destination;
public class DestinationUpdateDTO {
}

View file

@ -0,0 +1,5 @@
package de.avatic.lcc.dto.calculation.edit.masterData;
public enum MasterDataType {
MATERIAL, PRICE, PACKAGING, ALL
}

View file

@ -1,26 +1,20 @@
package de.avatic.lcc.dto.calculation.edit.update.data; package de.avatic.lcc.dto.calculation.edit.masterData;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import de.avatic.lcc.dto.calculation.edit.update.MasterData;
public class MaterialUpdateDTO implements MasterData { import java.util.List;
@JsonProperty("part_number")
private String partNumber; public class MaterialUpdateDTO {
@JsonProperty("premise_id")
private List<Integer> premiseIds;
@JsonProperty("hs_code") @JsonProperty("hs_code")
private String hsCode; private String hsCode;
@JsonProperty("tariff_rate") @JsonProperty("tariff_rate")
private Number tariffRate ; private Number tariffRate;
public String getPartNumber() {
return partNumber;
}
public void setPartNumber(String partNumber) {
this.partNumber = partNumber;
}
public String getHsCode() { public String getHsCode() {
return hsCode; return hsCode;
@ -37,4 +31,12 @@ public class MaterialUpdateDTO implements MasterData {
public void setTariffRate(Number tariffRate) { public void setTariffRate(Number tariffRate) {
this.tariffRate = tariffRate; this.tariffRate = tariffRate;
} }
public List<Integer> getPremiseIds() {
return premiseIds;
}
public void setPremiseIds(List<Integer> premiseIds) {
this.premiseIds = premiseIds;
}
} }

View file

@ -1,10 +1,11 @@
package de.avatic.lcc.dto.calculation.edit.update.data; package de.avatic.lcc.dto.calculation.edit.masterData;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import de.avatic.lcc.dto.calculation.edit.update.MasterData;
import de.avatic.lcc.dto.generic.DimensionDTO; import de.avatic.lcc.dto.generic.DimensionDTO;
public class PackagingUpdateDTO implements MasterData { import java.util.List;
public class PackagingUpdateDTO {
@JsonProperty("handling_unit") @JsonProperty("handling_unit")
private DimensionDTO dimensions; private DimensionDTO dimensions;
@ -15,6 +16,8 @@ public class PackagingUpdateDTO implements MasterData {
@JsonProperty("is_stackable") @JsonProperty("is_stackable")
private Boolean isStackable; private Boolean isStackable;
private List<Integer> premiseIds;
public DimensionDTO getDimensions() { public DimensionDTO getDimensions() {
return dimensions; return dimensions;
@ -39,4 +42,12 @@ public class PackagingUpdateDTO implements MasterData {
public void setStackable(Boolean stackable) { public void setStackable(Boolean stackable) {
isStackable = stackable; isStackable = stackable;
} }
public List<Integer> getPremiseIds() {
return premiseIds;
}
public void setPremiseIds(List<Integer> premiseIds) {
this.premiseIds = premiseIds;
}
} }

View file

@ -1,9 +1,14 @@
package de.avatic.lcc.dto.calculation.edit.update.data; package de.avatic.lcc.dto.calculation.edit.masterData;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import de.avatic.lcc.dto.calculation.edit.update.MasterData;
public class PriceUpdateDTO implements MasterData { import java.util.List;
public class PriceUpdateDTO {
@JsonProperty("premise_ids")
private List<Integer> premiseIds;
private Number price; private Number price;
@ -36,4 +41,12 @@ public class PriceUpdateDTO implements MasterData {
public void setIncludeFcaFee(Boolean includeFcaFee) { public void setIncludeFcaFee(Boolean includeFcaFee) {
this.includeFcaFee = includeFcaFee; this.includeFcaFee = includeFcaFee;
} }
public List<Integer> getPremiseIds() {
return premiseIds;
}
public void setPremiseIds(List<Integer> premiseIds) {
this.premiseIds = premiseIds;
}
} }

View file

@ -1,4 +0,0 @@
package de.avatic.lcc.dto.calculation.edit.update;
public interface MasterData {
}

View file

@ -1,38 +0,0 @@
package de.avatic.lcc.dto.calculation.edit.update;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import de.avatic.lcc.dto.calculation.edit.update.data.AllUpdateDTO;
import de.avatic.lcc.dto.calculation.edit.update.data.MaterialUpdateDTO;
import de.avatic.lcc.dto.calculation.edit.update.data.PackagingUpdateDTO;
import de.avatic.lcc.dto.calculation.edit.update.data.PriceUpdateDTO;
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(value = MaterialUpdateDTO.class, name = "MATERIAL"),
@JsonSubTypes.Type(value = PackagingUpdateDTO.class, name = "PACKAGING"),
@JsonSubTypes.Type(value = PriceUpdateDTO.class, name = "PRICE"),
@JsonSubTypes.Type(value = AllUpdateDTO.class, name = "ALL"),
})
public class MasterDataUpdateDTO {
private MasterDataUpdateType type;
private MasterData data;
public MasterDataUpdateType getType() {
return type;
}
public void setType(MasterDataUpdateType type) {
this.type = type;
}
public MasterData getData() {
return data;
}
public void setData(MasterData data) {
this.data = data;
}
}

View file

@ -1,5 +0,0 @@
package de.avatic.lcc.dto.calculation.edit.update;
public enum MasterDataUpdateType {
MATERIAL, PRICE, PACKAGING, ALL
}

View file

@ -1,106 +0,0 @@
package de.avatic.lcc.dto.calculation.edit.update.data;
import com.fasterxml.jackson.annotation.JsonProperty;
import de.avatic.lcc.dto.calculation.edit.update.MasterData;
import de.avatic.lcc.dto.generic.DimensionDTO;
public class AllUpdateDTO implements MasterData {
private Number price;
@JsonProperty("oversea_share")
private Number overseaShare;
@JsonProperty("fca_fee_included")
private Boolean includeFcaFee;
@JsonProperty("handling_unit")
private DimensionDTO dimensions;
@JsonProperty("is_mixable")
private Boolean isMixable;
@JsonProperty("is_stackable")
private Boolean isStackable;
@JsonProperty("part_number")
private String partNumber;
@JsonProperty("hs_code")
private String hsCode;
@JsonProperty("tariff_rate")
private Number tariffRate ;
public Number getPrice() {
return price;
}
public void setPrice(Number price) {
this.price = price;
}
public Number getOverseaShare() {
return overseaShare;
}
public void setOverseaShare(Number overseaShare) {
this.overseaShare = overseaShare;
}
public Boolean getIncludeFcaFee() {
return includeFcaFee;
}
public void setIncludeFcaFee(Boolean includeFcaFee) {
this.includeFcaFee = includeFcaFee;
}
public DimensionDTO getDimensions() {
return dimensions;
}
public void setDimensions(DimensionDTO dimensions) {
this.dimensions = dimensions;
}
public Boolean getMixable() {
return isMixable;
}
public void setMixable(Boolean mixable) {
isMixable = mixable;
}
public Boolean getStackable() {
return isStackable;
}
public void setStackable(Boolean stackable) {
isStackable = stackable;
}
public String getPartNumber() {
return partNumber;
}
public void setPartNumber(String partNumber) {
this.partNumber = partNumber;
}
public String getHsCode() {
return hsCode;
}
public void setHsCode(String hsCode) {
this.hsCode = hsCode;
}
public Number getTariffRate() {
return tariffRate;
}
public void setTariffRate(Number tariffRate) {
this.tariffRate = tariffRate;
}
}

View file

@ -1,6 +1,7 @@
package de.avatic.lcc.dto.configuration.nodes.userNodes; package de.avatic.lcc.dto.configuration.nodes.userNodes;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import de.avatic.lcc.dto.generic.CountryDTO;
import de.avatic.lcc.dto.generic.LocationDTO; import de.avatic.lcc.dto.generic.LocationDTO;
import de.avatic.lcc.dto.generic.NodeType; import de.avatic.lcc.dto.generic.NodeType;
@ -11,6 +12,15 @@ public class AddUserNodeDTO {
private String name; private String name;
private String address; private String address;
private LocationDTO location; private LocationDTO location;
private CountryDTO country;
public CountryDTO getCountry() {
return country;
}
public void setCountry(CountryDTO country) {
this.country = country;
}
public String getName() { public String getName() {
return name; return name;

View file

@ -1,6 +1,6 @@
package de.avatic.lcc.model.calculations; package de.avatic.lcc.model.calculations;
import de.avatic.lcc.model.premisses.Premiss; import de.avatic.lcc.model.premises.Premise;
import de.avatic.lcc.model.properties.PropertySet; import de.avatic.lcc.model.properties.PropertySet;
import de.avatic.lcc.model.user.SysUser; import de.avatic.lcc.model.user.SysUser;
import de.avatic.lcc.model.rates.ValidityPeriod; import de.avatic.lcc.model.rates.ValidityPeriod;
@ -26,7 +26,7 @@ public class CalculationJob {
private CalculationJobState jobState; private CalculationJobState jobState;
@NotNull @NotNull
private AggregateReference<Premiss,Integer> premiss; private AggregateReference<Premise,Integer> premiss;
@NotNull @NotNull
private AggregateReference<ValidityPeriod, Integer> validityPeriod; private AggregateReference<ValidityPeriod, Integer> validityPeriod;
@ -64,11 +64,11 @@ public class CalculationJob {
this.jobState = jobState; this.jobState = jobState;
} }
public AggregateReference<Premiss, Integer> getPremiss() { public AggregateReference<Premise, Integer> getPremiss() {
return premiss; return premiss;
} }
public void setPremiss(AggregateReference<Premiss, Integer> premiss) { public void setPremiss(AggregateReference<Premise, Integer> premiss) {
this.premiss = premiss; this.premiss = premiss;
} }

View file

@ -1,6 +1,6 @@
package de.avatic.lcc.model.calculations; package de.avatic.lcc.model.calculations;
import de.avatic.lcc.model.premisses.PremissRouteSection; import de.avatic.lcc.model.premises.route.RouteSection;
import jakarta.validation.constraints.Digits; import jakarta.validation.constraints.Digits;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
@ -57,7 +57,7 @@ public class CalculationJobRouteSection {
private Integer transitTime; private Integer transitTime;
@NotNull @NotNull
private AggregateReference<PremissRouteSection, Integer> premissRouteSection; private AggregateReference<RouteSection, Integer> premissRouteSection;
public Integer getId() { public Integer getId() {
return id; return id;
@ -119,11 +119,11 @@ public class CalculationJobRouteSection {
this.transitTime = transitTime; this.transitTime = transitTime;
} }
public AggregateReference<PremissRouteSection, Integer> getPremissRouteSection() { public AggregateReference<RouteSection, Integer> getPremissRouteSection() {
return premissRouteSection; return premissRouteSection;
} }
public void setPremissRouteSection(AggregateReference<PremissRouteSection, Integer> premissRouteSection) { public void setPremissRouteSection(AggregateReference<RouteSection, Integer> premissRouteSection) {
this.premissRouteSection = premissRouteSection; this.premissRouteSection = premissRouteSection;
} }

View file

@ -1,6 +1,6 @@
package de.avatic.lcc.model.calculations; package de.avatic.lcc.model.calculations;
import de.avatic.lcc.model.premisses.PremissSink; import de.avatic.lcc.model.premises.route.Destination;
import jakarta.validation.constraints.Digits; import jakarta.validation.constraints.Digits;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jdk.jfr.Unsigned; import jdk.jfr.Unsigned;
@ -29,7 +29,7 @@ public class CalculationJobSink {
private BigDecimal totalCost; private BigDecimal totalCost;
@NotNull @NotNull
private AggregateReference<PremissSink, Integer> premissSink; private AggregateReference<Destination, Integer> premissSink;
@MappedCollection @MappedCollection
@ -83,11 +83,11 @@ public class CalculationJobSink {
this.totalCost = totalCost; this.totalCost = totalCost;
} }
public AggregateReference<PremissSink, Integer> getPremissSink() { public AggregateReference<Destination, Integer> getPremissSink() {
return premissSink; return premissSink;
} }
public void setPremissSink(AggregateReference<PremissSink, Integer> premissSink) { public void setPremissSink(AggregateReference<Destination, Integer> premissSink) {
this.premissSink = premissSink; this.premissSink = premissSink;
} }

View file

@ -8,7 +8,7 @@ public class NodeListEntry {
private String name; private String name;
private CountryListEntry country; private CountryListEntry country;
private String address; private String address;
private Boolean isSink; private Boolean isDestination;
private Boolean isSource; private Boolean isSource;
private Boolean isIntermediate; private Boolean isIntermediate;
private Boolean isDeprecated; private Boolean isDeprecated;
@ -45,12 +45,12 @@ public class NodeListEntry {
this.address = address; this.address = address;
} }
public Boolean getSink() { public Boolean getDestination() {
return isSink; return isDestination;
} }
public void setSink(Boolean sink) { public void setDestination(Boolean destination) {
isSink = sink; isDestination = destination;
} }
public Boolean getSource() { public Boolean getSource() {

View file

@ -1,35 +1,25 @@
package de.avatic.lcc.model.premisses; package de.avatic.lcc.model.premises;
import de.avatic.lcc.model.materials.Material;
import de.avatic.lcc.model.nodes.Node;
import de.avatic.lcc.model.packaging.Packaging;
import de.avatic.lcc.model.utils.DimensionUnit; import de.avatic.lcc.model.utils.DimensionUnit;
import de.avatic.lcc.model.utils.WeightUnit; import de.avatic.lcc.model.utils.WeightUnit;
import de.avatic.lcc.model.user.SysUser;
import jakarta.validation.constraints.Digits; import jakarta.validation.constraints.Digits;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size; import jakarta.validation.constraints.Size;
import jdk.jfr.Unsigned; import jdk.jfr.Unsigned;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.mapping.AggregateReference;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.MappedCollection;
import org.springframework.data.relational.core.mapping.Table;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.OffsetDateTime; import java.time.LocalDateTime;
import java.util.Set;
@Table(name = "premiss") public class Premise {
public class Premiss {
@Id @Id
private Integer id; private Integer id;
private OffsetDateTime createdAt; private LocalDateTime createdAt;
private OffsetDateTime updatedAt; private LocalDateTime updatedAt;
@Digits(integer = 15, fraction = 2) @Digits(integer = 15, fraction = 2)
private BigDecimal materialCost; private BigDecimal materialCost;
@ -46,7 +36,7 @@ public class Premiss {
private BigDecimal customRate; private BigDecimal customRate;
@Size(max = 16) @Size(max = 16)
private PremissState state; private PremiseState state;
@Unsigned @Unsigned
private Integer individualHuLength; private Integer individualHuLength;
@ -60,50 +50,28 @@ public class Premiss {
@Unsigned @Unsigned
private Integer individualHuWeight; private Integer individualHuWeight;
@Size(max = 2)
private DimensionUnit huDisplayedDimensionUnit; private DimensionUnit huDisplayedDimensionUnit;
@Size(max = 2)
private WeightUnit huDisplayedWeightUnit; private WeightUnit huDisplayedWeightUnit;
@Unsigned @Unsigned
private Integer huUnitCount; private Integer huUnitCount;
private Boolean huStackable; private Boolean huStackable;
private Boolean huMixable; private Boolean huMixable;
@MappedCollection(idColumn = "premiss_id")
private Set<PremissSink> sinks;
@NotNull @NotNull
@Column("material_id") private Integer materialId;
private AggregateReference<Material, Integer> material;
@Column("supplier_node_id") private Integer supplierNodeId;
private AggregateReference<Node, Integer> supplierNode;
@Column("user_supplier_node_id") private Integer userSupplierNodeId;
private AggregateReference<Node, Integer> userSupplierNode;
@Column("packaging_id") private Integer packagingId;
private Packaging packaging;
@NotNull private Integer userId;
private AggregateReference<SysUser, Integer> user;
@MappedCollection(idColumn = "premiss_id")
private Set<PremissSink> premissPremissSinks;
public Set<PremissSink> getSinks() {
return sinks;
}
public void setSinks(Set<PremissSink> sinks) {
this.sinks = sinks;
}
public Integer getId() { public Integer getId() {
return id; return id;
@ -113,19 +81,19 @@ public class Premiss {
this.id = id; this.id = id;
} }
public OffsetDateTime getCreatedAt() { public LocalDateTime getCreatedAt() {
return createdAt; return createdAt;
} }
public void setCreatedAt(OffsetDateTime createdAt) { public void setCreatedAt(LocalDateTime createdAt) {
this.createdAt = createdAt; this.createdAt = createdAt;
} }
public OffsetDateTime getUpdatedAt() { public LocalDateTime getUpdatedAt() {
return updatedAt; return updatedAt;
} }
public void setUpdatedAt(OffsetDateTime updatedAt) { public void setUpdatedAt(LocalDateTime updatedAt) {
this.updatedAt = updatedAt; this.updatedAt = updatedAt;
} }
@ -169,11 +137,11 @@ public class Premiss {
this.customRate = customRate; this.customRate = customRate;
} }
public PremissState getState() { public PremiseState getState() {
return state; return state;
} }
public void setState(PremissState state) { public void setState(PremiseState state) {
this.state = state; this.state = state;
} }
@ -209,7 +177,7 @@ public class Premiss {
this.individualHuWeight = individualHuWeight; this.individualHuWeight = individualHuWeight;
} }
public DimensionUnit getHuDisplayedDimensionUnit() { public DimensionUnit getDimensionUnit() {
return huDisplayedDimensionUnit; return huDisplayedDimensionUnit;
} }
@ -217,7 +185,7 @@ public class Premiss {
this.huDisplayedDimensionUnit = huDisplayedDimensionUnit; this.huDisplayedDimensionUnit = huDisplayedDimensionUnit;
} }
public WeightUnit getHuDisplayedWeightUnit() { public WeightUnit getWeightUnit() {
return huDisplayedWeightUnit; return huDisplayedWeightUnit;
} }
@ -249,51 +217,43 @@ public class Premiss {
this.huMixable = huMixable; this.huMixable = huMixable;
} }
public AggregateReference<Material, Integer> getMaterial() { public Integer getMaterialId() {
return material; return materialId;
} }
public void setMaterial(AggregateReference<Material, Integer> material) { public void setMaterialId(Integer materialId) {
this.material = material; this.materialId = materialId;
} }
public AggregateReference<Node, Integer> getSupplierNode() { public Integer getSupplierNodeId() {
return supplierNode; return supplierNodeId;
} }
public void setSupplierNode(AggregateReference<Node, Integer> supplierNode) { public void setSupplierNodeId(Integer supplierNodeId) {
this.supplierNode = supplierNode; this.supplierNodeId = supplierNodeId;
} }
public AggregateReference<Node, Integer> getUserSupplierNode() { public Integer getUserSupplierNodeId() {
return userSupplierNode; return userSupplierNodeId;
} }
public void setUserSupplierNode(AggregateReference<Node, Integer> userSupplierNode) { public void setUserSupplierNodeId(Integer userSupplierNodeId) {
this.userSupplierNode = userSupplierNode; this.userSupplierNodeId = userSupplierNodeId;
} }
public Packaging getPackaging() { public Integer getPackagingId() {
return packaging; return packagingId;
} }
public void setPackaging(Packaging packaging) { public void setPackagingId(Integer packagingId) {
this.packaging = packaging; this.packagingId = packagingId;
} }
public AggregateReference<SysUser, Integer> getUser() { public Integer getUserId() {
return user; return userId;
} }
public void setUser(AggregateReference<SysUser, Integer> user) { public void setUserId(Integer userId) {
this.user = user; this.userId = userId;
}
public Set<PremissSink> getPremissPremissSinks() {
return premissPremissSinks;
}
public void setPremissPremissSinks(Set<PremissSink> premissPremissSinks) {
this.premissPremissSinks = premissPremissSinks;
} }
} }

View file

@ -0,0 +1,163 @@
package de.avatic.lcc.model.premises;
import de.avatic.lcc.dto.calculation.PremiseState;
import de.avatic.lcc.model.materials.Material;
import java.math.BigDecimal;
import java.time.LocalDateTime;
public class PremiseListEntry {
private Integer id;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private PremiseState state;
private Material material;
private boolean isUserSupplier;
private Integer supplierId;
private String supplierName;
private Integer supplierCountryId;
private String supplierAddress;
private BigDecimal supplierGeoLongitude;
private BigDecimal supplierGeoLatitude;
private boolean supplierIsDestination;
private boolean supplierIsSource;
private boolean supplierIsIntermediate;
private Integer ownerId;
public BigDecimal getSupplierGeoLongitude() {
return supplierGeoLongitude;
}
public void setSupplierGeoLongitude(BigDecimal supplierGeoLongitude) {
this.supplierGeoLongitude = supplierGeoLongitude;
}
public BigDecimal getSupplierGeoLatitude() {
return supplierGeoLatitude;
}
public void setSupplierGeoLatitude(BigDecimal supplierGeoLatitude) {
this.supplierGeoLatitude = supplierGeoLatitude;
}
public boolean isSupplierIsDestination() {
return supplierIsDestination;
}
public void setSupplierIsDestination(boolean supplierIsDestination) {
this.supplierIsDestination = supplierIsDestination;
}
public boolean isSupplierIsSource() {
return supplierIsSource;
}
public void setSupplierIsSource(boolean supplierIsSource) {
this.supplierIsSource = supplierIsSource;
}
public boolean isSupplierIsIntermediate() {
return supplierIsIntermediate;
}
public void setSupplierIsIntermediate(boolean supplierIsIntermediate) {
this.supplierIsIntermediate = supplierIsIntermediate;
}
public boolean isUserSupplier() {
return isUserSupplier;
}
public void setUserSupplier(boolean userSupplier) {
isUserSupplier = userSupplier;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public LocalDateTime getCreatedAt() {
return createdAt;
}
public void setCreatedAt(LocalDateTime createdAt) {
this.createdAt = createdAt;
}
public LocalDateTime getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(LocalDateTime updatedAt) {
this.updatedAt = updatedAt;
}
public PremiseState getState() {
return state;
}
public void setState(PremiseState state) {
this.state = state;
}
public Material getMaterial() {
return material;
}
public void setMaterial(Material material) {
this.material = material;
}
public Integer getSupplierId() {
return supplierId;
}
public void setSupplierId(Integer supplierId) {
this.supplierId = supplierId;
}
public String getSupplierName() {
return supplierName;
}
public void setSupplierName(String supplierName) {
this.supplierName = supplierName;
}
public Integer getSupplierCountryId() {
return supplierCountryId;
}
public void setSupplierCountryId(Integer supplierCountryId) {
this.supplierCountryId = supplierCountryId;
}
public String getSupplierAddress() {
return supplierAddress;
}
public void setSupplierAddress(String supplierAddress) {
this.supplierAddress = supplierAddress;
}
public Integer getOwnerId() {
return ownerId;
}
public void setOwnerId(Integer ownerId) {
this.ownerId = ownerId;
}
}

View file

@ -0,0 +1,6 @@
package de.avatic.lcc.model.premises;
public enum PremiseState {
DRAFT, COMPLETED, ARCHIVED, DELETED
}

View file

@ -0,0 +1,97 @@
package de.avatic.lcc.model.premises.route;
import java.math.BigDecimal;
public class Destination {
private Integer id;
private Integer premiseId;
private BigDecimal annualAmount;
private Integer destinationNodeId;
private BigDecimal rateD2d;
private Boolean isD2d;
private BigDecimal repackingCost;
private BigDecimal handlingCost;
private BigDecimal disposalCost;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getPremiseId() {
return premiseId;
}
public void setPremiseId(Integer premiseId) {
this.premiseId = premiseId;
}
public BigDecimal getAnnualAmount() {
return annualAmount;
}
public void setAnnualAmount(BigDecimal annualAmount) {
this.annualAmount = annualAmount;
}
public Integer getDestinationNodeId() {
return destinationNodeId;
}
public void setDestinationNodeId(Integer destinationNodeId) {
this.destinationNodeId = destinationNodeId;
}
public BigDecimal getRateD2d() {
return rateD2d;
}
public void setRateD2d(BigDecimal rateD2d) {
this.rateD2d = rateD2d;
}
public Boolean getD2d() {
return isD2d;
}
public void setD2d(Boolean d2d) {
isD2d = d2d;
}
public BigDecimal getRepackingCost() {
return repackingCost;
}
public void setRepackingCost(BigDecimal repackingCost) {
this.repackingCost = repackingCost;
}
public BigDecimal getHandlingCost() {
return handlingCost;
}
public void setHandlingCost(BigDecimal handlingCost) {
this.handlingCost = handlingCost;
}
public BigDecimal getDisposalCost() {
return disposalCost;
}
public void setDisposalCost(BigDecimal disposalCost) {
this.disposalCost = disposalCost;
}
}

View file

@ -0,0 +1,54 @@
package de.avatic.lcc.model.premises.route;
public class Route {
private Integer id;
private Boolean isFastest;
private Boolean isCheapest;
private Boolean isSelected;
private Integer destinationId;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Boolean getFastest() {
return isFastest;
}
public void setFastest(Boolean fastest) {
isFastest = fastest;
}
public Boolean getCheapest() {
return isCheapest;
}
public void setCheapest(Boolean cheapest) {
isCheapest = cheapest;
}
public Boolean getSelected() {
return isSelected;
}
public void setSelected(Boolean selected) {
isSelected = selected;
}
public Integer getDestinationId() {
return destinationId;
}
public void setDestinationId(Integer destinationId) {
this.destinationId = destinationId;
}
}

View file

@ -1,49 +1,34 @@
package de.avatic.lcc.model.premisses; package de.avatic.lcc.model.premises.route;
import de.avatic.lcc.model.nodes.Node;
import de.avatic.lcc.model.user.SysUserNode;
import jakarta.validation.constraints.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.mapping.AggregateReference;
import org.springframework.data.relational.core.mapping.Table;
import java.math.BigDecimal; import java.math.BigDecimal;
@Table(name = "premiss_route_node") public class RouteNode {
public class PremissRouteNode {
@Id
private Integer id; private Integer id;
@NotNull
@Size(max = 255)
private String name; private String name;
@Size(max = 500)
private String address; private String address;
private Boolean isSink; private Boolean isDestination;
private Boolean isIntermediate; private Boolean isIntermediate;
private Boolean isSource; private Boolean isSource;
@DecimalMin("-90")
@DecimalMax("90")
@Digits(integer = 7, fraction = 4)
private BigDecimal geoLat; private BigDecimal geoLat;
@DecimalMin("-180")
@DecimalMax("180")
@Digits(integer = 7, fraction = 4)
private BigDecimal geoLng; private BigDecimal geoLng;
private Boolean isOutdated; private Boolean isOutdated;
private AggregateReference<Node,Integer> node; private Integer nodeId;
private Integer userNodeId;
private Integer countryId;
private AggregateReference<SysUserNode,Integer> userNode;
public Integer getId() { public Integer getId() {
return id; return id;
@ -69,12 +54,12 @@ public class PremissRouteNode {
this.address = address; this.address = address;
} }
public Boolean getSink() { public Boolean getDestination() {
return isSink; return isDestination;
} }
public void setSink(Boolean sink) { public void setDestination(Boolean destination) {
isSink = sink; isDestination = destination;
} }
public Boolean getIntermediate() { public Boolean getIntermediate() {
@ -117,19 +102,29 @@ public class PremissRouteNode {
isOutdated = outdated; isOutdated = outdated;
} }
public AggregateReference<Node, Integer> getNode() { public Integer getNodeId() {
return node; return nodeId;
} }
public void setNode(AggregateReference<Node, Integer> node) { public void setNodeId(Integer nodeId) {
this.node = node; if (nodeId == 0) this.nodeId = null;
else this.nodeId = nodeId;
} }
public AggregateReference<SysUserNode, Integer> getUserNode() { public Integer getUserNodeId() {
return userNode; return userNodeId;
} }
public void setUserNode(AggregateReference<SysUserNode, Integer> userNode) { public void setUserNodeId(Integer userNodeId) {
this.userNode = userNode; if (userNodeId == 0) this.userNodeId = null;
else this.userNodeId = userNodeId;
}
public Integer getCountryId() {
return countryId;
}
public void setCountryId(Integer countryId) {
this.countryId = countryId;
} }
} }

View file

@ -0,0 +1,107 @@
package de.avatic.lcc.model.premises.route;
import de.avatic.lcc.dto.generic.RouteType;
public class RouteSection {
private Integer id;
private Integer routeId;
private Integer listPosition;
private RouteType transportType;
private Boolean isPreRun;
private Boolean isMainRun;
private Boolean isPostRun;
private Boolean isOutdated;
private Integer fromRouteNodeId;
private Integer toRouteNodeId;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getRouteId() {
return routeId;
}
public void setRouteId(Integer routeId) {
this.routeId = routeId;
}
public Integer getListPosition() {
return listPosition;
}
public void setListPosition(Integer listPosition) {
this.listPosition = listPosition;
}
public RouteType getTransportType() {
return transportType;
}
public void setTransportType(RouteType transportType) {
this.transportType = transportType;
}
public Boolean getPreRun() {
return isPreRun;
}
public void setPreRun(Boolean preRun) {
isPreRun = preRun;
}
public Boolean getMainRun() {
return isMainRun;
}
public void setMainRun(Boolean mainRun) {
isMainRun = mainRun;
}
public Boolean getPostRun() {
return isPostRun;
}
public void setPostRun(Boolean postRun) {
isPostRun = postRun;
}
public Boolean getOutdated() {
return isOutdated;
}
public void setOutdated(Boolean outdated) {
isOutdated = outdated;
}
public Integer getFromRouteNodeId() {
return fromRouteNodeId;
}
public void setFromRouteNodeId(Integer fromRouteNodeId) {
this.fromRouteNodeId = fromRouteNodeId;
}
public Integer getToRouteNodeId() {
return toRouteNodeId;
}
public void setToRouteNodeId(Integer toRouteNodeId) {
this.toRouteNodeId = toRouteNodeId;
}
}

View file

@ -0,0 +1,5 @@
package de.avatic.lcc.model.premises.route;
public enum RouteSectionType {
RAIL, SEA, POST_RUN, ROAD, D2D
}

View file

@ -1,87 +0,0 @@
package de.avatic.lcc.model.premisses;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.MappedCollection;
import org.springframework.data.relational.core.mapping.Table;
import java.util.List;
import java.util.Set;
@Table(name = "premiss_route")
public class PremissRoute {
@Id
private Integer id;
private Boolean isFastest;
private Boolean isCheapest;
private Boolean isSelected;
@MappedCollection
private PremissSink premissSink;
@MappedCollection(idColumn = "premiss_route_id", keyColumn = "list_position")
private List<PremissRouteSection> sections;
@MappedCollection(idColumn = "premiss_route_id")
private Set<PremissRouteNode> nodes;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Boolean getFastest() {
return isFastest;
}
public void setFastest(Boolean fastest) {
isFastest = fastest;
}
public Boolean getCheapest() {
return isCheapest;
}
public void setCheapest(Boolean cheapest) {
isCheapest = cheapest;
}
public Boolean getSelected() {
return isSelected;
}
public void setSelected(Boolean selected) {
isSelected = selected;
}
public PremissSink getPremissSink() {
return premissSink;
}
public void setPremissSink(PremissSink premissSink) {
this.premissSink = premissSink;
}
public List<PremissRouteSection> getSections() {
return sections;
}
public void setSections(List<PremissRouteSection> sections) {
this.sections = sections;
}
public Set<PremissRouteNode> getNodes() {
return nodes;
}
public void setNodes(Set<PremissRouteNode> nodes) {
this.nodes = nodes;
}
}

View file

@ -1,122 +0,0 @@
package de.avatic.lcc.model.premisses;
import jakarta.validation.constraints.Digits;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import jdk.jfr.Unsigned;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;
import java.math.BigDecimal;
@Table(name = "premiss_route_section")
public class PremissRouteSection {
@Id
private Integer id;
@Unsigned
@NotNull
private Integer listPosition;
@Size(max = 16)
private PremissRouteSectionType transportType;
@Digits(integer = 15, fraction = 2)
private BigDecimal rateD2d;
private Boolean isPreRun;
private Boolean isMainRun;
private Boolean isPostRun;
private Boolean isOutdated;
@NotNull
private PremissRouteNode fromRouteNode;
@NotNull
private PremissRouteNode toRouteNode;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getListPosition() {
return listPosition;
}
public void setListPosition(Integer listPosition) {
this.listPosition = listPosition;
}
public PremissRouteSectionType getTransportType() {
return transportType;
}
public void setTransportType(PremissRouteSectionType transportType) {
this.transportType = transportType;
}
public BigDecimal getRateD2d() {
return rateD2d;
}
public void setRateD2d(BigDecimal rateD2d) {
this.rateD2d = rateD2d;
}
public Boolean getPreRun() {
return isPreRun;
}
public void setPreRun(Boolean preRun) {
isPreRun = preRun;
}
public Boolean getMainRun() {
return isMainRun;
}
public void setMainRun(Boolean mainRun) {
isMainRun = mainRun;
}
public Boolean getPostRun() {
return isPostRun;
}
public void setPostRun(Boolean postRun) {
isPostRun = postRun;
}
public Boolean getOutdated() {
return isOutdated;
}
public void setOutdated(Boolean outdated) {
isOutdated = outdated;
}
public PremissRouteNode getFromRouteNode() {
return fromRouteNode;
}
public void setFromRouteNode(PremissRouteNode fromRouteNode) {
this.fromRouteNode = fromRouteNode;
}
public PremissRouteNode getToRouteNode() {
return toRouteNode;
}
public void setToRouteNode(PremissRouteNode toRouteNode) {
this.toRouteNode = toRouteNode;
}
}

View file

@ -1,5 +0,0 @@
package de.avatic.lcc.model.premisses;
public enum PremissRouteSectionType {
RAIL, SEA, POST_RUN, ROAD, D2D
}

View file

@ -1,63 +0,0 @@
package de.avatic.lcc.model.premisses;
import de.avatic.lcc.model.nodes.Node;
import jakarta.validation.constraints.NotNull;
import jdk.jfr.Unsigned;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.mapping.AggregateReference;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.MappedCollection;
import org.springframework.data.relational.core.mapping.Table;
import java.util.Set;
@Table(name = "premiss_sink")
public class PremissSink {
@Id
private Integer id;
@Unsigned
@NotNull
private Integer annualAmount;
@NotNull
@Column("sink_node_id")
private AggregateReference<Node,Integer> sinkNode;
@MappedCollection(idColumn = "premiss_sink_id")
private Set<PremissRoute> routes;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getAnnualAmount() {
return annualAmount;
}
public void setAnnualAmount(Integer annualAmount) {
this.annualAmount = annualAmount;
}
public AggregateReference<Node, Integer> getSinkNode() {
return sinkNode;
}
public void setSinkNode(AggregateReference<Node, Integer> sinkNode) {
this.sinkNode = sinkNode;
}
public Set<PremissRoute> getRoutes() {
return routes;
}
public void setRoutes(Set<PremissRoute> routes) {
this.routes = routes;
}
}

View file

@ -1,6 +0,0 @@
package de.avatic.lcc.model.premisses;
public enum PremissState {
DRAFT, COMPLETED, ARCHIVED, DELETED
}

View file

@ -132,6 +132,10 @@ public class NodeRepository {
@Transactional @Transactional
public Optional<Integer> update(Node node) { public Optional<Integer> update(Node node) {
//TODO update predecessors and outbound_countries too //TODO update predecessors and outbound_countries too
//TODO implement correctly
//TODO if node is updated set all linked RouteNodes to outdated!
String query = "UPDATE node SET name = ?, address = ?, country_id = ?, is_source = ?, is_destination = ?, is_intermediate = ?, predecessor_required = ? WHERE id = ?"; String query = "UPDATE node SET name = ?, address = ?, country_id = ?, is_source = ?, is_destination = ?, is_intermediate = ?, predecessor_required = ? WHERE id = ?";
return Optional.ofNullable(jdbcTemplate.update(query, node.getId()) == 0 ? null : node.getId()); return Optional.ofNullable(jdbcTemplate.update(query, node.getId()) == 0 ? null : node.getId());
} }

View file

@ -0,0 +1,58 @@
package de.avatic.lcc.repositories.premise;
import de.avatic.lcc.model.premises.route.Destination;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Optional;
@Service
public class DestinationRepository {
private final JdbcTemplate jdbcTemplate;
public DestinationRepository(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public Optional<Destination> getById(Integer id) {
String query = "SELECT * FROM premise_destination WHERE id = ?";
var destinations = jdbcTemplate.query(query, new DestinationMapper(), id);
if (destinations.isEmpty())
return Optional.empty();
else
return Optional.of(destinations.getFirst());
}
public List<Destination> getByPremiseId(Integer id) {
String query = "SELECT * FROM premise_destination WHERE premise_id = ?";
return jdbcTemplate.query(query, new DestinationMapper(), id);
}
private static class DestinationMapper implements RowMapper<Destination> {
@Override
public Destination mapRow(ResultSet rs, int rowNum) throws SQLException {
Destination entity = new Destination();
entity.setId(rs.getInt("id"));
entity.setAnnualAmount(rs.getBigDecimal("annual_amount"));
entity.setPremiseId(rs.getInt("premise_id"));
entity.setDestinationNodeId(rs.getInt("destination_node_id"));
entity.setRateD2d(rs.getBigDecimal("rate_d2d"));
entity.setD2d(rs.getBoolean("is_d2d"));
entity.setRepackingCost(rs.getBigDecimal("repacking_cost"));
entity.setHandlingCost(rs.getBigDecimal("handling_cost"));
entity.setDisposalCost(rs.getBigDecimal("disposal_cost"));
return entity;
}
}
}

View file

@ -0,0 +1,345 @@
package de.avatic.lcc.repositories.premise;
import de.avatic.lcc.model.materials.Material;
import de.avatic.lcc.model.packaging.PackagingDimension;
import de.avatic.lcc.model.premises.Premise;
import de.avatic.lcc.model.premises.PremiseListEntry;
import de.avatic.lcc.model.premises.PremiseState;
import de.avatic.lcc.model.utils.DimensionUnit;
import de.avatic.lcc.model.utils.WeightUnit;
import de.avatic.lcc.repositories.pagination.SearchQueryPagination;
import de.avatic.lcc.repositories.pagination.SearchQueryResult;
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.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
@Repository
public class PremiseRepository {
private final JdbcTemplate jdbcTemplate;
public PremiseRepository(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public SearchQueryResult<PremiseListEntry> listPremises(String filter, SearchQueryPagination pagination, Integer userId, Boolean deleted, Boolean archived, Boolean done) {
String query = buildQuery(filter, deleted, archived, done);
String countQuery = buildCountQuery(filter, deleted, archived, done);
List<PremiseListEntry> entities = null;
Integer totalCount = 0;
if (filter == null || filter.isBlank()) {
entities = jdbcTemplate.query(query, new PremiseListEntryMapper(), userId, pagination.getLimit(), pagination.getOffset());
totalCount = jdbcTemplate.queryForObject(countQuery, Integer.class, userId);
} else {
entities = jdbcTemplate.query(query, new PremiseListEntryMapper(), userId, "%" + filter + "%", "%" + filter + "%", "%" + filter + "%", "%" + filter + "%", "%" + filter + "%", "%" + filter + "%", "%" + filter + "%", pagination.getLimit(), pagination.getOffset());
totalCount = jdbcTemplate.queryForObject(countQuery, Integer.class, userId, "%" + filter + "%", "%" + filter + "%", "%" + filter + "%", "%" + filter + "%", "%" + filter + "%", "%" + filter + "%", "%" + filter + "%");
}
return new SearchQueryResult<>(entities, pagination.getPage(), totalCount, pagination.getLimit());
}
private String buildCountQuery(String filter, Boolean deleted, Boolean archived, Boolean done) {
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append("""
SELECT COUNT(*) FROM premise AS p
LEFT JOIN material as m ON p.material_id = m.id
LEFT JOIN node as n ON p.supplier_node_id = n.id
LEFT JOIN sys_user_node as user_n ON p.user_supplier_node_id = user_n.id
WHERE p.userId = ?""");
if (filter != null && !filter.isBlank()) {
queryBuilder.append(" AND (n.name LIKE ? OR n.external_mapping_id LIKE ? OR n.note LIKE ? OR user_n.name LIKE ? OR m.name LIKE ? OR m.description LIKE ? OR m.part_number LIKE ?)");
}
if (deleted != null && deleted) {
queryBuilder.append(" AND p.deleted = TRUE");
}
if (archived != null && archived) {
queryBuilder.append(" AND p.archived = TRUE");
}
if (done != null && done) {
queryBuilder.append(" AND p.done = TRUE");
}
return queryBuilder.toString();
}
private String buildQuery(String filter, Boolean deleted, Boolean archived, Boolean done) {
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append("""
SELECT * FROM premise AS p
LEFT JOIN material as m ON p.material_id = m.id
LEFT JOIN node as n ON p.supplier_node_id = n.id
LEFT JOIN sys_user_node as user_n ON p.user_supplier_node_id = user_n.id
WHERE p.userId = ?""");
if (filter != null && !filter.isBlank()) {
queryBuilder.append(" AND (n.name LIKE ? OR n.external_mapping_id LIKE ? OR n.note LIKE ? OR user_n.name LIKE ? OR m.name LIKE ? OR m.description LIKE ? OR m.part_number LIKE ?)");
}
if (deleted != null && deleted) {
queryBuilder.append(" AND p.deleted = TRUE");
}
if (archived != null && archived) {
queryBuilder.append(" AND p.archived = TRUE");
}
if (done != null && done) {
queryBuilder.append(" AND p.done = TRUE");
}
queryBuilder.append(" LIMIT ? OFFSET ?");
queryBuilder.append(" ORDER BY p.updated_at DESC");
return queryBuilder.toString();
}
public List<Premise> getPremisesById(List<Integer> premiseIds) {
String placeholders = String.join(",", Collections.nCopies(premiseIds.size(), "?"));
String query = """
SELECT * FROM premise
WHERE id IN (""" + placeholders + ")";
return jdbcTemplate.query(
query,
ps -> {
for (int parameterIndex = 0; parameterIndex < premiseIds.size(); parameterIndex++) {
ps.setInt(parameterIndex + 1, premiseIds.get(parameterIndex));
}
},
new PremiseMapper()
);
}
public Optional<Premise> getPremiseById(Integer id) {
String query = """
SELECT * FROM premise
WHERE id = ?""";
var premises = jdbcTemplate.query(query, new PremiseMapper(), id);
if (premises.isEmpty()) {
return Optional.empty();
} else {
return Optional.of(premises.getFirst());
}
}
@Transactional
public void updatePackaging(List<Integer> premiseIds, Integer userId, PackagingDimension dimensionEntity, Boolean stackable, Boolean mixable) {
String placeholders = String.join(",", Collections.nCopies(premiseIds.size(), "?"));
String query = """
UPDATE premise
SET individual_hu_length = ?,
individual_hu_height = ?,
individual_hu_width = ?,
individual_hu_weight = ?,
hu_displayed_dimension_unit = ?,
hu_displayed_weight_unit = ?,
hu_unit_count = ?,
hu_stackable = ?,
hu_mixable = ?,
WHERE user_id = ? AND id IN (""" + placeholders + ")" ;
jdbcTemplate.update(
query,
ps -> {
ps.setInt(1, dimensionEntity.getLength());
ps.setInt(2, dimensionEntity.getHeight());
ps.setInt(3, dimensionEntity.getWidth());
ps.setInt(4, dimensionEntity.getWeight());
ps.setString(5, dimensionEntity.getDimensionUnit().name());
ps.setString(6, dimensionEntity.getWeightUnit().name());
ps.setInt(7, dimensionEntity.getContentUnitCount());
ps.setBoolean(8, stackable);
ps.setBoolean(9, mixable);
ps.setInt(10, userId);
for (int parameterIndex = 0; parameterIndex <= premiseIds.size(); parameterIndex++) {
ps.setInt(parameterIndex+10, premiseIds.get(parameterIndex));
}
}
);
}
public void updateMaterial(List<Integer> premiseIds, Integer userId, String hsCode, BigDecimal tariffRate) {
String placeholders = String.join(",", Collections.nCopies(premiseIds.size(), "?"));
String query = """
UPDATE premise
SET hs_code = ?,
tariff_rate = ?
WHERE user_id = ? id IN ("""+placeholders+")";
jdbcTemplate.update(
query,
ps -> {
ps.setString(1, hsCode);
ps.setBigDecimal(2, tariffRate);
ps.setInt(3, userId);
for (int parameterIndex = 0; parameterIndex <= premiseIds.size(); parameterIndex++) {
ps.setInt(parameterIndex+3, premiseIds.get(parameterIndex));
}
}
);
}
public void updatePrice(List<Integer> premiseIds, int userId, BigDecimal price, Boolean includeFcaFee, BigDecimal overseaShare) {
String placeholders = String.join(",", Collections.nCopies(premiseIds.size(), "?"));
String query = """
UPDATE premise
SET price = ?,
is_fca_enabled = ?,
oversea_share = ?
WHERE user_id = ? AND id IN ("""+placeholders+")";
jdbcTemplate.update(
query,
ps -> {
ps.setBigDecimal(1, price);
ps.setBoolean(2, includeFcaFee);
ps.setBigDecimal(3, overseaShare);
ps.setInt(4, userId);
for (int parameterIndex = 0; parameterIndex <= premiseIds.size(); parameterIndex++) {
ps.setInt(parameterIndex+4, premiseIds.get(parameterIndex));
}
}
);
}
private static class PremiseListEntryMapper implements RowMapper<PremiseListEntry> {
@Override
public PremiseListEntry mapRow(ResultSet rs, int rowNum) throws SQLException {
PremiseListEntry entity = new PremiseListEntry();
entity.setId(rs.getInt("p.id"));
entity.setState(de.avatic.lcc.dto.calculation.PremiseState.valueOf(rs.getString("p.state")));
entity.setOwnerId(rs.getInt("p.user_id"));
entity.setCreatedAt(rs.getTimestamp("p.created_at").toLocalDateTime());
entity.setUpdatedAt(rs.getTimestamp("p.created_at").toLocalDateTime());
entity.setMaterial(mapMaterial(rs));
if (rs.getInt("p.supplier_node_id") != 0) {
entity.setSupplierId(rs.getInt("n.id"));
entity.setSupplierName(rs.getString("n.name"));
entity.setSupplierAddress(rs.getString("n.address"));
entity.setSupplierCountryId(rs.getInt("n.country_id"));
entity.setUserSupplier(false);
entity.setSupplierGeoLatitude(rs.getBigDecimal("n.geo_latitude"));
entity.setSupplierGeoLongitude(rs.getBigDecimal("n.geo_longitude"));
entity.setSupplierIsDestination(rs.getBoolean("n.is_destination"));
entity.setSupplierIsIntermediate(rs.getBoolean("n.is_intermediate"));
entity.setSupplierIsSource(rs.getBoolean("n.is_source"));
} else if (rs.getInt("p.user_supplier_node_id") != 0) {
entity.setSupplierId(rs.getInt("user_n.id"));
entity.setSupplierName(rs.getString("user_n.name"));
entity.setSupplierAddress(rs.getString("user_n.address"));
entity.setSupplierCountryId(rs.getInt("user_n.country_id"));
entity.setUserSupplier(false);
entity.setSupplierGeoLatitude(rs.getBigDecimal("user_n.geo_latitude"));
entity.setSupplierGeoLongitude(rs.getBigDecimal("user_n.geo_longitude"));
entity.setSupplierIsDestination(rs.getBoolean("user_n.is_destination"));
entity.setSupplierIsIntermediate(rs.getBoolean("user_n.is_intermediate"));
entity.setSupplierIsSource(rs.getBoolean("user_n.is_source"));
}
return entity;
}
private Material mapMaterial(ResultSet rs) throws SQLException {
var data = new Material();
data.setId(rs.getInt("m.id"));
data.setName(rs.getString("m.name"));
data.setDeprecated(rs.getBoolean("m.is_deprecated"));
data.setHsCode(rs.getString("m.hs_code"));
data.setPartNumber(rs.getString("m.part_number"));
return data;
}
}
private static class PremiseMapper implements RowMapper<Premise> {
@Override
public Premise mapRow(ResultSet rs, int rowNum) throws SQLException {
var entity = new Premise();
entity.setId(rs.getInt("id"));
entity.setPackagingId(rs.getInt("packaging_id"));
entity.setMaterialId(rs.getInt("material_id"));
entity.setSupplierNodeId(rs.getInt("supplier_node_id"));
entity.setUserSupplierNodeId(rs.getInt("user_supplier_node_id"));
entity.setUserId(rs.getInt("user_id"));
entity.setMaterialCost(rs.getBigDecimal("material_cost"));
entity.setHsCode(rs.getString("hs_code"));
entity.setCustomRate(rs.getBigDecimal("tariff_rate"));
entity.setFcaEnabled(rs.getBoolean("is_fca_enabled"));
entity.setOverseaShare(rs.getBigDecimal("oversea_share"));
entity.setIndividualHuHeight(rs.getInt("individual_hu_height"));
entity.setIndividualHuWidth(rs.getInt("individual_hu_width"));
entity.setIndividualHuLength(rs.getInt("individual_hu_length"));
entity.setIndividualHuWeight(rs.getInt("individual_hu_weight"));
entity.setHuDisplayedDimensionUnit(DimensionUnit.valueOf(rs.getString("hu_displayed_dimension_unit")));
entity.setHuDisplayedWeightUnit(WeightUnit.valueOf(rs.getString("hu_displayed_weight_unit")));
entity.setHuStackable(rs.getBoolean("hu_stackable"));
entity.setHuMixable(rs.getBoolean("hu_mixable"));
entity.setHuUnitCount(rs.getInt("hu_unit_count"));
entity.setState(PremiseState.valueOf(rs.getString("state")));
entity.setUpdatedAt(rs.getTimestamp("updated_at").toLocalDateTime());
entity.setCreatedAt(rs.getTimestamp("created_at").toLocalDateTime());
return entity;
}
}
}

View file

@ -0,0 +1,59 @@
package de.avatic.lcc.repositories.premise;
import de.avatic.lcc.model.premises.route.RouteNode;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Optional;
@Repository
public class RouteNodeRepository {
private final JdbcTemplate jdbcTemplate;
public RouteNodeRepository(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public Optional<RouteNode> getById(Integer id) {
String query = "SELECT * FROM premise_route_node WHERE id = ?";
List<RouteNode> nodes = jdbcTemplate.query(query, new RouteNodeMapper(), id);
if(nodes.isEmpty())
return Optional.empty();
else
return Optional.of(nodes.getFirst());
}
private static class RouteNodeMapper implements RowMapper<RouteNode> {
@Override
public RouteNode mapRow(ResultSet rs, int rowNum) throws SQLException {
RouteNode entity = new RouteNode();
entity.setId(rs.getInt("id"));
entity.setName(rs.getString("name"));
entity.setAddress(rs.getString("address"));
entity.setGeoLat(rs.getBigDecimal("geo_lat"));
entity.setGeoLng(rs.getBigDecimal("geo_lng"));
entity.setDestination(rs.getBoolean("is_destination"));
entity.setIntermediate(rs.getBoolean("is_intermediate"));
entity.setSource(rs.getBoolean("is_source"));
entity.setNodeId(rs.getInt("node_id"));
entity.setUserNodeId(rs.getInt("user_node_id"));
entity.setOutdated(rs.getBoolean("is_outdated"));
return entity;
}
}
}

View file

@ -0,0 +1,40 @@
package de.avatic.lcc.repositories.premise;
import de.avatic.lcc.model.premises.route.Route;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
@Repository
public class RouteRepository {
private final JdbcTemplate jdbcTemplate;
public RouteRepository(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public List<Route> getByDestinationId(Integer id) {
String query = "SELECT * FROM premise_route WHERE premise_destination_id = ?";
return jdbcTemplate.query(query, new RouteMapper(), id);
}
private static class RouteMapper implements RowMapper<Route> {
@Override
public Route mapRow(ResultSet rs, int rowNum) throws SQLException {
Route entity = new Route();
entity.setId(rs.getInt("id"));
entity.setCheapest(rs.getBoolean("is_cheapest"));
entity.setFastest(rs.getBoolean("is_fastest"));
entity.setSelected(rs.getBoolean("is_selected"));
entity.setDestinationId(rs.getInt("premise_destination_id"));
return entity;
}
}
}

View file

@ -0,0 +1,51 @@
package de.avatic.lcc.repositories.premise;
import de.avatic.lcc.dto.generic.RouteType;
import de.avatic.lcc.model.premises.route.RouteSection;
import de.avatic.lcc.model.premises.route.RouteSectionType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
@Repository
public class RouteSectionRepository {
private final JdbcTemplate jdbcTemplate;
public RouteSectionRepository(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public List<RouteSection> getByRouteId(Integer routeId) {
String query = "SELECT * FROM premise_route_section WHERE premise_route_id = ?";
return jdbcTemplate.query(query, new RouteSectionMapper(), routeId);
}
private static class RouteSectionMapper implements RowMapper<RouteSection> {
@Override
public RouteSection mapRow(ResultSet rs, int rowNum) throws SQLException {
RouteSection entity = new RouteSection();
entity.setId(rs.getInt("id"));
entity.setRouteId(rs.getInt("premise_route_id"));
entity.setFromRouteNodeId(rs.getInt("from_route_node_id"));
entity.setToRouteNodeId(rs.getInt("to_route_node_id"));
entity.setListPosition(rs.getInt("list_position"));
entity.setTransportType(RouteType.valueOf(rs.getString("transport_type")));
entity.setPreRun(rs.getBoolean("is_pre_run"));
entity.setMainRun(rs.getBoolean("is_main_run"));
entity.setPostRun(rs.getBoolean("is_post_run"));
entity.setOutdated(rs.getBoolean("is_outdated"));
return entity;
}
}
}

View file

@ -2,9 +2,13 @@ package de.avatic.lcc.repositories.users;
import de.avatic.lcc.model.nodes.Node; import de.avatic.lcc.model.nodes.Node;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection; import java.util.Collection;
import java.util.Optional;
@Repository @Repository
public class UserNodeRepository { public class UserNodeRepository {
@ -16,9 +20,6 @@ public class UserNodeRepository {
this.jdbcTemplate = jdbcTemplate; this.jdbcTemplate = jdbcTemplate;
} }
public Node getUserNode(String userId) {
}
public Collection<Node> searchNode(String filter, int limit, int userId, boolean excludeDeprecated) { public Collection<Node> searchNode(String filter, int limit, int userId, boolean excludeDeprecated) {
@ -30,7 +31,29 @@ public class UserNodeRepository {
queryBuilder.append("LIMIT ?"); queryBuilder.append("LIMIT ?");
return jdbcTemplate.query(queryBuilder.toString(), (rs, rowNum) -> { return jdbcTemplate.query(queryBuilder.toString(), new NodeMapper(), userId, '%' + filter + '%', '%' + filter + '%', limit);
}
public void add(Node node) {
// todo insert user node
}
public Optional<Node> getById(Integer id) {
String query = "SELECT * FROM sys_user_node WHERE id = ?";
var nodes = jdbcTemplate.query(query, new NodeMapper(), id);
if(nodes.isEmpty())
return Optional.empty();
else
return Optional.of(nodes.getFirst());
}
private static class NodeMapper implements RowMapper<Node> {
@Override
public Node mapRow(ResultSet rs, int rowNum) throws SQLException {
var node = new Node(); var node = new Node();
node.setId(rs.getInt("id")); node.setId(rs.getInt("id"));
@ -42,10 +65,7 @@ public class UserNodeRepository {
node.setCountryId(rs.getInt("country_id")); node.setCountryId(rs.getInt("country_id"));
return node; return node;
}, userId, '%'+filter+'%','%'+filter+'%', limit );
}
public void add(Node node) { }
// todo insert user node
} }
} }

View file

@ -5,12 +5,16 @@ import de.avatic.lcc.model.users.User;
import de.avatic.lcc.repositories.pagination.SearchQueryPagination; import de.avatic.lcc.repositories.pagination.SearchQueryPagination;
import de.avatic.lcc.repositories.pagination.SearchQueryResult; import de.avatic.lcc.repositories.pagination.SearchQueryResult;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.GeneratedKeyHolder; import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder; import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -33,22 +37,7 @@ public class UserRepository {
FROM sys_user FROM sys_user
ORDER BY sys_user.workday_id LIMIT ? OFFSET ?"""; ORDER BY sys_user.workday_id LIMIT ? OFFSET ?""";
return new SearchQueryResult<>(jdbcTemplate.query(query, (rs, rowNum) -> { return new SearchQueryResult<>(jdbcTemplate.query(query, new UserMapper(), pagination.getLimit(), pagination.getOffset()), pagination.getPage(), getTotalUserCount(), pagination.getLimit());
var user = new User();
int id = rs.getInt("id");
user.setId(id);
user.setActive(rs.getBoolean("is_active"));
user.setEmail(rs.getString("email"));
user.setFirstName(rs.getString("firstname"));
user.setLastName(rs.getString("lastname"));
user.setWorkdayId(rs.getString("workday_id"));
user.setGroups(getGroupMemberships(id));
return user;
}, pagination.getLimit(), pagination.getOffset()), pagination.getPage(), getTotalUserCount(), pagination.getLimit());
} }
@ -147,8 +136,8 @@ public class UserRepository {
jdbcTemplate.query( jdbcTemplate.query(
query, query,
ps -> { ps -> {
for (int parameterIndex = 1; parameterIndex <= groups.size(); parameterIndex++) { for (int parameterIndex = 0; parameterIndex < groups.size(); parameterIndex++) {
ps.setInt(parameterIndex, groups.get(parameterIndex)); ps.setInt(parameterIndex + 1, groups.get(parameterIndex));
} }
}, },
(rs, rowNum) -> rs.getInt("id") (rs, rowNum) -> rs.getInt("id")
@ -164,4 +153,35 @@ public class UserRepository {
return results.isEmpty() ? null : results.getFirst(); return results.isEmpty() ? null : results.getFirst();
} }
@Transactional
public User getById(Integer id) {
String query = """
SELECT *
FROM sys_user
WHERE id = ?""";
return jdbcTemplate.queryForObject(query, new UserMapper(), id);
}
private class UserMapper implements RowMapper<User> {
@Override
public User mapRow(ResultSet rs, int rowNum) throws SQLException {
var user = new User();
int id = rs.getInt("id");
user.setId(id);
user.setActive(rs.getBoolean("is_active"));
user.setEmail(rs.getString("email"));
user.setFirstName(rs.getString("firstname"));
user.setLastName(rs.getString("lastname"));
user.setWorkdayId(rs.getString("workday_id"));
user.setGroups(getGroupMemberships(id));
return user;
}
}
} }

View file

@ -49,6 +49,7 @@ public class BulkFileProcessingService {
Workbook workbook = new XSSFWorkbook(in); Workbook workbook = new XSSFWorkbook(in);
Sheet sheet = workbook.getSheet(BulkFileTypes.valueOf(type.name()).getSheetName()); Sheet sheet = workbook.getSheet(BulkFileTypes.valueOf(type.name()).getSheetName());
//todo: if processing type = append than merge with current data, if full, delete old data
switch (type) { switch (type) {
case CONTAINER_RATE: case CONTAINER_RATE:
var containerRates = containerRateExcelMapper.extractSheet(sheet); var containerRates = containerRateExcelMapper.extractSheet(sheet);

View file

@ -0,0 +1,43 @@
package de.avatic.lcc.service.calculation;
import de.avatic.lcc.dto.calculation.edit.destination.DestinationCreateDTO;
import de.avatic.lcc.dto.calculation.DestinationDTO;
import de.avatic.lcc.dto.calculation.edit.destination.DestinationUpdateDTO;
import de.avatic.lcc.repositories.premise.DestinationRepository;
import org.springframework.stereotype.Service;
import java.util.HashMap;
@Service
public class DestinationService {
private final DestinationRepository destinationRepository;
public DestinationService(DestinationRepository destinationRepository) {
this.destinationRepository = destinationRepository;
}
public HashMap<Integer, DestinationDTO> createDestination(DestinationCreateDTO destinationCreateDTO) {
// do some checks
// - no duplicates
// do routing.
// create database entries.
return null;
}
public DestinationDTO getDestination(Integer id) {
return null;
}
public void updateDestination(Integer id, DestinationUpdateDTO destinationUpdateDTO) {
//destinationRepository.update(id, destinationUpdateDTO.)
}
public void deleteDestination(Integer id) {
}
}

View file

@ -1,47 +1,117 @@
package de.avatic.lcc.service.calculation; package de.avatic.lcc.service.calculation;
import de.avatic.lcc.dto.calculation.edit.*; import de.avatic.lcc.dto.calculation.PremiseDTO;
import de.avatic.lcc.dto.calculation.edit.update.MasterDataUpdateDTO; import de.avatic.lcc.dto.calculation.edit.PremiseDetailDTO;
import de.avatic.lcc.dto.calculation.edit.update.MasterDataUpdateType; import de.avatic.lcc.dto.calculation.edit.SetDataDTO;
import de.avatic.lcc.dto.calculation.view.PremiseViewDTO; import de.avatic.lcc.dto.calculation.edit.masterData.*;
import de.avatic.lcc.repositories.premise.PremiseRepository;
import de.avatic.lcc.repositories.pagination.SearchQueryPagination;
import de.avatic.lcc.repositories.pagination.SearchQueryResult;
import de.avatic.lcc.service.transformer.generic.DimensionTransformer;
import de.avatic.lcc.service.transformer.premise.PremiseTransformer;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@Service @Service
public class PremisesService { public class PremisesService {
public List<PremiseViewDTO> listPremises(String filter, Integer page, Integer limit, Integer userId, Boolean deleted, Boolean archived, Boolean done) { private final PremiseRepository premiseRepository;
return null; private final PremiseTransformer premiseTransformer;
}; private final DimensionTransformer dimensionTransformer;
public List<PremiseDetailDTO> getPremises(List<Integer> premissIds) { public PremisesService(PremiseRepository premiseRepository, PremiseTransformer premiseTransformer, DimensionTransformer dimensionTransformer) {
return null; this.premiseRepository = premiseRepository;
this.premiseTransformer = premiseTransformer;
this.dimensionTransformer = dimensionTransformer;
}
@Transactional(readOnly = true)
public SearchQueryResult<PremiseDTO> listPremises(String filter, Integer page, Integer limit, Integer userId, Boolean deleted, Boolean archived, Boolean done) {
//TODO check if user is admin. if not: use the user_id of currently authorized user.
var admin = false;
return SearchQueryResult.map(premiseRepository.listPremises(filter, new SearchQueryPagination(page, limit), userId, deleted, archived, done), admin ? premiseTransformer::toPremiseDTOWithUserInfo : premiseTransformer::toPremiseDTO);
}
@Transactional(readOnly = true)
public List<PremiseDetailDTO> getPremises(List<Integer> premiseIds) {
//TODO check if user authorized
var userId = 0;
return premiseRepository.getPremisesById(premiseIds).stream().map(premiseTransformer::toPremiseDetailDTO).toList();
} }
public Integer startCalculation(List<Integer> premises) { public Integer startCalculation(List<Integer> premises) {
} }
public HashMap<String, String> updateMasterData(MasterDataUpdateType type, MasterDataUpdateDTO dto) {
}
public HashMap<Integer, DestinationDTO> createDestination(CreateDestinationDTO createDestinationDTO) { @Transactional
public List<PremiseDetailDTO> setSupplier(SetDataDTO setSupplierDTO) {
//0. check if one of the given premises contains the same part number, and abort if any duplicate would emerge
//1. delete all routes.
//2. recalculate routes
//3 if updateMasterDate is set:
//3.1 copy packaging data (if exists) of new supplier to premise
//3.2 set new tariff rate (if supplier country changed)
//4. Deliver Premise Detail
return null; return null;
} }
public DestinationDTO getDestination(Integer id) { @Transactional
public List<PremiseDetailDTO> setMaterial(SetDataDTO setMaterialDTO) {
//0. check if one of the given premises contains the same supplier id, and abort if any duplicate would emerge
//3 if updateMasterDate is set:
//3.1 copy packaging data (if exists) of new material to premise
//3.2 set new tariff rate and hs code (if supplier country changed)
//4. Deliver Premise Detail
return null; return null;
} }
public void updateDestination(Integer id) { public HashMap<String, String> updatePackaging(PackagingUpdateDTO packagingDTO) {
//TODO check values. and return errors if needed
var userId = 1; // todo get id from current user.
premiseRepository.updatePackaging(packagingDTO.getPremiseIds(), userId, dimensionTransformer.toDimensionEntity(packagingDTO.getDimensions()), packagingDTO.getStackable(), packagingDTO.getMixable());
return null;
} }
public void deleteDestination(Integer id) { public HashMap<String, String> updateMaterial(MaterialUpdateDTO materialUpdateDTO) {
//TODO check values. and return errors if needed
var userId = 1; // todo get id from current user.
premiseRepository.updateMaterial(materialUpdateDTO.getPremiseIds(), userId, materialUpdateDTO.getHsCode(), BigDecimal.valueOf(materialUpdateDTO.getTariffRate().doubleValue()));
return null;
} }
public List<PremiseDetailDTO> setSupplier(SetSupplierDTO setSupplierDTO) { public HashMap<String, String> updatePrice(PriceUpdateDTO priceUpdateDTO) {
//TODO check values. and return errors if needed
var userId = 1; // todo get id from current user.
premiseRepository.updatePrice(priceUpdateDTO.getPremiseIds(), userId, BigDecimal.valueOf(priceUpdateDTO.getPrice().doubleValue()), priceUpdateDTO.getIncludeFcaFee(), BigDecimal.valueOf(priceUpdateDTO.getOverseaShare().doubleValue()));
return null; return null;
} }
} }

View file

@ -5,11 +5,14 @@ import de.avatic.lcc.dto.generic.NodeDTO;
import de.avatic.lcc.dto.configuration.nodes.view.NodeDetailDTO; import de.avatic.lcc.dto.configuration.nodes.view.NodeDetailDTO;
import de.avatic.lcc.dto.configuration.nodes.update.NodeUpdateDTO; import de.avatic.lcc.dto.configuration.nodes.update.NodeUpdateDTO;
import de.avatic.lcc.dto.generic.NodeType; import de.avatic.lcc.dto.generic.NodeType;
import de.avatic.lcc.model.country.IsoCode;
import de.avatic.lcc.model.nodes.Node; import de.avatic.lcc.model.nodes.Node;
import de.avatic.lcc.repositories.NodeRepository; import de.avatic.lcc.repositories.NodeRepository;
import de.avatic.lcc.repositories.country.CountryRepository;
import de.avatic.lcc.repositories.pagination.SearchQueryPagination; import de.avatic.lcc.repositories.pagination.SearchQueryPagination;
import de.avatic.lcc.repositories.pagination.SearchQueryResult; import de.avatic.lcc.repositories.pagination.SearchQueryResult;
import de.avatic.lcc.repositories.users.UserNodeRepository; import de.avatic.lcc.repositories.users.UserNodeRepository;
import de.avatic.lcc.service.GeoApiService;
import de.avatic.lcc.service.transformer.nodes.NodeUpdateDTOTransformer; import de.avatic.lcc.service.transformer.nodes.NodeUpdateDTOTransformer;
import de.avatic.lcc.service.transformer.nodes.NodeDetailTransformer; import de.avatic.lcc.service.transformer.nodes.NodeDetailTransformer;
import de.avatic.lcc.service.transformer.generic.NodeTransformer; import de.avatic.lcc.service.transformer.generic.NodeTransformer;
@ -28,13 +31,16 @@ public class NodeService {
private final NodeDetailTransformer nodeDetailTransformer; private final NodeDetailTransformer nodeDetailTransformer;
private final NodeUpdateDTOTransformer nodeUpdateDTOTransformer; private final NodeUpdateDTOTransformer nodeUpdateDTOTransformer;
private final UserNodeRepository userNodeRepository; private final UserNodeRepository userNodeRepository;
private final CountryRepository countryRepository;
public NodeService(NodeRepository nodeRepository, NodeTransformer nodeTransformer, NodeDetailTransformer nodeDetailTransformer, NodeUpdateDTOTransformer nodeUpdateDTOTransformer, UserNodeRepository userNodeRepository) { public NodeService(NodeRepository nodeRepository, NodeTransformer nodeTransformer, NodeDetailTransformer nodeDetailTransformer, NodeUpdateDTOTransformer nodeUpdateDTOTransformer, UserNodeRepository userNodeRepository, CountryRepository countryRepository) {
this.nodeRepository = nodeRepository; this.nodeRepository = nodeRepository;
this.nodeTransformer = nodeTransformer; this.nodeTransformer = nodeTransformer;
this.nodeDetailTransformer = nodeDetailTransformer; this.nodeDetailTransformer = nodeDetailTransformer;
this.nodeUpdateDTOTransformer = nodeUpdateDTOTransformer; this.nodeUpdateDTOTransformer = nodeUpdateDTOTransformer;
this.userNodeRepository = userNodeRepository; this.userNodeRepository = userNodeRepository;
this.countryRepository = countryRepository;
} }
public SearchQueryResult<NodeDTO> listNodes(String filter, int page, int limit) { public SearchQueryResult<NodeDTO> listNodes(String filter, int page, int limit) {
@ -75,7 +81,6 @@ public class NodeService {
} }
public void addUserNode(AddUserNodeDTO dto) { public void addUserNode(AddUserNodeDTO dto) {
Node node = new Node(); Node node = new Node();
node.setName(dto.getName()); node.setName(dto.getName());
@ -86,10 +91,7 @@ public class NodeService {
node.setSource(true); node.setSource(true);
node.setIntermediate(false); node.setIntermediate(false);
node.setDeprecated(false); node.setDeprecated(false);
node.setCountryId(countryRepository.getByIsoCode(IsoCode.valueOf(dto.getCountry().getIsoCode())).orElseThrow().getId());
//todo resolve country
node.setCountryId(0);
userNodeRepository.add(node); userNodeRepository.add(node);
} }

View file

@ -2,6 +2,8 @@ package de.avatic.lcc.service.transformer.generic;
import de.avatic.lcc.dto.generic.DimensionDTO; import de.avatic.lcc.dto.generic.DimensionDTO;
import de.avatic.lcc.model.packaging.PackagingDimension; import de.avatic.lcc.model.packaging.PackagingDimension;
import de.avatic.lcc.model.packaging.PackagingType;
import de.avatic.lcc.model.premises.Premise;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
@ -40,4 +42,20 @@ public class DimensionTransformer {
return entity; return entity;
} }
public DimensionDTO toDimensionDTO(Premise entity) {
DimensionDTO dto = new DimensionDTO();
dto.setId(entity.getId());
dto.setType(PackagingType.HU);
dto.setLength(entity.getDimensionUnit().convertFromMM(entity.getIndividualHuLength()).doubleValue());
dto.setWidth(entity.getDimensionUnit().convertFromMM(entity.getIndividualHuWidth()).doubleValue());
dto.setHeight(entity.getDimensionUnit().convertFromMM(entity.getIndividualHuHeight()).doubleValue());
dto.setDimensionUnit(entity.getDimensionUnit());
dto.setWeight(entity.getWeightUnit().convertFromG(entity.getIndividualHuWeight()).doubleValue());
dto.setWeightUnit(entity.getWeightUnit());
dto.setContentUnitCount(entity.getHuUnitCount());
dto.setDeprecated(null);
return dto;
}
} }

View file

@ -2,6 +2,7 @@ package de.avatic.lcc.service.transformer.generic;
import de.avatic.lcc.dto.generic.LocationDTO; import de.avatic.lcc.dto.generic.LocationDTO;
import de.avatic.lcc.model.nodes.Node; import de.avatic.lcc.model.nodes.Node;
import de.avatic.lcc.model.premises.route.RouteNode;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
@ -9,4 +10,8 @@ public class LocationTransformer {
public LocationDTO toLocationDTO(Node entity) { public LocationDTO toLocationDTO(Node entity) {
return new LocationDTO(entity.getGeoLat().doubleValue(), entity.getGeoLng().doubleValue()); return new LocationDTO(entity.getGeoLat().doubleValue(), entity.getGeoLng().doubleValue());
} }
public LocationDTO toLocationDTO(RouteNode entity) {
return new LocationDTO(entity.getGeoLat().doubleValue(), entity.getGeoLng().doubleValue());
}
} }

View file

@ -3,6 +3,7 @@ package de.avatic.lcc.service.transformer.generic;
import de.avatic.lcc.dto.generic.NodeDTO; import de.avatic.lcc.dto.generic.NodeDTO;
import de.avatic.lcc.dto.generic.NodeType; import de.avatic.lcc.dto.generic.NodeType;
import de.avatic.lcc.model.nodes.Node; import de.avatic.lcc.model.nodes.Node;
import de.avatic.lcc.model.premises.route.RouteNode;
import de.avatic.lcc.repositories.country.CountryRepository; import de.avatic.lcc.repositories.country.CountryRepository;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -41,4 +42,24 @@ public class NodeTransformer {
return dto; return dto;
} }
public NodeDTO toNodeDTO(RouteNode entity) {
NodeDTO dto = new NodeDTO();
ArrayList<NodeType> types = new ArrayList<>();
if (entity.getDestination()) types.add(NodeType.DESTINATION);
if (entity.getSource()) types.add(NodeType.SOURCE);
if (entity.getIntermediate()) types.add(NodeType.INTERMEDIATE);
dto.setId(entity.getId());
dto.setName(entity.getName());
dto.setAddress(entity.getAddress());
dto.setCountry(countryTransformerService.toCountryDTO(countryRepository.getById(entity.getCountryId()).orElseThrow()));
dto.setTypes(types);
dto.setDeprecated(entity.getOutdated());
dto.setLocation(locationTransformer.toLocationDTO(entity));
dto.setUserNode(false);
return dto;
}
} }

View file

@ -0,0 +1,38 @@
package de.avatic.lcc.service.transformer.premise;
import de.avatic.lcc.dto.calculation.DestinationDTO;
import de.avatic.lcc.model.premises.route.Destination;
import de.avatic.lcc.repositories.NodeRepository;
import de.avatic.lcc.repositories.premise.RouteRepository;
import de.avatic.lcc.service.transformer.generic.NodeTransformer;
import org.springframework.stereotype.Service;
@Service
public class DestinationTransformer {
private final NodeRepository nodeRepository;
private final NodeTransformer nodeTransformer;
private final RouteRepository routeRepository;
private final RouteTransformer routeTransformer;
public DestinationTransformer(NodeRepository nodeRepository, NodeTransformer nodeTransformer, RouteRepository routeRepository, RouteTransformer routeTransformer) {
this.nodeRepository = nodeRepository;
this.nodeTransformer = nodeTransformer;
this.routeRepository = routeRepository;
this.routeTransformer = routeTransformer;
}
public DestinationDTO toDestinationDTO(Destination destination) {
var dto = new DestinationDTO();
dto.setId(destination.getId());
dto.setRepackingCosts(destination.getRepackingCost());
dto.setDisposalCosts(destination.getDisposalCost());
dto.setHandlingCosts(destination.getHandlingCost());
dto.setDestinationNode(nodeTransformer.toNodeDTO(nodeRepository.getById(destination.getDestinationNodeId()).orElseThrow()));
dto.setRoutes(routeRepository.getByDestinationId(destination.getId()).stream().map(routeTransformer::toRouteDTO).toList());
return dto;
}
}

View file

@ -0,0 +1,112 @@
package de.avatic.lcc.service.transformer.premise;
import de.avatic.lcc.dto.calculation.PremiseDTO;
import de.avatic.lcc.dto.calculation.edit.PremiseDetailDTO;
import de.avatic.lcc.dto.generic.LocationDTO;
import de.avatic.lcc.dto.generic.NodeDTO;
import de.avatic.lcc.dto.generic.NodeType;
import de.avatic.lcc.model.premises.Premise;
import de.avatic.lcc.model.premises.PremiseListEntry;
import de.avatic.lcc.repositories.premise.DestinationRepository;
import de.avatic.lcc.repositories.MaterialRepository;
import de.avatic.lcc.repositories.NodeRepository;
import de.avatic.lcc.repositories.country.CountryRepository;
import de.avatic.lcc.repositories.users.UserNodeRepository;
import de.avatic.lcc.repositories.users.UserRepository;
import de.avatic.lcc.service.transformer.generic.CountryTransformer;
import de.avatic.lcc.service.transformer.generic.DimensionTransformer;
import de.avatic.lcc.service.transformer.generic.MaterialTransformer;
import de.avatic.lcc.service.transformer.generic.NodeTransformer;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@Service
public class PremiseTransformer {
private final MaterialTransformer materialTransformer;
private final UserRepository userRepository;
private final CountryRepository countryRepository;
private final CountryTransformer countryTransformer;
private final NodeTransformer nodeTransformer;
private final MaterialRepository materialRepository;
private final DimensionTransformer dimensionTransformer;
private final NodeRepository nodeRepository;
private final UserNodeRepository userNodeRepository;
private final DestinationRepository destinationRepository;
private final DestinationTransformer destinationTransformer;
public PremiseTransformer(MaterialTransformer materialTransformer, UserRepository userRepository, CountryRepository countryRepository, CountryTransformer countryTransformer, NodeTransformer nodeTransformer, MaterialRepository materialRepository, DimensionTransformer dimensionTransformer, NodeRepository nodeRepository, UserNodeRepository userNodeRepository, DestinationRepository destinationRepository, DestinationTransformer destinationTransformer) {
this.materialTransformer = materialTransformer;
this.userRepository = userRepository;
this.countryRepository = countryRepository;
this.countryTransformer = countryTransformer;
this.nodeTransformer = nodeTransformer;
this.materialRepository = materialRepository;
this.dimensionTransformer = dimensionTransformer;
this.nodeRepository = nodeRepository;
this.userNodeRepository = userNodeRepository;
this.destinationRepository = destinationRepository;
this.destinationTransformer = destinationTransformer;
}
public PremiseDTO toPremiseDTOWithUserInfo(PremiseListEntry entity) {
var dto = toPremiseDTO(entity);
dto.setOwner(userRepository.getById(entity.getOwnerId()));
return dto;
}
public PremiseDTO toPremiseDTO(PremiseListEntry entity) {
NodeDTO node = new NodeDTO();
ArrayList<NodeType> types = new ArrayList<>();
if (entity.isSupplierIsDestination()) types.add(NodeType.DESTINATION);
if (entity.isSupplierIsSource()) types.add(NodeType.SOURCE);
if (entity.isSupplierIsIntermediate()) types.add(NodeType.INTERMEDIATE);
node.setUserNode(entity.isUserSupplier());
node.setName(entity.getSupplierName());
node.setId(entity.getSupplierId());
node.setName(entity.getSupplierName());
node.setCountry(countryTransformer.toCountryDTO(countryRepository.getById(entity.getSupplierCountryId()).orElseThrow()));
node.setAddress(entity.getSupplierAddress());
node.setLocation(new LocationDTO(entity.getSupplierGeoLatitude().doubleValue(), entity.getSupplierGeoLongitude().doubleValue()));
node.setTypes(types);
PremiseDTO dto = new PremiseDTO();
dto.setId(entity.getId());
dto.setState(entity.getState());
dto.setMaterial(materialTransformer.toMaterialDTO(entity.getMaterial()));
dto.setOwner(null);
dto.setSupplier(node);
return dto;
}
public PremiseDetailDTO toPremiseDetailDTO(Premise entity) {
var dto = new PremiseDetailDTO();
dto.setId(entity.getId());
dto.setMaterial(materialTransformer.toMaterialDTO(materialRepository.getById(entity.getMaterialId()).orElseThrow()));
dto.setMixable(entity.getHuMixable());
dto.setStackable(entity.getHuStackable());
dto.setDimension(dimensionTransformer.toDimensionDTO(entity));
if (entity.getSupplierNodeId() != null)
dto.setSupplier(nodeRepository.getById(entity.getSupplierNodeId()).map(nodeTransformer::toNodeDTO).orElseThrow());
if(entity.getUserSupplierNodeId() != null) {
dto.setSupplier(userNodeRepository.getById(entity.getUserSupplierNodeId()).map(nodeTransformer::toNodeDTO).orElseThrow());
dto.getSupplier().setUserNode(true);
}
dto.setDestinations(destinationRepository.getByPremiseId(entity.getId()).stream().map(destinationTransformer::toDestinationDTO).toList());
return dto;
}
}

View file

@ -0,0 +1,10 @@
package de.avatic.lcc.service.transformer.premise;
import org.springframework.stereotype.Service;
@Service
public class RouteSectionTransformer {
public RouteSectionDTO
}

View file

@ -0,0 +1,60 @@
package de.avatic.lcc.service.transformer.premise;
import de.avatic.lcc.dto.calculation.RouteDTO;
import de.avatic.lcc.dto.calculation.TransitNodeDTO;
import de.avatic.lcc.dto.generic.RouteType;
import de.avatic.lcc.model.premises.route.RouteNode;
import de.avatic.lcc.model.premises.route.RouteSection;
import de.avatic.lcc.repositories.premise.RouteNodeRepository;
import de.avatic.lcc.repositories.premise.RouteSectionRepository;
import de.avatic.lcc.service.transformer.generic.NodeTransformer;
import org.springframework.stereotype.Service;
import de.avatic.lcc.model.premises.route.Route;
import java.util.ArrayList;
import java.util.List;
@Service
public class RouteTransformer {
private final RouteSectionRepository routeSectionRepository;
private final RouteNodeRepository routeNodeRepository;
private final NodeTransformer nodeTransformer;
public RouteTransformer(RouteSectionRepository routeSectionRepository, RouteNodeRepository routeNodeRepository, NodeTransformer nodeTransformer) {
this.routeSectionRepository = routeSectionRepository;
this.routeNodeRepository = routeNodeRepository;
this.nodeTransformer = nodeTransformer;
}
public RouteDTO toRouteDTO(Route entity) {
var dto = new RouteDTO();
dto.setId(entity.getId());
dto.setCheapest(entity.getCheapest());
dto.setFastest(entity.getFastest());
dto.setSelected(entity.getSelected());
List<RouteSection> sections = routeSectionRepository.getByRouteId(entity.getId());
dto.setTransitNodes(getRouteNodes(sections).stream().map(nodeTransformer::toNodeDTO).toList());
dto.setType(RouteType.valueOf(sections.stream().filter(RouteSection::getMainRun).findFirst().orElseThrow().getTransportType().name()));
return dto;
}
private List<RouteNode> getRouteNodes(List<RouteSection> sections) {
List<RouteNode> nodes = new ArrayList<>();
nodes.add(routeNodeRepository.getById(sections.getFirst().getFromRouteNodeId()).orElseThrow());
for (RouteSection section : sections) {
nodes.add(routeNodeRepository.getById(section.getToRouteNodeId()).orElseThrow());
}
return nodes;
}
}

View file

@ -323,7 +323,7 @@ CREATE TABLE IF NOT EXISTS packaging_property
UNIQUE KEY idx_packaging_property_unique (packaging_property_type_id, packaging_id) UNIQUE KEY idx_packaging_property_unique (packaging_property_type_id, packaging_id)
); );
CREATE TABLE IF NOT EXISTS premiss CREATE TABLE IF NOT EXISTS premise
( (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
material_id INT NOT NULL, material_id INT NOT NULL,
@ -331,8 +331,8 @@ CREATE TABLE IF NOT EXISTS premiss
user_supplier_node_id INT, user_supplier_node_id INT,
packaging_id INT DEFAULT NULL, packaging_id INT DEFAULT NULL,
user_id INT NOT NULL, user_id INT NOT NULL,
createdAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
material_cost DECIMAL(15, 2) COMMENT 'aka MEK_A in EUR', material_cost DECIMAL(15, 2) COMMENT 'aka MEK_A in EUR',
is_fca_enabled BOOLEAN DEFAULT FALSE, is_fca_enabled BOOLEAN DEFAULT FALSE,
oversea_share DECIMAL(7, 4), oversea_share DECIMAL(7, 4),
@ -353,11 +353,11 @@ CREATE TABLE IF NOT EXISTS premiss
FOREIGN KEY (user_supplier_node_id) REFERENCES sys_user_node (id), FOREIGN KEY (user_supplier_node_id) REFERENCES sys_user_node (id),
FOREIGN KEY (packaging_id) REFERENCES packaging (id), FOREIGN KEY (packaging_id) REFERENCES packaging (id),
FOREIGN KEY (user_id) REFERENCES sys_user (id), FOREIGN KEY (user_id) REFERENCES sys_user (id),
CONSTRAINT `chk_premiss_state_values` CHECK (`state` IN CONSTRAINT `chk_premise_state_values` CHECK (`state` IN
('DRAFT', 'COMPLETED', 'ARCHIVED', 'DELETED')), ('DRAFT', 'COMPLETED', 'ARCHIVED', 'DELETED')),
CONSTRAINT `chk_premiss_displayed_dimension_unit` CHECK (`hu_displayed_dimension_unit` IN CONSTRAINT `chk_premise_displayed_dimension_unit` CHECK (`hu_displayed_dimension_unit` IN
('MM', 'CM', 'M')), ('MM', 'CM', 'M')),
CONSTRAINT `chk_premiss_displayed_weight_unit` CHECK (`hu_displayed_weight_unit` IN CONSTRAINT `chk_premise_displayed_weight_unit` CHECK (`hu_displayed_weight_unit` IN
('G', 'KG')), ('G', 'KG')),
INDEX idx_material_id (material_id), INDEX idx_material_id (material_id),
INDEX idx_supplier_node_id (supplier_node_id), INDEX idx_supplier_node_id (supplier_node_id),
@ -367,38 +367,39 @@ CREATE TABLE IF NOT EXISTS premiss
); );
CREATE TABLE IF NOT EXISTS premiss_destination CREATE TABLE IF NOT EXISTS premise_destination
( (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
premiss_id INT NOT NULL, premise_id INT NOT NULL,
annual_amount INT UNSIGNED NOT NULL COMMENT 'annual amount in single pieces', annual_amount INT UNSIGNED NOT NULL COMMENT 'annual amount in single pieces',
destination_node_id INT NOT NULL, destination_node_id INT NOT NULL,
repacking_cost DECIMAL(15, 2) DEFAULT NULL, repacking_cost DECIMAL(15, 2) DEFAULT NULL,
handling_cost DECIMAL(15, 2) DEFAULT NULL, handling_cost DECIMAL(15, 2) DEFAULT NULL,
disposal_cost DECIMAL(15, 2) DEFAULT NULL, disposal_cost DECIMAL(15, 2) DEFAULT NULL,
FOREIGN KEY (premiss_id) REFERENCES premiss (id), FOREIGN KEY (premise_id) REFERENCES premise (id),
FOREIGN KEY (destination_node_id) REFERENCES node (id), FOREIGN KEY (destination_node_id) REFERENCES node (id),
INDEX idx_destination_node_id (destination_node_id), INDEX idx_destination_node_id (destination_node_id),
INDEX idx_premiss_id (premiss_id) INDEX idx_premise_id (premise_id)
); );
CREATE TABLE IF NOT EXISTS premiss_route CREATE TABLE IF NOT EXISTS premise_route
( (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
premiss_destination_id INT NOT NULL, premise_destination_id INT NOT NULL,
is_fastest BOOLEAN DEFAULT FALSE, is_fastest BOOLEAN DEFAULT FALSE,
is_cheapest BOOLEAN DEFAULT FALSE, is_cheapest BOOLEAN DEFAULT FALSE,
is_selected BOOLEAN DEFAULT FALSE, is_selected BOOLEAN DEFAULT FALSE,
FOREIGN KEY (premiss_destination_id) REFERENCES premiss_destination (id) FOREIGN KEY (premise_destination_id) REFERENCES premise_destination (id)
); );
CREATE TABLE IF NOT EXISTS premiss_route_node CREATE TABLE IF NOT EXISTS premise_route_node
( (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
node_id INT DEFAULT NULL, node_id INT DEFAULT NULL,
user_node_id INT DEFAULT NULL, user_node_id INT DEFAULT NULL,
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
address VARCHAR(500), address VARCHAR(500),
country_id INT NOT NULL,
is_destination BOOLEAN DEFAULT FALSE, is_destination BOOLEAN DEFAULT FALSE,
is_intermediate BOOLEAN DEFAULT FALSE, is_intermediate BOOLEAN DEFAULT FALSE,
is_source BOOLEAN DEFAULT FALSE, is_source BOOLEAN DEFAULT FALSE,
@ -406,16 +407,17 @@ CREATE TABLE IF NOT EXISTS premiss_route_node
geo_lng DECIMAL(7, 4) CHECK (geo_lng BETWEEN -180 AND 180), geo_lng DECIMAL(7, 4) CHECK (geo_lng BETWEEN -180 AND 180),
is_outdated BOOLEAN DEFAULT FALSE, is_outdated BOOLEAN DEFAULT FALSE,
FOREIGN KEY (node_id) REFERENCES node (id), FOREIGN KEY (node_id) REFERENCES node (id),
FOREIGN KEY (country_id) REFERENCES country (id),
FOREIGN KEY (user_node_id) REFERENCES sys_user_node (id), FOREIGN KEY (user_node_id) REFERENCES sys_user_node (id),
INDEX idx_node_id (node_id), INDEX idx_node_id (node_id),
INDEX idx_user_node_id (user_node_id), INDEX idx_user_node_id (user_node_id),
CONSTRAINT `chk_node` CHECK (`user_node_id` IS NULL OR `node_id` IS NULL) CONSTRAINT `chk_node` CHECK (`user_node_id` IS NULL OR `node_id` IS NULL)
); );
CREATE TABLE IF NOT EXISTS premiss_route_section CREATE TABLE IF NOT EXISTS premise_route_section
( (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
premiss_route_id INT NOT NULL, premise_route_id INT NOT NULL,
from_route_node_id INT NOT NULL, from_route_node_id INT NOT NULL,
to_route_node_id INT NOT NULL, to_route_node_id INT NOT NULL,
list_position INT NOT NULL, list_position INT NOT NULL,
@ -426,15 +428,15 @@ CREATE TABLE IF NOT EXISTS premiss_route_section
is_main_run BOOLEAN DEFAULT FALSE, is_main_run BOOLEAN DEFAULT FALSE,
is_post_run BOOLEAN DEFAULT FALSE, is_post_run BOOLEAN DEFAULT FALSE,
is_outdated BOOLEAN DEFAULT FALSE, is_outdated BOOLEAN DEFAULT FALSE,
FOREIGN KEY (premiss_route_id) REFERENCES premiss_route (id), FOREIGN KEY (premise_route_id) REFERENCES premise_route (id),
FOREIGN KEY (from_route_node_id) REFERENCES premiss_route_node (id), FOREIGN KEY (from_route_node_id) REFERENCES premise_route_node (id),
FOREIGN KEY (to_route_node_id) REFERENCES premiss_route_node (id), FOREIGN KEY (to_route_node_id) REFERENCES premise_route_node (id),
CONSTRAINT chk_d2d CHECK ((transport_type != 'D2D' AND rate_d2d IS NULL) OR CONSTRAINT chk_d2d CHECK ((transport_type != 'D2D' AND rate_d2d IS NULL) OR
(transport_type = 'D2D' AND rate_d2d IS NOT NULL)), (transport_type = 'D2D' AND rate_d2d IS NOT NULL)),
CONSTRAINT chk_post_run CHECK ((transport_type = 'POST-RUN' AND is_post_run IS TRUE) OR CONSTRAINT chk_post_run CHECK ((transport_type = 'POST-RUN' AND is_post_run IS TRUE) OR
(transport_type != 'POST-RUN' AND rate_d2d IS FALSE)), (transport_type != 'POST-RUN' AND rate_d2d IS FALSE)),
CONSTRAINT chk_main_run CHECK ((transport_type = 'RAIL' OR transport_type = 'SEA') AND is_main_run IS TRUE), CONSTRAINT chk_main_run CHECK ((transport_type = 'RAIL' OR transport_type = 'SEA') AND is_main_run IS TRUE),
INDEX idx_premiss_route_id (premiss_route_id), INDEX idx_premise_route_id (premise_route_id),
INDEX idx_from_route_node_id (from_route_node_id), INDEX idx_from_route_node_id (from_route_node_id),
INDEX idx_to_route_node_id (to_route_node_id) INDEX idx_to_route_node_id (to_route_node_id)
); );
@ -442,18 +444,18 @@ CREATE TABLE IF NOT EXISTS premiss_route_section
CREATE TABLE IF NOT EXISTS calculation_job CREATE TABLE IF NOT EXISTS calculation_job
( (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
premiss_id INT NOT NULL, premise_id INT NOT NULL,
calculation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, calculation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
validity_period_id INT NOT NULL, validity_period_id INT NOT NULL,
property_set_id INT NOT NULL, property_set_id INT NOT NULL,
job_state CHAR(10) CHECK (job_state IN job_state CHAR(10) CHECK (job_state IN
('CREATED', 'SCHEDULED', 'VALID', 'INVALID', 'EXCEPTION')), ('CREATED', 'SCHEDULED', 'VALID', 'INVALID', 'EXCEPTION')),
user_id INT NOT NULL, user_id INT NOT NULL,
FOREIGN KEY (premiss_id) REFERENCES premiss (id), FOREIGN KEY (premise_id) REFERENCES premise (id),
FOREIGN KEY (validity_period_id) REFERENCES validity_period (id), FOREIGN KEY (validity_period_id) REFERENCES validity_period (id),
FOREIGN KEY (property_set_id) REFERENCES property_set (id), FOREIGN KEY (property_set_id) REFERENCES property_set (id),
FOREIGN KEY (user_id) REFERENCES sys_user (id), FOREIGN KEY (user_id) REFERENCES sys_user (id),
INDEX idx_premiss_id (premiss_id), INDEX idx_premise_id (premise_id),
INDEX idx_validity_period_id (validity_period_id), INDEX idx_validity_period_id (validity_period_id),
INDEX idx_property_set_id (property_set_id) INDEX idx_property_set_id (property_set_id)
); );
@ -483,7 +485,7 @@ CREATE TABLE IF NOT EXISTS calculation_job_transportation
CREATE TABLE IF NOT EXISTS calculation_job_route_section CREATE TABLE IF NOT EXISTS calculation_job_route_section
( (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
premiss_route_section_id INT NOT NULL, premise_route_section_id INT NOT NULL,
calculation_job_transportation_id INT NOT NULL, calculation_job_transportation_id INT NOT NULL,
used_rule CHAR(8) CHECK (used_rule IN used_rule CHAR(8) CHECK (used_rule IN
('CONTAINER', 'MATRIX')), ('CONTAINER', 'MATRIX')),
@ -500,9 +502,9 @@ CREATE TABLE IF NOT EXISTS calculation_job_route_section
weight_price DECIMAL(15, 2) NOT NULL COMMENT 'calculated price per kilogram', weight_price DECIMAL(15, 2) NOT NULL COMMENT 'calculated price per kilogram',
annual_cost DECIMAL(15, 2) NOT NULL COMMENT 'annual costs for this route section, result depends on calculation method (mixed or unmixed, stacked or unstacked, per volume/per weight resp. container rate/price matrix)', annual_cost DECIMAL(15, 2) NOT NULL COMMENT 'annual costs for this route section, result depends on calculation method (mixed or unmixed, stacked or unstacked, per volume/per weight resp. container rate/price matrix)',
transit_time INT UNSIGNED NOT NULL, transit_time INT UNSIGNED NOT NULL,
FOREIGN KEY (premiss_route_section_id) REFERENCES premiss_route_section (id), FOREIGN KEY (premise_route_section_id) REFERENCES premise_route_section (id),
FOREIGN KEY (calculation_job_transportation_id) REFERENCES calculation_job_transportation (id), FOREIGN KEY (calculation_job_transportation_id) REFERENCES calculation_job_transportation (id),
INDEX idx_premiss_route_section_id (premiss_route_section_id), INDEX idx_premise_route_section_id (premise_route_section_id),
INDEX idx_calculation_job_transportation_id (calculation_job_transportation_id), INDEX idx_calculation_job_transportation_id (calculation_job_transportation_id),
CONSTRAINT chk_stacked CHECK (is_unmixed_price IS TRUE OR is_stacked IS TRUE), -- only unmixed transports can be unstacked CONSTRAINT chk_stacked CHECK (is_unmixed_price IS TRUE OR is_stacked IS TRUE), -- only unmixed transports can be unstacked
CONSTRAINT chk_cbm_weight_price CHECK (is_unmixed_price IS FALSE OR CONSTRAINT chk_cbm_weight_price CHECK (is_unmixed_price IS FALSE OR
@ -562,7 +564,7 @@ CREATE TABLE IF NOT EXISTS calculation_job_destination
( (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
calculation_job_id INT NOT NULL, calculation_job_id INT NOT NULL,
premiss_destination_id INT NOT NULL, premise_destination_id INT NOT NULL,
safety_stock INT UNSIGNED COMMENT 'safety stock in single pieces ?!?!', safety_stock INT UNSIGNED COMMENT 'safety stock in single pieces ?!?!',
shipping_frequency INT UNSIGNED COMMENT 'annual shipping frequency', shipping_frequency INT UNSIGNED COMMENT 'annual shipping frequency',
total_cost DECIMAL(15, 2) COMMENT 'aka MEK_B in EUR', total_cost DECIMAL(15, 2) COMMENT 'aka MEK_B in EUR',
@ -574,7 +576,7 @@ CREATE TABLE IF NOT EXISTS calculation_job_destination
calculation_job_transportation_id INT NOT NULL, calculation_job_transportation_id INT NOT NULL,
calculation_job_airfreight_id INT NOT NULL, calculation_job_airfreight_id INT NOT NULL,
FOREIGN KEY (calculation_job_id) REFERENCES calculation_job (id), FOREIGN KEY (calculation_job_id) REFERENCES calculation_job (id),
FOREIGN KEY (premiss_destination_id) REFERENCES premiss_destination (id), FOREIGN KEY (premise_destination_id) REFERENCES premise_destination (id),
FOREIGN KEY (calculation_job_custom_id) REFERENCES calculation_job_custom (id), FOREIGN KEY (calculation_job_custom_id) REFERENCES calculation_job_custom (id),
FOREIGN KEY (calculation_job_inventory_id) REFERENCES calculation_job_inventory (id), FOREIGN KEY (calculation_job_inventory_id) REFERENCES calculation_job_inventory (id),
FOREIGN KEY (calculation_job_handling_id) REFERENCES calculation_job_handling (id), FOREIGN KEY (calculation_job_handling_id) REFERENCES calculation_job_handling (id),
@ -583,5 +585,5 @@ CREATE TABLE IF NOT EXISTS calculation_job_destination
FOREIGN KEY (calculation_job_transportation_id) REFERENCES calculation_job_transportation (id), FOREIGN KEY (calculation_job_transportation_id) REFERENCES calculation_job_transportation (id),
FOREIGN KEY (calculation_job_airfreight_id) REFERENCES calculation_job_airfreight (id), FOREIGN KEY (calculation_job_airfreight_id) REFERENCES calculation_job_airfreight (id),
INDEX idx_calculation_job_id (calculation_job_id), INDEX idx_calculation_job_id (calculation_job_id),
INDEX idx_premiss_destination_id (premiss_destination_id) INDEX idx_premise_destination_id (premise_destination_id)
); );