From c1ef9fa1db881e705d8d9a44b11d49375278d075 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Fri, 5 Jul 2024 15:08:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E6=89=93=E8=BD=A6?= =?UTF-8?q?=E8=A1=8C=E7=A8=8B=E6=B2=A1=E6=9C=89=E6=9B=B4=E6=96=B0=E5=9C=B0?= =?UTF-8?q?=E7=82=B9=E8=AE=A1=E7=AE=97=E5=AD=97=E6=AE=B5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/dtos/response/LegRes.java | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/chint/application/dtos/response/LegRes.java b/src/main/java/com/chint/application/dtos/response/LegRes.java index 5895a117..da5e082b 100644 --- a/src/main/java/com/chint/application/dtos/response/LegRes.java +++ b/src/main/java/com/chint/application/dtos/response/LegRes.java @@ -8,11 +8,14 @@ import com.chint.domain.aggregates.order.Location; import com.chint.domain.aggregates.order.OrderDetail; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import org.jetbrains.annotations.NotNull; import org.springframework.data.annotation.Id; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import static com.chint.infrastructure.constant.LegConstant.LEG_TYPE_OTHER; import static com.chint.infrastructure.constant.LegConstant.LEG_TYPE_TAXI; @@ -99,26 +102,36 @@ public class LegRes { legRes.setSupplierNameList(new ArrayList<>()); } + StringBuilder sb = getStringBuilder(leg, originLocation, destinationLocation); + legRes.setLocationNameList(sb.toString()); + + return legRes; + } + + private static @NotNull StringBuilder getStringBuilder(Leg leg, + Location originLocation, + Location destinationLocation) { StringBuilder sb = new StringBuilder(); + Set locationSet = new HashSet<>(); if (leg.getLegType().equals(LEG_TYPE_TAXI) || leg.getLegType().equals(LEG_TYPE_OTHER)) { List locationList = leg.getLegExtensionField().getLocationList(); if (locationList != null && !locationList.isEmpty()) { for (Location location : locationList) { - sb.append(location.getLocationName()); - sb.append(","); + locationSet.add(location.getLocationName()); } - // Remove the last comma - if (!sb.isEmpty()) { - sb.setLength(sb.length() - 1); - } - legRes.setLocationNameList(sb.toString()); } } else { - sb.append(originLocation.getLocationName()); - sb.append(","); - sb.append(destinationLocation.getLocationName()); + locationSet.add(originLocation.getLocationName()); + locationSet.add(destinationLocation.getLocationName()); } - legRes.setLocationNameList(sb.toString()); - return legRes; + for (String locationName : locationSet) { + sb.append(locationName); + sb.append(","); + } + // Remove the last comma if StringBuilder is not empty + if (!sb.isEmpty()) { + sb.setLength(sb.length() - 1); + } + return sb; } }