Skip to content

Commit

Permalink
Merge pull request #86 from FinalDoubleTen/develop
Browse files Browse the repository at this point in the history
Refactor : 여정 아이템 1개 일때 경로 정보 추가
  • Loading branch information
Kim-Dong-Jun99 authored Jan 17, 2024
2 parents d48f1d1 + 4c57150 commit e0987fe
Showing 1 changed file with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.tenten.tentenstomp.domain.trip.dto.response.TripPathInfoMsg;
import org.tenten.tentenstomp.domain.trip.dto.response.TripPathInfoMsg.PathInfo;
import org.tenten.tentenstomp.global.common.annotation.GetExecutionTime;
import org.tenten.tentenstomp.global.common.enums.Transportation;
import org.tenten.tentenstomp.global.component.dto.request.PathCalculateRequest;
Expand All @@ -25,29 +26,40 @@ public class PathComponent {
public TripPathCalculationResult getTripPath(List<TripPlace> tripPlaceList, Transportation transportation) {

List<PathCalculateRequest> pathCalculateRequests = toPathCalculateRequest(tripPlaceList);
Integer priceSum = 0;
List<TripPathInfoMsg> pathInfoMsgs = new CopyOnWriteArrayList<>();
for (PathCalculateRequest calculateRequest : pathCalculateRequests) {
asyncPathComponent.calculatePath(calculateRequest.from(), calculateRequest.to(), pathInfoMsgs, transportation);
}
while (true) {
if (pathInfoMsgs.size() == pathCalculateRequests.size()) {
break;
if (pathCalculateRequests.isEmpty()) {
List<TripPathInfoMsg> pathInfoMsgs = new ArrayList<>();
TripPlace tripPlace = tripPlaceList.get(0);
pathInfoMsgs.add(new TripPathInfoMsg(
tripPlace.tripItemId(), tripPlace.tripItemId(), tripPlace.seqNum(), tripPlace.seqNum(),
tripPlace.longitude(), tripPlace.latitude(), tripPlace.longitude(), tripPlace.latitude(), new PathInfo(0, 0.0, 0L)
));
return new TripPathCalculationResult(0, pathInfoMsgs);
} else {
Integer priceSum = 0;
List<TripPathInfoMsg> pathInfoMsgs = new CopyOnWriteArrayList<>();
for (PathCalculateRequest calculateRequest : pathCalculateRequests) {
asyncPathComponent.calculatePath(calculateRequest.from(), calculateRequest.to(), pathInfoMsgs, transportation);
}
}
for (TripPathInfoMsg tpm : pathInfoMsgs) {
if (tpm.pathInfo() != null) {
priceSum += tpm.pathInfo().price();
while (true) {
if (pathInfoMsgs.size() == pathCalculateRequests.size()) {
break;
}
}
for (TripPathInfoMsg tpm : pathInfoMsgs) {
if (tpm.pathInfo() != null) {
priceSum += tpm.pathInfo().price();
}
}
pathInfoMsgs.sort((a, b) -> {
if (!a.fromSeqNum().equals(b.fromSeqNum())) {

return Integer.parseInt(Long.toString(a.fromSeqNum() - b.fromSeqNum()));
}
return Integer.parseInt(Long.toString(a.fromTripItemId() - b.fromTripItemId()));
});
return new TripPathCalculationResult(priceSum, pathInfoMsgs);
}
pathInfoMsgs.sort((a, b) -> {
if (!a.fromSeqNum().equals(b.fromSeqNum())) {

return Integer.parseInt(Long.toString(a.fromSeqNum() - b.fromSeqNum()));
}
return Integer.parseInt(Long.toString(a.fromTripItemId() - b.fromTripItemId()));
});
return new TripPathCalculationResult(priceSum, pathInfoMsgs);

}

Expand Down

0 comments on commit e0987fe

Please sign in to comment.