Skip to content

Commit

Permalink
Fix/select query (#24)
Browse files Browse the repository at this point in the history
* feat: Entity 에 Index 적용

* refactor: TrafficDetailRepository findMostRecentlyData 쿼리 수정

* refactor: DTO 클래스 네이밍 통일

---------

Co-authored-by: belljun3395 <[email protected]>
  • Loading branch information
nove1080 and belljun3395 authored Jun 19, 2024
1 parent 02055fe commit c07d680
Show file tree
Hide file tree
Showing 76 changed files with 730 additions and 379 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ List<TrafficDetailEntity> findAllInIdsBetween(

@Query(
value =
"SELECT * FROM traffic_detail td "
+ "INNER JOIN (SELECT t.traffic_id, MAX(t.time_left_reg_dt) AS maxTimeLeftRegDt "
+ " FROM traffic_detail t "
+ " WHERE t.traffic_id IN :trafficIds "
+ " GROUP BY t.traffic_id) maxTd "
+ "ON td.traffic_id = maxTd.traffic_id AND td.time_left_reg_dt = maxTd.maxTimeLeftRegDt "
+ "WHERE td.traffic_id IN :trafficIds",
nativeQuery = true)
List<TrafficDetailEntity> findAllTopDataInTrafficIds(@Param("trafficIds") List<Long> trafficIds);
" SELECT td1 "
+ " FROM TrafficDetailEntity td1 "
+ " WHERE td1.traffic in (:trafficIds) "
+ " AND td1.timeLeftRegDt = ( "
+ " SELECT MAX(td2.timeLeftRegDt) "
+ " FROM TrafficDetailEntity td2 "
+ " WHERE td2.traffic = td1.traffic)")
List<TrafficDetailEntity> findMostRecenlyData(@Param("trafficIds") List<Long> trafficIds);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.walking.api.domain.path.dto;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Getter
@ToString
@EqualsAndHashCode
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
public class CalculatePathFavoritesTimeUseCaseIn {
private Long favoritesPathId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.walking.api.domain.path.dto;

import com.walking.api.domain.traffic.dto.detail.PointDetail;
import com.walking.api.domain.traffic.dto.detail.TrafficDetail;
import java.time.LocalDateTime;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Getter
@ToString
@EqualsAndHashCode
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
public class CalculatePathFavoritesTimeUseCaseOut {
private LocalDateTime nowTime;
private Integer totalTime;
private Integer trafficCount;
private List<LocalDateTime> departureTimes;
private Integer timeToFirstTraffic;
private Integer totalDistance;
private PointDetail startPoint;
private PointDetail endPoint;
private List<TrafficDetail> traffics;
private List<Long> trafficIdsInPath;
private List<PointDetail> paths;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.walking.api.domain.path.dto;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Getter
@ToString
@EqualsAndHashCode
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
public class CalculatePathTimeUseCaseIn {
private Double startLat;
private Double startLng;
private Double endLat;
private Double endLng;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.walking.api.domain.path.dto;

import com.walking.api.domain.traffic.dto.detail.PointDetail;
import com.walking.api.domain.traffic.dto.detail.TrafficDetail;
import java.time.LocalDateTime;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Getter
@ToString
@EqualsAndHashCode
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
public class CalculatePathTimeUseCaseOut {
private LocalDateTime nowTime;
private Integer totalTime;
private Integer trafficCount;
private List<LocalDateTime> departureTimes;
private Integer timeToFirstTraffic;
private Integer totalDistance;
private PointDetail startPoint;
private PointDetail endPoint;
private List<TrafficDetail> traffics;
private List<Long> trafficIdsInPath;
private List<PointDetail> paths;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.walking.api.domain.path.dto;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Getter
@ToString
@EqualsAndHashCode
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
public class DeleteFavoriteRouteUseCaseIn {
private Long memberId;
private Long pathId;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.walking.api.domain.path.dto;

import com.walking.api.web.dto.request.OrderFilter;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Getter
@ToString
@EqualsAndHashCode
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
public class ReadFavoritesPathUseCaseIn {
private Long memberId;
private String name;
private OrderFilter orderFilter;

public boolean isOrderFiltered() {
return orderFilter != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ReadFavoritesPathUseCaseResponse {

public class ReadFavoritesPathUseCaseOut {
private Long id;
private Point startPoint;
private Point endPoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SavePathFavoritesUseCaseRequest {
public class SavePathFavoritesUseCaseIn {
private Long memberId;
private String name;
private String startName;
private double startLat;
private double startLng;
private Double startLat;
private Double startLng;
private String endName;
private double endLat;
private double endLng;
private Double endLat;
private Double endLng;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class UpdateRoutePathNameUseCaseRequest {
public class UpdateRoutePathNameUseCaseIn {
private Long memberId;
private Long pathId;
private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@
import com.walking.api.domain.client.dto.response.TMapResponseDto;
import com.walking.api.domain.client.dto.response.detail.FeatureDetail;
import com.walking.api.domain.client.dto.response.detail.GeometryDetail;
import com.walking.api.domain.path.dto.PathPrimaryData;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.locationtech.jts.geom.*;

@AllArgsConstructor
public class SearchPath {

private final TMapResponseDto tMapPathData;

public PathPrimaryData extractPrimaryDataByTMap() {
return new PathPrimaryData(
@Data
@AllArgsConstructor
public static class PathPrimaryVO {
private Integer totalTime;
private Integer untilTrafficTime;
private Integer totalDistance;
}

public PathPrimaryVO extractPrimaryDataByTMap() {
return new PathPrimaryVO(
calculateTotalTime(tMapPathData),
calculateUntilFirstTraffic(tMapPathData),
tMapPathData.getFeatureDetails().get(0).getPropertyDetails().getTotalDistance());
Expand Down
Loading

0 comments on commit c07d680

Please sign in to comment.