Bugfix: was mixing up user node and non-user node in RoutingService
This commit is contained in:
parent
adc1ee0d04
commit
06ad1415fb
2 changed files with 31 additions and 5 deletions
|
|
@ -5,6 +5,7 @@ import de.avatic.lcc.model.db.ValidityTuple;
|
|||
import de.avatic.lcc.model.db.nodes.Node;
|
||||
import de.avatic.lcc.repositories.pagination.SearchQueryPagination;
|
||||
import de.avatic.lcc.repositories.pagination.SearchQueryResult;
|
||||
import de.avatic.lcc.util.exception.internalerror.DatabaseException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
|
|
@ -165,6 +166,9 @@ public class NodeRepository {
|
|||
return Optional.empty();
|
||||
}
|
||||
|
||||
if(node.isUserNode())
|
||||
throw new DatabaseException("Cannot update user node in node repository.");
|
||||
|
||||
String updateNodeSql = """
|
||||
UPDATE node SET
|
||||
country_id = ?,
|
||||
|
|
@ -389,6 +393,25 @@ public class NodeRepository {
|
|||
@Transactional
|
||||
public List<Node> getByDistance(Node node, Integer regionRadius) {
|
||||
|
||||
if(node.isUserNode()) {
|
||||
String query = """
|
||||
SELECT * FROM node
|
||||
WHERE is_deprecated = FALSE AND
|
||||
(
|
||||
6371 * acos(
|
||||
cos(radians(?)) *
|
||||
cos(radians(geo_lat)) *
|
||||
cos(radians(geo_lng) - radians(?)) +
|
||||
sin(radians(?)) *
|
||||
sin(radians(geo_lat))
|
||||
)
|
||||
) <= ?
|
||||
""";
|
||||
|
||||
return jdbcTemplate.query(query, new NodeMapper(), node.getGeoLat(), node.getGeoLng(), node.getGeoLat(), regionRadius);
|
||||
}
|
||||
|
||||
|
||||
String query = """
|
||||
SELECT * FROM node
|
||||
WHERE is_deprecated = FALSE AND id != ? AND
|
||||
|
|
|
|||
|
|
@ -431,7 +431,7 @@ public class RoutingService {
|
|||
TemporaryRateObject finalSection = null;
|
||||
SourceConnectionType connectionType = SourceConnectionType.NONE;
|
||||
|
||||
if (source.getId().equals(chain.getLast().getId())) {
|
||||
if (!source.isUserNode() && source.getId().equals(chain.getLast().getId())) {
|
||||
connectionType = SourceConnectionType.CHAIN_END_IS_SOURCE_NODE;
|
||||
} else if (nearByNodes != null) {
|
||||
nearByNode = nearByNodes.stream().filter(n -> n.getId().equals(chain.getLast().getId())).findFirst().orElse(null);
|
||||
|
|
@ -690,7 +690,7 @@ public class RoutingService {
|
|||
if (container.getRates().contains(matrixRateObj))
|
||||
return container.getRates().stream().filter(r -> r.equals(matrixRateObj)).findFirst().orElseThrow();
|
||||
|
||||
Optional<ContainerRate> containerRate = containerRateRepository.findRoute(startNode.getId(), endNode.getId(), TransportType.ROAD);
|
||||
Optional<ContainerRate> containerRate = startNode.isUserNode() ? Optional.empty() : containerRateRepository.findRoute(startNode.getId(), endNode.getId(), TransportType.ROAD);
|
||||
|
||||
if (containerRate.isPresent()) {
|
||||
containerRateObj.setRate(containerRate.get());
|
||||
|
|
@ -987,7 +987,10 @@ public class RoutingService {
|
|||
if (this.type.equals(TemporaryRateObjectType.MATRIX)) {
|
||||
return Objects.equals(this.fromNode.getCountryId(), that.fromNode.getCountryId()) && Objects.equals(this.toNode.getCountryId(), that.toNode.getCountryId());
|
||||
} else if (this.type.equals(TemporaryRateObjectType.CONTAINER) || this.type.equals(TemporaryRateObjectType.MAIN_RUN) || this.type.equals(TemporaryRateObjectType.POST_RUN) || this.type.equals(TemporaryRateObjectType.NEAR_BY)) {
|
||||
return Objects.equals(this.fromNode.getId(), that.fromNode.getId()) && Objects.equals(this.toNode.getId(), that.toNode.getId());
|
||||
return Objects.equals(this.fromNode.getId(), that.fromNode.getId())
|
||||
&& Objects.equals(this.toNode.getId(), that.toNode.getId())
|
||||
&& Objects.equals(this.fromNode.isUserNode(), that.fromNode.isUserNode())
|
||||
&& Objects.equals(this.toNode.isUserNode(), that.toNode.isUserNode());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1000,7 +1003,7 @@ public class RoutingService {
|
|||
|
||||
if (containerRate != null) return Objects.hash(containerRate.getFromNodeId(), containerRate.getToNodeId());
|
||||
|
||||
return Objects.hash(null, null);
|
||||
return Objects.hash(fromNode.getId(), toNode.getId(), fromNode.isUserNode(), toNode.isUserNode());
|
||||
}
|
||||
|
||||
public void setRate(ContainerRate containerRate) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue